Checks whether file under old path exists, and moves it to better place when necessary. Can be slow if big file is being moved. @param bestPlace is desired directory for file (e.g. new place after migration) @param oldPlace is old (obsolete) directory for file (e.g. location from older releases) @pa
( File bestPlace, File oldPlace, String filename )
| 856 | * @return file to use (from old or new place) |
| 857 | */ |
| 858 | public static File checkOrMoveFile( File bestPlace, File oldPlace, String filename ) { |
| 859 | if ( !bestPlace.exists() ) { |
| 860 | bestPlace.mkdirs(); |
| 861 | } |
| 862 | File oldFile = new File(oldPlace, filename); |
| 863 | if ( bestPlace.isDirectory() && bestPlace.canWrite() ) { |
| 864 | File bestFile = new File(bestPlace, filename); |
| 865 | if (bestFile.exists()) |
| 866 | return bestFile; // already exists |
| 867 | if (oldFile.exists() && oldFile.isFile()) { |
| 868 | // move file |
| 869 | if (moveFile(oldFile, bestFile)) |
| 870 | return bestFile; |
| 871 | return oldFile; |
| 872 | } |
| 873 | return bestFile; |
| 874 | } |
| 875 | return oldFile; |
| 876 | } |
| 877 | |
| 878 | private static String CR3_SETTINGS_DIR_NAME; |
| 879 |
no test coverage detected