tustvold commented on PR #2207:
URL: https://github.com/apache/arrow-rs/pull/2207#issuecomment-1198549404
```
#[tokio::test]
#[cfg(target_family = "unix")]
async fn test_symlink() {
let root = TempDir::new().unwrap();
let integration =
LocalFileSystem::new_with_prefix(root.path()).unwrap();
let subdir = root.path().join("a");
std::fs::create_dir(&subdir).unwrap();
let file = subdir.join("file.parquet");
std::fs::write(&file, "test").unwrap();
check_list(&integration, &["a/file.parquet"], None).await;
// Out of tree symlink gets ignored
let other = NamedTempFile::new().unwrap();
std::os::unix::fs::symlink(other.path(),
root.path().join("test.parquet"))
.unwrap();
check_list(&integration, &["a/file.parquet"], None).await;
// In tree symlink gets resolved and deduplicated
std::os::unix::fs::symlink(&subdir, root.path().join("b")).unwrap();
check_list(&integration, &["a/file.parquet"], None).await;
// In tree symlink gets resolved and canonicalised to actual path
check_list(&integration, &["a/file.parquet"],
Some(&Path::from("b"))).await;
// Out of tree symlink that loops back is ignored
let dir = TempDir::new().unwrap();
let child = root.path().join("child");
let link = child.join("link");
std::fs::create_dir(child).unwrap();
std::os::unix::fs::symlink(dir.path(), &link).unwrap();
std::os::unix::fs::symlink(&subdir,
dir.path().join("back")).unwrap();
// If we list above the symlink it follows the symlink back
check_list(&integration, &[], Some(&Path::from("child"))).await;
check_list(&integration, &[], Some(&Path::from("child/link"))).await;
// Ignore broken symlink
std::os::unix::fs::symlink(
root.path().join("foo.parquet"),
root.path().join("c"),
)
.unwrap();
check_list(&integration, &["a/file.parquet"], None).await;
}
```
To summarise:
* Symlinks that "escape" the LocalFileSystem root are silently ignored, even
if they link back into the tree
* Symlinks that are within the LocalFileSystem root are resolved to paths,
even if these then aren't prefixes of the search path
There may be other weirdness going on, I'm actually having a hard time fully
understanding what the behaviour is... The above was entirely determined
empirically...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]