OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file contains utility functions for dealing with the local | 5 // This file contains utility functions for dealing with the local |
6 // filesystem. | 6 // filesystem. |
7 | 7 |
8 #ifndef BASE_FILE_UTIL_H_ | 8 #ifndef BASE_FILE_UTIL_H_ |
9 #define BASE_FILE_UTIL_H_ | 9 #define BASE_FILE_UTIL_H_ |
10 #pragma once | 10 #pragma once |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 BASE_EXPORT int64 ComputeFilesSize(const FilePath& directory, | 94 BASE_EXPORT int64 ComputeFilesSize(const FilePath& directory, |
95 const FilePath::StringType& pattern); | 95 const FilePath::StringType& pattern); |
96 | 96 |
97 // Deletes the given path, whether it's a file or a directory. | 97 // Deletes the given path, whether it's a file or a directory. |
98 // If it's a directory, it's perfectly happy to delete all of the | 98 // If it's a directory, it's perfectly happy to delete all of the |
99 // directory's contents. Passing true to recursive deletes | 99 // directory's contents. Passing true to recursive deletes |
100 // subdirectories and their contents as well. | 100 // subdirectories and their contents as well. |
101 // Returns true if successful, false otherwise. | 101 // Returns true if successful, false otherwise. |
102 // | 102 // |
103 // In posix environment and if |path| is a symbolic link, this deletes only | 103 // In posix environment and if |path| is a symbolic link, this deletes only |
104 // the symlink. (even if the symlink deferences to a non-existent file) | 104 // the symlink. (even if the symlink points to a non-existent file) |
105 // | 105 // |
106 // WARNING: USING THIS WITH recursive==true IS EQUIVALENT | 106 // WARNING: USING THIS WITH recursive==true IS EQUIVALENT |
107 // TO "rm -rf", SO USE WITH CAUTION. | 107 // TO "rm -rf", SO USE WITH CAUTION. |
108 BASE_EXPORT bool Delete(const FilePath& path, bool recursive); | 108 BASE_EXPORT bool Delete(const FilePath& path, bool recursive); |
109 | 109 |
110 #if defined(OS_WIN) | 110 #if defined(OS_WIN) |
111 // Schedules to delete the given path, whether it's a file or a directory, until | 111 // Schedules to delete the given path, whether it's a file or a directory, until |
112 // the operating system is restarted. | 112 // the operating system is restarted. |
113 // Note: | 113 // Note: |
114 // 1) The file/directory to be deleted should exist in a temp folder. | 114 // 1) The file/directory to be deleted should exist in a temp folder. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 BASE_EXPORT bool ReadFromFD(int fd, char* buffer, size_t bytes); | 189 BASE_EXPORT bool ReadFromFD(int fd, char* buffer, size_t bytes); |
190 | 190 |
191 // Creates a symbolic link at |symlink| pointing to |target|. Returns | 191 // Creates a symbolic link at |symlink| pointing to |target|. Returns |
192 // false on failure. | 192 // false on failure. |
193 BASE_EXPORT bool CreateSymbolicLink(const FilePath& target, | 193 BASE_EXPORT bool CreateSymbolicLink(const FilePath& target, |
194 const FilePath& symlink); | 194 const FilePath& symlink); |
195 | 195 |
196 // Reads the given |symlink| and returns where it points to in |target|. | 196 // Reads the given |symlink| and returns where it points to in |target|. |
197 // Returns false upon failure. | 197 // Returns false upon failure. |
198 BASE_EXPORT bool ReadSymbolicLink(const FilePath& symlink, FilePath* target); | 198 BASE_EXPORT bool ReadSymbolicLink(const FilePath& symlink, FilePath* target); |
| 199 |
| 200 // Bits ans masks of the file permission. |
| 201 enum FilePermissionBits { |
| 202 FILE_PERMISSION_MASK = S_IRWXU | S_IRWXG | S_IRWXO, |
| 203 FILE_PERMISSION_USER_MASK = S_IRWXU, |
| 204 FILE_PERMISSION_GROUP_MASK = S_IRWXG, |
| 205 FILE_PERMISSION_OTHERS_MASK = S_IRWXO, |
| 206 |
| 207 FILE_PERMISSION_READ_BY_USER = S_IRUSR, |
| 208 FILE_PERMISSION_WRITE_BY_USER = S_IWUSR, |
| 209 FILE_PERMISSION_EXECUTE_BY_USER = S_IXUSR, |
| 210 FILE_PERMISSION_READ_BY_GROUP = S_IRGRP, |
| 211 FILE_PERMISSION_WRITE_BY_GROUP = S_IWGRP, |
| 212 FILE_PERMISSION_EXECUTE_BY_GROUP = S_IXGRP, |
| 213 FILE_PERMISSION_READ_BY_OTHERS = S_IROTH, |
| 214 FILE_PERMISSION_WRITE_BY_OTHERS = S_IWOTH, |
| 215 FILE_PERMISSION_EXECUTE_BY_OTHERS = S_IXOTH, |
| 216 }; |
| 217 |
| 218 // Reads the permission of the given |path|, storing the file permission |
| 219 // bits in |mode|. If |path| is symbolic link, |mode| is the permission of |
| 220 // a file which the symlink points to. |
| 221 BASE_EXPORT bool GetPosixFilePermissions(const FilePath& path, |
| 222 int* mode); |
| 223 // Sets the permission of the given |path|. If |path| is symbolic link, sets |
| 224 // the permission of a file which the symlink points to. |
| 225 BASE_EXPORT bool SetPosixFilePermissions(const FilePath& path, |
| 226 int mode); |
199 #endif // defined(OS_POSIX) | 227 #endif // defined(OS_POSIX) |
200 | 228 |
201 #if defined(OS_WIN) | 229 #if defined(OS_WIN) |
202 enum ShortcutOptions { | 230 enum ShortcutOptions { |
203 SHORTCUT_NO_OPTIONS = 0, | 231 SHORTCUT_NO_OPTIONS = 0, |
204 // Set DualMode property for Windows 8 Metro-enabled shortcuts. | 232 // Set DualMode property for Windows 8 Metro-enabled shortcuts. |
205 SHORTCUT_DUAL_MODE = 1 << 0, | 233 SHORTCUT_DUAL_MODE = 1 << 0, |
206 // Create a new shortcut (overwriting if necessary). | 234 // Create a new shortcut (overwriting if necessary). |
207 SHORTCUT_CREATE_ALWAYS = 1 << 1, | 235 SHORTCUT_CREATE_ALWAYS = 1 << 1, |
208 }; | 236 }; |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 }; | 666 }; |
639 | 667 |
640 // Attempts determine the FileSystemType for |path|. | 668 // Attempts determine the FileSystemType for |path|. |
641 // Returns false if |path| doesn't exist. | 669 // Returns false if |path| doesn't exist. |
642 BASE_EXPORT bool GetFileSystemType(const FilePath& path, FileSystemType* type); | 670 BASE_EXPORT bool GetFileSystemType(const FilePath& path, FileSystemType* type); |
643 #endif | 671 #endif |
644 | 672 |
645 } // namespace file_util | 673 } // namespace file_util |
646 | 674 |
647 #endif // BASE_FILE_UTIL_H_ | 675 #endif // BASE_FILE_UTIL_H_ |
OLD | NEW |