Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflink(Copy On Write)支持 #38

Closed
tksmly opened this issue Mar 23, 2023 · 3 comments
Closed

Reflink(Copy On Write)支持 #38

tksmly opened this issue Mar 23, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@tksmly
Copy link
Contributor

tksmly commented Mar 23, 2023

https://btrfs.readthedocs.io/en/latest/Reflink.html
https://docs.python.org/dev/library/os.html#os.copy_file_range
对btrfs,xfs,zfs等支持cow的文件系统可以大幅度缩短复制时间
https://docs.python.org/zh-cn/3/library/shutil.html#shutil.copy
似乎shutil.copy并不支持这一特性

在我的存档中,cp -r --reflink耗时不到1s,而cp -r --reflink=never需要60s左右

@tksmly
Copy link
Contributor Author

tksmly commented Mar 23, 2023

def cpcow(src_path, dst_path):
    if os.path.isfile(src_path):
        f11 = open(src_path,'r')
        f1 = f11.fileno()
        f21 = open(dst_path,'w+')
        f2 = f21.fileno()
        os.copy_file_range(f1, f2, os.path.getsize(src_path))
    elif os.path.isdir(src_path):
        os.makedirs(dst_path)
        for ww in os.listdir(src_path):
            cpcow(src_path+ "/" + ww,dst_path + "/" +ww)
    
t1 = time.time()
cpcow("/home/tksmly/Downloads/world", "./ww")
print(time.time() - t1)

没有原生的目录复制
大概长这样?

@tksmly
Copy link
Contributor Author

tksmly commented Mar 23, 2023

#39

@Fallen-Breath Fallen-Breath added the enhancement New feature or request label Apr 7, 2023
@Fallen-Breath
Copy link
Collaborator

closed as the PR is merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants