Skip to content
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

[help appreciated] Support multi arch packages / Solving "Manifest Unknown" error #189

Closed
wants to merge 4 commits into from
Closed
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
67 changes: 62 additions & 5 deletions src/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,87 @@ export function finalIds(input: Input): Observable<string[]> {
new Date(a.created_at).getTime() - new Date(b.created_at).getTime()
)
})

/*
Here first filter out the versions that are to be ignored.
Then compute number of versions to delete (toDelete) based on the inputs.
*/
*/
value = value.filter(info => !input.ignoreVersions.test(info.version))

/*
Step 0:
Iterate over value to extract subIDs and create a new array.
This new array just contains the subIDs and shows to which parentID (= Multi Arch package) the are linked and whether that parentId is tagged
*/
value.forEach(value => {
const { id, tagged, subIds } = version;

// Add parentID to the subIDs array with tagged status
subIds.forEach(subId => {
subIdsArray.push({
subId: subId,
parentId: id,
tagged: tagged
});
});
});



if (input.deleteUntaggedVersions === 'true') {
value = value.filter(info => !info.tagged)
// Previous Code:
// value = value.filter(info => !info.tagged)
// Problem: This loses untagged packages that belong to multi-arch containers that are tagged

// PSEUDOCODE TO FIX THIS:
// Keep only packages that are not subpackages and not tagged; or that are subpackages and the parent package is not tagged
value = value.filter(info =>
(!info.tagged && !subIdsArray.some(subIdInfo => subIdInfo.subId === info.id)) ||
(subIdsArray.some(subIdInfo => subIdInfo.subId === info.id && !subIdInfo.tagged))
);

}

let toDelete = 0
/*
Keeps only n packages
If deleteUntaggedVersions is true, then all tagged versions are kept, plus a number of untagged versions (minVersionsToKeep)
If deleteUntaggedVersions is false, then just n versions should remain.
In both cases, sub-packages should not be counted (keen n real packages, not n subpackages)
Problem with current code: when determining n-versions, also subpackages are counted (rather than just counting real packages)
*/
// PSEUDOCODE TO FIX THIS:
// Step 1: Create an array that does not include the subpackages to calculate which ones need to be retained / deleted
const valueWithoutSub = value.filter(info => (!subIdsArray.some(subIdInfo => subIdInfo.subId === info.id)))

if (input.minVersionsToKeep < 0) {
toDelete = Math.min(
value.length,
valueWithoutSub.length,
Math.min(input.numOldVersionsToDelete, RATE_LIMIT)
)
} else {
toDelete = Math.min(
value.length - input.minVersionsToKeep,
valueWithoutSub.length - input.minVersionsToKeep,
RATE_LIMIT
)
}
if (toDelete < 0) return []
return value.map(info => info.id.toString()).slice(0, toDelete)

// Step 2: Filter out the parent packages that need to be retained
valueWithoutSub = valueWithoutSub.map(info => info.id.toString()).slice(0, toDelete)

// Step 3: Filter out from value all packages that meet either of these two conditions:
// a. all parent packages flagged for deletion
// b. all subpackages that belong to these parent packages that are flagged for deletion
value = value.filter(info =>
valueWithoutSub.some(item => item.id === info.id) ||
subIdsArray.some(subIdInfo =>
subIdInfo.subId === info.id &&
valueWithoutSub.some(item => item.id === subIdInfo.parentId)
)
);

return value
})
)
}
Expand Down
11 changes: 10 additions & 1 deletion src/version/get-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,16 @@ export function getOldestVersions(
id: version.id,
version: version.name,
created_at: version.created_at,
tagged
tagged,
subIds: [] /* <<<<<<<<<<<<<<<<<<<<<<<<<<<<< First, we need to get for all packages the subIds (if they have any)
Example: https://github.com/ManiMatter/decluttarr/pkgs/container/decluttarr/204442395?tag=v1.38.0
Package v1.38.0: sha256:b4a9b04d8c0a5ab9f400f7f64f8be20d9951a996fd00882a936087af8f5ce43d
Has 3 Sub-IDs:
linux/amd64: sha256:c2dfb515fd9a6ad396fe6a48cd3e535b4079b467cb691bcb3faede6889089d6e
linux/arm64: sha256:59b2aa2e04cc6b3391f612833e87bbd0c4fdfddb04845b8e8f0365a45e90151c
unknown/unknown: sha256:6dfc07ab69cbe95303f51fed14b40a9574bbebbb3501d7aec481d184a8321c91
*/

}
}),
page,
Expand Down