summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavor <vorgrimmlerdavid@gmx.de>2012-03-20 16:16:36 +0100
committerdavor <vorgrimmlerdavid@gmx.de>2012-03-20 16:16:36 +0100
commitc0f8b6839e46dae719c754f9548da6e770192ce3 (patch)
tree1875735de6be8d15fe439235e6b5bf061c1d77f7
parenta430f0cf2ece93f1359ac0fb2247fc6903804ed4 (diff)
parent859365c570a514b7c33fa446875f42ff1aa62100 (diff)
Merge remote branch 'origin/development' into jl
-rw-r--r--application.rb19
1 files changed, 16 insertions, 3 deletions
diff --git a/application.rb b/application.rb
index 51ce621..0245abd 100644
--- a/application.rb
+++ b/application.rb
@@ -19,11 +19,24 @@ set :lock, true
@@datadir = "data"
+@@idfile_path = @@datadir+"/id"
+unless File.exist?(@@idfile_path)
+ id = Dir["./#{@@datadir}/*json"].collect{|f| File.basename(f.sub(/.json/,'')).to_i}.sort.last
+ id = 0 if id.nil?
+ open(@@idfile_path,"w") do |f|
+ f.puts(id)
+ end
+end
+
helpers do
def next_id
- id = Dir["./#{@@datadir}/*json"].collect{|f| File.basename(f.sub(/.json/,'')).to_i}.sort.last
- id = 0 if id.nil?
- id + 1
+ open(@@idfile_path, "r+") do |f|
+ f.flock(File::LOCK_EX)
+ @id = f.gets.to_i + 1
+ f.rewind
+ f.print @id
+ end
+ return @id
end
def uri(id)