1 /* 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef WEBRTC_BASE_UNIXFILESYSTEM_H_ 12 #define WEBRTC_BASE_UNIXFILESYSTEM_H_ 13 14 #include <sys/types.h> 15 16 #include "webrtc/base/fileutils.h" 17 18 namespace rtc { 19 20 class UnixFilesystem : public FilesystemInterface { 21 public: 22 UnixFilesystem(); 23 virtual ~UnixFilesystem(); 24 25 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) 26 // Android does not have a native code API to fetch the app data or temp 27 // folders. That needs to be passed into this class from Java. Similarly, iOS 28 // only supports an Objective-C API for fetching the folder locations, so that 29 // needs to be passed in here from Objective-C. Or at least that used to be 30 // the case; now the ctor will do the work if necessary and possible. 31 // TODO(fischman): add an Android version that uses JNI and drop the 32 // SetApp*Folder() APIs once external users stop using them. 33 static void SetAppDataFolder(const std::string& folder); 34 static void SetAppTempFolder(const std::string& folder); 35 #endif 36 37 // Opens a file. Returns an open StreamInterface if function succeeds. 38 // Otherwise, returns NULL. 39 virtual FileStream *OpenFile(const Pathname &filename, 40 const std::string &mode); 41 42 // Atomically creates an empty file accessible only to the current user if one 43 // does not already exist at the given path, otherwise fails. 44 virtual bool CreatePrivateFile(const Pathname &filename); 45 46 // This will attempt to delete the file located at filename. 47 // It will fail with VERIY if you pass it a non-existant file, or a directory. 48 virtual bool DeleteFile(const Pathname &filename); 49 50 // This will attempt to delete the folder located at 'folder' 51 // It ASSERTs and returns false if you pass it a non-existant folder or a 52 // plain file. 53 virtual bool DeleteEmptyFolder(const Pathname &folder); 54 55 // Creates a directory. This will call itself recursively to create /foo/bar 56 // even if /foo does not exist. All created directories are created with the 57 // given mode. 58 // Returns TRUE if function succeeds 59 virtual bool CreateFolder(const Pathname &pathname, mode_t mode); 60 61 // As above, with mode = 0755. 62 virtual bool CreateFolder(const Pathname &pathname); 63 64 // This moves a file from old_path to new_path, where "file" can be a plain 65 // file or directory, which will be moved recursively. 66 // Returns true if function succeeds. 67 virtual bool MoveFile(const Pathname &old_path, const Pathname &new_path); 68 virtual bool MoveFolder(const Pathname &old_path, const Pathname &new_path); 69 70 // This copies a file from old_path to _new_path where "file" can be a plain 71 // file or directory, which will be copied recursively. 72 // Returns true if function succeeds 73 virtual bool CopyFile(const Pathname &old_path, const Pathname &new_path); 74 75 // Returns true if a pathname is a directory 76 virtual bool IsFolder(const Pathname& pathname); 77 78 // Returns true if pathname represents a temporary location on the system. 79 virtual bool IsTemporaryPath(const Pathname& pathname); 80 81 // Returns true of pathname represents an existing file 82 virtual bool IsFile(const Pathname& pathname); 83 84 // Returns true if pathname refers to no filesystem object, every parent 85 // directory either exists, or is also absent. 86 virtual bool IsAbsent(const Pathname& pathname); 87 88 virtual std::string TempFilename(const Pathname &dir, 89 const std::string &prefix); 90 91 // A folder appropriate for storing temporary files (Contents are 92 // automatically deleted when the program exists) 93 virtual bool GetTemporaryFolder(Pathname &path, bool create, 94 const std::string *append); 95 96 virtual bool GetFileSize(const Pathname& path, size_t* size); 97 virtual bool GetFileTime(const Pathname& path, FileTimeType which, 98 time_t* time); 99 100 // Returns the path to the running application. 101 virtual bool GetAppPathname(Pathname* path); 102 103 virtual bool GetAppDataFolder(Pathname* path, bool per_user); 104 105 // Get a temporary folder that is unique to the current user and application. 106 virtual bool GetAppTempFolder(Pathname* path); 107 108 virtual bool GetDiskFreeSpace(const Pathname& path, int64 *freebytes); 109 110 // Returns the absolute path of the current directory. 111 virtual Pathname GetCurrentDirectory(); 112 113 private: 114 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) 115 static char* provided_app_data_folder_; 116 static char* provided_app_temp_folder_; 117 #else 118 static char* app_temp_path_; 119 #endif 120 121 static char* CopyString(const std::string& str); 122 }; 123 124 } // namespace rtc 125 126 #endif // WEBRTC_BASE_UNIXFILESYSTEM_H_ 127