@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
50 lines • 2.07 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 { epochToIso } from "../../../utils/dates.js";
/**
* Overlay namespace node attrs onto a backend stat.
*
* Backends without a native attribute slot store chmod/chown/touch
* results in the namespace node table; every stat surface (dispatch,
* `ws.vfs`, FUSE) merges through here (overlay wins per-field)
* so they cannot disagree.
*/
export function mergeOverlayStat(meta, stat) {
if (meta === null)
return stat;
const update = {};
if (meta.mode !== undefined)
update.mode = meta.mode;
if (meta.uid !== undefined)
update.uid = meta.uid;
if (meta.gid !== undefined)
update.gid = meta.gid;
if (meta.atime !== undefined)
update.atime = meta.atime;
if (meta.mtime !== undefined && meta.target === undefined) {
update.modified = epochToIso(meta.mtime);
}
else if (meta.observedMtime !== undefined &&
meta.target === undefined &&
stat.modified === null) {
// Fallback only: a backend-reported mtime always wins; the observed
// write time fills the gap on mtime-less backends so `find -mtime`
// and `ls -l` see when mirage last wrote the file.
update.modified = epochToIso(meta.observedMtime);
}
if (Object.keys(update).length === 0)
return stat;
return stat.with(update);
}
//# sourceMappingURL=overlay.js.map