summaryrefslogtreecommitdiff
path: root/lib/backupclient/BackupClientFileAttributes.cpp
diff options
context:
space:
mode:
authorReinhard Tartler <siretart@tauware.de>2009-04-02 13:58:11 +0200
committerReinhard Tartler <siretart@tauware.de>2009-04-02 13:58:11 +0200
commita84d45498bd861c9225080232948a99c2e317bb8 (patch)
tree8f1f5fb7bf7ffbf6f24cf4a4fd6888a235dbcc08 /lib/backupclient/BackupClientFileAttributes.cpp
parent25db897553a0db0f912602b375029e724f51556e (diff)
Import upstream version 0.11~rc3~r2491
Diffstat (limited to 'lib/backupclient/BackupClientFileAttributes.cpp')
-rw-r--r--lib/backupclient/BackupClientFileAttributes.cpp64
1 files changed, 54 insertions, 10 deletions
diff --git a/lib/backupclient/BackupClientFileAttributes.cpp b/lib/backupclient/BackupClientFileAttributes.cpp
index 3ffeb189..bb17d41f 100644
--- a/lib/backupclient/BackupClientFileAttributes.cpp
+++ b/lib/backupclient/BackupClientFileAttributes.cpp
@@ -15,11 +15,14 @@
#include <sys/types.h>
#include <sys/stat.h>
-#include <string.h>
+#include <errno.h>
#include <limits.h>
+
#include <algorithm>
+#include <cstring>
#include <new>
#include <vector>
+
#ifdef HAVE_SYS_XATTR_H
#include <cerrno>
#include <sys/xattr.h>
@@ -299,9 +302,11 @@ void BackupClientFileAttributes::ReadAttributes(const char *Filename, bool ZeroM
StreamableMemBlock *pnewAttr = 0;
try
{
- struct stat st;
- if(::lstat(Filename, &st) != 0)
+ EMU_STRUCT_STAT st;
+ if(EMU_LSTAT(Filename, &st) != 0)
{
+ BOX_LOG_SYS_ERROR("Failed to stat file: '" <<
+ Filename << "'");
THROW_EXCEPTION(CommonException, OSFileError)
}
@@ -390,7 +395,7 @@ void BackupClientFileAttributes::ReadAttributes(const char *Filename, bool ZeroM
// Created: 2003/10/07
//
// --------------------------------------------------------------------------
-void BackupClientFileAttributes::FillAttributes(StreamableMemBlock &outputBlock, const char *Filename, struct stat &st, bool ZeroModificationTimes)
+void BackupClientFileAttributes::FillAttributes(StreamableMemBlock &outputBlock, const char *Filename, EMU_STRUCT_STAT &st, bool ZeroModificationTimes)
{
outputBlock.ResizeBlock(sizeof(attr_StreamFormat));
attr_StreamFormat *pattr = (attr_StreamFormat*)outputBlock.GetBuffer();
@@ -439,6 +444,7 @@ void BackupClientFileAttributes::FillAttributesLink(StreamableMemBlock &outputBl
int linkedToSize = ::readlink(Filename, linkedTo, PATH_MAX);
if(linkedToSize == -1)
{
+ BOX_LOG_SYS_ERROR("Failed to readlink '" << Filename << "'");
THROW_EXCEPTION(CommonException, OSFileError);
}
@@ -463,7 +469,7 @@ void BackupClientFileAttributes::FillAttributesLink(StreamableMemBlock &outputBl
void BackupClientFileAttributes::FillExtendedAttr(StreamableMemBlock &outputBlock, const char *Filename)
{
#ifdef HAVE_SYS_XATTR_H
- int listBufferSize = 1000;
+ int listBufferSize = 10000;
char* list = new char[listBufferSize];
try
@@ -529,6 +535,9 @@ void BackupClientFileAttributes::FillExtendedAttr(StreamableMemBlock &outputBloc
int valueSize = ::lgetxattr(Filename, attrKey.c_str(), 0, 0);
if(valueSize<0)
{
+ BOX_LOG_SYS_ERROR("Failed to get "
+ "extended attributes size "
+ "for '" << Filename << "'");
THROW_EXCEPTION(CommonException, OSFileError);
}
@@ -544,6 +553,9 @@ void BackupClientFileAttributes::FillExtendedAttr(StreamableMemBlock &outputBloc
valueSize = ::lgetxattr(Filename, attrKey.c_str(), buffer+xattrSize, xattrBufferSize-xattrSize);
if(valueSize<0)
{
+ BOX_LOG_SYS_ERROR("Failed to get "
+ "extended attributes for "
+ "'" << Filename << "'");
THROW_EXCEPTION(CommonException, OSFileError);
}
xattrSize += valueSize;
@@ -559,9 +571,25 @@ void BackupClientFileAttributes::FillExtendedAttr(StreamableMemBlock &outputBloc
outputBlock.ResizeBlock(xattrSize);
}
- else if(listSize<0 && errno!=EOPNOTSUPP && errno!=EACCES)
+ else if(listSize<0)
{
- THROW_EXCEPTION(CommonException, OSFileError);
+ if(errno == EOPNOTSUPP || errno == EACCES)
+ {
+ // fail silently
+ }
+ else if(errno == ERANGE)
+ {
+ BOX_ERROR("Failed to list extended "
+ "attributes of '" << Filename << "': "
+ "buffer too small, not backed up");
+ }
+ else
+ {
+ BOX_LOG_SYS_ERROR("Failed to list extended "
+ "attributes of '" << Filename << "', "
+ "not backed up");
+ THROW_EXCEPTION(CommonException, OSFileError);
+ }
}
}
catch(...)
@@ -638,6 +666,8 @@ void BackupClientFileAttributes::WriteAttributes(const char *Filename,
::unlink(Filename);
if(::symlink((char*)(pattr + 1), Filename) != 0)
{
+ BOX_LOG_SYS_ERROR("Failed to symlink '" << Filename <<
+ "' to '" << (char*)(pattr + 1) << "'");
THROW_EXCEPTION(CommonException, OSFileError)
}
#endif
@@ -655,12 +685,18 @@ void BackupClientFileAttributes::WriteAttributes(const char *Filename,
// Not a link, use normal chown
if(::chown(Filename, ntohl(pattr->UID), ntohl(pattr->GID)) != 0)
{
+ BOX_LOG_SYS_ERROR("Failed to change "
+ "owner of file "
+ "'" << Filename << "'");
THROW_EXCEPTION(CommonException, OSFileError)
}
}
#else
- if(::lchown(Filename, ntohl(pattr->UID), ntohl(pattr->GID)) != 0) // use the version which sets things on symlinks
+ // use the version which sets things on symlinks
+ if(::lchown(Filename, ntohl(pattr->UID), ntohl(pattr->GID)) != 0)
{
+ BOX_LOG_SYS_ERROR("Failed to change owner of "
+ "symbolic link '" << Filename << "'");
THROW_EXCEPTION(CommonException, OSFileError)
}
#endif
@@ -705,6 +741,8 @@ void BackupClientFileAttributes::WriteAttributes(const char *Filename,
// Try to apply
if(::utimes(Filename, times) != 0)
{
+ BOX_LOG_SYS_ERROR("Failed to change times of "
+ "file '" << Filename << "'");
THROW_EXCEPTION(CommonException, OSFileError)
}
}
@@ -715,8 +753,12 @@ void BackupClientFileAttributes::WriteAttributes(const char *Filename,
}
// Apply everything else... (allowable mode flags only)
- if(::chmod(Filename, mode & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX)) != 0) // mode must be done last (think setuid)
+ // Mode must be done last (think setuid)
+ if(::chmod(Filename, mode & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID
+ | S_ISGID | S_ISVTX)) != 0)
{
+ BOX_LOG_SYS_ERROR("Failed to change permissions of file "
+ "'" << Filename << "'");
THROW_EXCEPTION(CommonException, OSFileError)
}
}
@@ -831,6 +873,8 @@ void BackupClientFileAttributes::WriteExtendedAttr(const char *Filename, int xat
// FIXME: Warn on EOPNOTSUPP
if(::lsetxattr(Filename, key, buffer+xattrOffset, valueSize, 0)!=0 && errno!=EOPNOTSUPP)
{
+ BOX_LOG_SYS_ERROR("Failed to set extended attributes "
+ "on file '" << Filename << "'");
THROW_EXCEPTION(CommonException, OSFileError);
}
@@ -993,7 +1037,7 @@ void BackupClientFileAttributes::SetAttributeHashSecret(const void *pSecret, int
// Created: 25/4/04
//
// --------------------------------------------------------------------------
-uint64_t BackupClientFileAttributes::GenerateAttributeHash(struct stat &st, const std::string &filename, const std::string &leafname)
+uint64_t BackupClientFileAttributes::GenerateAttributeHash(EMU_STRUCT_STAT &st, const std::string &filename, const std::string &leafname)
{
if(sAttributeHashSecretLength == 0)
{