chiark / gitweb /
disorderfm preserves permissions now
authorRichard Kettlewell <rjk@greenend.org.uk>
Tue, 30 Dec 2008 19:32:49 +0000 (19:32 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Tue, 30 Dec 2008 19:32:49 +0000 (19:32 +0000)
CHANGES.html
clients/disorderfm.c

index 98149aa7488bc53e2cef643687db7263c329844c..c4cbe1e043d6fc15e938c6d95ce306445f16e611 100644 (file)
@@ -93,10 +93,12 @@ span.command {
 
       </div>
 
 
       </div>
 
-    <h3>General</h3>
+    <h3>Miscellaneous</h3>
 
       <div class=section>
 
 
       <div class=section>
 
+        <p><tt>disorderfm</tt> now preserves directory permissions.</p>
+
         <p>DisOrder is now licensed under <a
          href="http://www.gnu.org/licenses/gpl-3.0.html">GPL v3</a>.  The main
         goal is to prohibit <a
         <p>DisOrder is now licensed under <a
          href="http://www.gnu.org/licenses/gpl-3.0.html">GPL v3</a>.  The main
         goal is to prohibit <a
index 07743f88aaf6a9b45b89d9307704a22bcfbb00b7..241b701b7f2e046c1dae102b7ff60972436a3b2b 100644 (file)
@@ -136,6 +136,7 @@ static int copy(const char *from, const char *to) {
   int fdin, fdout;
   char buffer[4096];
   int n;
   int fdin, fdout;
   char buffer[4096];
   int n;
+  struct stat sb;
 
   if((fdin = open(from, O_RDONLY)) < 0)
     fatal(errno, "error opening %s", from);
 
   if((fdin = open(from, O_RDONLY)) < 0)
     fatal(errno, "error opening %s", from);
@@ -146,6 +147,12 @@ static int copy(const char *from, const char *to) {
       fatal(errno, "error writing to %s", to);
   }
   if(n < 0) fatal(errno, "error reading %s", from);
       fatal(errno, "error writing to %s", to);
   }
   if(n < 0) fatal(errno, "error reading %s", from);
+  if(fstat(fdin, &sb) < 0)
+    fatal(errno, "error stating %s", from);
+  if(fchown(fdout, sb.st_uid, sb.st_gid) < 0)
+    fatal(errno, "error chowning %s", from);
+  if(fchmod(fdout, sb.st_mode & 07777) < 0)
+    fatal(errno, "error chmoding %s", from);
   if(close(fdout) < 0) fatal(errno, "error closing %s", to);
   xclose(fdin);
   return 0;
   if(close(fdout) < 0) fatal(errno, "error closing %s", to);
   xclose(fdin);
   return 0;
@@ -310,7 +317,20 @@ static void visit(const char *path, const char *destpath) {
   
     /* We create the directory on the destination side.  If it already exists,
      * that's fine. */
   
     /* We create the directory on the destination side.  If it already exists,
      * that's fine. */
-    if(dirmaker(fulldestpath, 0777) < 0 && errno != EEXIST) {
+    if(dirmaker(fulldestpath, 0700) == 0) {
+      if(dirmaker != nomkdir) {
+        /* Created new directory.  Adjust permissions and ownership to match the
+         * old one. */
+        if(chown(fulldestpath, sb.st_uid, sb.st_gid) < 0) {
+          error(errno, "cannot chown %s", errdestpath);
+          ++errors;
+        }
+        if(chmod(fulldestpath, sb.st_mode & 07777) < 0) {
+          error(errno, "cannot chmod %s", errdestpath);
+          ++errors;
+        }
+      }
+    } else if(errno != EEXIST) {
       error(errno, "cannot mkdir %s", errdestpath);
       ++errors;
       return;
       error(errno, "cannot mkdir %s", errdestpath);
       ++errors;
       return;