Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bob doesn't unpack plugin shared libraries unless they've changed #6472

Merged
merged 2 commits into from
Mar 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,30 @@ public static boolean isAndroidAssetDirectory(Project project, String path) {
return false;
}

public static byte[] createSha1(File file) throws Exception {
MessageDigest digest = MessageDigest.getInstance("SHA1");
InputStream fis = new FileInputStream(file);
int n = 0;
byte[] buffer = new byte[8192];
while (n != -1) {
n = fis.read(buffer);
if (n > 0) {
digest.update(buffer, 0, n);
}
}
return digest.digest();
}

private static boolean areFilesIdentical(IResource src, File tgt) {
try {
byte[] sha1_src = src.sha1();
byte[] sha1_tgt = createSha1(tgt);
return Arrays.equals(sha1_src, sha1_tgt);
} catch(Exception e) {
return false;
}
}

// Collects all resources (even those inside the zip packages) and stores them into one single folder
public static void storeResources(File targetDirectory, Map<String, IResource> resources) throws CompileExceptionError {
for (String relativePath : resources.keySet()) {
Expand All @@ -724,6 +748,11 @@ public static void storeResources(File targetDirectory, Map<String, IResource> r
if (!outputFile.getParentFile().exists()) {
outputFile.getParentFile().mkdirs();
}

if (outputFile.exists() && areFilesIdentical(r, outputFile)) {
continue;
}

try {
byte[] data = r.getContent();
FileUtils.writeByteArrayToFile(outputFile, data);
Expand All @@ -740,6 +769,13 @@ public static void storeResources(File targetDirectory, List<IResource> resource
if (!outputFile.getParentFile().exists()) {
outputFile.getParentFile().mkdirs();
}

// We do this because we might be called from within the editor, which ight have the .dll's locked.
// and so we don't want to fail copying those if we can avoid it.
if (outputFile.exists() && areFilesIdentical(resource, outputFile)) {
continue;
}

try {
byte[] data = resource.getContent();
FileUtils.writeByteArrayToFile(outputFile, data);
Expand Down