diff options
author | Filipe Brandenburger <filbranden@google.com> | 2018-03-12 00:23:21 -0700 |
---|---|---|
committer | Filipe Brandenburger <filbranden@google.com> | 2018-04-18 11:44:54 -0700 |
commit | 59b0fa9722c92f2df76dc87f7a4f0afbce4bd6fa (patch) | |
tree | 5298931668940d7b8ffe963b5afb2e11f822f8ae | |
parent | b0382733d80e4963036a6abd4f475ebbea67d72c (diff) | |
download | meson-59b0fa9722c92f2df76dc87f7a4f0afbce4bd6fa.zip meson-59b0fa9722c92f2df76dc87f7a4f0afbce4bd6fa.tar.gz meson-59b0fa9722c92f2df76dc87f7a4f0afbce4bd6fa.tar.bz2 |
Add a unit test for install_umask.
This test copies a src tree using umask of 002, then runs the build and
install under umask 027. It ensures that the default install_umask of
022 is still applied to all files and directories in the install tree.
-rwxr-xr-x | run_unittests.py | 68 | ||||
-rw-r--r-- | test cases/unit/24 install umask/datafile.cat | 1 | ||||
-rw-r--r-- | test cases/unit/24 install umask/meson.build | 7 | ||||
-rw-r--r-- | test cases/unit/24 install umask/myinstall.py | 17 | ||||
-rw-r--r-- | test cases/unit/24 install umask/prog.1 | 1 | ||||
-rw-r--r-- | test cases/unit/24 install umask/prog.c | 3 | ||||
-rw-r--r-- | test cases/unit/24 install umask/sample.h | 6 | ||||
-rw-r--r-- | test cases/unit/24 install umask/subdir/datafile.dog | 1 | ||||
-rwxr-xr-x | test cases/unit/24 install umask/subdir/sayhello | 2 |
9 files changed, 106 insertions, 0 deletions
diff --git a/run_unittests.py b/run_unittests.py index e0cd1ec..bb18f11 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -2669,6 +2669,74 @@ class LinuxlikeTests(BasePlatformTests): # The chown failed nonfatally if we're not root self.assertEqual(0, statf.st_uid) + def test_install_umask(self): + ''' + Test that files are installed with correct permissions using default + install umask of 022, regardless of the umask at time the worktree + was checked out or the build was executed. + ''' + # Copy source tree to a temporary directory and change permissions + # there to simulate a checkout with umask 002. + orig_testdir = os.path.join(self.unit_test_dir, '24 install umask') + # Create a new testdir under tmpdir. + tmpdir = os.path.realpath(tempfile.mkdtemp()) + self.addCleanup(windows_proof_rmtree, tmpdir) + testdir = os.path.join(tmpdir, '24 install umask') + # Copy the tree using shutil.copyfile, which will use the current umask + # instead of preserving permissions of the old tree. + save_umask = os.umask(0o002) + self.addCleanup(os.umask, save_umask) + shutil.copytree(orig_testdir, testdir, copy_function=shutil.copyfile) + # Preserve the executable status of subdir/sayhello though. + os.chmod(os.path.join(testdir, 'subdir', 'sayhello'), 0o775) + self.init(testdir) + # Run the build under a 027 umask now. + os.umask(0o027) + self.build() + # And keep umask 027 for the install step too. + self.install() + + for executable in [ + 'bin/prog', + 'share/subdir/sayhello', + ]: + f = os.path.join(self.installdir, 'usr', *executable.split('/')) + found_mode = stat.filemode(os.stat(f).st_mode) + want_mode = '-rwxr-xr-x' + self.assertEqual(want_mode, found_mode, + msg=('Expected file %s to have mode %s but found %s instead.' % + (executable, want_mode, found_mode))) + + for directory in [ + 'usr', + 'usr/bin', + 'usr/include', + 'usr/share', + 'usr/share/man', + 'usr/share/man/man1', + 'usr/share/subdir', + ]: + f = os.path.join(self.installdir, *directory.split('/')) + found_mode = stat.filemode(os.stat(f).st_mode) + want_mode = 'drwxr-xr-x' + self.assertEqual(want_mode, found_mode, + msg=('Expected directory %s to have mode %s but found %s instead.' % + (directory, want_mode, found_mode))) + + for datafile in [ + 'include/sample.h', + 'share/datafile.cat', + 'share/file.dat', + 'share/man/man1/prog.1.gz', + 'share/subdir/datafile.dog', + ]: + f = os.path.join(self.installdir, 'usr', *datafile.split('/')) + found_mode = stat.filemode(os.stat(f).st_mode) + want_mode = '-rw-r--r--' + self.assertEqual(want_mode, found_mode, + msg=('Expected file %s to have mode %s but found %s instead.' % + (datafile, want_mode, found_mode))) + def test_cpp_std_override(self): testdir = os.path.join(self.unit_test_dir, '6 std override') self.init(testdir) diff --git a/test cases/unit/24 install umask/datafile.cat b/test cases/unit/24 install umask/datafile.cat new file mode 100644 index 0000000..53d81fc --- /dev/null +++ b/test cases/unit/24 install umask/datafile.cat @@ -0,0 +1 @@ +Installed cat is installed. diff --git a/test cases/unit/24 install umask/meson.build b/test cases/unit/24 install umask/meson.build new file mode 100644 index 0000000..225f71c --- /dev/null +++ b/test cases/unit/24 install umask/meson.build @@ -0,0 +1,7 @@ +project('install umask', 'c') +executable('prog', 'prog.c', install : true) +install_headers('sample.h') +install_man('prog.1') +install_data('datafile.cat', install_dir : get_option('prefix') + '/share') +install_subdir('subdir', install_dir : get_option('prefix') + '/share') +meson.add_install_script('myinstall.py', 'share', 'file.dat') diff --git a/test cases/unit/24 install umask/myinstall.py b/test cases/unit/24 install umask/myinstall.py new file mode 100644 index 0000000..db6a51c --- /dev/null +++ b/test cases/unit/24 install umask/myinstall.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 + +import os +import sys + +prefix = os.environ['MESON_INSTALL_DESTDIR_PREFIX'] + +dirname = os.path.join(prefix, sys.argv[1]) + +try: + os.makedirs(dirname) +except FileExistsError: + if not os.path.isdir(dirname): + raise + +with open(os.path.join(dirname, sys.argv[2]), 'w') as f: + f.write('') diff --git a/test cases/unit/24 install umask/prog.1 b/test cases/unit/24 install umask/prog.1 new file mode 100644 index 0000000..08ef7da --- /dev/null +++ b/test cases/unit/24 install umask/prog.1 @@ -0,0 +1 @@ +Man up, you. diff --git a/test cases/unit/24 install umask/prog.c b/test cases/unit/24 install umask/prog.c new file mode 100644 index 0000000..0f0061d --- /dev/null +++ b/test cases/unit/24 install umask/prog.c @@ -0,0 +1,3 @@ +int main(int argc, char **arv) { + return 0; +} diff --git a/test cases/unit/24 install umask/sample.h b/test cases/unit/24 install umask/sample.h new file mode 100644 index 0000000..dc030da --- /dev/null +++ b/test cases/unit/24 install umask/sample.h @@ -0,0 +1,6 @@ +#ifndef SAMPLE_H +#define SAMPLE_H + +int wackiness(); + +#endif diff --git a/test cases/unit/24 install umask/subdir/datafile.dog b/test cases/unit/24 install umask/subdir/datafile.dog new file mode 100644 index 0000000..7a5bcb7 --- /dev/null +++ b/test cases/unit/24 install umask/subdir/datafile.dog @@ -0,0 +1 @@ +Installed dog is installed. diff --git a/test cases/unit/24 install umask/subdir/sayhello b/test cases/unit/24 install umask/subdir/sayhello new file mode 100755 index 0000000..1e1c90a --- /dev/null +++ b/test cases/unit/24 install umask/subdir/sayhello @@ -0,0 +1,2 @@ +#!/bin/sh +echo 'Hello, World!' |