Gitlab Community Edition Instance

Commit 3d3ae40c authored by mhellka's avatar mhellka
Browse files

TUS: Apply default expire time to on-disk chunks after restart

parent a2744151
......@@ -3,7 +3,6 @@ package de.gwdg.cdstar.rest.ext.tus;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.nio.file.StandardOpenOption;
import java.time.Duration;
import java.time.Instant;
import java.util.Date;
......@@ -32,7 +31,6 @@ public class TusBlueprint implements RestBlueprint {
private static final String TUS_VERSION = "1.0.0";
private final TusService chunkService;
private Duration defaultExpire = Duration.ofHours(24);
public TusBlueprint(TusService service) {
chunkService = service;
......@@ -62,7 +60,6 @@ public class TusBlueprint implements RestBlueprint {
final TusFile chunk = chunkService.createChunk();
chunk.setLength(length);
chunk.setMeta(meta);
chunk.expireIn(defaultExpire);
ctx.status(201);
ctx.header(TUS_RESUMABLE, TUS_VERSION);
......
......@@ -3,6 +3,7 @@ package de.gwdg.cdstar.rest.ext.tus;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
......@@ -29,6 +30,7 @@ public class TusService {
public static final String pluginName = "tus-upload";
static final Logger log = LoggerFactory.getLogger(TusService.class);
private Duration defaultExpire = Duration.ofHours(24);
Path basePath;
Map<String, TusFile> chunks = new ConcurrentHashMap<>();
......@@ -44,6 +46,7 @@ public class TusService {
try (Stream<Path> s = Files.list(basePath)) {
s.filter(this::isChunk).forEach(path -> {
final TusFile chunk = new TusFile(chunkNameFormPath(path), path);
chunk.expireIn(defaultExpire);
chunks.put(chunk.getName(), chunk);
});
}
......@@ -89,6 +92,7 @@ public class TusService {
final String id = Utils.bytesToHex(Utils.randomBytes(16));
final Path path = basePath.resolve(chunkFileName(id));
chunk = new TusFile(id, path);
chunk.expireIn(defaultExpire);
} while (chunks.putIfAbsent(chunk.getName(), chunk) != null);
return chunk;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment