1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 03:23:01 +02:00
Commit Graph

159 Commits

Author SHA1 Message Date
James Henderson
dff2d6c589 [Support] Add support for getting file system permissions on Windows and implement sys::fs::set/getPermissions to work with them
This change adds support for functions to set and get file permissions, in a similar manner to the C++17 permissions() function in <filesystem>. The setter uses chmod on Unix systems and SetFileAttributes on Windows, setting the permissions as passed in. The getter simply uses the existing status() function.

Prior to this change, status() would always return an unknown value for the permissions on a Windows file, making it impossible to test the new function on Windows. I have therefore added support for this as well. On Linux, prior to this change, the permissions included the file type, which should actually be accessed via a different member of the file_status class.

Note that on Windows, only the *_write permission bits have any affect - if any are set, the file is writable, and if not, the file is read-only. This is in common with what MSDN describes for their behaviour of std::filesystem::permissions(), and also what boost::filesystem does.

The motivation behind this change is so that we can easily test behaviour on read-only files in LLVM unit tests, but I am sure that others may find it useful in some situations.

Reviewers: zturner, amccarth, aaron.ballman

Differential Revision: https://reviews.llvm.org/D30736

llvm-svn: 297945
2017-03-16 11:22:09 +00:00
Juergen Ributzka
7fb2de4316 [Support] Make the SystemZ bot happy by using make_error_code.
This should fix the last issue on the SystemZ bot related to the broken symlink
test.

llvm-svn: 297767
2017-03-14 18:37:44 +00:00
Juergen Ributzka
054e583082 [Support] Follow-up for "Test directory iterators and recursive directory iterators with broken symlinks."
Fix the test by sorting the result vector.

llvm-svn: 297672
2017-03-13 21:40:20 +00:00
Juergen Ributzka
036b9677ed [Support] Test directory iterators and recursive directory iterators with broken symlinks.
This commit adds a unit test to the file system tests to verify the behavior of
the directory iterator and recursive directory iterator with broken symlinks.

This test is Unix only.

llvm-svn: 297669
2017-03-13 21:34:07 +00:00
Aaron Ballman
310244c642 Reverting r297617 because it broke some bots:
http://bb.pgr.jp/builders/cmake-llvm-x86_64-linux/builds/49970

llvm-svn: 297618
2017-03-13 12:24:51 +00:00
Aaron Ballman
6055e8d677 Add support for getting file system permissions and implement sys::fs::permissions to set them.
Patch by James Henderson.

llvm-svn: 297617
2017-03-13 12:17:14 +00:00
Zachary Turner
514d25ac05 Fix test failure when Home directory cannot be found.
llvm-svn: 297484
2017-03-10 17:47:13 +00:00
Zachary Turner
1f4e8c928a Add llvm::sys::fs::real_path.
LLVM already has real_path like functionality, but it is
cumbersome to use and involves clean up after (e.g. you have
to call openFileForRead, then close the resulting FD).

Furthermore, on Windows it doesn't work for directories since
opening a directory and opening a file require slightly
different flags.

So I add a simple function `real_path` which works for all
paths on all platforms and has a simple to use interface.

In doing so, I add the ability to opt in to resolving tilde
expressions (e.g. ~/foo), which are normally handled by
the shell.

Differential Revision: https://reviews.llvm.org/D30668

llvm-svn: 297483
2017-03-10 17:39:21 +00:00
Zachary Turner
7dad21d20f [Support] Add llvm::sys::fs::remove_directories.
We already have a function create_directories() which can create
an entire tree, and remove() which can remove an empty directory,
but we do not have remove_directories() which can remove an entire
tree.  This patch adds such a function.

Because removing a directory tree can have dangerous consequences
when the tree contains a directory symlink, the patch here updates
the existing directory_iterator construct to optionally not follow
symlinks (previously it would always follow symlinks).  The delete
algorithm uses this flag so that for symlinks, only the links are
removed, and not the targets.

On Windows this is implemented with SHFileOperation, which also
does not recurse into symbolic links or junctions.

Differential Revision: https://reviews.llvm.org/D30676

llvm-svn: 297314
2017-03-08 22:49:32 +00:00
Jonas Hahnfeld
c9a8650f00 [Support] Remove unit test for fs::is_local
rL295768 introduced this test that fails if LLVM is built and tested on
an NFS share. Delete the test as discussed on the corresponing commit
thread. The only feasible solution would have been to introduce
environment variables and to en/disable the test conditionally.

llvm-svn: 297260
2017-03-08 08:36:21 +00:00
Serge Pavlov
650342e8ee Process tilde in llvm::sys::path::native
Windows does not treat `~` as a reference to home directory, so the call
to `llvm::sys::path::native` on, say, `~/somedir` produces `~\somedir`,
which has different meaning than the original path. With this change
tilde is expanded on Windows to user profile directory. Such behavior
keeps original meaning of the path and is consistent with the algorithm
of `llvm::sys::path::home_directory`.

Differential Revision: https://reviews.llvm.org/D27527

llvm-svn: 296590
2017-03-01 09:38:15 +00:00
Simon Dardis
91fde907bf [Support] XFAIL is_local for mips
is_local can't pass on some our buildbots as some of our buildbots use network
shares for building and testing LLVM.

llvm-svn: 295840
2017-02-22 14:34:45 +00:00
Zachary Turner
1d2f86a79f [Support] Add a function to check if a file resides locally.
Differential Revision: https://reviews.llvm.org/D30010

llvm-svn: 295768
2017-02-21 20:55:47 +00:00
Pavel Labath
8be3755941 Fix fs::set_current_path unit test
The test fails when there is a symlink on the path because then the path
returned by current_path will not match the one we have set. Instead of
doing a string match check the unique id of the two files.

llvm-svn: 292916
2017-01-24 11:35:26 +00:00
Pavel Labath
04a50db5e5 [Support] Add sys::fs::set_current_path() (aka chdir)
Summary:
This adds a cross-platform way of setting the current working directory
analogous to the existing current_path() function used for retrieving
it. The function will be used in lldb.

Reviewers: rafael, silvas, zturner

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D29035

llvm-svn: 292907
2017-01-24 10:32:03 +00:00
Benjamin Kramer
d49808acaf [Support] remove_dots: Remove windows test.
Windows doesn't have roots, so I think this test doesn't make sense
there.

llvm-svn: 284386
2016-10-17 13:57:16 +00:00
Benjamin Kramer
dbfa1b204a [Support] remove_dots: Remove .. from absolute paths.
/../foo is still a proper path after removing the dotdot. This should
now finally match https://9p.io/sys/doc/lexnames.html [Cleaning names].

llvm-svn: 284384
2016-10-17 13:28:21 +00:00
Justin Bogner
5e39c399de unittests: Explicitly ignore some return values in crash tests
Ideally these would actually check that the results are reasonable,
but given that we're looping over so many different kinds of path that
isn't really practical.

llvm-svn: 284350
2016-10-16 22:09:24 +00:00
Eric Liu
d7954a6a21 Do not delete leading ../ in remove_dots.
Reviewers: bkramer

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D25561

llvm-svn: 284129
2016-10-13 15:07:14 +00:00
Reid Kleckner
a24c77d404 Fix a real temp file leak in FileOutputBuffer
If we failed to commit the buffer but did not die to a signal, the temp
file would remain on disk on Windows. Having an open file mapping and
file handle prevents the file from being deleted. I am choosing not to
add an assertion of success on the temp file removal, since virus
scanners and other environmental things can often cause removal to fail
in real world tools.

Also fix more temp file leaks in unit tests.

llvm-svn: 280445
2016-09-02 01:10:53 +00:00
Reid Kleckner
e90901530b Try to fix some temp file leaks in SupportTests, PR18335
llvm-svn: 280443
2016-09-02 00:51:34 +00:00
David Majnemer
85242fb9f9 Use the range variant of find instead of unpacking begin/end
If the result of the find is only used to compare against end(), just
use is_contained instead.

No functionality change is intended.

llvm-svn: 278433
2016-08-11 22:21:41 +00:00
Aaron Ballman
c014977a05 Switch to using an API that handles non-ASCII paths appropriately on Windows.
llvm-svn: 273262
2016-06-21 14:24:48 +00:00
Aaron Ballman
a72fbddfcb Fix a relatively nasty bug with fs::getPathFromOpenFD() on Windows. The GetFinalPathNameByHandle API does not behave as documented; if given a buffer that has enough space for the path but not the null terminator, the call will return the number of characters required *without* the null terminator (despite being documented otherwise) and it will not set GetLastError(). The result was that this function would return a bogus path and no error. Instead, ensure there is sufficient space for a null terminator (we already strip it off manually for compatibility with older versions of Windows).
llvm-svn: 273195
2016-06-20 20:28:49 +00:00
Taewook Oh
dbde0a1f7d In openFileForRead, attempt to fetch the actual name of the file on disk -- including case -- so that clang can later warn about non-portable #include and #import directives.
Differential Revision: http://reviews.llvm.org/D19842
Corresponding clang patch: http://reviews.llvm.org/D19843

Re-commit after addressing issues with of generating too many warnings for Windows and asan test failures

Patch by Eric Niebler

llvm-svn: 272555
2016-06-13 15:54:56 +00:00
Taewook Oh
798fe72f38 Revert commit r271704, a patch that enables warnings for non-portable #include and #import paths (Corresponding clang patch has been reverted by r271761). Patches are reverted because they generate lots of unadressable warnings for windows and fail tests under ASAN.
llvm-svn: 271764
2016-06-04 03:36:12 +00:00
Taewook Oh
0442d2071f In openFileForRead, attempt to fetch the actual name of the file on disk -- including case -- so that clang can later warn about non-portable #include and #import directives.
Differential Revision: http://reviews.llvm.org/D19842

Patch by Eric Niebler

llvm-svn: 271704
2016-06-03 18:38:39 +00:00
Teresa Johnson
8a51792cf4 [ThinLTO] Option to control path of distributed backend files
Summary:
Add support to control where files for a distributed backend (the
individual index files and optional imports files) are created.

This is invoked with a new thinlto-prefix-replace option in the gold
plugin and llvm-lto. If specified, expects a string of the form
"oldprefix:newprefix", and instead of generating these files in the
same directory path as the corresponding bitcode file, will use a path
formed by replacing the bitcode file's path prefix matching oldprefix
with newprefix.

Also add a new replace_path_prefix helper to Path.h in libSupport.

Depends on D19636.

Reviewers: joker.eph

Subscribers: llvm-commits, joker.eph

Differential Revision: http://reviews.llvm.org/D19644

llvm-svn: 269771
2016-05-17 14:45:30 +00:00
Bruno Cardoso Lopes
8b294ba100 [Support][Unittests] Add unittest for recursive_directory_iterator::level()
llvm-svn: 269488
2016-05-13 21:31:32 +00:00
Nico Weber
992481bdd0 Unbreak building unit tests on Windows after r266595.
llvm-svn: 266614
2016-04-18 13:54:50 +00:00
Etienne Bergeron
159be8f3fc [Support] Fix an invalid character escaping in string literal (unittest).
Summary:
A character within a string literal is not escaped correctly.
In this case, there is no semantic change because the invalid character turn out to be NUL anyway.

note: "\0x12" is equivalent to {0, 'x', '1', '2'} and not { 12 }.

This issue was found by clang-tidy.

Reviewers: rnk

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D18747

llvm-svn: 265376
2016-04-05 01:46:26 +00:00
Reid Kleckner
109dc763a3 Fix a -Wsign-compare in Support Path unittests
llvm-svn: 260418
2016-02-10 19:29:01 +00:00
Kevin Enderby
1a3115548c Fix identify_magic() to check that a file that starts with MH_MAGIC is
at least as big as the mach header to be identified as a Mach-O file and
make sure smaller files are not identified as a Mach-O files but as
unknown files. Also fix identify_magic() so it looks at all 4 bytes of
the filetype field when determining the type of the Mach-O file.
Then fix the macho-invalid-header test case to check that it is an
unknown file and make sure it does not get the error for
object_error::parse_failed.  And also update the unit tests.

llvm-svn: 258883
2016-01-26 23:43:37 +00:00
David Blaikie
d6549131aa Fix -Wunused-function in a non-Win32 build
llvm-svn: 253373
2015-11-17 20:38:54 +00:00
Pawel Bylica
0fc3130a5d [Support] Tweak path::system_temp_directory() on Windows.
Summary:
This patch changes the behavior of path::system_temp_directory() on Windows to be closer to GetTempPath Windows API call. Enforces path separator to be the native one, makes path absolute, etc. GetTempPath is not used directly because of limitations/implementation bugs on Windows 7.

Windows specific unit tests are added. Most of them runs in separated process with modified environment variables.

This change fixes FileSystemTest.CreateDir unittest that had been failing when run from Unix-like shell on Windows (Unix-like path separator (/) used in env variables).

Reviewers: chapuni, rafael, aaron.ballman

Subscribers: rafael, llvm-commits

Differential Revision: http://reviews.llvm.org/D14231

llvm-svn: 253345
2015-11-17 16:54:32 +00:00
Mike Aizatsky
733b1a089d Windows-specific test for sys::path::remove_dots.
Differential Revision: http://reviews.llvm.org/D14503

llvm-svn: 252504
2015-11-09 19:36:53 +00:00
Mike Aizatsky
e7f6232199 Moving FileManager::removeDotPaths to llvm::sys::path::remove_dots
Differential Revision: http://reviews.llvm.org/D14393

llvm-svn: 252499
2015-11-09 18:56:31 +00:00
Pawel Bylica
8f0fab0cec Revert r252366: [Support] Use GetTempDir to get the temporary dir path on Windows.
llvm-svn: 252367
2015-11-06 23:44:23 +00:00
Pawel Bylica
ba564b0007 [Support] Use GetTempDir to get the temporary dir path on Windows.
Summary:
In general GetTempDir follows the same logic as the replaced code: checks env variables TMP, TEMP, USERPROFILE in order. However, it also perform other checks like making separators native (\), making the path absolute, etc.

This change fixes FileSystemTest.CreateDir unittest that had been failing when run from Unix-like shell on Windows (Unix-like path separator (/) used in env variables).

Reviewers: chapuni, rafael, aaron.ballman

Subscribers: rafael, llvm-commits

Differential Revision: http://reviews.llvm.org/D14231

llvm-svn: 252366
2015-11-06 23:21:49 +00:00
Pawel Bylica
669b84345b [Support] Extend sys::path with user_cache_directory function.
Summary:
The new function sys::path::user_cache_directory tries to discover
a directory suitable for cache storage for current system user.

On Windows and Darwin it returns a path to system-specific user cache directory.

On Linux it follows XDG Base Directory Specification, what is:
- use non-empty $XDG_CACHE_HOME env var,
- use $HOME/.cache.

Reviewers: chapuni, aaron.ballman, rafael

Subscribers: rafael, aaron.ballman, llvm-commits

Differential Revision: http://reviews.llvm.org/D13801

llvm-svn: 251784
2015-11-02 09:49:17 +00:00
Pawel Bylica
acca575c03 Fix path::home_directory() unit test.
It turns out that constructing std::string from null pointer is not the very best idea.

llvm-svn: 250506
2015-10-16 10:11:07 +00:00
NAKAMURA Takumi
996d217689 SupportTests::HomeDirectory: Don't try tests when $HOME is undefined.
Lit sanitizes env vars. $HOME is not exported in Lit tests.

llvm-svn: 250505
2015-10-16 09:40:01 +00:00
NAKAMURA Takumi
56bba74d41 Reformat.
llvm-svn: 250504
2015-10-16 09:38:49 +00:00
Pawel Bylica
0c0a1631af Use Windows Vista API to get the user's home directory
Summary: This patch replaces usage of deprecated SHGetFolderPathW with SHGetKnownFolderPath. The usage of SHGetKnownFolderPath is wrapped to allow queries for other "known" folders in the near future.

Reviewers: aaron.ballman, gbedwell

Subscribers: chapuni, llvm-commits

Differential Revision: http://reviews.llvm.org/D13753

llvm-svn: 250501
2015-10-16 09:08:59 +00:00
Benjamin Kramer
c91eff2e79 Make test resilient against windows path separators.
llvm-svn: 249320
2015-10-05 14:15:13 +00:00
Benjamin Kramer
cb7a29d22e [Support] Add a version of fs::make_absolute with a custom CWD.
This will be used soon from clang.

llvm-svn: 249309
2015-10-05 13:02:43 +00:00
Chandler Carruth
c484a28f0a [ADT] Switch a bunch of places in LLVM that were doing single-character
splits to actually use the single character split routine which does
less work, and in a debug build is *substantially* faster.

llvm-svn: 247245
2015-09-10 06:12:31 +00:00
Douglas Katzman
f33b44fd2f Move twice-repeated clang path operation into a new function.
And make it more robust in the edge case of exactly "./" as input.

llvm-svn: 246711
2015-09-02 21:02:10 +00:00
Frederic Riss
6027545a69 Thread premissions through sys::fs::create_director{y|ies}
llvm-svn: 244268
2015-08-06 21:04:55 +00:00
NAKAMURA Takumi
6ed243a1a2 llvm/unittests/Support/Path.cpp: Use <windows.h> instead of <Windows.h>.
llvm-svn: 239804
2015-06-16 06:46:16 +00:00