Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removes any symlinks before importing a project export file. Also add…
…ed relevant spec.
- Loading branch information
Showing
7 changed files
with
106 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'spec_helper' | ||
|
||
describe Gitlab::ImportExport::FileImporter, lib: true do | ||
let(:shared) { Gitlab::ImportExport::Shared.new(relative_path: 'test') } | ||
let(:export_path) { "#{Dir::tmpdir}/file_importer_spec" } | ||
let(:valid_file) { "#{shared.export_path}/valid.json" } | ||
let(:symlink_file) { "#{shared.export_path}/invalid.json" } | ||
let(:subfolder_symlink_file) { "#{shared.export_path}/subfolder/invalid.json" } | ||
|
||
before do | ||
stub_const('Gitlab::ImportExport::FileImporter::MAX_RETRIES', 0) | ||
allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path) | ||
allow_any_instance_of(Gitlab::ImportExport::CommandLineUtil).to receive(:untar_zxf).and_return(true) | ||
|
||
setup_files | ||
|
||
described_class.import(archive_file: '', shared: shared) | ||
end | ||
|
||
after do | ||
FileUtils.rm_rf(export_path) | ||
end | ||
|
||
it 'removes symlinks in root folder' do | ||
expect(File.exist?(symlink_file)).to be false | ||
end | ||
|
||
it 'removes symlinks in subfolders' do | ||
expect(File.exist?(subfolder_symlink_file)).to be false | ||
end | ||
|
||
it 'does not remove a valid file' do | ||
expect(File.exist?(valid_file)).to be true | ||
end | ||
|
||
def setup_files | ||
FileUtils.mkdir_p("#{shared.export_path}/subfolder/") | ||
FileUtils.touch(valid_file) | ||
FileUtils.ln_s(valid_file, symlink_file) | ||
FileUtils.ln_s(valid_file, subfolder_symlink_file) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module ImportExport | ||
module CommonUtil | ||
def setup_symlink(tmpdir, symlink_name) | ||
allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(tmpdir) | ||
|
||
File.open("#{tmpdir}/test", 'w') { |file| file.write("test") } | ||
FileUtils.ln_s("#{tmpdir}/test", "#{tmpdir}/#{symlink_name}") | ||
end | ||
end | ||
end |