diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-05-27 10:33:15 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-27 10:33:15 -0400 |
commit | a96844118c24d870abfe5332547dab99dc53d09c (patch) | |
tree | 194bde1661ad66e41efc912ccbb151edf268c643 /test_util/src/temp_dir.rs | |
parent | be59e93220e24a2e66ae2843a136e61eab9d8ac3 (diff) |
fix(compile): inline symlinks as files outside node_modules dir and warn for directories (#19285)
If a symlink within the `node_modules` directory lies outside that
directory, it will now warn and inline the file. For directories, it
will just warn for now.
Probably fixes #19251 (I'm still unable to reproduce).
Diffstat (limited to 'test_util/src/temp_dir.rs')
-rw-r--r-- | test_util/src/temp_dir.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test_util/src/temp_dir.rs b/test_util/src/temp_dir.rs index f0f866d88..f66bf1398 100644 --- a/test_util/src/temp_dir.rs +++ b/test_util/src/temp_dir.rs @@ -80,4 +80,40 @@ impl TempDir { pub fn write(&self, path: impl AsRef<Path>, text: impl AsRef<str>) { fs::write(self.path().join(path), text.as_ref()).unwrap(); } + + pub fn symlink_dir( + &self, + oldpath: impl AsRef<Path>, + newpath: impl AsRef<Path>, + ) { + #[cfg(unix)] + { + use std::os::unix::fs::symlink; + symlink(self.path().join(oldpath), self.path().join(newpath)).unwrap(); + } + #[cfg(not(unix))] + { + use std::os::windows::fs::symlink_dir; + symlink_dir(self.path().join(oldpath), self.path().join(newpath)) + .unwrap(); + } + } + + pub fn symlink_file( + &self, + oldpath: impl AsRef<Path>, + newpath: impl AsRef<Path>, + ) { + #[cfg(unix)] + { + use std::os::unix::fs::symlink; + symlink(self.path().join(oldpath), self.path().join(newpath)).unwrap(); + } + #[cfg(not(unix))] + { + use std::os::windows::fs::symlink_file; + symlink_file(self.path().join(oldpath), self.path().join(newpath)) + .unwrap(); + } + } } |