mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-23 23:42:29 +00:00
Update signature of fsUtils.getPathOnHost
The function now returns either a string array if it receives multiple arguments or a single string if it receives a single argument.
This commit is contained in:
parent
2917f03452
commit
a2d6db1e1d
@ -80,8 +80,14 @@ export async function unlinkAll(...paths: string[]): Promise<void> {
|
||||
/**
|
||||
* Get one or more paths as they exist in relation to host OS's root.
|
||||
*/
|
||||
export function getPathOnHost(...paths: string[]): string[] {
|
||||
export function getPathOnHost(path: string): string;
|
||||
export function getPathOnHost(...paths: string[]): string[];
|
||||
export function getPathOnHost(...paths: string[]): string[] | string {
|
||||
if (paths.length === 1) {
|
||||
return path.join(constants.rootMountPoint, paths[0]);
|
||||
} else {
|
||||
return paths.map((p: string) => path.join(constants.rootMountPoint, p));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -145,8 +145,7 @@ export function lock<T extends unknown>(
|
||||
.then((lockOverride) => {
|
||||
return writeLock(appId)
|
||||
.tap((release: () => void) => {
|
||||
const [lockDir] = getPathOnHost(lockPath(appId));
|
||||
|
||||
const lockDir = getPathOnHost(lockPath(appId));
|
||||
return Bluebird.resolve(fs.readdir(lockDir))
|
||||
.catchReturn(ENOENT, [])
|
||||
.mapSeries((serviceName) => {
|
||||
|
@ -154,9 +154,9 @@ describe('lib/fs-utils', () => {
|
||||
after(unmockFs);
|
||||
|
||||
it("should return the paths of one or more files as they exist on host OS's root", async () => {
|
||||
expect(fsUtils.getPathOnHost(testFileName1)).to.deep.equal([testFile1]);
|
||||
expect(fsUtils.getPathOnHost(testFileName1)).to.deep.equal(testFile1);
|
||||
expect(
|
||||
fsUtils.getPathOnHost(...[testFileName1, testFileName2]),
|
||||
fsUtils.getPathOnHost(testFileName1, testFileName2),
|
||||
).to.deep.equal([testFile1, testFile2]);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user