( root: string, rel: string, nextName: string )
| 3269 | } |
| 3270 | |
| 3271 | export 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 | |
| 3300 | export async function moveAsset( |
| 3301 | root: string, |
no test coverage detected