|
8 | 8 | import re |
9 | 9 | import sys |
10 | 10 | import bz2 |
11 | | -import pathlib |
12 | 11 | import requests |
| 12 | +from pathlib import Path |
13 | 13 |
|
14 | 14 | from intelmq import VAR_STATE_PATH |
15 | 15 | from intelmq.lib.bot import ExpertBot |
@@ -41,6 +41,8 @@ def init(self): |
41 | 41 | self.logger.error("Read 'bots/experts/asn_lookup/README' and " |
42 | 42 | "follow the procedure.") |
43 | 43 | self.stop() |
| 44 | + if not Path(self.database).is_file: |
| 45 | + raise ValueError('Database file does not exist or is not a file.') |
44 | 46 |
|
45 | 47 | def process(self): |
46 | 48 | event = self.receive_message() |
@@ -113,6 +115,12 @@ def update_database(cls, verbose=False): |
113 | 115 | if pyasn is None: |
114 | 116 | raise MissingDependencyError("pyasn") |
115 | 117 |
|
| 118 | + for database_path in set(bots.values()): |
| 119 | + if not Path(database_path).is_file: |
| 120 | + raise ValueError('Database file does not exist or is not a file.') |
| 121 | + elif not os.access(database_path, os.W_OK): |
| 122 | + raise ValueError('Database file is not writeable.') |
| 123 | + |
116 | 124 | try: |
117 | 125 | if verbose: |
118 | 126 | print("Searching for the latest database update...") |
@@ -160,7 +168,7 @@ def update_database(cls, verbose=False): |
160 | 168 | prefixes = pyasn.mrtx.parse_mrt_file(archive, print_progress=False, skip_record_on_error=True) |
161 | 169 |
|
162 | 170 | for database_path in set(bots.values()): |
163 | | - database_dir = pathlib.Path(database_path).parent |
| 171 | + database_dir = Path(database_path).parent |
164 | 172 | database_dir.mkdir(parents=True, exist_ok=True) |
165 | 173 | pyasn.mrtx.dump_prefixes_to_file(prefixes, database_path) |
166 | 174 |
|
|
0 commit comments