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

Dont delete user content #1625

Merged
merged 2 commits into from
Apr 5, 2024
Merged

Dont delete user content #1625

merged 2 commits into from
Apr 5, 2024

Conversation

bryteise
Copy link
Member

@bryteise bryteise commented Apr 4, 2024

No description provided.

The remove_files_in_manifest_from_fs function isn't used and was a
user of a rather dangerous recursive remove function. Get rid of it to
avoid potential confusion.

Signed-off-by: William Douglas <[email protected]>
@@ -330,6 +333,61 @@ static enum swupd_code install_dir(const char *fullfile_path, const char *target
return install_dir_using_tar(fullfile_path, target_file);
}

/* Backup target directory to a backup and timestamp prefixed name. */
/* This function should only be used after the deletes are processed. */
static enum swupd_code move_to_timestamp(const char *filename)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe call it "dirname" not "filename" to indicate we expect it to be a directory?


/* It shouldn't be possible to have an already created backup_dir
but just in case, try and remove it and error out if unable to. */
ret = sys_rm_recursive(backup_dir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shuold we actually check if this is there first? just incase we have some bug... then it only ever happens if it actually exists

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, less to go wrong. I suspect if things are going wrong in this area though we are in a whole different world of hurt that'll show up all over in testing.

src/swupd_lib/target_root.c Outdated Show resolved Hide resolved
src/swupd_lib/target_root.c Show resolved Hide resolved
src/swupd_lib/target_root.c Outdated Show resolved Hide resolved
src/swupd_lib/target_root.c Show resolved Hide resolved
Currently sys_rm_recursive was used in any instance of deleting swupd
content from the system (update, repair and bundle-remove). This can
cause user data loss when unkown files are in directories that swupd
is deleting.

To prevent this, this patch changes how deleting content in swupd
operates. Swupd content removal is now done with sys_rm and the return
value is checked in case the removal failed due to a directory that
still had files in it. When this specific failure occurs, the
directory is added to a new list for reprocessing removals as it is
expected once the rest of the deletes on the system occur the failures
will go away as the directories will be empty (these deletes are
processed in alphabetical reverse order so leaf directories are
processed first). If the removal fails again it is presumed the
contents of the directory are not files swupd knows about and as such
should be kept somewhere else.

For handling the retention of user data, directories (with only the
content unknown to swupd) are renamed (currently using a
.deleted.$timestamp. prefix of the old name) and stored at the same
directory level they were previously found with one exception. The
exception is for nested deleted content best illustrated with an
example:

/swupd-dir1/user-file1
/swupd-dir1/swupd-dir2/user-file2

When swupd tries to remove the /swupd-dir1 content, it will store the
user files as follows:

/.deleted.$timestamp1.swupd-dir1/user-file1
/.deleted.$timestamp1.swupd-dir1/.deleted.$timestamp1.swupd-dir2/user-file2

To demarcate what was part of swupd content vs user content.

Signed-off-by: William Douglas <[email protected]>
@bryteise bryteise merged commit 02d2765 into master Apr 5, 2024
30 checks passed
@bryteise bryteise deleted the dont-delete-user-content branch April 5, 2024 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants