Golang OpenFile O_APPEND不尊重Seek
发布时间:2020-12-16 09:22:27 所属栏目:大数据 来源:网络整理
导读:当我在这样的模式下打开文件时: file,_ := os.OpenFile("/path/to/my/file",os.O_RDWR|os.O_APPEND,os.FileMode(0666))file.Seek(start,os.SEEK_SET)io.CopyN(file,resp.Body,length) io.CopyN不尊重我寻求的位置.它似乎只是附加到文件的尾部.相反,如果我打
当我在这样的模式下打开文件时:
file,_ := os.OpenFile("/path/to/my/file",os.O_RDWR|os.O_APPEND,os.FileMode(0666)) file.Seek(start,os.SEEK_SET) io.CopyN(file,resp.Body,length) io.CopyN不尊重我寻求的位置.它似乎只是附加到文件的尾部.相反,如果我打开这样的文件: file,os.O_RDWR,length) 它按我的预期工作. io.CopyN从我寻找的“开始”点写入文件.不确定这是一个功能还是一个bug? 解决方法
它绝对是一个功能(
http://man7.org/linux/man-pages/man2/open.2.html),它由底层操作系统控制,而不是golang运行时.
O_APPEND The file is opened in append mode. Before each write(2),the file offset is positioned at the end of the file,as if with lseek(2). O_APPEND may lead to corrupted files on NFS filesystems if more than one process appends data to a file at once. This is because NFS does not support appending to a file,so the client kernel has to simulate it,which can't be done without a race condition. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |