From c98c2b560b3d890aa585daad0fd80136674e9bb6 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Tue, 21 Oct 2008 20:25:33 +0000 Subject: Report the filename that failed when various file attribute syscalls fail, for example setting, listing or reading extended attributes, or creating or changing the owner of a symlink. Thanks to Torsten for noticing that the filename was not reported in these cases. --- lib/backupclient/BackupClientFileAttributes.cpp | 41 ++++++++++++++++++++----- 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupClientFileAttributes.cpp b/lib/backupclient/BackupClientFileAttributes.cpp index ee8f94b0..56c64c6b 100644 --- a/lib/backupclient/BackupClientFileAttributes.cpp +++ b/lib/backupclient/BackupClientFileAttributes.cpp @@ -304,6 +304,8 @@ void BackupClientFileAttributes::ReadAttributes(const char *Filename, bool ZeroM struct stat st; if(::lstat(Filename, &st) != 0) { + BOX_LOG_SYS_ERROR("Failed to stat file: '" << + Filename << "'"); THROW_EXCEPTION(CommonException, OSFileError) } @@ -441,6 +443,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); } @@ -531,6 +534,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); } @@ -546,6 +552,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; @@ -569,15 +578,15 @@ void BackupClientFileAttributes::FillExtendedAttr(StreamableMemBlock &outputBloc } else if(errno == ERANGE) { - BOX_ERROR("Failed to read extended " - "attributes of " << Filename << - ": buffer too small, not backed up"); + BOX_ERROR("Failed to list extended " + "attributes of '" << Filename << "': " + "buffer too small, not backed up"); } else { - BOX_LOG_SYS_ERROR("Failed to read extended " - "attributes of " << Filename << - ", not backed up"); + BOX_LOG_SYS_ERROR("Failed to list extended " + "attributes of '" << Filename << "', " + "not backed up"); THROW_EXCEPTION(CommonException, OSFileError); } } @@ -656,6 +665,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 @@ -673,12 +684,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 @@ -723,6 +740,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) } } @@ -733,8 +752,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) } } @@ -849,6 +872,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); } -- cgit v1.2.3