|
22 | 22 | DEFAULT_BANNED_PORTS = "9050,9051,9150,9151" |
23 | 23 | GECKO_DRIVER_EXE_PATH = shutil.which("geckodriver") |
24 | 24 |
|
25 | | -import os, stat |
26 | | -def get_perm(path): |
27 | | - return stat.S_IMODE(os.lstat(path)[stat.ST_MODE]) |
28 | | - #return os.stat(path).st_mode # ? |
29 | | - |
30 | | -# https://stackoverflow.com/a/6878204/10440128 |
31 | | -def make_writeable_recursive(path): |
32 | | - os.chmod(path, get_perm(path) | os.ST_WRITE) |
33 | | - for root, dirs, files in os.walk(path, topdown=False): |
34 | | - for dir in [os.path.join(root, d) for d in dirs]: |
35 | | - os.chmod(dir, get_perm(dir) | os.ST_WRITE) |
36 | | - for file in [os.path.join(root, f) for f in files]: |
37 | | - os.chmod(file, get_perm(file) | os.ST_WRITE) |
38 | | - |
39 | 25 | class TorBrowserDriver(FirefoxDriver): |
40 | 26 | """ |
41 | 27 | Extend Firefox webdriver to automate Tor Browser. |
@@ -241,16 +227,18 @@ def setup_tbb_paths(self, tbb_browser_dir, tbb_path, tbb_fx_binary_path, |
241 | 227 | # if not isdir(tor_data_dir): |
242 | 228 | # raise TBDriverPathError("Invalid Tor data directory %s" % tor_data_dir) |
243 | 229 |
|
244 | | - # tor_data_dir must be writable |
| 230 | + # tbb_browser_dir must be writable, but its contents can be read-only |
245 | 231 | # fix: Your Tor Browser profile cannot be loaded. It may be missing or inaccessible. |
246 | | - if not os.access(tor_data_dir, os.W_OK): |
247 | | - temp_tor_data_dir = tempfile.mkdtemp(prefix="tbselenium-tor_data_dir-") |
248 | | - # print(f"not writable tor_data_dir {tor_data_dir} - using tempdir {temp_tor_data_dir}") |
249 | | - self.remove_on_exit.append(temp_tor_data_dir) |
250 | | - # copy the contents of tor_data_dir and make them writable |
251 | | - shutil.copytree(tor_data_dir, temp_tor_data_dir, dirs_exist_ok=True) |
252 | | - make_writeable_recursive(temp_tor_data_dir) |
253 | | - tor_data_dir = temp_tor_data_dir |
| 232 | + if not os.access(tbb_browser_dir, os.W_OK): |
| 233 | + temp_tbb_browser_dir = tempfile.mkdtemp(prefix="tbselenium-tbb_browser_dir-") |
| 234 | + # print(f"not writable tbb_browser_dir {tbb_browser_dir} - using tempdir {temp_tbb_browser_dir}") |
| 235 | + self.remove_on_exit.append(temp_tbb_browser_dir) |
| 236 | + # symlink the contents of tbb_browser_dir |
| 237 | + for name in os.listdir(tbb_browser_dir): |
| 238 | + src = tbb_browser_dir + "/" + name |
| 239 | + dst = temp_tbb_browser_dir + "/" + name |
| 240 | + os.symlink(src, dst, target_is_directory=os.path.isdir(src)) |
| 241 | + tbb_browser_dir = temp_tbb_browser_dir |
254 | 242 |
|
255 | 243 | #self.tbb_path = abspath(tbb_path) |
256 | 244 | self.tbb_browser_dir = abspath(tbb_browser_dir) |
|
0 commit comments