@@ -109,6 +109,14 @@ impl Layout {
109
109
///
110
110
/// This function will block if the directory is already locked.
111
111
pub fn at ( config : & Config , root : Filesystem ) -> CargoResult < Layout > {
112
+ // If the root directory doesn't already exist go ahead and create it
113
+ // here. Use this opportunity to exclude it from backups as well if the
114
+ // system supports it since this is a freshly created folder.
115
+ if !root. as_path_unlocked ( ) . exists ( ) {
116
+ root. create_dir ( ) ?;
117
+ exclude_from_backups ( root. as_path_unlocked ( ) ) ;
118
+ }
119
+
112
120
// For now we don't do any more finer-grained locking on the artifact
113
121
// directory, so just lock the entire thing for the duration of this
114
122
// compile.
@@ -127,42 +135,8 @@ impl Layout {
127
135
} )
128
136
}
129
137
130
- #[ cfg( not( target_os = "macos" ) ) ]
131
- fn exclude_from_backups ( & self , _: & Path ) { }
132
-
133
- #[ cfg( target_os = "macos" ) ]
134
- /// Marks files or directories as excluded from Time Machine on macOS
135
- ///
136
- /// This is recommended to prevent derived/temporary files from bloating backups.
137
- fn exclude_from_backups ( & self , path : & Path ) {
138
- use core_foundation:: base:: TCFType ;
139
- use core_foundation:: { number, string, url} ;
140
- use std:: ptr;
141
-
142
- // For compatibility with 10.7 a string is used instead of global kCFURLIsExcludedFromBackupKey
143
- let is_excluded_key: Result < string:: CFString , _ > = "NSURLIsExcludedFromBackupKey" . parse ( ) ;
144
- let path = url:: CFURL :: from_path ( path, false ) ;
145
- if let ( Some ( path) , Ok ( is_excluded_key) ) = ( path, is_excluded_key) {
146
- unsafe {
147
- url:: CFURLSetResourcePropertyForKey (
148
- path. as_concrete_TypeRef ( ) ,
149
- is_excluded_key. as_concrete_TypeRef ( ) ,
150
- number:: kCFBooleanTrue as * const _ ,
151
- ptr:: null_mut ( ) ,
152
- ) ;
153
- }
154
- }
155
- // Errors are ignored, since it's an optional feature and failure
156
- // doesn't prevent Cargo from working
157
- }
158
-
159
138
/// Makes sure all directories stored in the Layout exist on the filesystem.
160
139
pub fn prepare ( & mut self ) -> io:: Result < ( ) > {
161
- if fs:: metadata ( & self . root ) . is_err ( ) {
162
- fs:: create_dir_all ( & self . root ) ?;
163
- self . exclude_from_backups ( & self . root ) ;
164
- }
165
-
166
140
mkdir ( & self . deps ) ?;
167
141
mkdir ( & self . native ) ?;
168
142
mkdir ( & self . incremental ) ?;
@@ -209,3 +183,32 @@ impl Layout {
209
183
& self . build
210
184
}
211
185
}
186
+
187
+ #[ cfg( not( target_os = "macos" ) ) ]
188
+ fn exclude_from_backups ( _: & Path ) { }
189
+
190
+ #[ cfg( target_os = "macos" ) ]
191
+ /// Marks files or directories as excluded from Time Machine on macOS
192
+ ///
193
+ /// This is recommended to prevent derived/temporary files from bloating backups.
194
+ fn exclude_from_backups ( path : & Path ) {
195
+ use core_foundation:: base:: TCFType ;
196
+ use core_foundation:: { number, string, url} ;
197
+ use std:: ptr;
198
+
199
+ // For compatibility with 10.7 a string is used instead of global kCFURLIsExcludedFromBackupKey
200
+ let is_excluded_key: Result < string:: CFString , _ > = "NSURLIsExcludedFromBackupKey" . parse ( ) ;
201
+ let path = url:: CFURL :: from_path ( path, false ) ;
202
+ if let ( Some ( path) , Ok ( is_excluded_key) ) = ( path, is_excluded_key) {
203
+ unsafe {
204
+ url:: CFURLSetResourcePropertyForKey (
205
+ path. as_concrete_TypeRef ( ) ,
206
+ is_excluded_key. as_concrete_TypeRef ( ) ,
207
+ number:: kCFBooleanTrue as * const _ ,
208
+ ptr:: null_mut ( ) ,
209
+ ) ;
210
+ }
211
+ }
212
+ // Errors are ignored, since it's an optional feature and failure
213
+ // doesn't prevent Cargo from working
214
+ }
0 commit comments