Просмотр исходного кода

Fixed copy and movement of files to ownCloud local folder with explicit creation of parent directory and target file

David A. Velasco 12 лет назад
Родитель
Сommit
4476c04736

+ 11 - 0
src/com/owncloud/android/operations/SynchronizeFolderOperation.java

@@ -21,6 +21,7 @@ package com.owncloud.android.operations;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.HashMap;
@@ -308,6 +309,15 @@ public class SynchronizeFolderOperation extends RemoteOperation {
                 OutputStream out = null;
                 try {
                     File expectedFile = new File(expectedPath);
+                    File expectedParent = expectedFile.getParentFile();
+                    expectedParent.mkdirs();
+                    if (!expectedParent.isDirectory()) {
+                        throw new IOException("Unexpected error: parent directory could not be created");
+                    }
+                    expectedFile.createNewFile();
+                    if (!expectedFile.isFile()) {
+                        throw new IOException("Unexpected error: target file could not be created");
+                    }                    
                     in = new FileInputStream(originalFile);
                     out = new FileOutputStream(expectedFile);
                     byte[] buf = new byte[1024];
@@ -318,6 +328,7 @@ public class SynchronizeFolderOperation extends RemoteOperation {
                     file.setStoragePath(expectedPath);
                     
                 } catch (Exception e) {
+                    Log.e(TAG, "Exception while copying foreign file " + expectedPath, e);
                     mForgottenLocalFiles.put(file.getRemotePath(), storagePath);
                     file.setStoragePath(null);
                     

+ 9 - 0
src/com/owncloud/android/operations/UploadFileOperation.java

@@ -189,6 +189,15 @@ public class UploadFileOperation extends RemoteOperation {
                         InputStream in = null;
                         OutputStream out = null;
                         try {
+                            File temporalParent = temporalFile.getParentFile();
+                            temporalParent.mkdirs();
+                            if (!temporalParent.isDirectory()) {
+                                throw new IOException("Unexpected error: parent directory could not be created");
+                            }
+                            temporalFile.createNewFile();
+                            if (!temporalFile.isFile()) {
+                                throw new IOException("Unexpected error: target file could not be created");
+                            }                    
                             in = new FileInputStream(originalFile);
                             out = new FileOutputStream(temporalFile);
                             byte[] buf = new byte[1024];