Begin work on FileSystemShell and touch command

This commit is contained in:
David Humphrey (:humph) david.humphrey@senecacollege.ca 2014-02-15 10:05:04 -05:00
parent ed206d68d8
commit f618a44b9e
3 changed files with 86 additions and 2 deletions

View File

@ -53,6 +53,7 @@ define(function(require) {
var providers = require('src/providers/providers'); var providers = require('src/providers/providers');
var adapters = require('src/adapters/adapters'); var adapters = require('src/adapters/adapters');
var Shell = require('src/shell');
/* /*
* DirectoryEntry * DirectoryEntry
@ -2473,6 +2474,10 @@ define(function(require) {
callback(error); callback(error);
} }
}; };
FileSystem.prototype.Shell = function(options) {
return new Shell(this, options);
};
return FileSystem; return FileSystem;
}); });

View File

@ -4,7 +4,8 @@ define(function(require) {
return { return {
FileSystem: require('src/fs'), FileSystem: require('src/fs'),
FileSystemShell: require('src/shell'),
Path: require('src/path') Path: require('src/path')
} };
}); });

78
src/shell.js Normal file
View File

@ -0,0 +1,78 @@
define(function(require) {
function Shell(fs, options) {
options = options || {};
var cwd = options.cwd || '/';
Object.defineProperty(this, 'fs', {
get: function() { return fs; },
enumerable: true
});
Object.defineProperty(this, 'cwd', {
get: function() { return cwd; },
enumerable: true
});
// We include `cd` on the this vs. proto so that
// we can access cwd without exposing it externally.
this.cd = function(path) {
};
}
Shell.prototype.ls = function(path) {
};
Shell.prototype.rm = function(path, options, callback) {
};
Shell.prototype.mv = function(path) {
};
Shell.prototype.cp = function(path) {
};
Shell.prototype.mkdir = function(path) {
};
Shell.prototype.touch = function(path, options, callback) {
var fs = this.fs;
path = Path.resolve(this.cwd, path);
function createFile(path) {
fs.writeFile(path, '', function(error) {
callback(error);
});
}
function updateTimes(path) {
var now = Date.now();
fs.utimes(path, now, now, function(error) {
callback(error);
});
}
fs.stat(path, function(error, stats) {
if(error) {
createFile(path);
} else {
updateTimes(path);
}
});
};
Shell.prototype.ln = function(path) {
};
return Shell;
});