/** * Ensure that the destination folder exists. * * @param dest the final file name desired. * @return true if we could ensure the prerequisites */ /* package */ boolean ensureFolderExists(final String dest) { Log.d(LOG_TAG, "ensureFolderExists(" + dest + ") called"); if (null == dest) { failureMessage = MSG_BAD_DEST; downloadErrorCode = DownloadError.BAD_DESTINATION.getValue(); return false; } final File f = new File(dest); final File dir = f.getParentFile(); // This can occur if the directory exists but another // process is using it. if (null == dir) { failureMessage = MSG_BAD_DIR; downloadErrorCode = DownloadError.BAD_DIRECTORY.getValue(); Log.e(LOG_TAG, failureMessage); return false; } // mkdirs returns false if the directory already exists // so check here before calling it. if (dir.exists()) { return true; } final boolean result = dir.mkdirs(); if (!result) { failureMessage = MSG_COULDNT_MKDIR; downloadErrorCode = DownloadError.COULDNT_MKDIR.getValue(); } return result; }
/** * Ensure that a partial download file exists. * * @param dest the file to check * @param offset how big we think it should be * @return true if things look good */ /* package */ boolean ensurePartialFilePresent(final String dest, final long offset) { if (null == dest) { failureMessage = MSG_BAD_DEST; downloadErrorCode = DownloadError.BAD_DESTINATION.getValue(); return false; } final File f = new File(dest); final boolean result = f.exists() && f.length() >= offset; if (!result) { Log.d(LOG_TAG, "Bad partial file"); } return result; }