Skip to content

Commit

Permalink
Changed file name case check to local filesystem case-sensitivity check.
Browse files Browse the repository at this point in the history
  • Loading branch information
stevealexrs committed Nov 5, 2022
1 parent 73cf6a0 commit 9a1b5ac
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Objects;
import java.util.concurrent.Executor;

import org.apache.commons.net.ftp.FTPClient;
Expand Down Expand Up @@ -441,13 +442,12 @@ public static void rename(

private final DataUtils dataUtils = DataUtils.getInstance();

/**
* Determines whether double rename is required based on original and new file name regardless
* of the case-sensitivity of the filesystem
*/
private final boolean isCaseSensitiveRename =
oldFile.getSimpleName().equalsIgnoreCase(newFile.getSimpleName())
&& !oldFile.getSimpleName().equals(newFile.getSimpleName());
private final boolean isLocalFilesystemCaseInsensitive =
Objects.requireNonNull(oldFile.getFile()).exists()
&& new File(oldFile.getFile().getParent(), oldFile.getSimpleName().toUpperCase())
.exists()
&& new File(oldFile.getFile().getParent(), oldFile.getSimpleName().toLowerCase())
.exists();

/**
* random string that is appended to file to prevent name collision, max file name is 255
Expand Down Expand Up @@ -530,7 +530,7 @@ protected Void doInBackground(Void... params) {
return null;
}

if (newFile.exists() && !isCaseSensitiveRename) {
if (newFile.exists() && !isLocalFilesystemCaseInsensitive) {
errorCallBack.exists(newFile);
return null;
}
Expand Down Expand Up @@ -687,7 +687,7 @@ public Boolean executeWithFtpClient(@NonNull FTPClient ftpClient)
}

boolean result;
if (isCaseSensitiveRename) {
if (isLocalFilesystemCaseInsensitive) {
result = localDoubleRename(oldFile, newFile);
} else {
result = localRename(oldFile, newFile);
Expand Down

0 comments on commit 9a1b5ac

Please sign in to comment.