-
Notifications
You must be signed in to change notification settings - Fork 25
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
fix: removing duplicated nuget packages folder #746
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { Logging, Workspace } from '@aws/language-server-runtimes/server-interface' | ||
import * as archiver from 'archiver' | ||
import * as crypto from 'crypto' | ||
Check warning on line 3 in server/aws-lsp-codewhisperer/src/language-server/netTransform/artifactManager.ts GitHub Actions / Test
|
||
import * as fs from 'fs' | ||
Check warning on line 4 in server/aws-lsp-codewhisperer/src/language-server/netTransform/artifactManager.ts GitHub Actions / Test
|
||
import { CodeFile, Project, References, RequirementJson, StartTransformRequest } from './models' | ||
import path = require('path') | ||
const requriementJsonFileName = 'requirement.json' | ||
|
@@ -9,6 +9,7 @@ | |
const referencesFolderName = 'references' | ||
const zipFileName = 'artifact.zip' | ||
const sourceCodeFolderName = 'sourceCode' | ||
const packagesFolderName = 'packages' | ||
|
||
export class ArtifactManager { | ||
private workspace: Workspace | ||
|
@@ -22,6 +23,7 @@ | |
async createZip(request: StartTransformRequest): Promise<string> { | ||
await this.createRequirementJson(request) | ||
await this.copySolutionConfigFiles(request) | ||
await this.removeDuplicateNugetPackagesFolder(request) | ||
return await this.zipArtifact() | ||
} | ||
async removeDir(dir: string) { | ||
|
@@ -41,6 +43,21 @@ | |
} | ||
} | ||
|
||
async removeDuplicateNugetPackagesFolder(request: StartTransformRequest) { | ||
const packagesFolder = path.join( | ||
this.workspacePath, | ||
artifactFolderName, | ||
sourceCodeFolderName, | ||
packagesFolderName | ||
) | ||
if (!fs.existsSync(packagesFolder)) { | ||
this.logging.log('Cannot find nuget packages folder in source code') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to log this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1. If we invert the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed, it is causing unnecessary logs, will remove this. |
||
return | ||
} | ||
fs.rmSync(packagesFolder, { recursive: true, force: true }) | ||
this.logging.log(`Removed nuget packages folder: ${packagesFolder}`) | ||
} | ||
|
||
async createRequirementJson(request: StartTransformRequest) { | ||
const fileContent = await this.createRequirementJsonContent(request) | ||
const dir = this.getRequirementJsonPath() | ||
|
@@ -194,6 +211,10 @@ | |
this.createFolderIfNotExist(dir) | ||
fs.copyFile(sourceFilePath, destFilePath, error => { | ||
if (error) { | ||
if (!fs.existsSync(dir) && dir.includes(packagesFolderName)) { | ||
//Packages folder has been deleted to avoid duplicates in artifacts.zip | ||
return | ||
} | ||
this.logging.log('Failed to copy: ' + sourceFilePath + error) | ||
} | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as a potential optimization, is it possible to skip adding these files to the zip in the first place. If I understand correctly right now we spend extra time copying these files in the step before only to end up going through the folder again and deleting them. If we could create the artifacts in a single go that would also make the process more efficient. Is this possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes Ege, thanks for suggestion.
After this hotfix, we will take a stab in detail on optimizing entire zipping with ticket P194692593.