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
51ee1e77
authored
2014-08-18 14:42:17 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
beego: close the file when finish init
1 parent
986e91b7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
10 deletions
session/sess_file.go
session/sess_file.go
View file @
51ee1e7
...
...
@@ -29,7 +29,6 @@ var (
// File session store
type
FileSessionStore
struct
{
f
*
os
.
File
sid
string
lock
sync
.
RWMutex
values
map
[
interface
{}]
interface
{}
...
...
@@ -77,14 +76,23 @@ func (fs *FileSessionStore) SessionID() string {
// Write file session to local file with Gob string
func
(
fs
*
FileSessionStore
)
SessionRelease
(
w
http
.
ResponseWriter
)
{
defer
fs
.
f
.
Close
()
b
,
err
:=
EncodeGob
(
fs
.
values
)
if
err
!=
nil
{
return
}
fs
.
f
.
Truncate
(
0
)
fs
.
f
.
Seek
(
0
,
0
)
fs
.
f
.
Write
(
b
)
_
,
err
=
os
.
Stat
(
path
.
Join
(
filepder
.
savePath
,
string
(
fs
.
sid
[
0
]),
string
(
fs
.
sid
[
1
]),
fs
.
sid
))
var
f
*
os
.
File
if
err
==
nil
{
f
,
err
=
os
.
OpenFile
(
path
.
Join
(
filepder
.
savePath
,
string
(
fs
.
sid
[
0
]),
string
(
fs
.
sid
[
1
]),
fs
.
sid
),
os
.
O_RDWR
,
0777
)
}
else
if
os
.
IsNotExist
(
err
)
{
f
,
err
=
os
.
Create
(
path
.
Join
(
filepder
.
savePath
,
string
(
fs
.
sid
[
0
]),
string
(
fs
.
sid
[
1
]),
fs
.
sid
))
}
else
{
return
}
f
.
Truncate
(
0
)
f
.
Seek
(
0
,
0
)
f
.
Write
(
b
)
f
.
Close
()
}
// File session provider
...
...
@@ -137,8 +145,7 @@ func (fp *FileProvider) SessionRead(sid string) (SessionStore, error) {
}
}
f
.
Close
()
f
,
err
=
os
.
OpenFile
(
path
.
Join
(
fp
.
savePath
,
string
(
sid
[
0
]),
string
(
sid
[
1
]),
sid
),
os
.
O_WRONLY
|
os
.
O_CREATE
,
0777
)
ss
:=
&
FileSessionStore
{
f
:
f
,
sid
:
sid
,
values
:
kv
}
ss
:=
&
FileSessionStore
{
sid
:
sid
,
values
:
kv
}
return
ss
,
nil
}
...
...
@@ -235,9 +242,7 @@ func (fp *FileProvider) SessionRegenerate(oldsid, sid string) (SessionStore, err
return
nil
,
err
}
}
newf
,
err
=
os
.
OpenFile
(
path
.
Join
(
fp
.
savePath
,
string
(
sid
[
0
]),
string
(
sid
[
1
]),
sid
),
os
.
O_WRONLY
|
os
.
O_CREATE
,
0777
)
ss
:=
&
FileSessionStore
{
f
:
newf
,
sid
:
sid
,
values
:
kv
}
ss
:=
&
FileSessionStore
{
sid
:
sid
,
values
:
kv
}
return
ss
,
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