2014-02-05 1 views
3

탐색 존중하지 않습니다. 그것은 단지 파일의 꼬리에 추가하는 것 같습니다. 대신이 파일을 여는 경우 :Golang OpenFile O_APPEND는이 같은 모드에서 파일을 열 때

file, _ := os.OpenFile("/path/to/my/file", os.O_RDWR, os.FileMode(0666)) 
file.Seek(start, os.SEEK_SET) 
io.CopyN(file, resp.Body, length) 

예상대로 작동합니다. io.CopyN은 내가 찾은 "시작"지점에서 파일에 기록합니다. 이것이 기능 또는 버그인지 확실하지 않습니까?

답변

10

확실히 기능 (http://man7.org/linux/man-pages/man2/open.2.html)이며 golang 런타임이 아닌 기본 OS에 의해 제어됩니다.

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.