summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorvandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-29 19:58:36 +0000
committervandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-29 19:58:36 +0000
commit6624b46283f1974b8ea3d3b149763b3dd612359d (patch)
treea54ba22b3117fc2c6bcf709bcf9866d21b42ce45 /base
parent1683e11834b15dbd4e0e8161a9ed036d78a8d4d7 (diff)
downloadchromium_src-6624b46283f1974b8ea3d3b149763b3dd612359d.zip
chromium_src-6624b46283f1974b8ea3d3b149763b3dd612359d.tar.gz
chromium_src-6624b46283f1974b8ea3d3b149763b3dd612359d.tar.bz2
Report unreadable files as size zero when uploading.
Upload zero bytes if the file size shrinks. BUG=30850 TEST=uploading an unreadable file works Review URL: http://codereview.chromium.org/1250002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42981 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/file_util.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/base/file_util.h b/base/file_util.h
index fdc13ee..2e509bb 100644
--- a/base/file_util.h
+++ b/base/file_util.h
@@ -12,6 +12,9 @@
#if defined(OS_WIN)
#include <windows.h>
+#if defined(UNIT_TEST)
+#include <aclapi.h>
+#endif
#elif defined(OS_POSIX)
#include <sys/stat.h>
#endif
@@ -502,6 +505,57 @@ bool RenameFileAndResetSecurityDescriptor(
bool HasFileBeenModifiedSince(const FileEnumerator::FindInfo& find_info,
const base::Time& cutoff_time);
+#ifdef UNIT_TEST
+
+inline bool MakeFileUnreadable(const FilePath& path) {
+#if defined(OS_POSIX)
+ struct stat stat_buf;
+ if (stat(path.value().c_str(), &stat_buf) != 0)
+ return false;
+ stat_buf.st_mode &= ~(S_IRUSR | S_IRGRP | S_IROTH);
+
+ return chmod(path.value().c_str(), stat_buf.st_mode) == 0;
+
+#elif defined(OS_WIN)
+ PACL old_dacl;
+ PSECURITY_DESCRIPTOR security_descriptor;
+ if (GetNamedSecurityInfo(path.value().c_str(), SE_FILE_OBJECT,
+ DACL_SECURITY_INFORMATION, NULL, NULL, &old_dacl,
+ NULL, &security_descriptor) != ERROR_SUCCESS)
+ return false;
+
+ // Deny Read access for the current user.
+ EXPLICIT_ACCESS change;
+ change.grfAccessPermissions = GENERIC_READ;
+ change.grfAccessMode = DENY_ACCESS;
+ change.grfInheritance = 0;
+ change.Trustee.pMultipleTrustee = NULL;
+ change.Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
+ change.Trustee.TrusteeForm = TRUSTEE_IS_NAME;
+ change.Trustee.TrusteeType = TRUSTEE_IS_USER;
+ change.Trustee.ptstrName = L"CURRENT_USER";
+
+ PACL new_dacl;
+ if (SetEntriesInAcl(1, &change, old_dacl, &new_dacl) != ERROR_SUCCESS) {
+ LocalFree(security_descriptor);
+ return false;
+ }
+
+ DWORD rc = SetNamedSecurityInfo(const_cast<wchar_t*>(path.value().c_str()),
+ SE_FILE_OBJECT, DACL_SECURITY_INFORMATION,
+ NULL, NULL, new_dacl, NULL);
+ LocalFree(security_descriptor);
+ LocalFree(new_dacl);
+
+ return rc == ERROR_SUCCESS;
+#else
+ NOTIMPLEMENTED();
+ return false;
+#endif
+}
+
+#endif // UNIT_TEST
+
} // namespace file_util
// Deprecated functions have been moved to this separate header file,