Skip to content

Commit a45b0b6

Browse files
authored
Update MongoDB_FileWorkspaceMap.java
1 parent 5c64566 commit a45b0b6

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/main/java/picoded/dstack/mongodb/MongoDB_FileWorkspaceMap.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,51 @@ public void backend_removeFile(String oid, String filepath) {
708708

709709
// Folder Pathing support
710710
//--------------------------------------------------------------------------
711+
/**
712+
* [Internal use, to be extended in future implementation]
713+
*
714+
* Copy a given file within the system
715+
*
716+
* WARNING: Copy operations are typically not "atomic" in nature, and can be unsafe where
717+
* missing files / corrupted data can occur when executed concurrently with other operations.
718+
*
719+
* In general "S3-like" object storage will not safely support atomic Copy operations.
720+
* Please use the `atomicCopySupported()` function to validate if such operations are supported.
721+
*
722+
* Note that both source, and destionation folder will be normalized to include the "/" path.
723+
* This operation may in effect function as a rename
724+
* If the destionation folder exists with content, the result will be merged. With the sourceFolder files, overwriting on conflicts.
725+
*
726+
* @param ObjectID of workspace
727+
* @param sourceFolder
728+
* @param destinationFolder
729+
*
730+
*/
731+
public void backend_copyFolderPath(final String oid, final String sourceFolder,
732+
final String destinationFolder) {
733+
734+
// Get the list of valid sub paths in the sourceFolder
735+
Set<String> subPath = backend_getFileAndFolderPathSet(oid, sourceFolder, -1, -1);
736+
737+
//Special handling for the edge case where you try to move an empty folder and it just get removed instead
738+
if(subPath.isEmpty() && sourceFolder != null && sourceFolder !="" && sourceFolder != "/" && sourceFolder.length() > 0){
739+
subPath.add("/");
740+
}
741+
742+
743+
// Lets sync up all the folders first
744+
for (String dir : subPath) {
745+
if (dir.endsWith("/")) {
746+
backend_ensureFolderPath(oid, destinationFolder + dir);
747+
}
748+
}
749+
// Lets sync up all the files next
750+
for (String file : subPath) {
751+
if (file.endsWith("/") == false) {
752+
backend_copyFile(oid, sourceFolder + file, destinationFolder + file);
753+
}
754+
}
755+
}
711756

712757
/**
713758
* [Internal use, to be extended in future implementation]

0 commit comments

Comments
 (0)