Fix a bug that utility.isNote does not handle symlinks properly

This commit is contained in:
Seongjae Lee
2015-10-07 07:55:36 -07:00
parent 6ae37437be
commit 2d2a070d1e
5 changed files with 45 additions and 3 deletions
+2 -2
View File
@@ -73,8 +73,8 @@ module.exports =
autodelete: (paneItem) ->
return false unless paneItem?.getURI?()?
uri = paneItem.getURI()
return unless Utility.isNote(uri)
return false unless paneItem?.isEmpty()
return false unless Utility.isNote(uri)
return false unless paneItem.isEmpty()
fs.unlinkSync(uri)
noteName = uri.substring(@rootDirectory.length + 1)
atom.notifications.addInfo("Empty note #{noteName} is deleted.")
+10 -1
View File
@@ -11,7 +11,16 @@ class Utility
@getPrimaryNoteExtension: -> if atom.config.get('nvatom.extensions').length then atom.config.get('nvatom.extensions')[0] else '.md'
@isNote: (filePath) ->
return false unless path.extname(filePath) in atom.config.get('nvatom.extensions')
filePath = fs.normalize(filePath)
return filePath.startsWith(Utility.getNoteDirectory()) and path.extname(filePath) in atom.config.get('nvatom.extensions')
return true if filePath.startsWith(Utility.getNoteDirectory())
return true if filePath.startsWith(fs.realpathSync(Utility.getNoteDirectory()))
return false unless fs.existsSync(filePath)
filePath = fs.realpathSync(filePath)
return true if filePath.startsWith(Utility.getNoteDirectory())
return true if filePath.startsWith(fs.realpathSync(Utility.getNoteDirectory()))
return false
@trim: (str) -> str?.replace /^\s+|\s+$/g, ''