UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

52 lines • 2 kB
// ========= 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 { FileType } from "../../types.js"; import { deleteDirectory, listDirectoryContents } from "./client.js"; import { isNotFound } from "./errors.js"; import { backendPath } from "./path.js"; import { holdsChild } from "./rm.js"; import { stat } from "./stat.js"; import { enoent, enotdir, enotempty } from "../../errors/fs.js"; export async function rmdir(accessor, path) { const fileStat = await stat(accessor, path); if (fileStat.type !== FileType.DIRECTORY) { throw enotdir(path.virtual); } const remotePath = backendPath(accessor.config, path); let entries; try { entries = await listDirectoryContents(accessor, remotePath); } catch (exc) { if (isNotFound(exc)) throw enoent(path.virtual); throw exc; } if (entries.length > 0) { throw enotempty(path.virtual); } try { await deleteDirectory(accessor, remotePath); } catch (exc) { if (isNotFound(exc)) throw enoent(path.virtual); // The Files API deletes only an empty directory, so a child written // after the listing refuses it. if (await holdsChild(accessor, remotePath)) throw enotempty(path.virtual); throw exc; } } //# sourceMappingURL=rmdir.js.map