Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
6f3a759b
authored
2014-01-05 23:16:47 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
gmfim add lock. fix #445
1 parent
338124e3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
5 deletions
memzipfile.go
memzipfile.go
View file @
6f3a759
...
...
@@ -5,16 +5,17 @@ import (
"compress/flate"
"compress/gzip"
"errors"
//"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
"sync"
"time"
)
var
gmfim
map
[
string
]
*
MemFileInfo
=
make
(
map
[
string
]
*
MemFileInfo
)
var
lock
sync
.
RWMutex
// OpenMemZipFile returns MemFile object with a compressed static file.
// it's used for serve static file if gzip enable.
...
...
@@ -32,12 +33,12 @@ func OpenMemZipFile(path string, zip string) (*MemFile, error) {
modtime
:=
osfileinfo
.
ModTime
()
fileSize
:=
osfileinfo
.
Size
()
lock
.
RLock
()
cfi
,
ok
:=
gmfim
[
zip
+
":"
+
path
]
lock
.
RUnlock
()
if
ok
&&
cfi
.
ModTime
()
==
modtime
&&
cfi
.
fileSize
==
fileSize
{
//fmt.Printf("read %s file %s from cache\n", zip, path)
}
else
{
//fmt.Printf("NOT read %s file %s from cache\n", zip, path)
var
content
[]
byte
if
zip
==
"gzip"
{
//将文件内容压缩到zipbuf中
...
...
@@ -81,8 +82,9 @@ func OpenMemZipFile(path string, zip string) (*MemFile, error) {
}
cfi
=
&
MemFileInfo
{
osfileinfo
,
modtime
,
content
,
int64
(
len
(
content
)),
fileSize
}
lock
.
Lock
()
defer
lock
.
Unlock
()
gmfim
[
zip
+
":"
+
path
]
=
cfi
//fmt.Printf("%s file %s to %d, cache it\n", zip, path, len(content))
}
return
&
MemFile
{
fi
:
cfi
,
offset
:
0
},
nil
}
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment