mirror of
https://github.com/git/git.git
synced 2024-06-01 12:26:32 +02:00
Merge 'docker-volumes-are-no-symlinks'
This was pull request #1645 from ZCube/master Support windows container. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
commit
502d75bb73
|
@ -1053,7 +1053,7 @@ int mingw_lstat(const char *file_name, struct stat *buf)
|
|||
buf->st_uid = 0;
|
||||
buf->st_nlink = 1;
|
||||
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes,
|
||||
reparse_tag);
|
||||
reparse_tag, file_name);
|
||||
buf->st_size = S_ISLNK(buf->st_mode) ? link_len :
|
||||
fdata.nFileSizeLow | (((off_t) fdata.nFileSizeHigh) << 32);
|
||||
buf->st_dev = buf->st_rdev = 0; /* not used by Git */
|
||||
|
@ -1104,7 +1104,7 @@ static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
|
|||
buf->st_gid = 0;
|
||||
buf->st_uid = 0;
|
||||
buf->st_nlink = 1;
|
||||
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes, 0);
|
||||
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes, 0, NULL);
|
||||
buf->st_size = fdata.nFileSizeLow |
|
||||
(((off_t)fdata.nFileSizeHigh)<<32);
|
||||
buf->st_dev = buf->st_rdev = 0; /* not used by Git */
|
||||
|
@ -2590,6 +2590,13 @@ int mingw_rename(const char *pold, const char *pnew)
|
|||
return 0;
|
||||
gle = GetLastError();
|
||||
|
||||
if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container()) {
|
||||
/* Fall back to copy to destination & remove source */
|
||||
if (CopyFileW(wpold, wpnew, FALSE) && !mingw_unlink(pold))
|
||||
return 0;
|
||||
gle = GetLastError();
|
||||
}
|
||||
|
||||
/* revert file attributes on failure */
|
||||
if (attrs != INVALID_FILE_ATTRIBUTES)
|
||||
SetFileAttributesW(wpnew, attrs);
|
||||
|
@ -3990,3 +3997,62 @@ int mingw_have_unix_sockets(void)
|
|||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Based on https://stackoverflow.com/questions/43002803
|
||||
*
|
||||
* [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
|
||||
* "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
|
||||
* "ErrorControl"=dword:00000001
|
||||
* "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
|
||||
* 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
|
||||
* 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
|
||||
* 65,00,00,00
|
||||
* "Start"=dword:00000002
|
||||
* "Type"=dword:00000010
|
||||
* "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
|
||||
* "ObjectName"="LocalSystem"
|
||||
* "ServiceSidType"=dword:00000001
|
||||
*/
|
||||
int is_inside_windows_container(void)
|
||||
{
|
||||
static int inside_container = -1; /* -1 uninitialized */
|
||||
const char *key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc";
|
||||
HKEY handle = NULL;
|
||||
|
||||
if (inside_container != -1)
|
||||
return inside_container;
|
||||
|
||||
inside_container = ERROR_SUCCESS ==
|
||||
RegOpenKeyExA(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &handle);
|
||||
RegCloseKey(handle);
|
||||
|
||||
return inside_container;
|
||||
}
|
||||
|
||||
int file_attr_to_st_mode (DWORD attr, DWORD tag, const char *path)
|
||||
{
|
||||
int fMode = S_IREAD;
|
||||
if ((attr & FILE_ATTRIBUTE_REPARSE_POINT) &&
|
||||
tag == IO_REPARSE_TAG_SYMLINK) {
|
||||
int flag = S_IFLNK;
|
||||
char buf[MAX_LONG_PATH];
|
||||
|
||||
/*
|
||||
* Windows containers' mapped volumes are marked as reparse
|
||||
* points and look like symbolic links, but they are not.
|
||||
*/
|
||||
if (path && is_inside_windows_container() &&
|
||||
readlink(path, buf, sizeof(buf)) > 27 &&
|
||||
starts_with(buf, "/ContainerMappedDirectories/"))
|
||||
flag = S_IFDIR;
|
||||
|
||||
fMode |= flag;
|
||||
} else if (attr & FILE_ATTRIBUTE_DIRECTORY)
|
||||
fMode |= S_IFDIR;
|
||||
else
|
||||
fMode |= S_IFREG;
|
||||
if (!(attr & FILE_ATTRIBUTE_READONLY))
|
||||
fMode |= S_IWRITE;
|
||||
return fMode;
|
||||
}
|
||||
|
|
|
@ -728,3 +728,8 @@ int mingw_have_unix_sockets(void);
|
|||
#undef have_unix_sockets
|
||||
#define have_unix_sockets mingw_have_unix_sockets
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Check current process is inside Windows Container.
|
||||
*/
|
||||
int is_inside_windows_container(void);
|
||||
|
|
|
@ -6,19 +6,7 @@
|
|||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
static inline int file_attr_to_st_mode (DWORD attr, DWORD tag)
|
||||
{
|
||||
int fMode = S_IREAD;
|
||||
if ((attr & FILE_ATTRIBUTE_REPARSE_POINT) && tag == IO_REPARSE_TAG_SYMLINK)
|
||||
fMode |= S_IFLNK;
|
||||
else if (attr & FILE_ATTRIBUTE_DIRECTORY)
|
||||
fMode |= S_IFDIR;
|
||||
else
|
||||
fMode |= S_IFREG;
|
||||
if (!(attr & FILE_ATTRIBUTE_READONLY))
|
||||
fMode |= S_IWRITE;
|
||||
return fMode;
|
||||
}
|
||||
extern int file_attr_to_st_mode (DWORD attr, DWORD tag, const char *path);
|
||||
|
||||
static inline int get_file_attr(const char *fname, WIN32_FILE_ATTRIBUTE_DATA *fdata)
|
||||
{
|
||||
|
|
|
@ -202,8 +202,30 @@ static struct fsentry *fseentry_create_entry(struct fscache *cache,
|
|||
fdata->FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT ?
|
||||
fdata->EaSize : 0;
|
||||
|
||||
/*
|
||||
* On certain Windows versions, host directories mapped into
|
||||
* Windows Containers ("Volumes", see https://docs.docker.com/storage/volumes/)
|
||||
* look like symbolic links, but their targets are paths that
|
||||
* are valid only in kernel mode.
|
||||
*
|
||||
* Let's work around this by detecting that situation and
|
||||
* telling Git that these are *not* symbolic links.
|
||||
*/
|
||||
if (fse->reparse_tag == IO_REPARSE_TAG_SYMLINK &&
|
||||
sizeof(buf) > (list ? list->len + 1 : 0) + fse->len + 1 &&
|
||||
is_inside_windows_container()) {
|
||||
size_t off = 0;
|
||||
if (list) {
|
||||
memcpy(buf, list->dirent.d_name, list->len);
|
||||
buf[list->len] = '/';
|
||||
off = list->len + 1;
|
||||
}
|
||||
memcpy(buf + off, fse->dirent.d_name, fse->len);
|
||||
buf[off + fse->len] = '\0';
|
||||
}
|
||||
|
||||
fse->st_mode = file_attr_to_st_mode(fdata->FileAttributes,
|
||||
fdata->EaSize);
|
||||
fdata->EaSize, buf);
|
||||
fse->dirent.d_type = S_ISREG(fse->st_mode) ? DT_REG :
|
||||
S_ISDIR(fse->st_mode) ? DT_DIR : DT_LNK;
|
||||
fse->u.s.st_size = S_ISLNK(fse->st_mode) ? MAX_LONG_PATH :
|
||||
|
|
Loading…
Reference in New Issue