Handle renamed files correctly, log invalidation

This commit is contained in:
comp500 2019-07-03 22:49:08 +01:00
parent 780efe2c9f
commit 34a86ffb7d
No known key found for this signature in database
GPG Key ID: 214C822FFEC586B5

View File

@ -230,6 +230,7 @@ public class UpdateManager {
} }
it.remove(); it.remove();
} else if (!Files.exists(filePath)) { } else if (!Files.exists(filePath)) {
System.out.println("File " + fileUri.toString() + " invalidated, marked for redownloading");
invalidatedUris.add(fileUri); invalidatedUris.add(fileUri);
} }
} }
@ -302,9 +303,11 @@ public class UpdateManager {
} catch (Exception e) {} } catch (Exception e) {}
} }
Path destPath = Paths.get(opts.packFolder, f.getDestURI().toString());
// Don't update files marked with preserve if they already exist on disk // Don't update files marked with preserve if they already exist on disk
if (f.preserve) { if (f.preserve) {
if (Files.exists(Paths.get(opts.packFolder, f.getDestURI().toString()))) { if (Files.exists(destPath)) {
return dc; return dc;
} }
} }
@ -326,14 +329,19 @@ public class UpdateManager {
Okio.buffer(fileSource).readAll(data); Okio.buffer(fileSource).readAll(data);
if (fileSource.hashIsEqual(hash)) { if (fileSource.hashIsEqual(hash)) {
Files.createDirectories(Paths.get(opts.packFolder, f.getDestURI().toString()).getParent()); Files.createDirectories(destPath.getParent());
Files.copy(data.inputStream(), Paths.get(opts.packFolder, f.getDestURI().toString()), StandardCopyOption.REPLACE_EXISTING); Files.copy(data.inputStream(), destPath, StandardCopyOption.REPLACE_EXISTING);
} else { } else {
System.out.println("Invalid hash for " + f.getDestURI().toString()); System.out.println("Invalid hash for " + f.getDestURI().toString());
System.out.println("Calculated: " + fileSource.getHash()); System.out.println("Calculated: " + fileSource.getHash());
System.out.println("Expected: " + hash); System.out.println("Expected: " + hash);
dc.err = new Exception("Hash invalid!"); dc.err = new Exception("Hash invalid!");
} }
if (cachedFile != null && !destPath.equals(Paths.get(opts.packFolder, cachedFile.cachedLocation))) {
// Delete old file if location changes
Files.delete(Paths.get(opts.packFolder, cachedFile.cachedLocation));
}
return dc; return dc;
} catch (Exception e) { } catch (Exception e) {