Metadata-Version: 2.4
Name: clonefile
Version: 1.4.1
Summary: Copy-on-write clones of files and directories, on macOS (APFS) and on Linux filesystems with reflinks (XFS, Btrfs)
Author-email: Gabriel Meola <banter@gabe.mx>
License-Expression: MPL-2.0
Keywords: apfs,btrfs,clone,copy-on-write,reflink,snapshot,xfs
Project-URL: Homepage, https://github.com/sprisa/clonetree/tree/main/lib/python/clonefile
Project-URL: Source, https://github.com/sprisa/clonetree
Project-URL: Issues, https://github.com/sprisa/clonetree/issues
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: System :: Filesystems
Classifier: Typing :: Typed
Requires-Python: >=3.11
Description-Content-Type: text/markdown

# clonefile

Copy-on-write clones of files and directories, on macOS (APFS) and Linux (XFS
and Btrfs). A clone shares the original's data on disk, so it's fast to make,
and takes no new space until either copy changes.

It's the library behind the [clonetree](https://github.com/sprisa/clonetree)
CLI's clones. For whole-project snapshots, see
[`clonetree`](https://pypi.org/project/clonetree/).

```sh
pip install clonefile
```

```python
import clonefile

# Clone a file, or a directory with everything in it.
clonefile.clone("src", "src-copy")
```

- It never copies data. If the filesystem can't clone, it raises.
- It never replaces anything. The destination must not exist, but its parent
  must.
- If it fails partway, it removes what it created.
- Other Python threads keep running while it clones.

## Errors

`clone` raises `clonefile.Error`, an `OSError` whose `code` says why, such as
`"PathAlreadyExists"` or `"OperationUnsupported"`. Its `errno` is the closest
errno, such as `errno.EEXIST`, where there is one. The type hints list every
code.

```python
try:
    clonefile.clone("src", "src-copy")
except clonefile.Error as err:
    if err.code != "PathAlreadyExists":
        raise
    print("src-copy is already there")
```

## Requirements

- macOS with APFS, or Linux with XFS (with reflinks) or Btrfs. The source and
  the clone must be on the same filesystem.
- x86_64 or arm64. On Linux, glibc 2.28 or later, or musl.
- Python 3.11 or later.

pip installs the wheel for your platform, which includes the compiled library,
so it needs no build tools, and the package has no dependencies. On other
platforms, `clone` raises `clonefile.Error` with code `"OperationUnsupported"`.

## Documentation

- [The docstrings](https://github.com/sprisa/clonetree/blob/main/lib/python/clonefile/clonefile/__init__.py)
  document what a clone keeps on each platform, and every error.
- [The library from Go, Zig, Rust and Node](https://github.com/sprisa/clonetree/tree/main/lib)

<img src="https://pl.sprisa.com/Asts1wWV5" alt="" width="1" height="1">
