@@ -69,6 +69,11 @@ public static void extract(File archiveFile, File destFolder) throws IOException
6969 * @throws IOException
7070 */
7171 public static void extract (File archiveFile , File destFolder , int stripPath ) throws IOException {
72+ extract (archiveFile , destFolder , stripPath , false );
73+ }
74+
75+
76+ public static void extract (File archiveFile , File destFolder , int stripPath , boolean overwrite ) throws IOException {
7277
7378 // Folders timestamps must be set at the end of archive extraction
7479 // (because creating a file in a folder alters the folder's timestamp)
@@ -193,14 +198,14 @@ public static void extract(File archiveFile, File destFolder, int stripPath) thr
193198
194199 // Safety check
195200 if (isDirectory ) {
196- if (outputFile .isFile ()) {
201+ if (outputFile .isFile () && ! overwrite ) {
197202 throw new IOException ("Can't create folder " + outputFile + ", a file with the same name exists!" );
198203 }
199204 } else {
200205 // - isLink
201206 // - isSymLink
202207 // - anything else
203- if (outputFile .exists ()) {
208+ if (outputFile .exists () && ! overwrite ) {
204209 throw new IOException ("Can't extract file " + outputFile + ", file already exists!" );
205210 }
206211 }
@@ -233,6 +238,9 @@ public static void extract(File archiveFile, File destFolder, int stripPath) thr
233238 }
234239
235240 for (Map .Entry <File , File > entry : hardLinks .entrySet ()) {
241+ if (entry .getKey ().exists () && overwrite ) {
242+ entry .getKey ().delete ();
243+ }
236244 FileNativeUtils .link (entry .getValue (), entry .getKey ());
237245 Integer mode = hardLinksMode .get (entry .getKey ());
238246 if (mode != null ) {
@@ -241,6 +249,9 @@ public static void extract(File archiveFile, File destFolder, int stripPath) thr
241249 }
242250
243251 for (Map .Entry <File , File > entry : symLinks .entrySet ()) {
252+ if (entry .getKey ().exists () && overwrite ) {
253+ entry .getKey ().delete ();
254+ }
244255 FileNativeUtils .symlink (entry .getValue (), entry .getKey ());
245256 entry .getKey ().setLastModified (symLinksModifiedTimes .get (entry .getKey ()));
246257 }
0 commit comments