Move verification down
@@ -32,19 +32,16 @@ public class ApplicationFileManager implements AddFileInterface {
@Override
public FileReference addFile(String relativePath) throws IOException {
- Path path = Path.of(relativePath).normalize();
- if (path.isAbsolute())
- throw new IllegalArgumentException(relativePath + " is not relative");
File file = new File(applicationDir, relativePath);
- Path relative = applicationDir.toPath().relativize(file.toPath()).normalize();
- if (relative.isAbsolute() || relative.startsWith(".."))
- throw new IllegalArgumentException(file + " is not a descendant of " + applicationDir);
-
- return fileDirectory.addFile(file);
+ return addFile(file);
}
@Override
public FileReference addFile(File file) throws IOException {
+ Path relative = applicationDir.toPath().relativize(file.toPath()).normalize();
+ if (relative.isAbsolute() || relative.startsWith(".."))
+ throw new IllegalArgumentException(file + " is not a descendant of " + applicationDir);
+
return fileDirectory.addFile(file);
}
