Skip to content

Commit cff1db8

Browse files
committed
Change logic to delete files
1 parent 3ca2a52 commit cff1db8

File tree

1 file changed

+3
-16
lines changed
  • aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/utils

1 file changed

+3
-16
lines changed

aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/utils/ModelUtils.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,28 +94,15 @@ public static void deleteFileSafely( @Nonnull final File file ) {
9494
return;
9595
}
9696

97-
waitForFileUnlock( file, 10, 200 );
98-
99-
if ( !file.isDirectory() ) {
97+
if ( isFileLocked( file ) ) {
98+
FileUtils.deleteQuietly( file );
99+
} else if ( !file.isDirectory() ) {
100100
Files.deleteIfExists( file.toPath() );
101101
} else {
102102
FileUtils.deleteDirectory( file );
103103
}
104104
} catch ( final IOException e ) {
105105
throw new FileHandlingException( "File could not be deleted: " + file.getAbsolutePath(), e );
106-
} catch ( final InterruptedException e ) {
107-
Thread.currentThread().interrupt();
108-
throw new FileReadException( "Interrupted while waiting to delete file: " + file.getAbsolutePath() );
109-
}
110-
}
111-
112-
private static void waitForFileUnlock( final File file, final int maxRetries, final long sleepMillis ) throws InterruptedException {
113-
int retry = 0;
114-
while ( isFileLocked( file ) ) {
115-
if ( retry++ >= maxRetries ) {
116-
throw new RuntimeException( "File is still locked after retries: " + file.getAbsolutePath() );
117-
}
118-
Thread.sleep( sleepMillis );
119106
}
120107
}
121108

0 commit comments

Comments
 (0)