This commit is contained in:
r-ca 2024-01-09 11:55:24 +09:00
parent 16ac36dd4f
commit cc35d8a5ea
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9

View File

@ -7,6 +7,7 @@ import org.w3c.dom.Document;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.file.DirectoryIteratorException;
import java.nio.file.DirectoryStream; import java.nio.file.DirectoryStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
@ -28,13 +29,90 @@ import one.nem.lacerta.utils.LacertaLogger;
public class FileManagerImpl implements FileManager { public class FileManagerImpl implements FileManager {
// variables
private Path rootDir;
private Path path;
// Injection // Injection
private LacertaLogger logger; private LacertaLogger logger;
@AssistedInject @AssistedInject
public FileManagerImpl(LacertaLogger logger, @Assisted Path rootDir) { public FileManagerImpl(LacertaLogger logger, @Assisted Path rootDir) {
this.logger = logger; this.logger = logger;
this.rootDir = rootDir;
}
// Internal
private Path resolveStringPath(String path) throws IOException{
String[] pathArray = path.split("/");
Path resolvedPath = this.rootDir;
for (String pathPart : pathArray) {
if (pathPart.equals("..")) {
resolvedPath = resolvedPath.getParent();
continue;
}
try {
resolvedPath = resolvedPath.resolve(pathPart);
} catch (Exception e) {
throw new IOException("Invalid path: " + path);
return null;
}
}
logger.debug("resolveStringPath", "resolvedPath: " + resolvedPath);
return resolvedPath;
} }
@Override
public File getFileRef() {
return null;
}
@Override
public boolean isExist() {
return false;
}
@Override
public boolean isDirectory() {
return false;
}
@Override
public boolean isFile() {
return false;
}
@Override
public boolean isWritable() {
return false;
}
@Override
public boolean isReadable() {
return false;
}
@Override
public Document readXml() {
return null;
}
@Override
public FileManager setRootDir(Path rootDir) {
this.rootDir = rootDir;
return this;
}
@Override
public FileManager setPath(Path path) {
return null;
}
@Override
public FileManager setPath(String path) {
return null;
}
} }