UNPKG

jsdav-ext

Version:

jsDAV allows you to easily add WebDAV support to a NodeJS application. jsDAV is meant to cover the entire standard, and attempts to allow integration using an easy to understand API.

78 lines (69 loc) 2.05 kB
/* * @package jsDAV * @subpackage DAV * @copyright Copyright(c) 2011 Ajax.org B.V. <info AT ajax DOT org> * @author Mike de Boer <info AT mikedeboer DOT nl> * @license http://github.com/mikedeboer/jsDAV/blob/master/LICENSE MIT License */ "use strict"; var jsDAV_iNode = require("./../../interfaces/iNode"); var Fs = require("fs"); var Path = require("path"); var Util = require("./../../../shared/util"); var jsDAV_FS_Node = module.exports = jsDAV_iNode.extend({ initialize: function(path) { this.path = path; }, /** * Returns the name of the node * * @return {string} */ getName: function() { if(this.mountedPath) { return Util.splitPath(this.mountedPath)[1]; } return Util.splitPath(this.path)[1]; }, /** * Renames the node * * @param {string} name The new name * @return void */ setName: function(name, cbfssetname) { var parentPath = Util.splitPath(this.path)[0]; var newName = Util.splitPath(name)[1]; var newPath = Path.join(parentPath, newName); var self = this; Fs.rename(this.path, newPath, function(err) { if (err) return cbfssetname(err); self.path = newPath; cbfssetname(); }); }, /** * Returns the last modification time, as a unix timestamp * * @return {Number} */ getLastModified: function(cbfsgetlm) { if (this.$stat) return cbfsgetlm(null, this.$stat.mtime); Fs.stat(this.path, function(err, stat) { if (err || typeof stat == "undefined") return cbfsgetlm(err); //_self.$stat = stat; cbfsgetlm(null, stat.mtime); }); }, /** * Returns whether a node exists or not * * @return {Boolean} */ exists: function(cbfsexist) { Fs.exists(this.path, cbfsexist); }, });