]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cp --sparse=always sparse-image-file.img /dev/hda1 could
authorJim Meyering <jim@meyering.net>
Sat, 6 Mar 2004 17:40:56 +0000 (17:40 +0000)
committerJim Meyering <jim@meyering.net>
Sat, 6 Mar 2004 17:40:56 +0000 (17:40 +0000)
produce an invalid copy on the destination device.

(copy_reg): Even with --sparse=always, try to
make `holes' only if the destination is a regular file.
Reported by Szakacsits Szabolcs.

src/copy.c

index b38b535ae863d49f34d79ec31c2e4b7aa8334de5..8685234e5ebbc3e665e8c1dc3c89ae0546870996 100644 (file)
@@ -214,7 +214,7 @@ copy_reg (const char *src_path, const char *dst_path,
   int return_val = 0;
   off_t n_read_total = 0;
   int last_write_made_hole = 0;
-  int make_holes = (x->sparse_mode == SPARSE_ALWAYS);
+  int make_holes = 0;
 
   source_desc = open (src_path, O_RDONLY);
   if (source_desc < 0)
@@ -286,6 +286,11 @@ copy_reg (const char *src_path, const char *dst_path,
 
   buf_size = ST_BLKSIZE (sb);
 
+  /* Even with --sparse=always, try to create holes only
+     if the destination is a regular file.  */
+  if (x->sparse_mode == SPARSE_ALWAYS && S_ISREG (sb.st_mode))
+    make_holes = 1;
+
 #if HAVE_STRUCT_STAT_ST_BLOCKS
   if (x->sparse_mode == SPARSE_AUTO && S_ISREG (sb.st_mode))
     {