Skip to content

Inplace flag overwrites symlinks with file contents when data file and /tmp are on the same partition #2155

@sestegra

Description

@sestegra

Describe the bug
The -i inplace flag overwrites symlinks with the file contents instead of modifying the symlinked file when data file and /tmp are on the same partition.

Version of yq: v4.44.3
Operating system: linux
Installed via: binary release

Thanks to #1306 for helping me investigate the root cause.

Input Yaml
data1.yml is on a the same filesystem partition as /tmp

data1.yml:

this: should really work
but: it strangely didn't

data2.yml:
symlink to data1.yml

Command
The command you ran:

yq -i '.components += "test"' data2.yml

Actual behavior

Before running yq command

$ ls -l | grep data
-rw-rw-r--  1 sestegra sestegra   67 Sep 21 14:53 data1.yml
lrwxrwxrwx  1 sestegra sestegra    9 Sep 21 14:31 data2.yml -> data1.yml

After running yq command

$ ls -l | grep data
-rw-rw-r-- 1 sestegra sestegra   50 Sep 21 14:55 data1.yml
-rw-rw-r-- 1 sestegra sestegra   67 Sep 21 14:58 data2.yml

Expected behavior

data2.yml file must be a symlink after update.

Additional context
If the same command is ran with data1.yml and /tmp on different filesystem partitions, it works as expected.

The difference occurs when calling renameat. If on a different partitions, the first strace occurs.

renameat(AT_FDCWD, "/tmp/temp736164879", AT_FDCWD, "data2.yml") = -1 EXDEV (Invalid cross-device link)
renameat(AT_FDCWD, "/tmp/temp2419478472", AT_FDCWD, "data2.yml") = 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions