Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Contains to the traversing section
Browse files Browse the repository at this point in the history
  • Loading branch information
benogle committed Sep 11, 2014
1 parent d6163a4 commit 7268f12
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions src/directory.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -112,31 +112,6 @@ class Directory
@lowerCaseRealPath = @lowerCasePath if fs.isCaseInsensitive()
@realPath

# Public: Returns whether the given path (real or symbolic) is inside this
# directory. This method does not actually check if the path exists, it just
# checks if the path is under this directory.
contains: (pathToCheck) ->
return false unless pathToCheck

# Normalize forward slashes to back slashes on windows
pathToCheck = pathToCheck.replace(/\//g, '\\') if process.platform is 'win32'

if fs.isCaseInsensitive()
directoryPath = @lowerCasePath
pathToCheck = pathToCheck.toLowerCase()
else
directoryPath = @path

return true if @isPathPrefixOf(directoryPath, pathToCheck)

# Check real path
@getRealPathSync()
if fs.isCaseInsensitive()
directoryPath = @lowerCaseRealPath
else
directoryPath = @realPath

@isPathPrefixOf(directoryPath, pathToCheck)
# Public: Returns the {String} basename of the directory.
getBaseName: ->
path.basename(@path)
Expand Down Expand Up @@ -252,6 +227,36 @@ class Directory
async.eachLimit entries, 1, statEntry, ->
callback(null, directories.concat(files))

# Public: Returns whether the given path (real or symbolic) is inside this
# directory. This method does not actually check if the path exists, it just
# checks if the path is under this directory.
contains: (pathToCheck) ->
return false unless pathToCheck

# Normalize forward slashes to back slashes on windows
pathToCheck = pathToCheck.replace(/\//g, '\\') if process.platform is 'win32'

if fs.isCaseInsensitive()
directoryPath = @lowerCasePath
pathToCheck = pathToCheck.toLowerCase()
else
directoryPath = @path

return true if @isPathPrefixOf(directoryPath, pathToCheck)

# Check real path
@getRealPathSync()
if fs.isCaseInsensitive()
directoryPath = @lowerCaseRealPath
else
directoryPath = @realPath

@isPathPrefixOf(directoryPath, pathToCheck)

###
Section: Private
###

subscribeToNativeChangeEvents: ->
@watchSubscription ?= PathWatcher.watch @path, (eventType) =>
if eventType is 'change'
Expand Down

0 comments on commit 7268f12

Please sign in to comment.