Skip to content

Commit ecd623c

Browse files
committed
Add check for move/copy destination parent
1 parent 1522b9b commit ecd623c

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

endpoints_files.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,18 @@ func performMoveCopyOperation(operation *fileOperation) (int, string) {
219219
return http.StatusInternalServerError, "Internal Server Error! " + err.Error()
220220
}
221221

222+
// Ensure parent directory of dest exists and is a directory
223+
parent := filepath.Dir(operation.Dest)
224+
if parentStat, pErr := os.Stat(parent); pErr != nil {
225+
if os.IsNotExist(pErr) {
226+
return http.StatusBadRequest, "Destination parent folder does not exist!"
227+
}
228+
log.Println("An error occurred checking destination parent "+parent, pErr)
229+
return http.StatusInternalServerError, "Internal Server Error! " + pErr.Error()
230+
} else if !parentStat.IsDir() {
231+
return http.StatusBadRequest, "Destination parent is not a folder!"
232+
}
233+
222234
// Perform move/copy operation
223235
if operation.Operation == "mv" {
224236
err = os.Rename(operation.Src, operation.Dest)

0 commit comments

Comments
 (0)