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

Update Metadata.js #39

Closed
wants to merge 1 commit into from

Conversation

DanielFreiburger
Copy link
Contributor

File was not updated correct after changing "modificationTime" to "lastModifiedDate"

File was not updated correct after changing "modificationTime" to "lastModifiedDate"
@shazron
Copy link
Member

shazron commented Apr 18, 2014

Not sure this is correct. The spec says it should be "modificationTime": http://dev.w3.org/2009/dap/file-system/pub/FileSystem/

The js function that uses Metadata:

Entry.prototype.getMetadata = function(successCallback, errorCallback) {
argscheck.checkArgs('FF', 'Entry.getMetadata', arguments);
var success = successCallback && function(entryMetadata) {
var metadata = new Metadata(entryMetadata);
successCallback(metadata);
};
var fail = errorCallback && function(code) {
errorCallback(new FileError(code));
};
exec(success, fail, "File", "getMetadata", [this.filesystem.__format__(this.fullPath)]);
};

On iOS, it is modificationTime:

result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:@{@"modificationTime": @([modDate timeIntervalSince1970] * 1000), @"size": @(size)}];

But, on Android it's lastModifiedDate:

metadata.put("lastModifiedDate", file.lastModified());

So I think this is a bug in Android.

@shazron
Copy link
Member

shazron commented Apr 18, 2014

Also, Android has all these extra properties that are not part of the spec:

metadata.put("type", FileHelper.getMimeType(file.getAbsolutePath(), cordova));
metadata.put("name", file.getName());
metadata.put("fullPath", inputURL.fullPath);

@alessandronunes
Copy link

What about the "com.apple.MobileBackup"? I'm trying to set it but neither the success or the fail callback function is being called.

@shazron
Copy link
Member

shazron commented Apr 23, 2014

@alessandronunes this was a bug in the File plugin. It should be fixed in the dev branch, or wait an hour or so when the new plugin version gets published.

@shazron
Copy link
Member

shazron commented Apr 23, 2014

Woops, it just happened - plugins are released! http://cordova.apache.org/news/2014/04/23/plugins.release.html

@alessandronunes
Copy link

Thanks Shaz! Do you know when, usually, Phonegap gets updated after this?

@shazron
Copy link
Member

shazron commented Apr 23, 2014

For Plugins, we aim for a weekly release, however prior to this, our last one was over 5 weeks ago I think. For the core platforms, we used to aim for a monthly release, but now it is indeterminate.

@alessandronunes
Copy link

Thanks again. Good job!

@clelland
Copy link
Contributor

It looks like the mobilespec test for this just checked that metadata.modificationTime instanceof Date was true. Unfortunately,

new Date(undefined) instanceof Date === true

So it never failed. :(

Definitely a bug in Android; I'll fix that for the next release.

@DanielFreiburger
Copy link
Contributor Author

In File.js always "lastModifiedDate" is used,
in Metadata.js always "modificationTime" is used
but there is no correlation between these two.
So one of the two must be wrong.
After creating a correlation between the two by changing Metadata.js line 29 from:
this.modificationTime = new Date(metadata.modificationTime);
to
this.modificationTime = new Date(metadata.lastModifiedDate);
everything is fine.

@shazron
Copy link
Member

shazron commented May 28, 2014

Hmm File.js represents the File interface in the File API spec: http://www.w3.org/TR/FileAPI/#file and it does specify lastModifiedDate, which is correct.

FileEntry.file is correct, it should return a File object, so that's fine -- but it has a bug in it in how it constructs the File object. Since it is calling the getMetadata function, the call to get the date should be f.modificationTime instead of f.lastModifiedDate (since the returned object to the successcallback is a Metadata object):

var file = new File(f.name, localURL, f.type, f.lastModifiedDate, f.size);

@clelland
Copy link
Contributor

I've created CB-6922 for this -- it was certainly a problem in Android.

The trouble, as Shaz identified, is that both the File API and the FileEntry API have a method to get metadata for a file, and they use inconsistent names for the timestamp.

I've committed a different fix, which just makes use of getFileMetadata for both functions (on all platforms) and changes the key names in JavaScript before instantiating the Metadata object. This should ensure consistent behaviour across all platforms.

@clelland
Copy link
Contributor

This fix has been committed, and the tests are ensuring that the correct keys appear in the callbacks. You can close this pull request, I think.

@asfgit asfgit closed this in f6fdb4a Jun 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants