abashev / vfs-s3

Amazon S3 driver for Apache commons-vfs (Virtual File System) project
Apache License 2.0
93 stars 50 forks source link

S3FileObject#doSetLastModifiedTime doesn't set last modified time in uploaded S3 object #26

Closed flicken closed 8 years ago

flicken commented 9 years ago

We're using this library to mirror a remote FTP site to S3, and would like to compare the last modified timestamp of the files in FTP to the last modified timestamp in S3, to ensure that the timestamps are the same.

However, setting last modified time on S3FileObject doesn't change the timestamp on the S3 server.
Per documentation (see also discussion), it's impossible. A workaround is to set a custom metadata field (e.g. x-amz-meta-last-modified).

Would you be open to a pull request that sets this metadata on upload and uses it as the last modified date if set?

abashev commented 9 years ago

PRs' are always welcome 😊 Do it and I'll release 2.3.1 with that fix.

ptahchiev commented 8 years ago

I'm getting a Null-pointer and I believe it's related to this one. Basically I create a new VFS FileObject for my bucket "s3://my-bucket", then I do:

fileObject.getContent().getLastModifiedTime()

and I get this Null-pointer exception:

Caused by: org.apache.commons.vfs2.FileSystemException: Could not determine the last modified timestamp of "s3://my-bucket/".
    at org.apache.commons.vfs2.provider.DefaultFileContent.getLastModifiedTime(DefaultFileContent.java:179)
    at com.mycompany.core.repository.impl.MyRepositoryImpl.compileProperties(MYRepositoryImpl.java:1359)
    ... 114 more
Caused by: java.lang.NullPointerException
    at com.intridea.io.vfs.provider.s3.S3FileObject.doGetLastModifiedTime(S3FileObject.java:190)
    at org.apache.commons.vfs2.provider.DefaultFileContent.getLastModifiedTime(DefaultFileContent.java:175)
    ... 115 more