apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject svn commit: r679630 - in /apr/apr/trunk: CHANGES file_io/unix/copy.c file_io/win32/open.c include/apr_file_io.h test/testfilecopy.c
Date Fri, 25 Jul 2008 00:17:04 GMT
Author: bojan
Date: Thu Jul 24 17:17:04 2008
New Revision: 679630

URL: http://svn.apache.org/viewvc?rev=679630&view=rev
Log:
Add apr_file_link() function.
PR 44841.
Patch by Mark Heily <mark heily.com>

Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/file_io/unix/copy.c
    apr/apr/trunk/file_io/win32/open.c
    apr/apr/trunk/include/apr_file_io.h
    apr/apr/trunk/test/testfilecopy.c

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?rev=679630&r1=679629&r2=679630&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES [utf-8] (original)
+++ apr/apr/trunk/CHANGES [utf-8] Thu Jul 24 17:17:04 2008
@@ -26,6 +26,8 @@
   *) Implement apr_proc_wait_all_procs for windows.
      [Mladen Turk]
 
+  *) Add apr_file_link() function. PR 44841 
+     [Mark Heily <mark heily.com>]
 
 Changes for APR 1.3.0
 

Modified: apr/apr/trunk/file_io/unix/copy.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/unix/copy.c?rev=679630&r1=679629&r2=679630&view=diff
==============================================================================
--- apr/apr/trunk/file_io/unix/copy.c (original)
+++ apr/apr/trunk/file_io/unix/copy.c Thu Jul 24 17:17:04 2008
@@ -116,3 +116,13 @@
                                       perms,
                                       pool);
 }
+
+APR_DECLARE(apr_status_t) apr_file_link(const char *from_path, 
+                                          const char *to_path)
+{
+    if (link(from_path, to_path) == -1) {
+        return errno;
+    }
+
+    return APR_SUCCESS;
+}

Modified: apr/apr/trunk/file_io/win32/open.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/win32/open.c?rev=679630&r1=679629&r2=679630&view=diff
==============================================================================
--- apr/apr/trunk/file_io/win32/open.c (original)
+++ apr/apr/trunk/file_io/win32/open.c Thu Jul 24 17:17:04 2008
@@ -581,6 +581,36 @@
     return apr_get_os_error();
 }
 
+APR_DECLARE(apr_status_t) apr_file_link(const char *from_path, 
+                                           const char *to_path)
+{
+    apr_status_t rv;
+
+#if APR_HAS_UNICODE_FS
+    IF_WIN_OS_IS_UNICODE
+    {
+        apr_wchar_t wfrom_path[APR_PATH_MAX];
+        apr_wchar_t wto_path[APR_PATH_MAX];
+
+        if (rv = utf8_to_unicode_path(wfrom_path, sizeof(wfrom_path) 
+                                               / sizeof(apr_wchar_t), from_path))
+            return rv;
+        if (rv = utf8_to_unicode_path(wto_path, sizeof(wto_path) 
+                                               / sizeof(apr_wchar_t), to_path))
+            return rv;
+
+        if (!CreateHardLinkW(wto_path, wfrom_path))
+                return apr_get_os_error()
+    }
+#endif
+#if APR_HAS_ANSI_FS
+    ELSE_WIN_OS_IS_ANSI {
+        if (!CreateHardLinkA(wto_path, wfrom_path))
+                return apr_get_os_error()
+    }
+#endif
+}
+
 APR_DECLARE(apr_status_t) apr_os_file_get(apr_os_file_t *thefile,
                                           apr_file_t *file)
 {

Modified: apr/apr/trunk/include/apr_file_io.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_file_io.h?rev=679630&r1=679629&r2=679630&view=diff
==============================================================================
--- apr/apr/trunk/include/apr_file_io.h (original)
+++ apr/apr/trunk/include/apr_file_io.h Thu Jul 24 17:17:04 2008
@@ -265,6 +265,15 @@
                                           apr_pool_t *pool);
 
 /**
+ * Create a hard link to the specified file.
+ * @param from_path The full path to the original file (using / on all systems)
+ * @param to_path The full path to the new file (using / on all systems)
+ * @remark Both files must reside on the same device.
+ */
+APR_DECLARE(apr_status_t) apr_file_link(const char *from_path, 
+                                          const char *to_path);
+
+/**
  * Copy the specified file to another file.
  * @param from_path The full path to the original file (using / on all systems)
  * @param to_path The full path to the new file (using / on all systems)

Modified: apr/apr/trunk/test/testfilecopy.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testfilecopy.c?rev=679630&r1=679629&r2=679630&view=diff
==============================================================================
--- apr/apr/trunk/test/testfilecopy.c (original)
+++ apr/apr/trunk/test/testfilecopy.c Thu Jul 24 17:17:04 2008
@@ -123,6 +123,23 @@
     APR_ASSERT_SUCCESS(tc, "Couldn't remove copy file", rv);
 }
 
+static void link_existing(abts_case *tc, void *data)
+{
+    apr_status_t rv;
+    
+    rv = apr_file_link("data/file_datafile.txt", "data/file_datafile2.txt");
+    apr_file_remove("data/file_datafile2.txt", p);
+    ABTS_ASSERT(tc, "Couldn't create hardlink to file", rv == APR_SUCCESS);
+}
+
+static void link_nonexisting(abts_case *tc, void *data)
+{
+    apr_status_t rv;
+    
+    rv = apr_file_link("data/does_not_exist.txt", "data/fake.txt");
+    ABTS_ASSERT(tc, "", rv != APR_SUCCESS);
+}
+
 abts_suite *testfilecopy(abts_suite *suite)
 {
     suite = ADD_SUITE(suite)
@@ -133,6 +150,9 @@
     abts_run_test(suite, append_nonexist, NULL);
     abts_run_test(suite, append_exist, NULL);
 
+    abts_run_test(suite, link_existing, NULL);
+    abts_run_test(suite, link_nonexisting, NULL);
+
     return suite;
 }
 



Mime
View raw message