Skip to content

Create bag in place with includeHidden = true #93

@rvanheest

Description

@rvanheest

When I call BagCreator.bagInPlace with includeHidden = true, the call produces a java.nio.file.FileSystemException. In this case it wants to move the newly created data/ folder into itself (data/data/), which isn't possible.

An hour of debugging later I found out that this is because of the following code block:

try(final DirectoryStream<Path> directoryStream = Files.newDirectoryStream(root)){
  for(final Path path : directoryStream){
    if(!path.equals(dataDir) && !Files.isHidden(path) || includeHidden){
      Files.move(path, dataDir.resolve(path.getFileName()));
    }
  }
}

Here if(!path.equals(dataDir) && !Files.isHidden(path) || includeHidden) must actually be if(!path.equals(dataDir) && (!Files.isHidden(path) || includeHidden)) (extra parentheses around !Files.isHidden(path) || includeHidden). This has to do with operator precedence in Java: && binds stronger than ||.

In the test suite I only found a test with includeHidden = false, which works correctly. If you will duplicate that one with includeHidden = true, you will find the same error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions