Method: Opal::Cache::FileCache.find_dir

Defined in:
lib/opal/cache/file_cache.rb

.find_dirObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/opal/cache/file_cache.rb', line 96

def self.find_dir
  @find_dir ||= case
                # Try to write cache into a directory pointed by an environment variable if present
                when dir = ENV['OPAL_CACHE_DIR']
                  FileUtils.mkdir_p(dir)
                  dir
                # Otherwise, we write to the place where Opal is installed...
                # I don't think it's a good location to store cache, so many things can go wrong.
                # when dir = dir_writable?(Opal.gem_dir, '..', 'tmp', 'cache')
                #   FileUtils.mkdir_p(dir)
                #   FileUtils.chmod(0o700, dir)
                #   dir
                # Otherwise, ~/.cache/opal...
                when dir = dir_writable?(Dir.home, '.cache', 'opal')
                  FileUtils.mkdir_p(dir)
                  FileUtils.chmod(0o700, dir)
                  dir
                # Only /tmp is writable... or isn't it?
                when (dir = dir_writable?('/tmp', "opal-cache-#{ENV['USER']}")) && File.sticky?('/tmp')
                  FileUtils.mkdir_p(dir)
                  FileUtils.chmod(0o700, dir)
                  dir
                # No way... we can't write anywhere...
                else
                  warn "Couldn't find a writable path to store Opal cache. " \
                       'Try setting OPAL_CACHE_DIR environment variable'
                  nil
                end
end