31 lines
618 B
Python
31 lines
618 B
Python
import os
|
|
import shutil
|
|
from pathlib import Path
|
|
|
|
|
|
def is_btrfs(path):
|
|
try:
|
|
import subprocess
|
|
out = subprocess.check_output(["stat", "-f", "-c", "%T", path]).decode()
|
|
return "btrfs" in out.lower()
|
|
except:
|
|
return False
|
|
|
|
|
|
def store_reflink(src, dst):
|
|
"""
|
|
Fast copy using CoW if supported
|
|
"""
|
|
try:
|
|
shutil.copy2(src, dst, follow_symlinks=True)
|
|
except Exception:
|
|
shutil.copy(src, dst)
|
|
|
|
|
|
def cas_path(config, key):
|
|
base = Path(config["btrfs_path"])
|
|
path = base / key
|
|
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
return str(path)
|