You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by bo...@apache.org on 2008/07/25 02:17:04 UTC

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

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;
 }
 



Re: 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

Posted by Bojan Smojver <bo...@rexursive.com>.
On Thu, 2008-07-24 at 22:45 -0500, William A. Rowe, Jr. wrote:

> I pended this patch because I was thinking about the softlink side.

We can always have apr_file_symlink() in the future, right?

-- 
Bojan


Re: 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

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
Tom Donovan wrote:
> 
> After a few small changes to the win code, apr_file_link() now works 
> fine on windows.  Hardlinks require an NTFS filesystem on windows and 
> are seldom encountered, but they work just as on unix.

I pended this patch because I was thinking about the softlink side.  We
can create junctions on NTFS facilitating soft links on all, the only
sad bit is that they work on windows only for directories, not for files.

Re: 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

Posted by Bojan Smojver <bo...@rexursive.com>.
On Thu, 2008-07-24 at 23:35 -0400, Tom Donovan wrote:

> I moved apr_file_link() to open.c for all platforms - r679652.
> Also moved the tests to testfile vs. testfilecopy.
> 
> unix/copy.c is currently used for both unix & windows, as it had no platform-specific code before this.

Ah, wasn't aware of this, thanks.

> After a few small changes to the win code, apr_file_link() now works fine on windows.  Hardlinks 
> require an NTFS filesystem on windows and are seldom encountered, but they work just as on unix.
> 
> apr trunk testfile (with the two new apr_file_link tests) shows SUCCESS on both windows & linux.

Excellent, thank you!

-- 
Bojan


Re: 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

Posted by Tom Donovan <do...@bellatlantic.net>.
Bojan Smojver wrote:
> On Fri, 2008-07-25 at 00:17 +0000, bojan@apache.org wrote:
> 
>> Add apr_file_link() function.
>> PR 44841.
>> Patch by Mark Heily <mark heily.com>
> 
> Folks, this addition includes Windows code, which I am unable to review
> at all (Unix code is very simple, though). So, I'm relying on CTR here!
> 
I moved apr_file_link() to open.c for all platforms - r679652.
Also moved the tests to testfile vs. testfilecopy.

unix/copy.c is currently used for both unix & windows, as it had no platform-specific code before this.

After a few small changes to the win code, apr_file_link() now works fine on windows.  Hardlinks 
require an NTFS filesystem on windows and are seldom encountered, but they work just as on unix.

apr trunk testfile (with the two new apr_file_link tests) shows SUCCESS on both windows & linux.

-tom-

Re: 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

Posted by Bojan Smojver <bo...@rexursive.com>.
On Fri, 2008-07-25 at 00:17 +0000, bojan@apache.org wrote:

> Add apr_file_link() function.
> PR 44841.
> Patch by Mark Heily <mark heily.com>

Folks, this addition includes Windows code, which I am unable to review
at all (Unix code is very simple, though). So, I'm relying on CTR here!

-- 
Bojan