Jelajahi Sumber

- use internal temp directory
- always try to delete temp file

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>

tobiasKaminsky 6 tahun lalu
induk
melakukan
c3b65814df

+ 10 - 11
src/main/java/com/owncloud/android/operations/UploadFileOperation.java

@@ -543,7 +543,8 @@ public class UploadFileOperation extends SyncOperation {
             } catch (FileNotFoundException e) {
                 // this basically means that the file is on SD card
                 // try to copy file to temporary dir if it doesn't exist
-                String temporalPath = FileStorageUtils.getTemporalPath(mAccount.name) + mFile.getRemotePath();
+                String temporalPath = FileStorageUtils.getInternalTemporalPath(mAccount.name, mContext) +
+                        mFile.getRemotePath();
                 mFile.setStoragePath(temporalPath);
                 temporalFile = new File(temporalPath);
 
@@ -782,7 +783,8 @@ public class UploadFileOperation extends SyncOperation {
             } catch (FileNotFoundException e) {
                 // this basically means that the file is on SD card
                 // try to copy file to temporary dir if it doesn't exist
-                String temporalPath = FileStorageUtils.getTemporalPath(mAccount.name) + mFile.getRemotePath();
+                String temporalPath = FileStorageUtils.getInternalTemporalPath(mAccount.name, mContext) +
+                        mFile.getRemotePath();
                 mFile.setStoragePath(temporalPath);
                 temporalFile = new File(temporalPath);
 
@@ -900,7 +902,7 @@ public class UploadFileOperation extends SyncOperation {
         RemoteOperationResult result = null;
 
         if (mLocalBehaviour == FileUploader.LOCAL_BEHAVIOUR_COPY && !mOriginalStoragePath.equals(expectedPath)) {
-            String temporalPath = FileStorageUtils.getTemporalPath(mAccount.name) + mFile.getRemotePath();
+            String temporalPath = FileStorageUtils.getInternalTemporalPath(mAccount.name, mContext) + mFile.getRemotePath();
             mFile.setStoragePath(temporalPath);
             File temporalFile = new File(temporalPath);
 
@@ -939,19 +941,11 @@ public class UploadFileOperation extends SyncOperation {
         switch (mLocalBehaviour) {
             case FileUploader.LOCAL_BEHAVIOUR_FORGET:
             default:
-                String temporalPath = FileStorageUtils.getTemporalPath(mAccount.name) + mFile.getRemotePath();
-                if (mOriginalStoragePath.equals(temporalPath)) {
-                    // delete local file is was pre-copied in temporary folder (see .ui.helpers.UriUploader)
-                    temporalFile = new File(temporalPath);
-                    temporalFile.delete();
-                }
                 mFile.setStoragePath("");
                 saveUploadedFile(client);
                 break;
 
             case FileUploader.LOCAL_BEHAVIOUR_DELETE:
-                Log_OC.d(TAG, "Delete source file");
-
                 originalFile.delete();
                 getStorageManager().deleteFileInMediaScan(originalFile.getAbsolutePath());
                 saveUploadedFile(client);
@@ -985,6 +979,11 @@ public class UploadFileOperation extends SyncOperation {
                 FileDataStorageManager.triggerMediaScan(newFile.getAbsolutePath());
                 break;
         }
+
+        // delete temporal file
+        String temporalPath = FileStorageUtils.getInternalTemporalPath(mAccount.name, mContext) + mFile.getRemotePath();
+        temporalFile = new File(temporalPath);
+        temporalFile.delete();
     }
 
     /**

+ 16 - 0
src/main/java/com/owncloud/android/utils/FileStorageUtils.java

@@ -20,6 +20,7 @@
 package com.owncloud.android.utils;
 
 import android.accounts.Account;
+import android.content.Context;
 import android.net.Uri;
 import android.util.Log;
 import android.webkit.MimeTypeMap;
@@ -96,6 +97,21 @@ public final class FileStorageUtils {
         // that can be in the accountName since 0.1.190B
     }
 
+    /**
+     * Get absolute path to tmp folder inside app folder for given accountName.
+     */
+    public static String getInternalTemporalPath(String accountName, Context context) {
+        return context.getFilesDir()
+                + File.separator
+                + MainApp.getDataFolder()
+                + File.separator
+                + "tmp"
+                + File.separator
+                + Uri.encode(accountName, "@");
+        // URL encoding is an 'easy fix' to overcome that NTFS and FAT32 don't allow ":" in file names,
+        // that can be in the accountName since 0.1.190B
+    }
+
     /**
      * Optimistic number of bytes available on sd-card. accountName is ignored.
      *