]> arthur.barton.de Git - netatalk.git/commitdiff
Merge branch 'branch-netatalk-3-1' of netafp.com:git/netatalk into branch-netatalk-3-1
authorRalph Boehme <rb@sernet.de>
Wed, 18 Jun 2014 15:00:36 +0000 (17:00 +0200)
committerRalph Boehme <rb@sernet.de>
Wed, 18 Jun 2014 15:00:36 +0000 (17:00 +0200)
Conflicts:
NEWS

NEWS
etc/afpd/ofork.c
libatalk/adouble/ad_write.c

diff --git a/NEWS b/NEWS
index 2f5807d22235f37665eb9f327dd1d49f7018689e..eb10cf613100afad1caf475b15c7a2abd70f1bc9 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,7 @@ Changes in 3.1.3
 * FIX: afpd: Unarchiving certain ZIP archives fails, bug #569
 * UPD: Update Unicode support to version 7.0.0
 * FIX: Memory overflow caused by 'basedir regex', bug #567
+* NEW: afpd: delete empty resource forks, from FR #92
 * FIX: afpd: fix a crash when accessing ._ AppleDouble files created
        by OS X via SMB, bug #564
 
index 7c975c38f9ed581702e74827aaaf2c2d863e8ce7..9d389bb2cb9345960bdcfb7a6cc2630e3bc2e391 100644 (file)
 #include <atalk/bstradd.h>
 #include <atalk/globals.h>
 #include <atalk/fce_api.h>
+#include <atalk/ea.h>
 
 #include "volume.h"
 #include "directory.h"
 #include "fork.h"
+#include "desktop.h"
 
 /* we need to have a hashed list of oforks (by dev inode) */
 #define OFORK_HASHSIZE  64
@@ -389,6 +391,8 @@ int of_closefork(const AFPObj *obj, struct ofork *ofork)
     struct timeval      tv;
     int         adflags = 0;
     int                 ret;
+    struct dir *dir;
+    bstring forkpath = NULL;
 
     adflags = 0;
     if (ofork->of_flags & AFPFORK_DATA)
@@ -405,14 +409,18 @@ int of_closefork(const AFPObj *obj, struct ofork *ofork)
         }
     }
 
+    dir = dirlookup(ofork->of_vol, ofork->of_did);
+    if (dir == NULL) {
+        LOG(log_debug, logtype_afpd, "dirlookup failed for %ju", (uintmax_t)ofork->of_did);
+    }
+
+    if (dir) {
+        forkpath = bformat("%s/%s", bdata(dir->d_fullpath), of_name(ofork));
+    }
+
     /* Somone has used write_fork, we assume file was changed, register it to file change event api */
-    if (ofork->of_flags & AFPFORK_MODIFIED) {
-        struct dir *dir =  dirlookup(ofork->of_vol, ofork->of_did);
-        if (dir) {
-            bstring forkpath = bformat("%s/%s", bdata(dir->d_fullpath), of_name(ofork));
-            fce_register(FCE_FILE_MODIFY, bdata(forkpath), NULL, fce_file);
-            bdestroy(forkpath);
-        }
+    if ((ofork->of_flags & AFPFORK_MODIFIED) && (forkpath)) {
+        fce_register(FCE_FILE_MODIFY, bdata(forkpath), NULL, fce_file);
     }
 
     ad_unlock(ofork->of_ad, ofork->of_refnum, ofork->of_flags & AFPFORK_ERROR ? 0 : 1);
@@ -429,12 +437,46 @@ int of_closefork(const AFPObj *obj, struct ofork *ofork)
 #endif
 
     ret = 0;
+
+    /*
+     * Check for 0 byte size resource forks, delete them.
+     * Here's the deal:
+     * (1) the size must be 0
+     * (2) the fork must refer to a resource fork
+     * (3) the refcount must be 1 which means this fork has the last
+     *     reference to the adouble struct and the subsequent
+     *     ad_close() will close the assoiciated fd.
+     * (4) nobody else has the resource fork open
+     *
+     * We only do this for ._ AppleDouble resource forks, not for
+     * xattr resource forks, because the test-suite then fails several
+     * tests on Solaris, the reason for that still needs to be
+     * determined.
+     */
+    if ((ofork->of_ad->ad_rlen == 0)
+        && (ofork->of_flags & AFPFORK_RSRC)
+        && (ofork->of_ad->ad_rfp->adf_refcount == 1)
+        && (ad_openforks(ofork->of_ad, ATTRBIT_DOPEN) == 0)) {
+
+#ifndef HAVE_EAFD
+        (void)unlink(ofork->of_ad->ad_ops->ad_path(
+                         mtoupath(ofork->of_vol,
+                                  of_name(ofork),
+                                  ofork->of_did,
+                                  utf8_encoding(obj)),
+                         0));
+#endif
+    }
+
     if ( ad_close( ofork->of_ad, adflags | ADFLAGS_SETSHRMD) < 0 ) {
         ret = -1;
     }
 
     of_dealloc(ofork);
 
+    if (forkpath)
+        bdestroy(forkpath);
+
     return ret;
 }
 
index 5cd3742d69f9890f3fa01a5148fc23fda7ae1e6f..4ae1cf60adf1cfcbd61907d20a5fc430c1f4d31a 100644 (file)
@@ -161,17 +161,22 @@ int ad_rtruncate(struct adouble *ad, const char *uname, const off_t size)
 {
     EC_INIT;
 
-#ifndef HAVE_EAFD
-    if (ad->ad_vers == AD_VERSION_EA && size == 0)
-        EC_NEG1( unlink(ad->ad_ops->ad_path(uname, 0)) );
-    else
-#endif
-        EC_NEG1( sys_ftruncate(ad_reso_fileno(ad), size + ad->ad_eid[ ADEID_RFORK ].ade_off) );
+    /*
+     * We can't delete 0 byte size resource forks either, because a
+     * fork may reference the adouble handle with an open fd for the
+     * file, which means we would only delete the directory entry, not
+     * the file. Subsequently all code that works with fork handles
+     * finds the fork open, so eg flushing a fork (ad_flush()) will
+     * recreate ._ files.  The correct place to delete 0 byte sized
+     * resource forks is in of_closefork().
+     */
+
+    EC_NEG1( sys_ftruncate(ad_reso_fileno(ad), size + ad->ad_eid[ ADEID_RFORK ].ade_off) );
+
+    ad->ad_rlen = size;
 
 EC_CLEANUP:
-    if (ret == 0)
-        ad->ad_rlen = size;    
-    else
+    if (ret != 0)
         LOG(log_error, logtype_ad, "ad_rtruncate(\"%s\"): %s",
             fullpathname(uname), strerror(errno));
     EC_EXIT;