Skip to content

Commit

Permalink
refactor: ensure have permission to delete the file
Browse files Browse the repository at this point in the history
Signed-off-by: loonghao <[email protected]>
  • Loading branch information
loonghao committed May 19, 2024
1 parent f870ea1 commit be3b0ad
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
7 changes: 7 additions & 0 deletions maya_umbrella/cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class MayaVirusCleaner(object):
translator (Translator): Translator object for translation purposes.
collector (MayaVirusCollector): MayaVirusCollector object for collecting issues.
"""

def __init__(self, collector, logger=None):
"""Initialize the MayaVirusCleaner.
Expand Down Expand Up @@ -50,6 +51,9 @@ def fix_script_jobs(self):
def fix_malicious_files(self):
"""Fix malicious files."""
for file_ in self.collector.malicious_files:
if not os.access(file_, os.W_OK):
self.logger.debug(self.translator.translate("file_not_writable", name=file_))
continue
if os.path.exists(file_):
if os.path.isfile(file_):
self.logger.debug(self.translator.translate("remove_file", name=file_))
Expand Down Expand Up @@ -94,6 +98,9 @@ def fix_infected_files(self):
"""Fix infected files."""
for file_path in self.collector.infected_files:
self.logger.info(self.translator.translate("fix_infected_files", name=file_path))
if not os.access(file_path, os.W_OK):
self.logger.debug(self.translator.translate("file_not_writable", name=file_path))
continue
remove_virus_file_by_signature(file_path, FILE_VIRUS_SIGNATURES)
self.collector.remove_infected_file(file_path)

Expand Down
3 changes: 2 additions & 1 deletion maya_umbrella/locales/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"delete": "Deleting: $name",
"remove_file": "Deleting file:$name",
"remove_path": "Deleting path:$name",
"fix_script_job": "Kill script job: %s"
"fix_script_job": "Kill script job: %s",
"file_not_writable": "File not writable: $name"
}
3 changes: 2 additions & 1 deletion maya_umbrella/locales/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"delete": "删除感染文件:$name",
"remove_file": "删除文件:$name",
"remove_path": "删除文件夹:$name",
"fix_script_job": "删除被感染的节点:$name"
"fix_script_job": "删除被感染的节点:$name",
"file_not_writable": "文件不可写:$name"
}

0 comments on commit be3b0ad

Please sign in to comment.