@@ -37,18 +37,18 @@ import (
3737// If Lock returns nil, no other process will be able to place a read or write lock on the file until
3838// this process exits, closes f, or calls Unlock on it.
3939func Lock (path string ) (file * os.File , err error ) {
40- return commonlock (path , writeLock , false )
40+ return commonlock (path , writeLock )
4141}
4242
4343// ReadOnlyLock places an advisory read lock on the file, blocking until it can be locked.
4444//
4545// If ReadOnlyLock returns nil, no other process will be able to place a write lock on
4646// the file until this process exits, closes f, or calls Unlock on it.
4747func ReadOnlyLock (path string ) (file * os.File , err error ) {
48- return commonlock (path , readLock , false )
48+ return commonlock (path , readLock )
4949}
5050
51- func commonlock (path string , mode lockType , appendMode bool ) (file * os.File , err error ) {
51+ func commonlock (path string , mode lockType ) (file * os.File , err error ) {
5252 defer func () {
5353 if err != nil {
5454 err = errors .Join (ErrLockFail , err , file .Close ())
@@ -65,21 +65,12 @@ func commonlock(path string, mode lockType, appendMode bool) (file *os.File, err
6565 }
6666 }
6767
68- // For append mode, open with specific flags
69- if appendMode {
70- file , err = os .OpenFile (path , os .O_WRONLY , privateFilePermission )
71- if err != nil {
72- return nil , err
73- }
74- } else {
75- // Preserve the original behavior for non-append operations
76- file , err = os .Open (path )
77- if errors .Is (err , os .ErrNotExist ) {
78- file , err = os .OpenFile (path , os .O_RDONLY | os .O_CREATE , privateFilePermission )
79- }
80- if err != nil {
81- return nil , err
82- }
68+ file , err = os .Open (path )
69+ if errors .Is (err , os .ErrNotExist ) {
70+ file , err = os .OpenFile (path , os .O_RDONLY | os .O_CREATE , privateFilePermission )
71+ }
72+ if err != nil {
73+ return nil , err
8374 }
8475
8576 if err = platformSpecificLock (file , mode ); err != nil {
@@ -131,17 +122,3 @@ func WithReadOnlyLock(path string, function func() error) (err error) {
131122
132123 return function ()
133124}
134-
135- // WithAppendLock executes the function with a file opened in append mode
136- func WithAppendLock (path string , function func (file * os.File ) error ) (err error ) {
137- file , err := commonlock (path , writeLock , true )
138- if err != nil {
139- return err
140- }
141-
142- defer func () {
143- err = errors .Join (Unlock (file ), err )
144- }()
145-
146- return function (file )
147- }
0 commit comments