Skip to content

Commit

Permalink
Merge pull request #5183 from bgeuken/bugfix/backend_file_
Browse files Browse the repository at this point in the history
Bugfix/backend file
  • Loading branch information
bgeuken committed Jun 26, 2018
2 parents 990fea4 + 62daff3 commit 4eece6a
Show file tree
Hide file tree
Showing 15 changed files with 186 additions and 56 deletions.
Expand Up @@ -9,7 +9,7 @@ def show

return if forward_from_backend(config.full_path(sliced_params))

content = config.to_s(sliced_params)
content = config.content(sliced_params)

unless content
render_404(config.errors.full_messages.to_sentence)
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/controllers/webui/project_controller.rb
Expand Up @@ -541,7 +541,7 @@ def prjconf
sliced_params = params.slice(:rev)
sliced_params.permit!

@content = @project.config.to_s(sliced_params.to_h)
@content = @project.config.content(sliced_params.to_h)
return if @content
flash[:error] = @project.config.errors.full_messages.to_sentence
redirect_to controller: 'project', nextstatus: 404
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/helpers/validation_helper.rb
Expand Up @@ -45,7 +45,7 @@ def validate_read_access_of_deleted_package(project, name)

query = { deleted: 1 }
query[:rev] = lastrev.value('srcmd5') if lastrev
meta = PackageMetaFile.new(project_name: project, package_name: name).to_s(query)
meta = PackageMetaFile.new(project_name: project, package_name: name).content(query)
raise Package::UnknownObjectError, "#{project}/#{name}" unless meta

return true if User.current.is_admin?
Expand Down
20 changes: 0 additions & 20 deletions src/api/app/models/build_reason_file.rb

This file was deleted.

19 changes: 9 additions & 10 deletions src/api/app/models/package.rb
Expand Up @@ -362,8 +362,8 @@ def changes_files
def commit_message(target_project, target_package)
result = ''
changes_files.each do |changes_file|
source_changes = PackageFile.new(package_name: name, project_name: project.name, name: changes_file).to_s
target_changes = PackageFile.new(package_name: target_package, project_name: target_project, name: changes_file).to_s
source_changes = PackageFile.new(package_name: name, project_name: project.name, name: changes_file).content
target_changes = PackageFile.new(package_name: target_package, project_name: target_project, name: changes_file).content
result << source_changes.try(:chomp, target_changes)
end
# Remove header and empty lines
Expand Down Expand Up @@ -960,7 +960,7 @@ def jobhistory_list(project, repository, arch, options = {})

def service_error(revision = nil)
revision ||= serviceinfo.try { to_hash['xsrcmd5'] }
PackageServiceErrorFile.new(project_name: project.name, package_name: name).to_s(rev: revision)
PackageServiceErrorFile.new(project_name: project.name, package_name: name).content(rev: revision)
end

# local mode (default): last package in link chain in my project
Expand Down Expand Up @@ -1450,14 +1450,13 @@ def self.what_depends_on(project, package, repository, architecture)
def last_build_reason(repo, arch, package_name = nil)
repo = repo.name if repo.is_a? Repository

xml_data = BuildReasonFile.new(
project_name: project.name,
package_name: package_name || name,
repo: repo,
arch: arch
)
begin
build_reason = Backend::Api::BuildResults::Status.build_reason(project.name, package_name || name, repo, arch)
rescue ActiveXML::Transport::NotFoundError
return PackageBuildReason.new
end

data = Xmlhash.parse(xml_data.to_s)
data = Xmlhash.parse(build_reason)
# ensure that if 'packagechange' exists, it is an Array and not a Hash
# Bugreport: https://github.com/openSUSE/open-build-service/issues/3230
data['packagechange'] = [data['packagechange']] if data && data['packagechange'].is_a?(Hash)
Expand Down
10 changes: 5 additions & 5 deletions src/api/app/models/project.rb
Expand Up @@ -132,7 +132,7 @@ def self.home?(name)
def self.deleted?(project_name)
return false if find_by_name(project_name)

response = ProjectFile.new(project_name: project_name, name: '_history').to_s(deleted: 1)
response = ProjectFile.new(project_name: project_name, name: '_history').content(deleted: 1)
return false unless response

!Xmlhash.parse(response).empty?
Expand All @@ -145,14 +145,14 @@ def self.restore(project_name, backend_opts = {})
project = Project.new(name: project_name)

Project.transaction do
project.update_from_xml!(Xmlhash.parse(project.meta.to_s))
project.update_from_xml!(Xmlhash.parse(project.meta.content))
project.store

# restore all package meta data objects in DB
backend_packages = Collection.find(:package, match: "@project='#{project_name}'")
backend_packages.each('package') do |package|
package = project.packages.new(name: package.value(:name))
package_meta = Xmlhash.parse(package.meta.to_s)
package_meta = Xmlhash.parse(package.meta.content)

Package.transaction do
package.update_from_xml(package_meta)
Expand Down Expand Up @@ -1037,7 +1037,7 @@ def branch_local_repositories(project, pkg_to_enable, opts = {})

def branch_remote_repositories(project)
remote_project = Project.new(name: project)
remote_project_meta = Nokogiri::XML(remote_project.meta.to_s)
remote_project_meta = Nokogiri::XML(remote_project.meta.content)
local_project_meta = Nokogiri::XML(to_axml)

remote_repositories = remote_project.repositories_from_meta
Expand Down Expand Up @@ -1079,7 +1079,7 @@ def meta

def repositories_from_meta
result = []
Nokogiri::XML(meta.to_s).xpath('//repository').each do |repo|
Nokogiri::XML(meta.content).xpath('//repository').each do |repo|
result.push(repo.attributes.values.first.to_s)
end
result
Expand Down
4 changes: 4 additions & 0 deletions src/api/lib/backend/api/build_results/status.rb
Expand Up @@ -18,6 +18,10 @@ def self.job_status(project_name, package_name, repository_name, architecture_na
http_get(['/build/:project/:repository/:architecture/:package/_jobstatus', project_name, repository_name, architecture_name, package_name])
end

def self.build_reason(project_name, package_name, repository_name, architecture_name)
http_get(['/build/:project/:repository/:architecture/:package/_reason', project_name, repository_name, architecture_name, package_name])
end

# Returns the result view for a build
# @return [String]
def self.build_result(project_name, package_name, repository_name, architecture_name)
Expand Down
6 changes: 3 additions & 3 deletions src/api/lib/backend/file.rb
Expand Up @@ -55,10 +55,10 @@ def file(query = {})
nil
end

# Converts file into a String if it's valid
def to_s(query = {})
# Converts file into a String if it's valid and nil if it's not
def content(query = {})
file(query)
!@file.nil? && valid? ? ::File.open(@file.path).read : nil
@file && valid? ? ::File.open(@file.path).read : nil
end

# Reloads from Backend the file content
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -43,7 +43,7 @@
end

it { expect(response).to be_success }
it { expect(project.config.to_s).to include('Updated', 'by', 'test') }
it { expect(project.config.content).to include('Updated', 'by', 'test') }
end
end
end
8 changes: 4 additions & 4 deletions src/api/spec/models/backend/file_spec.rb
Expand Up @@ -157,7 +157,7 @@
subject.file
end

it { expect(subject.to_s).to be_nil }
it { expect(subject.content).to be_nil }
end
end

Expand All @@ -166,7 +166,7 @@
before do
login user

@previous_content = subject.to_s
@previous_content = subject.content
subject.save({}, 'hello') # Change the content of the file
end

Expand All @@ -177,7 +177,7 @@
describe '#save!' do
context 'with a string as content' do
before do
@previous_content = subject.to_s
@previous_content = subject.content
subject.save!({}, 'hello') # Change the content of the file with a string
end

Expand All @@ -187,7 +187,7 @@

context 'with a file as content' do
before do
@previous_content = subject.to_s
@previous_content = subject.content

subject.file = File.open(fake_file.path)
subject.save!
Expand Down

0 comments on commit 4eece6a

Please sign in to comment.