# CGI::Session::FileStore $B$N%G!\<%?$,2u$l$k(B

**URL:** <https://www.ruby-forum.com/t/cgi-filestore-b-n-g-2u-l-k-b/120231>\
**Category:** Development\
**Created:** [November 15, 2007, 12:19am UTC](https://www.ruby-forum.com/t/cgi-filestore-b-n-g-2u-l-k-b/120231 "2007-11-15T00:19:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SSSBSHS\_SSSSS5SRSmS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecd19e/32.png) [@SSSBSHS\_SSSSS5SRSmS](https://www.ruby-forum.com/u/SSSBSHS_SSSSS5SRSmS)\
**Post date:** [November 15, 2007, 12:19am UTC](https://www.ruby-forum.com/t/cgi-filestore-b-n-g-2u-l-k-b/120231/1 "2007-11-15T00:19:46Z")

</div>

e$B$H$\_$?$G$9!#e(B

1.8.6 e$B$Ge(B CGI::Session::FileStore  
e$B$N%G!\<%?$,2u$l$k$3$H$,$"$j$^$9!#e(B

- LOCK\_EX e$B$r3MF@$G$-$F$J$$$N$K%U%!%$%k$NFbMF$r\>C$7$F$$$k!#e(B

412: f = File.open(@path, File::CREAT|File::TRUNC|File::RDWR, 0600)  
413: f.flock File::LOCK\_EX

- finalizer  
e$B$+$i8F$P$l$k;~!"%U%!%$%k$NFbMF$,CfESH\>C\<$K$J$k$3$H$,$"$k!#e(B

e$B$3$C$A$N860x$ONI$/J,$+$j$^$;$s$,!"e(B@hash  
e$B$NFbMF$r%U%!%$%k$K=PNO$7$F$$$ke(B  
e$B;~$K2?$+$,5/$-$FESCf$^$G$K$J$C$F$7$^$&$h$&$G$9!#e(BCGI  
e$B$,=\*N;$7$J$$$&$A$Ke(B  
e$B%V%i%&%6$,JL$N%j%s%/$r2!$7$?Ey$G!"e(BCGI e$B$,e(B SIGPIPE  
e$B$K$J$C$?\>l9g$KH/@8$9$ke(B  
e$B$\_$?$$$G$9!#e(B

e$B$H$$$&$3$H$G!"\<!$N$h$&$K$7$F$\_$?$i$&$^$/F0$$$F$$$k$h$&$G$9!#e(B

— session.rb.orig 2007-02-13 08:01:19.000000000 +0900  
+++ session.rb 2007-11-15 07:49:17.000000000 +0900  
@@ -391,8 +391,9 @@  
unless @hash  
@hash = {}  
begin

- 

```
       lockf = File.open(@path+".lock", "r")

```

- 

```
       lockf.flock File::LOCK_SH
 f = File.open(@path, 'r')

```

- 

```
 f.flock File::LOCK_SH
 for line in f
   line.chomp!
   k, v = line.split('=',2)

```

@@ -400,6 +401,7 @@  
end  
ensure  
f.close unless f.nil?

- 

```
       lockf.close if lockf
     end

```

end  
@hash  
@@ -409,13 +411,17 @@  
def update  
return unless @hash  
begin

- f = File.open(@path, File::CREAT|File::TRUNC|File::RDWR, 0600)
- f.flock File::LOCK\_EX

- 

```
     lockf = File.open(@path+".lock", File::CREAT|File::RDWR, 

```

1. 

- lockf.flock File::LOCK\_EX
- 

```
     f = File.open(@path+".new", 

```

File::CREAT|File::TRUNC|File::WRONLY, 0600)  
for k,v in @hash  
f.printf “%s=%s\n”, CGI::escape(k), CGI::escape(String(v))  
end

- 

```
     f.close

```

- 

```
     File.rename @path+".new", @path
   ensure

```

- 

```
     f.close unless f.nil?

```

- 

```
     f.close if f and !f.closed?

```

- 

```
     lockf.close if lockf
   end
 end

```

@@ -426,6 +432,8 @@

```
   # Close and delete the session's FileStore file.
   def delete

```

- 

```
   File::unlink @path+".lock" rescue nil

```

- 

```
   File::unlink @path+".new" rescue nil
   File::unlink @path
 rescue Errno::ENOENT
 end
```
