github.com/TeaOSLab/EdgeNode@v1.3.8/internal/utils/fs/os.go (about)

     1  // Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
     2  
     3  package fsutils
     4  
     5  import (
     6  	"os"
     7  )
     8  
     9  func Remove(filename string) (err error) {
    10  	WriterLimiter.Ack()
    11  	err = os.Remove(filename)
    12  	WriterLimiter.Release()
    13  	return
    14  }
    15  
    16  func Rename(oldPath string, newPath string) (err error) {
    17  	WriterLimiter.Ack()
    18  	err = os.Rename(oldPath, newPath)
    19  	WriterLimiter.Release()
    20  	return
    21  }
    22  
    23  func ReadFile(filename string) (data []byte, err error) {
    24  	ReaderLimiter.Ack()
    25  	data, err = os.ReadFile(filename)
    26  	ReaderLimiter.Release()
    27  	return
    28  }
    29  
    30  func WriteFile(filename string, data []byte, perm os.FileMode) (err error) {
    31  	WriterLimiter.Ack()
    32  	err = os.WriteFile(filename, data, perm)
    33  	WriterLimiter.Release()
    34  	return
    35  }
    36  
    37  func OpenFile(name string, flag int, perm os.FileMode) (f *os.File, err error) {
    38  	if flag&os.O_RDONLY == os.O_RDONLY {
    39  		ReaderLimiter.Ack()
    40  	}
    41  
    42  	f, err = os.OpenFile(name, flag, perm)
    43  
    44  	if flag&os.O_RDONLY == os.O_RDONLY {
    45  		ReaderLimiter.Release()
    46  	}
    47  
    48  	return
    49  }
    50  
    51  func Open(name string) (f *os.File, err error) {
    52  	ReaderLimiter.Ack()
    53  	f, err = os.Open(name)
    54  	ReaderLimiter.Release()
    55  	return
    56  }