1*6777b538SAndroid Build Coastguard Worker // Copyright 2012 The Chromium Authors 2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file. 4*6777b538SAndroid Build Coastguard Worker 5*6777b538SAndroid Build Coastguard Worker // This file contains utility functions for dealing with the local 6*6777b538SAndroid Build Coastguard Worker // filesystem. 7*6777b538SAndroid Build Coastguard Worker 8*6777b538SAndroid Build Coastguard Worker #ifndef BASE_FILES_FILE_UTIL_H_ 9*6777b538SAndroid Build Coastguard Worker #define BASE_FILES_FILE_UTIL_H_ 10*6777b538SAndroid Build Coastguard Worker 11*6777b538SAndroid Build Coastguard Worker #include <stddef.h> 12*6777b538SAndroid Build Coastguard Worker #include <stdint.h> 13*6777b538SAndroid Build Coastguard Worker #include <stdio.h> 14*6777b538SAndroid Build Coastguard Worker 15*6777b538SAndroid Build Coastguard Worker #include <limits> 16*6777b538SAndroid Build Coastguard Worker #include <optional> 17*6777b538SAndroid Build Coastguard Worker #include <set> 18*6777b538SAndroid Build Coastguard Worker #include <string> 19*6777b538SAndroid Build Coastguard Worker 20*6777b538SAndroid Build Coastguard Worker #include "base/base_export.h" 21*6777b538SAndroid Build Coastguard Worker #include "base/containers/span.h" 22*6777b538SAndroid Build Coastguard Worker #include "base/files/file.h" 23*6777b538SAndroid Build Coastguard Worker #include "base/files/file_path.h" 24*6777b538SAndroid Build Coastguard Worker #include "base/files/scoped_file.h" 25*6777b538SAndroid Build Coastguard Worker #include "base/functional/callback.h" 26*6777b538SAndroid Build Coastguard Worker #include "base/types/pass_key.h" 27*6777b538SAndroid Build Coastguard Worker #include "build/build_config.h" 28*6777b538SAndroid Build Coastguard Worker 29*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_WIN) 30*6777b538SAndroid Build Coastguard Worker #include "base/win/windows_types.h" 31*6777b538SAndroid Build Coastguard Worker #elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) 32*6777b538SAndroid Build Coastguard Worker #include <sys/stat.h> 33*6777b538SAndroid Build Coastguard Worker #include <unistd.h> 34*6777b538SAndroid Build Coastguard Worker #include "base/posix/eintr_wrapper.h" 35*6777b538SAndroid Build Coastguard Worker #endif 36*6777b538SAndroid Build Coastguard Worker 37*6777b538SAndroid Build Coastguard Worker namespace content::internal { 38*6777b538SAndroid Build Coastguard Worker class ChildProcessLauncherHelper; 39*6777b538SAndroid Build Coastguard Worker } // namespace content::internal 40*6777b538SAndroid Build Coastguard Worker 41*6777b538SAndroid Build Coastguard Worker namespace base { 42*6777b538SAndroid Build Coastguard Worker 43*6777b538SAndroid Build Coastguard Worker class Environment; 44*6777b538SAndroid Build Coastguard Worker class Time; 45*6777b538SAndroid Build Coastguard Worker 46*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_WIN) 47*6777b538SAndroid Build Coastguard Worker class PreventExecuteMappingClasses { 48*6777b538SAndroid Build Coastguard Worker public: 49*6777b538SAndroid Build Coastguard Worker using PassKey = base::PassKey<PreventExecuteMappingClasses>; 50*6777b538SAndroid Build Coastguard Worker 51*6777b538SAndroid Build Coastguard Worker private: GetPassKey()52*6777b538SAndroid Build Coastguard Worker static PassKey GetPassKey() { return PassKey(); } 53*6777b538SAndroid Build Coastguard Worker 54*6777b538SAndroid Build Coastguard Worker // Allowed to open log files in arbitrary locations. 55*6777b538SAndroid Build Coastguard Worker friend class content::internal::ChildProcessLauncherHelper; 56*6777b538SAndroid Build Coastguard Worker }; 57*6777b538SAndroid Build Coastguard Worker #endif 58*6777b538SAndroid Build Coastguard Worker 59*6777b538SAndroid Build Coastguard Worker //----------------------------------------------------------------------------- 60*6777b538SAndroid Build Coastguard Worker // Functions that involve filesystem access or modification: 61*6777b538SAndroid Build Coastguard Worker 62*6777b538SAndroid Build Coastguard Worker // Returns an absolute version of a relative path. Returns an empty path on 63*6777b538SAndroid Build Coastguard Worker // error. This function can result in I/O so it can be slow. 64*6777b538SAndroid Build Coastguard Worker // 65*6777b538SAndroid Build Coastguard Worker // On POSIX, this function calls realpath(), so: 66*6777b538SAndroid Build Coastguard Worker // 1) it fails if the path does not exist. 67*6777b538SAndroid Build Coastguard Worker // 2) it expands all symlink components of the path. 68*6777b538SAndroid Build Coastguard Worker // 3) it removes "." and ".." directory components. 69*6777b538SAndroid Build Coastguard Worker BASE_EXPORT FilePath MakeAbsoluteFilePath(const FilePath& input); 70*6777b538SAndroid Build Coastguard Worker 71*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_POSIX) 72*6777b538SAndroid Build Coastguard Worker // Prepends the current working directory if `input` is not already absolute, 73*6777b538SAndroid Build Coastguard Worker // and removes "/./" and "/../" This is similar to MakeAbsoluteFilePath(), but 74*6777b538SAndroid Build Coastguard Worker // MakeAbsoluteFilePath() expands all symlinks in the path and this does not. 75*6777b538SAndroid Build Coastguard Worker // 76*6777b538SAndroid Build Coastguard Worker // This may block if `input` is a relative path, when calling 77*6777b538SAndroid Build Coastguard Worker // GetCurrentDirectory(). 78*6777b538SAndroid Build Coastguard Worker // 79*6777b538SAndroid Build Coastguard Worker // This doesn't return std::nullopt unless (1) `input` is empty, or (2) 80*6777b538SAndroid Build Coastguard Worker // `input` is a relative path and GetCurrentDirectory() fails. 81*6777b538SAndroid Build Coastguard Worker [[nodiscard]] BASE_EXPORT std::optional<FilePath> 82*6777b538SAndroid Build Coastguard Worker MakeAbsoluteFilePathNoResolveSymbolicLinks(const FilePath& input); 83*6777b538SAndroid Build Coastguard Worker #endif 84*6777b538SAndroid Build Coastguard Worker 85*6777b538SAndroid Build Coastguard Worker // Returns the total number of bytes used by all the files under |root_path|. 86*6777b538SAndroid Build Coastguard Worker // If the path does not exist the function returns 0. 87*6777b538SAndroid Build Coastguard Worker // 88*6777b538SAndroid Build Coastguard Worker // This function is implemented using the FileEnumerator class so it is not 89*6777b538SAndroid Build Coastguard Worker // particularly speedy on any platform. 90*6777b538SAndroid Build Coastguard Worker BASE_EXPORT int64_t ComputeDirectorySize(const FilePath& root_path); 91*6777b538SAndroid Build Coastguard Worker 92*6777b538SAndroid Build Coastguard Worker // Deletes the given path, whether it's a file or a directory. 93*6777b538SAndroid Build Coastguard Worker // If it's a directory, it's perfectly happy to delete all of the directory's 94*6777b538SAndroid Build Coastguard Worker // contents, but it will not recursively delete subdirectories and their 95*6777b538SAndroid Build Coastguard Worker // contents. 96*6777b538SAndroid Build Coastguard Worker // Returns true if successful, false otherwise. It is considered successful to 97*6777b538SAndroid Build Coastguard Worker // attempt to delete a file that does not exist. 98*6777b538SAndroid Build Coastguard Worker // 99*6777b538SAndroid Build Coastguard Worker // In POSIX environment and if |path| is a symbolic link, this deletes only 100*6777b538SAndroid Build Coastguard Worker // the symlink. (even if the symlink points to a non-existent file) 101*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool DeleteFile(const FilePath& path); 102*6777b538SAndroid Build Coastguard Worker 103*6777b538SAndroid Build Coastguard Worker // Deletes the given path, whether it's a file or a directory. 104*6777b538SAndroid Build Coastguard Worker // If it's a directory, it's perfectly happy to delete all of the 105*6777b538SAndroid Build Coastguard Worker // directory's contents, including subdirectories and their contents. 106*6777b538SAndroid Build Coastguard Worker // Returns true if successful, false otherwise. It is considered successful 107*6777b538SAndroid Build Coastguard Worker // to attempt to delete a file that does not exist. 108*6777b538SAndroid Build Coastguard Worker // 109*6777b538SAndroid Build Coastguard Worker // In POSIX environment and if |path| is a symbolic link, this deletes only 110*6777b538SAndroid Build Coastguard Worker // the symlink. (even if the symlink points to a non-existent file) 111*6777b538SAndroid Build Coastguard Worker // 112*6777b538SAndroid Build Coastguard Worker // WARNING: USING THIS EQUIVALENT TO "rm -rf", SO USE WITH CAUTION. 113*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool DeletePathRecursively(const FilePath& path); 114*6777b538SAndroid Build Coastguard Worker 115*6777b538SAndroid Build Coastguard Worker // Returns a closure that, when run on any sequence that allows blocking calls, 116*6777b538SAndroid Build Coastguard Worker // will kick off a potentially asynchronous operation to delete `path`, whose 117*6777b538SAndroid Build Coastguard Worker // behavior is similar to `DeleteFile()` and `DeletePathRecursively()` 118*6777b538SAndroid Build Coastguard Worker // respectively. 119*6777b538SAndroid Build Coastguard Worker // 120*6777b538SAndroid Build Coastguard Worker // In contrast to `DeleteFile()` and `DeletePathRecursively()`, the thread pool 121*6777b538SAndroid Build Coastguard Worker // may be used in case retries are needed. On Windows, in particular, retries 122*6777b538SAndroid Build Coastguard Worker // will be attempted for some time to allow other programs (e.g., anti-virus 123*6777b538SAndroid Build Coastguard Worker // scanners or malware) to close any open handles to `path` or its contents. If 124*6777b538SAndroid Build Coastguard Worker // `reply_callback` is not null, it will be posted to the caller's sequence with 125*6777b538SAndroid Build Coastguard Worker // true if `path` was fully deleted or false otherwise. 126*6777b538SAndroid Build Coastguard Worker // 127*6777b538SAndroid Build Coastguard Worker // WARNING: It is NOT safe to use `path` until `reply_callback` is run, as the 128*6777b538SAndroid Build Coastguard Worker // retry task may still be actively trying to delete it. 129*6777b538SAndroid Build Coastguard Worker BASE_EXPORT OnceClosure 130*6777b538SAndroid Build Coastguard Worker GetDeleteFileCallback(const FilePath& path, 131*6777b538SAndroid Build Coastguard Worker OnceCallback<void(bool)> reply_callback = {}); 132*6777b538SAndroid Build Coastguard Worker BASE_EXPORT OnceClosure 133*6777b538SAndroid Build Coastguard Worker GetDeletePathRecursivelyCallback(const FilePath& path, 134*6777b538SAndroid Build Coastguard Worker OnceCallback<void(bool)> reply_callback = {}); 135*6777b538SAndroid Build Coastguard Worker 136*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_WIN) 137*6777b538SAndroid Build Coastguard Worker // Schedules to delete the given path, whether it's a file or a directory, until 138*6777b538SAndroid Build Coastguard Worker // the operating system is restarted. 139*6777b538SAndroid Build Coastguard Worker // Note: 140*6777b538SAndroid Build Coastguard Worker // 1) The file/directory to be deleted should exist in a temp folder. 141*6777b538SAndroid Build Coastguard Worker // 2) The directory to be deleted must be empty. 142*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool DeleteFileAfterReboot(const FilePath& path); 143*6777b538SAndroid Build Coastguard Worker 144*6777b538SAndroid Build Coastguard Worker // Prevents opening the file at `path` with EXECUTE access by adding a deny ACE 145*6777b538SAndroid Build Coastguard Worker // on the filesystem. This allows the file handle to be safely passed to an 146*6777b538SAndroid Build Coastguard Worker // untrusted process. See also `File::FLAG_WIN_NO_EXECUTE`. 147*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool PreventExecuteMapping(const FilePath& path); 148*6777b538SAndroid Build Coastguard Worker 149*6777b538SAndroid Build Coastguard Worker // Same as PreventExecuteMapping but DCHECK for known allowed paths is omitted. 150*6777b538SAndroid Build Coastguard Worker // Only call this if you know the path you are providing is safe to mark as 151*6777b538SAndroid Build Coastguard Worker // non-executable, such as log files. 152*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool PreventExecuteMappingUnchecked( 153*6777b538SAndroid Build Coastguard Worker const FilePath& path, 154*6777b538SAndroid Build Coastguard Worker base::PassKey<PreventExecuteMappingClasses> passkey); 155*6777b538SAndroid Build Coastguard Worker 156*6777b538SAndroid Build Coastguard Worker // Set `path_key` to the second of two valid paths that support safely marking a 157*6777b538SAndroid Build Coastguard Worker // file as non-execute. The first allowed path is always PATH_TEMP. This is 158*6777b538SAndroid Build Coastguard Worker // needed to avoid layering violations, as the user data dir is an embedder 159*6777b538SAndroid Build Coastguard Worker // concept and only known later at runtime. 160*6777b538SAndroid Build Coastguard Worker BASE_EXPORT void SetExtraNoExecuteAllowedPath(int path_key); 161*6777b538SAndroid Build Coastguard Worker #endif // BUILDFLAG(IS_WIN) 162*6777b538SAndroid Build Coastguard Worker 163*6777b538SAndroid Build Coastguard Worker // Moves the given path, whether it's a file or a directory. 164*6777b538SAndroid Build Coastguard Worker // If a simple rename is not possible, such as in the case where the paths are 165*6777b538SAndroid Build Coastguard Worker // on different volumes, this will attempt to copy and delete. Returns 166*6777b538SAndroid Build Coastguard Worker // true for success. 167*6777b538SAndroid Build Coastguard Worker // This function fails if either path contains traversal components ('..'). 168*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool Move(const FilePath& from_path, const FilePath& to_path); 169*6777b538SAndroid Build Coastguard Worker 170*6777b538SAndroid Build Coastguard Worker // Renames file |from_path| to |to_path|. Both paths must be on the same 171*6777b538SAndroid Build Coastguard Worker // volume, or the function will fail. Destination file will be created 172*6777b538SAndroid Build Coastguard Worker // if it doesn't exist. Prefer this function over Move when dealing with 173*6777b538SAndroid Build Coastguard Worker // temporary files. On Windows it preserves attributes of the target file. 174*6777b538SAndroid Build Coastguard Worker // Returns true on success, leaving *error unchanged. 175*6777b538SAndroid Build Coastguard Worker // Returns false on failure and sets *error appropriately, if it is non-NULL. 176*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool ReplaceFile(const FilePath& from_path, 177*6777b538SAndroid Build Coastguard Worker const FilePath& to_path, 178*6777b538SAndroid Build Coastguard Worker File::Error* error); 179*6777b538SAndroid Build Coastguard Worker 180*6777b538SAndroid Build Coastguard Worker // Copies a single file. Use CopyDirectory() to copy directories. 181*6777b538SAndroid Build Coastguard Worker // This function fails if either path contains traversal components ('..'). 182*6777b538SAndroid Build Coastguard Worker // This function also fails if |to_path| is a directory. 183*6777b538SAndroid Build Coastguard Worker // 184*6777b538SAndroid Build Coastguard Worker // On POSIX, if |to_path| is a symlink, CopyFile() will follow the symlink. This 185*6777b538SAndroid Build Coastguard Worker // may have security implications. Use with care. 186*6777b538SAndroid Build Coastguard Worker // 187*6777b538SAndroid Build Coastguard Worker // If |to_path| already exists and is a regular file, it will be overwritten, 188*6777b538SAndroid Build Coastguard Worker // though its permissions will stay the same. 189*6777b538SAndroid Build Coastguard Worker // 190*6777b538SAndroid Build Coastguard Worker // If |to_path| does not exist, it will be created. The new file's permissions 191*6777b538SAndroid Build Coastguard Worker // varies per platform: 192*6777b538SAndroid Build Coastguard Worker // 193*6777b538SAndroid Build Coastguard Worker // - This function keeps the metadata on Windows. The read only bit is not kept. 194*6777b538SAndroid Build Coastguard Worker // - On Mac and iOS, |to_path| retains |from_path|'s permissions, except user 195*6777b538SAndroid Build Coastguard Worker // read/write permissions are always set. 196*6777b538SAndroid Build Coastguard Worker // - On Linux and Android, |to_path| has user read/write permissions only. i.e. 197*6777b538SAndroid Build Coastguard Worker // Always 0600. 198*6777b538SAndroid Build Coastguard Worker // - On ChromeOS, |to_path| has user read/write permissions and group/others 199*6777b538SAndroid Build Coastguard Worker // read permissions. i.e. Always 0644. 200*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool CopyFile(const FilePath& from_path, const FilePath& to_path); 201*6777b538SAndroid Build Coastguard Worker 202*6777b538SAndroid Build Coastguard Worker // Copies the contents of one file into another. 203*6777b538SAndroid Build Coastguard Worker // The files are taken as is: the copy is done starting from the current offset 204*6777b538SAndroid Build Coastguard Worker // of |infile| until the end of |infile| is reached, into the current offset of 205*6777b538SAndroid Build Coastguard Worker // |outfile|. 206*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool CopyFileContents(File& infile, File& outfile); 207*6777b538SAndroid Build Coastguard Worker 208*6777b538SAndroid Build Coastguard Worker // Copies the given path, and optionally all subdirectories and their contents 209*6777b538SAndroid Build Coastguard Worker // as well. 210*6777b538SAndroid Build Coastguard Worker // 211*6777b538SAndroid Build Coastguard Worker // If there are files existing under to_path, always overwrite. Returns true 212*6777b538SAndroid Build Coastguard Worker // if successful, false otherwise. Wildcards on the names are not supported. 213*6777b538SAndroid Build Coastguard Worker // 214*6777b538SAndroid Build Coastguard Worker // This function has the same metadata behavior as CopyFile(). 215*6777b538SAndroid Build Coastguard Worker // 216*6777b538SAndroid Build Coastguard Worker // If you only need to copy a file use CopyFile, it's faster. 217*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool CopyDirectory(const FilePath& from_path, 218*6777b538SAndroid Build Coastguard Worker const FilePath& to_path, 219*6777b538SAndroid Build Coastguard Worker bool recursive); 220*6777b538SAndroid Build Coastguard Worker 221*6777b538SAndroid Build Coastguard Worker // Like CopyDirectory() except trying to overwrite an existing file will not 222*6777b538SAndroid Build Coastguard Worker // work and will return false. 223*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool CopyDirectoryExcl(const FilePath& from_path, 224*6777b538SAndroid Build Coastguard Worker const FilePath& to_path, 225*6777b538SAndroid Build Coastguard Worker bool recursive); 226*6777b538SAndroid Build Coastguard Worker 227*6777b538SAndroid Build Coastguard Worker // Returns true if the given path exists on the local filesystem, 228*6777b538SAndroid Build Coastguard Worker // false otherwise. 229*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool PathExists(const FilePath& path); 230*6777b538SAndroid Build Coastguard Worker 231*6777b538SAndroid Build Coastguard Worker // Returns true if the given path is readable by the user, false otherwise. 232*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool PathIsReadable(const FilePath& path); 233*6777b538SAndroid Build Coastguard Worker 234*6777b538SAndroid Build Coastguard Worker // Returns true if the given path is writable by the user, false otherwise. 235*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool PathIsWritable(const FilePath& path); 236*6777b538SAndroid Build Coastguard Worker 237*6777b538SAndroid Build Coastguard Worker // Returns true if the given path exists and is a directory, false otherwise. 238*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool DirectoryExists(const FilePath& path); 239*6777b538SAndroid Build Coastguard Worker 240*6777b538SAndroid Build Coastguard Worker // Returns true if the contents of the two files given are equal, false 241*6777b538SAndroid Build Coastguard Worker // otherwise. If either file can't be read, returns false. 242*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool ContentsEqual(const FilePath& filename1, 243*6777b538SAndroid Build Coastguard Worker const FilePath& filename2); 244*6777b538SAndroid Build Coastguard Worker 245*6777b538SAndroid Build Coastguard Worker // Returns true if the contents of the two text files given are equal, false 246*6777b538SAndroid Build Coastguard Worker // otherwise. This routine treats "\r\n" and "\n" as equivalent. 247*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool TextContentsEqual(const FilePath& filename1, 248*6777b538SAndroid Build Coastguard Worker const FilePath& filename2); 249*6777b538SAndroid Build Coastguard Worker 250*6777b538SAndroid Build Coastguard Worker // Reads the file at |path| and returns a vector of bytes on success, and 251*6777b538SAndroid Build Coastguard Worker // nullopt on error. For security reasons, a |path| containing path traversal 252*6777b538SAndroid Build Coastguard Worker // components ('..') is treated as a read error, returning nullopt. 253*6777b538SAndroid Build Coastguard Worker BASE_EXPORT std::optional<std::vector<uint8_t>> ReadFileToBytes( 254*6777b538SAndroid Build Coastguard Worker const FilePath& path); 255*6777b538SAndroid Build Coastguard Worker 256*6777b538SAndroid Build Coastguard Worker // Reads the file at |path| into |contents| and returns true on success and 257*6777b538SAndroid Build Coastguard Worker // false on error. For security reasons, a |path| containing path traversal 258*6777b538SAndroid Build Coastguard Worker // components ('..') is treated as a read error and |contents| is set to empty. 259*6777b538SAndroid Build Coastguard Worker // In case of I/O error, |contents| holds the data that could be read from the 260*6777b538SAndroid Build Coastguard Worker // file before the error occurred. 261*6777b538SAndroid Build Coastguard Worker // |contents| may be NULL, in which case this function is useful for its side 262*6777b538SAndroid Build Coastguard Worker // effect of priming the disk cache (could be used for unit tests). 263*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool ReadFileToString(const FilePath& path, std::string* contents); 264*6777b538SAndroid Build Coastguard Worker 265*6777b538SAndroid Build Coastguard Worker // Reads the file at |path| into |contents| and returns true on success and 266*6777b538SAndroid Build Coastguard Worker // false on error. For security reasons, a |path| containing path traversal 267*6777b538SAndroid Build Coastguard Worker // components ('..') is treated as a read error and |contents| is set to empty. 268*6777b538SAndroid Build Coastguard Worker // In case of I/O error, |contents| holds the data that could be read from the 269*6777b538SAndroid Build Coastguard Worker // file before the error occurred. When the file size exceeds |max_size|, the 270*6777b538SAndroid Build Coastguard Worker // function returns false with |contents| holding the file truncated to 271*6777b538SAndroid Build Coastguard Worker // |max_size|. 272*6777b538SAndroid Build Coastguard Worker // |contents| may be NULL, in which case this function is useful for its side 273*6777b538SAndroid Build Coastguard Worker // effect of priming the disk cache (could be used for unit tests). 274*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool ReadFileToStringWithMaxSize(const FilePath& path, 275*6777b538SAndroid Build Coastguard Worker std::string* contents, 276*6777b538SAndroid Build Coastguard Worker size_t max_size); 277*6777b538SAndroid Build Coastguard Worker 278*6777b538SAndroid Build Coastguard Worker // As ReadFileToString, but reading from an open stream after seeking to its 279*6777b538SAndroid Build Coastguard Worker // start (if supported by the stream). This can also be used to read the whole 280*6777b538SAndroid Build Coastguard Worker // file from a file descriptor by converting the file descriptor into a stream 281*6777b538SAndroid Build Coastguard Worker // by using base::FileToFILE() before calling this function. 282*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool ReadStreamToString(FILE* stream, std::string* contents); 283*6777b538SAndroid Build Coastguard Worker 284*6777b538SAndroid Build Coastguard Worker // As ReadFileToStringWithMaxSize, but reading from an open stream after seeking 285*6777b538SAndroid Build Coastguard Worker // to its start (if supported by the stream). 286*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool ReadStreamToStringWithMaxSize(FILE* stream, 287*6777b538SAndroid Build Coastguard Worker size_t max_size, 288*6777b538SAndroid Build Coastguard Worker std::string* contents); 289*6777b538SAndroid Build Coastguard Worker 290*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) 291*6777b538SAndroid Build Coastguard Worker 292*6777b538SAndroid Build Coastguard Worker // Reads exactly as many bytes as `buffer` can hold from file descriptor `fd` 293*6777b538SAndroid Build Coastguard Worker // into `buffer`. This function is protected against EINTR and partial reads. 294*6777b538SAndroid Build Coastguard Worker // Returns true iff `buffer` was successfully filled with bytes read from `fd`. 295*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool ReadFromFD(int fd, span<char> buffer); 296*6777b538SAndroid Build Coastguard Worker // TODO(https://crbug.com/1490484): Migrate callers to the span variant. 297*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool ReadFromFD(int fd, char* buffer, size_t bytes); 298*6777b538SAndroid Build Coastguard Worker 299*6777b538SAndroid Build Coastguard Worker // Performs the same function as CreateAndOpenTemporaryStreamInDir(), but 300*6777b538SAndroid Build Coastguard Worker // returns the file-descriptor wrapped in a ScopedFD, rather than the stream 301*6777b538SAndroid Build Coastguard Worker // wrapped in a ScopedFILE. 302*6777b538SAndroid Build Coastguard Worker // The caller is responsible for deleting the file `path` points to, if 303*6777b538SAndroid Build Coastguard Worker // appropriate. 304*6777b538SAndroid Build Coastguard Worker BASE_EXPORT ScopedFD CreateAndOpenFdForTemporaryFileInDir(const FilePath& dir, 305*6777b538SAndroid Build Coastguard Worker FilePath* path); 306*6777b538SAndroid Build Coastguard Worker 307*6777b538SAndroid Build Coastguard Worker #endif // BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) 308*6777b538SAndroid Build Coastguard Worker 309*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_POSIX) 310*6777b538SAndroid Build Coastguard Worker 311*6777b538SAndroid Build Coastguard Worker // ReadFileToStringNonBlocking is identical to ReadFileToString except it 312*6777b538SAndroid Build Coastguard Worker // guarantees that it will not block. This guarantee is provided on POSIX by 313*6777b538SAndroid Build Coastguard Worker // opening the file as O_NONBLOCK. This variant should only be used on files 314*6777b538SAndroid Build Coastguard Worker // which are guaranteed not to block (such as kernel files). Or in situations 315*6777b538SAndroid Build Coastguard Worker // where a partial read would be acceptable because the backing store returned 316*6777b538SAndroid Build Coastguard Worker // EWOULDBLOCK. 317*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool ReadFileToStringNonBlocking(const base::FilePath& file, 318*6777b538SAndroid Build Coastguard Worker std::string* ret); 319*6777b538SAndroid Build Coastguard Worker 320*6777b538SAndroid Build Coastguard Worker // Creates a symbolic link at |symlink| pointing to |target|. Returns 321*6777b538SAndroid Build Coastguard Worker // false on failure. 322*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool CreateSymbolicLink(const FilePath& target, 323*6777b538SAndroid Build Coastguard Worker const FilePath& symlink); 324*6777b538SAndroid Build Coastguard Worker 325*6777b538SAndroid Build Coastguard Worker // Reads the given |symlink| and returns the raw string in |target|. 326*6777b538SAndroid Build Coastguard Worker // Returns false upon failure. 327*6777b538SAndroid Build Coastguard Worker // IMPORTANT NOTE: if the string stored in the symlink is a relative file path, 328*6777b538SAndroid Build Coastguard Worker // it should be interpreted relative to the symlink's directory, NOT the current 329*6777b538SAndroid Build Coastguard Worker // working directory. ReadSymbolicLinkAbsolute() may be the better choice. 330*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool ReadSymbolicLink(const FilePath& symlink, FilePath* target); 331*6777b538SAndroid Build Coastguard Worker 332*6777b538SAndroid Build Coastguard Worker // Same as ReadSymbolicLink(), but properly converts it into an absolute path if 333*6777b538SAndroid Build Coastguard Worker // the link is relative. 334*6777b538SAndroid Build Coastguard Worker // Can fail if readlink() fails, or if 335*6777b538SAndroid Build Coastguard Worker // MakeAbsoluteFilePathNoResolveSymbolicLinks() fails on the resulting absolute 336*6777b538SAndroid Build Coastguard Worker // path. 337*6777b538SAndroid Build Coastguard Worker BASE_EXPORT std::optional<FilePath> ReadSymbolicLinkAbsolute( 338*6777b538SAndroid Build Coastguard Worker const FilePath& symlink); 339*6777b538SAndroid Build Coastguard Worker 340*6777b538SAndroid Build Coastguard Worker // Bits and masks of the file permission. 341*6777b538SAndroid Build Coastguard Worker enum FilePermissionBits { 342*6777b538SAndroid Build Coastguard Worker FILE_PERMISSION_MASK = S_IRWXU | S_IRWXG | S_IRWXO, 343*6777b538SAndroid Build Coastguard Worker FILE_PERMISSION_USER_MASK = S_IRWXU, 344*6777b538SAndroid Build Coastguard Worker FILE_PERMISSION_GROUP_MASK = S_IRWXG, 345*6777b538SAndroid Build Coastguard Worker FILE_PERMISSION_OTHERS_MASK = S_IRWXO, 346*6777b538SAndroid Build Coastguard Worker 347*6777b538SAndroid Build Coastguard Worker FILE_PERMISSION_READ_BY_USER = S_IRUSR, 348*6777b538SAndroid Build Coastguard Worker FILE_PERMISSION_WRITE_BY_USER = S_IWUSR, 349*6777b538SAndroid Build Coastguard Worker FILE_PERMISSION_EXECUTE_BY_USER = S_IXUSR, 350*6777b538SAndroid Build Coastguard Worker FILE_PERMISSION_READ_BY_GROUP = S_IRGRP, 351*6777b538SAndroid Build Coastguard Worker FILE_PERMISSION_WRITE_BY_GROUP = S_IWGRP, 352*6777b538SAndroid Build Coastguard Worker FILE_PERMISSION_EXECUTE_BY_GROUP = S_IXGRP, 353*6777b538SAndroid Build Coastguard Worker FILE_PERMISSION_READ_BY_OTHERS = S_IROTH, 354*6777b538SAndroid Build Coastguard Worker FILE_PERMISSION_WRITE_BY_OTHERS = S_IWOTH, 355*6777b538SAndroid Build Coastguard Worker FILE_PERMISSION_EXECUTE_BY_OTHERS = S_IXOTH, 356*6777b538SAndroid Build Coastguard Worker }; 357*6777b538SAndroid Build Coastguard Worker 358*6777b538SAndroid Build Coastguard Worker // Reads the permission of the given |path|, storing the file permission 359*6777b538SAndroid Build Coastguard Worker // bits in |mode|. If |path| is symbolic link, |mode| is the permission of 360*6777b538SAndroid Build Coastguard Worker // a file which the symlink points to. 361*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool GetPosixFilePermissions(const FilePath& path, int* mode); 362*6777b538SAndroid Build Coastguard Worker // Sets the permission of the given |path|. If |path| is symbolic link, sets 363*6777b538SAndroid Build Coastguard Worker // the permission of a file which the symlink points to. 364*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool SetPosixFilePermissions(const FilePath& path, int mode); 365*6777b538SAndroid Build Coastguard Worker 366*6777b538SAndroid Build Coastguard Worker // Returns true iff |executable| can be found in any directory specified by the 367*6777b538SAndroid Build Coastguard Worker // environment variable in |env|. 368*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool ExecutableExistsInPath(Environment* env, 369*6777b538SAndroid Build Coastguard Worker const FilePath::StringType& executable); 370*6777b538SAndroid Build Coastguard Worker 371*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_AIX) 372*6777b538SAndroid Build Coastguard Worker // Determine if files under a given |path| can be mapped and then mprotect'd 373*6777b538SAndroid Build Coastguard Worker // PROT_EXEC. This depends on the mount options used for |path|, which vary 374*6777b538SAndroid Build Coastguard Worker // among different Linux distributions and possibly local configuration. It also 375*6777b538SAndroid Build Coastguard Worker // depends on details of kernel--ChromeOS uses the noexec option for /dev/shm 376*6777b538SAndroid Build Coastguard Worker // but its kernel allows mprotect with PROT_EXEC anyway. 377*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool IsPathExecutable(const FilePath& path); 378*6777b538SAndroid Build Coastguard Worker #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_AIX) 379*6777b538SAndroid Build Coastguard Worker 380*6777b538SAndroid Build Coastguard Worker #endif // BUILDFLAG(IS_POSIX) 381*6777b538SAndroid Build Coastguard Worker 382*6777b538SAndroid Build Coastguard Worker // Returns true if the given directory is empty 383*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool IsDirectoryEmpty(const FilePath& dir_path); 384*6777b538SAndroid Build Coastguard Worker 385*6777b538SAndroid Build Coastguard Worker // Get the temporary directory provided by the system. 386*6777b538SAndroid Build Coastguard Worker // 387*6777b538SAndroid Build Coastguard Worker // WARNING: In general, you should use CreateTemporaryFile variants below 388*6777b538SAndroid Build Coastguard Worker // instead of this function. Those variants will ensure that the proper 389*6777b538SAndroid Build Coastguard Worker // permissions are set so that other users on the system can't edit them while 390*6777b538SAndroid Build Coastguard Worker // they're open (which can lead to security issues). 391*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool GetTempDir(FilePath* path); 392*6777b538SAndroid Build Coastguard Worker 393*6777b538SAndroid Build Coastguard Worker // Get the home directory. This is more complicated than just getenv("HOME") 394*6777b538SAndroid Build Coastguard Worker // as it knows to fall back on getpwent() etc. 395*6777b538SAndroid Build Coastguard Worker // 396*6777b538SAndroid Build Coastguard Worker // You should not generally call this directly. Instead use DIR_HOME with the 397*6777b538SAndroid Build Coastguard Worker // path service which will use this function but cache the value. 398*6777b538SAndroid Build Coastguard Worker // Path service may also override DIR_HOME. 399*6777b538SAndroid Build Coastguard Worker BASE_EXPORT FilePath GetHomeDir(); 400*6777b538SAndroid Build Coastguard Worker 401*6777b538SAndroid Build Coastguard Worker // Returns a new temporary file in |dir| with a unique name. The file is opened 402*6777b538SAndroid Build Coastguard Worker // for exclusive read, write, and delete access. 403*6777b538SAndroid Build Coastguard Worker // On success, |temp_file| is populated with the full path to the created file. 404*6777b538SAndroid Build Coastguard Worker // 405*6777b538SAndroid Build Coastguard Worker // NOTE: Exclusivity is unique to Windows. On Windows, the returned file 406*6777b538SAndroid Build Coastguard Worker // supports File::DeleteOnClose. On other platforms, the caller is responsible 407*6777b538SAndroid Build Coastguard Worker // for deleting the file `temp_file` points to, if appropriate. 408*6777b538SAndroid Build Coastguard Worker BASE_EXPORT File CreateAndOpenTemporaryFileInDir(const FilePath& dir, 409*6777b538SAndroid Build Coastguard Worker FilePath* temp_file); 410*6777b538SAndroid Build Coastguard Worker 411*6777b538SAndroid Build Coastguard Worker // Creates a temporary file. The full path is placed in `path`, and the 412*6777b538SAndroid Build Coastguard Worker // function returns true if was successful in creating the file. The file will 413*6777b538SAndroid Build Coastguard Worker // be empty and all handles closed after this function returns. 414*6777b538SAndroid Build Coastguard Worker // The caller is responsible for deleting the file `path` points to, if 415*6777b538SAndroid Build Coastguard Worker // appropriate. 416*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool CreateTemporaryFile(FilePath* path); 417*6777b538SAndroid Build Coastguard Worker 418*6777b538SAndroid Build Coastguard Worker // Same as CreateTemporaryFile() but the file is created in `dir`. 419*6777b538SAndroid Build Coastguard Worker // The caller is responsible for deleting the file `temp_file` points to, if 420*6777b538SAndroid Build Coastguard Worker // appropriate. 421*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool CreateTemporaryFileInDir(const FilePath& dir, 422*6777b538SAndroid Build Coastguard Worker FilePath* temp_file); 423*6777b538SAndroid Build Coastguard Worker 424*6777b538SAndroid Build Coastguard Worker // Returns the file name for a temporary file by using a platform-specific 425*6777b538SAndroid Build Coastguard Worker // naming scheme that incorporates |identifier|. 426*6777b538SAndroid Build Coastguard Worker BASE_EXPORT FilePath 427*6777b538SAndroid Build Coastguard Worker FormatTemporaryFileName(FilePath::StringPieceType identifier); 428*6777b538SAndroid Build Coastguard Worker 429*6777b538SAndroid Build Coastguard Worker // Create and open a temporary file stream for exclusive read, write, and delete 430*6777b538SAndroid Build Coastguard Worker // access. The full path is placed in `path`. Returns the opened file stream, or 431*6777b538SAndroid Build Coastguard Worker // null in case of error. 432*6777b538SAndroid Build Coastguard Worker // NOTE: Exclusivity is unique to Windows. On Windows, the returned file 433*6777b538SAndroid Build Coastguard Worker // supports File::DeleteOnClose. On other platforms, the caller is responsible 434*6777b538SAndroid Build Coastguard Worker // for deleting the file `path` points to, if appropriate. 435*6777b538SAndroid Build Coastguard Worker BASE_EXPORT ScopedFILE CreateAndOpenTemporaryStream(FilePath* path); 436*6777b538SAndroid Build Coastguard Worker 437*6777b538SAndroid Build Coastguard Worker // Similar to CreateAndOpenTemporaryStream(), but the file is created in `dir`. 438*6777b538SAndroid Build Coastguard Worker BASE_EXPORT ScopedFILE CreateAndOpenTemporaryStreamInDir(const FilePath& dir, 439*6777b538SAndroid Build Coastguard Worker FilePath* path); 440*6777b538SAndroid Build Coastguard Worker 441*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_WIN) 442*6777b538SAndroid Build Coastguard Worker // Retrieves the path `%systemroot%\SystemTemp`, if available, else retrieves 443*6777b538SAndroid Build Coastguard Worker // `%programfiles%`. 444*6777b538SAndroid Build Coastguard Worker // Returns the path in `temp` and `true` if the path is writable by the caller, 445*6777b538SAndroid Build Coastguard Worker // which is usually only when the caller is running as admin or system. 446*6777b538SAndroid Build Coastguard Worker // Returns `false` otherwise. 447*6777b538SAndroid Build Coastguard Worker // Both paths are only accessible to admin and system processes, and are 448*6777b538SAndroid Build Coastguard Worker // therefore secure. 449*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool GetSecureSystemTemp(FilePath* temp); 450*6777b538SAndroid Build Coastguard Worker 451*6777b538SAndroid Build Coastguard Worker // Set whether or not the use of %systemroot%\SystemTemp or %programfiles% is 452*6777b538SAndroid Build Coastguard Worker // permitted for testing. This is so tests that run as admin will still continue 453*6777b538SAndroid Build Coastguard Worker // to use %TMP% so their files will be correctly cleaned up by the test 454*6777b538SAndroid Build Coastguard Worker // launcher. 455*6777b538SAndroid Build Coastguard Worker BASE_EXPORT void SetDisableSecureSystemTempForTesting(bool disabled); 456*6777b538SAndroid Build Coastguard Worker #endif // BUILDFLAG(IS_WIN) 457*6777b538SAndroid Build Coastguard Worker 458*6777b538SAndroid Build Coastguard Worker // Do NOT USE in new code. Use ScopedTempDir instead. 459*6777b538SAndroid Build Coastguard Worker // TODO(crbug.com/561597) Remove existing usage and make this an implementation 460*6777b538SAndroid Build Coastguard Worker // detail inside ScopedTempDir. 461*6777b538SAndroid Build Coastguard Worker // 462*6777b538SAndroid Build Coastguard Worker // Create a new directory. If prefix is provided, the new directory name is in 463*6777b538SAndroid Build Coastguard Worker // the format of prefixyyyy. 464*6777b538SAndroid Build Coastguard Worker // NOTE: prefix is ignored in the POSIX implementation. 465*6777b538SAndroid Build Coastguard Worker // If success, return true and output the full path of the directory created. 466*6777b538SAndroid Build Coastguard Worker // 467*6777b538SAndroid Build Coastguard Worker // For Windows, this directory is usually created in a secure location if the 468*6777b538SAndroid Build Coastguard Worker // caller is admin. This is because the default %TEMP% folder for Windows is 469*6777b538SAndroid Build Coastguard Worker // insecure, since low privilege users can get the path of folders under %TEMP% 470*6777b538SAndroid Build Coastguard Worker // after creation and are able to create subfolders and files within these 471*6777b538SAndroid Build Coastguard Worker // folders which can lead to privilege escalation. 472*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool CreateNewTempDirectory(const FilePath::StringType& prefix, 473*6777b538SAndroid Build Coastguard Worker FilePath* new_temp_path); 474*6777b538SAndroid Build Coastguard Worker 475*6777b538SAndroid Build Coastguard Worker // Create a directory within another directory. 476*6777b538SAndroid Build Coastguard Worker // Extra characters will be appended to |prefix| to ensure that the 477*6777b538SAndroid Build Coastguard Worker // new directory does not have the same name as an existing directory. 478*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool CreateTemporaryDirInDir(const FilePath& base_dir, 479*6777b538SAndroid Build Coastguard Worker const FilePath::StringType& prefix, 480*6777b538SAndroid Build Coastguard Worker FilePath* new_dir); 481*6777b538SAndroid Build Coastguard Worker 482*6777b538SAndroid Build Coastguard Worker // Creates a directory, as well as creating any parent directories, if they 483*6777b538SAndroid Build Coastguard Worker // don't exist. Returns 'true' on successful creation, or if the directory 484*6777b538SAndroid Build Coastguard Worker // already exists. The directory is only readable by the current user. 485*6777b538SAndroid Build Coastguard Worker // Returns true on success, leaving *error unchanged. 486*6777b538SAndroid Build Coastguard Worker // Returns false on failure and sets *error appropriately, if it is non-NULL. 487*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool CreateDirectoryAndGetError(const FilePath& full_path, 488*6777b538SAndroid Build Coastguard Worker File::Error* error); 489*6777b538SAndroid Build Coastguard Worker 490*6777b538SAndroid Build Coastguard Worker // Backward-compatible convenience method for the above. 491*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool CreateDirectory(const FilePath& full_path); 492*6777b538SAndroid Build Coastguard Worker 493*6777b538SAndroid Build Coastguard Worker // Returns the file size. Returns true on success. 494*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool GetFileSize(const FilePath& file_path, int64_t* file_size); 495*6777b538SAndroid Build Coastguard Worker 496*6777b538SAndroid Build Coastguard Worker // Sets |real_path| to |path| with symbolic links and junctions expanded. 497*6777b538SAndroid Build Coastguard Worker // On windows, make sure the path starts with a lettered drive. 498*6777b538SAndroid Build Coastguard Worker // |path| must reference a file. Function will fail if |path| points to 499*6777b538SAndroid Build Coastguard Worker // a directory or to a nonexistent path. On windows, this function will 500*6777b538SAndroid Build Coastguard Worker // fail if |real_path| would be longer than MAX_PATH characters. 501*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool NormalizeFilePath(const FilePath& path, FilePath* real_path); 502*6777b538SAndroid Build Coastguard Worker 503*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_WIN) 504*6777b538SAndroid Build Coastguard Worker 505*6777b538SAndroid Build Coastguard Worker // Given a path in NT native form ("\Device\HarddiskVolumeXX\..."), 506*6777b538SAndroid Build Coastguard Worker // return in |drive_letter_path| the equivalent path that starts with 507*6777b538SAndroid Build Coastguard Worker // a drive letter ("C:\..."). Return false if no such path exists. 508*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool DevicePathToDriveLetterPath(const FilePath& device_path, 509*6777b538SAndroid Build Coastguard Worker FilePath* drive_letter_path); 510*6777b538SAndroid Build Coastguard Worker 511*6777b538SAndroid Build Coastguard Worker // Method that wraps the win32 GetLongPathName API, normalizing the specified 512*6777b538SAndroid Build Coastguard Worker // path to its long form. An example where this is needed is when comparing 513*6777b538SAndroid Build Coastguard Worker // temp file paths. If a username isn't a valid 8.3 short file name (even just a 514*6777b538SAndroid Build Coastguard Worker // lengthy name like "user with long name"), Windows will set the TMP and TEMP 515*6777b538SAndroid Build Coastguard Worker // environment variables to be 8.3 paths. ::GetTempPath (called in 516*6777b538SAndroid Build Coastguard Worker // base::GetTempDir) just uses the value specified by TMP or TEMP, and so can 517*6777b538SAndroid Build Coastguard Worker // return a short path. Returns an empty path on error. 518*6777b538SAndroid Build Coastguard Worker BASE_EXPORT FilePath MakeLongFilePath(const FilePath& input); 519*6777b538SAndroid Build Coastguard Worker 520*6777b538SAndroid Build Coastguard Worker // Creates a hard link named |to_file| to the file |from_file|. Both paths 521*6777b538SAndroid Build Coastguard Worker // must be on the same volume, and |from_file| may not name a directory. 522*6777b538SAndroid Build Coastguard Worker // Returns true if the hard link is created, false if it fails. 523*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool CreateWinHardLink(const FilePath& to_file, 524*6777b538SAndroid Build Coastguard Worker const FilePath& from_file); 525*6777b538SAndroid Build Coastguard Worker #endif 526*6777b538SAndroid Build Coastguard Worker 527*6777b538SAndroid Build Coastguard Worker // This function will return if the given file is a symlink or not. 528*6777b538SAndroid Build Coastguard Worker // 529*6777b538SAndroid Build Coastguard Worker // IMPORTANT NOTE: This method is subject to race conditions, meaning its 530*6777b538SAndroid Build Coastguard Worker // results might not always accurately reflect the current state of the file 531*6777b538SAndroid Build Coastguard Worker // system by the time they are used. Specifically, the link target could change 532*6777b538SAndroid Build Coastguard Worker // between the time of this check and subsequent operations, leading to 533*6777b538SAndroid Build Coastguard Worker // potential inconsistencies. Therefore, this method should only be used by 534*6777b538SAndroid Build Coastguard Worker // callers that need to know nothing more than whether or not a given directory 535*6777b538SAndroid Build Coastguard Worker // entry is a symlink. When the path to the target is required, callers should 536*6777b538SAndroid Build Coastguard Worker // instead use `base::ReadSymbolicLink()` or `base::ReadSymbolicLinkAbsolute()`. 537*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool IsLink(const FilePath& file_path); 538*6777b538SAndroid Build Coastguard Worker 539*6777b538SAndroid Build Coastguard Worker // Returns information about the given file path. Also see |File::GetInfo|. 540*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool GetFileInfo(const FilePath& file_path, File::Info* info); 541*6777b538SAndroid Build Coastguard Worker 542*6777b538SAndroid Build Coastguard Worker // Sets the time of the last access and the time of the last modification. 543*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool TouchFile(const FilePath& path, 544*6777b538SAndroid Build Coastguard Worker const Time& last_accessed, 545*6777b538SAndroid Build Coastguard Worker const Time& last_modified); 546*6777b538SAndroid Build Coastguard Worker 547*6777b538SAndroid Build Coastguard Worker // Wrapper for fopen-like calls. Returns non-NULL FILE* on success. The 548*6777b538SAndroid Build Coastguard Worker // underlying file descriptor (POSIX) or handle (Windows) is unconditionally 549*6777b538SAndroid Build Coastguard Worker // configured to not be propagated to child processes. 550*6777b538SAndroid Build Coastguard Worker BASE_EXPORT FILE* OpenFile(const FilePath& filename, const char* mode); 551*6777b538SAndroid Build Coastguard Worker 552*6777b538SAndroid Build Coastguard Worker // Closes file opened by OpenFile. Returns true on success. 553*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool CloseFile(FILE* file); 554*6777b538SAndroid Build Coastguard Worker 555*6777b538SAndroid Build Coastguard Worker // Associates a standard FILE stream with an existing File. Note that this 556*6777b538SAndroid Build Coastguard Worker // functions take ownership of the existing File. 557*6777b538SAndroid Build Coastguard Worker BASE_EXPORT FILE* FileToFILE(File file, const char* mode); 558*6777b538SAndroid Build Coastguard Worker 559*6777b538SAndroid Build Coastguard Worker // Returns a new handle to the file underlying |file_stream|. 560*6777b538SAndroid Build Coastguard Worker BASE_EXPORT File FILEToFile(FILE* file_stream); 561*6777b538SAndroid Build Coastguard Worker 562*6777b538SAndroid Build Coastguard Worker // Truncates an open file to end at the location of the current file pointer. 563*6777b538SAndroid Build Coastguard Worker // This is a cross-platform analog to Windows' SetEndOfFile() function. 564*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool TruncateFile(FILE* file); 565*6777b538SAndroid Build Coastguard Worker 566*6777b538SAndroid Build Coastguard Worker // Reads from the file into `buffer`. This will read at most as many bytes as 567*6777b538SAndroid Build Coastguard Worker // `buffer` can hold, but may not always fill `buffer` entirely. 568*6777b538SAndroid Build Coastguard Worker // Returns the number of bytes read, or nullopt on error. 569*6777b538SAndroid Build Coastguard Worker // TODO(crbug.com/1333521): Despite the 64-bit return value, this only supports 570*6777b538SAndroid Build Coastguard Worker // reading at most INT_MAX bytes. The program will crash if a buffer is passed 571*6777b538SAndroid Build Coastguard Worker // whose length exceeds INT_MAX. 572*6777b538SAndroid Build Coastguard Worker BASE_EXPORT std::optional<uint64_t> ReadFile(const FilePath& filename, 573*6777b538SAndroid Build Coastguard Worker span<char> buffer); 574*6777b538SAndroid Build Coastguard Worker BASE_EXPORT std::optional<uint64_t> ReadFile(const FilePath& filename, 575*6777b538SAndroid Build Coastguard Worker span<uint8_t> buffer); 576*6777b538SAndroid Build Coastguard Worker 577*6777b538SAndroid Build Coastguard Worker // Same as above, but returns -1 on error. 578*6777b538SAndroid Build Coastguard Worker // TODO(https://crbug.com/1490484): Migrate callers to the span variant. 579*6777b538SAndroid Build Coastguard Worker BASE_EXPORT int ReadFile(const FilePath& filename, char* data, int max_size); 580*6777b538SAndroid Build Coastguard Worker 581*6777b538SAndroid Build Coastguard Worker // Writes the given buffer into the file, overwriting any data that was 582*6777b538SAndroid Build Coastguard Worker // previously there. Returns the number of bytes written, or -1 on error. 583*6777b538SAndroid Build Coastguard Worker // If file doesn't exist, it gets created with read/write permissions for all. 584*6777b538SAndroid Build Coastguard Worker // Note that the other variants of WriteFile() below may be easier to use. 585*6777b538SAndroid Build Coastguard Worker // TODO(https://crbug.com/1490484): Migrate callers to the span variant. 586*6777b538SAndroid Build Coastguard Worker BASE_EXPORT int WriteFile(const FilePath& filename, const char* data, 587*6777b538SAndroid Build Coastguard Worker int size); 588*6777b538SAndroid Build Coastguard Worker 589*6777b538SAndroid Build Coastguard Worker // Writes |data| into the file, overwriting any data that was previously there. 590*6777b538SAndroid Build Coastguard Worker // Returns true if and only if all of |data| was written. If the file does not 591*6777b538SAndroid Build Coastguard Worker // exist, it gets created with read/write permissions for all. 592*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool WriteFile(const FilePath& filename, span<const uint8_t> data); 593*6777b538SAndroid Build Coastguard Worker 594*6777b538SAndroid Build Coastguard Worker // Another WriteFile() variant that takes a StringPiece so callers don't have to 595*6777b538SAndroid Build Coastguard Worker // do manual conversions from a char span to a uint8_t span. 596*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool WriteFile(const FilePath& filename, StringPiece data); 597*6777b538SAndroid Build Coastguard Worker 598*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) 599*6777b538SAndroid Build Coastguard Worker // Appends |data| to |fd|. Does not close |fd| when done. Returns true iff all 600*6777b538SAndroid Build Coastguard Worker // of |data| were written to |fd|. 601*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool WriteFileDescriptor(int fd, span<const uint8_t> data); 602*6777b538SAndroid Build Coastguard Worker 603*6777b538SAndroid Build Coastguard Worker // WriteFileDescriptor() variant that takes a StringPiece so callers don't have 604*6777b538SAndroid Build Coastguard Worker // to do manual conversions from a char span to a uint8_t span. 605*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool WriteFileDescriptor(int fd, StringPiece data); 606*6777b538SAndroid Build Coastguard Worker 607*6777b538SAndroid Build Coastguard Worker // Allocates disk space for the file referred to by |fd| for the byte range 608*6777b538SAndroid Build Coastguard Worker // starting at |offset| and continuing for |size| bytes. The file size will be 609*6777b538SAndroid Build Coastguard Worker // changed if |offset|+|len| is greater than the file size. Zeros will fill the 610*6777b538SAndroid Build Coastguard Worker // new space. 611*6777b538SAndroid Build Coastguard Worker // After a successful call, subsequent writes into the specified range are 612*6777b538SAndroid Build Coastguard Worker // guaranteed not to fail because of lack of disk space. 613*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool AllocateFileRegion(File* file, int64_t offset, size_t size); 614*6777b538SAndroid Build Coastguard Worker #endif 615*6777b538SAndroid Build Coastguard Worker 616*6777b538SAndroid Build Coastguard Worker // Appends |data| to |filename|. Returns true iff |data| were written to 617*6777b538SAndroid Build Coastguard Worker // |filename|. 618*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool AppendToFile(const FilePath& filename, 619*6777b538SAndroid Build Coastguard Worker span<const uint8_t> data); 620*6777b538SAndroid Build Coastguard Worker 621*6777b538SAndroid Build Coastguard Worker // AppendToFile() variant that takes a StringPiece so callers don't have to do 622*6777b538SAndroid Build Coastguard Worker // manual conversions from a char span to a uint8_t span. 623*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool AppendToFile(const FilePath& filename, StringPiece data); 624*6777b538SAndroid Build Coastguard Worker 625*6777b538SAndroid Build Coastguard Worker // Gets the current working directory for the process. 626*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool GetCurrentDirectory(FilePath* path); 627*6777b538SAndroid Build Coastguard Worker 628*6777b538SAndroid Build Coastguard Worker // Sets the current working directory for the process. 629*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool SetCurrentDirectory(const FilePath& path); 630*6777b538SAndroid Build Coastguard Worker 631*6777b538SAndroid Build Coastguard Worker // The largest value attempted by GetUniquePath{Number,}. 632*6777b538SAndroid Build Coastguard Worker enum { kMaxUniqueFiles = 100 }; 633*6777b538SAndroid Build Coastguard Worker 634*6777b538SAndroid Build Coastguard Worker // Returns the number N that makes |path| unique when formatted as " (N)" in a 635*6777b538SAndroid Build Coastguard Worker // suffix to its basename before any file extension, where N is a number between 636*6777b538SAndroid Build Coastguard Worker // 1 and 100 (inclusive). Returns 0 if |path| does not exist (meaning that it is 637*6777b538SAndroid Build Coastguard Worker // unique as-is), or -1 if no such number can be found. 638*6777b538SAndroid Build Coastguard Worker BASE_EXPORT int GetUniquePathNumber(const FilePath& path); 639*6777b538SAndroid Build Coastguard Worker 640*6777b538SAndroid Build Coastguard Worker // Returns |path| if it does not exist. Otherwise, returns |path| with the 641*6777b538SAndroid Build Coastguard Worker // suffix " (N)" appended to its basename before any file extension, where N is 642*6777b538SAndroid Build Coastguard Worker // a number between 1 and 100 (inclusive). Returns an empty path if no such 643*6777b538SAndroid Build Coastguard Worker // number can be found. 644*6777b538SAndroid Build Coastguard Worker BASE_EXPORT FilePath GetUniquePath(const FilePath& path); 645*6777b538SAndroid Build Coastguard Worker 646*6777b538SAndroid Build Coastguard Worker // Sets the given |fd| to non-blocking mode. 647*6777b538SAndroid Build Coastguard Worker // Returns true if it was able to set it in the non-blocking mode, otherwise 648*6777b538SAndroid Build Coastguard Worker // false. 649*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool SetNonBlocking(int fd); 650*6777b538SAndroid Build Coastguard Worker 651*6777b538SAndroid Build Coastguard Worker // Hints the OS to prefetch the first |max_bytes| of |file_path| into its cache. 652*6777b538SAndroid Build Coastguard Worker // 653*6777b538SAndroid Build Coastguard Worker // If called at the appropriate time, this can reduce the latency incurred by 654*6777b538SAndroid Build Coastguard Worker // feature code that needs to read the file. 655*6777b538SAndroid Build Coastguard Worker // 656*6777b538SAndroid Build Coastguard Worker // |max_bytes| specifies how many bytes should be pre-fetched. It may exceed the 657*6777b538SAndroid Build Coastguard Worker // file's size. Passing in std::numeric_limits<int64_t>::max() is a convenient 658*6777b538SAndroid Build Coastguard Worker // way to get the entire file pre-fetched. 659*6777b538SAndroid Build Coastguard Worker // 660*6777b538SAndroid Build Coastguard Worker // |is_executable| specifies whether the file is to be prefetched as 661*6777b538SAndroid Build Coastguard Worker // executable code or as data. Windows treats the file backed pages in RAM 662*6777b538SAndroid Build Coastguard Worker // differently, and specifying the wrong value results in two copies in RAM. 663*6777b538SAndroid Build Coastguard Worker // 664*6777b538SAndroid Build Coastguard Worker // |sequential| hints that the file will be read sequentially in the future. 665*6777b538SAndroid Build Coastguard Worker // This has the affect of using POSIX_FADV_SEQUENTIAL on supported POSIX 666*6777b538SAndroid Build Coastguard Worker // systems. 667*6777b538SAndroid Build Coastguard Worker // 668*6777b538SAndroid Build Coastguard Worker // Returns true if at least part of the requested range was successfully 669*6777b538SAndroid Build Coastguard Worker // prefetched. 670*6777b538SAndroid Build Coastguard Worker // 671*6777b538SAndroid Build Coastguard Worker // Calling this before using ::LoadLibrary() on Windows is more efficient memory 672*6777b538SAndroid Build Coastguard Worker // wise, but we must be sure no other threads try to LoadLibrary() the file 673*6777b538SAndroid Build Coastguard Worker // while we are doing the mapping and prefetching, or the process will get a 674*6777b538SAndroid Build Coastguard Worker // private copy of the DLL via COW. 675*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool PreReadFile( 676*6777b538SAndroid Build Coastguard Worker const FilePath& file_path, 677*6777b538SAndroid Build Coastguard Worker bool is_executable, 678*6777b538SAndroid Build Coastguard Worker bool sequential, 679*6777b538SAndroid Build Coastguard Worker int64_t max_bytes = std::numeric_limits<int64_t>::max()); 680*6777b538SAndroid Build Coastguard Worker 681*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) 682*6777b538SAndroid Build Coastguard Worker 683*6777b538SAndroid Build Coastguard Worker // Creates a pipe. Returns true on success, otherwise false. 684*6777b538SAndroid Build Coastguard Worker // On success, |read_fd| will be set to the fd of the read side, and 685*6777b538SAndroid Build Coastguard Worker // |write_fd| will be set to the one of write side. If |non_blocking| 686*6777b538SAndroid Build Coastguard Worker // is set the pipe will be created with O_NONBLOCK|O_CLOEXEC flags set 687*6777b538SAndroid Build Coastguard Worker // otherwise flag is set to zero (default). 688*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool CreatePipe(ScopedFD* read_fd, 689*6777b538SAndroid Build Coastguard Worker ScopedFD* write_fd, 690*6777b538SAndroid Build Coastguard Worker bool non_blocking = false); 691*6777b538SAndroid Build Coastguard Worker 692*6777b538SAndroid Build Coastguard Worker // Creates a non-blocking, close-on-exec pipe. 693*6777b538SAndroid Build Coastguard Worker // This creates a non-blocking pipe that is not intended to be shared with any 694*6777b538SAndroid Build Coastguard Worker // child process. This will be done atomically if the operating system supports 695*6777b538SAndroid Build Coastguard Worker // it. Returns true if it was able to create the pipe, otherwise false. 696*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool CreateLocalNonBlockingPipe(int fds[2]); 697*6777b538SAndroid Build Coastguard Worker 698*6777b538SAndroid Build Coastguard Worker // Sets the given |fd| to close-on-exec mode. 699*6777b538SAndroid Build Coastguard Worker // Returns true if it was able to set it in the close-on-exec mode, otherwise 700*6777b538SAndroid Build Coastguard Worker // false. 701*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool SetCloseOnExec(int fd); 702*6777b538SAndroid Build Coastguard Worker 703*6777b538SAndroid Build Coastguard Worker // Removes close-on-exec flag from the given |fd|. 704*6777b538SAndroid Build Coastguard Worker // Returns true if it was able to remove the close-on-exec flag, otherwise 705*6777b538SAndroid Build Coastguard Worker // false. 706*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool RemoveCloseOnExec(int fd); 707*6777b538SAndroid Build Coastguard Worker #endif // BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) 708*6777b538SAndroid Build Coastguard Worker 709*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_MAC) 710*6777b538SAndroid Build Coastguard Worker // Test that |path| can only be changed by a given user and members of 711*6777b538SAndroid Build Coastguard Worker // a given set of groups. 712*6777b538SAndroid Build Coastguard Worker // Specifically, test that all parts of |path| under (and including) |base|: 713*6777b538SAndroid Build Coastguard Worker // * Exist. 714*6777b538SAndroid Build Coastguard Worker // * Are owned by a specific user. 715*6777b538SAndroid Build Coastguard Worker // * Are not writable by all users. 716*6777b538SAndroid Build Coastguard Worker // * Are owned by a member of a given set of groups, or are not writable by 717*6777b538SAndroid Build Coastguard Worker // their group. 718*6777b538SAndroid Build Coastguard Worker // * Are not symbolic links. 719*6777b538SAndroid Build Coastguard Worker // This is useful for checking that a config file is administrator-controlled. 720*6777b538SAndroid Build Coastguard Worker // |base| must contain |path|. 721*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool VerifyPathControlledByUser(const base::FilePath& base, 722*6777b538SAndroid Build Coastguard Worker const base::FilePath& path, 723*6777b538SAndroid Build Coastguard Worker uid_t owner_uid, 724*6777b538SAndroid Build Coastguard Worker const std::set<gid_t>& group_gids); 725*6777b538SAndroid Build Coastguard Worker 726*6777b538SAndroid Build Coastguard Worker // Is |path| writable only by a user with administrator privileges? 727*6777b538SAndroid Build Coastguard Worker // This function uses Mac OS conventions. The super user is assumed to have 728*6777b538SAndroid Build Coastguard Worker // uid 0, and the administrator group is assumed to be named "admin". 729*6777b538SAndroid Build Coastguard Worker // Testing that |path|, and every parent directory including the root of 730*6777b538SAndroid Build Coastguard Worker // the filesystem, are owned by the superuser, controlled by the group 731*6777b538SAndroid Build Coastguard Worker // "admin", are not writable by all users, and contain no symbolic links. 732*6777b538SAndroid Build Coastguard Worker // Will return false if |path| does not exist. 733*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool VerifyPathControlledByAdmin(const base::FilePath& path); 734*6777b538SAndroid Build Coastguard Worker #endif // BUILDFLAG(IS_MAC) 735*6777b538SAndroid Build Coastguard Worker 736*6777b538SAndroid Build Coastguard Worker // Returns the maximum length of path component on the volume containing 737*6777b538SAndroid Build Coastguard Worker // the directory |path|, in the number of FilePath::CharType, or -1 on failure. 738*6777b538SAndroid Build Coastguard Worker BASE_EXPORT int GetMaximumPathComponentLength(const base::FilePath& path); 739*6777b538SAndroid Build Coastguard Worker 740*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) 741*6777b538SAndroid Build Coastguard Worker // Get a temporary directory for shared memory files. The directory may depend 742*6777b538SAndroid Build Coastguard Worker // on whether the destination is intended for executable files, which in turn 743*6777b538SAndroid Build Coastguard Worker // depends on how /dev/shmem was mounted. As a result, you must supply whether 744*6777b538SAndroid Build Coastguard Worker // you intend to create executable shmem segments so this function can find 745*6777b538SAndroid Build Coastguard Worker // an appropriate location. 746*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool GetShmemTempDir(bool executable, FilePath* path); 747*6777b538SAndroid Build Coastguard Worker #endif 748*6777b538SAndroid Build Coastguard Worker 749*6777b538SAndroid Build Coastguard Worker // Internal -------------------------------------------------------------------- 750*6777b538SAndroid Build Coastguard Worker 751*6777b538SAndroid Build Coastguard Worker namespace internal { 752*6777b538SAndroid Build Coastguard Worker 753*6777b538SAndroid Build Coastguard Worker // Same as Move but allows paths with traversal components. 754*6777b538SAndroid Build Coastguard Worker // Use only with extreme care. 755*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool MoveUnsafe(const FilePath& from_path, 756*6777b538SAndroid Build Coastguard Worker const FilePath& to_path); 757*6777b538SAndroid Build Coastguard Worker 758*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_WIN) 759*6777b538SAndroid Build Coastguard Worker // Copy from_path to to_path recursively and then delete from_path recursively. 760*6777b538SAndroid Build Coastguard Worker // Returns true if all operations succeed. 761*6777b538SAndroid Build Coastguard Worker // This function simulates Move(), but unlike Move() it works across volumes. 762*6777b538SAndroid Build Coastguard Worker // This function is not transactional. 763*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, 764*6777b538SAndroid Build Coastguard Worker const FilePath& to_path); 765*6777b538SAndroid Build Coastguard Worker #endif // BUILDFLAG(IS_WIN) 766*6777b538SAndroid Build Coastguard Worker 767*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) 768*6777b538SAndroid Build Coastguard Worker // CopyFileContentsWithSendfile will use the sendfile(2) syscall to perform a 769*6777b538SAndroid Build Coastguard Worker // file copy without moving the data between kernel and userspace. This is much 770*6777b538SAndroid Build Coastguard Worker // more efficient than sequences of read(2)/write(2) calls. The |retry_slow| 771*6777b538SAndroid Build Coastguard Worker // parameter instructs the caller that it should try to fall back to a normal 772*6777b538SAndroid Build Coastguard Worker // sequences of read(2)/write(2) syscalls. 773*6777b538SAndroid Build Coastguard Worker // 774*6777b538SAndroid Build Coastguard Worker // The input file |infile| must be opened for reading and the output file 775*6777b538SAndroid Build Coastguard Worker // |outfile| must be opened for writing. 776*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool CopyFileContentsWithSendfile(File& infile, 777*6777b538SAndroid Build Coastguard Worker File& outfile, 778*6777b538SAndroid Build Coastguard Worker bool& retry_slow); 779*6777b538SAndroid Build Coastguard Worker #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || 780*6777b538SAndroid Build Coastguard Worker // BUILDFLAG(IS_ANDROID) 781*6777b538SAndroid Build Coastguard Worker 782*6777b538SAndroid Build Coastguard Worker } // namespace internal 783*6777b538SAndroid Build Coastguard Worker } // namespace base 784*6777b538SAndroid Build Coastguard Worker 785*6777b538SAndroid Build Coastguard Worker #endif // BASE_FILES_FILE_UTIL_H_ 786