Skip to content

Commit

Permalink
Remove default directories
Browse files Browse the repository at this point in the history
No longer needed after 3814c8a

Issue: #29
  • Loading branch information
2bllw8 committed Sep 15, 2022
1 parent c96c081 commit fdae088
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,14 @@
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.HashMap;
import java.util.Map;

public final class HomeEnvironment {
public static final String AUTHORITY = "exe.bbllw8.anemo.documents";

public static final String ROOT = "anemo";
public static final String ROOT_DOC_ID = "root";

private static final String DOCUMENTS = "Documents";
private static final String PICTURES = "Pictures";
private static final String MOVIES = "Movies";
private static final String MUSIC = "Music";

private final Path baseDir;
private final Map<String, Path> defaultDirectories;

private static volatile HomeEnvironment instance;

Expand All @@ -45,21 +37,15 @@ public static HomeEnvironment getInstance(Context context) throws IOException {
private HomeEnvironment(Context context) throws IOException {
baseDir = context.getFilesDir().toPath().resolve(ROOT);

defaultDirectories = new HashMap<>(4);
defaultDirectories.put(DOCUMENTS, baseDir.resolve(DOCUMENTS));
defaultDirectories.put(PICTURES, baseDir.resolve(PICTURES));
defaultDirectories.put(MOVIES, baseDir.resolve(MOVIES));
defaultDirectories.put(MUSIC, baseDir.resolve(MUSIC));

prepare();
}

public Path getBaseDir() {
return baseDir;
}

public boolean isDefaultDirectory(Path path) {
return baseDir.equals(path) || defaultDirectories.containsValue(path);
public boolean isRoot(Path path) {
return baseDir.equals(path);
}

public void wipe() throws IOException {
Expand All @@ -82,17 +68,10 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc)
}

private void prepare() throws IOException {
ensureExists(baseDir);
for (final Path dir : defaultDirectories.values()) {
ensureExists(dir);
}
}

private void ensureExists(Path dir) throws IOException {
if (!Files.exists(dir)) {
Files.createDirectory(dir);
} else if (!Files.isDirectory(dir)) {
throw new IOException(dir + " is not a directory");
if (!Files.exists(baseDir)) {
Files.createDirectory(baseDir);
} else if (!Files.isDirectory(baseDir)) {
throw new IOException(baseDir + " is not a directory");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ protected String getDocIdForPath(Path path) {

@Override
protected boolean isNotEssential(Path path) {
return !homeEnvironment.isDefaultDirectory(path);
return !homeEnvironment.isRoot(path);
}

@Override
Expand Down

0 comments on commit fdae088

Please sign in to comment.