mirror of
https://github.com/containerd/containerd.git
synced 2026-08-09 09:33:06 +00:00
erofs: Move immutable file handling before storage.Remove
The layer blob immutable flag clearing logic was moved before storage.Remove() call to ensure that immutable files can be properly removed even if subsequent operations fail after storage.Remove(). The previous order had storage.Remove() called first, which meant if any subsequent operations failed, there would be no opportunity to remove the immutable flag on the layer blob files. Signed-off-by: jinda.ljd <jinda.ljd@alibaba-inc.com>
This commit is contained in:
@@ -728,9 +728,23 @@ func (s *snapshotter) Remove(ctx context.Context, key string) (err error) {
|
||||
}
|
||||
}()
|
||||
return s.ms.WithTransaction(ctx, true, func(ctx context.Context) error {
|
||||
var k snapshots.Kind
|
||||
id, info, _, err := storage.GetInfo(ctx, key)
|
||||
if err != nil {
|
||||
if errdefs.IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("failed to get snapshot info: %w", err)
|
||||
}
|
||||
|
||||
id, k, err = storage.Remove(ctx, key)
|
||||
// The layer blob is only persisted for committed snapshots.
|
||||
if info.Kind == snapshots.KindCommitted {
|
||||
// Clear IMMUTABLE_FL before removal, since this flag avoids it.
|
||||
err = setImmutable(s.layerBlobPath(id), false)
|
||||
if err != nil && !errdefs.IsNotImplemented(err) {
|
||||
return fmt.Errorf("failed to clear IMMUTABLE_FL: %w", err)
|
||||
}
|
||||
}
|
||||
_, _, err = storage.Remove(ctx, key)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to remove snapshot %s: %w", key, err)
|
||||
}
|
||||
@@ -739,14 +753,6 @@ func (s *snapshotter) Remove(ctx context.Context, key string) (err error) {
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to get directories for removal: %w", err)
|
||||
}
|
||||
// The layer blob is only persisted for committed snapshots.
|
||||
if k == snapshots.KindCommitted {
|
||||
// Clear IMMUTABLE_FL before removal, since this flag avoids it.
|
||||
err = setImmutable(s.layerBlobPath(id), false)
|
||||
if err != nil && !errdefs.IsNotImplemented(err) {
|
||||
return fmt.Errorf("failed to clear IMMUTABLE_FL: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user