-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
UnsupportedOperationException when using copy-tree
with zip file path as source
#108
Comments
copy-tree has been written with normal files in mind. Have you tried the unzip function? jar files are basically just zip files |
Thank you for the feedback. Yes, I know the A possibility for sub-tree extraction could be an option named {:include-entry? (constantly true)
:resolve-entry (fn [^Path output-path ^Path entry-path]
(.resolve output-path entry-path))} and for sub tree extraction, they would be (where {:include-entry? (fn [^Path entry-path]
(fs/starts-with? entry-path sub-tree-root))
:resolve-entry (fn [^Path output-path ^Path entry-path]
(.resolve output-path (.relativize sub-tree-root entry-path)))} |
Sounds like an idea. With Then we could have: |
nice. |
yes please! |
Hello,
I stumbled over the following problem when trying to copy a sub-tree with
copy-tree
from a jar resources to the the file system. You can reproduce the error with the following code snippet in a REPL in thebabashka/fs
project (The first resource to be found with the name "META-INF" is in the nrepl jar).When evaluating the code snippet above, I get an
UnsupportedOperationException
exception.The exception comes one of the two
(path to rel)
calls inside thecopy-tree
function. The dyadic version of thepath
function transforms its argument as Files to resolve them and then transforms them back as Paths. However ZipPaths cannot be transformed to File instances and therefore call fails with theUnsupportedOperationException
exception.I tried to change the definition
path
(dyadic) as follows:But it still does not work because we get now a
ProviderMismatchException
when callingPath#resolve
. The reason is that ZipPaths and UnixPaths cannot be combined/resolved/relatived with each others (I am on MacOS, but I guess it is the same problem with Windows).Finally, I tried the following function to use instead of the
Path#resolve
call. The function resolve component by component when the paths cannot be resolved directly.It works in my specific case, because the child path is always relative and relative ZipPaths are built similarly to UnixPaths. However I do not believe that it is a good solution as combinations between Paths from different FileSystems are always ad-hoc. It is probably why the JRE raises a
ProviderMismatchException
exception in the first place.I still would like to use
copy-tree
to extract resources from a jar and I see the following alternatives.copy-tree
method in my project and replacing the two(path to rel)
calls by a custom resolving function for the ad-hoc resolving of a ZipPath relative path against a UnixPath and renaming it to something likeextract-tree-from-zip-file
.copy-tree
to pass a custom resolving function withpath
as the default. In this case,bababshka.fs
could even offer the specific resolving function to copy from a zip file to a unix (and windows) directory.What do you think? Is this use case (copying out of a zip file to the file system) important enough to warrant the introduction of a new option? Would such option be a good API?
You can have a look at the code above in the following branch: https://github.com/codesmith-gmbh/fs/tree/stan/path-resolve
The text was updated successfully, but these errors were encountered: