@@ -66,8 +66,6 @@ define(function (require, exports, module) {
6666 _domainPath = [ _bracketsPath , _modulePath , _nodePath ] . join ( "/" ) ,
6767 _nodeDomain = new NodeDomain ( "fileWatcher" , _domainPath ) ;
6868
69- var _isRunningOnWindowsXP = window . navigator . userAgent . indexOf ( "Windows NT 5." ) >= 0 ;
70-
7169
7270 // If the connection closes, notify the FileSystem that watchers have gone offline.
7371 _nodeDomain . connection . on ( "close" , function ( event , promise ) {
@@ -177,6 +175,17 @@ define(function (require, exports, module) {
177175 return FileSystemError . UNKNOWN ;
178176 }
179177
178+ /**
179+ * Normalises path.
180+ *
181+ * @param {string } path The path to normalise
182+ * @return {string } Normalised path.
183+ * @private
184+ */
185+ function _normalise_path ( path ) {
186+ return window . Phoenix . VFS . path . normalize ( path ) ;
187+ }
188+
180189 /**
181190 * Convert a callback to one that transforms its first parameter from an
182191 * appshell error code to a FileSystemError string.
@@ -233,6 +242,7 @@ define(function (require, exports, module) {
233242 */
234243 function stat ( path , callback ) {
235244 console . log ( 'stat: ' , path ) ;
245+ path = _normalise_path ( path ) ;
236246 appshell . fs . stat ( path , function ( err , stats ) {
237247 if ( err ) {
238248 callback ( _mapError ( err ) ) ;
@@ -264,6 +274,7 @@ define(function (require, exports, module) {
264274 */
265275 function exists ( path , callback ) {
266276 console . log ( 'exists: ' , path ) ;
277+ path = _normalise_path ( path ) ;
267278 stat ( path , function ( err ) {
268279 if ( err ) {
269280 if ( err === FileSystemError . NOT_FOUND ) {
@@ -291,6 +302,7 @@ define(function (require, exports, module) {
291302 */
292303 function readdir ( path , callback ) {
293304 console . log ( 'readdir: ' , path ) ;
305+ path = _normalise_path ( path ) ;
294306 appshell . fs . readdir ( path , function ( err , contents ) {
295307 if ( err ) {
296308 callback ( _mapError ( err ) ) ;
@@ -305,7 +317,7 @@ define(function (require, exports, module) {
305317
306318 var stats = [ ] ;
307319 contents . forEach ( function ( val , idx ) {
308- stat ( path + "/" + val , function ( err , stat ) {
320+ stat ( _normalise_path ( path + "/" + val ) , function ( err , stat ) {
309321 stats [ idx ] = err || stat ;
310322 count -- ;
311323 if ( count <= 0 ) {
@@ -328,11 +340,12 @@ define(function (require, exports, module) {
328340 */
329341 function mkdir ( path , mode , callback ) {
330342 console . log ( 'mkdir: ' , path ) ;
343+ path = _normalise_path ( path ) ;
331344 if ( typeof mode === "function" ) {
332345 callback = mode ;
333346 mode = parseInt ( "0755" , 8 ) ;
334347 }
335- appshell . fs . mkdir ( path , mode , function ( err ) {
348+ appshell . fs . mkdirs ( path , mode , true , function ( err ) {
336349 if ( err ) {
337350 callback ( _mapError ( err ) ) ;
338351 } else {
@@ -353,6 +366,8 @@ define(function (require, exports, module) {
353366 */
354367 function rename ( oldPath , newPath , callback ) {
355368 console . log ( 'rename: ' , oldPath , ' to ' , newPath ) ;
369+ oldPath = _normalise_path ( oldPath ) ;
370+ newPath = _normalise_path ( newPath ) ;
356371 appshell . fs . rename ( oldPath , newPath , _wrap ( callback ) ) ;
357372 }
358373
@@ -374,6 +389,7 @@ define(function (require, exports, module) {
374389 */
375390 function readFile ( path , options , callback ) {
376391 console . log ( 'Reading file: ' , path ) ;
392+ path = _normalise_path ( path ) ;
377393 var encoding = window . Phoenix . VFS . getFsEncoding ( options . encoding ) || "utf8" ;
378394
379395 // callback to be executed when the call to stat completes
@@ -423,6 +439,7 @@ define(function (require, exports, module) {
423439 */
424440 function writeFile ( path , data , options , callback ) {
425441 console . log ( 'Write file: ' , path ) ;
442+ path = _normalise_path ( path ) ;
426443 var encoding = window . Phoenix . VFS . getFsEncoding ( options . encoding ) || "utf8" ,
427444 preserveBOM = options . preserveBOM ;
428445
@@ -483,6 +500,7 @@ define(function (require, exports, module) {
483500 */
484501 function unlink ( path , callback ) {
485502 console . log ( 'delete file: ' , path ) ;
503+ path = _normalise_path ( path ) ;
486504 appshell . fs . unlink ( path , function ( err ) {
487505 callback ( _mapError ( err ) ) ;
488506 } ) ;
@@ -498,6 +516,7 @@ define(function (require, exports, module) {
498516 */
499517 function moveToTrash ( path , callback ) {
500518 console . log ( 'Trash file: ' , path ) ;
519+ path = _normalise_path ( path ) ;
501520 appshell . fs . moveToTrash ( path , function ( err ) {
502521 callback ( _mapError ( err ) ) ;
503522 } ) ;
@@ -523,7 +542,7 @@ define(function (require, exports, module) {
523542 _changeCallback = changeCallback ;
524543 _offlineCallback = offlineCallback ;
525544
526- if ( _isRunningOnWindowsXP && _offlineCallback ) {
545+ if ( _offlineCallback ) {
527546 _offlineCallback ( ) ;
528547 }
529548 }
@@ -542,6 +561,7 @@ define(function (require, exports, module) {
542561 */
543562 function watchPath ( path , ignored , callback ) {
544563 console . log ( 'Watch path: ' , path ) ;
564+ path = _normalise_path ( path ) ;
545565 callback ( FileSystemError . NOT_SUPPORTED ) ;
546566 return ;
547567 // TODO: Phoenix. file watch fix.
@@ -571,6 +591,7 @@ define(function (require, exports, module) {
571591 */
572592 function unwatchPath ( path , ignored , callback ) {
573593 console . log ( 'unwatch path: ' , path ) ;
594+ path = _normalise_path ( path ) ;
574595 _nodeDomain . exec ( "unwatchPath" , path )
575596 . then ( callback , callback ) ;
576597 }
0 commit comments