mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-14 23:06:34 +00:00
fix: order the resources to delete
longest path comes first to remove to most nested resources, then their container if any. Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
parent
478c36c5bd
commit
67e863d9ea
@ -104,9 +104,9 @@ export class CreateFsProvider
|
||||
let errToRethrow = err;
|
||||
// Not Found (Create API) errors must be remapped to VS Code filesystem provider specific errors
|
||||
// https://code.visualstudio.com/api/references/vscode-api#FileSystemError
|
||||
if (isNotFound(err)) {
|
||||
if (isNotFound(errToRethrow)) {
|
||||
errToRethrow = createFileSystemProviderError(
|
||||
err,
|
||||
errToRethrow,
|
||||
FileSystemProviderErrorCode.FileNotFound
|
||||
);
|
||||
}
|
||||
|
@ -391,9 +391,10 @@ export class CloudSketchbookTree extends SketchbookTree {
|
||||
const { filesToWrite, filesToDelete } = await this.treeDiff(source, dest);
|
||||
// Sort by the URIs. The shortest comes first. It's to ensure creating the parent folder for nested resources, for example.
|
||||
// When sorting the URIs, it does not matter whether on source or dest, only the URI path and its length matters; they're the same for a source+dest pair
|
||||
filesToWrite.sort(
|
||||
(left, right) =>
|
||||
left.source.path.toString().length - right.source.path.toString().length
|
||||
const uriPathLengthComparator = (left: URI, right: URI) =>
|
||||
left.path.toString().length - right.path.toString().length;
|
||||
filesToWrite.sort((left, right) =>
|
||||
uriPathLengthComparator(left.source, right.source)
|
||||
);
|
||||
for (const { source, dest } of filesToWrite) {
|
||||
const stat = await this.fileService.resolve(source);
|
||||
@ -405,11 +406,11 @@ export class CloudSketchbookTree extends SketchbookTree {
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
filesToDelete.map((file) =>
|
||||
this.fileService.delete(file, { recursive: true })
|
||||
)
|
||||
);
|
||||
// Longes URI paths come first to delete the most nested ones first.
|
||||
filesToDelete.sort(uriPathLengthComparator).reverse();
|
||||
for (const resource of filesToDelete) {
|
||||
await this.fileService.delete(resource, { recursive: true });
|
||||
}
|
||||
}
|
||||
|
||||
override async resolveChildren(
|
||||
|
Loading…
x
Reference in New Issue
Block a user