Skip to content

Commit

Permalink
suricatals: no error message for new files
Browse files Browse the repository at this point in the history
  • Loading branch information
regit committed Feb 17, 2024
1 parent 491a4cb commit 234a22f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion suricatals/langserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,16 @@ def update_workspace_file(self, filepath, read_file=False, allow_empty=False):
file_obj = self.workspace.get(filepath)
if read_file:
if file_obj is None:
file_obj = SuricataFile(filepath, self.rules_tester)
# Create empty file if not yet saved to disk
if not os.path.isfile(filepath):
file_obj = SuricataFile(filepath, self.rules_tester, empty=True)
if allow_empty:
self.workspace[filepath] = file_obj
return False, None
else:
return False, 'File does not exist' # Error during load
else:
file_obj = SuricataFile(filepath, self.rules_tester)
hash_old = file_obj.hash
err_string = None
if os.path.isfile(filepath):
Expand Down
5 changes: 3 additions & 2 deletions suricatals/parse_signatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class SuricataFile:
IS_COMMENT = re.compile(r"[ \t]*#")
GET_MULTILINES = re.compile(r"\\ *$")

def __init__(self, path, rules_tester):
def __init__(self, path, rules_tester, empty=False):
self.path = path
self.rules_tester = rules_tester
self.contents_split = []
Expand All @@ -191,7 +191,8 @@ def __init__(self, path, rules_tester):
self.hash = None
self.mpm = {}
self.diagnosis = None
self.count_lines()
if not empty:
self.count_lines()

def count_lines(self):
with open(self.path, 'r', encoding='utf-8', errors='replace') as fhandle:
Expand Down

0 comments on commit 234a22f

Please sign in to comment.