Skip to content

Commit

Permalink
drivers: support chown of hard links
Browse files Browse the repository at this point in the history
make sure the same inode is not chowned twice.  Track all the inodes
that are chowned and skip the same inode if it is encountered multiple
times.

Closes: containers#1143

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Feb 21, 2022
1 parent d30db7b commit 189aeeb
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion drivers/chown_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,50 @@ import (
"errors"
"fmt"
"os"
"sync"
"syscall"

"github.com/containers/storage/pkg/idtools"
"github.com/containers/storage/pkg/system"
)

type inode struct {
Dev uint64
Ino uint64
}

type platformChowner struct {
mutex sync.Mutex
inodes map[inode]bool
}

func newLChowner() *platformChowner {
return &platformChowner{}
return &platformChowner{
inodes: make(map[inode]bool),
}
}

func (c *platformChowner) LChown(path string, info os.FileInfo, toHost, toContainer *idtools.IDMappings) error {
st, ok := info.Sys().(*syscall.Stat_t)
if !ok {
return nil
}

i := inode{
Dev: st.Dev,
Ino: st.Ino,
}
c.mutex.Lock()
_, found := c.inodes[i]
if !found {
c.inodes[i] = true
}
c.mutex.Unlock()

if found {
return nil
}

// Map an on-disk UID/GID pair from host to container
// using the first map, then back to the host using the
// second map. Skip that first step if they're 0, to
Expand Down

0 comments on commit 189aeeb

Please sign in to comment.