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

Problem with file operation on windows #54

Closed
xpunch opened this issue Apr 14, 2021 · 1 comment
Closed

Problem with file operation on windows #54

xpunch opened this issue Apr 14, 2021 · 1 comment

Comments

@xpunch
Copy link

xpunch commented Apr 14, 2021

package main

import (
	"io/ioutil"
	"os"

	"github.com/gofrs/flock"
)

func main() {
	file := "test.txt"
	lock := flock.New(file)
	if err := lock.Lock(); err != nil {
		panic(err)
	}
	defer lock.Unlock()

	f, err := os.Open(file)
	if err != nil {
		panic(err)
	}
	_, err = ioutil.ReadAll(f)
	if err != nil {
		panic(err)
	}
}
panic: read test.txt: The process cannot access the file because another process has locked a portion of the file.

goroutine 1 [running]:
main.main()
        C:/github/fslock/main.go:24 +0x16b
exit status 2
@xpunch
Copy link
Author

xpunch commented Jun 24, 2021

Should use RLock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants