Skip to content

Commit 9653506

Browse files
authored
Refactor renameProject to return Project and throw IOException
Updated renameProject method to return a new Project instance and handle IOException.
1 parent 0e6bba9 commit 9653506

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

main/src/main/java/org/xedox/webaide/project/Project.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,17 @@ public String file(String path) {
8989
return new File(projectPath, path).getAbsolutePath();
9090
}
9191

92-
public static void renameProject(Project project, String newName) {
93-
File newFile = new File(project.getParent(), newName);
94-
new File(project.getAbsolutePath()).renameTo(newFile);
92+
public static Project renameProject(Project project, String newName) throws IOException {
93+
File oldFile = new File(project.getAbsolutePath());
94+
File newFile = new File(project.getParent(), newName);
95+
96+
if (!oldFile.renameTo(newFile)) {
97+
throw new IOException("Failed to rename project.");
9598
}
9699

100+
return new Project(newFile);
101+
}
102+
97103
public static void removeProject(Project project) {
98104
project.projectPath.deleteRecursively();
99105
}

0 commit comments

Comments
 (0)