1 | (function (require, exports) {
|
2 |
|
3 | var Q = require("q");
|
4 | var BOOT = require("fs-boot");
|
5 | var COMMON = require("./common");
|
6 |
|
7 | var Fs = exports.Fs = function (outer, root) {
|
8 | var inner = Object.create(BOOT);
|
9 |
|
10 | function attenuate(path) {
|
11 |
|
12 |
|
13 |
|
14 | var actual;
|
15 |
|
16 |
|
17 | if (outer.isAbsolute(path)) {
|
18 | actual = outer.relativeFromDirectory(outer.ROOT, path);
|
19 | } else {
|
20 | actual = path;
|
21 | }
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | actual = outer.join(outer.ROOT, actual);
|
27 |
|
28 |
|
29 | actual = outer.relativeFromDirectory(outer.ROOT, actual);
|
30 |
|
31 | actual = outer.join(root, actual);
|
32 |
|
33 | actual = outer.canonical(actual);
|
34 | return Q.when(actual, function (actual) {
|
35 |
|
36 |
|
37 |
|
38 | if (outer.contains(root, actual)) {
|
39 | return {
|
40 | "inner": outer.join(outer.ROOT, outer.relativeFromDirectory(root, actual)),
|
41 | "outer": actual
|
42 | };
|
43 | } else {
|
44 | return Q.reject("No such file: " + JSON.stringify(path));
|
45 | }
|
46 | });
|
47 | }
|
48 |
|
49 | function workingDirectory() {
|
50 | return outer.ROOT;
|
51 | }
|
52 |
|
53 | COMMON.update(inner, workingDirectory);
|
54 |
|
55 | inner.list = function (path) {
|
56 | return Q.when(attenuate(path), function (path) {
|
57 | return outer.list(path.outer);
|
58 | }).then(null, function (reason) {
|
59 | return Q.reject("Can't list " + JSON.stringify(path));
|
60 | });
|
61 | };
|
62 |
|
63 | inner.open = function (path, flags, charset) {
|
64 | return Q.when(attenuate(path), function (path) {
|
65 | return outer.open(path.outer, flags, charset);
|
66 | }).then(null, function (reason) {
|
67 | return Q.reject("Can't open " + JSON.stringify(path));
|
68 | });
|
69 | };
|
70 |
|
71 | inner.stat = function (path) {
|
72 | return Q.when(attenuate(path), function (path) {
|
73 | return outer.stat(path.outer);
|
74 | }).then(null, function (reason) {
|
75 | return Q.reject("Can't stat " + JSON.stringify(path));
|
76 | });
|
77 | };
|
78 |
|
79 | inner.canonical = function (path) {
|
80 | return Q.when(attenuate(path), function (path) {
|
81 | return path.inner;
|
82 | }).then(null, function (reason) {
|
83 | return Q.reject("Can't find canonical of " + JSON.stringify(path));
|
84 | });
|
85 | };
|
86 |
|
87 | return Q.when(outer.canonical(root), function (_root) {
|
88 | root = _root;
|
89 | return inner;
|
90 | });
|
91 | };
|
92 |
|
93 | }).apply(null, typeof exports !== "undefined" ?
|
94 | [require, exports] :
|
95 | [
|
96 | function (id) {
|
97 | id = id.toUpperCase()
|
98 | .replace(".", "Q_FS")
|
99 | .replace("/", "$")
|
100 | .replace("-", "_");
|
101 | return window[id];
|
102 | },
|
103 | Q_FS$ROOT
|
104 | ]
|
105 | )
|