[Pkg-shadow-commits] r1522 - upstream/trunk/libmisc

nekral-guest at alioth.debian.org nekral-guest at alioth.debian.org
Fri Dec 28 00:23:33 UTC 2007


Author: nekral-guest
Date: 2007-12-28 00:23:33 +0000 (Fri, 28 Dec 2007)
New Revision: 1522

Modified:
   upstream/trunk/libmisc/copydir.c
Log:
Other cleanups and documentation.
Do the checks, then build the filenames. Do not mix both.


Modified: upstream/trunk/libmisc/copydir.c
===================================================================
--- upstream/trunk/libmisc/copydir.c	2007-12-28 00:08:16 UTC (rev 1521)
+++ upstream/trunk/libmisc/copydir.c	2007-12-28 00:23:33 UTC (rev 1522)
@@ -109,7 +109,7 @@
 #endif
 
 /*
- * remove_link - delete a link from the link list
+ * remove_link - delete a link from the linked list
  */
 static void remove_link (struct link_name *ln)
 {
@@ -218,38 +218,33 @@
 		set_orig++;
 	}
 	while ((0 == err) && (ent = readdir (dir)) != NULL) {
-
 		/*
 		 * Skip the "." and ".." entries
 		 */
+		if ((strcmp (ent->d_name, ".") != 0) &&
+		    (strcmp (ent->d_name, "..") != 0)) {
+			/*
+			 * Make sure the resulting source and destination
+			 * filenames will fit in their buffers.
+			 */
+			if (   (strlen (src_root) + strlen (ent->d_name) + 2 >
+			        sizeof src_name)
+			    || (strlen (dst_root) + strlen (ent->d_name) + 2 >
+			        sizeof dst_name)) {
+				err = -1;
+			} else {
+				/*
+				 * Build the filename for both the source and
+				 * the destination files.
+				 */
+				snprintf (src_name, sizeof src_name, "%s/%s",
+				          src_root, ent->d_name);
+				snprintf (dst_name, sizeof dst_name, "%s/%s",
+				          dst_root, ent->d_name);
 
-		if (strcmp (ent->d_name, ".") == 0 ||
-		    strcmp (ent->d_name, "..") == 0) {
-			continue;
+				err = copy_entry (src_name, dst_name, uid, gid);
+			}
 		}
-
-		/*
-		 * Make the filename for both the source and the
-		 * destination files.
-		 */
-
-		if (strlen (src_root) + strlen (ent->d_name) + 2 >
-		    sizeof src_name) {
-			err = -1;
-			break;
-		}
-		snprintf (src_name, sizeof src_name, "%s/%s", src_root,
-			  ent->d_name);
-
-		if (strlen (dst_root) + strlen (ent->d_name) + 2 >
-		    sizeof dst_name) {
-			err = -1;
-			break;
-		}
-		snprintf (dst_name, sizeof dst_name, "%s/%s", dst_root,
-			  ent->d_name);
-
-		err = copy_entry (src_name, dst_name, uid, gid);
 	}
 	closedir (dir);
 
@@ -389,8 +384,8 @@
 #endif
 	if (   (symlink (oldlink, dst) != 0)
 	    || (lchown (dst,
-	                uid == (uid_t) - 1 ? statp->st_uid : uid,
-	                gid == (gid_t) - 1 ? statp->st_gid : gid) != 0)) {
+	                (uid == (uid_t) - 1) ? statp->st_uid : uid,
+	                (gid == (gid_t) - 1) ? statp->st_gid : gid) != 0)) {
 		return -1;
 	}
 
@@ -417,6 +412,8 @@
 		return -1;
 	}
 
+	/* If the file could be unlinked, decrement the links counter,
+	 * and delete the file if it was the last reference */
 	lp->ln_count--;
 	if (lp->ln_count <= 0) {
 		remove_link (lp);




More information about the Pkg-shadow-commits mailing list