MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / renameAsset

Function renameAsset

apps/desktop/src/main/vault.ts:3271–3298  ·  view source on GitHub ↗
(
  root: string,
  rel: string,
  nextName: string
)

Source from the content-addressed store, hash-verified

3269}
3270
3271export async function renameAsset(
3272 root: string,
3273 rel: string,
3274 nextName: string
3275): Promise<AssetMeta> {
3276 const source = await assertAssetFile(root, rel)
3277 const cleanName = cleanAssetFilename(nextName)
3278 const destAbs = path.join(path.dirname(source.abs), cleanName)
3279 if (destAbs !== source.abs) {
3280 try {
3281 await fs.access(destAbs)
3282 const [srcStat, dstStat] = await Promise.all([fs.stat(source.abs), fs.stat(destAbs)])
3283 if (srcStat.ino !== dstStat.ino) {
3284 throw new Error(`An asset named "${cleanName}" already exists in this folder.`)
3285 }
3286 } catch (e) {
3287 if ((e as NodeJS.ErrnoException).code !== 'ENOENT') throw e
3288 }
3289 if (source.abs.toLowerCase() === destAbs.toLowerCase() && source.abs !== destAbs) {
3290 const tmp = `${source.abs}_rename_tmp_${Date.now()}`
3291 await fs.rename(source.abs, tmp)
3292 await fs.rename(tmp, destAbs)
3293 } else {
3294 await fs.rename(source.abs, destAbs)
3295 }
3296 }
3297 return await assetMetaForPath(root, destAbs)
3298}
3299
3300export async function moveAsset(
3301 root: string,

Callers 2

vault.test.tsFile · 0.90
registerIpcFunction · 0.90

Calls 3

assertAssetFileFunction · 0.85
cleanAssetFilenameFunction · 0.85
assetMetaForPathFunction · 0.85

Tested by

no test coverage detected