Skip to content

Commit

Permalink
Return arguments array from ls, check for dir existence, create paren…
Browse files Browse the repository at this point in the history
…t dirs
  • Loading branch information
DariaKunoichi committed Dec 16, 2024
1 parent e39bc64 commit 5f645ff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
16 changes: 2 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ void exists(String path, Promise promise) {
boolean result = new File(path).exists();
if (result) {
promise.resolve(result);
} else {
promise.reject(new Exception("File does not exist"));
}
} catch(Exception e) {
promise.reject(e);
Expand All @@ -107,8 +105,6 @@ void isDir(String path, Promise promise) {
boolean result = new File(path).isDirectory();
if (result) {
promise.resolve(result);
} else {
promise.reject(new Exception("Path is not a directory"));
}
} catch(Exception e) {
promise.reject(e);
Expand All @@ -117,15 +113,27 @@ void isDir(String path, Promise promise) {

void ls(String path, Promise promise) {
try {
promise.resolve(new File(path).list());
String[] files = new File(path).list();
WritableArray resultArray = Arguments.createArray();
for (String file : files) {
resultArray.pushString(file);
}

promise.resolve(resultArray);
} catch(Exception e) {
promise.reject(e);
}
}

void mkdir(String path, Promise promise) {
try {
boolean result = new File(path).mkdir();
File file = new File(path);
if (file.exists()) {
promise.reject("EEXIST", new Exception("Already exists."));
return;
}

boolean result = file.mkdirs();
if (result) {
promise.resolve(path);
} else {
Expand Down

0 comments on commit 5f645ff

Please sign in to comment.