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

modif: fcopy: Use lstat when copying directory #5957

Merged
merged 1 commit into from
Nov 24, 2023

Conversation

gerasiov
Copy link
Contributor

When copying directories use lstat when reading info about source files.

Closes #5378.

Copy link
Collaborator

@glitsj16 glitsj16 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

src/fcopy/main.c Show resolved Hide resolved
When copying directories use lstat when reading info about source files.
Copy link
Collaborator

@kmk3 kmk3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gerasiov

Actually, I just realized that the issue is probably because it is both a
directory and a symlink and the directory test appears before the symlink test.

Does it work with only the following changes?

diff --git a/src/fcopy/main.c b/src/fcopy/main.c
index a56e8a91b..72fb8e01f 100644
--- a/src/fcopy/main.c
+++ b/src/fcopy/main.c
@@ -503,12 +503,12 @@ int main(int argc, char **argv) {
                exit(1);
        }

-       if (S_ISDIR(s.st_mode))
+       if (S_ISLNK(s.st_mode))
+               duplicate_link(src, dest, &s);
+       else if (S_ISDIR(s.st_mode))
                duplicate_dir(src, dest, &s);
        else if (S_ISREG(s.st_mode))
                duplicate_file(src, dest, &s);
-       else if (S_ISLNK(s.st_mode))
-               duplicate_link(src, dest, &s);
        else {
                fprintf(stderr, "Error fcopy: src %s is an unsupported type of file\n", src);
                exit(1);

@gerasiov
Copy link
Contributor Author

In my case the problem was with nvidia driver libs, like
/etc/alternatives/nvidia--libnvidia-ml.so.1-x86_64-linux-gnu -> /usr/lib/x86_64-linux-gnu/nvidia/current/libnvidia-ml.so.525.125.06
there are bunch of them.
They're symlinks, but not directories.

@kmk3
Copy link
Collaborator

kmk3 commented Aug 15, 2023

In my case the problem was with nvidia driver libs, like
/etc/alternatives/nvidia--libnvidia-ml.so.1-x86_64-linux-gnu -> /usr/lib/x86_64-linux-gnu/nvidia/current/libnvidia-ml.so.525.125.06 there
are bunch of them. They're symlinks, but not directories.

Ah that makes sense now, S_ISDIR(s.st_mode) -> duplicate_dir ->
fs_copydir is called because /etc/alternatives is a directory, but then the
paths in it are files.

I see that there is some code in main() that chooses between stat and lstat
based on the arg_follow_links variable:

	// copy files
	if ((arg_follow_link ? stat : lstat)(src, &s) == -1) {
		fprintf(stderr, "Error fcopy: src %s: %s\n", src, strerror(errno));
		exit(1);
	}

Though I'm not sure if it is indeed only intended to apply to the top-level
path or to every symlink, in which case it might make sense to reuse the same
construct in fs_copydir.

Cc: @netblue30 @smitsohu

@netblue30 netblue30 merged commit a9867d5 into netblue30:master Nov 24, 2023
9 checks passed
@kmk3 kmk3 changed the title fcopy: Use lstat when copy directory. fcopy: Use lstat when copy directory Mar 28, 2024
@kmk3 kmk3 changed the title fcopy: Use lstat when copy directory modif: fcopy: Use lstat when copying directory Mar 28, 2024
kmk3 added a commit that referenced this pull request Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done (on RELNOTES)
Development

Successfully merging this pull request may close these issues.

Yet another --private-etc symlink issue, with /etc/alternatives/
4 participants