diff --git a/app/api/Datasets.scala b/app/api/Datasets.scala index b59e67e8a..f43aee69b 100644 --- a/app/api/Datasets.scala +++ b/app/api/Datasets.scala @@ -716,7 +716,15 @@ class Datasets @Inject()( } Logger.debug("----- Adding file to dataset completed") } else { + val foldersContainingFile = folders.findByFileId(file.id).sortBy(_.name) Logger.debug("File was already in dataset.") + val foldersContainingFile = folders.findByFileId(file.id).sortBy(_.name) + Logger.debug("Remove file from folders in dataset") + folders.get(foldersContainingFile).foreach(folder => { + if (folder.parentDatasetId == dsId){ + folders.removeFile(folder.id, fileId) + } + }) } }