| 105 | // end with one (e.g. a directory). Also, resolve '.' and '..' to an absolute |
| 106 | // one. This method ensures path is legit! |
| 107 | function resolveToFullPath_(cwdFullPath, path) { |
| 108 | var fullPath = path; |
| 109 | |
| 110 | var relativePath = path[0] != DIR_SEPARATOR; |
| 111 | if (relativePath) { |
| 112 | fullPath = cwdFullPath; |
| 113 | if (cwdFullPath != DIR_SEPARATOR) { |
| 114 | fullPath += DIR_SEPARATOR + path; |
| 115 | } else { |
| 116 | fullPath += path; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | // Adjust '..'s by removing parent directories when '..' flows in path. |
| 121 | var parts = fullPath.split(DIR_SEPARATOR); |
| 122 | for (var i = 0; i < parts.length; ++i) { |
| 123 | var part = parts[i]; |
| 124 | if (part == '..') { |
| 125 | parts[i - 1] = ''; |
| 126 | parts[i] = ''; |
| 127 | } |
| 128 | } |
| 129 | fullPath = parts.filter(function(el) { |
| 130 | return el; |
| 131 | }).join(DIR_SEPARATOR); |
| 132 | |
| 133 | // Add back in leading slash. |
| 134 | if (fullPath[0] != DIR_SEPARATOR) { |
| 135 | fullPath = DIR_SEPARATOR + fullPath; |
| 136 | } |
| 137 | |
| 138 | // Replace './' by current dir. ('./one/./two' -> one/two) |
| 139 | fullPath = fullPath.replace(/\.\//g, DIR_SEPARATOR); |
| 140 | |
| 141 | // Replace '//' with '/'. |
| 142 | fullPath = fullPath.replace(/\/\//g, DIR_SEPARATOR); |
| 143 | |
| 144 | // Replace '/.' with '/'. |
| 145 | fullPath = fullPath.replace(/\/\./g, DIR_SEPARATOR); |
| 146 | |
| 147 | // Remove '/' if it appears on the end. |
| 148 | if (fullPath[fullPath.length - 1] == DIR_SEPARATOR && |
| 149 | fullPath != DIR_SEPARATOR) { |
| 150 | fullPath = fullPath.substring(0, fullPath.length - 1); |
| 151 | } |
| 152 | |
| 153 | return fullPath; |
| 154 | } |
| 155 | |
| 156 | // // Path can be relative or absolute. If relative, it's taken from the cwd_. |
| 157 | // // If a filesystem URL is passed it, it is simple returned |