From: Paul Hänsch Date: Mon, 28 Sep 2026 03:22:27 +0000 (+0200) Subject: copy function for attachments X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=565d58e04cd419225ab09d2cab24fe489f9bf6c8;p=shellwiki copy function for attachments --- diff --git a/handlers/40_edit_attachment.sh b/handlers/40_edit_attachment.sh index b23a35d..11770dd 100755 --- a/handlers/40_edit_attachment.sh +++ b/handlers/40_edit_attachment.sh @@ -1,6 +1,6 @@ #!/bin/sh -# Copyright 2022 - 2023 Paul Hänsch +# Copyright 2022 - 2026 Paul Hänsch # # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above @@ -15,6 +15,7 @@ # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. REV_ATTACHMENTS="${REV_ATTACHMENTS:-false}" +COPY_ATTACHMENTS="${COPY_ATTACHMENTS:-auto}" # copy|reflink|hardlink|auto if [ "${PATH_INFO##*/\[attachment\]}" ]; then # Skip any action not happening on attachment page @@ -86,7 +87,7 @@ elif [ "$SESSION_ID" != "$tsid" ]; then return 0 fi -if [ "$action" = delete -o "$action" = move ]; then +if [ "$action" = delete -o "$action" = move -o "$action" = copy ]; then set -- n="$(POST_COUNT select)"; while [ $n -gt 0 ]; do select="$(POST select $n |PATH)" @@ -122,6 +123,7 @@ elif [ "$action" = move ]; then mkdir -p -- "${_DATA}/pages${moveto}/#attachments" git -C "$_DATA" mv -f -- "$@" "pages${moveto}/#attachments/" + # load new names into parameter array cnt=$#; while [ $cnt -gt 0 ]; do set -- "$@" "$1" "pages/${moveto}/#attachments/${1##*/}" cnt=$((cnt - 1)); shift 1 @@ -135,6 +137,55 @@ elif [ "$action" = move ]; then fi REDIRECT "${_BASE}${PATH_INFO}" +elif [ "$action" = copy ]; then + copyto="$(POST copyto |PATH)" + + if ! acl_write "$copyto"; then + printf 'Refresh: %i\r\n' 4 + theme_error 403 + return 0 + + elif [ ! -d "${_DATA}/pages${copyto}" ]; then + printf 'Refresh: %i\r\n' 4 + theme_error 404 + return 0 + + else + mkdir -p -- "${_DATA}/pages${copyto}/#attachments" + case $COPY_ATTACHMENTS in + hardlink) + ( cd "$_DATA" && ln -- "$@" "pages${copyto}/#attachments/"; ) + ;; + copy) + ( cd "$_DATA" && cp -- "$@" "pages${copyto}/#attachments/"; ) + ;; + reflink) + ( cd "$_DATA" && cp --reflink=always -- "$@" "pages${copyto}/#attachments/"; ) + ;; + auto|*) + ( cd "$_DATA"; + ln -- "$@" "pages${copyto}/#attachments/" \ + || cp --reflink=always -- "$@" "pages${copyto}/#attachments/" \ + || cp -- "$@" "pages${copyto}/#attachments/" + ) + ;; + esac + fi + + if [ "$REV_ATTACHMENTS" = true ]; then + # load new names into parameter array + cnt=$#; while [ $cnt -gt 0 ]; do + set -- "$@" "$1" "pages/${copyto}/#attachments/${1##*/}" + cnt=$((cnt - 1)); shift 1 + done + + git -C "$_DATA" add -- "$@" + git -C "$_DATA" commit -qm \ + "Attachment copied from # $page # to # $copyto # by @ $USER_NAME @" -- "$@" + fi + + REDIRECT "${_BASE}${PATH_INFO}" + elif [ "$action" = rename ]; then fail='' success='' set -- diff --git a/themes/default.css b/themes/default.css index 6bf4985..af2f330 100644 --- a/themes/default.css +++ b/themes/default.css @@ -393,7 +393,9 @@ table { [id$="/[attachment]"] input[type=radio].tab#tdel:checked ~ div.tab ul li input[name=select], [id$="/[attachment]"] input[type=radio].tab#tdel:checked ~ div.tab ul li label.name, [id$="/[attachment]"] input[type=radio].tab#tmove:checked ~ div.tab ul li input[name=select], -[id$="/[attachment]"] input[type=radio].tab#tmove:checked ~ div.tab ul li label.name { +[id$="/[attachment]"] input[type=radio].tab#tmove:checked ~ div.tab ul li label.name, +[id$="/[attachment]"] input[type=radio].tab#tcopy:checked ~ div.tab ul li input[name=select], +[id$="/[attachment]"] input[type=radio].tab#tcopy:checked ~ div.tab ul li label.name { display: inline; } [id$="/[attachment]"] input[type=radio].tab#tren:checked ~ .tab ul li input.name { @@ -401,6 +403,7 @@ table { } [id$="/[attachment]"] label[for=moveto], [id$="/[attachment]"] input#moveto, +[id$="/[attachment]"] label[for=copyto], [id$="/[attachment]"] input#copyto, [id$="/[attachment]"] button[name=action] { display: none; } [id$="/[attachment]"] .upload button[name=action] { display: inline-block; } @@ -408,6 +411,9 @@ table { [id$="/[attachment]"] input[type=radio].tab#tmove:checked ~ div.tab label[for=moveto], [id$="/[attachment]"] input[type=radio].tab#tmove:checked ~ div.tab input#moveto, [id$="/[attachment]"] input[type=radio].tab#tmove:checked ~ div.tab button[name=action][value=move], +[id$="/[attachment]"] input[type=radio].tab#tcopy:checked ~ div.tab label[for=copyto], +[id$="/[attachment]"] input[type=radio].tab#tcopy:checked ~ div.tab input#copyto, +[id$="/[attachment]"] input[type=radio].tab#tcopy:checked ~ div.tab button[name=action][value=copy], [id$="/[attachment]"] input[type=radio].tab#tren:checked ~ div.tab button[name=action][value=rename] { display: inline; } diff --git a/themes/default.sh b/themes/default.sh index e331534..a81b06f 100755 --- a/themes/default.sh +++ b/themes/default.sh @@ -161,6 +161,7 @@ theme_attachments(){ +