<commit_before>require 'zlib'

module DAV
  class Base < Struct.new(:request, :uri)
    include DAV

    include Traversing
    include Actions
    include Convenience
    include Opener

    extend Callbacks
    define_callbacks :get, :put, :mkcol, :delete, :copy, :move
    define_callbacks :propfind, :proppatch, :lock, :unlock
    define_callbacks :search

    def self.mkroot(domain, now = Time.now)
      root = new nil, URI.parse("file://#{ domain }/")

      unless root.collection?
        root.content = nil

        root.properties.creation_date = now
        root.properties.display_name  = ''
        root.properties.resource_type = 'collection'

        root.store_all
      end
    end

    def self.new(request, uri = nil)
      uri ||= begin
        # FIXME something is broken here, see warning in litmus
        utf8_url = Convenience.transcode(request.url) do |url|
          Convenience.to_utf8 url
        end

        URI.parse utf8_url
      end

      super request, uri
    end

    def properties
      @properties ||= Properties.new self
    end
    def ==(other)
      Resource === other and uri == other.uri
    end
    def id
      path = uri.path.split '/'
      path.shift if path.first and path.first.empty?
      path.pop if path.last and path.last.empty?

      @id ||= "#{ uri.host }/#{ path.join '/' }"
    end

    def body
      @body = resource_storage.reader id unless defined? @body
      @body
    end
    def content
      @content = collection?? nil : body.read unless defined? @content
      @content
    end
    def content=(content)
      @content = content.nil?? content : content.clone
      properties.content_length = @content.to_s.length
      update_etag
    end

    def store
      resource_storage.set id, content
    end
    def store_all
      store

      properties.last_modified = Time.now
      properties.store

      parent.children.add self unless parent == self
      parent.children.store
    end
    def delete_all
      parent.children.remove(self).store
      properties.delete
      resource_storage.delete id
    end
    def update_etag
      properties.
        entity_tag = content ? "#{ content.length }-#{ checksum }" : nil
    end

    protected

      def checksum
        Zlib.crc32 content
      end

  end
end
<commit_msg>Do not store host information in ID.<commit_after>require 'zlib'

module DAV
  class Base < Struct.new(:request, :uri)
    include DAV

    include Traversing
    include Actions
    include Convenience
    include Opener

    extend Callbacks
    define_callbacks :get, :put, :mkcol, :delete, :copy, :move
    define_callbacks :propfind, :proppatch, :lock, :unlock
    define_callbacks :search

    def self.mkroot(domain, now = Time.now)
      root = new nil, URI.parse("file://#{ domain }/")

      unless root.collection?
        root.content = nil

        root.properties.creation_date = now
        root.properties.display_name  = ''
        root.properties.resource_type = 'collection'

        root.store_all
      end
    end

    def self.new(request, uri = nil)
      uri ||= begin
        # FIXME something is broken here, see warning in litmus
        utf8_url = Convenience.transcode(request.url) do |url|
          Convenience.to_utf8 url
        end

        URI.parse utf8_url
      end

      super request, uri
    end

    def properties
      @properties ||= Properties.new self
    end
    def ==(other)
      Resource === other and uri == other.uri
    end
    def id
      path = uri.path.split '/'
      path.shift if path.first and path.first.empty?
      path.pop if path.last and path.last.empty?

      @id ||= path.join '/'
    end

    def body
      @body = resource_storage.reader id unless defined? @body
      @body
    end
    def content
      @content = collection?? nil : body.read unless defined? @content
      @content
    end
    def content=(content)
      @content = content.nil?? content : content.clone
      properties.content_length = @content.to_s.length
      update_etag
    end

    def store
      resource_storage.set id, content
    end
    def store_all
      store

      properties.last_modified = Time.now
      properties.store

      parent.children.add self unless parent == self
      parent.children.store
    end
    def delete_all
      parent.children.remove(self).store
      properties.delete
      resource_storage.delete id
    end
    def update_etag
      properties.
        entity_tag = content ? "#{ content.length }-#{ checksum }" : nil
    end

    protected

      def checksum
        Zlib.crc32 content
      end

  end
end

{'fraction_non_alphanumeric': 0.08564614050303555, 'fraction_numerical': 0.002168256721595837, 'mean_word_length': 2.1423705722070845, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3047459', 'n_tokens_mistral': 1381, 'n_tokens_neox': 1340, 'n_words': 385}