Skip to content

Commit

Permalink
Throw failure when file already exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed May 3, 2024
1 parent fc2b4f7 commit 9f22daf
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,8 @@ public void touch(final Local file) throws AccessDeniedException {
}
catch(FileAlreadyExistsException e) {
log.warn(String.format("File %s already exists", file));
if(Files.isDirectory(Paths.get(file.getAbsolute()))) {
throw new LocalAccessDeniedException(MessageFormat.format(
throw new LocalAccessDeniedException(MessageFormat.format(
LocaleFactory.localizedString("Cannot create {0}", "Error"), file.getAbsolute()), e);
}
return;
}
}
catch(IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

import java.util.UUID;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

public class DefaultLocalTouchFeatureTest {

Expand All @@ -24,10 +23,7 @@ public void testTouch() throws Exception {
f.touch(l);
assertTrue(parent.exists());
assertTrue(l.exists());
f.touch(l);
assertTrue(l.exists());
// Test fail silently
f.touch(l);
assertThrows(LocalAccessDeniedException.class, () -> f.touch(l));
l.delete();
parent.delete();
}
Expand Down
2 changes: 2 additions & 0 deletions core/src/test/java/ch/cyberduck/core/local/LocalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ public void testOpenInputStream() throws Exception {
public void testOpenOutputStream() throws Exception {
Local l = new TestLocal(String.format("%s/%s", System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random()));
assertNotNull(l.getOutputStream(false));
assertThrows(LocalAccessDeniedException.class, () -> new DefaultLocalTouchFeature().touch(l));
l.delete();
new DefaultLocalTouchFeature().touch(l);
assertNotNull(l.getOutputStream(false));
assertNotNull(l.getOutputStream(true));
Expand Down

0 comments on commit 9f22daf

Please sign in to comment.