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

Rmt cleanup old metadata #1261

Merged
merged 5 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions lib/rmt/mirror/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def cleanup_stale_metadata

def move_files(glob:, destination:)
FileUtils.mkpath(destination) unless Dir.exist?(destination)
FileUtils.rm_rf(Dir.glob(File.join(destination, '*')))
felixsch marked this conversation as resolved.
Show resolved Hide resolved
FileUtils.mv(Dir.glob(glob), destination, force: true)
rescue StandardError => e
raise RMT::Mirror::Exception.new(_('Error while moving files %{glob} to %{dest}: %{error}') % {
Expand Down
1 change: 1 addition & 0 deletions package/obs/rmt-server.changes
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Wed Oct 30 09:01:32 UTC 2024 - Natnael Getahun <[email protected]>
* Allow SLE Micro system to access SLES repositories (bsc#1230419)
* Skip system token rotation in read-only APIs
* Enable RMT to handle the new dl.suse.com CDN domain (bsc#1234641)
* Clean up RMT metadata after repo update (bsc#1233308)

-------------------------------------------------------------------
Wed Aug 21 15:28:43 UTC 2024 - Jesús Bermúdez Velázquez <[email protected]>
Expand Down
34 changes: 34 additions & 0 deletions spec/lib/rmt/mirror/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,40 @@

expect { base.move_files(glob: src, destination: dest) }.to raise_exception(/Error while moving files/)
end

it 'remove existing files in the destination directory before moving' do
allow(Dir).to receive(:exist?).with(dest).and_return(true)
allow(Dir).to receive(:glob).with(File.join(dest, '*')).and_return(%w[/destination/path/file1.txt /destination/path/file2.txt])
allow(Dir).to receive(:glob).with(src).and_return(%w[/source/path/newfile1.txt /source/path/newfile2.txt])
expect(FileUtils).not_to receive(:mkpath).with(dest)
expect(FileUtils).to receive(:rm_rf).with(%w[/destination/path/file1.txt /destination/path/file2.txt])
expect(FileUtils).to receive(:mv).with(%w[/source/path/newfile1.txt /source/path/newfile2.txt], dest, force: true)

base.move_files(glob: src, destination: dest)
end

it 'removes existing files when destination directory is empty' do
allow(Dir).to receive(:exist?).with(dest).and_return(false)
allow(Dir).to receive(:glob).with(src).and_return(%w[/source/path/newfile1.txt /source/path/newfile2.txt])
allow(Dir).to receive(:glob).with(File.join(dest, '*')).and_return([])
expect(FileUtils).to receive(:mkpath).with(dest)
expect(FileUtils).to receive(:rm_rf).with([])
expect(FileUtils).to receive(:mv).with(%w[/source/path/newfile1.txt /source/path/newfile2.txt], dest, force: true)

base.move_files(glob: src, destination: dest)
end

it 'handles errors during removal of existing files' do
allow(Dir).to receive(:exist?).with(dest).and_return(true)
existing_files = ['/destination/path/file1.txt']

allow(Dir).to receive(:glob).with(File.join(dest, '*')).and_return(existing_files)
allow(FileUtils).to receive(:rm_rf).with(existing_files).and_raise(StandardError.new('Remove failed'))

expect do
base.move_files(glob: src, destination: dest)
end.to raise_exception(/Error while moving files/)
end
end

describe '#need_to_download?' do
Expand Down
Loading