mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-01 13:19:53 +01:00
Check whether directory already exists as a file
This commit is contained in:
@@ -77,7 +77,7 @@ public class GitModifyCommand extends AbstractGitCommand implements ModifyComman
|
||||
@Override
|
||||
public void create(String toBeCreated, File file, boolean overwrite) throws IOException {
|
||||
Path targetFile = new File(workDir, toBeCreated).toPath();
|
||||
Files.createDirectories(targetFile.getParent());
|
||||
createDirectories(targetFile);
|
||||
if (overwrite) {
|
||||
Files.move(file.toPath(), targetFile, REPLACE_EXISTING);
|
||||
} else {
|
||||
@@ -97,7 +97,7 @@ public class GitModifyCommand extends AbstractGitCommand implements ModifyComman
|
||||
@Override
|
||||
public void modify(String path, File file) throws IOException {
|
||||
Path targetFile = new File(workDir, path).toPath();
|
||||
Files.createDirectories(targetFile.getParent());
|
||||
createDirectories(targetFile);
|
||||
if (!targetFile.toFile().exists()) {
|
||||
throw notFound(createFileContext(path));
|
||||
}
|
||||
@@ -124,6 +124,14 @@ public class GitModifyCommand extends AbstractGitCommand implements ModifyComman
|
||||
}
|
||||
}
|
||||
|
||||
private void createDirectories(Path targetFile) throws IOException {
|
||||
try {
|
||||
Files.createDirectories(targetFile.getParent());
|
||||
} catch (FileAlreadyExistsException e) {
|
||||
throw alreadyExists(createFileContext(targetFile.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
private ContextEntry.ContextBuilder createFileContext(String path) {
|
||||
ContextEntry.ContextBuilder contextBuilder = entity("file", path);
|
||||
if (!StringUtils.isEmpty(request.getBranch())) {
|
||||
|
||||
Reference in New Issue
Block a user