maestro/app/classes/state/fs/DirectoryState.js
2020-04-15 09:11:10 -05:00

40 lines
860 B
JavaScript

const State = require('../State')
class DirectoryState extends State {
async apply() {
if ( !(await this.check()) ) {
const path = await this._path()
await path.touch(true)
// TODO directories
}
}
async check() {
const path = await this._path()
await path.classify()
return path.is_directory()
}
async reverse() {
if ( await this.check() ) {
const path = await this._path()
await path.unlink()
}
}
async _path() {
return this._host.get_path(this._config.path)
}
failure_message() {
return `The path "${this._config.path}" does not exist on host "${this._host.name}."`
}
check_message() {
return this.failure_message()
}
}
module.exports = exports = DirectoryState