OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_TEST_TEST_FILE_UTIL_H_ | 5 #ifndef BASE_TEST_TEST_FILE_UTIL_H_ |
6 #define BASE_TEST_TEST_FILE_UTIL_H_ | 6 #define BASE_TEST_TEST_FILE_UTIL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 // File utility functions used only by tests. | 9 // File utility functions used only by tests. |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/file_path.h" |
14 | 15 |
15 class FilePath; | 16 class FilePath; |
16 | 17 |
17 namespace file_util { | 18 namespace file_util { |
18 | 19 |
19 // Wrapper over file_util::Delete. On Windows repeatedly invokes Delete in case | 20 // Wrapper over file_util::Delete. On Windows repeatedly invokes Delete in case |
20 // of failure to workaround Windows file locking semantics. Returns true on | 21 // of failure to workaround Windows file locking semantics. Returns true on |
21 // success. | 22 // success. |
22 bool DieFileDie(const FilePath& file, bool recurse); | 23 bool DieFileDie(const FilePath& file, bool recurse); |
23 | 24 |
(...skipping 25 matching lines...) Expand all Loading... |
49 // string16 elsewhere for Unicode strings, but in tests it is frequently | 50 // string16 elsewhere for Unicode strings, but in tests it is frequently |
50 // convenient to be able to compare paths to literals like L"foobar". | 51 // convenient to be able to compare paths to literals like L"foobar". |
51 std::wstring FilePathAsWString(const FilePath& path); | 52 std::wstring FilePathAsWString(const FilePath& path); |
52 FilePath WStringAsFilePath(const std::wstring& path); | 53 FilePath WStringAsFilePath(const std::wstring& path); |
53 | 54 |
54 // For testing, make the file unreadable or unwritable. | 55 // For testing, make the file unreadable or unwritable. |
55 // In POSIX, this does not apply to the root user. | 56 // In POSIX, this does not apply to the root user. |
56 bool MakeFileUnreadable(const FilePath& path) WARN_UNUSED_RESULT; | 57 bool MakeFileUnreadable(const FilePath& path) WARN_UNUSED_RESULT; |
57 bool MakeFileUnwritable(const FilePath& path) WARN_UNUSED_RESULT; | 58 bool MakeFileUnwritable(const FilePath& path) WARN_UNUSED_RESULT; |
58 | 59 |
| 60 // Saves the current permissions for a path, and restores it on destruction. |
| 61 class PermissionRestorer { |
| 62 public: |
| 63 explicit PermissionRestorer(const FilePath& path); |
| 64 ~PermissionRestorer(); |
| 65 |
| 66 private: |
| 67 const FilePath path_; |
| 68 void* info_; // The opaque stored permission information. |
| 69 size_t length_; // The length of the stored permission information. |
| 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(PermissionRestorer); |
| 72 }; |
| 73 |
59 } // namespace file_util | 74 } // namespace file_util |
60 | 75 |
61 #endif // BASE_TEST_TEST_FILE_UTIL_H_ | 76 #endif // BASE_TEST_TEST_FILE_UTIL_H_ |
OLD | NEW |