Skip to content

Handle cases where user ID does not map to a user name (e.g. docker) #130

@arnaudh

Description

@arnaudh

Bumped into this issue while working within a docker container:

julia> stat(Path("/test/foo.txt"))
ERROR: ArgumentError: User 1000 not found.
Stacktrace:
 [1] FilePathsBase.User(uid::UInt64)
   @ FilePathsBase ~/.julia/packages/FilePathsBase/YFK4h/src/libc.jl:84
 [2] Status(s::Base.Filesystem.StatStruct)
   @ FilePathsBase ~/.julia/packages/FilePathsBase/YFK4h/src/status.jl:21
 [3] stat(fp::PosixPath)
   @ FilePathsBase ~/.julia/packages/FilePathsBase/YFK4h/src/system.jl:54
 [4] top-level scope
   @ REPL[5]:1

This happens because the owner of the file in question has uid 1000, and that particular user is not visible inside docker. This answer on Stack Overflow lists other possible use cases: mounting an external file system, or a file belonging to a deleted user.
It would be nice if FilePathsBase supported those use cases, i.e. if it were possible to manipulate files even if the owners or groups can't be found.

Here's a Minimum Working Example to reproduce:

# On an AWS EC2 instance running linux:

-bash-4.2$ mkdir test && cd test

-bash-4.2$ touch foo.txt

-bash-4.2$ ls -l
total 0
-rw-rw-r-- 1 ec2-user ec2-user 0 Sep  7 16:27 foo.txt

-bash-4.2$ ls -ln # Display user and group IDs numerically
total 0
-rw-rw-r-- 1 1000 1000 0 Sep  7 16:27 foo.txt

-bash-4.2$ docker run -it -v $(pwd):/test julia:1.6 bash

root@fdad1f65434d:$ ls -l /test # Inside docker we see the user id doesn't get translated to a username
total 0
-rw-rw-r-- 1 1000 1000 0 Sep  7 16:27 foo.txt

root@fdad1f65434d:$ julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.6.2 (2021-07-14)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

(@v1.6) pkg> add FilePathsBase
  Installing known registries into `~/.julia`
       Added registry `General` to `~/.julia/registries/General`
   Resolving package versions...
   Installed FilePathsBase ─ v0.9.10
    Updating `~/.julia/environments/v1.6/Project.toml`
  [48062228] + FilePathsBase v0.9.10
    Updating `~/.julia/environments/v1.6/Manifest.toml`
  [48062228] + FilePathsBase v0.9.10
  [2a0f44e3] + Base64
  [ade2ca70] + Dates
  [b77e0a4c] + InteractiveUtils
  [56ddb016] + Logging
  [d6f4376e] + Markdown
  [a63ad114] + Mmap
  [de0858da] + Printf
  [9a3f8284] + Random
  [ea8e919c] + SHA
  [9e88b42a] + Serialization
  [8dfed614] + Test
  [cf7118a7] + UUIDs
  [4ec0a83e] + Unicode
Precompiling project...
  1 dependency successfully precompiled in 3 seconds

julia> run(`ls -l /test`)
total 0
-rw-rw-r-- 1 1000 1000 0 Sep  7 16:27 foo.txt
Process(`ls -l /test`, ProcessExited(0))

julia> using FilePathsBase

julia> stat(Path("/test/foo.txt"))
ERROR: ArgumentError: User 1000 not found.
Stacktrace:
 [1] FilePathsBase.User(uid::UInt64)
   @ FilePathsBase ~/.julia/packages/FilePathsBase/YFK4h/src/libc.jl:84
 [2] Status(s::Base.Filesystem.StatStruct)
   @ FilePathsBase ~/.julia/packages/FilePathsBase/YFK4h/src/status.jl:21
 [3] stat(fp::PosixPath)
   @ FilePathsBase ~/.julia/packages/FilePathsBase/YFK4h/src/system.jl:54
 [4] top-level scope
   @ REPL[5]:1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions