Skip to content

Commit 8f03080

Browse files
committed
App.cmd_tags as Tags, remote set_tags infafor of Snapshot.add_tag
1 parent 81e533c commit 8f03080

3 files changed

Lines changed: 17 additions & 28 deletions

File tree

src/AppConsole.vala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ public class AppConsole : GLib.Object {
210210
break;
211211

212212
case "--tags":
213-
App.cmd_tags = args[++k];
214-
App.validate_cmd_tags();
213+
App.parse_cmd_tags(args[++k]);
215214
break;
216215

217216
case "--debug":

src/Core/Main.vala

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public class Main : GLib.Object{
154154
public bool cmd_verbose = true;
155155
public bool cmd_scripted = false;
156156
public string cmd_comments = "";
157-
public string cmd_tags = "";
157+
public Tags cmd_tags = 0;
158158
public bool? cmd_btrfs_mode = null;
159159

160160
public string progress_text = "";
@@ -1709,7 +1709,7 @@ public class Main : GLib.Object{
17091709
snapshot_path, dt_created, sys_uuid, current_distro.full_name(),
17101710
initial_tags, cmd_comments, fcount, false, false, repo);
17111711

1712-
set_tags(snapshot); // set_tags() will update the control file
1712+
snapshot.add_tag(App.cmd_tags, true); // add_tag() may update the control file
17131713

17141714
// Perform any post-backup actions
17151715
this.run_post_backup_hooks(snapshot_path);
@@ -1802,7 +1802,7 @@ public class Main : GLib.Object{
18021802
}
18031803
snapshot.update_control_file(); // save subvolume info
18041804

1805-
set_tags(snapshot); // set_tags() will update the control file
1805+
snapshot.add_tag(App.cmd_tags, true); // add_tag() may update the control file
18061806

18071807
// Perform any post-backup actions
18081808
this.run_post_backup_hooks(snapshot_path);
@@ -1826,30 +1826,16 @@ public class Main : GLib.Object{
18261826
}
18271827
}
18281828

1829-
private void set_tags(Snapshot snapshot){
1830-
1831-
// add tags passed on commandline for both --check and --create
1832-
1833-
foreach(string tag in cmd_tags.split(",")){
1834-
Tags? parsed = Tags.parse(tag);
1835-
if(parsed != null) {
1836-
snapshot.add_tag(parsed);
1837-
}
1838-
}
1839-
1840-
// add tag as ondemand if no other tag is specified
1841-
1842-
if (snapshot.tags == 0){
1843-
snapshot.add_tag(Tags.OnDemand);
1844-
}
1845-
}
1846-
1847-
public void validate_cmd_tags(){
1848-
foreach(string tag in cmd_tags.split(",")){
1849-
if(Tags.parse(tag) == null) {
1829+
public void parse_cmd_tags(string input_tags){
1830+
App.cmd_tags = 0;
1831+
foreach(string tag in input_tags.split(",")){
1832+
Tags? parsed_tag = Tags.parse(tag);
1833+
if(parsed_tag == null) {
18501834
log_error(_("Unknown value specified for option --tags") + " (%s).".printf(tag));
18511835
log_error(_("Expected values: O, B, H, D, W, M"));
18521836
exit_app(1);
1837+
} else {
1838+
App.cmd_tags |= parsed_tag;
18531839
}
18541840
}
18551841
}

src/Core/Snapshot.vala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,13 @@ public class Snapshot : GLib.Object{
162162
}
163163
}
164164

165-
public void add_tag(Tags tag){
166-
if (!(tag in this.tags)){
165+
/* if at_least_on_demand is true and no tags are set, set Tags.OnDemand */
166+
public void add_tag(Tags tag, bool at_least_on_demand = false){
167+
if (!(tag in this.tags) || at_least_on_demand){
167168
this.tags |= tag;
169+
if (at_least_on_demand && this.tags == 0){
170+
this.tags |= Tags.OnDemand;
171+
}
168172
update_control_file();
169173
}
170174
}

0 commit comments

Comments
 (0)