From f119690ab7b9b008e937628c4568c3b9df344689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Thu, 28 Mar 2024 08:52:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=87=E4=BB=B6=E5=8F=A5?= =?UTF-8?q?=E6=9F=84=E7=BC=93=E5=AD=98=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/caches/open_file_cache.go | 6 ++++++ internal/caches/storage_file.go | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/internal/caches/open_file_cache.go b/internal/caches/open_file_cache.go index 3b0be13..7a8a88a 100644 --- a/internal/caches/open_file_cache.go +++ b/internal/caches/open_file_cache.go @@ -64,6 +64,8 @@ func NewOpenFileCache(maxCount int) (*OpenFileCache, error) { } func (this *OpenFileCache) Get(filename string) *OpenFile { + filename = filepath.Clean(filename) + this.locker.RLock() pool, ok := this.poolMap[filename] this.locker.RUnlock() @@ -85,6 +87,8 @@ func (this *OpenFileCache) Get(filename string) *OpenFile { } func (this *OpenFileCache) Put(filename string, file *OpenFile) { + filename = filepath.Clean(filename) + if file.size > maxOpenFileSize { return } @@ -119,6 +123,8 @@ func (this *OpenFileCache) Put(filename string, file *OpenFile) { } func (this *OpenFileCache) Close(filename string) { + filename = filepath.Clean(filename) + this.locker.Lock() pool, ok := this.poolMap[filename] diff --git a/internal/caches/storage_file.go b/internal/caches/storage_file.go index 6a1e9c7..36f0e16 100644 --- a/internal/caches/storage_file.go +++ b/internal/caches/storage_file.go @@ -622,6 +622,11 @@ func (this *FileStorage) openWriter(key string, expiredAt int64, status int, hea return nil, fmt.Errorf("%w (003)", ErrFileIsWriting) } + // 关闭 + if openFileCache != nil { + openFileCache.Close(cachePath) + } + var metaBodySize int64 = -1 var metaHeaderSize = -1 if isNewCreated {