]> arthur.barton.de Git - netatalk.git/commitdiff
Move existing AppleDesktop folders to localstatedir
authorFrank Lahm <franklahm@googlemail.com>
Tue, 17 Apr 2012 10:42:28 +0000 (12:42 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Tue, 17 Apr 2012 10:42:28 +0000 (12:42 +0200)
etc/afpd/desktop.c

index 8ba1d1511d36dbd7efb2036ce0c22357bc278b0a..6019150360f4d8a56a6bff4ce1108e1eabab3e4e 100644 (file)
 
 static void create_appledesktop_folder(const struct vol * vol)
 {
-    bstring dtpath;
+    bstring olddtpath = NULL, dtpath = NULL;
     struct stat st;
+    char *cmd_argv[4];
+
+    olddtpath = bfromcstr(vol->v_path);
+    bcatcstr(olddtpath, "/" APPLEDESKTOP);
 
     dtpath = bfromcstr(vol->v_dbpath);
     bcatcstr(dtpath, "/" APPLEDESKTOP);
 
-    if (stat(bdata(dtpath), &st) != 0) {
+    if (lstat(bdata(dtpath), &st) != 0) {
+
         become_root();
-        mkdir(bdata(dtpath), 0777);
+
+        if (lstat(bdata(olddtpath), &st) == 0) {
+            cmd_argv[0] = "mv";
+            cmd_argv[1] = bdata(olddtpath);
+            cmd_argv[2] = bdata(dtpath);
+            cmd_argv[3] = NULL;
+            if (run_cmd("mv", cmd_argv) != 0) {
+                LOG(log_error, logtype_afpd, "moving .AppleDesktop from \"%s\" to \"%s\" failed",
+                    bdata(olddtpath), bdata(dtpath));
+                mkdir(bdata(dtpath), 0777);
+            }
+        } else {
+            mkdir(bdata(dtpath), 0777);
+        }
+
         unbecome_root();
     }
 
     bdestroy(dtpath);
+    bdestroy(olddtpath);
 }
 
 int afp_opendt(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)