Skip to content

Commit d44df8f

Browse files
committed
Implement reset_data functionality
1 parent 92d34a1 commit d44df8f

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

rootfs/standard/var/pynode/application_info.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,36 @@ def restart_application(short_name):
754754
except Exception as e:
755755
return False
756756

757+
def reset_data_folder(app_data):
758+
log_message(" Running reset_data_folder...")
759+
760+
# If app_data is a string (short name), convert it to a full configuration
761+
# and preserve the original short name.
762+
if isinstance(app_data, str):
763+
original_short_name = app_data # Save the short name for service commands.
764+
app_data = get_application(app_data)
765+
else:
766+
original_short_name = app_data["short_name"]
767+
768+
# Stop the service before removing data_folder
769+
log_message("Stopping '{}'.".format(original_short_name))
770+
stop_service(original_short_name)
771+
772+
# Remove App data_folder
773+
log_message("Removing storage folder '{}' of '{}'...".format(data_folder, original_short_name))
774+
data_folder = app_data["storage_folder"]
775+
run_linux_cmd("rm -rf {}".format(data_folder))
776+
777+
# Re-create the storage folder
778+
log_message("Creating storage folder '{}' of '{}'...".format(data_folder, original_short_name))
779+
create_application_storage_folder(app_data)
780+
781+
# Re-start the service
782+
log_message("Starting '{}'.".format(original_short_name))
783+
start_service(original_short_name)
784+
785+
return True
786+
757787
######################################################################################
758788
## Bulk Application Actions
759789
######################################################################################

rootfs/standard/var/www/mynode/api.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,17 @@ def api_restore_data_folder():
177177
# return "ERROR"
178178
return "OK"
179179

180-
# @mynode_api.route("/api/restart_app")
181180
@mynode_api.route("/api/reset_data_folder")
182181
def api_reset_data_folder():
183-
# check_logged_in()
184-
#
185-
# app = request.args.get("app")
186-
# if not app:
187-
# return "NO_APP_SPECIFIED"
188-
# if not is_application_valid(app):
189-
# return "INVALID_APP_NAME"
190-
# if not restart_application(app):
191-
# return "ERROR"
182+
check_logged_in()
183+
184+
app = request.args.get("app")
185+
if not app:
186+
return "NO_APP_SPECIFIED"
187+
if not is_application_valid(app):
188+
return "INVALID_APP_NAME"
189+
if not reset_data_folder(app):
190+
return "ERROR"
192191
return "OK"
193192

194193
@mynode_api.route("/api/get_device_info")

0 commit comments

Comments
 (0)