@@ -62,13 +62,7 @@ impl TarballManager {
62
62
archive. unpack ( & unpack_path) ?;
63
63
fs:: remove_file ( tarball_path) ?;
64
64
fs:: create_dir_all ( extract_path) ?;
65
- // Check if extract_path is empty or not.
66
- // This is due by a race condition causing 2 different threads to download and
67
- // extract to the same folder. Likely be fixed with mutex locks.
68
- // TODO: Remove this when we have some sort of thread safety
69
- if extract_path. read_dir ( ) ?. next ( ) . is_none ( ) {
70
- fs:: rename ( unpack_path. join ( "package" ) , extract_path) ?;
71
- }
65
+ fs:: rename ( unpack_path. join ( "package" ) , extract_path) ?;
72
66
fs:: remove_dir_all ( & unpack_path) ?;
73
67
Ok ( ( ) )
74
68
}
@@ -81,15 +75,17 @@ impl TarballManager {
81
75
save_path : & Path ,
82
76
symlink_to : & Path ,
83
77
) -> Result < ( ) , TarballError > {
78
+ let symlink_exists = symlink_to. is_symlink ( ) ;
79
+
84
80
// If name contains `/` such as @fastify/error, we need to make sure that @fastify folder
85
81
// exists before we symlink to that directory.
86
- if name. contains ( '/' ) {
82
+ if name. contains ( '/' ) && !symlink_exists {
87
83
fs:: create_dir_all ( symlink_to. parent ( ) . unwrap ( ) ) ?;
88
84
}
89
85
90
86
// Do not try to install dependency if this version already exists in package.json
91
- if save_path. exists ( ) {
92
- if !symlink_to . is_symlink ( ) {
87
+ if save_path. exists ( ) || symlink_exists {
88
+ if !symlink_exists {
93
89
symlink_dir ( & save_path. to_path_buf ( ) , & symlink_to. to_path_buf ( ) ) ?;
94
90
}
95
91
return Ok ( ( ) ) ;
@@ -102,9 +98,7 @@ impl TarballManager {
102
98
103
99
// TODO: Currently symlink paths are absolute paths.
104
100
// If you move the root folder to a different path, all symlinks will be broken.
105
- if !symlink_to. is_symlink ( ) {
106
- symlink_dir ( & save_path. to_path_buf ( ) , & symlink_to. to_path_buf ( ) ) ?;
107
- }
101
+ symlink_dir ( & save_path. to_path_buf ( ) , & symlink_to. to_path_buf ( ) ) ?;
108
102
109
103
Ok ( ( ) )
110
104
}
0 commit comments