lib/openid/store/filesystem.rb in ruby-openid-2.1.8 vs lib/openid/store/filesystem.rb in ruby-openid-2.2.0

- old
+ new

@@ -11,14 +11,13 @@ class Filesystem < Interface @@FILENAME_ALLOWED = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-".split("") # Create a Filesystem store instance, putting all data in +directory+. def initialize(directory) - p_dir = Pathname.new(directory) - @nonce_dir = p_dir.join('nonces') - @association_dir = p_dir.join('associations') - @temp_dir = p_dir.join('temp') + @nonce_dir = File.join(directory, 'nonces') + @association_dir = File.join(directory, 'associations') + @temp_dir = File.join(directory, 'temp') self.ensure_dir(@nonce_dir) self.ensure_dir(@association_dir) self.ensure_dir(@temp_dir) end @@ -38,11 +37,11 @@ handle_hash = safe64(handle) else handle_hash = '' end filename = [proto,domain,url_hash,handle_hash].join('-') - @association_dir.join(filename) + File.join(@association_dir, filename) end # Store an association in the assoc directory def store_association(server_url, association) assoc_s = association.serialize @@ -153,11 +152,11 @@ url_hash = safe64(server_url) salt_hash = safe64(salt) nonce_fn = '%08x-%s-%s-%s-%s'%[timestamp, proto, domain, url_hash, salt_hash] - filename = @nonce_dir.join(nonce_fn) + filename = File.join(@nonce_dir, nonce_fn) begin fd = File.new(filename, File::CREAT | File::EXCL | File::WRONLY, 0200) fd.close return true @@ -172,11 +171,11 @@ cleanup_associations cleanup_nonces end def cleanup_associations - association_filenames = Dir[@association_dir.join("*").to_s] + association_filenames = Dir[File.join(@association_dir, "*")] count = 0 association_filenames.each do |af| begin f = File.open(af, 'r') rescue Errno::ENOENT @@ -202,11 +201,11 @@ end return count end def cleanup_nonces - nonces = Dir[@nonce_dir.join("*").to_s] + nonces = Dir[File.join(@nonce_dir, "*")] now = Time.now.to_i count = 0 nonces.each do |filename| nonce = filename.split('/')[-1] @@ -234,10 +233,10 @@ filename_chunks = [] s.split('').each do |c| if @@FILENAME_ALLOWED.index(c) filename_chunks << c else - filename_chunks << sprintf("_%02X", c[0]) + filename_chunks << sprintf("_%02X", c.bytes.first) end end filename_chunks.join("") end