henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 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(); |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 23 | ~UnixFilesystem() override; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 24 | |
erikchen | 2ca8d5c | 2016-10-05 16:04:33 -0700 | [diff] [blame] | 25 | #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 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 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 37 | // This will attempt to delete the file located at filename. |
| 38 | // It will fail with VERIY if you pass it a non-existant file, or a directory. |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 39 | bool DeleteFile(const Pathname& filename) override; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 40 | |
| 41 | // This will attempt to delete the folder located at 'folder' |
nisse | 0ebdf27 | 2017-01-23 07:43:05 -0800 | [diff] [blame] | 42 | // It DCHECKs and returns false if you pass it a non-existant folder or a |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 43 | // plain file. |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 44 | bool DeleteEmptyFolder(const Pathname& folder) override; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 45 | |
| 46 | // Creates a directory. This will call itself recursively to create /foo/bar |
| 47 | // even if /foo does not exist. All created directories are created with the |
| 48 | // given mode. |
| 49 | // Returns TRUE if function succeeds |
| 50 | virtual bool CreateFolder(const Pathname &pathname, mode_t mode); |
| 51 | |
| 52 | // As above, with mode = 0755. |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 53 | bool CreateFolder(const Pathname& pathname) override; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 54 | |
| 55 | // This moves a file from old_path to new_path, where "file" can be a plain |
| 56 | // file or directory, which will be moved recursively. |
| 57 | // Returns true if function succeeds. |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 58 | bool MoveFile(const Pathname& old_path, const Pathname& new_path) override; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 59 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 60 | // Returns true if a pathname is a directory |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 61 | bool IsFolder(const Pathname& pathname) override; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 62 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 63 | // Returns true of pathname represents an existing file |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 64 | bool IsFile(const Pathname& pathname) override; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 65 | |
| 66 | // Returns true if pathname refers to no filesystem object, every parent |
| 67 | // directory either exists, or is also absent. |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 68 | bool IsAbsent(const Pathname& pathname) override; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 69 | |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 70 | std::string TempFilename(const Pathname& dir, |
| 71 | const std::string& prefix) override; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 72 | |
| 73 | // A folder appropriate for storing temporary files (Contents are |
| 74 | // automatically deleted when the program exists) |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 75 | bool GetTemporaryFolder(Pathname& path, |
| 76 | bool create, |
| 77 | const std::string* append) override; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 78 | |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 79 | bool GetFileSize(const Pathname& path, size_t* size) override; |
| 80 | bool GetFileTime(const Pathname& path, |
| 81 | FileTimeType which, |
| 82 | time_t* time) override; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 83 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 84 | private: |
erikchen | 2ca8d5c | 2016-10-05 16:04:33 -0700 | [diff] [blame] | 85 | #if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 86 | static char* provided_app_data_folder_; |
| 87 | static char* provided_app_temp_folder_; |
| 88 | #else |
| 89 | static char* app_temp_path_; |
| 90 | #endif |
| 91 | |
| 92 | static char* CopyString(const std::string& str); |
| 93 | }; |
| 94 | |
| 95 | } // namespace rtc |
| 96 | |
| 97 | #endif // WEBRTC_BASE_UNIXFILESYSTEM_H_ |