summaryrefslogtreecommitdiff
path: root/src/buildstream/utils.py
Commit message (Collapse)AuthorAgeFilesLines
* utils.py: Use `onerror` in `_force_rmtree`Tristan Maat2019-12-171-11/+16
| | | | | | | | | If we don't, and encounter a file we don't own, but have permission to delete, we'll fail with EPERM, since we won't be able to change permissions but will be able to delete it. Instead, we now try to change permissions and remove a file *after* we realize we couldn't at first.
* utils.py: safe_link(): Copy if hardlink creation is not permittedJürg Billeter2019-12-031-1/+1
| | | | | | | | | | | By default, Linux doesn't allow creating hardlinks to read-only files of other users since Linux 3.6 (see /proc/sys/fs/protected_hardlinks). This fixes staging when buildbox-casd is running as a separate user and the traditional bubblewrap sandboxing backend is used. This combination is not recommended, however, it's triggered in CI by docker images that run buildbox-casd as a separate user and a few test cases that override BST_FORCE_SANDBOX.
* casserver.py: Proxy CAS requests to buildbox-casdTristan Maat2019-12-031-0/+38
|
* lint: remove all unecessary elif/else after break/continueBenjamin Schubert2019-12-021-3/+3
| | | | | Newer pylint versions detect and complain about unnecessary elif/else after a continue/break/return clause. Let's remove them
* utils.py: Respect umask in _tempdir()Jürg Billeter2019-11-251-1/+18
| | | | | | | This allows access by buildbox-casd running as different user with a suitable umask. As this is not generally safe in global temp directories such as /tmp, make the `dir` parameter mandatory and add a note to the documentation.
* utils.py: Respect umask in save_file_atomic()Jürg Billeter2019-11-251-0/+2
| | | | This allows access by buildbox-casd running as different user.
* utils.py: Add get_umask() methodJürg Billeter2019-11-251-0/+16
|
* Reformat code using BlackChandan Singh2019-11-141-121/+144
| | | | | | | As discussed over the mailing list, reformat code using Black. This is a one-off change to reformat all our codebase. Moving forward, we shouldn't expect such blanket reformats. Rather, we expect each change to already comply with the Black formatting style.
* Address no-else-raise pylint warningJames Ennis2019-09-061-3/+3
| | | | | | | | | | | In the latest released version of pylint (2.3.x), the "no-else-raise" (R1720) warning has been introduced. See: http://pylint.pycqa.org/en/latest/whatsnew/changelog.html#what-s-new-in-pylint-2-3-0 There are many instances of this in our codebase, which this patch addresses.
* utils.py: Ensure dest copy directory is writableShahwat Dalal2019-09-051-1/+11
| | | | | | | | | | | | | In the case we are copying something to a read-only directory, `_copy_directories` fails. Copying should work regardless. Now when we are copying something to a read-only directory, we reset the permissions of the directory to writable, and then revert to the directory's original permissions after copying is completed. An example where this is nessesary is when extracting Docker layers. If one layer adds a read-only directory `/a` and the following layers adds `/a/foo`, we must be able to copy `foo` into the otherwise read-only directory, whilst still ensuring `/a` is read-only once the layer is staged.
* utils.py: Wait for threads to exit in _is_single_threaded()Jürg Billeter2019-09-041-3/+15
| | | | gRPC threads are not joined when shut down.
* utils.py: Add _is_single_threaded() methodJürg Billeter2019-09-031-0/+20
| | | | | This will be used to safeguard against fork issues with multiple threads.
* Add initial mypy configuration and typesChandan Singh2019-09-021-49/+69
| | | | | | | | | | As a first step, add type hints to variables whose type `mypy` cannot infer automatically. This is the minimal set of type hints that allow running `mypy` without any arguments, and having it not fail. We currently ignore C extensions that mypy can't process directly. Later, we can look into generating stubs for such modules (potentially automatically).
* buildstream/utils.py: Fix parameter types for calendar.timegmChandan Singh2019-09-021-1/+1
| | | | | `calendar.timegm()` accepts a tuple, but we were giving it a list. This was highlighted by `mypy`.
* utils: uppercase global _MAIN_PID, move to topAngelos Evripiotis2019-08-161-6/+5
| | | | This is consistent with the other global vars in the module.
* utils: Extract 'url_directory_name' to a cython moduleBenjamin Schubert2019-07-171-18/+4
| | | | | `url_directory_name` is heavily called from any downloadable source plugin, and moving it to cython gives a more than 10x speedup
* Allowing tar files to be compressedbecky/tar_compressionRebecca Grayson2019-07-161-0/+35
| | | | | | | Changes made to cli.py and _stream.py in order to support tar compression. Compression flag has been added, which overrides any file extensions given. Where no compression or file extension provided, default to uncompressed .tar.
* utils: add _tempnamedfile_name for win32 happinessAngelos Evripiotis2019-07-091-0/+60
| | | | | | | | Avoid a restriction of Windows that prevents us from using both the file descriptor and the file name of tempfile.NamedTemporaryFile. Provide a wrapper that only returns the temporary filename, and makes it easier to be windows-compatible.
* utils: fix yield type of _tempnamedfileAngelos Evripiotis2019-07-091-1/+1
|
* utils: indent 'with' continuation lineAngelos Evripiotis2019-07-091-1/+1
|
* utils.py: Make `magic_timestamp` a public variableshashwatdalal/make-magic-timestamp-publicShahwat Dalal2019-07-051-4/+3
| | | | | | | Some plugin elements, such as docker-element and tar-element, require to set `created` and/or `modified` meta-data fields. It would be nice to use `magic_timestamp` to ensure these fields are being set in a consistent and deterministic way.
* utils.py: Add write permission to root path in _force_rmtreeshashwatdalal/tar-file-extractionShahwat Dalal2019-07-041-0/+2
| | | | | This is needed in the case where the temp directory permissions are changed between creation and deletion.
* utils._get_volume_size: use shutil.disk_usageaevri/psutil_volumeAngelos Evripiotis2019-06-121-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | This is win32-friendly, less to read, and fixes a latent bug. Avoid dealing with low-level platform specifics by using the higher-level shutil.disk_usage() function to calc total and available bytes for us. shutil is also more correct - it uses f_frsize to convert from blocks to bytes, instead of f_bsize. I verified that the numbers match with the output from `df -k`, whereas the old implementation did not. Here are the meanings from `man statvfs`: f_frsize The size in bytes of the minimum unit of allocation on this file system. (This corresponds to the f_bsize member of struct statfs.) f_bsize The preferred length of I/O requests for files on this file system. (Corresponds to the f_iosize member of struct statfs.) Link to shutil.disk_usage() implementation: https://github.com/python/cpython/blob/3.5/Lib/shutil.py#L980
* utils.py: remove misleading documentationraoul/983-cas-source-stagingRaoul Hidalgo Charman2019-05-221-2/+2
| | | | | copy_files and link_files suggested that a single file path is a valid argument when it isn't.
* Move source from 'buildstream' to 'src/buildstream'Chandan Singh2019-05-211-0/+1293
This was discussed in #1008. Fixes #1009.