From: David A. Velasco Date: Wed, 5 Dec 2012 15:01:19 +0000 (+0100) Subject: Fixed copy and movement of files to ownCloud local folder with explicit creation... X-Git-Tag: oc-android-1.4.3~80^2~1 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/4476c047364e6697372b9d6e9da6371cece2d62f?ds=inline;hp=--cc Fixed copy and movement of files to ownCloud local folder with explicit creation of parent directory and target file --- 4476c047364e6697372b9d6e9da6371cece2d62f diff --git a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java index d2e45a43..eaf3c3eb 100644 --- a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/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); diff --git a/src/com/owncloud/android/operations/UploadFileOperation.java b/src/com/owncloud/android/operations/UploadFileOperation.java index 1be103b6..ac276284 100644 --- a/src/com/owncloud/android/operations/UploadFileOperation.java +++ b/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];