Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove SD Card migration #228

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 1 addition & 60 deletions app/dockerdwrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ typedef enum {
STATUS_NO_SD_CARD,
STATUS_SD_CARD_WRONG_FS,
STATUS_SD_CARD_WRONG_PERMISSION,
STATUS_SD_CARD_MIGRATION_FAILED,
STATUS_CODE_COUNT,
} status_code_t;

Expand All @@ -64,8 +63,7 @@ static const char* const status_code_strs[STATUS_CODE_COUNT] = {"-1 NOT STARTED"
"4 NO SOCKET",
"5 NO SD CARD",
"6 SD CARD WRONG FS",
"7 SD CARD WRONG PERMISSION",
"8 SD CARD MIGRATION FAILED"};
"7 SD CARD WRONG PERMISSION"};

struct settings {
char* data_root;
Expand Down Expand Up @@ -258,57 +256,6 @@ static char* get_parameter_value(AXParameter* param_handle, const char* paramete
return parameter_value;
}

/**
* @brief Migrate the contents of the data directory from the old setup on the
* SD card to 'new_dir' The new directory must be created and empty. If the
* operation is successful, the old setup directory will be removed.
*
* @return True if operation was successful, false otherwise.
*/
static bool migrate_from_old_sdcard_setup(const char* new_dir) {
const char* old_top_dir = "/var/spool/storage/SD_DISK/dockerd";
struct stat directory_stat;
int stat_result = stat(old_top_dir, &directory_stat);
if (stat(old_top_dir, &directory_stat) != 0) {
// No files to move
return true;
}

// The new directory must be created and empty.
GDir* dir = g_dir_open(new_dir, 0, NULL);
if (dir == NULL) {
log_error("Failed to open %s", new_dir);
return false;
}
// Get name to first entry in directory, NULL if empty, . and .. are omitted
const char* dir_entry = g_dir_read_name(dir);
bool directory_not_empty = dir_entry != NULL;
g_dir_close(dir);

if (directory_not_empty) {
log_error("Target directory %s is not empty. Will not move files.", new_dir);
return false;
}

// Move data from the old directory
const char* move_command = g_strdup_printf("mv %s/data/* %s/.", old_top_dir, new_dir);
log_info("Run move cmd: \"%s\"", move_command);
int res = system(move_command);
if (res != 0) {
log_error("Failed to move %s to %s, error: %d", old_top_dir, new_dir, res);
return false;
}

// Remove the directory
const char* remove_command = g_strdup_printf("rm -rf %s", old_top_dir);
res = system(remove_command);
if (res != 0) {
log_error("Failed to remove %s, error: %d", old_top_dir, res);
}

return res == 0;
}

/**
* @brief Retrieve the file system type of the device containing this path.
*
Expand Down Expand Up @@ -394,12 +341,6 @@ static bool setup_sdcard(AXParameter* param_handle, const char* data_root) {
return false;
}

if (!migrate_from_old_sdcard_setup(data_root)) {
log_error("Failed to migrate data from old data-root");
set_status_parameter(param_handle, STATUS_SD_CARD_MIGRATION_FAILED);
return false;
}

return true;
}

Expand Down