[Bug 2758] New: "File exists" error using options -b and --backup-dir with device files.

samba-bugs at samba.org samba-bugs at samba.org
Tue May 31 19:54:45 GMT 2005


https://bugzilla.samba.org/show_bug.cgi?id=2758

           Summary: "File exists" error using options -b and --backup-dir
                    with device files.
           Product: rsync
           Version: 2.6.4
          Platform: All
        OS/Version: AIX
            Status: NEW
          Severity: normal
          Priority: P3
         Component: core
        AssignedTo: wayned at samba.org
        ReportedBy: jonathan.townsend at telus.com
         QAContact: rsync-qa at samba.org


Problem:

rsync does not check for exisitence of device file (in backup-dir) before trying
to recreate it with mknod using options -b and --backup-dir. Backups all have
the following errors when device files are updated

rsync: mknod "/dev/pts/111" failed: File exists (17)
rsync error: some files could not be transferred (code 23) at main.c(789)


Test Script:

#!/usr/bin/ksh
# 
# Test rsync backup of device files
#

ROOT=/tmp/rsync_mknod
[[ -d $ROOT ]] || mkdir $ROOT

cd $ROOT

# Create test dirs
for x in src dst backup; do
  [[ -d $x ]] || mkdir $x
  [[ -e $x/nod ]] && rm $x/nod
  [[ -e $x/src/nod ]] && rm $x/src/nod
done

# Create test device file
mknod $ROOT/src/nod c 255 255
chmod 666 $ROOT/src/nod

# Initial rsync
rsync -a -b --backup-dir=$ROOT/backup $ROOT/src $ROOT/dst

# Update file causing backup to be made
chmod 440 $ROOT/src/nod
rsync -a -b --backup-dir=$ROOT/backup $ROOT/src $ROOT/dst

# Update file again, this rsync should have the error
chmod 666 $ROOT/src/nod
rsync -a -b --backup-dir=$ROOT/backup $ROOT/src $ROOT/dst


Patch: 

* only removes file if it was already a device file

--- backup.c.gen        Mon Feb 21 17:57:58 2005
+++ backup.c    Tue May 31 11:33:30 2005
@@ -171,7 +171,7 @@
  * We will move the file to be deleted into a parallel directory tree. */
 static int keep_backup(char *fname)
 {
-       STRUCT_STAT st;
+       STRUCT_STAT st, bufst;
        struct file_struct *file;
        char *buf;
        int kept = 0;
@@ -190,6 +190,12 @@
        /* Check to see if this is a device file, or link */
        if (IS_DEVICE(file->mode)) {
                if (am_root && preserve_devices) {
+                       /* delete backup_dir destination device if it exists */
+                       if (do_stat(buf, &bufst) == 0 && IS_DEVICE(bufst.st_mode)) {
+                               if (do_unlink(buf) < 0)
+                                       rsyserr(FERROR, errno, "unlink %s failed",
+                                               full_fname(buf));
+                       }
                        if (do_mknod(buf, file->mode, file->u.rdev) < 0
                            && (errno != ENOENT || make_bak_dir(buf) < 0
                             || do_mknod(buf, file->mode, file->u.rdev) < 0)) {

-- 
Configure bugmail: https://bugzilla.samba.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug, or are watching the QA contact.


More information about the rsync mailing list