Skip to content

Commit

Permalink
winget-source: rename index file after syncing is done
Browse files Browse the repository at this point in the history
Try fixing the issue mentioned in
ustclug/discussions#435 (comment).
  • Loading branch information
taoky committed Jun 30, 2024
1 parent d4b9466 commit 196ab87
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions winget-source/sync-repo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import async from 'async'
import { rm } from 'fs/promises'
import { rm, rename } from 'fs/promises'
import { EX_IOERR, EX_TEMPFAIL, EX_UNAVAILABLE } from './sysexits.js';

import {
Expand All @@ -17,9 +17,12 @@ const { parallelLimit, remote, sqlite3, winston } = setupEnvironment();

winston.info(`start syncing with ${remote}`);

syncFile('source.msix').catch(exitOnError(EX_UNAVAILABLE)).then(async _ => {
const tmpSourceFilename = 'source.msix.syncing';
const sourceFilename = 'source.msix';

syncFile(tmpSourceFilename).catch(exitOnError(EX_UNAVAILABLE)).then(async _ => {
const temp = await makeTempDirectory('winget-repo-');
const database = await extractDatabaseFromBundle(getLocalPath('source.msix'), temp);
const database = await extractDatabaseFromBundle(getLocalPath(tmpSourceFilename), temp);
const db = new sqlite3.Database(database, sqlite3.OPEN_READONLY, exitOnError(EX_IOERR));

db.all('SELECT * FROM pathparts', (error, rows) => {
Expand All @@ -35,4 +38,6 @@ syncFile('source.msix').catch(exitOnError(EX_UNAVAILABLE)).then(async _ => {
});
});
});
}).then(() => {
rename(getLocalPath(tmpSourceFilename), getLocalPath(sourceFilename))
});

0 comments on commit 196ab87

Please sign in to comment.