Skip to content

Commit 386875a

Browse files
committed
Polyfill basic copy / move operations
1 parent 6eb69a8 commit 386875a

1 file changed

Lines changed: 38 additions & 6 deletions

File tree

src/main/java/picoded/dstack/core/Core_FileWorkspaceMap.java

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ public void backend_ensureFolderPath(final String oid, final String folderPath)
299299
*/
300300
public void backend_moveFile(final String oid, final String sourceFile,
301301
final String destinationFile) {
302-
throw new RuntimeException("Missing backend implementation");
302+
backend_copyFile(oid, sourceFile, destinationFile);
303+
backend_removeFile(oid, sourceFile);
303304
}
304305

305306
/**
@@ -324,7 +325,23 @@ public void backend_moveFile(final String oid, final String sourceFile,
324325
*/
325326
public void backend_moveFolderPath(final String oid, final String sourceFolder,
326327
final String destinationFolder) {
327-
throw new RuntimeException("Missing backend implementation");
328+
// Get the list of valid sub paths in the sourceFolder
329+
Set<String> subPath = backend_getFileAndFolderPathSet(oid, sourceFolder, -1, -1);
330+
331+
// Lets sync up all the folders first
332+
for(String dir : subPath) {
333+
if(dir.endsWith("/")) {
334+
backend_ensureFolderPath(oid, destinationFolder+subPath);
335+
}
336+
}
337+
// Lets sync up all the files next
338+
for(String file : subPath) {
339+
if(!file.endsWith("/")) {
340+
backend_moveFile(oid, sourceFolder+subPath, destinationFolder+subPath);
341+
}
342+
}
343+
// Lets remove the original folders
344+
backend_removeFolderPath(oid, sourceFolder);
328345
}
329346

330347
// Copy support
@@ -350,7 +367,7 @@ public void backend_moveFolderPath(final String oid, final String sourceFolder,
350367
*/
351368
public void backend_copyFile(final String oid, final String sourceFile,
352369
final String destinationFile) {
353-
throw new RuntimeException("Missing backend implementation");
370+
backend_fileWriteInputStream(oid, destinationFile, backend_fileReadInputStream(oid, sourceFile));
354371
}
355372

356373
/**
@@ -375,7 +392,21 @@ public void backend_copyFile(final String oid, final String sourceFile,
375392
*/
376393
public void backend_copyFolderPath(final String oid, final String sourceFolder,
377394
final String destinationFolder) {
378-
throw new RuntimeException("Missing backend implementation");
395+
// Get the list of valid sub paths in the sourceFolder
396+
Set<String> subPath = backend_getFileAndFolderPathSet(oid, sourceFolder, -1, -1);
397+
398+
// Lets sync up all the folders first
399+
for(String dir : subPath) {
400+
if(dir.endsWith("/")) {
401+
backend_ensureFolderPath(oid, destinationFolder+subPath);
402+
}
403+
}
404+
// Lets sync up all the files next
405+
for(String file : subPath) {
406+
if(!file.endsWith("/")) {
407+
backend_copyFile(oid, sourceFolder+subPath, destinationFolder+subPath);
408+
}
409+
}
379410
}
380411

381412
//
@@ -421,15 +452,16 @@ public long backend_modifiedTimestamp(final String oid, final String filepath) {
421452
//--------------------------------------------------------------------------
422453

423454
/**
424-
* Internal utility function used to filter a path set, and remove items that does not match
455+
* Internal utility function used to filter a path set, and remove items that does not match.
456+
* This is used to help filter raw results, from existing implementation
425457
*
426458
* - its folderPath prefix
427459
* - min/max depth
428460
* - any / file / folder
429461
*
430462
* @param rawSet
431463
* @param folderPath
432-
* @param minDepth
464+
* @param minDepth (0 = all items, 1 = must be in atleast a folder, 2 = folder, inside a folder)
433465
* @param maxDepth
434466
* @param pathType (0 = any, 1 = file, 2 = folder)
435467
* @return

0 commit comments

Comments
 (0)