Skip to content

Commit 09aa954

Browse files
committed
Use forceDelete flag instead of direct deletion.
1 parent 9764b40 commit 09aa954

File tree

4 files changed

+13
-23
lines changed

4 files changed

+13
-23
lines changed

app/lib/admin/actions/moderate_package.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Note: the action may take a longer time to complete as the public archive bucket
8383
});
8484

8585
// sync exported API(s)
86-
await apiExporter?.synchronizePackage(package);
86+
await apiExporter?.synchronizePackage(package, forceDelete: true);
8787

8888
// retract or re-populate public archive files
8989
await packageBackend.tarballStorage.updatePublicArchiveBucket(

app/lib/admin/actions/moderate_package_versions.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Set the moderated flag on a package version (updating the flag and the timestamp
116116
});
117117

118118
// sync exported API(s)
119-
await apiExporter?.synchronizePackage(package);
119+
await apiExporter?.synchronizePackage(package, forceDelete: true);
120120

121121
// retract or re-populate public archive files
122122
await packageBackend.tarballStorage.updatePublicArchiveBucket(

app/lib/package/api_export/api_exporter.dart

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,16 @@ final class ApiExporter {
188188
/// * Running a full background synchronization.
189189
/// * When a change in [Package.updated] is detected.
190190
/// * A package is moderated, or other admin action is applied.
191+
///
192+
/// When [forceDelete] is set, the age threshold limit for stray files is
193+
/// ignored, they will be deleted even if they were updated recently.
194+
///
195+
/// When [forceDelete] is set, the age threshold limit for stray files is
196+
/// ignored, they will be deleted even if they were updated recently.
191197
Future<void> synchronizePackage(
192198
String package, {
193199
bool forceWrite = false,
200+
bool forceDelete = false,
194201
}) async {
195202
_log.info('synchronizePackage("$package")');
196203

@@ -216,19 +223,6 @@ final class ApiExporter {
216223
final versions = await packageBackend.tarballStorage
217224
.listVersionsInCanonicalBucket(package);
218225

219-
// Check versions that are not exposed in the public API and if they are moderated, delete them.
220-
for (final cv in versions.entries) {
221-
final version = cv.key;
222-
if (versionListing.versions.any((v) => v.version == version)) {
223-
continue;
224-
}
225-
final pv = await packageBackend.lookupPackageVersion(package, version);
226-
if (pv != null && pv.isModerated) {
227-
// We only delete the package if it is explicitly moderated.
228-
// If we can't find it, then it's safer to assume that it's a bug.
229-
await _api.package(package).deleteVersion(version);
230-
}
231-
}
232226
// Remove versions that are not exposed in the public API.
233227
versions.removeWhere(
234228
(version, _) => !versionListing.versions.any((v) => v.version == version),
@@ -237,6 +231,7 @@ final class ApiExporter {
237231
await _api.package(package).synchronizeTarballs(
238232
versions,
239233
forceWrite: forceWrite,
234+
forceDelete: forceDelete,
240235
);
241236
await _api.package(package).advisories.write(
242237
advisories,

app/lib/package/api_export/exported_api.dart

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ final class ExportedPackage {
293293
Future<void> synchronizeTarballs(
294294
Map<String, SourceObjectInfo> versions, {
295295
bool forceWrite = false,
296+
bool forceDelete = false,
296297
}) async {
297298
await Future.wait([
298299
..._owner._prefixes.map((prefix) async {
@@ -331,7 +332,8 @@ final class ExportedPackage {
331332
}
332333

333334
// Delete the item, if it's old enough.
334-
if (item.updated.isBefore(clock.agoBy(_minGarbageAge))) {
335+
if (forceDelete ||
336+
item.updated.isBefore(clock.agoBy(_minGarbageAge))) {
335337
// Only delete if the item if it's older than _minGarbageAge
336338
// This avoids any races where we delete files we've just created
337339
await _owner._bucket.tryDelete(item.name);
@@ -402,13 +404,6 @@ final class ExportedPackage {
402404
}),
403405
]);
404406
}
405-
406-
/// Deletes the files related to this package and [version].
407-
Future<void> deleteVersion(String version) async {
408-
await Future.wait([
409-
tarball(version).delete(),
410-
]);
411-
}
412407
}
413408

414409
/// Information about an object to be used as source in a copy operation.

0 commit comments

Comments
 (0)