mirror of
https://gitlab.com/mangadex-pub/mangadex_at_home.git
synced 2024-01-19 02:48:37 +00:00
Use atomic operations for cache migration
This commit is contained in:
parent
4b7c8bb0cb
commit
d611f4a6da
5
src/main/java/mdnet/cache/DiskLruCache.java
vendored
5
src/main/java/mdnet/cache/DiskLruCache.java
vendored
|
@ -38,6 +38,7 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.nio.file.FileAlreadyExistsException;
|
import java.nio.file.FileAlreadyExistsException;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
@ -1002,7 +1003,7 @@ public final class DiskLruCache implements Closeable {
|
||||||
Path new_cache = Paths.get(directory + subkeypath + File.separator + key + "." + i);
|
Path new_cache = Paths.get(directory + subkeypath + File.separator + key + "." + i);
|
||||||
if (Files.exists(old_cache)) {
|
if (Files.exists(old_cache)) {
|
||||||
try {
|
try {
|
||||||
Files.move(old_cache, new_cache);
|
Files.move(old_cache, new_cache, StandardCopyOption.ATOMIC_MOVE);
|
||||||
} catch (FileAlreadyExistsException faee) {
|
} catch (FileAlreadyExistsException faee) {
|
||||||
try {
|
try {
|
||||||
Files.delete(old_cache);
|
Files.delete(old_cache);
|
||||||
|
@ -1019,7 +1020,7 @@ public final class DiskLruCache implements Closeable {
|
||||||
Path new_cache = Paths.get(directory + subkeypath + File.separator + key + "." + i + ".tmp");
|
Path new_cache = Paths.get(directory + subkeypath + File.separator + key + "." + i + ".tmp");
|
||||||
if (Files.exists(old_cache)) {
|
if (Files.exists(old_cache)) {
|
||||||
try {
|
try {
|
||||||
Files.move(old_cache, new_cache);
|
Files.move(old_cache, new_cache, StandardCopyOption.ATOMIC_MOVE);
|
||||||
} catch (FileAlreadyExistsException faee) {
|
} catch (FileAlreadyExistsException faee) {
|
||||||
try {
|
try {
|
||||||
Files.delete(old_cache);
|
Files.delete(old_cache);
|
||||||
|
|
Loading…
Reference in a new issue