Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dataset upload: Fix special case in common prefix handling #5534

Merged
merged 4 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
-

### Fixed
-
- Fixed a bug where dataset uploads of zips with just one file inside failed. [#5534](https://github.com/scalableminds/webknossos/pull/5534)

### Removed
-
Expand Down
9 changes: 7 additions & 2 deletions util/src/main/scala/com/scalableminds/util/io/PathUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,17 @@ trait PathUtils extends LazyLogging {
def isFileNameInPrefix(prefix: Path, fileName: String) = prefix.endsWith(Paths.get(fileName).getFileName)

fileNames match {
case head :: tl if tl.isEmpty && isFileNameInPrefix(prefix, head) =>
prefix.subpath(0, prefix.getNameCount - 1)
case head :: tail if tail.isEmpty && isFileNameInPrefix(prefix, head) =>
removeOneName(prefix)
case _ => prefix
}
}

private def removeOneName(path: Path): Path =
if (path.getNameCount == 1) {
Paths.get("")
} else path.subpath(0, path.getNameCount - 1)

def deleteDirectoryRecursively(path: Path): Box[Unit] = {
val directory = new Directory(new File(path.toString))
if (!directory.exists) return Full(())
Expand Down