Fixed copy and movement of files to ownCloud local folder with explicit creation...
authorDavid A. Velasco <dvelasco@solidgear.es>
Wed, 5 Dec 2012 15:01:19 +0000 (16:01 +0100)
committerDavid A. Velasco <dvelasco@solidgear.es>
Wed, 5 Dec 2012 15:01:19 +0000 (16:01 +0100)
src/com/owncloud/android/operations/SynchronizeFolderOperation.java
src/com/owncloud/android/operations/UploadFileOperation.java

index d2e45a4..eaf3c3e 100644 (file)
@@ -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);
                     
index 1be103b..ac27628 100644 (file)
@@ -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];