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

Commit 7268f12

Browse files
committed
Contains to the traversing section
1 parent d6163a4 commit 7268f12

1 file changed

Lines changed: 30 additions & 25 deletions

File tree

src/directory.coffee

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -112,31 +112,6 @@ class Directory
112112
@lowerCaseRealPath = @lowerCasePath if fs.isCaseInsensitive()
113113
@realPath
114114

115-
# Public: Returns whether the given path (real or symbolic) is inside this
116-
# directory. This method does not actually check if the path exists, it just
117-
# checks if the path is under this directory.
118-
contains: (pathToCheck) ->
119-
return false unless pathToCheck
120-
121-
# Normalize forward slashes to back slashes on windows
122-
pathToCheck = pathToCheck.replace(/\//g, '\\') if process.platform is 'win32'
123-
124-
if fs.isCaseInsensitive()
125-
directoryPath = @lowerCasePath
126-
pathToCheck = pathToCheck.toLowerCase()
127-
else
128-
directoryPath = @path
129-
130-
return true if @isPathPrefixOf(directoryPath, pathToCheck)
131-
132-
# Check real path
133-
@getRealPathSync()
134-
if fs.isCaseInsensitive()
135-
directoryPath = @lowerCaseRealPath
136-
else
137-
directoryPath = @realPath
138-
139-
@isPathPrefixOf(directoryPath, pathToCheck)
140115
# Public: Returns the {String} basename of the directory.
141116
getBaseName: ->
142117
path.basename(@path)
@@ -252,6 +227,36 @@ class Directory
252227
async.eachLimit entries, 1, statEntry, ->
253228
callback(null, directories.concat(files))
254229

230+
# Public: Returns whether the given path (real or symbolic) is inside this
231+
# directory. This method does not actually check if the path exists, it just
232+
# checks if the path is under this directory.
233+
contains: (pathToCheck) ->
234+
return false unless pathToCheck
235+
236+
# Normalize forward slashes to back slashes on windows
237+
pathToCheck = pathToCheck.replace(/\//g, '\\') if process.platform is 'win32'
238+
239+
if fs.isCaseInsensitive()
240+
directoryPath = @lowerCasePath
241+
pathToCheck = pathToCheck.toLowerCase()
242+
else
243+
directoryPath = @path
244+
245+
return true if @isPathPrefixOf(directoryPath, pathToCheck)
246+
247+
# Check real path
248+
@getRealPathSync()
249+
if fs.isCaseInsensitive()
250+
directoryPath = @lowerCaseRealPath
251+
else
252+
directoryPath = @realPath
253+
254+
@isPathPrefixOf(directoryPath, pathToCheck)
255+
256+
###
257+
Section: Private
258+
###
259+
255260
subscribeToNativeChangeEvents: ->
256261
@watchSubscription ?= PathWatcher.watch @path, (eventType) =>
257262
if eventType is 'change'

0 commit comments

Comments
 (0)