@@ -37,18 +37,18 @@ import (
37
37
// If Lock returns nil, no other process will be able to place a read or write lock on the file until
38
38
// this process exits, closes f, or calls Unlock on it.
39
39
func Lock (path string ) (file * os.File , err error ) {
40
- return commonlock (path , writeLock , false )
40
+ return commonlock (path , writeLock )
41
41
}
42
42
43
43
// ReadOnlyLock places an advisory read lock on the file, blocking until it can be locked.
44
44
//
45
45
// If ReadOnlyLock returns nil, no other process will be able to place a write lock on
46
46
// the file until this process exits, closes f, or calls Unlock on it.
47
47
func ReadOnlyLock (path string ) (file * os.File , err error ) {
48
- return commonlock (path , readLock , false )
48
+ return commonlock (path , readLock )
49
49
}
50
50
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 ) {
52
52
defer func () {
53
53
if err != nil {
54
54
err = errors .Join (ErrLockFail , err , file .Close ())
@@ -65,21 +65,12 @@ func commonlock(path string, mode lockType, appendMode bool) (file *os.File, err
65
65
}
66
66
}
67
67
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
83
74
}
84
75
85
76
if err = platformSpecificLock (file , mode ); err != nil {
@@ -131,17 +122,3 @@ func WithReadOnlyLock(path string, function func() error) (err error) {
131
122
132
123
return function ()
133
124
}
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