Test FileUtilities.wipe_path on image or block device For device image, pass device_path and set n_bytes to None. For image, pass n_bytes and set device_path to None.
(fs_type, n_bytes=None, device_path=None, passes=MAX_WIPES, sleep_seconds=5)
| 240 | |
| 241 | @common.skipIfWindows |
| 242 | def wipe_helper(fs_type, n_bytes=None, device_path=None, passes=MAX_WIPES, sleep_seconds=5): |
| 243 | """Test FileUtilities.wipe_path on image or block device |
| 244 | |
| 245 | For device image, pass device_path and set n_bytes to None. |
| 246 | For image, pass n_bytes and set device_path to None. |
| 247 | """ |
| 248 | |
| 249 | assert isinstance(fs_type, str) |
| 250 | assert fs_type in FS_TYPES |
| 251 | |
| 252 | is_device = False |
| 253 | if device_path: |
| 254 | if _is_block_device(device_path): |
| 255 | filename = device_path |
| 256 | else: |
| 257 | raise ValueError(f'Not a block device: {device_path}') |
| 258 | _real_device_warning(device_path, sleep_seconds) |
| 259 | is_device = True |
| 260 | assert n_bytes is None, 'n_bytes must be None when using a block device' |
| 261 | else: |
| 262 | assert isinstance(n_bytes, int) |
| 263 | assert n_bytes > 0 |
| 264 | filename = create_disk_image(n_bytes, fs_type) |
| 265 | logger.debug('created disk image %s', filename) |
| 266 | |
| 267 | for exe in ('strings', 'df'): |
| 268 | if not exe_exists(exe): |
| 269 | raise RuntimeError(f'{exe} not found') |
| 270 | |
| 271 | # format filesystem |
| 272 | format_filesystem(filename, fs_type) |
| 273 | |
| 274 | # mount |
| 275 | mountpoint = tempfile.mkdtemp(prefix='bleachbit-wipe-mountpoint') |
| 276 | mount_filesystem(filename, mountpoint) |
| 277 | |
| 278 | # baseline free disk space |
| 279 | logger.debug('df for clean filesystem %s', mountpoint) |
| 280 | logger.debug(run_external(['df', mountpoint])[1]) |
| 281 | |
| 282 | # make dirty |
| 283 | make_dirty(mountpoint) |
| 284 | |
| 285 | # verify dirtiness (require contents marker; filenames may not be detectable on all FS) |
| 286 | unmount_filesystem(mountpoint) |
| 287 | content_markers_dirty = assert_clean(filename, fs_type, expect_clean=False) |
| 288 | mount_filesystem(filename, mountpoint) |
| 289 | |
| 290 | # standard delete |
| 291 | logger.info('standard delete') |
| 292 | delete_counter = 0 |
| 293 | for secretfile in listdir(mountpoint): |
| 294 | if 'secret' not in secretfile: |
| 295 | # skip lost+found |
| 296 | continue |
| 297 | delete(secretfile, shred=False) |
| 298 | delete_counter += 1 |
| 299 | logger.debug('deleted %s files', f"{delete_counter:,}") |
no test coverage detected