Skip to content

Commit 1caeac9

Browse files
committed
Try unlink in a loop
1 parent eec9530 commit 1caeac9

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

src/DB_Command_SQLite.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,22 @@ protected function sqlite_drop() {
156156
unset( $wpdb );
157157
gc_collect_cycles();
158158

159-
if ( ! unlink( $db_path ) ) {
159+
$attempts = 0;
160+
$unlinked = false;
161+
while ( $attempts < 10 ) {
162+
if ( ! file_exists( $db_path ) ) {
163+
$unlinked = true;
164+
break;
165+
}
166+
if ( @unlink( $db_path ) ) {
167+
$unlinked = true;
168+
break;
169+
}
170+
++$attempts;
171+
usleep( 100000 ); // 100ms
172+
}
173+
174+
if ( ! $unlinked ) {
160175
WP_CLI::error( "Could not delete database file: {$db_path}" );
161176
}
162177

@@ -182,7 +197,22 @@ protected function sqlite_reset() {
182197
unset( $wpdb );
183198
gc_collect_cycles();
184199

185-
if ( ! unlink( $db_path ) ) {
200+
$attempts = 0;
201+
$unlinked = false;
202+
while ( $attempts < 10 ) {
203+
if ( ! file_exists( $db_path ) ) {
204+
$unlinked = true;
205+
break;
206+
}
207+
if ( @unlink( $db_path ) ) {
208+
$unlinked = true;
209+
break;
210+
}
211+
++$attempts;
212+
usleep( 100000 ); // 100ms
213+
}
214+
215+
if ( ! $unlinked ) {
186216
WP_CLI::error( "Could not delete database file: {$db_path}" );
187217
}
188218
}

0 commit comments

Comments
 (0)