Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return args array from ls, check for dir existence, create parent dirs #547

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -92,11 +92,7 @@ WritableMap getNativeConstants() {
void exists(String path, Promise promise) {
try {
boolean result = new File(path).exists();
if (result) {
promise.resolve(result);
} else {
promise.reject(new Exception("File does not exist"));
}
promise.resolve(result);
} catch(Exception e) {
promise.reject(e);
}
Expand All @@ -105,31 +101,39 @@ void exists(String path, Promise promise) {
void isDir(String path, Promise promise) {
try {
boolean result = new File(path).isDirectory();
if (result) {
promise.resolve(result);
} else {
promise.reject(new Exception("Path is not a directory"));
}
promise.resolve(result);
} catch(Exception e) {
promise.reject(e);
}
}

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 {
promise.reject(new Exception("Failed to create directory"));
promise.reject("EPERM", new Exception("Failed to create directory"));
}
} catch(Exception e) {
promise.reject(e);
Expand Down
Loading