1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +03:00

Assuming the bundled version is an AVR bundle, force unpacking the default package if it's missing

This commit is contained in:
Federico Fissore
2015-03-25 17:40:50 +01:00
parent a83d6e9886
commit 6679393b7a
3 changed files with 30 additions and 7 deletions

View File

@ -69,6 +69,11 @@ public class ArchiveExtractor {
* @throws IOException * @throws IOException
*/ */
public static void extract(File archiveFile, File destFolder, int stripPath) throws IOException { public static void extract(File archiveFile, File destFolder, int stripPath) throws IOException {
extract(archiveFile, destFolder, stripPath, false);
}
public static void extract(File archiveFile, File destFolder, int stripPath, boolean overwrite) throws IOException {
// Folders timestamps must be set at the end of archive extraction // Folders timestamps must be set at the end of archive extraction
// (because creating a file in a folder alters the folder's timestamp) // (because creating a file in a folder alters the folder's timestamp)
@ -193,14 +198,14 @@ public class ArchiveExtractor {
// Safety check // Safety check
if (isDirectory) { if (isDirectory) {
if (outputFile.isFile()) { if (outputFile.isFile() && !overwrite) {
throw new IOException("Can't create folder " + outputFile + ", a file with the same name exists!"); throw new IOException("Can't create folder " + outputFile + ", a file with the same name exists!");
} }
} else { } else {
// - isLink // - isLink
// - isSymLink // - isSymLink
// - anything else // - anything else
if (outputFile.exists()) { if (outputFile.exists() && !overwrite) {
throw new IOException("Can't extract file " + outputFile + ", file already exists!"); throw new IOException("Can't extract file " + outputFile + ", file already exists!");
} }
} }
@ -233,6 +238,9 @@ public class ArchiveExtractor {
} }
for (Map.Entry<File, File> entry : hardLinks.entrySet()) { for (Map.Entry<File, File> entry : hardLinks.entrySet()) {
if (entry.getKey().exists() && overwrite) {
entry.getKey().delete();
}
FileNativeUtils.link(entry.getValue(), entry.getKey()); FileNativeUtils.link(entry.getValue(), entry.getKey());
Integer mode = hardLinksMode.get(entry.getKey()); Integer mode = hardLinksMode.get(entry.getKey());
if (mode != null) { if (mode != null) {
@ -241,6 +249,9 @@ public class ArchiveExtractor {
} }
for (Map.Entry<File, File> entry : symLinks.entrySet()) { for (Map.Entry<File, File> entry : symLinks.entrySet()) {
if (entry.getKey().exists() && overwrite) {
entry.getKey().delete();
}
FileNativeUtils.symlink(entry.getValue(), entry.getKey()); FileNativeUtils.symlink(entry.getValue(), entry.getKey());
entry.getKey().setLastModified(symLinksModifiedTimes.get(entry.getKey())); entry.getKey().setLastModified(symLinksModifiedTimes.get(entry.getKey()));
} }

View File

@ -578,11 +578,12 @@ public class BaseNoGui {
static public void initPackages() throws Exception { static public void initPackages() throws Exception {
indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder()); indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder());
File indexFile = indexer.getIndexFile(); File indexFile = indexer.getIndexFile();
if (!indexFile.isFile()) { File avrCoreFolder = FileUtils.newFile(indexFile.getParentFile(), "packages", "arduino", "hardware", "avr");
if (!indexFile.isFile() || !(avrCoreFolder.exists() && avrCoreFolder.isDirectory())) {
File distFile = findDefaultPackageFile(); File distFile = findDefaultPackageFile();
if (distFile != null) { if (distFile != null) {
ArchiveExtractor.extract(distFile, BaseNoGui.getSettingsFolder(), 0); ArchiveExtractor.extract(distFile, BaseNoGui.getSettingsFolder(), 0, true);
} else { } else if (!indexFile.isFile()) {
// Otherwise create an empty packages index // Otherwise create an empty packages index
FileOutputStream out = null; FileOutputStream out = null;
try { try {

View File

@ -73,11 +73,13 @@ public class FileUtils {
} }
public static void recursiveDelete(File file) { public static void recursiveDelete(File file) {
if (file == null) if (file == null) {
return; return;
}
if (file.isDirectory()) { if (file.isDirectory()) {
for (File current : file.listFiles()) for (File current : file.listFiles()) {
recursiveDelete(current); recursiveDelete(current);
}
} }
file.delete(); file.delete();
} }
@ -254,5 +256,14 @@ public class FileUtils {
return result; return result;
} }
public static File newFile(File parent, String... parts) {
File result = parent;
for (String part : parts) {
result = new File(result, part);
}
return result;
}
} }