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

[MSHARED-1176] Test case for NoSuchFileException while copying symbolic #110

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kwin
Copy link
Member

@kwin kwin commented Jul 26, 2022

link with relative non-existing target

@kwin kwin marked this pull request as draft July 26, 2022 17:39
@kwin
Copy link
Member Author

kwin commented Jul 26, 2022

@slawekjaranowski This depends on #109 being merged first otherwise the build breaks even before executing the unit test.

Update: Done and rebased this PR.

@michael-o
Copy link
Member

michael-o commented Jul 26, 2022

Without testing your PR, here is what I see on FreeBSD (FreeBSD bsd1srv.fritz.box 12.3-STABLE FreeBSD 12.3-STABLE GENERIC amd64) where chmod -h works as expected:

mosipov@bsd1srv:/usr/home/mosipov/var/Projekte/maven-shared-utils (master =)
$ grep chmod /tmp/out
fchmod(188,0100644)                              = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/classes/org/apache/maven/shared/utils/annotations.xml",0644) = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/classes/org/apache/maven/shared/utils/annotations.xml",0644) = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/classes/META-INF/LICENSE",0644) = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/classes/META-INF/LICENSE",0644) = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/classes/META-INF/DEPENDENCIES",0644) = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/classes/META-INF/DEPENDENCIES",0644) = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/classes/META-INF/NOTICE",0644) = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/classes/META-INF/NOTICE",0644) = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/test-classes/directorywalker/directory1/file1.txt",0644) = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/test-classes/directorywalker/directory1/file1.txt",0644) = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/test-classes/directorywalker/directory2/directory21/file21.txt",0644) = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/test-classes/directorywalker/directory2/directory21/file21.txt",0644) = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/test-classes/directorywalker/directory2/file2.txt",0644) = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/test-classes/directorywalker/directory2/file2.txt",0644) = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/test-classes/directorywalker/file.txt",0644) = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/test-classes/directorywalker/file.txt",0644) = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/test-classes/expand/expand_test.zip",0644) = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/test-classes/expand/expand_test.zip",0644) = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/test-classes/symlinks/src/targetDir/targetFile.txt",0644) = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/test-classes/symlinks/src/targetDir/targetFile.txt",0644) = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/test-classes/symlinks/src/fileR.txt",0644) = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/test-classes/symlinks/src/fileR.txt",0644) = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/test-classes/symlinks/src/symLinkToFileOnTheOutside",0644) ERR#2 'No such file or directory'

and

mosipov@bsd1srv:/usr/home/mosipov/var/Projekte/maven-shared-utils (master =)
$ grep symLinkToFileOnTheOutside /tmp/out
fstatat(AT_FDCWD,"/var/mosipov/Projekte/maven-shared-utils/target/test-classes/symlinks/src/symLinkToFileOnTheOutside",0x7fffdfffc1f0,0x0) ERR#2 'No such file or directory'
fstatat(AT_FDCWD,"/var/mosipov/Projekte/maven-shared-utils/target/test-classes/symlinks/src/symLinkToFileOnTheOutside",{ mode=lrwxr-xr-x ,inode=91832,size=19,blksize=131072 },AT_SYMLINK_NOFOLLOW) = 0 (0x0)
unlink("/var/mosipov/Projekte/maven-shared-utils/target/test-classes/symlinks/src/symLinkToFileOnTheOutside") = 0 (0x0)
fstatat(AT_FDCWD,"/var/mosipov/Projekte/maven-shared-utils/src/test/resources/symlinks/src/symLinkToFileOnTheOutside",{ mode=-rw-r--r-- ,inode=91148,size=839,blksize=4096 },0x0) = 0 (0x0)
fstatat(AT_FDCWD,"/var/mosipov/Projekte/maven-shared-utils/src/test/resources/symlinks/src/symLinkToFileOnTheOutside",{ mode=-rw-r--r-- ,inode=91148,size=839,blksize=4096 },0x0) = 0 (0x0)
fstatat(AT_FDCWD,"/var/mosipov/Projekte/maven-shared-utils/src/test/resources/symlinks/src/symLinkToFileOnTheOutside",{ mode=-rw-r--r-- ,inode=91148,size=839,blksize=4096 },0x0) = 0 (0x0)
fstatat(AT_FDCWD,"/var/mosipov/Projekte/maven-shared-utils/src/test/resources/symlinks/src/symLinkToFileOnTheOutside",{ mode=-rw-r--r-- ,inode=91148,size=839,blksize=4096 },0x0) = 0 (0x0)
fstatat(AT_FDCWD,"/var/mosipov/Projekte/maven-shared-utils/src/test/resources/symlinks/src/symLinkToFileOnTheOutside",{ mode=-rw-r--r-- ,inode=91148,size=839,blksize=4096 },0x0) = 0 (0x0)
fstatat(AT_FDCWD,"/var/mosipov/Projekte/maven-shared-utils/src/test/resources/symlinks/src/symLinkToFileOnTheOutside",{ mode=-rw-r--r-- ,inode=91148,size=839,blksize=4096 },0x0) = 0 (0x0)
fstatat(AT_FDCWD,"/var/mosipov/Projekte/maven-shared-utils/target/test-classes/symlinks/src/symLinkToFileOnTheOutside",0x7fffdfffc460,0x0) ERR#2 'No such file or directory'
fstatat(AT_FDCWD,"/var/mosipov/Projekte/maven-shared-utils/src/test/resources/symlinks/src/symLinkToFileOnTheOutside",{ mode=-rw-r--r-- ,inode=91148,size=839,blksize=4096 },0x0) = 0 (0x0)
fstatat(AT_FDCWD,"/var/mosipov/Projekte/maven-shared-utils/src/test/resources/symlinks/src/symLinkToFileOnTheOutside",{ mode=-rw-r--r-- ,inode=91148,size=839,blksize=4096 },0x0) = 0 (0x0)
fstatat(AT_FDCWD,"/var/mosipov/Projekte/maven-shared-utils/src/test/resources/symlinks/src/symLinkToFileOnTheOutside",{ mode=lrwxr-xr-x ,inode=91158,size=19,blksize=131072 },AT_SYMLINK_NOFOLLOW) = 0 (0x0)
readlink("/var/mosipov/Projekte/maven-shared-utils/src/test/resources/symlinks/src/symLinkToFileOnTheOutside","../onTheOutside.txt",1025) = 19 (0x13)
access("/var/mosipov/Projekte/maven-shared-utils/target/test-classes/symlinks/src/symLinkToFileOnTheOutside",F_OK) ERR#2 'No such file or directory'
symlink("../onTheOutside.txt","/var/mosipov/Projekte/maven-shared-utils/target/test-classes/symlinks/src/symLinkToFileOnTheOutside") = 0 (0x0)
fstatat(AT_FDCWD,"/var/mosipov/Projekte/maven-shared-utils/src/test/resources/symlinks/src/symLinkToFileOnTheOutside",{ mode=-rw-r--r-- ,inode=91148,size=839,blksize=4096 },0x0) = 0 (0x0)
chmod("/var/mosipov/Projekte/maven-shared-utils/target/test-classes/symlinks/src/symLinkToFileOnTheOutside",0644) ERR#2 'No such file or directory'

The symlink or its target does not exist.

@kwin
Copy link
Member Author

kwin commented Jul 26, 2022

Yes, exactly. In this case the target does not (yet) exist. The question is how FileUtils.copyFile(...) should behave in that case.

@kwin kwin force-pushed the bugfix/MSHARED-1112-nsfe-on-symlink-copy branch from 94fa38a to da11090 Compare July 26, 2022 18:00
@michael-o
Copy link
Member

I'll try to look into this this month.

@kwin
Copy link
Member Author

kwin commented Jul 26, 2022

IMHO copy should also not fail in case the source symlink is broken (which it currently does)

@michael-o
Copy link
Member

michael-o commented Jul 26, 2022

IMHO copy should also not fail in case the source symlink is broken (which it currently does)

I agree with that. If source leads to nowhere then dest should do too. Fully valid with POSIX.

@kwin
Copy link
Member Author

kwin commented Jul 27, 2022

IMHO copy should also not fail in case the source symlink is broken (which it currently does)

I added another (failing) test case for this scenario in 8ff14a5

@michael-o
Copy link
Member

From my PoV, it should mimic cp(1).

@kwin kwin changed the title [MSHARED-1112] Test case for NoSuchFileException while copying symbolic [MSHARED-1176] Test case for NoSuchFileException while copying symbolic Jan 1, 2023
tempFolder.newFolder( "destDirectory" ),
"toSymLink"
);
// this creates a symlink in a new folder pointing to a non-existing relative target "./target.txt"
Copy link
Member

Choose a reason for hiding this comment

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

directory, not folder

"toSymLink"
);
// this creates a symlink in a new folder pointing to a non-existing relative target "./non-existing.txt"
FileUtils.copyFile( from.toFile(), to, null, (FileUtils.FilterWrapper[]) null );
Copy link
Member

Choose a reason for hiding this comment

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

directory, not folder

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