124 {
125
129 }
130 else if (
name ==
"@home"){
132 }
133 }
134
135 string cmd = "";
136 string std_out, std_err, subpath;
137 int ret_val;
138
140
141 log_msg(
"%s: %s (Id:%ld)".printf(
_(
"Deleting subvolume"),
name,
id));
142
143
144 string options = App.use_option_raw ? "--commit-after" : "";
145
146 if (Main.btrfs_version__can_recursive_delete) {
147 options += " --recursive";
148 }
149
152 int rc_show =
exec_sync(
"btrfs subvolume show '%s'".printf(subpath), out std_out, out std_err);
153 if (rc_show == 0) {
154
155 cmd = "btrfs subvolume delete %s '%s'".printf(options, subpath);
156 log_debug(
"Deleting nested subvolume in snapshot");
158 ret_val =
exec_sync(cmd, out std_out, out std_err);
159 if (ret_val != 0){
161 log_error(
_(
"Failed to delete snapshot nested subvolume") +
": '%s'".printf(subpath));
162 return false;
163 }
164 } else {
165
166 log_debug(
"Nested path exists but is not a btrfs subvolume, skipping: %s".printf(subpath));
167 }
168 }
169
170 cmd =
"btrfs subvolume delete %s '%s'".printf(options,
path);
172 ret_val =
exec_sync(cmd, out std_out, out std_err);
173 if (ret_val != 0){
175 log_error(
_(
"Failed to delete snapshot subvolume") +
": '%s'".printf(
path));
176 return false;
177 }
178
179 log_msg(
"%s: %s (Id:%ld)\n".printf(
_(
"Deleted subvolume"),
name,
id));
180
182 if ((
id > 0) && (
repo !=
null)){
183
184 log_debug(
"Waiting on btrfs to finish deleting...");
185 while (
exec_sync(
"btrfs subvolume sync %s".printf(
mount_path), out std_out, out std_err) != 0) {
186 log_debug(
"Still waiting for btrfs to finish deleting... %s".printf(std_err));
188 }
189
191 while (
exec_sync(
"btrfs quota rescan %s".printf(
mount_path), out std_out, out std_err) != 0) {
192 log_debug(
"Still rescanning quotas... %s".printf(std_err));
194 }
195
196
197
198 string qgroup_id = "0/%ld".printf(id);
201 ret_val =
exec_sync(cmd, out std_out, out std_err);
202
203 bool qgroup_exists = (ret_val == 0) && (std_out.contains(qgroup_id));
204
205 if (!qgroup_exists) {
206 log_debug(
"Qgroup %s already removed (auto-destroyed with subvolume)".printf(qgroup_id));
207 } else {
208 log_msg(
"%s: %s".printf(
_(
"Destroying qgroup"), qgroup_id));
209
212 ret_val =
exec_sync(cmd, out std_out, out std_err);
213 if (ret_val != 0){
214
215 log_debug(
"Qgroup %s could not be destroyed (likely already removed): %s".printf(qgroup_id, std_err));
216 } else {
217 log_msg(
"%s: %s\n".printf(
_(
"Destroyed qgroup"), qgroup_id));
218 }
219 }
220
221 log_debug(
"Rescanning quotas (post)...");
222 while (
exec_sync(
"btrfs quota rescan %s".printf(
mount_path), out std_out, out std_err) != 0) {
223 log_debug(
"Still rescanning quotas (post)... %s".printf(std_err));
225 }
226
228 while (
exec_sync(
"btrfs subvolume sync %s".printf(
mount_path), out std_out, out std_err) != 0) {
229 log_debug(
"Still syncing (post)... %s".printf(std_err));
231 }
232
233 }
234 }
235
236 return true;
237 }
bool btrfs_qgroups_enabled
bool dir_exists(string dir_path)
void log_error(string message, bool highlight=false, bool is_warning=false)
void log_msg(string message, bool highlight=false)
int exec_sync(string cmd, out string? std_out=null, out string? std_err=null)
void sleep(int milliseconds)