Skip to content

Commit

Permalink
Set directory ownership/permissions to match the filesystem package.
Browse files Browse the repository at this point in the history
Per the fedora package guidelines:
https://fedoraproject.org/wiki/Packaging:Guidelines#File_and_Directory_Ownership
this allows us to specify /opt in the spec file to support rpm5.
  • Loading branch information
Yvonne Lam committed Aug 17, 2015
1 parent c9937e6 commit 160389f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
24 changes: 20 additions & 4 deletions lib/omnibus/packagers/rpm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,29 @@ def config_files
end

#
# Exclude directories from the spec that are owned by the filesystem package:
# Directories owned by the filesystem package:
# http://fedoraproject.org/wiki/Packaging:Guidelines#File_and_Directory_Ownership
#
# @return [Array]
#
def filesystem_directories
@filesystem_directories ||= IO.readlines(resource_path('filesystem_list')).map! { |dirname| dirname.chomp }
@filesystem_directories ||= IO.readlines(resource_path('filesystem_list')).map { |f| f.chomp }
end

#
# Mark filesystem directories with ownership and permissions specified in the filesystem package
# https://git.fedorahosted.org/cgit/filesystem.git/plain/filesystem.spec
#
# @return [String]
#
def mark_filesystem_directories(fsdir)
if fsdir.eql?('/') || fsdir.eql?('/usr/lib') || fsdir.eql?('/usr/share/empty')
return "%dir %attr(555,root,root) #{fsdir}"
elsif filesystem_directories.include?(fsdir)
return "%dir %attr(0755,root,root) #{fsdir}"
else
return "%dir #{fsdir}"
end
end

#
Expand Down Expand Up @@ -350,12 +366,12 @@ def create_rpm_file
#
def build_filepath(path)
filepath = rpm_safe('/' + path.gsub("#{build_dir}/", ''))
return if config_files.include?(filepath) || filesystem_directories.include?(filepath)
return if config_files.include?(filepath)
full_path = build_dir + filepath.gsub('[%]','%')
# FileSyncer.glob quotes pathnames that contain spaces, which is a problem on el7
full_path.gsub!('"', '')
# Mark directories with the %dir directive to prevent rpmbuild from counting their contents twice.
return "%dir #{filepath}" if !File.symlink?(full_path) && File.directory?(full_path)
return mark_filesystem_directories(filepath) if !File.symlink?(full_path) && File.directory?(full_path)
filepath
end

Expand Down
9 changes: 6 additions & 3 deletions spec/unit/packagers/rpm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,17 @@ module Omnibus

context 'when leaf directories owned by the filesystem package are present' do
before do
create_file("#{staging_dir}/BUILD/opt")
create_directory("#{staging_dir}/BUILD/usr/lib")
create_directory("#{staging_dir}/BUILD/opt")
create_file("#{staging_dir}/BUILD/opt/thing")
end

it 'does not write them into the spec' do
it 'is written into the spec with ownership and permissions' do
subject.write_rpm_spec
contents = File.read(spec_file)

expect(contents).to_not include("/opt")
expect(contents).to include("%dir %attr(0755,root,root) /opt")
expect(contents).to include("%dir %attr(555,root,root) /usr/lib")
end
end
end
Expand Down

0 comments on commit 160389f

Please sign in to comment.