From 6f5138a56e31f3435efe08ffd764de4ee7fd153b Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 12 Mar 2013 08:23:54 -0700 Subject: [PATCH] Revert "Remove $native.md5ForPath()" This reverts commit 832df7149e7510fccea0f7637f6feb232d0c0a7f. --- native/v8_extensions/native.mm | 19 ++++++++++++++++++- src/stdlib/require.coffee | 4 +--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/native/v8_extensions/native.mm b/native/v8_extensions/native.mm index ee8ef0112..8d7705a79 100644 --- a/native/v8_extensions/native.mm +++ b/native/v8_extensions/native.mm @@ -25,7 +25,7 @@ namespace v8_extensions { const char* methodNames[] = { "absolute", "writeToPasteboard", "readFromPasteboard", "quit", "watchPath", "unwatchPath", "getWatchedPaths", "unwatchAllPaths", - "moveToTrash", "reload", "getPlatform", "setWindowState", + "moveToTrash", "reload", "md5ForPath", "getPlatform", "setWindowState", "getWindowState", "isMisspelled", "getCorrectionsForMisspelling" }; @@ -159,6 +159,23 @@ namespace v8_extensions { else if (name == "reload") { CefV8Context::GetCurrentContext()->GetBrowser()->ReloadIgnoreCache(); } + else if (name == "md5ForPath") { + NSString *path = stringFromCefV8Value(arguments[0]); + unsigned char outputData[CC_MD5_DIGEST_LENGTH]; + + NSData *inputData = [[NSData alloc] initWithContentsOfFile:path]; + CC_MD5([inputData bytes], [inputData length], outputData); + [inputData release]; + + NSMutableString *hash = [[NSMutableString alloc] init]; + + for (NSUInteger i = 0; i < CC_MD5_DIGEST_LENGTH; i++) { + [hash appendFormat:@"%02x", outputData[i]]; + } + + retval = CefV8Value::CreateString([hash UTF8String]); + return true; + } else if (name == "getPlatform") { retval = CefV8Value::CreateString("mac"); return true; diff --git a/src/stdlib/require.coffee b/src/stdlib/require.coffee index c6cb7b38d..b4fa85ea1 100644 --- a/src/stdlib/require.coffee +++ b/src/stdlib/require.coffee @@ -1,5 +1,4 @@ fs = nodeRequire 'fs' -crypto = nodeRequire 'crypto' paths = [ "#{window.resourcePath}/spec" @@ -87,8 +86,7 @@ createCacheDirectory = -> fs.mkdirSync('/tmp/atom-compiled-scripts') unless __exists('/tmp/atom-compiled-scripts') getCacheFilePath = (path) -> - md5 = crypto.createHash('md5').update(fs.readFileSync(path)).digest('hex') - "/tmp/atom-compiled-scripts/#{md5}" + "/tmp/atom-compiled-scripts/#{$native.md5ForPath(path)}" resolve = (name, {verifyExistence}={}) -> verifyExistence ?= true