Skip to content

Commit d894b47

Browse files
[Spyre] To replace udev rules into the config file rather than to append
problem: servicereport appends the new udev rule into config file rather than overwriting exisiting rule. fix: Modified the method to overwrite udev rules in spyre repair plugin, which ensures truncation of old rule and add the new rule. Signed-off-by: sahithi Ravindranath <[email protected]>
1 parent addc29e commit d894b47

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

servicereportpkg/repair/plugins/spyre_repair.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from servicereportpkg.check import Notes
1616
from servicereportpkg.utils import append_to_file
17+
from servicereportpkg.utils import add_to_file
1718
from servicereportpkg.utils import execute_command
1819
from servicereportpkg.utils import install_package
1920
from servicereportpkg.repair.plugins import RepairPlugin
@@ -62,7 +63,7 @@ def fix_udev_rules_conf(self, plugin_obj, udev_rules_conf_check):
6263

6364
for config, val in udev_rules_conf_check.get_config_attributes().items():
6465
if not val["status"]:
65-
append_to_file(udev_rules_conf_check.get_file_path(),
66+
add_to_file(udev_rules_conf_check.get_file_path(),
6667
"\n"+config)
6768
re_check = plugin_obj.check_udev_rule()
6869
if re_check.get_status():

servicereportpkg/utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,3 +448,17 @@ def append_to_file(file_path, s):
448448
except Exception as e:
449449
log.debug("Failed to open file: %s, error: %s", file_path, e)
450450
return False
451+
452+
def add_to_file(file_path, s):
453+
"""Add the given stirng to the file"""
454+
455+
log = get_default_logger()
456+
457+
try:
458+
with open(file_path, "w", encoding="utf-8") as file:
459+
file.write(s)
460+
461+
return True
462+
except Exception as e:
463+
log.debug("Failed to open file: %s, error: %s", file_path, e)
464+
return False

0 commit comments

Comments
 (0)