From 4b8f24a725eb40cd35e6af5420ad4e8f85ece8d5 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 16 Jul 2013 11:07:54 +0100 Subject: 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. --- src/js/files.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/js/files.js') 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 ); -- cgit v1.2.3