You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
maestro/app/classes/state/fs/FileState.js

45 lines
1.1 KiB

const State = require('../State')
class FileState extends State {
async apply() {
if ( !(await this.check()) ) {
const path = await this._path()
await path.touch()
if ( this._config.contents ) {
await path.echo(this._config.contents)
} else if ( this._config.template ) {
await path.copy_from(this._config.template)
}
}
}
async check() {
const path = await this._path()
await path.classify()
return path.is_file()
}
async reverse() {
if ( await this.check() ) {
const path = await this._path()
await path.unlink()
}
}
async _path() {
if ( !this._config.path ) throw new Error('Missing path config for FileState.')
return this._host.get_path(this._config.path)
}
failure_message() {
return `The file "${this._config.path}" does not exist on the host "${this._host.name}."`
}
check_message() {
return this.failure_message()
}
}
module.exports = exports = FileState