Skip to content

Commit

Permalink
Remove SD Card migration (#135)
Browse files Browse the repository at this point in the history
Co-authored-by: Madelen Andersson <[email protected]>
Co-authored-by: madelen-at-work <[email protected]>
  • Loading branch information
3 people authored Apr 19, 2024
1 parent 9f804f3 commit 903e3aa
Showing 1 changed file with 1 addition and 60 deletions.
61 changes: 1 addition & 60 deletions app/dockerdwrapperwithcompose.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

0 comments on commit 903e3aa

Please sign in to comment.