@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
52 lines • 2.18 kB
JavaScript
// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
import { operandsIo } from "../../utils/operands.js";
import { fsStrerror, isFsError } from "../../../../errors/fs.js";
import { specOf } from "../../../spec/builtins.js";
import { FlagView } from "../../../spec/flag_view.js";
import { commandFiles } from "../files.js";
import { UsageError } from "../../../errors.js";
import { usageHint } from "../../../spec/usage.js";
const touch = async (_accessor, paths, _texts, ctx) => {
const files = commandFiles(ctx, paths);
if (paths.length === 0) {
throw new UsageError(`touch: missing file operand\n${usageHint('touch')}`, 1);
}
const resolved = await files.resolveGlob(paths);
const createOnly = new FlagView(ctx.flags, specOf('touch')).asBool('no_create');
const errors = [];
for (const p of resolved) {
if (createOnly)
continue;
if (await files.exists(p))
continue;
try {
await files.write(p, new Uint8Array(0));
}
catch (err) {
// One unusable operand is not an aborted command: GNU reports it
// and still touches the remaining ones.
if (!isFsError(err))
throw err;
errors.push(`touch: cannot touch '${p.virtual}': ${String(fsStrerror(err))}`);
}
}
return [null, operandsIo(errors.map((line) => `${line}\n`).join(''))];
};
export const BUILDER = {
name: 'touch',
write: true,
fn: touch,
};
//# sourceMappingURL=touch.js.map