[enh] Be able to delete source file

This commit is contained in:
ljf 2021-08-31 04:20:21 +02:00
parent c20226fc54
commit bb11b5dcac
2 changed files with 16 additions and 4 deletions

View file

@ -187,7 +187,11 @@ _ynh_panel_apply() {
ynh_die "File '${short_setting}' can't be stored in settings"
fi
local source_file="$(echo "$source" | sed s@__FINALPATH__@$final_path@ | sed s/__APP__/$app/)"
if [[ "${!short_setting}" == "" ]] ; then
rm -f "$source_file"
else
cp "${!short_setting}" "$source_file"
fi
# Save value in app settings
elif [[ "$source" == "settings" ]] ; then
@ -247,6 +251,10 @@ _ynh_panel_validate() {
file_hash[new__$short_setting]=""
if [ -f "${old[$short_setting]}" ] ; then
file_hash[old__$short_setting]=$(sha256sum "${old[$short_setting]}" | cut -d' ' -f1)
if [ -z "${!short_setting}" ] ; then
changed[$short_setting]=true
is_error=false
fi
fi
if [ -f "${!short_setting}" ] ; then
file_hash[new__$short_setting]=$(sha256sum "${!short_setting}" | cut -d' ' -f1)

View file

@ -3190,20 +3190,24 @@ class FileArgumentParser(YunoHostArgumentFormatParser):
else:
question_parsed.accept = []
if Moulinette.interface.type== 'api':
if user_answers.get(question_parsed.name):
if user_answers.get(f"{question_parsed.name}[name]"):
question_parsed.value = {
'content': question_parsed.value,
'filename': user_answers.get(f"{question_parsed.name}[name]", question_parsed.name),
}
# If path file are the same
if question_parsed.value and str(question_parsed.value) == question_parsed.current_value:
question_parsed.value = None
return question_parsed
def _prevalidate(self, question):
super()._prevalidate(question)
if isinstance(question.value, str) and not os.path.exists(question.value):
if isinstance(question.value, str) and question.value and not os.path.exists(question.value):
raise YunohostValidationError(
"app_argument_invalid", name=question.name, error=m18n.n("invalid_number1")
)
if question.value is None or not question.accept:
if question.value in [None, ''] or not question.accept:
return
filename = question.value if isinstance(question.value, str) else question.value['filename']