Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

winget-source: rename index file after syncing is done #113

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 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.tmp';
const sourceFilename = 'source.msix';

syncFile(sourceFilename, false, true).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 @@ -31,6 +34,7 @@ syncFile('source.msix').catch(exitOnError(EX_UNAVAILABLE)).then(async _ => {
async.eachLimit(uris, parallelLimit, download, (error) => {
rm(temp, { recursive: true });
exitOnError(EX_TEMPFAIL)(error);
rename(getLocalPath(tmpSourceFilename), getLocalPath(sourceFilename));
winston.info(`successfully synced with ${remote}`);
});
});
Expand Down
5 changes: 3 additions & 2 deletions winget-source/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,12 @@ export function setupEnvironment() {
*
* @param {string} uri URI to sync.
* @param {boolean} update Whether to allow updating an existing file.
* @param {boolean} saveAsTmp Whether to save with ".tmp" suffix
*
* @returns {Promise<boolean>} If the file is new or updated.
*/
export async function syncFile(uri, update = true) {
const localPath = getLocalPath(uri);
export async function syncFile(uri, update = true, saveAsTmp = false) {
const localPath = getLocalPath(saveAsTmp ? uri + ".tmp" : uri);
const remoteURL = getRemoteURL(uri);
await mkdir(path.dirname(localPath), { recursive: true });
if (existsSync(localPath)) {
Expand Down
Loading