mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Be able to delete source file
This commit is contained in:
parent
c20226fc54
commit
bb11b5dcac
2 changed files with 16 additions and 4 deletions
|
@ -187,7 +187,11 @@ _ynh_panel_apply() {
|
||||||
ynh_die "File '${short_setting}' can't be stored in settings"
|
ynh_die "File '${short_setting}' can't be stored in settings"
|
||||||
fi
|
fi
|
||||||
local source_file="$(echo "$source" | sed s@__FINALPATH__@$final_path@ | sed s/__APP__/$app/)"
|
local source_file="$(echo "$source" | sed s@__FINALPATH__@$final_path@ | sed s/__APP__/$app/)"
|
||||||
cp "${!short_setting}" "$source_file"
|
if [[ "${!short_setting}" == "" ]] ; then
|
||||||
|
rm -f "$source_file"
|
||||||
|
else
|
||||||
|
cp "${!short_setting}" "$source_file"
|
||||||
|
fi
|
||||||
|
|
||||||
# Save value in app settings
|
# Save value in app settings
|
||||||
elif [[ "$source" == "settings" ]] ; then
|
elif [[ "$source" == "settings" ]] ; then
|
||||||
|
@ -247,6 +251,10 @@ _ynh_panel_validate() {
|
||||||
file_hash[new__$short_setting]=""
|
file_hash[new__$short_setting]=""
|
||||||
if [ -f "${old[$short_setting]}" ] ; then
|
if [ -f "${old[$short_setting]}" ] ; then
|
||||||
file_hash[old__$short_setting]=$(sha256sum "${old[$short_setting]}" | cut -d' ' -f1)
|
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
|
fi
|
||||||
if [ -f "${!short_setting}" ] ; then
|
if [ -f "${!short_setting}" ] ; then
|
||||||
file_hash[new__$short_setting]=$(sha256sum "${!short_setting}" | cut -d' ' -f1)
|
file_hash[new__$short_setting]=$(sha256sum "${!short_setting}" | cut -d' ' -f1)
|
||||||
|
|
|
@ -3190,20 +3190,24 @@ class FileArgumentParser(YunoHostArgumentFormatParser):
|
||||||
else:
|
else:
|
||||||
question_parsed.accept = []
|
question_parsed.accept = []
|
||||||
if Moulinette.interface.type== 'api':
|
if Moulinette.interface.type== 'api':
|
||||||
if user_answers.get(question_parsed.name):
|
if user_answers.get(f"{question_parsed.name}[name]"):
|
||||||
question_parsed.value = {
|
question_parsed.value = {
|
||||||
'content': question_parsed.value,
|
'content': question_parsed.value,
|
||||||
'filename': user_answers.get(f"{question_parsed.name}[name]", question_parsed.name),
|
'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
|
return question_parsed
|
||||||
|
|
||||||
def _prevalidate(self, question):
|
def _prevalidate(self, question):
|
||||||
super()._prevalidate(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(
|
raise YunohostValidationError(
|
||||||
"app_argument_invalid", name=question.name, error=m18n.n("invalid_number1")
|
"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
|
return
|
||||||
|
|
||||||
filename = question.value if isinstance(question.value, str) else question.value['filename']
|
filename = question.value if isinstance(question.value, str) else question.value['filename']
|
||||||
|
|
Loading…
Add table
Reference in a new issue