Fixed a couple minor problems in util.c:
authorWayne Davison <wayned@samba.org>
Sat, 2 Aug 2008 01:04:24 +0000 (18:04 -0700)
committerWayne Davison <wayned@samba.org>
Sat, 2 Aug 2008 01:04:24 +0000 (18:04 -0700)
- Make sure that handle_partial_dir() never returns a truncated fname.
- Make robust_rename() return that it failed to do a cross-device
  copy if the partial-dir could not be created.

util.c

diff --git a/util.c b/util.c
index 0af7259..4b6c11f 100644 (file)
--- a/util.c
+++ b/util.c
@@ -436,7 +436,7 @@ int robust_rename(const char *from, const char *to, const char *partialptr,
                case EXDEV:
                        if (partialptr) {
                                if (!handle_partial_dir(partialptr,PDIR_CREATE))
-                                       return -1;
+                                       return -2;
                                to = partialptr;
                        }
                        if (copy_file(from, to, -1, mode, 0) != 0)
@@ -1111,12 +1111,16 @@ int handle_partial_dir(const char *fname, int create)
                STRUCT_STAT st;
                int statret = do_lstat(dir, &st);
                if (statret == 0 && !S_ISDIR(st.st_mode)) {
-                       if (do_unlink(dir) < 0)
+                       if (do_unlink(dir) < 0) {
+                               *fn = '/';
                                return 0;
+                       }
                        statret = -1;
                }
-               if (statret < 0 && do_mkdir(dir, 0700) < 0)
+               if (statret < 0 && do_mkdir(dir, 0700) < 0) {
+                       *fn = '/';
                        return 0;
+               }
        } else
                do_rmdir(dir);
        *fn = '/';