summaryrefslogtreecommitdiff
path: root/glib/tests/fileutils.c
Commit message (Collapse)AuthorAgeFilesLines
* gtestutils: Use $G_TEST_TMPDIR as temporary directory when definedMarco Trevisan (Treviño)2022-12-191-0/+4
| | | | | | | | | | | | During tests in which we are isolating directories, we may still create temporary files in the global temporary directory without cleaning them because the value returned by g_get_tmp_dir() is cached when we isolate the tests directory to the global TMPDIR. To ensure that we're always isolating the temporary directories, let's unset the cached temporary directory once we've defined $G_TEST_TMPDIR so that the returned value of g_get_tmpdir() can be recomputed using the test isolated temporary directory.
* fileutils test: Use no-op invalid-parameter handler when exercising EBADFSimon McVittie2022-11-031-0/+4
| | | | | | | This is basically !3036, but wasn't included there because !3036 and !3027 were developed in parallel. Signed-off-by: Simon McVittie <smcv@collabora.com>
* Merge branch 'fix-fileutils-test' into 'main'Simon McVittie2022-11-021-2/+8
|\ | | | | | | | | | | | | Clean up Windows Invalid Parameter Handler setup and fix fileutils test Closes #2800 See merge request GNOME/glib!3036
| * fileutils.c: Fix the clearfd test on WindowsChun-wei Fan2022-11-031-2/+8
| | | | | | | | | | | | | | | | | | ...when the test program aborts while checking the FD's were indeed closed, since we need to override the invalid parameter handler to do such checks, if the CRT demands so, so that the test program will proceed normally. This will fix issue #2800.
* | tests: Test EBADF and errno handling when closing fdsSimon McVittie2022-11-021-0/+79
|/ | | | Signed-off-by: Simon McVittie <smcv@collabora.com>
* Add a SPDX LicenseRef for the license historically used for testsSimon McVittie2022-11-021-0/+2
| | | | | | | | | | | | | Some of GLib's unit tests are under an apparently GLib-specific permissive license, vaguely similar to the BSD/MIT family but with the GPL's lack-of-warranty wording. This is not on SPDX's list of well-known licenses, so we need to use a custom license name prefixed with LicenseRef if we want to represent this in SPDX/REUSE syntax. Most of the newer tests seem to be licensed under LGPL-2.1-or-later instead. Signed-off-by: Simon McVittie <smcv@collabora.com>
* Merge branch 'nirbheek/gmodule-suffix-deprecation' into 'main'Marco Trevisan2022-10-271-2/+2
|\ | | | | | | | | | | | | Improve g_module_open(), deprecate G_MODULE_SUFFIX Closes #520 e #1413 See merge request GNOME/glib!2950
| * tests: Fix fileutils test on macOSNirbheek Chauhan2022-10-271-2/+2
| | | | | | | | It can return EROFS instead of EPERM too.
* | gstdio: Add g_clear_fd() and g_autofdSimon McVittie2022-10-261-0/+76
|/ | | | | | | | | | | | | | | | | Inspired by libglnx's glnx_close_fd() and glnx_autofd, these let us have the same patterns as g_clear_object() and g_autoptr(GObject), but for file descriptors. g_clear_fd() is cross-platform, while g_autofd is syntactic sugar requiring a supported compiler (gcc or clang). Now that g_close() checks for EBADF as a programming error, we can implement the equivalent of glnx_autofd as an inline function without needing to have errno and EBADF in the header file. g_clear_fd() is like glnx_close_fd(), but with error checking. The private _g_clear_fd_ignore_error() function used to implement g_autofd is a closer equivalent of glnx_close_fd(). Signed-off-by: Simon McVittie <smcv@collabora.com>
* tests: Check the return value of fwrite() in a testPhilip Withnall2022-10-131-1/+3
| | | | | | | | | Not that we ever expect it to fail. This is basically just to silence a compiler warning with `-Werror=unused-result`. Signed-off-by: Philip Withnall <pwithnall@endlessos.org> Helps: #2758
* glib/tests/fileutils: use g_assert_no_errno instead of manual checkingMarco Trevisan (Treviño)2022-07-061-2/+2
|
* glib/tests: Ensure that calls to write, system, symlink and pipe are checkedMarco Trevisan (Treviño)2022-07-061-6/+6
| | | | Assert that calls to such system calls are returning the expected values
* tests: Add a missing assertionPhilip Withnall2022-04-281-0/+1
| | | | | | | | This fixes a warning about a dead store to `newpath` from scan-build. Signed-off-by: Philip Withnall <pwithnall@endlessos.org> Helps: #1767
* Cleaning file 'filename' after the test in glib/tests/fileutils.cEmmanuel Fleury2022-04-171-0/+1
|
* gutils: Add flags to g_format_size_full() to return only value or only unitsMilan Crha2022-04-081-0/+24
| | | | | | | This allows to split the formatted size into the value and into the units, when can be shown differently in the UI. Relate to https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1391
* tests/filutils: remove an mkdir expected to fail test on win32Marc-André Lureau2022-03-231-3/+1
| | | | | | | When running under msys2 (and supposedly cygwin), the root path is remapped and permissions are permissive, the test doesn't fail. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
* Move unit test on g_basename() function to glib/tests/fileutils.cEmmanuel Fleury2022-03-171-1/+16
| | | | | | g_basename() function is defined in glib/gfileutils.c which is tested by glib/tests/fileutils.c test set. Until now, g_basename() test was in glib/test/utils.c. This patch move the unit test to the proper file.
* tests: Allow g_mkdir_with_parents() to fail with EPERMPhilip Withnall2022-03-041-1/+3
| | | | | | | | | | | | | | | | As well as with `EACCES`. This can happen if the filesystem as a whole is read-only, and has been spotted in the wild on macOS: ``` Bail out! GLib:ERROR:../glib/tests/fileutils.c:756:test_mkdir_with_parents: assertion failed (errno == EACCES): (1 == 13) stderr: ** GLib:ERROR:../glib/tests/fileutils.c:756:test_mkdir_with_parents: assertion failed (errno == EACCES): (1 == 13) ``` See: https://stackoverflow.com/q/68766316/2931197 See: https://gitlab.gnome.org/GNOME/glib/-/jobs/1866500 Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
* Remove old test file tests/testglib.cEmmanuel Fleury2022-02-221-2/+280
|
* tests: Fix a memory leak in the fileutils testPhilip Withnall2022-02-201-0/+1
| | | | Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
* tests: Use g_test_skip() to skip a test on WindowsPhilip Withnall2022-02-101-5/+5
|
* tests: skip read-only-directory test on win32Marc-André Lureau2022-02-101-0/+5
| | | | Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
* tests: fix read-only-file testMarc-André Lureau2022-02-101-1/+1
| | | | | | | The test is meant to check read-only files don't get overwritten, which is 0400 in octal. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
* tests: use g_chmod in fileutils testsMarc-André Lureau2022-02-101-4/+4
| | | | Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
* tests: fix test_set_contents_full error test on win32Marc-André Lureau2022-02-101-1/+4
| | | | Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
* tests: fix test_set_contents_full mode check on win32Marc-André Lureau2022-02-101-1/+11
| | | | | | | Fixes: GLib:ERROR:../glib/tests/fileutils.c:1348:test_set_contents_full: assertion failed (statbuf.st_mode & ~S_IFMT == tests[i].new_mode): (438 == 420) Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
* Improve test coverage of glib/gfileutils.cEmmanuel Fleury2022-01-261-2/+111
|
* Move tests/file-test.c to glib/tests/fileutils.cEmmanuel Fleury2022-01-261-7/+135
|
* Moving tests/dirname-test.c to glib/tests/fileutils.cEmmanuel Fleury2021-12-161-0/+62
| | | | Helps issue #1434
* tests: Drop use of g_test_bug_base()Philip Withnall2021-05-131-3/+1
| | | | | | | | | | | | Include the base URI in the `g_test_bug()` calls instead. This resolves inconsistencies between the old bug base (bugzilla.gnome.org) and the new bug base (gitlab.gnome.org). It also has the advantage that the URI passed to `g_test_bug()` is now clickable in the code editor, rather than being split across two locations. See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/275#note_303175 Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
* glib/tests/fileutils: Fix expectations when running as rootwip/smcv/fileutils-test-as-rootSimon McVittie2020-10-311-8/+56
| | | | | | | | | | This test asserts that g_file_set_contents_full() will fail when used on a read-only file, but processes with CAP_DAC_OVERRIDE on Linux or uid 0 on traditional Unix can and do ignore DAC permissions. See also #2027, #2028. Bug-Debian: https://bugs.debian.org/973271 Signed-off-by: Simon McVittie <smcv@collabora.com>
* glib/tests/fileutils: Make more use of g_assert_no_errno()Simon McVittie2020-10-311-10/+10
| | | | Signed-off-by: Simon McVittie <smcv@collabora.com>
* Fix signedness warning in glib/tests/fileutils.cEmmanuel Fleury2020-10-141-1/+1
| | | | | | | | | glib/gtestutils.h:134:96: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘GFileError’ 134 | if (!err || (err)->domain != dom || (err)->code != c) \ | ^~ glib/tests/fileutils.c:1072:15: note: in expansion of macro ‘g_assert_error’ 1072 | g_assert_error (error, G_FILE_ERROR, tests[i].expected_error); | ^~~~~~~~~~~~~~
* glib: Avoid redefining GLIB_DISABLE_DEPRECATION_WARNINGSPhilip Withnall2020-07-271-0/+2
| | | | | | | | It may be defined by the environment (we document that as being allowed) — if so, individual files should not try to redefine it, as that causes a preprocessor warning. Signed-off-by: Philip Withnall <withnall@endlessm.com>
* tests: Add tests for g_file_set_contents_full()Philip Withnall2020-07-261-0/+254
| | | | | | | | | These exercise all the code paths I can manage without adding a load of machinery to inject faults into `write()`. Signed-off-by: Philip Withnall <withnall@endlessm.com> Helps: #1302
* tests: Use G_TEST_OPTION_ISOLATE_DIRS for fileutils testsPhilip Withnall2020-07-261-1/+1
| | | | | | They all still pass. Signed-off-by: Philip Withnall <withnall@endlessm.com>
* tree: Fix various typos and outdated terminologyPhilip Withnall2020-06-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | This was mostly machine generated with the following command: ``` codespell \ --builtin clear,rare,usage \ --skip './po/*' --skip './.git/*' --skip './NEWS*' \ --write-changes . ``` using the latest git version of `codespell` as per [these instructions](https://github.com/codespell-project/codespell#user-content-updating). Then I manually checked each change using `git add -p`, made a few manual fixups and dropped a load of incorrect changes. There are still some outdated or loaded terms used in GLib, mostly to do with git branch terminology. They will need to be changed later as part of a wider migration of git terminology. If I’ve missed anything, please file an issue! Signed-off-by: Philip Withnall <withnall@endlessm.com>
* tests: Cope with having CAP_DAC_OVERRIDE, even if not euid 0Simon McVittie2020-02-131-14/+88
| | | | | | | | | | | Some CI platforms invoke these tests with euid != 0 but with capabilities. Detect whether we have Linux CAP_DAC_OVERRIDE or other OSs' equivalents, and skip tests that rely on DAC permissions being denied if we do have that privilege. Signed-off-by: Simon McVittie <smcv@collabora.com> Fixes: https://gitlab.gnome.org/GNOME/glib/issues/2027 Fixes: https://gitlab.gnome.org/GNOME/glib/issues/2028
* Add a wrapper for fsync() functionTodd Goyen2019-09-181-0/+1
| | | | Closes issue #35
* tests: Fix skipping mkdir-with-parents-permission testPhilip Withnall2019-09-021-0/+1
| | | | | | | | | | | | | | If the user has `CAP_DAC_OVERRIDE` or similar (for example, if running the tests as root), the `mkdir-with-parents-permission` test is skipped. The check for `CAP_DAC_OVERRIDE` was by creating a subdirectory of the test directory. That subdirectory, however, was never removed, which caused a ‘directory not empty’ error when trying to delete the test directory. Fix that by correctly deleting the subdirectory if skipping the test. Signed-off-by: Philip Withnall <withnall@endlessm.com>
* glib/tests/fileutils: Add a reproducer for #1852Simon McVittie2019-08-131-0/+54
| | | | | | | This test passes on the glib-2-60 branch, and failed before merging !1027. Signed-off-by: Simon McVittie <smcv@collabora.com>
* glib/tests/fileutils.c: Fix stdio Wrapper Test on WindowsChun-wei Fan2019-06-191-1/+5
| | | | | | | | The g_creat() call was done in *nix style in regards to the mode parameter, which the Windows CRT isn't going to understand (nor like, on newer CRTs). Update the program such that it will pass, by using Windows-style permission mode parameters for g_creat(), on Windows.
* glib: Rename G_STDIO_NO_WRAP_ON_UNIX → G_STDIO_WRAP_ON_UNIXPhilip Withnall2019-05-101-2/+2
| | | | | | | | | | This clarifies the meaning a bit. Don’t change the logic associated with it. Add a few comments to clarify things further. Based on work done by Emmanuel Fleury. Signed-off-by: Philip Withnall <withnall@endlessm.com> Fixes: #77
* Merge branch 'win32-symlink-refactoring' into 'master'Philip Withnall2019-03-131-3/+234
|\ | | | | | | | | Win32 symlink code refactoring See merge request GNOME/glib!269
| * fileutils test: use current time instead of zeroРуслан Ижбулатов2018-10-101-3/+6
| | | | | | | | | | | | This works around weird issues MS C runtime has when dealing with timestamps close to zero, where timezone adjustment could result in a negative timestamp.
| * W32: significant symlink code changesРуслан Ижбулатов2018-10-101-0/+228
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Put the core readlink() code into a separate _g_win32_readlink_handle_raw() function that takes a file handle, can optionally ensure NUL-terminatedness of its output (for cases where we need a NUL-terminator and do *not* need to get the exact contents of the symlink as it is stored in FS) and can either fill a caller-provided buffer *or* allocate its own buffer, and can also read the reparse tag. Put the rest of readlink() code into separate functions that do UTF-16<->UTF-8, strip inconvenient prefix and open/close the symlink file handle as needed. Split _g_win32_stat_utf16_no_trailing_slashes() into two functions - the one that takes a filename and the one that takes a file descriptor. The part of these functions that would have been duplicate is now split into the _g_win32_fill_privatestat() funcion. Add more comments explaining what each function does. Only g_win32_readlink_utf8(), which is callable from outside via private function interface, gets a real doc-comment, the rest get normal, non-doc comments. Change all callers to use the new version of the private g_win32_readlink_utf8() function, which can now NUL-terminate and allocate on demand - no need to call it in a loop. Also, the new code should correctly get reparse tag when the caller does fstat() on a symlink. Do note that this requires the caller to get a FD for the symlink, not the target. Figuring out how to do that is up to the caller. Since symlink info (target path and reparse tag) are now always read directly, via DeviceIoControl(), we don't need to use FindFirstFileW() anymore.
* | gutils: Use no-break space in g_format_size()António Fernandes2018-12-191-31/+32
| | | | | | | | | | | | It's undesirable for quantity and unit to be separated by line breaks. Fixes https://gitlab.gnome.org/GNOME/glib/issues/1625
* | tests: Rename macro to avoid conflict with encoding prefixTomasz Miąsko2018-12-091-78/+78
|/ | | | | | | | | | | | | Use macro name that doesn't conflict with string literal encoding prefix `U`. ``` ../glib/tests/fileutils.c(282): warning C4133: 'function': incompatible types - from 'unsigned int [2]' to 'const gchar *' ../glib/tests/fileutils.c(284): warning C4133: 'function': incompatible types - from 'unsigned int [2]' to 'const gchar *' ../glib/tests/fileutils.c(285): warning C4133: 'function': incompatible types - from 'unsigned int [2]' to 'const gchar *' ../glib/tests/fileutils.c(286): warning C4133: 'function': incompatible types - from 'unsigned int [2]' to 'const gchar *' ../glib/tests/fileutils.c(287): warning C4133: 'function': incompatible types - from 'unsigned int [3]' to 'const gchar *' ... ```
* Fudge glib fileutils test to pass on WindowsРуслан Ижбулатов2018-09-181-0/+12
| | | | | | | | | | | | 1) Creating a directory with 0666 does not prevent traversal on Windows (ACL determines the possibility of traversal, and Windows mkdir() does not translate permission bits into ACL). Don't do the traversal check on Windows. 2) Creating a file with 0555 also isn't translated into read-only ACL, Windows sets the read-only attribute instead, which blocks all changes, including changes to file times. Add the write permissions on Windows before changing file times.
* W32: test the private path-stripping functionРуслан Ижбулатов2018-09-121-0/+136
|