MCPcopy Create free account
hub / github.com/bleachbit/bleachbit / wipe_swap_linux

Function wipe_swap_linux

bleachbit/Memory.py:269–299  ·  view source on GitHub ↗

Shred the Linux swap file and then reinitialize it

(devices, proc_swaps)

Source from the content-addressed store, hash-verified

267
268
269def wipe_swap_linux(devices, proc_swaps):
270 """Shred the Linux swap file and then reinitialize it"""
271 if devices is None:
272 return
273 if 0 < count_swap_linux():
274 raise RuntimeError('Cannot wipe swap while it is in use')
275 for device in devices:
276 # if '/cryptswap' in device:
277 # logger.info('Skipping encrypted swap device %s.', device)
278 # continue
279 # TRANSLATORS: The variable is a device like /dev/sda2
280 logger.info(_("Wiping the swap device %s."), device)
281 safety_limit_bytes = 29 * 1024 ** 3 # 29 gibibytes
282 actual_size_bytes = get_swap_size_linux(device, proc_swaps)
283 if actual_size_bytes > safety_limit_bytes:
284 raise RuntimeError(
285 f'swap device {device} is larger ({actual_size_bytes})'
286 f' than expected ({safety_limit_bytes})')
287 uuid = get_swap_uuid(device)
288 # wipe
289 wipe_contents(device, truncate=False)
290 # reinitialize
291 # TRANSLATORS: The variable is a device like /dev/sda2
292 logger.debug(_("Reinitializing the swap device %s."), device)
293 args = ['mkswap', device]
294 if uuid:
295 args.append("-U")
296 args.append(uuid)
297 (rc, _stdout, stderr) = General.run_external(args)
298 if 0 != rc:
299 raise RuntimeError(stderr.replace("\n", ""))
300
301
302def wipe_memory():

Callers 1

wipe_memoryFunction · 0.85

Calls 4

wipe_contentsFunction · 0.90
count_swap_linuxFunction · 0.85
get_swap_size_linuxFunction · 0.85
get_swap_uuidFunction · 0.85

Tested by

no test coverage detected