浏览代码

Fixed lost of track of a downloaded file when it's tried to be renamed but the operation fails

David A. Velasco 12 年之前
父节点
当前提交
9da82f797e
共有 1 个文件被更改,包括 10 次插入0 次删除
  1. 10 0
      src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java

+ 10 - 0
src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java

@@ -856,6 +856,16 @@ public class FileDetailFragment extends SherlockFragment implements
                 mHandler.post(new Runnable() {
                     @Override
                     public void run() {
+                        // undo the local rename
+                        if (mNew.isDown()) {
+                            File f = new File(mNew.getStoragePath());
+                            if (!f.renameTo(new File(mOld.getStoragePath()))) {
+                                // the local rename undoing failed; last chance: save the new local storage path in the old file
+                                mFile.setStoragePath(mNew.getStoragePath());
+                                FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver());
+                                fdsm.saveFile(mFile);
+                            }
+                        }
                         boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
                         getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
                         try {