Skip to content

Commit

Permalink
Fixes #5012 - Package: Missing backup files for files with the same c…
Browse files Browse the repository at this point in the history
…ontent.

Co-authored-by: Dominik Klein <dk@zammad.com>
  • Loading branch information
rolfschmidt and dominikklein committed Jan 19, 2024
1 parent 5f8cb09 commit b6d5f7b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/models/package.rb
Expand Up @@ -436,12 +436,13 @@ def self._write_file(file, permission, data)

# rename existing file if not already the same file
if File.exist?(location)
content_fs = _read_file(file)
if content_fs == data
backup_location = "#{location}.save"
content_fs = _read_file(file)
if content_fs == data && File.exist?(backup_location)
logger.debug { "NOTICE: file '#{location}' already exists, skip install" }
return true
end
backup_location = "#{location}.save"

logger.info "NOTICE: backup old file '#{location}' to #{backup_location}"
File.rename(location, backup_location)
end
Expand Down
28 changes: 28 additions & 0 deletions spec/models/package_spec.rb
Expand Up @@ -286,4 +286,32 @@ def expect_uninstall_package
expect(described_class.last.url).to eq('https://zammad.org/')
end
end

describe 'Package: Missing backup files for files with the same content #5012' do
let(:package_v1_files) do
<<-JSON
[
{
"permission": "644",
"location": "lib/version.rb",
"content": "#{Base64.strict_encode64(File.read('lib/version.rb')).strip}"
}
]
JSON
end
let(:package_v2_files) do
<<-JSON
[]
JSON
end

let(:package_v1) { get_package_structure(package_name, package_v1_files, '1.0.0') }
let(:package_v2) { get_package_structure(package_name, package_v2_files, '1.0.1') }

it 'does not lose core files when patched by package and released in future updates of zammad' do
described_class.install(string: package_v1)
described_class.install(string: package_v2)
expect(File.exist?('lib/version.rb')).to be(true)
end
end
end

0 comments on commit b6d5f7b

Please sign in to comment.