Skip to content

Commit d5eda97

Browse files
committed
fix archive permissions for ruby tar.gz roots
1 parent bd1658b commit d5eda97

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

pre_commit/resources/rbenv.tar.gz

26 Bytes
Binary file not shown.
55 Bytes
Binary file not shown.
190 Bytes
Binary file not shown.

testing/make-archives

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,20 @@ def make_archive(name: str, repo: str, ref: str, destdir: str) -> str:
3535
"""
3636
output_path = os.path.join(destdir, f'{name}.tar.gz')
3737
with tempfile.TemporaryDirectory() as tmpdir:
38+
# this ensures that the root directory has umask permissions
39+
gitdir = os.path.join(tmpdir, 'root')
40+
3841
# Clone the repository to the temporary directory
39-
subprocess.check_call(('git', 'clone', repo, tmpdir))
40-
subprocess.check_call(('git', '-C', tmpdir, 'checkout', ref))
42+
subprocess.check_call(('git', 'clone', repo, gitdir))
43+
subprocess.check_call(('git', '-C', gitdir, 'checkout', ref))
4144

4245
# We don't want the '.git' directory
4346
# It adds a bunch of size to the archive and we don't use it at
4447
# runtime
45-
shutil.rmtree(os.path.join(tmpdir, '.git'))
48+
shutil.rmtree(os.path.join(gitdir, '.git'))
4649

4750
with tarfile.open(output_path, 'w|gz') as tf:
48-
tf.add(tmpdir, name)
51+
tf.add(gitdir, name)
4952

5053
return output_path
5154

tests/languages/ruby_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os.path
2+
import tarfile
23
from unittest import mock
34

45
import pytest
@@ -8,6 +9,7 @@
89
from pre_commit.languages import ruby
910
from pre_commit.prefix import Prefix
1011
from pre_commit.util import cmd_output
12+
from pre_commit.util import resource_bytesio
1113
from testing.util import xfailif_windows
1214

1315

@@ -72,3 +74,14 @@ def test_install_ruby_with_version(fake_gem_prefix):
7274
# Should be able to activate and use rbenv install
7375
with ruby.in_env(fake_gem_prefix, '2.7.2'):
7476
cmd_output('rbenv', 'install', '--help')
77+
78+
79+
@pytest.mark.parametrize(
80+
'filename',
81+
('rbenv.tar.gz', 'ruby-build.tar.gz', 'ruby-download.tar.gz'),
82+
)
83+
def test_archive_root_stat(filename):
84+
with resource_bytesio(filename) as f:
85+
with tarfile.open(fileobj=f) as tarf:
86+
root, _, _ = filename.partition('.')
87+
assert oct(tarf.getmember(root).mode) == '0o755'

0 commit comments

Comments
 (0)