Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#17] Added the configuration parameter 'use-short-cache-path'. #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ Configuration affects how various commands operate.
path, it is relative to the directory containing the `Puppetfile`. The
equivalent environment variable is `LIBRARIAN_PUPPET_TMP`.

* The `use-short-cache-path` config shortens the cache path part of the Puppet
forge URI to the 7 first digits of its SHA1 checksum. This helps additionally
to the `tmp` config to avoid too long paths under Windows. Under Windows this
is especially important when you use an alternative Puppet forge with a quite
longer URI.

Configuration can be set by passing specific options to other commands.

* The `path` config can be set at the local level by passing the `--path` option
Expand Down
2 changes: 2 additions & 0 deletions lib/librarian/puppet/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def init
option "destructive", :type => :boolean, :default => false
option "local", :type => :boolean, :default => false
option "use-v1-api", :type => :boolean, :default => true
option "use-short-cache-path", :type => :boolean, :default => false
def install

ensure!
Expand All @@ -64,6 +65,7 @@ def install

environment.config_db.local['use-v1-api'] = options['use-v1-api'] ? '1' : nil
environment.config_db.local['mode'] = options['local'] ? 'local' : nil
environment.config_db.local['use-short-cache-path'] = options['use-short-cache-path'] ? '1' : nil

resolve!
debug { "Install: dependencies resolved"}
Expand Down
4 changes: 4 additions & 0 deletions lib/librarian/puppet/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def local?
def use_v1_api
config_db['use-v1-api']
end

def use_short_cache_path
config_db['use-short-cache-path']
end
end
end
end
9 changes: 8 additions & 1 deletion lib/librarian/puppet/source/forge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,14 @@ def manifest(name, version, dependencies)

def cache_path
@cache_path ||= begin
dir = "#{uri.host}#{uri.path}".gsub(/[^0-9a-z\-_]/i, '_')
if environment.use_short_cache_path
# To shorten the cache path to avoid #17
# take only the first 7 digits of the SHA1 checksum of the forge URI
# (short Git commit hash approach)
dir = Digest::SHA1.hexdigest("#{uri.host}#{uri.path}")[0..6]
else
dir = "#{uri.host}#{uri.path}".gsub(/[^0-9a-z\-_]/i, '_')
end
environment.cache_path.join("source/puppet/forge/#{dir}")
end
end
Expand Down