From fb08c7f95b37da9e0b0a581236cd788f9abdee3f Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 14 Oct 2006 14:07:37 +0000 Subject: * Use readdir's d_type field to determine type of directory entry without statting the entry, which allows users to exclude unreadable entries to suppress warnings about them on Win32 (refs #3) --- bin/bbackupd/BackupClientDirectoryRecord.cpp | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'bin/bbackupd/BackupClientDirectoryRecord.cpp') diff --git a/bin/bbackupd/BackupClientDirectoryRecord.cpp b/bin/bbackupd/BackupClientDirectoryRecord.cpp index d9b11ee4..1db6cbe5 100644 --- a/bin/bbackupd/BackupClientDirectoryRecord.cpp +++ b/bin/bbackupd/BackupClientDirectoryRecord.cpp @@ -236,6 +236,18 @@ void BackupClientDirectoryRecord::SyncDirectory(BackupClientDirectoryRecord::Syn // Stat file to get info filename = MakeFullPath(rLocalPath, en->d_name); + #ifdef WIN32 + // Don't stat the file just yet, to ensure + // that users can exclude unreadable files + // to suppress warnings that they are + // not accessible. + // + // Our emulated readdir() abuses en->d_type, + // which would normally contain DT_REG, + // DT_DIR, etc, but we only use it here and + // prefer S_IFREG, S_IFDIR... + int type = en->d_type; + #else if(::lstat(filename.c_str(), &st) != 0) { // Report the error (logs and @@ -248,6 +260,8 @@ void BackupClientDirectoryRecord::SyncDirectory(BackupClientDirectoryRecord::Syn } int type = st.st_mode & S_IFMT; + #endif + if(type == S_IFREG || type == S_IFLNK) { // File or symbolic link @@ -278,11 +292,34 @@ void BackupClientDirectoryRecord::SyncDirectory(BackupClientDirectoryRecord::Syn } else { + #ifdef WIN32 + ::syslog(LOG_ERR, "Unknown file type: " + "%d (%s)", type, + filename.c_str()); + #endif + SetErrorWhenReadingFilesystemObject( + rParams, filename.c_str()); continue; } // Here if the object is something to back up (file, symlink or dir, not excluded) // So make the information for adding to the checksum + + #ifdef WIN32 + // We didn't stat the file before, + // but now we need the information. + if(::lstat(filename.c_str(), &st) != 0) + { + // Report the error (logs and + // eventual email to administrator) + SetErrorWhenReadingFilesystemObject( + rParams, filename.c_str()); + + // Ignore this entry for now. + continue; + } + #endif + checksum_info.mModificationTime = FileModificationTime(st); checksum_info.mAttributeModificationTime = FileAttrModificationTime(st); checksum_info.mSize = st.st_size; -- cgit v1.2.3