Skip to content

Commit

Permalink
winget-source: use .tmp instead of .bak in syncFile
Browse files Browse the repository at this point in the history
  • Loading branch information
taoky committed Jul 1, 2024
1 parent 2fbf158 commit 34f4879
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions winget-source/sync-repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ const { parallelLimit, remote, sqlite3, winston } = setupEnvironment();

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

const bakSourceFilename = 'source.msix.bak';
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(bakSourceFilename), 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 @@ -34,7 +34,7 @@ syncFile(sourceFilename, false, true).catch(exitOnError(EX_UNAVAILABLE)).then(as
async.eachLimit(uris, parallelLimit, download, (error) => {
rm(temp, { recursive: true });
exitOnError(EX_TEMPFAIL)(error);
rename(getLocalPath(bakSourceFilename), getLocalPath(sourceFilename));
rename(getLocalPath(tmpSourceFilename), getLocalPath(sourceFilename));
winston.info(`successfully synced with ${remote}`);
});
});
Expand Down
6 changes: 3 additions & 3 deletions winget-source/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,12 @@ export function setupEnvironment() {
*
* @param {string} uri URI to sync.
* @param {boolean} update Whether to allow updating an existing file.
* @param {boolean} saveAsBak Whether to save with ".bak" suffix
* @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, saveAsBak = false) {
const localPath = getLocalPath(saveAsBak ? uri + ".bak" : 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

0 comments on commit 34f4879

Please sign in to comment.