File tree 1 file changed +19
-0
lines changed
1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ pub(crate) struct CratePatch {
21
21
pub struct BuildDirectory {
22
22
workspace : Workspace ,
23
23
name : String ,
24
+ purge_on_drop : bool ,
24
25
}
25
26
26
27
/// Builder for configuring builds in a [`BuildDirectory`](struct.BuildDirectory.html).
@@ -97,6 +98,7 @@ impl BuildDirectory {
97
98
Self {
98
99
workspace,
99
100
name : name. into ( ) ,
101
+ purge_on_drop : false ,
100
102
}
101
103
}
102
104
@@ -172,6 +174,13 @@ impl BuildDirectory {
172
174
Ok ( ( ) )
173
175
}
174
176
177
+ /// Enable or disable purging the build directory when dropped.
178
+ ///
179
+ /// By default, the directory is not dropped.
180
+ pub fn purge_on_drop ( & mut self , yes : bool ) {
181
+ self . purge_on_drop = yes;
182
+ }
183
+
175
184
fn build_dir ( & self ) -> PathBuf {
176
185
self . workspace . builds_dir ( ) . join ( & self . name )
177
186
}
@@ -185,6 +194,16 @@ impl BuildDirectory {
185
194
}
186
195
}
187
196
197
+ impl Drop for BuildDirectory {
198
+ fn drop ( & mut self ) {
199
+ if self . purge_on_drop {
200
+ if let Err ( err) = self . purge ( ) {
201
+ log:: error!( "failed to delete build directory: {}" , err) ;
202
+ }
203
+ }
204
+ }
205
+ }
206
+
188
207
/// API to interact with a running build.
189
208
///
190
209
/// This is created from [`BuildDirectory::build`](struct.BuildDirectory.html#method.build)
You can’t perform that action at this time.
0 commit comments