]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/findlib/create_file.c
dhb left console.cpp uncompileable. Modified a comment in mainwin.cpp
[bacula/bacula] / bacula / src / findlib / create_file.c
index 7460549b553db91c76b43e950a2467970a45c7d4..0cbf644fda9242572edfd2fe8c38f2e187389f92 100644 (file)
@@ -1,3 +1,30 @@
+/*
+   Bacula® - The Network Backup Solution
+
+   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+
+   The main author of Bacula is Kern Sibbald, with contributions from
+   many others, a complete list can be found in the file AUTHORS.
+   This program is Free Software; you can redistribute it and/or
+   modify it under the terms of version two of the GNU General Public
+   License as published by the Free Software Foundation plus additions
+   that are listed in the file LICENSE.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+   Bacula® is a registered trademark of John Walker.
+   The licensor of Bacula is the Free Software Foundation Europe
+   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+   Switzerland, email:ftf@fsfeurope.org.
+*/
 /*
  *  Create a file, and reset the modes
  *
@@ -6,20 +33,6 @@
  *   Version $Id$
  *
  */
-/*
-   Copyright (C) 2000-2006 Kern Sibbald
-
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as amended with additional clauses defined in the
-   file LICENSE in the main source directory.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
-   the file LICENSE for additional details.
-
- */
 
 #include "bacula.h"
 #include "find.h"
@@ -222,7 +235,7 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
                      attr->ofname, be.strerror());
                return CF_ERROR;
             }
-         } else if(S_ISSOCK(attr->statp.st_mode)) {
+         } else if (S_ISSOCK(attr->statp.st_mode)) {
              Dmsg1(200, "Skipping restore of socket: %s\n", attr->ofname);
          } else {
             Dmsg1(200, "Restore node: %s\n", attr->ofname);
@@ -276,9 +289,46 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
          Dmsg2(130, "Hard link %s => %s\n", attr->ofname, attr->olname);
          if (link(attr->olname, attr->ofname) != 0) {
             berrno be;
+#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