blob: 0ed36b43346a55b1b025b43afcdb42c41aa4b1c8 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001/*
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
Henrik Kjellanderc0362762017-06-29 08:03:04 +020011#ifndef WEBRTC_RTC_BASE_UNIXFILESYSTEM_H_
12#define WEBRTC_RTC_BASE_UNIXFILESYSTEM_H_
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000013
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020014#include <sys/types.h>
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000015
kjellanderf1c5ebf2017-06-30 05:27:14 -070016#include "webrtc/rtc_base/fileutils.h"
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020017
18namespace rtc {
19
20class UnixFilesystem : public FilesystemInterface {
21 public:
22 UnixFilesystem();
23 ~UnixFilesystem() override;
24
25#if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC)
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 // 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.
39 bool DeleteFile(const Pathname& filename) override;
40
41 // Creates a directory. This will call itself recursively to create /foo/bar
42 // even if /foo does not exist. All created directories are created with the
43 // given mode.
44 // Returns TRUE if function succeeds
45 virtual bool CreateFolder(const Pathname &pathname, mode_t mode);
46
47 // As above, with mode = 0755.
48 bool CreateFolder(const Pathname& pathname) override;
49
50 // This moves a file from old_path to new_path, where "file" can be a plain
51 // file or directory, which will be moved recursively.
52 // Returns true if function succeeds.
53 bool MoveFile(const Pathname& old_path, const Pathname& new_path) override;
54
55 // Returns true if a pathname is a directory
56 bool IsFolder(const Pathname& pathname) override;
57
58 // Returns true of pathname represents an existing file
59 bool IsFile(const Pathname& pathname) override;
60
61 // Returns true if pathname refers to no filesystem object, every parent
62 // directory either exists, or is also absent.
63 bool IsAbsent(const Pathname& pathname) override;
64
65 std::string TempFilename(const Pathname& dir,
66 const std::string& prefix) override;
67
68 // A folder appropriate for storing temporary files (Contents are
69 // automatically deleted when the program exists)
70 bool GetTemporaryFolder(Pathname& path,
71 bool create,
72 const std::string* append) override;
73
74 bool GetFileSize(const Pathname& path, size_t* size) override;
75
76 private:
77#if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC)
78 static char* provided_app_data_folder_;
79 static char* provided_app_temp_folder_;
80#else
81 static char* app_temp_path_;
82#endif
83
84 static char* CopyString(const std::string& str);
85};
86
87} // namespace rtc
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000088
Henrik Kjellanderc0362762017-06-29 08:03:04 +020089#endif // WEBRTC_RTC_BASE_UNIXFILESYSTEM_H_