Skip to content

Commit

Permalink
[GEOS-11332] Renaming style with uppercase/downcase empty the sld file
Browse files Browse the repository at this point in the history
  • Loading branch information
aaime authored and f-necas committed May 16, 2024
1 parent 772f91e commit d80670f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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());
}
}

0 comments on commit d80670f

Please sign in to comment.