Get the latest tech news

Create space-saving clones on macOS with Python


You can shell out to `cp -c` using `subprocess`, or you can make a `clonefile()` syscall using the `ctypes` library.

APFS uses a technique called copy-on-write to store the data efficiently on disk – the cloned files continue to share any pieces they have in common. In my project, I wrapped this cp call in a function which had some additional checks to spot common types of error, and throw them as more specific exceptions. The exception includes the numeric error code, and Python will throw named subclasses of OSError like FileNotFoundError, FileExistsError, or PermissionError.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Space

Space

Photo of macOS

macOS

Photo of python

python

Related news:

News photo

Rust, Python, and TypeScript: the new trifecta

News photo

Lamport's Byzantine Generals Algorithm in Python

News photo

Python-powered malware snags hundreds of credit cards, 200K passwords, and 4M cookies