forked from billywhizz/nodeftpd
-
Notifications
You must be signed in to change notification settings - Fork 2
/
dummyfs.js
45 lines (42 loc) · 906 Bytes
/
dummyfs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var sys = require("sys");
function dummyfs() {
this.dir = "/home/rob/workspace";
}
sys.inherits(dummyfs, process.EventEmitter);
exports.dummyfs = dummyfs;
dummyfs.prototype.chdir = function(dir) {
if(dir.charAt(dir.length-1) != "/") dir += "/";
if(dir.charAt(0) != "/"){
if(dir.substr(0,2) == ".."){
x = dir.split("/");
for(i=0; i<x.length; i++){
if(x[i] == ".."){
part = this.dir.split("/");
part.splice(part.length -2, 1);
ret = part.join("/");
if(ret.charAt(ret.length-1) != "/") ret += "/";
this.dir = ret;
}
else{
this.dir += x[i];
}
}
}
else{
if(dir.substr(0,2) == "./"){
this.dir += dir.substr(2,dir.length);
}
else{
this.dir += dir;
}
}
}
else{
this.dir = dir;
}
if(this.dir.charAt(this.dir.length-1) != "/") this.dir += "/";
return(this.dir);
}
dummyfs.prototype.cwd = function() {
return(this.dir)
}