Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed a bug in directory() for empty relative directories. Added tests.

  • Loading branch information...
commit 3ed1e567b7c5b4a58d55fddf98ed39e0293f4578 1 parent 953722a
authored August 30, 2011
1  .gitignore
... ...
@@ -0,0 +1 @@
  1
+node_modules
3  CHANGES
... ...
@@ -1,4 +1,7 @@
1 1
 
  2
+0.0.6
  3
+ - fixed bug in directory for relative directories
  4
+
2 5
 0.0.4
3 6
  - removed superfluous "q" package dependency.
4 7
 
22  fs-boot.js
... ...
@@ -1,3 +1,4 @@
  1
+(function (exports) {
1 2
 
2 3
 // -- kriskowal Kris Kowal Copyright (C) 2009-2010 MIT License
3 4
 // -- tlrobinson Tom Robinson TODO
@@ -25,7 +26,7 @@ var regExpEscape = function (str) {
25 26
 
26 27
 var os = typeof process !== "undefined"?
27 28
     process.platform :
28  
-    require("narwhal/engine").os;
  29
+    "unknown"
29 30
 var isWindows = /\bwind?(nt|ows)\b/i.test(os);
30 31
 
31 32
 /**
@@ -265,11 +266,25 @@ exports.root = function (path) {
265 266
  * @returns {String} the parent directory of the given path.
266 267
  */
267 268
 exports.directory = function (path) {
  269
+    path = exports.normal(path);
  270
+    var absolute = exports.isAbsolute(path);
268 271
     var parts = exports.split(path);
269 272
     // XXX needs to be sensitive to the root for
270 273
     // Windows compatibility
271  
-    parts.pop();
272  
-    return parts.join(exports.SEPARATOR) || exports.ROOT;
  274
+    console.log(parts);
  275
+    if (parts.length) {
  276
+        if (parts[parts.length - 1] == "..") {
  277
+            parts.push("..");
  278
+        } else {
  279
+            parts.pop();
  280
+        }
  281
+    } else {
  282
+        parts.unshift("..");
  283
+    }
  284
+    return parts.join(exports.SEPARATOR) || (
  285
+        exports.isRelative(path) ?
  286
+        "" : exports.ROOT
  287
+    );
273 288
 };
274 289
 
275 290
 /**
@@ -301,3 +316,4 @@ exports.extension = function (path) {
301 316
     return index <= 0 ? "" : path.substring(index);
302 317
 };
303 318
 
  319
+})(typeof exports !== "undefined" ? exports : FS_BOOT = {});
5  package.json
... ...
@@ -1,7 +1,7 @@
1 1
 {
2 2
     "name": "fs-boot",
  3
+    "version": "0.0.6",
3 4
     "description": "Pure JavaScript implementation of common file-system API components",
4  
-    "version": "0.0.5",
5 5
     "homepage": "http://github.com/kriskowal/fs-boot/",
6 6
     "author": "Kris Kowal <kris@cixar.com> (http://github.com/kriskowal/)",
7 7
     "bugs": {
@@ -19,6 +19,9 @@
19 19
         "type": "git",
20 20
         "url": "http://github.com/kriskowal/fs-boot.git"
21 21
     },
  22
+    "devDependences": {
  23
+        "test": "0.3.0"
  24
+    },
22 25
     "engines": {
23 26
         "node": ">=0.2.0"
24 27
     }
45  test/directory.js
... ...
@@ -0,0 +1,45 @@
  1
+
  2
+var FS = require("fs-boot");
  3
+
  4
+[
  5
+    {
  6
+        "from": "foo",
  7
+        "to": ""
  8
+    },
  9
+    {
  10
+        "from": "",
  11
+        "to": ".."
  12
+    },
  13
+    {
  14
+        "from": ".",
  15
+        "to": ".."
  16
+    },
  17
+    {
  18
+        "from": "..",
  19
+        "to": "../.."
  20
+    },
  21
+    {
  22
+        "from": "../foo",
  23
+        "to": ".."
  24
+    },
  25
+    {
  26
+        "from": "/foo/bar",
  27
+        "to": "/foo"
  28
+    },
  29
+    {
  30
+        "from": "/foo",
  31
+        "to": "/"
  32
+    },
  33
+    {
  34
+        "from": "/",
  35
+        "to": "/"
  36
+    }
  37
+].forEach(function (test) {
  38
+    exports['test ' + test.from] = function (assert) {
  39
+        assert.equal(FS.directory(test.from), test.to, 'ok');
  40
+    };
  41
+});
  42
+
  43
+if (require.main == module)
  44
+    require("test").run(exports);
  45
+

0 notes on commit 3ed1e56

Please sign in to comment.
Something went wrong with that request. Please try again.