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

Force UNC style to support win long paths #95

Merged
merged 9 commits into from
Jun 17, 2018
Merged
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: ruby
rvm:
- 2.3
- 2.4
- 2.5
script: bundle exec rake
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Travis status](https://api.travis-ci.org/spox/batali.svg?branch=develop)](https://travis-ci.org/spox/batali) [![Appveyor status](https://ci.appveyor.com/api/projects/status/bua5vb1f2jvpuu90?svg=true)](https://ci.appveyor.com/project/chrisroberts/batali)

![Batali](img/batali-logo.png)

# Batali
Expand Down
18 changes: 18 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
install:
# To avoid duplicated executables in PATH, see https:/ruby/spec/pull/468
- set PATH=C:\Ruby%ruby_version%\bin;%PATH%
- bundle install

environment:
matrix:
- ruby_version: 24-x64
- ruby_version: 25-x64

build: off

before_test:
- ruby -v

test_script:
- bundle exec rake
6 changes: 4 additions & 2 deletions lib/batali/b_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class BFile < Bogo::Config
# @param cache_path [String] path to cache directory
# @return [self]
def initialize(b_file, cache_path)
b_file = Utility.clean_path(b_file)
@cache = cache_path
super(b_file)
end
Expand Down Expand Up @@ -199,7 +200,7 @@ class Group < Utility
if v.is_a?(Hash)
ckbk = Cookbook.new(v)
else
dir = Pathname.new(File.dirname(b_file.path)).relative_path_from(Pathname.new(Dir.pwd)).to_path
dir = Pathname.new(File.dirname(b_file.path)).relative_path_from(Pathname.new(Utility.clean_path(Dir.pwd))).to_path
m_unit = Origin::Path.new(:name => "metadata", :path => dir, :cache_path => b_file.cache).units.first
ckbk = Cookbook.new(:name => m_unit.name, :version => m_unit.version, :path => dir)
end
Expand All @@ -217,7 +218,7 @@ def auto_discover!(environment = nil)
unless discover
raise "Attempting to perform auto-discovery but auto-discovery is not enabled!"
end
environment_items = Dir.glob(File.join(File.dirname(path), "environments", "*.{json,rb}")).map do |e_path|
environment_items = Dir.glob(Utility.join_path(File.dirname(path), "environments", "*.{json,rb}")).map do |e_path|
result = parse_environment(e_path)
if result[:name] && result[:cookbooks]
Smash.new(
Expand Down Expand Up @@ -334,6 +335,7 @@ def flatten_constraints(constraints)
# @param path [String] path to environment
# @return [Smash]
def parse_environment(path)
path = Utility.clean_path(path)
case File.extname(path)
when ".json"
env = MultiJson.load(
Expand Down
4 changes: 2 additions & 2 deletions lib/batali/chefspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class << self

# Create new instance
def initialize
@vendor_path = Dir.mktmpdir
@vendor_path = Utility.clean_path(Dir.mktmpdir)
end

# Setup the environment (load cookbooks)
Expand All @@ -25,7 +25,7 @@ def setup!
begin
::Batali::Command::Update.new(
Smash.new(
:file => File.join(Dir.pwd, "Batali"),
:file => Utility.join_path(Dir.pwd, "Batali"),
:path => @vendor_path,
:update => {
:install => true,
Expand Down
14 changes: 7 additions & 7 deletions lib/batali/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def initialize(*_)
def batali_file
memoize(:batali_file) do
# TODO: Add directory traverse searching
path = config.fetch(:file, File.join(Dir.pwd, "Batali"))
path = Utility.clean_path(config.fetch(:file, File.join(Dir.pwd, "Batali")))
ui.verbose "Loading Batali file from: #{path}"
bfile = BFile.new(path, cache_directory)
if bfile.discover
Expand All @@ -44,7 +44,7 @@ def batali_file
# @return [Manifest]
def manifest
memoize(:manifest) do
path = File.join(
path = Utility.join_path(
File.dirname(
config.fetch(:file, File.join(Dir.pwd, "batali.manifest"))
), "batali.manifest"
Expand All @@ -56,20 +56,20 @@ def manifest

# @return [String] correct user home location for platform
def user_home
if RUBY_PLATFORM =~ /mswin|mingw|windows/
ENV.fetch("LOCALAPPDATA", Dir.home)
if (RUBY_PLATFORM =~ /mswin|mingw|windows/)
Utility.clean_path(ENV.fetch("LOCALAPPDATA", Dir.home))
else
Dir.home
Utility.clean_path(Dir.home)
end
end

# @return [String] path to local cache
def cache_directory(*args)
memoize(["cache_directory", *args].join("_")) do
directory = config.fetch(:cache_directory, File.join(user_home, ".batali", "cache"))
directory = Utility.clean_path(config.fetch(:cache_directory, File.join(user_home, ".batali", "cache")))
ui.debug "Cache directory to persist cookbooks: #{directory}"
unless args.empty?
directory = File.join(directory, *args.map(&:to_s))
directory = Utility.join_path(directory, *args.map(&:to_s))
end
FileUtils.mkdir_p(directory)
directory
Expand Down
2 changes: 1 addition & 1 deletion lib/batali/command/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def scrub!

# Display local cache information
def display
cache_size = Dir.glob(File.join(cache_directory, "**", "**", "*")).map do |path|
cache_size = Dir.glob(Utility.join_path(cache_directory, "**", "**", "*")).map do |path|
File.size(path) if File.file?(path)
end.compact.inject(&:+).to_i
cache_size = "#{sprintf("%.2f", ((cache_size / 1024.to_f) / 1024))}M"
Expand Down
6 changes: 3 additions & 3 deletions lib/batali/command/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Install < Batali::Command
# Install cookbooks
def execute!
dry_run("Cookbook installation") do
install_path = config.fetch(:path, "cookbooks")
install_path = Utility.clean_path(config.fetch(:path, "cookbooks"))
run_action("Readying installation destination") do
FileUtils.rm_rf(install_path)
FileUtils.mkdir_p(install_path)
Expand All @@ -30,13 +30,13 @@ def execute!
)
end
asset_path = unit.source.asset
final_path = File.join(install_path, unit.name)
final_path = Utility.join_path(install_path, unit.name)
if infrastructure?
final_path << "-#{unit.version}"
end
begin
FileUtils.cp_r(
File.join(asset_path, "."),
Utility.join_path(asset_path, "."),
final_path
)
ui.debug "Completed unit install for: #{unit.name}<#{unit.version}>"
Expand Down
30 changes: 15 additions & 15 deletions lib/batali/command/supermarket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def execute!
Install.new(config.merge(:ui => ui, :install => {}), arguments).execute!
end
run_action "Prepare supermarket destination directory" do
FileUtils.mkdir_p(File.join(config[:supermarket_path], "api", "v1", "cookbooks"))
FileUtils.mkdir_p(Utility.join_path(config[:supermarket_path], "api", "v1", "cookbooks"))
FileUtils.mkdir_p(config[:assets_path])
nil
end
Expand All @@ -28,7 +28,7 @@ def execute!
end
unless config[:universe_only]
if config[:clean_assets]
Dir.glob(File.join(config[:assets_path], "*")).each do |old_asset|
Dir.glob(Utility.join_path(config[:assets_path], "*")).each do |old_asset|
FileUtils.rm(old_asset)
end
end
Expand All @@ -42,9 +42,9 @@ def execute!
run_action "Write supermarket universe file" do
FileUtils.cp(
new_universe_file.path,
File.join(config[:supermarket_path], "universe")
Utility.join_path(config[:supermarket_path], "universe")
)
FileUtils.chmod(0644, File.join(config[:supermarket_path], "universe"))
FileUtils.chmod(0644, Utility.join_path(config[:supermarket_path], "universe"))
new_universe_file.delete
nil
end
Expand All @@ -58,8 +58,8 @@ def generate_cookbook_assets
base_name = "#{ckbk.name}-#{ckbk.version}.tgz"
ckbk_name = infrastructure? ? "#{ckbk.name}-#{ckbk.version}" : ckbk.name
tar_ckbk_name = "#{ckbk.name}-#{ckbk.version}"
ckbk_content_path = File.join("cookbooks", ckbk_name)
ckbk_path = File.join(config[:assets_path], base_name)
ckbk_content_path = Utility.join_path("cookbooks", ckbk_name)
ckbk_path = Utility.join_path(config[:assets_path], base_name)
unless File.exist?(ckbk_path)
ckbk_io = File.open(ckbk_path, "wb")
gz_io = Zlib::GzipWriter.new(ckbk_io, Zlib::BEST_COMPRESSION)
Expand All @@ -69,10 +69,10 @@ def generate_cookbook_assets
unless File.directory?(ckbk_content_path)
raise "Cookbook path not found! Run `install`. (#{ckbk_content_path})"
end
Dir.glob(File.join(ckbk_content_path, "**", "**", "*")).each do |c_file|
Dir.glob(Utility.join_path(ckbk_content_path, "**", "**", "*")).each do |c_file|
next unless File.file?(c_file)
stat = File.stat(c_file)
c_path = c_file.sub(File.join(ckbk_content_path, ""), "")
c_path = c_file.sub(Utility.join_path(ckbk_content_path, ""), "")
tar.add_file_simple(File.join(tar_ckbk_name, c_path), stat.mode, stat.size) do |dst|
File.open(c_file, "rb") do |src|
until src.eof?
Expand Down Expand Up @@ -108,17 +108,17 @@ def populate_universe(items)
#
# @return [Smash, File] universe content hash, universe file
def generate_universe
supermarket_url = config[:remote_supermarket_url].sub(%r{/$}, "")
universe = Smash.new.tap do |uni|
manifest.cookbook.each do |ckbk|
uni.set(ckbk.name, ckbk.version.to_s,
Smash.new(
uni.set(ckbk.name, ckbk.version.to_s, Smash.new(
:location_type => config[:location_type],
:location_path => File.join(config[:remote_supermarket_url], "api", "v1"),
:download_url => File.join(
config[:remote_supermarket_url],
:location_path => [supermarket_url, "api", "v1"].join("/"),
:download_url => [
supermarket_url,
config[:download_prefix],
"#{ckbk.name}-#{ckbk.version}.tgz"
),
"#{ckbk.name}-#{ckbk.version}.tgz",
].map { |i| i.to_s.gsub(%r{(^/|/$)}, "") }.join("/"),
:dependencies => Smash[
ckbk.dependencies.map do |dep|
[dep.name, dep.requirement]
Expand Down
8 changes: 4 additions & 4 deletions lib/batali/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Git

# @return [String] path to repository clone
def base_path
File.join(cache_path, Base64.urlsafe_encode64(url))
Utility.join_path(cache_path, Base64.urlsafe_encode64(url))
end

# Clone the repository to the local machine
Expand All @@ -35,11 +35,11 @@ def ref_dup
git.checkout(ref)
git.pull("origin", ref)
self.ref = git.log.first.sha
self.path = File.join(cache_path, "git", ref)
self.path = Utility.join_path(cache_path, "git", ref)
unless File.directory?(path)
FileUtils.mkdir_p(path)
FileUtils.cp_r(File.join(base_path, "."), path)
FileUtils.rm_rf(File.join(path, ".git"))
FileUtils.cp_r(Utility.join_path(base_path, "."), path)
FileUtils.rm_rf(Utility.join_path(path, ".git"))
end
path
end
Expand Down
1 change: 1 addition & 0 deletions lib/batali/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Manifest < Utility
# @param path [String] path to manifest
# @return [Manifest]
def self.build(path)
path = Utility.join_path(path)
if File.exist?(path)
new(Bogo::Config.new(path).data.merge(:path => path))
else
Expand Down
5 changes: 5 additions & 0 deletions lib/batali/origin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ class Origin < Utility
attribute :cache_path, String, :required => true
attribute :identifier, String

def initialize(*_, &block)
super
self.cache_path = Utility.clean_path(cache_path)
end

# @return [Array<Unit>] all units
def units
raise NotImplementedError.new "Abstract class"
Expand Down
2 changes: 1 addition & 1 deletion lib/batali/origin/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def units
def load_metadata
fetch_repo
original_path = path.dup
self.path = File.join(*[path, subdirectory].compact)
self.path = Utility.path_join(*[path, subdirectory].compact)
result = super
self.path = original_path
result
Expand Down
1 change: 1 addition & 0 deletions lib/batali/origin/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def depends(*args)

def initialize(*_)
super
self.path = Utility.clean_path(path)
self.identifier = Smash.new(:path => path).checksum
unless name?
self.name = identifier
Expand Down
4 changes: 2 additions & 2 deletions lib/batali/origin/remote_site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def initialize(*_)
# @return [String] cache directory path
def cache_directory
memoize(:cache_directory) do
c_path = File.join(cache_path, "remote_site", identifier)
c_path = Utility.join_path(cache_path, "remote_site", identifier)
FileUtils.mkdir_p(c_path)
c_path
end
Expand Down Expand Up @@ -97,7 +97,7 @@ def fetch

# @return [String] path to universe file
def universe_path
File.join(cache_directory, "universe.json")
Utility.join_path(cache_directory, "universe.json")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/batali/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Source < Utility
attribute :type, String, :required => true, :default => lambda { self.name } # rubocop:disable Style/RedundantSelf

def initialize(args = {})
@cache_path = args.delete(:cache_path)
@cache_path = Utility.clean_path(args.delete(:cache_path))
super
end

Expand Down
6 changes: 3 additions & 3 deletions lib/batali/source/chef_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ def unit_dependencies
# @return [String] path to cache
def cache_directory
memoize(:cache_directory) do
@cache ||= File.join(cache_path, "chef_server", endpoint)
@cache ||= Utility.join_path(cache_path, "chef_server", endpoint)
cache
end
end

# @return [String] directory
def asset
path = File.join(cache_directory, name, version)
path = Utility.join_path(cache_directory, name, version)
begin
FileUtils.mkdir_p(path)
cookbook = rest.get_rest("cookbooks/#{name}/#{version}")
manifest = cookbook.manifest
Chef::CookbookVersion::COOKBOOK_SEGMENTS.each do |segement|
if manifest.key?(segment)
manifest[segement].each do |s_file|
new_path = File.join(path, s_file["path"].gsub("/", File::SEPARATOR))
new_path = Utility.join_path(path, s_file["path"].gsub("/", File::SEPARATOR))
FileUtils.mkdir_p(File.dirname(new_path))
api_service.sign_on_redirect = false
t_file = api_service.get_rest(s_file["url"], true)
Expand Down
8 changes: 7 additions & 1 deletion lib/batali/source/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ class Git < Path
attribute :subdirectory, String, :equivalent => true
attribute :path, String

def initialize(*_, &block)
super
self.subdirectory = Utility.clean_path(subdirectory)
self.path = Utility.clean_path(path)
end

# @return [String] directory containing contents
def asset
clone_repository
clone_path = ref_dup
self.path = File.join(*[ref_dup, subdirectory].compact)
self.path = Utility.join_path(*[ref_dup, subdirectory].compact)
result = super
self.path = clone_path
result
Expand Down
Loading