Skip to content

Commit 6679393

Browse files
author
Federico Fissore
committed
Assuming the bundled version is an AVR bundle, force unpacking the default package if it's missing
1 parent a83d6e9 commit 6679393

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

arduino-core/src/cc/arduino/utils/ArchiveExtractor.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

arduino-core/src/processing/app/BaseNoGui.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,11 +578,12 @@ static public void initLogger() {
578578
static public void initPackages() throws Exception {
579579
indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder());
580580
File indexFile = indexer.getIndexFile();
581-
if (!indexFile.isFile()) {
581+
File avrCoreFolder = FileUtils.newFile(indexFile.getParentFile(), "packages", "arduino", "hardware", "avr");
582+
if (!indexFile.isFile() || !(avrCoreFolder.exists() && avrCoreFolder.isDirectory())) {
582583
File distFile = findDefaultPackageFile();
583584
if (distFile != null) {
584-
ArchiveExtractor.extract(distFile, BaseNoGui.getSettingsFolder(), 0);
585-
} else {
585+
ArchiveExtractor.extract(distFile, BaseNoGui.getSettingsFolder(), 0, true);
586+
} else if (!indexFile.isFile()) {
586587
// Otherwise create an empty packages index
587588
FileOutputStream out = null;
588589
try {

arduino-core/src/processing/app/helpers/FileUtils.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ public static void copy(File sourceFolder, File destFolder) throws IOException {
7373
}
7474

7575
public static void recursiveDelete(File file) {
76-
if (file == null)
76+
if (file == null) {
7777
return;
78+
}
7879
if (file.isDirectory()) {
79-
for (File current : file.listFiles())
80+
for (File current : file.listFiles()) {
8081
recursiveDelete(current);
82+
}
8183
}
8284
file.delete();
8385
}
@@ -254,5 +256,14 @@ public static List<File> listFiles(File folder, boolean recursive,
254256
return result;
255257
}
256258

259+
public static File newFile(File parent, String... parts) {
260+
File result = parent;
261+
for (String part : parts) {
262+
result = new File(result, part);
263+
}
264+
265+
return result;
266+
}
267+
257268

258269
}

0 commit comments

Comments
 (0)