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

Feature Request: Support Files.move(...) #339

Closed
Nyamiou opened this issue Dec 16, 2023 · 4 comments
Closed

Feature Request: Support Files.move(...) #339

Nyamiou opened this issue Dec 16, 2023 · 4 comments
Labels
good first issue Good for newcomers

Comments

@Nyamiou
Copy link

Nyamiou commented Dec 16, 2023

When doing Files.move(...), Java will go through CopyMoveHelper.moveToForeignTarget(...) which has a private method convertMoveToCopyOptions(...) which will always add StandardCopyOption.COPY_ATTRIBUTES then in the other private method copyToForeignTarget(...) it will lead it to go through the if (opts.copyAttributes) path and ultimately call the view.setTimes(...) method which unfortunately in this library contains:

    /**
     * Unsupported operation, write operations are not supported.
     */
    @Override
    public void setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTime createTime) {
        throw new UnsupportedOperationException(
            "write operations are not supported, please submitted a feature request explaining your use case");
    }

I can workaround it for now by doing a Files.copy(...) and then Files.delete(...) since the time attributes are not critical. But I would appreciate if you could consider it for future releases.

Thank you.

@Nyamiou Nyamiou changed the title Files.move(...) is failing because S3BasicFileAttributeView Files.move(...) is failing because S3FileAttributeView.setTimes(...) is unsupported Dec 16, 2023
@Nyamiou Nyamiou changed the title Files.move(...) is failing because S3FileAttributeView.setTimes(...) is unsupported Feature Request: Files.move(...) is failing because S3FileAttributeView.setTimes(...) is unsupported Dec 16, 2023
@Nyamiou Nyamiou changed the title Feature Request: Files.move(...) is failing because S3FileAttributeView.setTimes(...) is unsupported Feature Request: Support Files.move(...) Dec 16, 2023
@markjschreiber
Copy link
Contributor

Apologies for the delay in responding.

Objects in S3 only have a created time and to change that the object would have to be recreated (basically copied deleted and rewritten) so setTimes isn't really something that can be implemented in any meaningful way. What we could do, to support Files.move() is to remove the code that throws the exception and do nothing instead (no-op) other than logging a warning. We would also want to document that this method call is a no-op.

Simple enough for me (or anyone) to implement, do you see any problems with not being able to actually set the times?

@markjschreiber markjschreiber added the good first issue Good for newcomers label Jan 17, 2024
@Nyamiou
Copy link
Author

Nyamiou commented Jan 22, 2024

I wasn't aware of this limitation on S3. In that case, I think your proposed solution is great. Thank you.

@markjschreiber
Copy link
Contributor

@Nyamiou can you try out this pull request to see if this works for you? #361

@markjschreiber
Copy link
Contributor

PR is merged. I believe it resolves the issue. Let me know if it doesn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants