Documentation
¶
Overview ¶
Copyright 2025 Chainguard, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AdvertiseCachedFile ¶ added in v0.25.2
AdvertisedCachedFile will create a symlink at `dst` pointing to `src`.
In the case that `dst` already exists, another process had already created the symlink and we can safely move on. We will also perform a best-effort attempt to clean up the unadvertised file at `src`.
func ReplaceCachedFile ¶ added in v1.4.3
ReplaceCachedFile points `dst` at `src`, replacing whatever was there.
It differs from AdvertiseCachedFile in who wins a collision. AdvertiseCachedFile defers to an existing entry, on the assumption that another process advertised equivalent content first. That assumption does not hold for a cache directory an attacker can write to: a planted entry would be adopted and the caller's own file discarded. Callers that hold content they have just verified use this instead, so the verified copy wins.
The replacement goes through a uniquely named temporary symlink and a rename, so `dst` is never observed missing or half-written by a concurrent reader.
Winning the collision means the entry that lost has to be disposed of, or the cache grows without bound. AdvertiseCachedFile removed the loser's `src` because it was the loser; here the loser is whatever `dst` already pointed at, and the rename replaces only the symlink, not its target. See orphanedTarget for why that removal is deliberately narrow.
That disposal makes one demand of callers: advertise a given `src` at most once. Once a file has lost a collision it has been deleted, so re-advertising it points `dst` at something that no longer exists. Each caller advertising files it just created — which is what holding freshly verified content means — satisfies this without having to think about it.
Types ¶
This section is empty.