From 86952ff85edcbb619deb8c414ba37490fb5e8590 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 12 Jun 2013 18:16:31 -0700 Subject: [PATCH] Rename isDirectory() to isDirectorySync() --- spec/app/git-spec.coffee | 2 +- src/app/atom.coffee | 6 +++--- src/app/directory.coffee | 2 +- src/app/file.coffee | 2 +- src/app/project.coffee | 2 +- src/app/text-mate-package.coffee | 8 ++++---- src/app/window-event-handler.coffee | 2 +- .../package-generator/lib/package-generator-view.coffee | 2 +- src/packages/snippets/lib/snippets.coffee | 4 ++-- src/packages/status-bar/spec/status-bar-spec.coffee | 2 +- src/packages/tree-view/spec/tree-view-spec.coffee | 4 ++-- src/stdlib/command-installer.coffee | 2 +- src/stdlib/fs-utils.coffee | 8 ++++---- 13 files changed, 23 insertions(+), 23 deletions(-) diff --git a/spec/app/git-spec.coffee b/spec/app/git-spec.coffee index 5e4474be4..af50a969f 100644 --- a/spec/app/git-spec.coffee +++ b/spec/app/git-spec.coffee @@ -7,7 +7,7 @@ describe "Git", -> repo = null beforeEach -> - fsUtils.remove('/tmp/.git') if fsUtils.isDirectory('/tmp/.git') + fsUtils.remove('/tmp/.git') if fsUtils.isDirectorySync('/tmp/.git') afterEach -> repo.destroy() if repo?.repo? diff --git a/src/app/atom.coffee b/src/app/atom.coffee index 5b2027bbc..e15f002ed 100644 --- a/src/app/atom.coffee +++ b/src/app/atom.coffee @@ -85,10 +85,10 @@ window.atom = throw new Error("No loaded package for name '#{name}'") resolvePackagePath: (name) -> - return name if fsUtils.isDirectory(name) + return name if fsUtils.isDirectorySync(name) packagePath = fsUtils.resolve(config.packageDirPaths..., name) - return packagePath if fsUtils.isDirectory(packagePath) + return packagePath if fsUtils.isDirectorySync(packagePath) packagePath = path.join(window.resourcePath, 'node_modules', name) return packagePath if @isInternalPackage(packagePath) @@ -114,7 +114,7 @@ window.atom = for packageDirPath in config.packageDirPaths for packagePath in fsUtils.list(packageDirPath) - packagePaths.push(packagePath) if fsUtils.isDirectory(packagePath) + packagePaths.push(packagePath) if fsUtils.isDirectorySync(packagePath) for packagePath in fsUtils.list(path.join(window.resourcePath, 'node_modules')) packagePaths.push(packagePath) if @isInternalPackage(packagePath) diff --git a/src/app/directory.coffee b/src/app/directory.coffee index aeca596f1..421015aad 100644 --- a/src/app/directory.coffee +++ b/src/app/directory.coffee @@ -47,7 +47,7 @@ class Directory stat = fs.statSync(entryPath) if symlink catch e continue - if stat.isDirectory() + if stat.isDirectorySync() directories.push(new Directory(entryPath, symlink)) else if stat.isFile() files.push(new File(entryPath, symlink)) diff --git a/src/app/file.coffee b/src/app/file.coffee index 19514bed7..f9aa6ff6c 100644 --- a/src/app/file.coffee +++ b/src/app/file.coffee @@ -21,7 +21,7 @@ class File # symlink - A {Boolean} indicating if the path is a symlink (default: false) constructor: (@path, @symlink=false) -> try - if fs.statSync(@path).isDirectory() + if fs.statSync(@path).isDirectorySync() throw new Error("#{@path} is a directory") # Sets the path for the file. diff --git a/src/app/project.coffee b/src/app/project.coffee index 7aebd0b5a..6ca62ab5e 100644 --- a/src/app/project.coffee +++ b/src/app/project.coffee @@ -58,7 +58,7 @@ class Project @rootDirectory?.off() if projectPath? - directory = if fsUtils.isDirectory(projectPath) then projectPath else path.dirname(projectPath) + directory = if fsUtils.isDirectorySync(projectPath) then projectPath else path.dirname(projectPath) @rootDirectory = new Directory(directory) else @rootDirectory = null diff --git a/src/app/text-mate-package.coffee b/src/app/text-mate-package.coffee index 48c6b70d8..dc76822a8 100644 --- a/src/app/text-mate-package.coffee +++ b/src/app/text-mate-package.coffee @@ -47,7 +47,7 @@ class TextMatePackage extends Package legalGrammarExtensions: ['plist', 'tmLanguage', 'tmlanguage', 'json'] loadGrammars: (done) -> - fsUtils.isDirectoryAsync @getSyntaxesPath(), (isDirectory) => + fsUtils.isDirectory @getSyntaxesPath(), (isDirectory) => if isDirectory fsUtils.listAsync @getSyntaxesPath(), @legalGrammarExtensions, (error, paths) => if error? @@ -76,14 +76,14 @@ class TextMatePackage extends Package getSyntaxesPath: -> syntaxesPath = path.join(@path, "syntaxes") - if fsUtils.isDirectory(syntaxesPath) + if fsUtils.isDirectorySync(syntaxesPath) syntaxesPath else path.join(@path, "Syntaxes") getPreferencesPath: -> preferencesPath = path.join(@path, "preferences") - if fsUtils.isDirectory(preferencesPath) + if fsUtils.isDirectorySync(preferencesPath) preferencesPath else path.join(@path, "Preferences") @@ -126,7 +126,7 @@ class TextMatePackage extends Package @loadTextMatePreferenceObjects(preferenceObjects, done) loadTextMatePreferenceObjects: (preferenceObjects, done) -> - fsUtils.isDirectoryAsync @getPreferencesPath(), (isDirectory) => + fsUtils.isDirectory @getPreferencesPath(), (isDirectory) => return done() unless isDirectory fsUtils.listAsync @getPreferencesPath(), (error, paths) => diff --git a/src/app/window-event-handler.coffee b/src/app/window-event-handler.coffee index 6679c0e56..5177fd5a9 100644 --- a/src/app/window-event-handler.coffee +++ b/src/app/window-event-handler.coffee @@ -13,7 +13,7 @@ class WindowEventHandler @subscribe $(window), 'focus', -> $("body").removeClass('is-blurred') @subscribe $(window), 'blur', -> $("body").addClass('is-blurred') @subscribe $(window), 'window:open-path', (event, pathToOpen) -> - rootView?.open(pathToOpen) unless fsUtils.isDirectory(pathToOpen) + rootView?.open(pathToOpen) unless fsUtils.isDirectorySync(pathToOpen) @subscribeToCommand $(window), 'window:toggle-full-screen', => atom.toggleFullScreen() @subscribeToCommand $(window), 'window:close', => diff --git a/src/packages/package-generator/lib/package-generator-view.coffee b/src/packages/package-generator/lib/package-generator-view.coffee index 8ee7b83fc..09c1cf918 100644 --- a/src/packages/package-generator/lib/package-generator-view.coffee +++ b/src/packages/package-generator/lib/package-generator-view.coffee @@ -67,7 +67,7 @@ class PackageGeneratorView extends View relativePath = @replacePackageNamePlaceholders(relativePath, packageName) sourcePath = path.join(@getPackagePath(), relativePath) - if fsUtils.isDirectory(templateChildPath) + if fsUtils.isDirectorySync(templateChildPath) fsUtils.makeTree(sourcePath) if fsUtils.isFile(templateChildPath) fsUtils.makeTree(path.dirname(sourcePath)) diff --git a/src/packages/snippets/lib/snippets.coffee b/src/packages/snippets/lib/snippets.coffee index a370ece34..e82f9808c 100644 --- a/src/packages/snippets/lib/snippets.coffee +++ b/src/packages/snippets/lib/snippets.coffee @@ -37,7 +37,7 @@ module.exports = loadAtomSnippets: (packagePath, done) -> snippetsDirPath = path.join(packagePath, 'snippets') - return done() unless fsUtils.isDirectory(snippetsDirPath) + return done() unless fsUtils.isDirectorySync(snippetsDirPath) loadSnippetFile = (filename, done) => return done() if filename.indexOf('.') is 0 @@ -54,7 +54,7 @@ module.exports = loadTextMateSnippets: (bundlePath, done) -> snippetsDirPath = path.join(bundlePath, 'Snippets') - return done() unless fsUtils.isDirectory(snippetsDirPath) + return done() unless fsUtils.isDirectorySync(snippetsDirPath) loadSnippetFile = (filename, done) => return done() if filename.indexOf('.') is 0 diff --git a/src/packages/status-bar/spec/status-bar-spec.coffee b/src/packages/status-bar/spec/status-bar-spec.coffee index ab7b99fb0..d34b3ac17 100644 --- a/src/packages/status-bar/spec/status-bar-spec.coffee +++ b/src/packages/status-bar/spec/status-bar-spec.coffee @@ -111,7 +111,7 @@ describe "StatusBar", -> describe "git branch label", -> beforeEach -> - fsUtils.remove('/tmp/.git') if fsUtils.isDirectory('/tmp/.git') + fsUtils.remove('/tmp/.git') if fsUtils.isDirectorySync('/tmp/.git') rootView.attachToDom() it "displays the current branch for files in repositories", -> diff --git a/src/packages/tree-view/spec/tree-view-spec.coffee b/src/packages/tree-view/spec/tree-view-spec.coffee index 8f6089f85..88337941d 100644 --- a/src/packages/tree-view/spec/tree-view-spec.coffee +++ b/src/packages/tree-view/spec/tree-view-spec.coffee @@ -680,7 +680,7 @@ describe "TreeView", -> addDialog.miniEditor.insertText("new/dir/") addDialog.trigger 'core:confirm' expect(fsUtils.exists(newPath)).toBeTruthy() - expect(fsUtils.isDirectory(newPath)).toBeTruthy() + expect(fsUtils.isDirectorySync(newPath)).toBeTruthy() expect(addDialog.parent()).not.toExist() expect(rootView.getActiveView().getPath()).not.toBe newPath expect(treeView.find(".tree-view")).toMatchSelector(':focus') @@ -693,7 +693,7 @@ describe "TreeView", -> addDialog.miniEditor.insertText("new2/") addDialog.trigger 'core:confirm' expect(fsUtils.exists(newPath)).toBeTruthy() - expect(fsUtils.isDirectory(newPath)).toBeTruthy() + expect(fsUtils.isDirectorySync(newPath)).toBeTruthy() expect(addDialog.parent()).not.toExist() expect(rootView.getActiveView().getPath()).not.toBe newPath expect(treeView.find(".tree-view")).toMatchSelector(':focus') diff --git a/src/stdlib/command-installer.coffee b/src/stdlib/command-installer.coffee index 6ef0dd86c..d122dc3c4 100644 --- a/src/stdlib/command-installer.coffee +++ b/src/stdlib/command-installer.coffee @@ -26,7 +26,7 @@ unlinkCommand = (destinationPath, callback) -> module.exports = findInstallDirectory: (callback) -> directories = ['/opt/boxen','/opt/github','/usr/local'] - async.detect(directories, fsUtils.isDirectoryAsync, callback) + async.detect(directories, fsUtils.isDirectory, callback) install: (commandPath, commandName, callback) -> if not commandName? or _.isFunction(commandName) diff --git a/src/stdlib/fs-utils.coffee b/src/stdlib/fs-utils.coffee index 0c322b287..f2e9fdd11 100644 --- a/src/stdlib/fs-utils.coffee +++ b/src/stdlib/fs-utils.coffee @@ -29,14 +29,14 @@ module.exports = # Returns true if the file specified by path exists and is a # directory. - isDirectory: (path) -> + isDirectorySync: (path) -> return false unless path?.length > 0 try fs.statSync(path).isDirectory() catch e false - isDirectoryAsync: (path, done) -> + isDirectory: (path, done) -> return done(false) unless path?.length > 0 fs.exists path, (exists) -> if exists @@ -67,7 +67,7 @@ module.exports = # Returns an array with all the names of files contained # in the directory path. list: (rootPath, extensions) -> - return [] unless @isDirectory(rootPath) + return [] unless @isDirectorySync(rootPath) paths = fs.readdirSync(rootPath) paths = @filterExtensions(paths, extensions) if extensions paths = paths.map (path) -> Path.join(rootPath, path) @@ -164,7 +164,7 @@ module.exports = @makeDirectory(path) traverseTreeSync: (rootPath, onFile, onDirectory) -> - return unless @isDirectory(rootPath) + return unless @isDirectorySync(rootPath) traverse = (rootPath, prefix, onFile, onDirectory) -> prefix = "#{prefix}/" if prefix