Files
xen-orchestra/@xen-orchestra/fs/src/path.js
Florent Beauchamp ad149740b1 feat(backups/cleanVm,vhd-lib): support resuming merge of VHD chains
The whole chain is now stored in the merge state.
2022-08-04 15:25:31 +02:00

25 lines
674 B
JavaScript

import path from 'path'
const { basename, dirname, join, resolve, relative, sep } = path.posix
export { basename, dirname, join }
// normalize the path:
// - does not contains `.` or `..` (cannot escape root dir)
// - always starts with `/`
// - no trailing slash (expect for root)
// - no duplicate slashes
export const normalize = path => resolve('/', path)
export function split(path) {
const parts = normalize(path).split(sep)
// remove first (empty) entry
parts.shift()
return parts
}
export const relativeFromFile = (file, path) => relative(dirname(file), path)
export const resolveFromFile = (file, path) => resolve('/', dirname(file), path).slice(1)