From: David A. Velasco Date: Fri, 19 Apr 2013 08:56:00 +0000 (+0200) Subject: Fixed rename of files when folder for local files is not already created X-Git-Tag: oc-android-1.4.3~31 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/6ef46f264e40e1e39e9a02936beb7df306779fac?ds=inline;hp=--cc Fixed rename of files when folder for local files is not already created --- 6ef46f264e40e1e39e9a02936beb7df306779fac diff --git a/src/com/owncloud/android/operations/RenameFileOperation.java b/src/com/owncloud/android/operations/RenameFileOperation.java index deff1311..7ea5cf94 100644 --- a/src/com/owncloud/android/operations/RenameFileOperation.java +++ b/src/com/owncloud/android/operations/RenameFileOperation.java @@ -192,17 +192,23 @@ public class RenameFileOperation extends RemoteOperation { * * TODO move this method, and maybe FileDownload.get***Path(), to a class with utilities specific for the interactions with the file system * - * @return 'True' if a temporal file named with the name to set could be created in the file system where - * local files are stored. + * @return 'True' if a temporal file named with the name to set could be created in the file system where + * local files are stored. + * @throws IOException When the temporal folder can not be created. */ - private boolean isValidNewName() { + private boolean isValidNewName() throws IOException { // check tricky names if (mNewName == null || mNewName.length() <= 0 || mNewName.contains(File.separator) || mNewName.contains("%")) { return false; } // create a test file - String tmpFolder = FileStorageUtils.getTemporalPath(""); - File testFile = new File(tmpFolder + mNewName); + String tmpFolderName = FileStorageUtils.getTemporalPath(""); + File testFile = new File(tmpFolderName + mNewName); + File tmpFolder = testFile.getParentFile(); + tmpFolder.mkdirs(); + if (!tmpFolder.isDirectory()) { + throw new IOException("Unexpected error: temporal directory could not be created"); + } try { testFile.createNewFile(); // return value is ignored; it could be 'false' because the file already existed, that doesn't invalidate the name } catch (IOException e) {