mirror of
https://github.com/arduino/Arduino.git
synced 2024-11-29 10:24:12 +01:00
Fixed missing symlinks after extraction
This commit is contained in:
parent
fc4179f1f7
commit
29d20f297c
@ -45,8 +45,6 @@ public abstract class HostDependentDownloadableContribution extends Downloadable
|
|||||||
Properties prop = System.getProperties();
|
Properties prop = System.getProperties();
|
||||||
String osName = prop.getProperty("os.name");
|
String osName = prop.getProperty("os.name");
|
||||||
String osArch = prop.getProperty("os.arch");
|
String osArch = prop.getProperty("os.arch");
|
||||||
// for (Object k : properties.keySet())
|
|
||||||
// System.out.println(k + " = " + properties.get(k));
|
|
||||||
|
|
||||||
String host = getHost();
|
String host = getHost();
|
||||||
|
|
||||||
|
@ -59,33 +59,33 @@ public class FileNativeUtils {
|
|||||||
* Create a hard link from <b>oldFile</b> to <b>newFile</b>. If the underlying
|
* Create a hard link from <b>oldFile</b> to <b>newFile</b>. If the underlying
|
||||||
* filesystem doesn't support hard links then the command is ignored.
|
* filesystem doesn't support hard links then the command is ignored.
|
||||||
*
|
*
|
||||||
* @param oldFile
|
* @param something
|
||||||
* @param newFile
|
* @param somewhere
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public static void link(File oldFile, File newFile) throws IOException {
|
public static void link(File something, File somewhere) throws IOException {
|
||||||
if (OSUtils.isLinux())
|
if (OSUtils.isLinux())
|
||||||
LinuxFileNativeUtils.link(oldFile, newFile);
|
LinuxFileNativeUtils.link(something, somewhere);
|
||||||
if (OSUtils.isMacOS())
|
if (OSUtils.isMacOS())
|
||||||
MacOSFileNativeUtils.link(oldFile, newFile);
|
MacOSFileNativeUtils.link(something, somewhere);
|
||||||
if (OSUtils.isWindows())
|
if (OSUtils.isWindows())
|
||||||
WindowsFileNativeUtils.link(oldFile, newFile);
|
WindowsFileNativeUtils.link(something, somewhere);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a symlink link from <b>oldFile</b> to <b>newFile</b>. If the
|
* Create a symlink link from <b>oldFile</b> to <b>newFile</b>. If the
|
||||||
* underlying filesystem doesn't support symlinks then the command is ignored.
|
* underlying filesystem doesn't support symlinks then the command is ignored.
|
||||||
*
|
*
|
||||||
* @param oldFile
|
* @param something
|
||||||
* @param newFile
|
* @param somewhere
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public static void symlink(File oldFile, File newFile) throws IOException {
|
public static void symlink(File something, File somewhere) throws IOException {
|
||||||
if (OSUtils.isLinux())
|
if (OSUtils.isLinux())
|
||||||
LinuxFileNativeUtils.symlink(oldFile, newFile);
|
LinuxFileNativeUtils.symlink(something, somewhere);
|
||||||
if (OSUtils.isMacOS())
|
if (OSUtils.isMacOS())
|
||||||
MacOSFileNativeUtils.symlink(oldFile, newFile);
|
MacOSFileNativeUtils.symlink(something, somewhere);
|
||||||
if (OSUtils.isWindows())
|
if (OSUtils.isWindows())
|
||||||
WindowsFileNativeUtils.symlink(oldFile, newFile);
|
WindowsFileNativeUtils.symlink(something, somewhere);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,18 +35,16 @@ import com.sun.jna.Pointer;
|
|||||||
|
|
||||||
public interface LibCNative extends Library {
|
public interface LibCNative extends Library {
|
||||||
|
|
||||||
static LibCNative libc = (LibCNative) Native.loadLibrary("c",
|
LibCNative libc = (LibCNative) Native.loadLibrary("c", LibCNative.class);
|
||||||
LibCNative.class);
|
|
||||||
|
|
||||||
Pointer errno = NativeLibrary.getInstance("c")
|
Pointer errno = NativeLibrary.getInstance("c").getGlobalVariableAddress("errno");
|
||||||
.getGlobalVariableAddress("errno");
|
|
||||||
|
|
||||||
public int chmod(String path, int mode);
|
int chmod(String path, int mode);
|
||||||
|
|
||||||
public int link(String oldpath, String newpath);
|
int link(String something, String somewhere);
|
||||||
|
|
||||||
public int symlink(String oldpath, String newpath);
|
int symlink(String something, String somewhere);
|
||||||
|
|
||||||
public String strerror(int errno);
|
String strerror(int errno);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -37,20 +37,23 @@ public class LinuxFileNativeUtils {
|
|||||||
|
|
||||||
public static void chmod(File file, int mode) throws IOException {
|
public static void chmod(File file, int mode) throws IOException {
|
||||||
int res = libc.chmod(file.getAbsolutePath(), mode);
|
int res = libc.chmod(file.getAbsolutePath(), mode);
|
||||||
if (res == -1)
|
if (res == -1) {
|
||||||
throw new IOException("Could not change file permission: " + strerror());
|
throw new IOException("Could not change file permission: " + strerror());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void link(File file, File link) throws IOException {
|
public static void link(File something, File somewhere) throws IOException {
|
||||||
int res = libc.link(file.getAbsolutePath(), link.getAbsolutePath());
|
int res = libc.link(something.getAbsolutePath(), somewhere.getAbsolutePath());
|
||||||
if (res == -1)
|
if (res == -1) {
|
||||||
throw new IOException("Could not create hard link to " + file + " from " + link + ": " + strerror());
|
throw new IOException("Could not create hard link to " + somewhere + " from " + something + ": " + strerror());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void symlink(File file, File link) throws IOException {
|
public static void symlink(File something, File somewhere) throws IOException {
|
||||||
int res = libc.symlink(file.getPath(), link.getAbsolutePath());
|
int res = libc.symlink(something.getPath(), somewhere.getAbsolutePath());
|
||||||
if (res == -1)
|
if (res == -1) {
|
||||||
throw new IOException("Could not create symlink: " + strerror());
|
throw new IOException("Could not create symlink to " + somewhere + " from " + something + ": " + strerror());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String strerror() {
|
private static String strerror() {
|
||||||
|
@ -174,21 +174,23 @@ public class ArchiveExtractor {
|
|||||||
}
|
}
|
||||||
File outputFile = new File(destFolder, name);
|
File outputFile = new File(destFolder, name);
|
||||||
|
|
||||||
File outputLinkFile = null;
|
File outputLinkedFile = null;
|
||||||
if (isLink) {
|
if (isLink) {
|
||||||
if (!linkName.startsWith(pathPrefix)) {
|
if (!linkName.startsWith(pathPrefix)) {
|
||||||
throw new IOException("Invalid archive: it must contains a single root folder while file " + linkName + " is outside " + pathPrefix);
|
throw new IOException("Invalid archive: it must contains a single root folder while file " + linkName + " is outside " + pathPrefix);
|
||||||
}
|
}
|
||||||
linkName = linkName.substring(pathPrefix.length());
|
linkName = linkName.substring(pathPrefix.length());
|
||||||
outputLinkFile = new File(destFolder, linkName);
|
outputLinkedFile = new File(destFolder, linkName);
|
||||||
}
|
}
|
||||||
if (isSymLink) {
|
if (isSymLink) {
|
||||||
// Symbolic links are referenced with relative paths
|
// Symbolic links are referenced with relative paths
|
||||||
outputLinkFile = new File(linkName);
|
outputLinkedFile = new File(linkName);
|
||||||
if (outputLinkFile.isAbsolute()) {
|
if (outputLinkedFile.isAbsolute()) {
|
||||||
System.err.println(I18n.format(_("Warning: file {0} links to an absolute path {1}, changing it to {2}"), outputFile, outputLinkFile, new File(outputLinkFile.getName())));
|
System.err.println(I18n.format(_("Warning: file {0} links to an absolute path {1}, changing it to {2}"), outputFile, outputLinkedFile, new File(outputLinkedFile.getName())));
|
||||||
System.err.println();
|
System.err.println();
|
||||||
outputLinkFile = new File(outputLinkFile.getName());
|
outputLinkedFile = new File(outputLinkedFile.getName());
|
||||||
|
} else {
|
||||||
|
outputLinkedFile = new File(outputFile.getParent(), linkName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,10 +215,10 @@ public class ArchiveExtractor {
|
|||||||
}
|
}
|
||||||
foldersTimestamps.put(outputFile, modifiedTime);
|
foldersTimestamps.put(outputFile, modifiedTime);
|
||||||
} else if (isLink) {
|
} else if (isLink) {
|
||||||
hardLinks.put(outputLinkFile, outputFile);
|
hardLinks.put(outputFile, outputLinkedFile);
|
||||||
hardLinksMode.put(outputFile, mode);
|
hardLinksMode.put(outputFile, mode);
|
||||||
} else if (isSymLink) {
|
} else if (isSymLink) {
|
||||||
symLinks.put(outputLinkFile, outputFile);
|
symLinks.put(outputFile, outputLinkedFile);
|
||||||
symLinksModifiedTimes.put(outputFile, modifiedTime);
|
symLinksModifiedTimes.put(outputFile, modifiedTime);
|
||||||
} else {
|
} else {
|
||||||
// Create the containing folder if not exists
|
// Create the containing folder if not exists
|
||||||
@ -234,16 +236,16 @@ public class ArchiveExtractor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<File, File> entry : hardLinks.entrySet()) {
|
for (Map.Entry<File, File> entry : hardLinks.entrySet()) {
|
||||||
FileNativeUtils.link(entry.getKey(), entry.getValue());
|
FileNativeUtils.link(entry.getValue(), entry.getKey());
|
||||||
Integer mode = hardLinksMode.get(entry.getValue());
|
Integer mode = hardLinksMode.get(entry.getKey());
|
||||||
if (mode != null) {
|
if (mode != null) {
|
||||||
FileNativeUtils.chmod(entry.getValue(), mode);
|
FileNativeUtils.chmod(entry.getKey(), mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<File, File> entry : symLinks.entrySet()) {
|
for (Map.Entry<File, File> entry : symLinks.entrySet()) {
|
||||||
FileNativeUtils.symlink(entry.getKey(), entry.getValue());
|
FileNativeUtils.symlink(entry.getValue(), entry.getKey());
|
||||||
entry.getValue().setLastModified(symLinksModifiedTimes.get(entry.getValue()));
|
entry.getKey().setLastModified(symLinksModifiedTimes.get(entry.getKey()));
|
||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
Loading…
Reference in New Issue
Block a user