On Sunday 24 February 2008, Stroller wrote:

> I've done this loads in the past, and never been aware of any file
> corruption, but I guess I'm just paranoid today. Perhaps I shouldn't
> use the -v flags during my copy - it's reassuring to see the files
> being copied, but what if I overlooked a bunch of errors in the
> middle of all those thousands of "copied successfully" confirmations?
> What if something has gone wrong during one of the two copies?

Well, in that case cp will have a nnonzero exit status. Look:

$ ls -l
total 12
-rw-r--r-- 1 kermit users    4 2008-02-24 12:30 a
-rw-r--r-- 1 kermit users   12 2008-02-24 12:30 b
drwxr-xr-x 2 kermit users 4096 2008-02-24 12:30 destdir
$ ls -l destdir
total 0
$ chmod 000 b
$ ls -l
total 12
-rw-r--r-- 1 kermit users    4 2008-02-24 12:30 a
---------- 1 kermit users   12 2008-02-24 12:30 b
drwxr-xr-x 2 kermit users 4096 2008-02-24 12:30 destdir
$ cp a b destdir
cp: cannot open `b' for reading: Permission denied
$ echo $?
1
$ ls -l destdir
total 4
-rw-r--r-- 1 kermit users 4 2008-02-24 12:31 a

I think this should hold for the majority of cases/errors cp might 
encounter during the copy.
Of course, this does not detect a succesful, but somehow corrupted, copy 
(which should be exceptionally rare, anyway).

> So my question is:
>
> Is there any way to check the integrity of copied directories, to be
> sure that none of the files or sub-directories in them have become
> damaged during transfer? I'm thinking of something like md5sum for
> directories.

I'm not aware of any such tool (which might exist nonetheless, of 
course). However, on the filesystem, the objects that we 
call "directories" are just index files holding filenames and pointers 
to inodes. Running a checksum on the directories themselves would not 
guarantee against corruption of any of the contained files, since file 
data is not contained in the directory. Thus, to be accurate, such a 
tool would have to scan the directory, find each file, and perform a 
checksum on it, which would result in something not much different from 
the find command you suggested, in terms of resource usage.
-- 
gentoo-user@lists.gentoo.org mailing list

Reply via email to