Habr•November 3, 2026•🇷🇺Translated from Russian

How to Avoid Becoming the Hero of 'My Program Deleted 800 GB': Safe Recursive Deletion in Bash and Python

A recent article on Habr explores how seemingly simple recursive deletion code can lead to catastrophic data loss, using the example of Telegram Desktop accidentally cleaning a custom folder and removing around 800 GB of projects and programs.

The author notes that many projects contain cleanup routines for caches, temporary files, or build artifacts that receive minimal review and later fail when variables are empty or unexpected symlinks appear.

Classic pitfalls with empty variables

Well-known incidents include the 2015 Steam Linux client bug where an unset STEAMROOT variable expanded rm -rf "$STEAMROOT/"* into rm -rf "/"*, and the 2011 Bumblebee installer that contained an extra space turning one path into rm -rf /usr /lib/nvidia-current/xorg/xorg.

Hardened Bash practices

The recommended Bash template begins with set -euo pipefail, followed by explicit checks such as ${CACHE_DIR:?CACHE_DIR not set}, double quotes around paths, and the -- separator. Additional safeguards include verifying the target is a real directory (not a symlink), resolving it with realpath, and rejecting paths that match forbidden roots like /, /home, or /usr.

The final deletion step uses find with -mindepth 1 and --one-file-system to avoid crossing mount points while still removing hidden files.

Safe Python implementation

In Python, the article warns that shutil.rmtree has identical risks and introduces a safe_rmtree function that rejects empty paths, symlinks, and targets outside a pre-defined allowed root. It relies on Path.resolve(strict=True) and is_relative_to rather than string prefix checks, and refuses to run on platforms where shutil.rmtree.avoids_symlink_attacks is False.

A dry-run mode and explicit exception handling for read-only files on Windows are also provided.

Practical recommendations

Additional advice includes using tempfile.TemporaryDirectory, leaving marker files in shared cache locations, moving files to a trash directory before final deletion, and always logging operations. The author stresses that deletion code should be reviewed as carefully as any security-sensitive routine because a single unchecked line can destroy all user data.

Related articles

AntiMalware•Other

Hackers tamper with refrigeration units in European supermarkets, setting temperatures to +50 °C

Attackers gained unauthorized access to refrigeration and freezer control systems in supermarkets across several European countries, including Sweden, Belgium, Luxembourg, and Estonia. In multiple locations they altered temperature settings to +50 °C, risking widespread spoilage of perishable goods. The incidents primarily affected older, unpatched Danfoss controllers that had been connected to networks for remote maintenance. Estonian manufacturer Kitman Coldtech reported that one attack on a legacy Danfoss system was detected and stopped within approximately ten minutes, preventing any damage. Similar intrusions were confirmed by Swedish chains ICA and Coop, following earlier incidents in French supermarkets in October that resulted in product losses. Experts note that legacy industrial controllers remain attractive targets because they are often left exposed once placed online for convenience.

Habr•Other

AmneziaWG Container for MikroTik Routers Delivers Top Performance Six Months After Launch

A developer released an AmneziaWG container for MikroTik devices in February 2026 and has since added major improvements in speed, protocol support, and stability. The lightweight container leverages the router's native WireGuard implementation for cryptography while handling AmneziaWG obfuscation in software. Performance now reaches 250-350 Mbit/s on models such as Hap Ax3 and RB5009B after switching to C code and increasing buffer sizes with RouterOS 7.24. New features include server mode for connecting multiple MikroTik devices, random port hopping, IPv6 support, dynamic DNS, and offline configuration. The project survived an early GitHub ban caused by test scripts and has grown to over 370 stars while remaining fully offline and privacy-focused.

Habr•Other

Building Resilient DoH Failover on MikroTik RouterOS to Handle Unreachable Cloudflare Responses

A network administrator encountered a persistent issue in a branch office where pages like Tailwind CSS CDN failed to load despite valid DNS responses from Cloudflare DoH. The problem stemmed from unreachable IP addresses such as 8.6.112.0 and 8.47.69.0 returned by the resolver, which RouterOS treated as healthy because it only checked for valid IP types rather than route reachability. RouterOS supports only a single active DoH upstream via the use-doh-server parameter, requiring custom scripting for failover between multiple endpoints like Cloudflare and dns.google. The solution involved static DNS entries for bootstrap addresses, certificate trust anchors including SSL.com TLS ECC Root CA 2022, and a health monitor script that probes using DNS-JSON API calls instead of switching the resolver directly. Multiple iterations addressed issues like cache-based false positives, plain DNS fallback risks from provider spoofing, and clock validation to prevent certificate failures. The final implementation uses thresholds for failure and recovery to avoid flapping and ensures post-switch verification before committing to a backup endpoint.

Habr•Other

NetRuleRouter Alpha Released to Route Traffic Across Multiple Connections Without Disabling VPN

Developer krox1 has released the first public alpha of NetRuleRouter v0.1.0-alpha.1 for Windows and Linux, a local network policy manager that distributes traffic between primary and secondary connections based on domains, IP ranges, applications, and subnets. The tool emerged from practical issues that intensified after Russian authorities discussed VPN restrictions in March 2026, with operators and platforms later prompting users to disable VPN for domestic services. NetRuleRouter sits on top of existing connections rather than acting as a VPN client or proxy, allowing users to keep corporate VPNs, personal VPNs, and direct internet active simultaneously. It supports seven matching methods including exact domains, wildcard subdomains, CIDR ranges, and application paths, with priority rules to resolve overlaps and built-in leak protection that prevents protected destinations from falling back when the secondary connection drops. The alpha includes diagnostic tracing, preset rule sets for Russia and other regions, import/export capabilities, and a first-run wizard that configures the background service and initial bindings. Limitations around DNS, shared IPs, and brief startup windows are documented, and the project explicitly does not protect against account-level blocks by services such as Anthropic.