mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-05-30 01:31:06 +08:00
feat(update-center): 添加详细日志记录以帮助调试更新中心服务
在更新中心服务的关键路径添加console.log和console.error输出 包括服务刷新、包解析、命令执行等环节的输入输出和中间状态 便于排查更新中心相关的问题
This commit is contained in:
@@ -52,7 +52,10 @@ const categoryCache = new Map<string, Promise<StoreAppMetadataMap>>();
|
|||||||
|
|
||||||
const APTSS_LIST_UPGRADABLE_COMMAND = {
|
const APTSS_LIST_UPGRADABLE_COMMAND = {
|
||||||
command: "bash",
|
command: "bash",
|
||||||
args: ["-lc", "env LANGUAGE=en_US aptss list --upgradable"],
|
args: [
|
||||||
|
"-lc",
|
||||||
|
"env LANGUAGE=en_US /usr/bin/apt -c /opt/durapps/spark-store/bin/apt-fast-conf/aptss-apt.conf list --upgradable -o Dir::Etc::sourcelist=/opt/durapps/spark-store/bin/apt-fast-conf/sources.list.d/aptss.list -o Dir::Etc::sourceparts=/dev/null -o APT::Get::List-Cleanup=0 | awk 'NR>1'",
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
const DPKG_QUERY_INSTALLED_COMMAND = {
|
const DPKG_QUERY_INSTALLED_COMMAND = {
|
||||||
@@ -363,9 +366,10 @@ const isCommandAvailable = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const loadUpdateCenterItems = async (
|
export const loadUpdateCenterItems = async (
|
||||||
runCommand: UpdateCenterCommandRunner = runCommandCapture,
|
|
||||||
storeFilter: StoreFilter = "both",
|
storeFilter: StoreFilter = "both",
|
||||||
|
runCommand: UpdateCenterCommandRunner = runCommandCapture,
|
||||||
): Promise<UpdateCenterLoadItemsResult> => {
|
): Promise<UpdateCenterLoadItemsResult> => {
|
||||||
|
console.log(`[UpdateCenter] loadUpdateCenterItems called with storeFilter=${storeFilter}`);
|
||||||
const [sparkEnabled, apmEnabled] = await Promise.all([
|
const [sparkEnabled, apmEnabled] = await Promise.all([
|
||||||
isSourceEnabled(storeFilter, "spark")
|
isSourceEnabled(storeFilter, "spark")
|
||||||
? isCommandAvailable(runCommand, "aptss")
|
? isCommandAvailable(runCommand, "aptss")
|
||||||
@@ -374,6 +378,7 @@ export const loadUpdateCenterItems = async (
|
|||||||
? isCommandAvailable(runCommand, "apm")
|
? isCommandAvailable(runCommand, "apm")
|
||||||
: Promise.resolve(false),
|
: Promise.resolve(false),
|
||||||
]);
|
]);
|
||||||
|
console.log(`[UpdateCenter] sparkEnabled=${sparkEnabled}, apmEnabled=${apmEnabled}`);
|
||||||
|
|
||||||
const [aptssResult, apmResult, aptssInstalledResult, apmInstalledResult] =
|
const [aptssResult, apmResult, aptssInstalledResult, apmInstalledResult] =
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
@@ -397,6 +402,11 @@ export const loadUpdateCenterItems = async (
|
|||||||
: Promise.resolve({ code: 0, stdout: "", stderr: "" }),
|
: Promise.resolve({ code: 0, stdout: "", stderr: "" }),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
console.log(`[UpdateCenter] aptssResult: code=${aptssResult.code}, stdout=${aptssResult.stdout.substring(0, 500)}, stderr=${aptssResult.stderr.substring(0, 500)}`);
|
||||||
|
console.log(`[UpdateCenter] apmResult: code=${apmResult.code}, stdout=${apmResult.stdout.substring(0, 500)}, stderr=${apmResult.stderr.substring(0, 500)}`);
|
||||||
|
console.log(`[UpdateCenter] aptssInstalledResult: code=${aptssInstalledResult.code}, stdout=${aptssInstalledResult.stdout.substring(0, 500)}`);
|
||||||
|
console.log(`[UpdateCenter] apmInstalledResult: code=${apmInstalledResult.code}, stdout=${apmInstalledResult.stdout.substring(0, 500)}`);
|
||||||
|
|
||||||
const aptssAvailable =
|
const aptssAvailable =
|
||||||
sparkEnabled && (aptssResult.code === 0 || aptssInstalledResult.code === 0);
|
sparkEnabled && (aptssResult.code === 0 || aptssInstalledResult.code === 0);
|
||||||
|
|
||||||
@@ -421,6 +431,8 @@ export const loadUpdateCenterItems = async (
|
|||||||
apmEnabled && apmResult.code === 0
|
apmEnabled && apmResult.code === 0
|
||||||
? parseApmUpgradableOutput(apmResult.stdout)
|
? parseApmUpgradableOutput(apmResult.stdout)
|
||||||
: [];
|
: [];
|
||||||
|
console.log(`[UpdateCenter] parsed aptssItems count=${aptssItems.length}`, aptssItems.map((i) => `${i.pkgname} ${i.currentVersion}->${i.nextVersion}`));
|
||||||
|
console.log(`[UpdateCenter] parsed apmItems count=${apmItems.length}`, apmItems.map((i) => `${i.pkgname} ${i.currentVersion}->${i.nextVersion}`));
|
||||||
|
|
||||||
const installedSources = buildInstalledSourceMap(
|
const installedSources = buildInstalledSourceMap(
|
||||||
aptssAvailable && aptssInstalledResult.code === 0
|
aptssAvailable && aptssInstalledResult.code === 0
|
||||||
@@ -428,6 +440,7 @@ export const loadUpdateCenterItems = async (
|
|||||||
: "",
|
: "",
|
||||||
apmInstalledResult.code === 0 ? apmInstalledResult.stdout : "",
|
apmInstalledResult.code === 0 ? apmInstalledResult.stdout : "",
|
||||||
);
|
);
|
||||||
|
console.log(`[UpdateCenter] installedSources size=${installedSources.size}`);
|
||||||
|
|
||||||
const [categorizedAptssItems, categorizedApmItems] = await Promise.all([
|
const [categorizedAptssItems, categorizedApmItems] = await Promise.all([
|
||||||
aptssAvailable ? enrichItemCategories(aptssItems) : Promise.resolve([]),
|
aptssAvailable ? enrichItemCategories(aptssItems) : Promise.resolve([]),
|
||||||
@@ -441,13 +454,18 @@ export const loadUpdateCenterItems = async (
|
|||||||
? enrichApmItems(categorizedApmItems, runCommand)
|
? enrichApmItems(categorizedApmItems, runCommand)
|
||||||
: Promise.resolve({ items: [], warnings: [] }),
|
: Promise.resolve({ items: [], warnings: [] }),
|
||||||
]);
|
]);
|
||||||
|
console.log(`[UpdateCenter] enrichedAptssItems: count=${enrichedAptssItems.items.length}, warnings=${enrichedAptssItems.warnings.length}`, enrichedAptssItems.warnings);
|
||||||
|
console.log(`[UpdateCenter] enrichedApmItems: count=${enrichedApmItems.items.length}, warnings=${enrichedApmItems.warnings.length}`, enrichedApmItems.warnings);
|
||||||
|
|
||||||
return {
|
const mergedItems = mergeUpdateSources(
|
||||||
items: mergeUpdateSources(
|
|
||||||
enrichItemIcons(enrichedAptssItems.items),
|
enrichItemIcons(enrichedAptssItems.items),
|
||||||
enrichItemIcons(enrichedApmItems.items),
|
enrichItemIcons(enrichedApmItems.items),
|
||||||
installedSources,
|
installedSources,
|
||||||
),
|
);
|
||||||
|
console.log(`[UpdateCenter] mergedItems count=${mergedItems.length}`, mergedItems.map((i) => `${i.pkgname} (${i.source}) ${i.currentVersion}->${i.nextVersion}`));
|
||||||
|
|
||||||
|
return {
|
||||||
|
items: mergedItems,
|
||||||
warnings: [
|
warnings: [
|
||||||
...warnings,
|
...warnings,
|
||||||
...enrichedAptssItems.warnings,
|
...enrichedAptssItems.warnings,
|
||||||
|
|||||||
@@ -262,10 +262,19 @@ const compareVersions = (left: string, right: string): number => {
|
|||||||
|
|
||||||
export const parseAptssUpgradableOutput = (
|
export const parseAptssUpgradableOutput = (
|
||||||
output: string,
|
output: string,
|
||||||
): UpdateCenterItem[] => parseUpgradableOutput(output, "aptss");
|
): UpdateCenterItem[] => {
|
||||||
|
console.log(`[UpdateCenter] parseAptssUpgradableOutput input (first 1000 chars): ${output.substring(0, 1000)}`);
|
||||||
|
const result = parseUpgradableOutput(output, "aptss");
|
||||||
|
console.log(`[UpdateCenter] parseAptssUpgradableOutput result count=${result.length}`);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
export const parseApmUpgradableOutput = (output: string): UpdateCenterItem[] =>
|
export const parseApmUpgradableOutput = (output: string): UpdateCenterItem[] => {
|
||||||
parseUpgradableOutput(output, "apm");
|
console.log(`[UpdateCenter] parseApmUpgradableOutput input (first 1000 chars): ${output.substring(0, 1000)}`);
|
||||||
|
const result = parseUpgradableOutput(output, "apm");
|
||||||
|
console.log(`[UpdateCenter] parseApmUpgradableOutput result count=${result.length}`);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
export const parsePrintUrisOutput = (
|
export const parsePrintUrisOutput = (
|
||||||
output: string,
|
output: string,
|
||||||
@@ -273,8 +282,11 @@ export const parsePrintUrisOutput = (
|
|||||||
UpdateCenterItem,
|
UpdateCenterItem,
|
||||||
"downloadUrl" | "fileName" | "size" | "sha512"
|
"downloadUrl" | "fileName" | "size" | "sha512"
|
||||||
> | null => {
|
> | null => {
|
||||||
const match = output.trim().match(PRINT_URIS_PATTERN);
|
const trimmed = output.trim();
|
||||||
|
console.log(`[UpdateCenter] parsePrintUrisOutput input (first 500 chars): ${trimmed.substring(0, 500)}`);
|
||||||
|
const match = trimmed.match(PRINT_URIS_PATTERN);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
|
console.log(`[UpdateCenter] parsePrintUrisOutput: no match found for pattern ${PRINT_URIS_PATTERN}`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -166,22 +166,27 @@ export const createUpdateCenterService = (
|
|||||||
storeFilter: StoreFilter = currentStoreFilter,
|
storeFilter: StoreFilter = currentStoreFilter,
|
||||||
): Promise<UpdateCenterServiceState> => {
|
): Promise<UpdateCenterServiceState> => {
|
||||||
currentStoreFilter = storeFilter;
|
currentStoreFilter = storeFilter;
|
||||||
|
console.log(`[UpdateCenter] service.refresh called with storeFilter=${storeFilter}`);
|
||||||
queue.startRefresh();
|
queue.startRefresh();
|
||||||
emit();
|
emit();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const ignoredEntries = await loadIgnored();
|
const ignoredEntries = await loadIgnored();
|
||||||
|
console.log(`[UpdateCenter] ignoredEntries count=${ignoredEntries.size}`);
|
||||||
const loadedItems = normalizeLoadedItems(
|
const loadedItems = normalizeLoadedItems(
|
||||||
await options.loadItems(currentStoreFilter),
|
await options.loadItems(currentStoreFilter),
|
||||||
);
|
);
|
||||||
|
console.log(`[UpdateCenter] loadItems returned: items=${loadedItems.items.length}, warnings=${loadedItems.warnings.length}`, loadedItems.warnings);
|
||||||
const items = sortIgnoredItems(
|
const items = sortIgnoredItems(
|
||||||
applyIgnoredEntries(loadedItems.items, ignoredEntries),
|
applyIgnoredEntries(loadedItems.items, ignoredEntries),
|
||||||
);
|
);
|
||||||
|
console.log(`[UpdateCenter] after applying ignored: items=${items.length}`);
|
||||||
queue.setItems(items);
|
queue.setItems(items);
|
||||||
queue.finishRefresh(loadedItems.warnings);
|
queue.finishRefresh(loadedItems.warnings);
|
||||||
return emit();
|
return emit();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = error instanceof Error ? error.message : String(error);
|
const message = error instanceof Error ? error.message : String(error);
|
||||||
|
console.error(`[UpdateCenter] refresh error:`, error);
|
||||||
queue.setItems([]);
|
queue.setItems([]);
|
||||||
applyWarning(message);
|
applyWarning(message);
|
||||||
return emit();
|
return emit();
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ type RemoteStoreResponse =
|
|||||||
| Array<Record<string, unknown>>;
|
| Array<Record<string, unknown>>;
|
||||||
|
|
||||||
const APTSS_LIST_UPGRADABLE_KEY =
|
const APTSS_LIST_UPGRADABLE_KEY =
|
||||||
"bash -lc env LANGUAGE=en_US aptss list --upgradable";
|
"bash -lc env LANGUAGE=en_US /usr/bin/apt -c /opt/durapps/spark-store/bin/apt-fast-conf/aptss-apt.conf list --upgradable -o Dir::Etc::sourcelist=/opt/durapps/spark-store/bin/apt-fast-conf/sources.list.d/aptss.list -o Dir::Etc::sourceparts=/dev/null -o APT::Get::List-Cleanup=0 | awk 'NR>1'";
|
||||||
|
|
||||||
const DPKG_QUERY_INSTALLED_KEY =
|
const DPKG_QUERY_INSTALLED_KEY =
|
||||||
"dpkg-query -W -f=${Package}\t${db:Status-Want} ${db:Status-Status} ${db:Status-Eflag}\n";
|
"dpkg-query -W -f=${Package}\t${db:Status-Want} ${db:Status-Status} ${db:Status-Eflag}\n";
|
||||||
@@ -191,7 +191,7 @@ describe("update-center load items", () => {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await loadUpdateCenterItems(async (command, args) => {
|
const result = await loadUpdateCenterItems("both", async (command, args) => {
|
||||||
const key = `${command} ${args.join(" ")}`;
|
const key = `${command} ${args.join(" ")}`;
|
||||||
const match = commandResults.get(key);
|
const match = commandResults.get(key);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
@@ -233,7 +233,7 @@ describe("update-center load items", () => {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await loadUpdateCenterItems(async (command, args) => {
|
const result = await loadUpdateCenterItems("both", async (command, args) => {
|
||||||
const key = `${command} ${args.join(" ")}`;
|
const key = `${command} ${args.join(" ")}`;
|
||||||
|
|
||||||
if (key === WHICH_APTSS_KEY) {
|
if (key === WHICH_APTSS_KEY) {
|
||||||
@@ -360,7 +360,7 @@ describe("update-center load items", () => {
|
|||||||
throw new Error(`Unexpected command ${key}`);
|
throw new Error(`Unexpected command ${key}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const firstResult = await loadUpdateCenterItems(runCommand);
|
const firstResult = await loadUpdateCenterItems("both", runCommand);
|
||||||
|
|
||||||
expect(firstResult.items).toEqual([
|
expect(firstResult.items).toEqual([
|
||||||
{
|
{
|
||||||
@@ -384,7 +384,7 @@ describe("update-center load items", () => {
|
|||||||
"https://erotica.spark-app.store/amd64-store/office/applist.json"
|
"https://erotica.spark-app.store/amd64-store/office/applist.json"
|
||||||
] = [{ Name: "Spark Notes", Pkgname: "spark-notes" }];
|
] = [{ Name: "Spark Notes", Pkgname: "spark-notes" }];
|
||||||
|
|
||||||
const secondResult = await loadUpdateCenterItems(runCommand);
|
const secondResult = await loadUpdateCenterItems("both", runCommand);
|
||||||
|
|
||||||
expect(secondResult.items).toEqual([
|
expect(secondResult.items).toEqual([
|
||||||
{
|
{
|
||||||
@@ -416,7 +416,7 @@ describe("update-center load items", () => {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await loadUpdateCenterItems(async (command, args) => {
|
const result = await loadUpdateCenterItems("both", async (command, args) => {
|
||||||
const key = `${command} ${args.join(" ")}`;
|
const key = `${command} ${args.join(" ")}`;
|
||||||
|
|
||||||
if (key === WHICH_APTSS_KEY) {
|
if (key === WHICH_APTSS_KEY) {
|
||||||
@@ -531,7 +531,7 @@ describe("update-center load items", () => {
|
|||||||
throw new Error(`Unexpected command ${key}`);
|
throw new Error(`Unexpected command ${key}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
await loadUpdateCenterItems(runCommand, "apm");
|
await loadUpdateCenterItems("apm", runCommand);
|
||||||
|
|
||||||
expect(runCommand).not.toHaveBeenCalledWith(
|
expect(runCommand).not.toHaveBeenCalledWith(
|
||||||
"bash",
|
"bash",
|
||||||
@@ -590,7 +590,7 @@ describe("update-center load items", () => {
|
|||||||
throw new Error(`Unexpected command ${key}`);
|
throw new Error(`Unexpected command ${key}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
await loadUpdateCenterItems(runCommand, "spark");
|
await loadUpdateCenterItems("spark", runCommand);
|
||||||
|
|
||||||
expect(runCommand).not.toHaveBeenCalledWith("apm", [
|
expect(runCommand).not.toHaveBeenCalledWith("apm", [
|
||||||
"list",
|
"list",
|
||||||
|
|||||||
Reference in New Issue
Block a user