Fixed: Fix FileUtils labels

This commit is contained in:
agnostic-apollo
2022-01-22 04:32:00 +05:00
parent 8e7e355fcb
commit 1fb4fe2510

View File

@@ -290,7 +290,7 @@ public class FileUtils {
public static Error validateRegularFileExistenceAndPermissions(String label, final String filePath, final String parentDirPath, public static Error validateRegularFileExistenceAndPermissions(String label, final String filePath, final String parentDirPath,
final String permissionsToCheck, final boolean setPermissions, final boolean setMissingPermissionsOnly, final String permissionsToCheck, final boolean setPermissions, final boolean setMissingPermissionsOnly,
final boolean ignoreErrorsIfPathIsUnderParentDirPath) { final boolean ignoreErrorsIfPathIsUnderParentDirPath) {
label = (label == null ? "" : label + " "); label = (label == null || label.isEmpty() ? "" : label + " ");
if (filePath == null || filePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "regular file path", "validateRegularFileExistenceAndPermissions"); if (filePath == null || filePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "regular file path", "validateRegularFileExistenceAndPermissions");
try { try {
@@ -371,7 +371,7 @@ public class FileUtils {
public static Error validateDirectoryFileExistenceAndPermissions(String label, final String filePath, final String parentDirPath, final boolean createDirectoryIfMissing, public static Error validateDirectoryFileExistenceAndPermissions(String label, final String filePath, final String parentDirPath, final boolean createDirectoryIfMissing,
final String permissionsToCheck, final boolean setPermissions, final boolean setMissingPermissionsOnly, final String permissionsToCheck, final boolean setPermissions, final boolean setMissingPermissionsOnly,
final boolean ignoreErrorsIfPathIsInParentDirPath, final boolean ignoreIfNotExecutable) { final boolean ignoreErrorsIfPathIsInParentDirPath, final boolean ignoreIfNotExecutable) {
label = (label == null ? "" : label + " "); label = (label == null || label.isEmpty() ? "" : label + " ");
if (filePath == null || filePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "directory file path", "validateDirectoryExistenceAndPermissions"); if (filePath == null || filePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "directory file path", "validateDirectoryExistenceAndPermissions");
try { try {
@@ -485,7 +485,7 @@ public class FileUtils {
*/ */
public static Error createRegularFile(String label, final String filePath, public static Error createRegularFile(String label, final String filePath,
final String permissionsToCheck, final boolean setPermissions, final boolean setMissingPermissionsOnly) { final String permissionsToCheck, final boolean setPermissions, final boolean setMissingPermissionsOnly) {
label = (label == null ? "" : label + " "); label = (label == null || label.isEmpty() ? "" : label + " ");
if (filePath == null || filePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "file path", "createRegularFile"); if (filePath == null || filePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "file path", "createRegularFile");
Error error; Error error;
@@ -662,7 +662,7 @@ public class FileUtils {
*/ */
public static Error createSymlinkFile(String label, final String targetFilePath, final String destFilePath, public static Error createSymlinkFile(String label, final String targetFilePath, final String destFilePath,
final boolean allowDangling, final boolean overwrite, final boolean overwriteOnlyIfDestIsASymlink) { final boolean allowDangling, final boolean overwrite, final boolean overwriteOnlyIfDestIsASymlink) {
label = (label == null ? "" : label + " "); label = (label == null || label.isEmpty() ? "" : label + " ");
if (targetFilePath == null || targetFilePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "target file path", "createSymlinkFile"); if (targetFilePath == null || targetFilePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "target file path", "createSymlinkFile");
if (destFilePath == null || destFilePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "destination file path", "createSymlinkFile"); if (destFilePath == null || destFilePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "destination file path", "createSymlinkFile");
@@ -935,7 +935,7 @@ public class FileUtils {
public static Error copyOrMoveFile(String label, final String srcFilePath, final String destFilePath, public static Error copyOrMoveFile(String label, final String srcFilePath, final String destFilePath,
final boolean moveFile, final boolean ignoreNonExistentSrcFile, int allowedFileTypeFlags, final boolean moveFile, final boolean ignoreNonExistentSrcFile, int allowedFileTypeFlags,
final boolean overwrite, final boolean overwriteOnlyIfDestSameFileTypeAsSrc) { final boolean overwrite, final boolean overwriteOnlyIfDestSameFileTypeAsSrc) {
label = (label == null ? "" : label + " "); label = (label == null || label.isEmpty() ? "" : label + " ");
if (srcFilePath == null || srcFilePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "source file path", "copyOrMoveFile"); if (srcFilePath == null || srcFilePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "source file path", "copyOrMoveFile");
if (destFilePath == null || destFilePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "destination file path", "copyOrMoveFile"); if (destFilePath == null || destFilePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "destination file path", "copyOrMoveFile");
@@ -1150,7 +1150,7 @@ public class FileUtils {
* @return Returns the {@code error} if deletion was not successful, otherwise {@code null}. * @return Returns the {@code error} if deletion was not successful, otherwise {@code null}.
*/ */
public static Error deleteFile(String label, final String filePath, final boolean ignoreNonExistentFile, final boolean ignoreWrongFileType, int allowedFileTypeFlags) { public static Error deleteFile(String label, final String filePath, final boolean ignoreNonExistentFile, final boolean ignoreWrongFileType, int allowedFileTypeFlags) {
label = (label == null ? "" : label + " "); label = (label == null || label.isEmpty() ? "" : label + " ");
if (filePath == null || filePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "file path", "deleteFile"); if (filePath == null || filePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "file path", "deleteFile");
try { try {
@@ -1257,7 +1257,7 @@ public class FileUtils {
* @return Returns the {@code error} if clearing was not successful, otherwise {@code null}. * @return Returns the {@code error} if clearing was not successful, otherwise {@code null}.
*/ */
public static Error clearDirectory(String label, final String filePath) { public static Error clearDirectory(String label, final String filePath) {
label = (label == null ? "" : label + " "); label = (label == null || label.isEmpty() ? "" : label + " ");
if (filePath == null || filePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "file path", "clearDirectory"); if (filePath == null || filePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "file path", "clearDirectory");
Error error; Error error;
@@ -1320,7 +1320,7 @@ public class FileUtils {
* @return Returns the {@code error} if deleting was not successful, otherwise {@code null}. * @return Returns the {@code error} if deleting was not successful, otherwise {@code null}.
*/ */
public static Error deleteFilesOlderThanXDays(String label, final String filePath, final IOFileFilter dirFilter, int days, final boolean ignoreNonExistentFile, int allowedFileTypeFlags) { public static Error deleteFilesOlderThanXDays(String label, final String filePath, final IOFileFilter dirFilter, int days, final boolean ignoreNonExistentFile, int allowedFileTypeFlags) {
label = (label == null ? "" : label + " "); label = (label == null || label.isEmpty() ? "" : label + " ");
if (filePath == null || filePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "file path", "deleteFilesOlderThanXDays"); if (filePath == null || filePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "file path", "deleteFilesOlderThanXDays");
if (days < 0) return FunctionErrno.ERRNO_INVALID_PARAMETER.getError(label + "days", "deleteFilesOlderThanXDays", " It must be >= 0."); if (days < 0) return FunctionErrno.ERRNO_INVALID_PARAMETER.getError(label + "days", "deleteFilesOlderThanXDays", " It must be >= 0.");
@@ -1386,7 +1386,7 @@ public class FileUtils {
* @return Returns the {@code error} if reading was not successful, otherwise {@code null}. * @return Returns the {@code error} if reading was not successful, otherwise {@code null}.
*/ */
public static Error readTextFromFile(String label, final String filePath, Charset charset, @NonNull final StringBuilder dataStringBuilder, final boolean ignoreNonExistentFile) { public static Error readTextFromFile(String label, final String filePath, Charset charset, @NonNull final StringBuilder dataStringBuilder, final boolean ignoreNonExistentFile) {
label = (label == null ? "" : label + " "); label = (label == null || label.isEmpty() ? "" : label + " ");
if (filePath == null || filePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "file path", "readStringFromFile"); if (filePath == null || filePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "file path", "readStringFromFile");
Logger.logVerbose(LOG_TAG, "Reading text from " + label + "file at path \"" + filePath + "\""); Logger.logVerbose(LOG_TAG, "Reading text from " + label + "file at path \"" + filePath + "\"");
@@ -1467,7 +1467,7 @@ public class FileUtils {
*/ */
@NonNull @NonNull
public static <T extends Serializable> ReadSerializableObjectResult readSerializableObjectFromFile(String label, final String filePath, Class<T> readObjectType, final boolean ignoreNonExistentFile) { public static <T extends Serializable> ReadSerializableObjectResult readSerializableObjectFromFile(String label, final String filePath, Class<T> readObjectType, final boolean ignoreNonExistentFile) {
label = (label == null ? "" : label + " "); label = (label == null || label.isEmpty() ? "" : label + " ");
if (filePath == null || filePath.isEmpty()) return new ReadSerializableObjectResult(FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "file path", "readSerializableObjectFromFile"), null); if (filePath == null || filePath.isEmpty()) return new ReadSerializableObjectResult(FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "file path", "readSerializableObjectFromFile"), null);
Logger.logVerbose(LOG_TAG, "Reading serializable object from " + label + "file at path \"" + filePath + "\""); Logger.logVerbose(LOG_TAG, "Reading serializable object from " + label + "file at path \"" + filePath + "\"");
@@ -1525,7 +1525,7 @@ public class FileUtils {
* @return Returns the {@code error} if writing was not successful, otherwise {@code null}. * @return Returns the {@code error} if writing was not successful, otherwise {@code null}.
*/ */
public static Error writeTextToFile(String label, final String filePath, Charset charset, final String dataString, final boolean append) { public static Error writeTextToFile(String label, final String filePath, Charset charset, final String dataString, final boolean append) {
label = (label == null ? "" : label + " "); label = (label == null || label.isEmpty() ? "" : label + " ");
if (filePath == null || filePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "file path", "writeStringToFile"); if (filePath == null || filePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "file path", "writeStringToFile");
Logger.logVerbose(LOG_TAG, Logger.getMultiLineLogStringEntry("Writing text to " + label + "file at path \"" + filePath + "\"", DataUtils.getTruncatedCommandOutput(dataString, Logger.LOGGER_ENTRY_MAX_SAFE_PAYLOAD, true, false, true), "-")); Logger.logVerbose(LOG_TAG, Logger.getMultiLineLogStringEntry("Writing text to " + label + "file at path \"" + filePath + "\"", DataUtils.getTruncatedCommandOutput(dataString, Logger.LOGGER_ENTRY_MAX_SAFE_PAYLOAD, true, false, true), "-"));
@@ -1571,7 +1571,7 @@ public class FileUtils {
* @return Returns the {@code error} if writing was not successful, otherwise {@code null}. * @return Returns the {@code error} if writing was not successful, otherwise {@code null}.
*/ */
public static <T extends Serializable> Error writeSerializableObjectToFile(String label, final String filePath, final T serializableObject) { public static <T extends Serializable> Error writeSerializableObjectToFile(String label, final String filePath, final T serializableObject) {
label = (label == null ? "" : label + " "); label = (label == null || label.isEmpty() ? "" : label + " ");
if (filePath == null || filePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "file path", "writeSerializableObjectToFile"); if (filePath == null || filePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "file path", "writeSerializableObjectToFile");
Logger.logVerbose(LOG_TAG, "Writing serializable object to " + label + "file at path \"" + filePath + "\""); Logger.logVerbose(LOG_TAG, "Writing serializable object to " + label + "file at path \"" + filePath + "\"");
@@ -1681,7 +1681,7 @@ public class FileUtils {
* @param permissionsToSet The 3 character string that contains the "r", "w", "x" or "-" in-order. * @param permissionsToSet The 3 character string that contains the "r", "w", "x" or "-" in-order.
*/ */
public static void setFilePermissions(String label, final String filePath, final String permissionsToSet) { public static void setFilePermissions(String label, final String filePath, final String permissionsToSet) {
label = (label == null ? "" : label + " "); label = (label == null || label.isEmpty() ? "" : label + " ");
if (filePath == null || filePath.isEmpty()) return; if (filePath == null || filePath.isEmpty()) return;
if (!isValidPermissionString(permissionsToSet)) { if (!isValidPermissionString(permissionsToSet)) {
@@ -1752,7 +1752,7 @@ public class FileUtils {
* @param permissionsToSet The 3 character string that contains the "r", "w", "x" or "-" in-order. * @param permissionsToSet The 3 character string that contains the "r", "w", "x" or "-" in-order.
*/ */
public static void setMissingFilePermissions(String label, final String filePath, final String permissionsToSet) { public static void setMissingFilePermissions(String label, final String filePath, final String permissionsToSet) {
label = (label == null ? "" : label + " "); label = (label == null || label.isEmpty() ? "" : label + " ");
if (filePath == null || filePath.isEmpty()) return; if (filePath == null || filePath.isEmpty()) return;
if (!isValidPermissionString(permissionsToSet)) { if (!isValidPermissionString(permissionsToSet)) {
@@ -1804,7 +1804,7 @@ public class FileUtils {
* @return Returns the {@code error} if validating permissions failed, otherwise {@code null}. * @return Returns the {@code error} if validating permissions failed, otherwise {@code null}.
*/ */
public static Error checkMissingFilePermissions(String label, final String filePath, final String permissionsToCheck, final boolean ignoreIfNotExecutable) { public static Error checkMissingFilePermissions(String label, final String filePath, final String permissionsToCheck, final boolean ignoreIfNotExecutable) {
label = (label == null ? "" : label + " "); label = (label == null || label.isEmpty() ? "" : label + " ");
if (filePath == null || filePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "file path", "checkMissingFilePermissions"); if (filePath == null || filePath.isEmpty()) return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError(label + "file path", "checkMissingFilePermissions");
if (!isValidPermissionString(permissionsToCheck)) { if (!isValidPermissionString(permissionsToCheck)) {