mirror of
https://github.com/AsamK/signal-cli.git
synced 2026-09-23 06:39:04 +00:00
parent
dc2a74e824
commit
29dcac23cf
@ -168,7 +168,7 @@ public class AttachmentHelper {
|
|||||||
try {
|
try {
|
||||||
attachmentStore.storeAttachment(pointer, outputStream -> this.retrieveAttachment(pointer, outputStream));
|
attachmentStore.storeAttachment(pointer, outputStream -> this.retrieveAttachment(pointer, outputStream));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.warn("Failed to download attachment ({}), ignoring: {}", pointer.getRemoteId(), e.getMessage());
|
logger.warn("Failed to download attachment ({}), ignoring", pointer.getRemoteId(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,9 +8,11 @@ import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemo
|
|||||||
import org.whispersystems.signalservice.api.util.StreamDetails;
|
import org.whispersystems.signalservice.api.util.StreamDetails;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.nio.file.AtomicMoveNotSupportedException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class AttachmentStore {
|
public class AttachmentStore {
|
||||||
@ -51,8 +53,23 @@ public class AttachmentStore {
|
|||||||
|
|
||||||
private void storeAttachment(final File attachmentFile, final AttachmentStorer storer) throws IOException {
|
private void storeAttachment(final File attachmentFile, final AttachmentStorer storer) throws IOException {
|
||||||
createAttachmentsDir();
|
createAttachmentsDir();
|
||||||
try (OutputStream output = new FileOutputStream(attachmentFile)) {
|
final var temporaryFile = Files.createTempFile(attachmentsPath.toPath(),
|
||||||
storer.store(output);
|
attachmentFile.getName() + ".",
|
||||||
|
".tmp");
|
||||||
|
try {
|
||||||
|
try (OutputStream output = Files.newOutputStream(temporaryFile)) {
|
||||||
|
storer.store(output);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Files.move(temporaryFile,
|
||||||
|
attachmentFile.toPath(),
|
||||||
|
StandardCopyOption.ATOMIC_MOVE,
|
||||||
|
StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
} catch (AtomicMoveNotSupportedException e) {
|
||||||
|
Files.move(temporaryFile, attachmentFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
Files.deleteIfExists(temporaryFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user