فهرست منبع

Remove uselsess ReadOnly params

Viktor Sokolov 3 ماه پیش
والد
کامیت
35157c6d9d
5فایلهای تغییر یافته به همراه29 افزوده شده و 15 حذف شده
  1. 26 5
      asyncbuffer/buffer.go
  2. 0 2
      storage/abs/config.go
  3. 3 5
      storage/fs/config.go
  4. 0 2
      storage/s3/config.go
  5. 0 1
      storage/swift/config.go

+ 26 - 5
asyncbuffer/buffer.go

@@ -97,6 +97,30 @@ func New(r io.ReadCloser, dataLen int, finishFn ...context.CancelFunc) *AsyncBuf
 	return ab
 }
 
+// NewReadFull creates a new AsyncBuffer that reads from the given io.ReadCloser
+// in foreground, blocking until all data is read. It returns an error if reading
+// fails. When read fails, the reader is closed and resources are released immediately.
+func NewReadFull(r io.ReadCloser, dataLen int, finishFn ...context.CancelFunc) (*AsyncBuffer, error) {
+	ab := &AsyncBuffer{
+		r:         r,
+		dataLen:   dataLen,
+		paused:    NewLatch(),
+		chunkCond: NewCond(),
+		finishFn:  finishFn,
+	}
+
+	// Read all data in foreground
+	ab.readChunks()
+
+	// If error occurred during reading, return it
+	if ab.Error() != nil {
+		ab.Close() // Reader should be closed and resources released
+		return nil, ab.Error()
+	}
+
+	return ab, nil
+}
+
 // callFinishFn calls the finish functions registered with the AsyncBuffer.
 func (ab *AsyncBuffer) callFinishFn() {
 	ab.finishOnce.Do(func() {
@@ -428,17 +452,14 @@ func (ab *AsyncBuffer) readAt(p []byte, off int64) (int, error) {
 	return n, nil
 }
 
-// Close closes the AsyncBuffer and releases all resources.
-// It returns an error if the reader was already closed or if there was
-// an error during reading data in background even if none of the subsequent
-// readers have reached the position where the error occurred.
+// Close closes the AsyncBuffer and releases all resources. It is idempotent.
 func (ab *AsyncBuffer) Close() error {
 	ab.mu.Lock()
 	defer ab.mu.Unlock()
 
 	// If the reader is already closed, we return immediately error or nil
 	if ab.closed.Load() {
-		return ab.Error()
+		return nil
 	}
 
 	ab.closed.Store(true)

+ 0 - 2
storage/abs/config.go

@@ -22,7 +22,6 @@ type Config struct {
 	Name           string   // Azure storage account name
 	Endpoint       string   // Azure Blob Storage endpoint URL
 	Key            string   // Azure storage account key
-	ReadOnly       bool     // Read-only access
 	AllowedBuckets []string // List of allowed buckets (containers)
 	DeniedBuckets  []string // List of denied buckets (containers)
 	desc           ConfigDesc
@@ -34,7 +33,6 @@ func NewDefaultConfig() Config {
 		Name:           "",
 		Endpoint:       "",
 		Key:            "",
-		ReadOnly:       true,
 		AllowedBuckets: nil,
 		DeniedBuckets:  nil,
 	}

+ 3 - 5
storage/fs/config.go

@@ -17,16 +17,14 @@ type ConfigDesc struct {
 
 // Config holds the configuration for local file system transport
 type Config struct {
-	Root     string // Root directory for the local file system transport
-	ReadOnly bool   // Read-only access
-	desc     ConfigDesc
+	Root string // Root directory for the local file system transport
+	desc ConfigDesc
 }
 
 // NewDefaultConfig returns a new default configuration for local file system transport
 func NewDefaultConfig() Config {
 	return Config{
-		Root:     "",
-		ReadOnly: true,
+		Root: "",
 	}
 }
 

+ 0 - 2
storage/s3/config.go

@@ -27,7 +27,6 @@ type Config struct {
 	AssumeRoleArn           string   // ARN for assuming an AWS role (default: "")
 	AssumeRoleExternalID    string   // External ID for assuming an AWS role (default: "")
 	DecryptionClientEnabled bool     // Enables S3 decryption client (default: false)
-	ReadOnly                bool     // Read-only access
 	AllowedBuckets          []string // List of allowed buckets (containers)
 	DeniedBuckets           []string // List of denied buckets (containers)
 	desc                    ConfigDesc
@@ -42,7 +41,6 @@ func NewDefaultConfig() Config {
 		AssumeRoleArn:           "",
 		AssumeRoleExternalID:    "",
 		DecryptionClientEnabled: false,
-		ReadOnly:                true,
 		AllowedBuckets:          nil,
 		DeniedBuckets:           nil,
 	}

+ 0 - 1
storage/swift/config.go

@@ -32,7 +32,6 @@ type Config struct {
 	AuthVersion    int           // Authentication version for Swift
 	ConnectTimeout time.Duration // Connection timeout for Swift
 	Timeout        time.Duration // Request timeout for Swift
-	ReadOnly       bool          // Read-only access
 	AllowedBuckets []string      // List of allowed buckets (containers)
 	DeniedBuckets  []string      // List of denied buckets (containers)
 	desc           ConfigDesc