-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
Fix os.copy and os.move directories to root #267
Fix os.copy and os.move directories to root #267
Conversation
with createFolders = true
with createFolders = true
directories to root
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable. Thank you!
You can ignore the failing test runner for macosx. It's independent of this issue and should be fixed once I merge #266.
try { | ||
os.move(root / "test" / "dir", root, createFolders = true) | ||
} catch { | ||
case e: PathError.AbsolutePathOutsideRoot.type => throw e | ||
case NonFatal(_) => () | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also use an intercept
here, to declare the concrete expected exception.
https://github.com/com-lihaoyi/utest?tab=readme-ov-file#intercept
Looks good to me. @kiendang if you could update the test to use intercept I can merge this and close the bounty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. We should cut a new release once this is merged.
@lefou @lihaoyi I did use |
More on the error with using pattern matching syntax inside a intercept block, this would result in an error intercept[...] {
os.list(os.root("/", fileSystem)).collect(os.move.matching { case p / "test" => p })
} while this wouldn't intercept[...] {
List(os.root("/", fileSystem)).collect(os.move.matching { case p => p })
} |
Which error do you mean specifically? The This test works for me with Scala 2.13: test("moveMatchingToRootDirectoryShouldFail") {
withCustomFs { fileSystem =>
intercept[FileAlreadyExistsException] {
os.list(os.root("/", fileSystem)).collect(os.move.matching { case p / "test" => p })
}
}
} But with Scala 2.12.17, I see the same compile error as the CI:
|
I tested on Scala 3.3.1 and jdk 17. For me it also doesn't throw |
This reverts commit 269a4d2.
Also yes I got a similar compilation error. |
Looks good to me. Thanks @kiendang! Can send me an email at haoyi.sg@gmail.com with your bank details for the bounty |
Fix an error where
os.copy(createFolders = true, mergeFolders = true)
a directory to root throw aPathError.AbsolutePathOutsideRoot
due to calling/up
on root.The same issue (calling
/up
on root) is seen inos.move
,os.copy.matching
andos.move.matching
so this fixes those as well. In case ofos.move
andos.move.matching
moving a directory to root should throw an error anyway but at least now it throws the correct underlying error instead ofAbsolutePathOutsideRoot
.Fix #167
Pull request: #267