]> arthur.barton.de Git - netatalk.git/commitdiff
Fix copyfile
authorFrank Lahm <franklahm@googlemail.com>
Wed, 25 Jan 2012 12:02:18 +0000 (13:02 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Wed, 25 Jan 2012 12:02:18 +0000 (13:02 +0100)
etc/afpd/file.c

index 51de7562330399b5545d6f6d20034d8ef9da4ceb..faabbf631dcb68c2fdcded05c2e624c1f1827a70 100644 (file)
@@ -1381,7 +1381,8 @@ static int copy_fork(int eid, struct adouble *add, struct adouble *ads)
     int     err = 0;
     char    filebuf[8192];
     int     sfd, dfd;
-    
+    off_t   soff, doff;
+
     if (eid == ADEID_DFORK) {
         sfd = ad_data_fileno(ads);
         dfd = ad_data_fileno(add);
@@ -1391,10 +1392,24 @@ static int copy_fork(int eid, struct adouble *add, struct adouble *ads)
         dfd = ad_reso_fileno(add);
     }        
 
-    if ((off_t)-1 == lseek(sfd, ad_getentryoff(ads, eid), SEEK_SET))
+    if (add->ad_version == AD_VERSION2)
+        soff = doff = ad_getentryoff(ads, eid);
+    else {
+        if (eid == ADEID_DFORK)
+            soff = doff = ad_getentryoff(ads, eid);
+        else {
+#ifdef HAVE_EAFD
+            soff = doff = 0;
+#else
+            soff = doff = ADEDOFF_RFORK_OSX;
+#endif
+        }
+    }
+
+    if ((off_t)-1 == lseek(sfd, soff, SEEK_SET))
        return -1;
 
-    if ((off_t)-1 == lseek(dfd, ad_getentryoff(add, eid), SEEK_SET))
+    if ((off_t)-1 == lseek(dfd, doff, SEEK_SET))
        return -1;
        
 #if 0 /* ifdef SENDFILE_FLAVOR_LINUX */
@@ -1469,7 +1484,7 @@ int copyfile(const struct vol *s_vol,
         adp = &ads;
     }
 
-    adflags = ADFLAGS_DF;
+    adflags = ADFLAGS_DF | ADFLAGS_RF | ADFLAGS_NORF;
     if (newname) {
         adflags |= ADFLAGS_HF;
     }
@@ -1479,10 +1494,9 @@ int copyfile(const struct vol *s_vol,
         goto done;
     }
 
-    if (ad_meta_fileno(adp) == -1 && ad_reso_fileno(adp) == -1) { /* META / HF */
+    if (!AD_RSRC_OPEN(adp))
         /* no resource fork, don't create one for dst file */
-        adflags &= ~ADFLAGS_HF;
-    }
+        adflags &= ~ADFLAGS_RF;
 
     stat_result = fstat(ad_data_fileno(adp), &st); /* saving stat exit code, thus saving us on one more stat later on */
 
@@ -1501,21 +1515,15 @@ int copyfile(const struct vol *s_vol,
         }
         return AFPERR_EXIST;
     }
+
+    if (AD_RSRC_OPEN(adp))
+        err = copy_fork(ADEID_RFORK, &add, adp);
     
-    /*
-     * XXX if the source and the dest don't use the same resource type it's broken
-     */
-    if (ad_reso_fileno(adp) == -1 || 0 == (err = copy_fork(ADEID_RFORK, &add, adp))){
-        /* copy the data fork */
-        if ((err = copy_fork(ADEID_DFORK, &add, adp)) == 0) {
-            if (ad_meta_fileno(adp) != -1)
-                err = d_vol->vfs->vfs_copyfile(d_vol, sfd, src, dst);
-        }
-    }
+    if (err == 0)
+        err = copy_fork(ADEID_DFORK, &add, adp);
 
-    if (err < 0) {
+    if (err < 0)
        ret_err = errno;
-    }
 
     if (!ret_err && newname && (adflags & ADFLAGS_HF)) {
         /* set the new name in the resource fork */