-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(app-config): Load app id from appinfo if possible
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
- Loading branch information
Showing
2 changed files
with
73 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import { lstatSync } from 'node:fs' | ||
import { join, resolve, sep } from 'node:path' | ||
|
||
/** | ||
* Check if a given path exists and is a directory | ||
* | ||
* @param {string} filePath The path | ||
* @return {boolean} | ||
*/ | ||
function isDirectory(filePath: string): boolean { | ||
const stats = lstatSync(filePath, { throwIfNoEntry: false }) | ||
return stats !== undefined && stats.isDirectory() | ||
} | ||
|
||
/** | ||
* Check if a given path exists and is a directory | ||
* | ||
* @param {string} filePath The path | ||
* @return {boolean} | ||
*/ | ||
function isFile(filePath: string): boolean { | ||
const stats = lstatSync(filePath, { throwIfNoEntry: false }) | ||
return stats !== undefined && stats.isFile() | ||
} | ||
|
||
/** | ||
* Find the path of nearest `appinfo/info.xml` relative to given path | ||
* | ||
* @param {string} currentPath The path to check for appinfo | ||
* @return {string|undefined} Either the full path including the `info.xml` part or `undefined` if no found | ||
*/ | ||
export function findAppinfo(currentPath: string): string | null { | ||
while (currentPath && currentPath !== sep) { | ||
const appinfoPath = join(currentPath, 'appinfo') | ||
if (isDirectory(appinfoPath) && isFile(join(appinfoPath, 'info.xml'))) { | ||
return join(appinfoPath, 'info.xml') | ||
} | ||
currentPath = resolve(currentPath, '..') | ||
} | ||
return undefined | ||
} |