src/win32/posix_w32.c


Log

Author Commit Date CI Message
Edward Thomson 43d7a42b 2020-03-08T18:14:09 win32: don't canonicalize symlink targets Don't canonicalize symlink targets; our win32 path canonicalization routines expect an absolute path. In particular, using the path canonicalization routines for symlink targets (introduced in commit 7d55bee6d, "win32: fix relative symlinks pointing into dirs", 2020-01-10). Now, use the utf8 -> utf16 relative path handling functions, so that paths like "../foo" will be translated to "..\foo".
Patrick Steinhardt 7d55bee6 2020-01-10T12:44:51 win32: fix relative symlinks pointing into dirs On Windows platforms, we need some logic to emulate symlink(3P) defined by POSIX. As unprivileged symlinks on Windows are a rather new feature, our current implementation is comparatively new and still has some rough edges in special cases. One such case is relative symlinks. While relative symlinks to files in the same directory work as expected, libgit2 currently fails to create reltaive symlinks pointing into other directories. This is due to the fact that we forgot to translate the Unix-style target path to Windows-style. Most importantly, we are currently not converting directory separators from "/" to "\". Fix the issue by calling `git_win32_path_canonicalize` on the target. Add a test that verifies our ability to create such relative links across directories.
Edward Thomson 6460e8ab 2019-06-23T18:13:29 internal: use off64_t instead of git_off_t Prefer `off64_t` internally.
Patrick Steinhardt 50194dcd 2019-07-11T15:14:42 win32: fix symlinks to relative file targets When creating a symlink in Windows, one needs to tell Windows whether the symlink should be a file or directory symlink. To determine which flag to pass, we call `GetFileAttributesW` on the target file to see whether it is a directory and then pass the flag accordingly. The problem though is if create a symlink with a relative target path, then we will check that relative path while not necessarily being inside of the working directory where the symlink is to be created. Thus, getting its attributes will either fail or return attributes of the wrong target. Fix this by resolving the target path relative to the directory in which the symlink is to be created.
Patrick Steinhardt a00842c4 2019-06-29T09:59:14 win32: correctly unlink symlinks to directories When deleting a symlink on Windows, then the way to delete it depends on whether it is a directory symlink or a file symlink. In the first case, we need to use `DeleteFile`, in the second `RemoveDirectory`. Right now, `p_unlink` will only ever try to use `DeleteFile`, though, and thus fail to remove directory symlinks. This mismatches how unlink(3P) is expected to behave, though, as it shall remove any symlink disregarding whether it is a file or directory symlink. In order to correctly unlink a symlink, we thus need to check what kind of file this is. If we were to first query file attributes of every file upon calling `p_unlink`, then this would penalize the common case though. Instead, we can try to first delete the file with `DeleteFile` and only if the error returned is `ERROR_ACCESS_DENIED` will we query file attributes and determine whether it is a directory symlink to use `RemoveDirectory` instead.
Patrick Steinhardt e54343a4 2019-06-29T09:17:32 fileops: rename to "futils.h" to match function signatures Our file utils functions all have a "futils" prefix, e.g. `git_futils_touch`. One would thus naturally guess that their definitions and implementation would live in files "futils.h" and "futils.c", respectively, but in fact they live in "fileops.h". Rename the files to match expectations.
Patrick Steinhardt 2d85c7e8 2019-06-14T14:12:19 posix: remove `p_fallocate` abstraction By now, we have repeatedly failed to provide a nice cross-platform implementation of `p_fallocate`. Recent tries to do that escalated quite fast to a set of different CMake checks, implementations, fallbacks, etc., which started to look real awkward to maintain. In fact, `p_fallocate` had only been introduced in commit 4e3949b73 (tests: test that largefiles can be read through the tree API, 2019-01-30) to support a test with large files, but given the maintenance costs it just seems not to be worht it. As we have removed the sole user of `p_fallocate` in the previous commit, let's drop it altogether.
Jacques Germishuys 0fd259ed 2019-05-20T12:44:37 define SYMBOLIC_LINK_FLAG_DIRECTORY if not defined
Daniel Cohen Gindi 336e98bb 2019-05-06T14:51:52 Moved dwFlags declaration to beginning of scope
Daniel Cohen Gindi 37a7adb5 2019-05-05T07:49:09 Support symlinks for directories in win32
Edward Thomson 32f50452 2019-02-22T11:22:28 p_fallocate: add Windows emulation Emulate `p_fallocate` on Windows by seeking beyond the end of the file and setting the size to the current seek position.
Etienne Samson 4e3949b7 2019-01-30T02:14:11 tests: test that largefiles can be read through the tree API
Edward Thomson f673e232 2018-12-27T13:47:34 git_error: use new names in internal APIs and usage Move to the `git_error` name in the internal API for error-related functions.
lhchavez 7b453e7e 2019-01-05T22:12:48 Fix a bunch of warnings This change fixes a bunch of warnings that were discovered by compiling with `clang -target=i386-pc-linux-gnu`. It turned out that the intrinsics were not necessarily being used in all platforms! Especially in GCC, since it does not support __has_builtin. Some more warnings were gleaned from the Windows build, but I stopped when I saw that some third-party dependencies (e.g. zlib) have warnings of their own, so we might never be able to enable -Werror there.
Edward Thomson 7321cff0 2018-11-15T09:17:51 Merge pull request #4713 from libgit2/ethomson/win_symlinks Support symlinks on Windows when core.symlinks=true
Edward Thomson 204cce66 2018-07-03T02:30:34 win32: add symbolic link support Enable `p_symlink` to actually create symbolic links, not just create a fake link (a text file containing the link target). This now means that `core.symlinks=true` works on Windows platforms where symbolic links are enabled (likely due to running in Developer Mode).
Edward Thomson 30771261 2018-07-03T02:21:17 win32: use GetFinalPathNameByHandle directly Now that we've updated to WIN32_WINNT version of Vista or better, we don't need to dynamically load GetFinalPathNameByHandle and can simply invoke it directly.
Edward Thomson b2e85f98 2018-10-17T08:48:43 win32: rename `git_win32__canonicalize_path` The internal API `git_win32__canonicalize_path` is far, far too easily confused with the internal API `git_win32_path_canonicalize`. The former removes the namespace prefix from a path (eg, given `\\?\C:\Temp\foo`, it returns `C:\Temp\foo`, and given `\\?\UNC\server\share`, it returns `\\server\share`). As such, rename it to `git_win32_path_remove_namespace`. `git_win32_path_canonicalize` remains unchanged.
Patrick Steinhardt 9994cd3f 2018-06-25T11:56:52 treewide: remove use of C++ style comments C++ style comment ("//") are not specified by the ISO C90 standard and thus do not conform to it. While libgit2 aims to conform to C90, we did not enforce it until now, which is why quite a lot of these non-conforming comments have snuck into our codebase. Do a tree-wide conversion of all C++ style comments to the supported C style comments to allow us enforcing strict C90 compliance in a later commit.
Edward Thomson 1560b580 2017-08-15T10:35:47 Merge pull request #4288 from pks-t/pks/include-fixups Include fixups
Edward Thomson bc35fd4b 2017-07-18T14:44:29 win32: provide fast-path for retrying filesystem operations When using the `do_with_retries` macro for retrying filesystem operations in the posix emulation layer, allow the remediation function to return `GIT_RETRY`, meaning that the error was believed to be remediated, and the operation should be retried immediately, without a sleep. This is a slightly more general solution to the problem fixed in #4312.
Carson Howard 1bcdaba2 2017-07-18T14:47:28 fixed win32 p_unlink retry sleep issue Fixed an issue where the retry logic on p_unlink sleeps before it tries setting a file to write mode causing unnecessary slowdown.
Patrick Steinhardt 0c7f49dd 2017-06-30T13:39:01 Make sure to always include "common.h" first Next to including several files, our "common.h" header also declares various macros which are then used throughout the project. As such, we have to make sure to always include this file first in all implementation files. Otherwise, we might encounter problems or even silent behavioural differences due to macros or defines not being defined as they should be. So in fact, our header and implementation files should make sure to always include "common.h" first. This commit does so by establishing a common include pattern. Header files inside of "src" will now always include "common.h" as its first other file, separated by a newline from all the other includes to make it stand out as special. There are two cases for the implementation files. If they do have a matching header file, they will always include this one first, leading to "common.h" being transitively included as first file. If they do not have a matching header file, they instead include "common.h" as first file themselves. This fixes the outlined problems and will become our standard practice for header and source files inside of the "src/" from now on.
Edward Thomson 86536c7e 2017-04-17T15:40:03 win32: `remediation` not `cleanup` The `remediation` function is run in the retry loop in order to attempt to fix any problems that the prior run encountered. There is nothing "cleaned up". Clarify the name.
Edward Thomson 89d403cc 2017-04-05T09:50:12 win32: enable `p_utimes` for readonly files Instead of failing to set the timestamp of a read-only file (like any object file), set it writable temporarily to update the timestamp.
Edward Thomson 7ece9065 2017-04-03T23:07:16 win32: make posix emulation retries configurable POSIX emulation retries should be configurable so that tests can disable them. In particular, maniacally threading tests may end up trying to open locked files and need retries, which will slow continuous integration tests significantly.
Edward Thomson 1069ad3c 2017-04-03T23:05:53 win32: do not inherit file descriptors
Sven Strickroth d5e6ca1e 2017-01-14T18:39:32 Allow to configure default file share mode for opening files This can prevent FILE_SHARED_VIOLATIONS when used in tools such as TortoiseGit TGitCache and FILE_SHARE_DELETE, because files can be opened w/o being locked any more. Signed-off-by: Sven Strickroth <email@cs-ware.de>
Sven Strickroth 92d5a637 2017-01-14T17:15:50 win32: deduplicate code: use p_open in p_creat Signed-off-by: Sven Strickroth <email@cs-ware.de>
Sven Strickroth ef5cfcdb 2017-01-14T18:20:59 win32: use CreateFile in p_open Signed-off-by: Sven Strickroth <email@cs-ware.de>
Edward Thomson fbc6910f 2017-04-01T13:25:14 win32: teach p_open about do_with_retries
Edward Thomson a0f67e4a 2017-04-01T13:19:51 win32: teach p_unlink about do_with_retries
Edward Thomson 8a4e1513 2017-04-01T00:23:03 win32: make p_rename use do_with_retries
Edward Thomson cc8d9a29 2017-04-01T10:44:17 win32: introduce `do_with_retries` macro Provide a macro that will allow us to run a function with posix-like return values multiple times in a retry loop, with an optional cleanup function called between invocations.
Edward Thomson dcaa9099 2017-03-29T23:54:47 win32: map windows error codes to errno Introduce mapping from windows error codes to errno values. This allows us to replace our calls to the Windows posix emulation functions with calls to the Win32 APIs for more fine-grained control over the emulation. These mappings match the Windows CRT's mappings for its posix emulation as they were described to me.
Edward Thomson fcb322f5 2017-03-31T23:39:33 Merge remote-tracking branch 'origin/pr/3790' into win32_posix
Edward Thomson e6ed0d2f 2016-12-13T11:31:38 odb_loose: fsync tests Introduce a simple counter that `p_fsync` implements. This is useful for ensuring that `p_fsync` is called when we expect it to be, for example when we have enabled an odb backend to perform `fsync`s when writing objects.
Tyler Church 32269b15 2016-05-18T09:33:17 Add retries to win32 p_unlink and p_open.
Edward Thomson c4d23928 2016-02-11T15:41:07 fstat: use our custom `stat`
Edward Thomson 35439f59 2016-02-11T12:24:21 win32: introduce p_timeval that isn't stupid Windows defines `timeval` with `long`, which we cannot sanely cope with. Instead, use a custom timeval struct.
Edward Thomson e164ddb1 2015-09-17T12:23:19 win32: return EACCES in `p_lstat` Don't coalesce all errors into ENOENT. At least identify EACCES. All callers should be handling this case already, as the POSIX `lstat` will return this.
Edward Thomson e069c621 2015-07-02T09:25:48 git__getenv: utf-8 aware env reader Introduce `git__getenv` which is a UTF-8 aware `getenv` everywhere. Make `cl_getenv` use this to keep consistent memory handling around return values (free everywhere, as opposed to only some platforms).
Edward Thomson 121c3171 2015-06-16T15:18:04 Introduce p_utimes and p_futimes Provide functionality to set the time on a filesystem entry, using utimes or futimes on POSIX type systems or SetFileTime on Win32.
Edward Thomson f3c444b8 2015-04-27T17:47:51 win32: abstract file attributes -> struct stat fn
J Wyman 1920ee4e 2015-03-26T18:10:24 Improvements to status performance on Windows. Changed win32/path_w32.c to utilize NTFS' FindFirst..FindNext data instead of doing an lstat per file. Avoiding unnecessary directory opens and file scans reduces IO, improving overall performance. Effect is magnified due to NTFS being a kernel mode file system (as opposed to user mode).
Matti Virolainen 78c34af0 2015-03-06T12:23:14 Use secure API if available.
Jeff Hostetler d8be5087 2015-03-03T13:35:10 Change ifdef for MINGW32.
Jeff Hostetler 7e9b21aa 2015-02-27T08:54:48 Fix p_ftruncate to handle big files for git_clone
Edward Thomson 527ed59a 2015-02-13T09:18:49 win32: limit the mode to `_wopen`/`_waccess` Win32 generally ignores Unix-like mode bits that don't make any sense on the platform (eg `0644` makes no sense to Windows). But WINE complains loudly when presented with POSIXy bits. Remove them. (Thanks @phkelley)
Edward Thomson 3c68bfcd 2015-02-04T18:24:31 stat: don't remove trailing '/' from root on win32 `p_stat` calls `git_win32_path_from_utf8`, which canonicalizes the path. Do not further try to modify the path, else we trim the trailing slash from a root directory and try to access `C:` instead of `C:/`.
Edward Thomson cceae9a2 2014-12-01T13:09:58 win32: use NT-prefixed "\\?\" paths When turning UTF-8 paths into UCS-2 paths for Windows, always use the \\?\-prefixed paths. Because this bypasses the system's path canonicalization, handle the canonicalization functions ourselves. We must: 1. always use a backslash as a directory separator 2. only use a single backslash between directories 3. not rely on the system to translate "." and ".." in paths 4. remove trailing backslashes, except at the drive root (C:\)
Edward Thomson 8d45b469 2014-10-11T14:34:24 p_lstat win32: don't canonicalize volume mounts A reparse point that is an IO_REPARSE_TAG_MOUNT_POINT could be a junction or an actual filesystem mount point. (Who knew?) If it's the latter, its reparse point will report the actual volume information \??\Volume{GUID}\ and we should not attempt to dereference that further, instead readlink should report EINVAL since it's not a symlink / junction and its original path was canonical. Yes, really.
Jacques Germishuys c983604e 2014-07-12T14:44:21 Consistently use p_snprintf
Jacques Germishuys 2f795d8f 2014-07-12T14:45:56 Cleanup portability/compatibility layer * Removes mingw-compat.h * Cleans up separation of compiler/platform idiosyncrasies * Unifies mingw/msvc stat structures and functions * (Tries to) hide more compiler specific implementation details (even in our internal API)
Jacques Germishuys 59ceb432 2014-07-05T21:27:47 Define IO_REPARSE_TAG_SYMLINK if its not defined by WinNT.h
Jacques Germishuys 72090514 2014-07-05T21:27:21 Secure CRT is only available from Visual Studio 2005+
Carlos Martín Nieto e58281aa 2014-04-04T14:40:38 filebuf: make unlocking atomic When renaming a lock file to its final location, we need to make sure that it is replaced atomically. We currently have a workaround for Windows by removing the target file. This means that the target file, which may be a ref or a packfile, may cease to exist for a short wile, which shold be avoided. Implement the workaround only in Windows, by making sure that the file we want to replace is writable.
Carlos Martín Nieto 0731a5b4 2014-05-14T19:12:48 indexer: mmap fixes for Windows Windows has its own ftruncate() called _chsize_s(). p_mkstemp() is changed to use p_open() so we can make sure we open for writing; the addition of exclusive create is a good thing to do regardless, as we want a temporary path for ourselves. Lastly, MSVC doesn't quite know how to add two numbers if one of them is a void pointer, so let's alias it to unsigned char.C
Philip Kelley f0b820dd 2014-05-16T12:38:56 Win32: Supply _O_NOINHERIT when calling _wopen
Philip Kelley 7110000d 2014-04-22T10:21:19 React to feedback for UTF-8 <-> WCHAR and reparse work
Edward Thomson 65477db1 2014-04-21T23:32:31 Handle win32 reparse points properly
Philip Kelley c2c81615 2014-04-19T18:05:31 Win32: UTF-8 <-> WCHAR conversion overhaul
Jan Melcher 2873a862 2014-03-27T12:42:44 Retry renaming files on Access Denied errors When a file is open for reading (without shared-delete permission), and then a different thread/process called p_rename, that would fail, even if the file was only open for reading for a few milliseconds. This change lets p_rename wait up to 50ms for the file to be closed by the reader. Applies only to win32. This is especially important for git_filebuf_commit, because writes should not fail if the file is read simultaneously. Fixes #2207
Russell Belfer 14997dc5 2013-10-08T12:45:43 More filemode cleanups for FAT on MacOS This cleans up some additional issues. The main change is that on a filesystem that doesn't support mode bits, libgit2 will now create new blobs with GIT_FILEMODE_BLOB always instead of being at the mercy to the filesystem driver to report executable or not. This means that if "core.filemode" lies and claims that filemode is not supported, then we will ignore the executable bit from the filesystem. Previously we would have allowed it. This adds an option to the new git_repository_reset_filesystem to recurse through submodules if desired. There may be other types of APIs that would like a "recurse submodules" option, but this one is particularly useful. This also has a number of cleanups, etc., for related things including trying to give better error messages when problems come up from the filesystem. For example, the FAT filesystem driver on MacOS appears to return errno EINVAL if you attempt to write a filename with invalid UTF-8 in it. We try to capture that with a better error message now.
Edward Thomson 238b7614 2013-08-16T13:31:24 Fix p_inet_pton on windows p_inet_pton on Windows should set errno properly for callers. Rewrite p_inet_pton to handle error cases correctly and add test cases to exercise this function.
Edward Thomson 86967cc5 2013-08-19T16:44:17 Use time(2) to get the time We didn't use the added precision in gettimeofday, so remove it. This prevents us from having an unnecessary reimplementation on win32.
Martin Woodward c9340df0 2013-08-16T19:40:58 Give credit to PHP for the p_readlink function in posix_w32.c
Russell Belfer ee065601 2013-08-13T09:53:56 Minor win32 fixes and improvements This is just a bunch of small fixes that I noticed while looking at the UTF8 and UTF16 path stuff. It fixes a slowdown in looking for an empty directory (not exiting loop asap), makes the dir name in the git__DIR structure be a GIT_FLEX_ARRAY to save an allocation, and fixes some slightly odd assumptions in the cl_getenv helper.
Russell Belfer 841034a3 2013-08-13T09:45:56 Reintroduce type for UTF8 win32 path conversions
Russell Belfer d4cff0cb 2013-08-13T09:40:32 Rename git__win32_path fns to git_win32_path
Vicent Marti abf37327 2013-08-13T09:15:39 windows: Path conversion with better semantics
Ben Straub aaefbdee 2013-08-08T08:48:57 Discriminate path-specific and general UTF-X conversions
Ben Straub 2c0128ee 2013-08-07T19:29:33 Rename git_win_str_utf* to git_win32_path_utf*
Ben Straub 9c38f7a6 2013-08-07T13:22:41 Add typedefs for win32 utf-8 and utf-16 buffers ...and normalize the signatures of the two conversion functions.
Ben Straub d8563619 2013-08-05T11:41:39 Split UTF-16 and UTF-8 buffer sizes for win32 Also fixed up call-sites to use the correct buffer sizes, especially when converting to utf-8.
Sven Strickroth 47537112 2013-06-25T16:46:06 Correctly handle junctions A junction has S_IFDIR | S_IFLNK set, however, only one makes sense. Signed-off-by: Sven Strickroth <email@cs-ware.de>
Russell Belfer 37f66e82 2013-06-12T15:21:21 Fix Windows warnings This fixes problems with missing function prototypes and 64-bit data issues on Windows.
nulltoken 1fed6b07 2013-05-13T21:57:37 Fix trailing whitespaces
Linquize 0cb16fe9 2013-05-15T20:26:55 Unify whitespaces to tabs
Vicent Martí 3405f787 2013-05-06T06:51:21 Merge pull request #1547 from ethomson/win32_stat p_stat() should follow symlinks on windows
Edward Thomson 00a4c479 2013-05-04T12:04:39 p_stat() should follow symlinks on windows
Edward Thomson e09d18ee 2013-05-03T18:39:44 allow checkout to proceed when a dir to be removed is in use (win32)
Vicent Martí cc427158 2013-02-28T15:09:32 Merge pull request #1373 from arrbee/why-cdecl-why Why cdecl why?
Russell Belfer f443a72d 2013-02-28T14:41:26 Fix some deprecation warnings on Windows This fixes some snprintf and vsnprintf related deprecation warnings we've been having on Windows with recent compilers.
Vicent Marti 5fa8abb8 2013-02-28T17:36:20 w32-posix: Wrap the `timezone` declaration with a clause Allows compilation in newer versions of MinGW that already defined it.
Jameson Miller ff9df883 2013-02-08T14:27:21 Fix Windows symlinks
Patrick Pokatilo 7672c8c7 2013-02-08T11:29:23 Moved braces to conform to code style
Patrick Pokatilo 64012fdb 2013-02-08T03:24:45 Replace LoadLibrary with GetModuleHandle, since kernel32 is loaded by default As requested
Patrick Pokatilo a49e5bed 2013-02-08T01:26:04 Replace call to strnlen with call to strlen
Patrick Pokatilo f88885e3 2013-02-08T01:10:03 Include <string.h>
Patrick Pokatilo 3b5e44ae 2013-02-08T00:50:20 Fix call to readlink
Patrick Pokatilo 94ed23f8 2013-02-07T01:41:20 Call p_readlink to determine symlink size
Edward Thomson 359fc2d2 2013-01-08T17:07:25 update copyrights
nulltoken bdb94c21 2012-12-17T12:20:52 Fix MSVC compilation warnings
Russell Belfer a8122b5d 2012-11-21T15:39:03 Fix warnings on Win64 build
Ben Straub 54b2a37a 2012-11-20T16:02:25 Clean up config.h
Eduardo Bart cf0dadcf 2012-11-20T01:19:31 Minor optimization in win32 do_lstat
Eduardo Bart 2d96fce2 2012-11-19T23:12:20 update win32 lstat comment
Eduardo Bart 52ead787 2012-11-19T22:30:20 Fix win32 lstat
Russell Belfer cccacac5 2012-11-14T22:41:51 Add POSIX compat lstat() variant for win32 The existing p_lstat implementation on win32 is not quite POSIX compliant when setting errno to ENOTDIR. This adds an option to make is be compliant so that code (such as checkout) that cares to have separate behavior for ENOTDIR can use it portably. This also contains a couple of other minor cleanups in the posix_w32.c implementations to avoid unnecessary work.