Skip to content

Commit

Permalink
Merge pull request #452 from snyk-tech-services/fix-file-removal
Browse files Browse the repository at this point in the history
Fix file removal
  • Loading branch information
CalamarBicefalo authored Jun 29, 2023
2 parents 6bd9137 + 38b05e4 commit 4742360
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ yarn.lock
.eslintcache
local.*
test/research
.idea
8 changes: 4 additions & 4 deletions .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@
{
"//": "build the macos",
"path": "@semantic-release/exec",
"cmd": "npx [email protected] dist/index.js -r './dist/**/*.js' -t mac-x64-12.9.0 -o snyk-api-import-macos"
"cmd": "npx [email protected] dist/index.js -r './dist/**/*.js' -t mac-x64-14.15.3 -o snyk-api-import-macos"
},
{
"//": "build the linux",
"path": "@semantic-release/exec",
"cmd": "npx [email protected] dist/index.js -r './dist/**/*.js' -t linux-x64-12.9.0 -o snyk-api-import-linux"
"cmd": "npx [email protected] dist/index.js -r './dist/**/*.js' -t linux-x64-14.15.3 -o snyk-api-import-linux"
},
{
"//": "build the alpine",
"path": "@semantic-release/exec",
"cmd": "npx [email protected] dist/index.js -r './dist/**/*.js' -t alpine-x64-12.9.0 -o snyk-api-import-alpine"
"cmd": "npx [email protected] dist/index.js -r './dist/**/*.js' -t alpine-x64-14.15.3 -o snyk-api-import-alpine"
},
{
"//": "build the windows binaries",
"path": "@semantic-release/exec",
"cmd": "npx [email protected] dist/index.js -r './dist/**/*.js' -t windows-x64-12.9.0 -o snyk-api-import-win.exe"
"cmd": "npx [email protected] dist/index.js -r './dist/**/*.js' -t windows-x64-14.15.3 -o snyk-api-import-win.exe"
},
{
"//": "shasum all binaries",
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"build-watch": "tsc -w",
"prepare": "npm run build",
"snyk-test": "snyk test",
"pkg-binaries-linux": "npx nexe@3.3.7 dist/index.js -r './dist/**/*.js' -t linux-x64-12.9.0 -o snyk-api-import-linux",
"pkg-binaries": "npx nexe@3.3.7 dist/index.js -r './dist/**/*.js' -t mac-x64-12.9.0 -o snyk-api-import-macos"
"pkg-binaries-linux": "npx nexe@4.0.0-rc.2 dist/index.js -r './dist/**/*.js' -t linux-x64-14.15.3 -o snyk-api-import-linux",
"pkg-binaries": "npx nexe@4.0.0-rc.2 dist/index.js -r './dist/**/*.js' -t mac-x64-14.15.3 -o snyk-api-import-macos"
},
"types": "./dist/index.d.ts",
"repository": {
Expand All @@ -47,6 +47,7 @@
"bottleneck": "2.19.5",
"bunyan": "1.8.15",
"debug": "4.3.4",
"fs-extra": "^11.1.1",
"lodash": "4.17.21",
"micromatch": "4.0.5",
"needle": "2.9.1",
Expand All @@ -64,6 +65,7 @@
"@semantic-release/exec": "5.0.0",
"@types/bunyan": "1.8.6",
"@types/debug": "4.1.5",
"@types/fs-extra": "^11.0.1",
"@types/jest": "^25.1.1",
"@types/lodash": "^4.14.149",
"@types/micromatch": "4.0.2",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/git-clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function gitClone(
} catch (err: any) {
debug(`Could not shallow clone the repo:\n ${err}`);
if (fs.existsSync(repoClonePath)) {
fs.rmdirSync(repoClonePath, { recursive: true, maxRetries: 3 });
fs.rmSync(repoClonePath, { recursive: true, maxRetries: 3, force: true });
}
return {
success: false,
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/sync/clone-and-analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export async function cloneAndAnalyze(
);

try {
fs.rmdirSync(repoPath, { recursive: true, maxRetries: 3 });
fs.rmSync(repoPath, { recursive: true, maxRetries: 3, force: true });
} catch (error) {
debug(`Failed to delete ${repoPath}. Error was ${error}.`);
}
Expand Down
4 changes: 2 additions & 2 deletions test/lib/git-clone.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('gitClone', () => {
afterEach(() => {
for (const f of removeFolders) {
try {
fs.rmdirSync(f, { recursive: true, maxRetries: 3 });
fs.rmSync(f, { recursive: true, force: true, maxRetries: 3 });
} catch (e) {
console.log('Failed to clean up test', e);
}
Expand Down Expand Up @@ -76,7 +76,7 @@ describe('gitClone', () => {
afterEach(() => {
for (const f of removeFolders) {
try {
fs.rmdirSync(f, { recursive: true, maxRetries: 3 });
fs.rmSync(f, { recursive: true, maxRetries: 3, force: true });
} catch (e) {
console.log('Failed to clean up test', e);
}
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/sync/clone-and-analyze.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('cloneAndAnalyze', () => {
afterEach(() => {
for (const f of removeFolders) {
try {
fs.rmdirSync(f, { recursive: true, maxRetries: 3 });
fs.rmSync(f, { recursive: true, maxRetries: 3, force: true });
} catch (e) {
console.log('Failed to clean up test', e);
}
Expand Down
27 changes: 18 additions & 9 deletions test/scripts/sync/sync-org-projects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { requestsManager } from 'snyk-request-manager';
import * as uuid from 'uuid';
import * as path from 'path';
import * as fs from 'fs';
import * as fse from 'fs-extra';
import {
updateOrgTargets,
updateTargets,
Expand Down Expand Up @@ -244,7 +245,7 @@ describe('updateTargets', () => {
cloneSpy.mockImplementation(() =>
Promise.resolve({
success: true,
repoPath: path.resolve(fixturesFolderPath, 'monorepo-new'),
repoPath: fixture('monorepo-new'),
gitResponse: '',
}),
);
Expand Down Expand Up @@ -353,7 +354,7 @@ describe('updateTargets', () => {
cloneSpy.mockImplementation(() =>
Promise.resolve({
success: true,
repoPath: path.resolve(fixturesFolderPath, 'goof'),
repoPath: fixture('goof'),
gitResponse: '',
}),
);
Expand Down Expand Up @@ -463,7 +464,7 @@ describe('updateTargets', () => {
cloneSpy.mockImplementation(() =>
Promise.resolve({
success: true,
repoPath: path.resolve(fixturesFolderPath, 'goof'),
repoPath: fixture('goof'),
gitResponse: '',
}),
);
Expand Down Expand Up @@ -554,7 +555,7 @@ describe('updateTargets', () => {
cloneSpy.mockImplementation(() =>
Promise.resolve({
success: true,
repoPath: path.resolve(fixturesFolderPath, 'goof'),
repoPath: fixture('goof'),
gitResponse: '',
}),
);
Expand Down Expand Up @@ -680,7 +681,7 @@ describe('updateTargets', () => {
cloneSpy.mockImplementation(() =>
Promise.resolve({
success: true,
repoPath: path.resolve(fixturesFolderPath, 'monorepo'),
repoPath: fixture('monorepo'),
gitResponse: '',
}),
);
Expand Down Expand Up @@ -890,7 +891,7 @@ describe('updateTargets', () => {
cloneSpy.mockImplementation(() =>
Promise.resolve({
success: true,
repoPath: path.resolve(fixturesFolderPath, 'monorepo'),
repoPath: fixture('monorepo'),
gitResponse: '',
}),
);
Expand Down Expand Up @@ -1033,7 +1034,7 @@ describe('updateTargets', () => {
cloneSpy.mockImplementation(() =>
Promise.resolve({
success: true,
repoPath: path.resolve(fixturesFolderPath, 'monorepo'),
repoPath: fixture('monorepo'),
gitResponse: '',
}),
);
Expand Down Expand Up @@ -1400,7 +1401,7 @@ describe('updateOrgTargets', () => {
cloneSpy.mockImplementation(() =>
Promise.resolve({
success: true,
repoPath: path.resolve(fixturesFolderPath, 'goof'),
repoPath: fixture('goof'),
gitResponse: '',
}),
);
Expand Down Expand Up @@ -1585,7 +1586,7 @@ describe('updateOrgTargets', () => {
cloneSpy.mockImplementation(() =>
Promise.resolve({
success: true,
repoPath: path.resolve(fixturesFolderPath, 'goof'),
repoPath: fixture('goof'),
gitResponse: '',
}),
);
Expand Down Expand Up @@ -1876,3 +1877,11 @@ describe('bulkImportTargetFiles', () => {
expect(updated.length).toEqual(5);
});
});

function fixture(name: string) {
const tempDir = fs.mkdtempSync('snyk-api-import-test-');
fse.copySync(path.resolve(fixturesFolderPath, name), tempDir, {
overwrite: true,
});
return tempDir;
}

0 comments on commit 4742360

Please sign in to comment.