-
Notifications
You must be signed in to change notification settings - Fork 2
/
FoundationFileOperations.java
116 lines (92 loc) · 2.73 KB
/
FoundationFileOperations.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package foundationdb_fslayer.fdb;
import com.apple.foundationdb.directory.DirectorySubspace;
import foundationdb_fslayer.fdb.object.Attr;
import foundationdb_fslayer.permissions.PermissionManager;
import java.util.List;
import java.util.Optional;
public interface FoundationFileOperations {
/**
* Read a file.
*
* @param path file path
* @param userId
* @return encoded byte representation of the file content
*/
byte[] read(String path, long offset, long size, long userId);
default byte[] read(String path, long userId){
return read(path, 0, getFileSize(path), userId);
}
/**
* Write to a file
* @param path file path
* @param data data to be added to file
* @param userId
* @return
*/
boolean write(String path, byte[] data, long offset, long userId);
default boolean write(String path, byte[] data, int version){
return write(path, data, 0, version);
}
/**
* Remove an empty directory if exists.
*
* @param path list of path strings
* @return a boolean value determining whether removing the directory is successful
*/
boolean rmdir(String path, long uid);
/**
* Create a new directory matching the provided path under the given directory.
*
* @param path list of path strings
* @return The directory subspace of the newly created directory
*/
DirectorySubspace mkdir(String path, long mode, long uid);
/**
* List all directories under the provided directory.
*
* @param path list of path strings
* @return a list of strings representing all sub-directories under the current directory
*/
List<String> ls(String path, long userId);
/**
* Clear content of file
*
* @param file file path
*/
boolean clearFileContent(String file, long userId);
/**
* Creates a new empty file at the given path
* returns false on failure
*/
boolean createFile(String path, long userId);
/**
* Get the attributes of this file or directory
*/
Attr getAttr(String path);
/**
* Set the time on a file
*/
boolean setFileTime(Long timestamp, String path);
/**
* Returns a file's size
*/
int getFileSize(String path);
/**
* Sets a file's size to the given length
* Will delete data on shrink, and do nothing on grow
*/
boolean truncate(String path, long size, long userId);
/**
* Sets a file's mode to the given value
*/
boolean chmod(String path, long mode, long userId);
/**
* Set the UID / GID of the file for linux
* permissions.
*/
boolean chown(String path, long uid, long gid);
int open(String path, int flags);
boolean move(String oldPath, String newPath, long userId);
void initRootIfNeeded();
Optional<PermissionManager> login(String username, String password);
}