aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/files.js
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2013-07-16 11:07:54 +0100
committerStruan Donald <struan@exo.org.uk>2013-07-16 11:07:54 +0100
commit4b8f24a725eb40cd35e6af5420ad4e8f85ece8d5 (patch)
treea561c422db3d9c82893cb92f43e89ea069ae42d8 /src/js/files.js
parentf04fd59a370153a7ab9f1c4b60bf04c58403890a (diff)
On android we access photos directly on the file system rather than in
their own app sandbox as on iOS so we need to copy files instead of moving them as otherwise we end up deleting people's photos which would be bad. As part of this we should avoid trying to copy or move a file on to itself as that fails so check that the source and destination files aren't the same. This should sort out the problems in #43.
Diffstat (limited to 'src/js/files.js')
-rw-r--r--src/js/files.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/js/files.js b/src/js/files.js
index a3a6458..583011a 100644
--- a/src/js/files.js
+++ b/src/js/files.js
@@ -26,6 +26,25 @@
});
},
+ copyURI: function (srcURI, dest ) {
+
+ var fileEntry;
+ return getFileFromURI(srcURI)
+ .pipe( function (file) {
+ fileEntry = file;
+
+ return getFileSystem();
+ })
+ .pipe( function (filesystem) {
+ console.log('Filesystem returned: ' + filesystem);
+
+ return getDirectory(filesystem.root, CONFIG.FILES_DIR, {create: true});
+ })
+ .pipe( function(directory) {
+ return copyFile( fileEntry, directory );
+ });
+ },
+
deleteURI: function (uri) {
console.log('Deleting URI: ' + uri);
@@ -122,6 +141,25 @@
return move.promise();
}
+ function copyFile (src, dest, options) {
+
+ console.log( 'copying file ' + src.fullPath + ' to ' + dest.fullPath );
+
+ var copy = $.Deferred();
+
+ var destPath = dest.fullPath + '/' + src.name;
+ var srcPath = src.fullPath + '';
+ if ( srcPath === destPath ) {
+ console.log('not copying because files are the same');
+ copy.resolve( src );
+ } else {
+ console.log('paths differ so copying');
+ src.copyTo( dest, null, copy.resolve, copy.reject);
+ }
+
+ return copy.promise();
+ }
+
function getFileFromURI(uri) {
console.log( 'getting file from uri ' + uri );