1 /*
2 * This file is part of Waarp Project (named also Waarp or GG).
3 *
4 * Copyright (c) 2019, Waarp SAS, and individual contributors by the @author
5 * tags. See the COPYRIGHT.txt in the distribution for a full listing of
6 * individual contributors.
7 *
8 * All Waarp Project is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY
14 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * Waarp . If not, see <http://www.gnu.org/licenses/>.
19 */
20 package org.waarp.common.file;
21
22 import org.waarp.common.command.exception.CommandAbstractException;
23 import org.waarp.common.command.exception.Reply530Exception;
24
25 import java.util.List;
26
27 /**
28 * Interface for Directory support
29 */
30 public interface DirInterface {
31 /**
32 * FileInterface separator for external
33 */
34 String SEPARATOR = "/";
35
36 /**
37 * FileInterface separator for external
38 */
39 char SEPARATORCHAR = '/';
40
41 /**
42 * @return the current value of Options for MLSx
43 */
44 OptsMLSxInterface getOptsMLSx();
45
46 /**
47 * Set empty this FtpDir, mark it unReady.
48 */
49 void clear();
50
51 /**
52 * Init DirInterface after authentication is done
53 */
54 void initAfterIdentification();
55
56 /**
57 * Check if the authentication is correct
58 *
59 * @throws Reply530Exception
60 */
61 void checkIdentify() throws Reply530Exception;
62
63 /**
64 * @return the FtpSession
65 */
66 SessionInterface getSession();
67
68 // **************** Directory part **************************
69
70 /**
71 * Construct and Check if the given path is valid from business point of
72 * view
73 * (see {@link AuthInterface})
74 *
75 * @param path
76 *
77 * @return the construct and validated path (could be different than the one
78 * given as argument, example: '..'
79 * are removed)
80 *
81 * @throws CommandAbstractException
82 */
83 String validatePath(String path) throws CommandAbstractException;
84
85 /**
86 * Check if the given path is valid in the sens starting from the current
87 * directory
88 *
89 * @param path
90 *
91 * @return True if OK
92 */
93 boolean isPathInCurrentDir(String path);
94
95 /**
96 * @return the current PWD
97 *
98 * @throws CommandAbstractException
99 */
100 String getPwd() throws CommandAbstractException;
101
102 /**
103 * Change directory with the one given as argument
104 *
105 * @param path
106 *
107 * @return True if the change is valid
108 *
109 * @throws CommandAbstractException
110 */
111 boolean changeDirectory(String path) throws CommandAbstractException;
112
113 /**
114 * Change directory with the one given as argument without checking
115 * existence
116 *
117 * @param path
118 *
119 * @return True if the change is valid
120 *
121 * @throws CommandAbstractException
122 */
123 boolean changeDirectoryNotChecked(String path)
124 throws CommandAbstractException;
125
126 /**
127 * Change for parent directory
128 *
129 * @return True if the change is valid
130 *
131 * @throws CommandAbstractException
132 */
133 boolean changeParentDirectory() throws CommandAbstractException;
134
135 /**
136 * Create the directory associated with the String as path
137 *
138 * @param directory
139 *
140 * @return the full path of the new created directory
141 *
142 * @throws CommandAbstractException
143 */
144 String mkdir(String directory) throws CommandAbstractException;
145
146 /**
147 * Delete the directory associated with the String as path
148 *
149 * @param directory
150 *
151 * @return the full path of the new deleted directory
152 *
153 * @throws CommandAbstractException
154 */
155 String rmdir(String directory) throws CommandAbstractException;
156
157 /**
158 * Is the given path a directory and exists
159 *
160 * @param path
161 *
162 * @return True if it is a directory and it exists
163 *
164 * @throws CommandAbstractException
165 */
166 boolean isDirectory(String path) throws CommandAbstractException;
167
168 /**
169 * Is the given path a file and exists
170 *
171 * @param path
172 *
173 * @return True if it is a file and it exists
174 *
175 * @throws CommandAbstractException
176 */
177 boolean isFile(String path) throws CommandAbstractException;
178
179 /**
180 * Return the Modification time for the path
181 *
182 * @param path
183 *
184 * @return the Modification time as a String YYYYMMDDHHMMSS.sss
185 *
186 * @throws CommandAbstractException
187 */
188 String getModificationTime(String path) throws CommandAbstractException;
189
190 /**
191 * List all files from the given path (could be a file or a directory)
192 *
193 * @param path
194 *
195 * @return the list of paths
196 *
197 * @throws CommandAbstractException
198 */
199 List<String> list(String path) throws CommandAbstractException;
200
201 /**
202 * List all files with other informations from the given path (could be a
203 * file
204 * or a directory)
205 *
206 * @param path
207 * @param lsFormat True if ls Format, else MLSx format
208 *
209 * @return the list of paths and other informations
210 *
211 * @throws CommandAbstractException
212 */
213 List<String> listFull(String path, boolean lsFormat)
214 throws CommandAbstractException;
215
216 /**
217 * Give for 1 file all informations from the given path (could be a file or
218 * a
219 * directory)
220 *
221 * @param path
222 * @param lsFormat True if ls Format, else MLSx format
223 *
224 * @return the path and other informations
225 *
226 * @throws CommandAbstractException
227 */
228 String fileFull(String path, boolean lsFormat)
229 throws CommandAbstractException;
230
231 /**
232 * @return the free space of the current Directory
233 *
234 * @throws CommandAbstractException
235 */
236 long getFreeSpace() throws CommandAbstractException;
237
238 // **************** Unique FileInterface part **************************
239
240 /**
241 * Create a new File
242 *
243 * @param path
244 * @param append
245 *
246 * @return the new FileInterface
247 *
248 * @throws CommandAbstractException
249 */
250 FileInterface newFile(String path, boolean append)
251 throws CommandAbstractException;
252
253 /**
254 * Set a path as the current FileInterface
255 *
256 * @param path
257 * @param append True if this file is supposed to be in append mode
258 * (APPE), False in any other cases
259 *
260 * @return the FileInterface if it is correctly initiate
261 *
262 * @throws CommandAbstractException
263 */
264 FileInterface setFile(String path, boolean append)
265 throws CommandAbstractException;
266
267 /**
268 * Set a new unique path as the current FileInterface from the current
269 * Directory (STOU)
270 *
271 * @return the FileInterface if it is correctly initiate
272 *
273 * @throws CommandAbstractException
274 */
275 FileInterface setUniqueFile() throws CommandAbstractException;
276
277 /**
278 * @return True if the current FileInterface is ready for reading
279 *
280 * @throws CommandAbstractException
281 */
282 boolean canRead() throws CommandAbstractException;
283
284 /**
285 * @return True if the current FileInterface is ready for writing
286 *
287 * @throws CommandAbstractException
288 */
289 boolean canWrite() throws CommandAbstractException;
290
291 /**
292 * @return True if the current FileInterface exists
293 *
294 * @throws CommandAbstractException
295 */
296 boolean exists() throws CommandAbstractException;
297
298 /**
299 * Get the CRC of the given FileInterface
300 *
301 * @param path
302 *
303 * @return the CRC
304 *
305 * @throws CommandAbstractException
306 */
307 long getCRC(String path) throws CommandAbstractException;
308
309 /**
310 * Get the MD5 of the given FileInterface
311 *
312 * @param path
313 *
314 * @return the MD5
315 *
316 * @throws CommandAbstractException
317 */
318 byte[] getMD5(String path) throws CommandAbstractException;
319
320 /**
321 * Get the SHA-1 of the given FileInterface
322 *
323 * @param path
324 *
325 * @return the SHA-1
326 *
327 * @throws CommandAbstractException
328 */
329 byte[] getSHA1(String path) throws CommandAbstractException;
330
331 /**
332 * Get the Digest of the given FileInterface
333 *
334 * @param path
335 * @param algo algorithm of Digest among CRC32, ADLER32, MD5, MD2,
336 * SHA-1, SHA-256, SHA-384, SHA-512
337 *
338 * @return the Digest
339 *
340 * @throws CommandAbstractException
341 */
342 byte[] getDigest(String path, String algo) throws CommandAbstractException;
343 }