@@ -29,12 +29,41 @@ pub(crate) fn write(path: impl AsRef<Path>, content: &[u8]) -> Result<()> {
29
29
}
30
30
}
31
31
32
- pub ( crate ) fn symlink_file ( original : impl AsRef < Path > , link : impl AsRef < Path > ) -> Result < ( ) > {
32
+ pub ( crate ) fn relative_symlink_file (
33
+ original : impl AsRef < Path > ,
34
+ link : impl AsRef < Path > ,
35
+ ) -> Result < ( ) > {
33
36
let original = original. as_ref ( ) ;
34
37
let link = link. as_ref ( ) ;
35
38
36
- let original = best_effort_relativize_symlink ( original, link) ;
39
+ let relativized = best_effort_relativize_symlink ( original, link) ;
37
40
41
+ symlink_file ( & relativized, original, link)
42
+ }
43
+
44
+ pub ( crate ) fn absolute_symlink_file (
45
+ original : impl AsRef < Path > ,
46
+ link : impl AsRef < Path > ,
47
+ ) -> Result < ( ) > {
48
+ let original = original. as_ref ( ) ;
49
+ let link = link. as_ref ( ) ;
50
+
51
+ symlink_file ( original, original, link)
52
+ }
53
+
54
+ pub ( crate ) fn relative_symlink_dir (
55
+ original : impl AsRef < Path > ,
56
+ link : impl AsRef < Path > ,
57
+ ) -> Result < ( ) > {
58
+ let original = original. as_ref ( ) ;
59
+ let link = link. as_ref ( ) ;
60
+
61
+ let relativized = best_effort_relativize_symlink ( original, link) ;
62
+
63
+ symlink_dir ( & relativized, link)
64
+ }
65
+
66
+ fn symlink_file ( path_for_symlink : & Path , path_for_copy : & Path , link : & Path ) -> Result < ( ) > {
38
67
let mut create_dir_error = None ;
39
68
if fs:: exists ( link) {
40
69
best_effort_remove ( link) ;
@@ -43,7 +72,7 @@ pub(crate) fn symlink_file(original: impl AsRef<Path>, link: impl AsRef<Path>) -
43
72
create_dir_error = fs:: create_dir_all ( parent) . err ( ) ;
44
73
}
45
74
46
- match paths:: symlink_or_copy ( original , link) {
75
+ match paths:: symlink_or_copy ( path_for_symlink , path_for_copy , link) {
47
76
// As long as symlink_or_copy succeeded, ignore any create_dir_all error.
48
77
Ok ( ( ) ) => Ok ( ( ) ) ,
49
78
Err ( err) => {
@@ -65,12 +94,7 @@ pub(crate) fn symlink_file(original: impl AsRef<Path>, link: impl AsRef<Path>) -
65
94
}
66
95
}
67
96
68
- pub ( crate ) fn symlink_dir ( original : impl AsRef < Path > , link : impl AsRef < Path > ) -> Result < ( ) > {
69
- let original = original. as_ref ( ) ;
70
- let link = link. as_ref ( ) ;
71
-
72
- let original = best_effort_relativize_symlink ( original, link) ;
73
-
97
+ fn symlink_dir ( path_for_symlink : & Path , link : & Path ) -> Result < ( ) > {
74
98
let mut create_dir_error = None ;
75
99
if fs:: exists ( link) {
76
100
best_effort_remove ( link) ;
@@ -79,7 +103,7 @@ pub(crate) fn symlink_dir(original: impl AsRef<Path>, link: impl AsRef<Path>) ->
79
103
create_dir_error = fs:: create_dir_all ( parent) . err ( ) ;
80
104
}
81
105
82
- match fs:: symlink_dir ( original , link) {
106
+ match fs:: symlink_dir ( path_for_symlink , link) {
83
107
// As long as symlink_dir succeeded, ignore any create_dir_all error.
84
108
Ok ( ( ) ) => Ok ( ( ) ) ,
85
109
// If create_dir_all and symlink_dir both failed, prefer the first error.
0 commit comments