UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

51 lines • 1.93 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 { createDirectory as createRemoteDirectory } from "./client.js"; import { parentPath } from "./_helpers.js"; import { isNotFound } from "./errors.js"; import { backendPath } from "./path.js"; import { stat } from "./stat.js"; import { enoent, enotdir } from "../../errors/fs.js"; async function createDirectory(accessor, remotePath, virtualTarget) { try { await createRemoteDirectory(accessor, remotePath); } catch (exc) { if (isNotFound(exc)) throw enoent(virtualTarget); throw exc; } } export async function mkdir(accessor, path, parents = false) { const remotePath = backendPath(accessor.config, path); if (parents) { await createDirectory(accessor, remotePath, path.virtual); return; } let parentStat; try { parentStat = await stat(accessor, parentPath(path)); } catch (exc) { if (exc.code === 'ENOENT') throw enoent(path.virtual); throw exc; } if (parentStat.type !== FileType.DIRECTORY) { throw enotdir(path.virtual); } await createDirectory(accessor, remotePath, path.virtual); } //# sourceMappingURL=mkdir.js.map