]> git.wh0rd.org - dump.git/blobdiff - restore/utilities.c
Fix a small bug on an error path introduced by the hashtree patch.
[dump.git] / restore / utilities.c
index e96dcf319fd97d70251005edc8a1539bba79edaf..f17bd9ce458a7214ab50050f787c794d79a033a1 100644 (file)
@@ -37,7 +37,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: utilities.c,v 1.25 2004/12/14 14:07:58 stelian Exp $";
+       "$Id: utilities.c,v 1.28 2005/03/30 13:21:45 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -269,10 +269,10 @@ linkit(char *existing, char *new, int type)
                         */
 #ifdef sunos
 #else
-                       if (fgetflags (existing, &s) != -1 &&
-                           fsetflags (existing, 0) != -1) {
+                       if (lgetflags (existing, &s) != -1 &&
+                           lsetflags (existing, 0) != -1) {
                                ret = link(existing, new);
-                               fsetflags(existing, s);
+                               lsetflags(existing, s);
                        }
 #endif
 #endif
@@ -380,7 +380,7 @@ badentry(struct entry *ep, const char *msg)
                int i;
                for (i = 0; i < DIRHASH_SIZE; i++) {
                        if (ep->e_entries[i] != NULL) {
-                               fprintf(stderr, "next entry name: %s\n", myname(ep->e_entries[0]));
+                               fprintf(stderr, "next entry name: %s\n", myname(ep->e_entries[i]));
                                break;
                        }
                }
@@ -487,8 +487,10 @@ panic(fmt, va_alist)
        if (yflag)
                return;
        if (reply("abort") == GOOD) {
-               if (reply("dump core") == GOOD)
+               if (reply("dump core") == GOOD) {
+                       fchdir(wdfd);
                        abort();
+               }
                exit(1);
        }
 }
@@ -724,9 +726,46 @@ CreateAppleDoubleFileRes(char *oFile, FndrFileInfo *finderinfo, mode_t mode, int
        (void)fchown(fdout, uid, gid);
        (void)fchmod(fdout, mode);
        close(fdout);
-       (void)fsetflags(oFile, flags);
+       (void)lsetflags(oFile, flags);
        utimes(oFile, timep);
        free(pp);
        return err;
 }
 #endif /* DUMP_MACOSX */
+
+int
+lgetflags(const char *path, unsigned long *flags)
+{
+       int err;
+       struct STAT sb;
+
+       err = LSTAT(path, &sb);
+       if (err < 0)
+               return err;
+
+       if (S_ISLNK(sb.st_mode) || S_ISFIFO(sb.st_mode)) {
+               // no way to get/set flags on a symlink
+               *flags = 0;
+               return 0;
+       }
+       else
+               return fgetflags(path, flags);
+}
+
+int
+lsetflags(const char *path, unsigned long flags)
+{
+       int err;
+       struct STAT sb;
+
+       err = LSTAT(path, &sb);
+       if (err < 0)
+               return err;
+
+       if (S_ISLNK(sb.st_mode) || S_ISFIFO(sb.st_mode)) {
+               // no way to get/set flags on a symlink
+               return 0;
+       }
+       else
+               return fsetflags(path, flags);
+}