我刚刚将docker配置为在wsl2下运行。这是有效的,没有任何相关的问题,我们的项目运行良好。
在本文之后,我介绍了如何设置wsl2对接环境:https://www.docker.com/blog/docker-desktop-wsl-2-best-practices/
出于性能考虑,本文建议将项目文件放入linux系统中,而不是使用/mnt下的挂载来访问它。
为了访问这些文件,本文提出了以下选项:
\\wsl$\下的网络共享有些同事使用的IDE既不兼容linux,也不能访问wsl。所以我试着让他们通过网络共享来访问这个项目。这些同事在IDE中使用git集成,不习惯使用git cli。
Git运行良好,只是有一个小问题。存储库中有文件,它们具有可执行权限(+x)。这些文件在linux上有perms 755,在windows网络驱动器上有644。
因为实际的文件perms与linux环境不同,所以git会检测到这些文件的更改。
是否有办法将正确的文件权限公开到windows环境中?
对于如何解决这个问题,你还有什么其他的想法吗?
发布于 2020-06-17 19:14:56
发布于 2020-06-20 04:27:53
我在git中也遇到了类似的问题,您可能无法使用各种神秘错误运行commit。其中的一部分就是git打开文件的方式,所以希望这篇文章能以某种方式解开它。
背景
在最新的Windows版本中,关于WSL如何与您的文件系统交互,WSL中有一些更改。一个问题是,以前Windows和Linux文件系统之间的不兼容性意味着大多数文件实际上在外部存储上拥有‘777’权限,因此任何用户都可以读/写/执行任何东西。这对于Linux来说并不理想,因为您不能存储私钥等等。微软现在已经改变了这种行为,以便文件可以通过扩展属性同时拥有Windows (NTFS)和Linux权限。在普通驱动器上,可以使用以下命令安装带有元数据的驱动器:
umount /mnt/c;
mount -t drvfs C:\\ /mnt/c/ -o metadata不幸的是,它们似乎也将这一更改扩展到网络和外部文件系统(如exFAT),它没有可扩展的属性,并且变得有点混乱,使外部驱动器无法使用。例如,如果该文件在Windows中是只读的,那么您就不能在WSL中写入它;您也不能用sudo重写它,因为Windows权限会覆盖WSL。这些变化破坏了很多程序,我今天在尝试将更改上传到git时发现了这些程序。这是那些在互联网上还没有解决方案的新问题之一,所以我附上了一个文件来解决这个问题。
要运行,首先编译共享对象:
cc -Wall -O3 -D_GNU_SOURCE -fPIC -c -o githack.o githack.c; gcc -o githack.so -nostartfiles -shared githack.o -ldl;然后运行以LD_PRELOAD为前缀的命令
LD_PRELOAD=./githack.so git commit -a -m "Another interesting commit"如何为其他程序进行研究
对于git来说,具体的问题是:
error: insufficient permission for adding an object to repository database .git/objects要找出失败的原因,可以使用strace
strace git commit -a -m "Another interesting commit"
>
...
gettimeofday({tv_sec=1592618056, tv_usec=52991}, NULL) = 0
getpid() = 651
openat(AT_FDCWD, ".git/objects/78/tmp_obj_flbKNc", O_RDWR|O_CREAT|O_EXCL, 0444) = -1 EACCES (Permission denied)
write(2, "error: insufficient permission f"..., 88error: insufficient permission for adding an object to repository database .git/objects
) = 88
close(4) = 0
...在打印的错误行之前,我们会看到它为什么失败(-1),因此要修复它,需要拦截该调用。您可以从ltrace中确定
ltrace git commit -a -m "Latest local copy from George"
>
...
open64(".git/objects/78/tmp_obj_zDayCc", 194, 0444) = -1
__errno_location() = 0x7f2777001000
__errno_location() = 0x7f2777001000
__vsnprintf_chk(0x7fffd4786d00, 4096, 1, 4096) = 80
__fprintf_chk(0x7f277631c680, 1, 0x7f27773eacfc, 0x7f27773c8083error: insufficient permission for adding an object to repository database .git/objects
) = 88
close(4)
...因此,本文底部附加的代码截取了open64代码,其标志与194相等。
解决方案代码(名称githack.c)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
//#define openat ignorethisopen
#define open ignorethisopen
#define open64 ignorethisopen64
#include <fcntl.h>
//#undef openat
#undef open
#undef open64
#include <dlfcn.h>
/*
'strace git ...' will show git fail on an openat() command
this is probably implemented as open64() on your system
you can confirm this by use of 'ltrace git ...'
you may also need to adjust the oflag comparison of 194
George O'Neill 2020/06/20 (feel free to reach out if issues remain)
*/
/*static int (*___openat)(int, char *, int, mode_t);*/
static int (*___open)(const char *, int, mode_t);
static int (*___open64)(const char *, int, mode_t);
static void* dlwrap(const char *fn)
{
const char *e;
void *p = dlsym(RTLD_NEXT, fn);
if ((e=dlerror())!=0)
fprintf(stderr, "dlsym(RTLD_NEXT,'%s'): %s\r\n", fn, e);
return p;
}
void _init(void)
{
___open = dlwrap("open");
___open64 = dlwrap("open64");
}
/*int openat(int dirfd, const char *pathname, int oflag, mode_t mode)*/
int open(const char *pathname, int oflag, mode_t mode)
{
if (oflag && oflag == 194)
return ___open(pathname, oflag, S_IRWXU);
return ___open(pathname, oflag, mode);
}
int open64(const char *pathname, int oflag, mode_t mode)
{
if (oflag && oflag == 194)
return ___open64(pathname, oflag, S_IRWXU);
return ___open64(pathname, oflag, mode);
}https://stackoverflow.com/questions/62429516
复制相似问题