Skip to content

Retry on file/folder deletion with Windows longpath support #9561

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

Merged
merged 3 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .lycheeignore
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,4 @@ site.com
http://sites.google.com/site/murmurhash/
helpmenow.com
http://dev.w3.org/
https://qntm.org/cmd
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
- Clear discover summary if t2ppl failed ([#9552](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9552))
- Query-assist removed the placeholder of last ask question ([#9552](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9552))
- Use markdown in discover summary ([#9553](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9553))
- Retry on file/folder deletion with Windows longpath support ([#9561](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9561))

### 🚞 Infrastructure

Expand Down Expand Up @@ -108,4 +109,4 @@
- [TESTID-234] Add tests for query editor display ([#9398](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9398))
- Fix flakieness in cypress tests ([#9433](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9433))
- Use before/after to speed up test ([#9439](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9439))
- Clear session storage in S3 integ test and update workflow ([#9490](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9490))
- Clear session storage in S3 integ test and update workflow ([#9490](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9490))
39 changes: 37 additions & 2 deletions src/dev/build/lib/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import deleteEmpty from 'delete-empty';
import tar, { ExtractOptions } from 'tar';
import { ToolingLog } from '@osd/dev-utils';
import { standardize } from '@osd/cross-platform';

const pipelineAsync = promisify(pipeline);
const mkdirAsync = promisify(fs.mkdir);
Expand Down Expand Up @@ -120,7 +121,24 @@
dryRun: true,
});

await Promise.all(filesToDelete.map((folder) => rm(folder, { force: true, recursive: true })));
await Promise.all(
filesToDelete.map(async (folder) => {
if (process.platform === 'win32') {
folder = standardize(folder, false, false, true); // extended long path

Check warning on line 127 in src/dev/build/lib/fs.ts

View check run for this annotation

Codecov / codecov/patch

src/dev/build/lib/fs.ts#L127

Added line #L127 was not covered by tests
}

for (let i = 0; i < 3; i++) {
try {
await rm(folder, { force: true, recursive: true });
return;

Check warning on line 133 in src/dev/build/lib/fs.ts

View check run for this annotation

Codecov / codecov/patch

src/dev/build/lib/fs.ts#L130-L133

Added lines #L130 - L133 were not covered by tests
} catch (err) {
if (i === 2) throw err;
log.debug(`Retry ${i + 1}/3 on ${folder}, waiting for 1000ms`);
await new Promise((resolveSleep) => setTimeout(resolveSleep, 1000));

Check warning on line 137 in src/dev/build/lib/fs.ts

View check run for this annotation

Codecov / codecov/patch

src/dev/build/lib/fs.ts#L136-L137

Added lines #L136 - L137 were not covered by tests
}
}
})
);

if (log) {
log.debug('Deleted %d files/directories', filesToDelete.length);
Expand Down Expand Up @@ -155,7 +173,24 @@
})
: [];

await Promise.all(foldersToDelete.map((folder) => rm(folder, { force: true, recursive: true })));
await Promise.all(

Check warning on line 176 in src/dev/build/lib/fs.ts

View check run for this annotation

Codecov / codecov/patch

src/dev/build/lib/fs.ts#L176

Added line #L176 was not covered by tests
foldersToDelete.map(async (folder) => {
if (process.platform === 'win32') {
folder = standardize(folder, false, false, true); // extended long path

Check warning on line 179 in src/dev/build/lib/fs.ts

View check run for this annotation

Codecov / codecov/patch

src/dev/build/lib/fs.ts#L179

Added line #L179 was not covered by tests
}

for (let i = 0; i < 3; i++) {
try {
await rm(folder, { force: true, recursive: true });
return;

Check warning on line 185 in src/dev/build/lib/fs.ts

View check run for this annotation

Codecov / codecov/patch

src/dev/build/lib/fs.ts#L182-L185

Added lines #L182 - L185 were not covered by tests
} catch (err) {
if (i === 2) throw err;
log.debug(`Retry ${i + 1}/3 on ${folder}, waiting for 1000ms`);
await new Promise((resolveSleep) => setTimeout(resolveSleep, 1000));

Check warning on line 189 in src/dev/build/lib/fs.ts

View check run for this annotation

Codecov / codecov/patch

src/dev/build/lib/fs.ts#L188-L189

Added lines #L188 - L189 were not covered by tests
}
}
})
);

log.debug('Deleted %d empty folders', foldersToDelete.length);
log.verbose('Deleted:', longInspect(foldersToDelete));
Expand Down
Loading