Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GEOS-11332] Renaming style with uppercase/downcase empty the sld file #36

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/platform/src/main/java/org/geoserver/util/IOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import org.apache.commons.io.FileUtils;
import org.geoserver.platform.resource.Files;
import org.geotools.util.logging.Logging;

/**
Expand Down Expand Up @@ -470,7 +471,7 @@ public static void rename(File f, String newName) throws IOException {
*/
public static void rename(File source, File dest) throws IOException {
// same path? Do nothing
if (source.getCanonicalPath().equalsIgnoreCase(dest.getCanonicalPath())) return;
if (source.getCanonicalPath().equals(dest.getCanonicalPath())) return;

// windows needs special treatment, we cannot rename onto an existing file
boolean win = System.getProperty("os.name").startsWith("Windows");
Expand All @@ -482,7 +483,9 @@ public static void rename(File source, File dest) throws IOException {
}
}
// make sure the rename actually succeeds
if (!source.renameTo(dest)) {
// using Files.move() instead of File.renameTo() to get better cross-platform support
// see also the javadoc of File.renameTo for more details
if (!Files.move(source, dest)) {
FileUtils.deleteQuietly(dest);
if (source.isDirectory()) {
FileUtils.moveDirectory(source, dest);
Expand Down
11 changes: 11 additions & 0 deletions src/platform/src/test/java/org/geoserver/util/IOUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,15 @@ public void testDecompressFileBadEntryName() throws IOException {
assertThat(e.getMessage(), startsWith("Entry is outside of the target directory"));
}
}

@Test
public void testRenameCaseChange() throws IOException {
File f = temp.newFile("foo.txt");
IOUtils.rename(f, "FOO.txt");
File renamed = new File(f.getParent(), "FOO.txt");

// file system can be case sensitive or not, so we can't really test
// that the old file is gone, but the new file should be there
assertTrue(renamed.exists());
}
}
Loading