Last active
September 5, 2015 23:00
-
-
Save snowyu/bdc39a93d25503333991 to your computer and use it in GitHub Desktop.
nodejs check whether the file name is case-insensitive and get the real path for the case-insensitive file-system across os.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs = require 'fs' | |
path= require 'path' | |
tmp = require 'tmp' | |
tmp.setGracefulCleanup() | |
folderIsInsensitive = (aFolder)-> | |
aFolder ?= '.' | |
t = tmp.fileSync template:path.join aFolder, '_tmp-XXXXXXXXX' | |
result = fs.existsSync t.name.toUpperCase() | |
t.removeCallback() | |
result | |
getRealPathForInsensitive = (aPath)-> | |
result = '' | |
while aPath and aPath != path.sep | |
basename = path.basename(aPath).toLowerCase() | |
aPath = path.dirname aPath | |
dirs = fs.readdirSync aPath | |
for dir in dirs | |
if dir.toLowerCase() is basename | |
result = path.join dir, result | |
break | |
path.join aPath, result | |
getRealPath = (aPath)-> | |
if folderIsInsensitive aPath | |
getRealPathForInsensitive(aPath) | |
else | |
aPath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment