This file is indexed.

/usr/lib/ruby/vendor_ruby/vagrant/data_store.rb is in vagrant 1.0.3-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
require 'pathname'

require 'log4r'

module Vagrant
  # The Vagrant data store is a key-value store which is persisted
  # as JSON in a local file which is specified in the initializer.
  # The data store itself is accessed via typical hash accessors: `[]`
  # and `[]=`. If a key is set to `nil`, then it is removed from the
  # datastore. The data store is only updated on disk when {#commit}
  # is called on the data store itself.
  #
  # The data store is a hash with indifferent access, meaning that
  # while all keys are persisted as strings in the JSON, you can access
  # them back as either symbols or strings. Note that this is only true
  # for the top-level data store. As soon as you set a hash inside the
  # data store, unless you explicitly use a {Util::HashWithIndifferentAccess},
  # it will be a regular hash.
  class DataStore < Util::HashWithIndifferentAccess
    attr_reader :file_path

    def initialize(file_path)
      @logger    = Log4r::Logger.new("vagrant::datastore")

      if file_path
        @logger.info("Created: #{file_path}")

        @file_path = Pathname.new(file_path)
        if @file_path.exist?
          raise Errors::DotfileIsDirectory if @file_path.directory?

          begin
            merge!(JSON.parse(@file_path.read))
          rescue JSON::ParserError
            # Ignore if the data is invalid in the file.
            @logger.error("Data store contained invalid JSON. Ignoring.")
          end
        end
      else
        @logger.info("No file path. In-memory data store.")
        @file_path = nil
      end
    end

    # Commits any changes to the data to disk. Even if the data
    # hasn't changed, it will be reserialized and written to disk.
    def commit
      if !@file_path
        raise StandardError, "In-memory data stores can't be committed."
      end

      clean_nil_and_empties

      if empty?
        # Delete the file since an empty data store is not useful
        @logger.info("Deleting data store since we're empty: #{@file_path}")
        @file_path.delete if @file_path.exist?
      else
        @logger.info("Committing data to data store: #{@file_path}")

        @file_path.open("w") do |f|
          f.write(to_json)
          f.fsync
        end
      end
    end

    protected

    # Removes the "nil" and "empty?" values from the hash (children
    # included) so that the final output JSON is cleaner.
    def clean_nil_and_empties(hash=self)
      # Clean depth first
      hash.each do |k, v|
        clean_nil_and_empties(v) if v.is_a?(Hash)
      end

      # Clean ourselves, knowing that any children have already been
      # cleaned up
      bad_keys = hash.inject([]) do |acc, data|
        k,v = data
        acc.push(k) if v.nil?
        acc.push(k) if v.respond_to?(:empty?) && v.empty?
        acc
      end

      bad_keys.each do |key|
        hash.delete(key)
      end
    end
  end
end