diff --git a/lib/LANraragi/Controller/Config.pm b/lib/LANraragi/Controller/Config.pm
index 6ecfdb014..60c66907a 100644
--- a/lib/LANraragi/Controller/Config.pm
+++ b/lib/LANraragi/Controller/Config.pm
@@ -45,7 +45,8 @@ sub index {
enablecryptofs => $self->LRR_CONF->enable_cryptofs,
hqthumbpages => $self->LRR_CONF->get_hqthumbpages,
csshead => generate_themes_header($self),
- tempsize => get_tempsize
+ tempsize => get_tempsize,
+ replacedupe => $self->LRR_CONF->get_replacedupe
);
}
@@ -84,6 +85,7 @@ sub save_config {
usedatemodified => ( scalar $self->req->param('usedatemodified') ? '1' : '0' ),
enablecryptofs => ( scalar $self->req->param('enablecryptofs') ? '1' : '0' ),
hqthumbpages => ( scalar $self->req->param('hqthumbpages') ? '1' : '0' ),
+ replacedupe => ( scalar $self->req->param('replacedupe') ? '1' : '0' ),
);
# Only add newpassword field as password if enablepass = 1
diff --git a/lib/LANraragi/Model/Config.pm b/lib/LANraragi/Model/Config.pm
index cef6d1a92..f39523810 100644
--- a/lib/LANraragi/Model/Config.pm
+++ b/lib/LANraragi/Model/Config.pm
@@ -182,5 +182,6 @@ sub enable_dateadded { return &get_redis_conf( "usedateadded", "1" ) }
sub use_lastmodified { return &get_redis_conf( "usedatemodified", "0" ) }
sub enable_cryptofs { return &get_redis_conf( "enablecryptofs", "0" ) }
sub get_hqthumbpages { return &get_redis_conf( "hqthumbpages", "0" ) }
+sub get_replacedupe { return &get_redis_conf( "replacedupe", "0" ) }
1;
diff --git a/lib/LANraragi/Model/Upload.pm b/lib/LANraragi/Model/Upload.pm
index e2e99bc47..2a142f0f2 100644
--- a/lib/LANraragi/Model/Upload.pm
+++ b/lib/LANraragi/Model/Upload.pm
@@ -53,23 +53,31 @@ sub handle_incoming_file {
#that the file it references still exists on the filesystem
my $redis = LANraragi::Model::Config->get_redis;
my $redis_search = LANraragi::Model::Config->get_redis_search;
+ my $replace_dupe = LANraragi::Model::Config->get_replacedupe;
my $isdupe = $redis->exists($id) && -e $redis->hget( $id, "file" );
- # Stop here if file is a dupe.
- if ( -e $output_file || $isdupe ) {
+ # Stop here if file is a dupe and replacement is turned off.
+ if ((-e $output_file || $isdupe) && !$replace_dupe) {
# Trash temporary file
unlink $tempfile;
# The file already exists
+ my $suffix = " Enable replace duplicated archive in config to replace old ones.";
my $msg =
$isdupe
- ? "This file already exists in the Library."
- : "A file with the same name is present in the Library.";
+ ? "This file already exists in the Library." . $suffix
+ : "A file with the same name is present in the Library." . $suffix;
return ( 0, $id, $filename, $msg );
}
+ # If we are replacing an existing one, just remove the old one first.
+ if ($replace_dupe) {
+ $logger->debug("Delete archive $id before replacing it.");
+ LANraragi::Utils::Database::delete_archive( $id );
+ }
+
# Add the file to the database ourselves so Shinobu doesn't do it
# This allows autoplugin to be ran ASAP.
my $name = LANraragi::Utils::Database::add_archive_to_redis( $id, $output_file, $redis );
@@ -100,7 +108,7 @@ sub handle_incoming_file {
}
# Move the file to the content folder.
- # Move to a .tmp first in case copy to the content folder takes a while...
+ # Move to a .upload first in case copy to the content folder takes a while...
move( $tempfile, $output_file . ".upload" );
# Then rename inside the content folder itself to proc Shinobu.
diff --git a/lib/LANraragi/Utils/Database.pm b/lib/LANraragi/Utils/Database.pm
index b3508683a..de197294a 100644
--- a/lib/LANraragi/Utils/Database.pm
+++ b/lib/LANraragi/Utils/Database.pm
@@ -199,7 +199,7 @@ sub build_json {
return $arcdata;
}
-#Deletes the archive with the given id from redis, and the matching archive file/thumbnail.
+# Deletes the archive with the given id from redis, and the matching archive file/thumbnail.
sub delete_archive {
my $id = $_[0];
diff --git a/templates/templates_config/config_files.html.tt2 b/templates/templates_config/config_files.html.tt2
index 59d03b5e5..820d487ee 100644
--- a/templates/templates_config/config_files.html.tt2
+++ b/templates/templates_config/config_files.html.tt2
@@ -85,4 +85,18 @@
If you want to clear those flags, click this button.
-
\ No newline at end of file
+
+
+