Improved error messages in gallery for images that can not be loaded
[pub/Android/ownCloud.git] / src / com / owncloud / android / operations / SynchronizeFolderOperation.java
index d2e45a4..849413f 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;
@@ -163,6 +164,7 @@ public class SynchronizeFolderOperation extends RemoteOperation {
                     if (oldFile != null) {
                         file.setKeepInSync(oldFile.keepInSync());
                         file.setLastSyncDateForData(oldFile.getLastSyncDateForData());
+                        file.setModificationTimestampAtLastSyncForData(oldFile.getModificationTimestampAtLastSyncForData());    // must be kept unchanged when the file contents are not updated
                         checkAndFixForeignStoragePath(oldFile);
                         file.setStoragePath(oldFile.getStoragePath());
                     }
@@ -278,7 +280,7 @@ public class SynchronizeFolderOperation extends RemoteOperation {
         file.setCreationTimestamp(we.createTimestamp());
         file.setFileLength(we.contentLength());
         file.setMimetype(we.contentType());
-        file.setModificationTimestamp(we.modifiedTimesamp());
+        file.setModificationTimestamp(we.modifiedTimestamp());
         file.setParentId(mParentId);
         return file;
     }
@@ -308,6 +310,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 +329,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);