From 2f8b1d5e3ea8dc357b235f9ec14750450590c651 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 7 Mar 2013 18:36:20 -0800 Subject: [PATCH] Remove $native.remove() --- native/v8_extensions/native.mm | 12 ------------ src/stdlib/fs.coffee | 14 +++++++++++++- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/native/v8_extensions/native.mm b/native/v8_extensions/native.mm index 7893f037a..179cf05d1 100644 --- a/native/v8_extensions/native.mm +++ b/native/v8_extensions/native.mm @@ -59,18 +59,6 @@ namespace v8_extensions { return true; } - else if (name == "remove") { - NSString *path = stringFromCefV8Value(arguments[0]); - - NSError *error = nil; - [[NSFileManager defaultManager] removeItemAtPath:path error:&error]; - - if (error) { - exception = [[error localizedDescription] UTF8String]; - } - - return true; - } else if (name == "writeToPasteboard") { NSString *text = stringFromCefV8Value(arguments[0]); diff --git a/src/stdlib/fs.coffee b/src/stdlib/fs.coffee index 3fc6d88e1..e5c361e32 100644 --- a/src/stdlib/fs.coffee +++ b/src/stdlib/fs.coffee @@ -86,7 +86,19 @@ module.exports = # Remove a file at the given path. Throws an error if path is not a # file or a symbolic link to a file. remove: (path) -> - $native.remove path + if @isFile(path) + nodeFs.unlinkSync(path) + else if @isDirectory(path) + removeDirectory = (path) => + for entry in nodeFs.readdirSync(path) + entryPath = @join(path, entry) + stats = nodeFs.statSync(entryPath) + if stats.isDirectory() + removeDirectory(entryPath) + else if stats.isFile() + nodeFs.unlinkSync(entryPath) + nodeFs.rmdirSync(path) + removeDirectory(path) # Open, read, and close a file, returning the file's contents. read: (path) ->