Skip to content

Commit

Permalink
fix: only delete non-forceignored sub-directories (#847)
Browse files Browse the repository at this point in the history
* fix: only delete non-forceignored sub-directories

* test: record perf

---------

Co-authored-by: svc-cli-bot <[email protected]>
  • Loading branch information
shetzel and svc-cli-bot authored Feb 9, 2023
1 parent 679e958 commit 90e9415
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/client/metadataApiRetrieve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,17 @@ export class MetadataApiRetrieve extends MetadataTransfer<
const localComp = partialDeleteComponents.get(comp.fullName);
if (localComp.contentPath && tree.isDirectory(comp.content)) {
const remoteContentList = tree.readDirectory(comp.content);
let deleteLocalComp = false;

const isForceIgnored = (filePath: string): boolean => {
const ignored = comp.getForceIgnore().denies(filePath);
if (ignored) {
this.logger.debug(
`Local component has ${filePath} while remote does not, but it is forceignored so ignoring.`
);
}
return ignored;
};

localComp.contentList.forEach((fileName) => {
if (!remoteContentList.includes(fileName)) {
// If fileName is forceignored it is not counted as a diff. If fileName is a directory
Expand All @@ -376,30 +386,27 @@ export class MetadataApiRetrieve extends MetadataTransfer<
const fileNameFullPath = path.join(localComp.contentPath, fileName);
if (fs.statSync(fileNameFullPath).isDirectory()) {
const nestedFiles = fs.readdirSync(fileNameFullPath);
if (nestedFiles.some((f) => comp.getForceIgnore().denies(path.join(fileNameFullPath, f)))) {
this.logger.debug(
`Local component has ${fileNameFullPath} while remote does not, but it is forceignored so ignoring.`
);
if (nestedFiles.some((f) => isForceIgnored(path.join(fileNameFullPath, f)))) {
return;
}
} else if (isForceIgnored(fileNameFullPath)) {
return;
}

this.logger.debug(
`Local component (${comp.fullName}) contains ${fileName} while remote component does not. This file is being removed.`
);
deleteLocalComp = true;

const filePath = path.join(localComp.contentPath, fileName);
partialDeleteFileResponses.push({
fullName: comp.fullName,
type: comp.type.name,
state: ComponentStatus.Deleted,
filePath: path.join(localComp.contentPath, fileName),
filePath,
});
fs.rmSync(filePath, { recursive: true, force: true });
}
});
if (deleteLocalComp) {
this.logger.debug(`Replacing local component: ${localComp.contentPath} with same component from org`);
fs.rmSync(localComp.contentPath, { recursive: true, force: true });
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"name": "componentSetCreate",
"duration": 206.49349700001767
},
{
"name": "sourceToMdapi",
"duration": 5455.362960000028
},
{
"name": "sourceToZip",
"duration": 5237.455126999994
},
{
"name": "mdapiToSource",
"duration": 3759.678862999979
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"name": "componentSetCreate",
"duration": 407.67415299999993
},
{
"name": "sourceToMdapi",
"duration": 7544.196715999977
},
{
"name": "sourceToZip",
"duration": 6185.875728999992
},
{
"name": "mdapiToSource",
"duration": 4336.305462999997
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"name": "componentSetCreate",
"duration": 704.1282699999865
},
{
"name": "sourceToMdapi",
"duration": 10994.699290999997
},
{
"name": "sourceToZip",
"duration": 9647.811220000003
},
{
"name": "mdapiToSource",
"duration": 8051.59345700001
}
]

0 comments on commit 90e9415

Please sign in to comment.