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

fs: return correct file size of symlink #672

Merged
merged 1 commit into from
Mar 7, 2022
Merged

Conversation

ktock
Copy link
Member

@ktock ktock commented Mar 5, 2022

The filesystem of stargz-snapshotter always returns size 0 when stat a symlink.

# nerdctl run --snapshotter=stargz --rm -it ghcr.io/stargz-containers/python:3.9-esgz stat /usr/lib/x86_64-linux-gnu/libpq.so
  File: /usr/lib/x86_64-linux-gnu/libpq.so -> libpq.so.5.13
  Size: 0         	Blocks: 0          IO Block: 4096   symbolic link
Device: 1000e3h/1048803d	Inode: 4845        Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 1970-01-01 00:00:00.000000000 +0000
Modify: 2021-05-11 20:10:35.000000000 +0000
Change: 1970-01-01 00:00:00.000000000 +0000
 Birth: -

But it needs to be the size of the link name according to man stat(2).

https://man7.org/linux/man-pages/man2/lstat.2.html

  st_size
         This field gives the size of the file (if it is a regular
         file or a symbolic link) in bytes.  The size of a symbolic
         link is the length of the pathname it contains, without a
         terminating null byte.

This behaviour seems to cause issue like moby/buildkit#2703 .
This commit fixes this issue.

this PR:

# nerdctl run --snapshotter=stargz --rm -it ghcr.io/stargz-containers/python:3.9-esgz stat /usr/lib/x86_64-linux-gnu/libpq.so
  File: /usr/lib/x86_64-linux-gnu/libpq.so -> libpq.so.5.13
  Size: 13        	Blocks: 1          IO Block: 4096   symbolic link
Device: 100054h/1048660d	Inode: 11801       Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 1970-01-01 00:00:00.000000000 +0000
Modify: 2021-05-11 20:10:35.000000000 +0000
Change: 1970-01-01 00:00:00.000000000 +0000
 Birth: -
# nerdctl run --snapshotter=stargz --rm -it ghcr.io/stargz-containers/python:3.9-esgz /bin/bash -c "apt-get update &&  apt-get install -y libpq-dev"
Get:1 http://deb.debian.org/debian bullseye InRelease [116 kB]
Get:2 http://security.debian.org/debian-security bullseye-security InRelease [44.1 kB]
Get:3 http://deb.debian.org/debian bullseye-updates InRelease [39.4 kB]
Get:4 http://security.debian.org/debian-security bullseye-security/main amd64 Packages [120 kB]
Get:5 http://deb.debian.org/debian bullseye/main amd64 Packages [8183 kB]
Get:6 http://deb.debian.org/debian bullseye-updates/main amd64 Packages [2596 B]
Fetched 8505 kB in 7s (1227 kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libpq5
Suggested packages:
  postgresql-doc-13
The following packages will be upgraded:
  libpq-dev libpq5
2 upgraded, 0 newly installed, 0 to remove and 56 not upgraded.
Need to get 316 kB of archives.
After this operation, 3072 B of additional disk space will be used.
Get:1 http://deb.debian.org/debian bullseye/main amd64 libpq-dev amd64 13.5-0+deb11u1 [138 kB]
Get:2 http://deb.debian.org/debian bullseye/main amd64 libpq5 amd64 13.5-0+deb11u1 [179 kB]
Fetched 316 kB in 0s (6996 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
(Reading database ... 23378 files and directories currently installed.)
Preparing to unpack .../libpq-dev_13.5-0+deb11u1_amd64.deb ...
Unpacking libpq-dev (13.5-0+deb11u1) over (13.3-1) ...
Preparing to unpack .../libpq5_13.5-0+deb11u1_amd64.deb ...
Unpacking libpq5:amd64 (13.5-0+deb11u1) over (13.3-1) ...
Setting up libpq5:amd64 (13.5-0+deb11u1) ...
Setting up libpq-dev (13.5-0+deb11u1) ...
Processing triggers for libc-bin (2.31-13) ...

@AkihiroSuda AkihiroSuda merged commit acf305c into containerd:main Mar 7, 2022
@ktock ktock deleted the fixapt branch March 7, 2022 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants