Skip to content

Commit b827e80

Browse files
authored
Change the gem publishing such that it changes the executable permissions if they are incorrect (#1228)
1 parent cf5c3f7 commit b827e80

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

ruby/Rakefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ task extract: [:fetch] do
8484
File.open(target_file, "rb") do |file|
8585
Gem::Package.new("").extract_tar_gz(file, target_directory)
8686
end
87+
88+
# Fix file permissions after extraction
89+
puts "Fixing file permissions in #{target_directory}"
90+
Helpers.fix_file_permissions(target_directory)
8791
end
8892
end
8993

@@ -140,6 +144,9 @@ task push_to_rubygems: [
140144
end
141145

142146
module Helpers
147+
# Files that should have executable permissions (755) in the gem
148+
EXECUTABLE_FILES = ["libdatadog-crashtracking-receiver", "libdatadog_profiling.so"].freeze
149+
143150
def self.each_github_release_variant
144151
LIB_GITHUB_RELEASES.each do |variant|
145152
file = variant.fetch(:file)
@@ -169,6 +176,29 @@ module Helpers
169176
puts("-" * 80)
170177
end
171178

179+
def self.fix_file_permissions(directory)
180+
Dir.glob("#{directory}/**/*").each do |path|
181+
next unless File.file?(path)
182+
183+
filename = File.basename(path)
184+
current_permissions = File.stat(path).mode & 0777
185+
186+
if EXECUTABLE_FILES.include?(filename)
187+
# Should be executable (755), fix if not
188+
if current_permissions != 0755
189+
puts "Fixing permissions for #{filename}: #{current_permissions.to_s(8)} -> 755"
190+
FileUtils.chmod(0755, path)
191+
end
192+
else
193+
# Should be non-executable (644), fix if not
194+
if current_permissions != 0644
195+
puts "Fixing permissions for #{filename}: #{current_permissions.to_s(8)} -> 644"
196+
FileUtils.chmod(0644, path)
197+
end
198+
end
199+
end
200+
end
201+
172202
def self.files_for(
173203
*included_platforms,
174204
excluded_files: [

ruby/spec/gem_packaging.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
RSpec.describe "gem release process (after packaging)" do
1010
let(:gem_version) { Libdatadog::VERSION }
1111
let(:packaged_gem_file) { "pkg/libdatadog-#{gem_version}.gem" }
12-
let(:executable_permissions) { ["libdatadog-crashtracking-receiver", "libdatadog_profiling.so"] }
1312

1413
it "sets the right permissions on the .gem files" do
1514
gem_files = Dir.glob("pkg/*.gem")
@@ -24,7 +23,7 @@
2423
filename = entry.header.name.split("/").last
2524
octal_permissions = entry.header.mode.to_s(8)[-3..-1]
2625

27-
expected_permissions = executable_permissions.include?(filename) ? "755" : "644"
26+
expected_permissions = Helpers::EXECUTABLE_FILES.include?(filename) ? "755" : "644"
2827

2928
expect(octal_permissions).to eq(expected_permissions),
3029
"Unexpected permissions for #{filename} inside #{gem_file} (got #{octal_permissions}, " \

0 commit comments

Comments
 (0)