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:
Felipe Lalanne 2022-02-10 15:30:30 -03:00
parent 2917f03452
commit a2d6db1e1d
3 changed files with 11 additions and 6 deletions

View File

@ -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));
}
}
/**

View File

@ -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) => {

View File

@ -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]);
});
});