# File lib/rufus/cloche.rb, line 273
    def lock (create, type, key, &block)

      @mutex.synchronize do
        begin

          d, f = path_for(type, key)
          fn = File.join(d, f)

          if create && ( ! File.exist?(fn))
            FileUtils.mkdir_p(d) unless File.exist?(d)
            FileUtils.touch(fn) unless File.exist?(fn)
          end

          file = File.new(fn) rescue nil

          return false if file.nil?

          file.flock(File::LOCK_EX) unless @nolock
          block.call(file)

        ensure
          begin
            file.flock(File::LOCK_UN) unless @nolock
          rescue Exception => e
            #p [ :lock, @fpath, e ]
            #e.backtrace.each { |l| puts l }
          end
          begin
            file.close if file
          rescue Exception => e
            #p [ :close_fail, e ]
          end
        end
      end
    end