Kern Sibbald wrote:

> Please fix it up correctly, then send it to me in the same diff format versus 
> the current CVS, but please send it as an attachment to avoid the possibility 
> of word wrap.  I'll then take a look at putting it in the code.  If you send 
> it in the next few days, it will probably become part of 1.40.0 ...

I've attached 2 patches (will both apply with some offset)

patch-src-findlib-create_file.c
  Try to unset file flags of the sourcefile when the hardlink failed.
  Retry to hardlink then. If the hardlink fails then again, restore the
  file flags of the sourcefile. If the hardlink was created w/o errors,
  restore the fileflags of the sourcefile.

patch-src-findlib-attribs.c
  when restoring a symlink, use lchflags to restore the file flags
  defined for the symlink ("new feature")
  when restoring a hardlink, don't call chmod, chown, utime because it is
  a hardlink and don't  have such attributes (as far as I know, if someone
  with more FS-foo can step up and confirm this?). Changing this
  attributes will change the sourcefiles attributes which is probably not
  what is wanted here anyway....


-- 
 Oliver Lehmann
  http://www.pofo.de/
  http://wishlist.ans-netz.de/
--- ./src/findlib/attribs.c.orig	Wed Dec 13 07:18:20 2006
+++ ./src/findlib/attribs.c	Wed Dec 13 07:26:49 2006
@@ -43,6 +43,7 @@
 #define lchown chown
 #endif
 
+
 /*=============================================================*/
 /*                                                             */
 /*             ***  A l l  S y s t e m s ***                   */
@@ -346,7 +347,8 @@
     * For link, change owner of link using lchown, but don't
     *   try to do a chmod as that will update the file behind it.
     */
-   if (attr->type == FT_LNK) {
+   switch (attr->type) {
+   case FT_LNK:
       /* Change owner of link, not of real file */
       if (lchown(attr->ofname, attr->statp.st_uid, attr->statp.st_gid) < 0) {
          berrno be;
@@ -354,7 +356,25 @@
             attr->ofname, be.strerror());
          ok = false;
       }
-   } else {
+#ifdef HAVE_CHFLAGS
+      /*
+       * FreeBSD user flags
+       *
+       * Note, this should really be done before the utime() above,
+       *  but if the immutable bit is set, it will make the utimes()
+       *  fail.
+       */
+      if (lchflags(attr->ofname, attr->statp.st_flags) < 0) {
+         berrno be;
+         Jmsg2(jcr, M_ERROR, 0, _("Unable to set file flags %s: ERR=%s\n"),
+            attr->ofname, be.strerror());
+         ok = false;
+      }
+#endif
+      break;
+  case FT_LNKSAVED:
+     break;
+  default:
       if (chown(attr->ofname, attr->statp.st_uid, attr->statp.st_gid) < 0) {
          berrno be;
          Jmsg2(jcr, M_ERROR, 0, _("Unable to set file owner %s: ERR=%s\n"),
--- src/findlib/create_file.c.orig	Tue May  2 16:48:16 2006
+++ src/findlib/create_file.c	Tue Dec 12 23:58:55 2006
@@ -304,9 +304,46 @@
          Dmsg2(130, "Hard link %s => %s\n", attr->ofname, attr->olname);
          if (link(attr->olname, attr->ofname) != 0) {
             berrno be;
-            Qmsg3(jcr, M_ERROR, 0, _("Could not hard link %s -> %s: ERR=%s\n"),
-                  attr->ofname, attr->olname, be.strerror());
-            return CF_ERROR;
+#ifdef HAVE_CHFLAGS
+            struct stat s;
+
+        /*
+            * If using BSD user flags, maybe has a file flag
+            * preventing this. So attempt to disable, retry link,
+            * and reset flags.
+            * Note that BSD securelevel may prevent disabling flag.
+	*/
+
+            if (stat(attr->olname, &s) == 0 && s.st_flags != 0) {
+               if (chflags(attr->olname, 0) == 0) {
+                  if (link(attr->olname, attr->ofname) != 0) {
+                     /* restore original file flags even when linking failed */
+                     if (chflags(attr->olname, s.st_flags) < 0) {
+                        Qmsg2(jcr, M_ERROR, 0, _("Could not restore file flags for file %s: ERR=%s\n"),
+                              attr->olname, be.strerror());
+                     }
+#endif /* HAVE_CHFLAGS */
+                     Qmsg3(jcr, M_ERROR, 0, _("Could not hard link %s -> %s: ERR=%s\n"),
+                           attr->ofname, attr->olname, be.strerror());
+                     return CF_ERROR;
+#ifdef HAVE_CHFLAGS
+                  }
+                  /* finally restore original file flags */
+                  if (chflags(attr->olname, s.st_flags) < 0) {
+                     Qmsg2(jcr, M_ERROR, 0, _("Could not restore file flags for file %s: ERR=%s\n"),
+                            attr->olname, be.strerror());
+                  }
+               } else {
+                 Qmsg2(jcr, M_ERROR, 0, _("Could not reset file flags for file %s: ERR=%s\n"),
+                       attr->olname, be.strerror());
+               }
+            } else {
+              Qmsg3(jcr, M_ERROR, 0, _("Could not hard link %s -> %s: ERR=%s\n"),
+                    attr->ofname, attr->olname, be.strerror());
+              return CF_ERROR;
+            }
+#endif /* HAVE_CHFLAGS */
+
          }
          return CF_CREATED;
 #endif
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users

Reply via email to