Skip to content

Commit

Permalink
Merge pull request #7211 from unfoldingWord/bugfix-mcleanb-7210
Browse files Browse the repository at this point in the history
Bugfix 7210/Fix problem the resources being clobbered
  • Loading branch information
mannycolon authored Jan 10, 2022
2 parents 8e4b8f1 + 4580664 commit 8d50789
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@
"string-punctuation-tokenizer": "^2.2.0",
"sudo-prompt": "6.2.1",
"tc-electron-env": "0.9.0",
"tc-source-content-updater": "^0.9.0",
"tc-source-content-updater": "0.9.1",
"tc-strings": "0.1.7",
"tc-tool": "4.1.0",
"tc-ui-toolkit": "6.0.0",
"truncate-utf8-bytes": "1.0.2",
"tsv-groupdata-parser": "0.10.1",
"tsv-groupdata-parser": "0.10.2",
"usfm-js": "3.3.1",
"uuid": "3.2.1",
"word-aligner": "1.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/js/actions/__tests__/MigrationActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,10 @@ describe('migrate tCore resources', () => {
expect(fs.existsSync(path.join(USER_RESOURCES_PATH, 'grc'))).toBeFalsy(); // should remove folder
});

it('test with older version of ugnt in grc/bible - should be removed', () => {
it('test with older version of ugnt in grc/bible - should not be removed', () => {
// given
const expectedHelpsVers = false;
const expectedBibleVers = ['v0.2'];
const expectedBibleVers = ['v0.1', 'v0.2'];
const bibleId = 'ugnt';
fs.copySync(path.join(STATIC_RESOURCES_PATH, 'el-x-koine/bibles', bibleId, 'v0.2'), path.join(USER_RESOURCES_PATH, 'grc/bibles', bibleId, 'v0.1'));
const migrateResourcesFolder = MigrationActions.migrateResourcesFolder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ Array [
]
`;

exports[`migrate tCore resources Test grc resource migration test with older version of ugnt in grc/bible - should be removed 1`] = `
exports[`migrate tCore resources Test grc resource migration test with older version of ugnt in grc/bible - should not be removed 1`] = `
Array [
"/Users/jest/mock/path/translationCore/resources/el-x-koine/bibles/ugnt/v0.1",
"/Users/jest/mock/path/translationCore/resources/el-x-koine/bibles/ugnt/v0.2",
"/Users/jest/mock/path/translationCore/resources/el-x-koine/translationHelps/translationWords/v8",
"/Users/jest/mock/path/translationCore/resources/en/bibles/ult/v12.1",
Expand Down
19 changes: 9 additions & 10 deletions src/js/helpers/ResourcesHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1208,16 +1208,17 @@ export function moveResourcesFromOldGrcFolder() {
/**
* find out which Original Language Bible versions are needed by installed tNs. Only keep the needed versions.
* The other versions are deleted.
* @param languageId
* @param resourceId
* @param resourcePath
* @param {string} languageId
* @param {string} resourceId
* @param {string} resourcePath - path for versions of current resource
* @param {string} resourcesPath - base path for all resources
* @return {boolean} - returns true if all old resources can be deleted
*/
export function preserveNeededOrigLangVersions(languageId, resourceId, resourcePath) {
export function preserveNeededOrigLangVersions(languageId, resourceId, resourcePath, resourcesPath) {
let deleteOldResources = true; // by default we do not keep old versions of resources

if (BibleHelpers.isOriginalLanguageBible(languageId, resourceId)) {
const requiredVersions = getOtherTnsOLVersions(USER_RESOURCES_PATH, resourceId).sort((a, b) =>
const requiredVersions = getOtherTnsOLVersions(resourcesPath, resourceId).sort((a, b) =>
-ResourceAPI.compareVersions(a, b), // do inverted sort
);
console.log('preserveNeededOrigLangVersions: requiredVersions', requiredVersions);
Expand Down Expand Up @@ -1272,15 +1273,13 @@ export function getMissingResources() {
} else if (!fs.existsSync(userResourcePath)) {// if resource isn't found in user resources folder.
copyAndExtractResource(staticResourcePath, userResourcePath, languageId, resourceId, resourceType);
} else { // compare resources manifest modified time
const userResourceVersionPath = ResourceAPI.getLatestVersion(userResourcePath);
const staticResourceVersionPath = ResourceAPI.getLatestVersion(staticResourcePath);
const version = path.basename(staticResourceVersionPath);
const userResourceVersionPath = path.join(userResourcePath, version);
const userResourceExists = fs.existsSync(userResourceVersionPath);
let isOldResource = false;
const filename = 'manifest.json';
const staticResourceManifestPath = path.join(staticResourceVersionPath, filename);

if (userResourceExists) {
if (userResourceVersionPath) {
const userResourceManifestPath = path.join(userResourceVersionPath, filename);

if (fs.existsSync(userResourceManifestPath) && fs.existsSync(staticResourceManifestPath)) {
Expand Down Expand Up @@ -1312,7 +1311,7 @@ export function getMissingResources() {
isOldResource = true;
}

const deleteOldResources = preserveNeededOrigLangVersions(languageId, resourceId, userResourcePath);
const deleteOldResources = preserveNeededOrigLangVersions(languageId, resourceId, userResourcePath, USER_RESOURCES_PATH);

if (isOldResource) {
console.log(`getMissingResources() - checking ${languageId} ${resourceId} - old resource found`);
Expand Down

0 comments on commit 8d50789

Please sign in to comment.