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

Delete old .sha1 files #401

Merged
merged 1 commit into from
Jun 3, 2020
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
10 changes: 10 additions & 0 deletions spec/integration/install_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ describe "install" do
end
end

it "deletes old .sha1 files" do
metadata = {dependencies: {web: "*"}}
with_shard(metadata) do
Dir.mkdir_p(Shards::INSTALL_DIR)
File.touch("#{Shards::INSTALL_DIR}/web.sha1")
run "shards install"
File.exists?("#{Shards::INSTALL_DIR}/web.sha1").should be_false
end
end

it "won't install prerelease version" do
metadata = {
dependencies: {unstable: "*"},
Expand Down
5 changes: 5 additions & 0 deletions src/info.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class Shards::Info

def save
Dir.mkdir_p(@install_path)

unless File.exists?(info_path)
Dir[File.join @install_path, "*.sha1"].each { |p| File.delete(p) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect: Glob patterns must always use / as separator, not \ even on Windows.

end

File.open(info_path, "w") do |file|
YAML.build(file) do |yaml|
yaml.mapping do
Expand Down