git-annex/doc/tips/Using_git-annex_on_NTFS_with_WSL1.mdwn

139 lines
3.7 KiB
Text
Raw Normal View History

2022-09-24 22:31:54 +00:00
The following steps are tested on Windows 10 21h1 with Ubuntu 20 and are designed to allow use of the annexed files through both WSL and Windows.
2021-10-22 22:13:46 +00:00
2022-09-24 22:31:54 +00:00
** Limitations **
* The repository must be created with `annex.tune.objecthashlower=true`.
* `git annex adjust --unlock` will not work. Unlocked files will work most of the time. Avoid `annex.addunlocked=true` because it is likely to not work.
2021-10-22 22:13:46 +00:00
**Setup**
* Enable Developer mode in Windows settings so that symlinks can be created without elevated privileges.
* Mount the NTFS drive with metadata option. [`/etc/wsl.conf`](https://docs.microsoft.com/en-us/windows/wsl/wsl-config) can be used or a line such as `C: /mnt/c drvfs metadata` can be added in `/etc/fstab`.
2022-09-30 18:03:50 +00:00
* Follow these steps in order when creating a new repository.
* `git config annex.sshcaching false`
* `git annex init`
* git-annex should not detect the filesystem as crippled but now set `git config annex.crippledfilesystem true`
2022-09-24 23:27:17 +00:00
* Safety of locked files will require these settings and scripts and the patch below.
* `git config annex.freezecontent-command 'wsl-freezecontent %path'`
2022-09-24 22:31:54 +00:00
* `git config annex.thawcontent-command 'wsl-thawcontent %path'`
2022-09-27 00:45:22 +00:00
<details>
<summary>wsl-freezecontent</summary>
2022-09-24 23:27:17 +00:00
```
#!/usr/bin/env bash
if [ -f "$1" ]; then
if \[[ "$1" == *.git/annex/objects/* ]]; then
PERM='(DE,WD,AD)'
else
PERM='(WD,AD)'
fi
elif [ -d "$1" ]; then
PERM='(DE,DC,WD,AD)'
else
exit 0
fi
OUTPUT="$(icacls.exe "$(wslpath -w "$1")" /deny "Authenticated Users:$PERM")"
if [ "$?" -ne 0 ]; then
echo "$OUTPUT"
exit 1
fi
2022-09-24 22:31:54 +00:00
2022-09-24 23:27:17 +00:00
```
2022-09-27 00:45:22 +00:00
</details>
2022-09-24 22:31:54 +00:00
2022-09-27 00:45:22 +00:00
<details>
<summary>wsl-thawcontent</summary>
2022-09-24 22:31:54 +00:00
2022-09-24 23:27:17 +00:00
```
#!/usr/bin/env bash
2022-09-24 22:31:54 +00:00
2022-09-24 23:27:17 +00:00
if [ -f "$1" ]; then
PERM='(DE,WD,AD)'
elif [ -d "$1" ]; then
PERM='(DE,DC,WD,AD)'
else
exit 0
fi
2022-09-24 22:31:54 +00:00
2022-09-24 23:27:17 +00:00
OUTPUT="$(icacls.exe "$(wslpath -w "$1")" /grant "Authenticated Users:$PERM")"
2021-10-22 22:13:46 +00:00
2022-09-24 23:27:17 +00:00
if [ "$?" -ne 0 ]; then
echo "$OUTPUT"
exit 1
fi
2021-10-22 22:13:46 +00:00
2022-09-24 23:27:17 +00:00
```
2022-09-27 00:45:22 +00:00
</details>
2021-10-22 22:13:46 +00:00
2022-09-24 23:23:40 +00:00
** Patches **
2022-09-27 00:45:22 +00:00
<details>
<summary>This patch allows `git annex fix` on a crippled file system.</summary>
2022-09-24 23:23:40 +00:00
```
From 65fe6e362dfbf2f54c8da5ca17c59af26de5ff83 Mon Sep 17 00:00:00 2001
From: Reiko Asakura <asakurareiko@protonmail.ch>
Date: Sat, 23 Oct 2021 17:13:50 -0400
Subject: [PATCH 1/2] Allow git-annex fix on crippled filesystem
---
Command/Fix.hs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Command/Fix.hs b/Command/Fix.hs
index 39853c894..2d66c1461 100644
--- a/Command/Fix.hs
+++ b/Command/Fix.hs
@@ -31,7 +31,7 @@ cmd = noCommit $ withAnnexOptions [annexedMatchingOptions] $
paramPaths (withParams seek)
seek :: CmdParams -> CommandSeek
-seek ps = unlessM crippledFileSystem $
+seek ps =
withFilesInGitAnnex ww seeker =<< workTreeItems ww ps
where
ww = WarnUnmatchLsFiles
--
2.30.2
```
2022-09-27 00:45:22 +00:00
</details>
2022-09-24 23:23:40 +00:00
2022-09-24 22:31:54 +00:00
** Usage tips **
2021-10-22 22:13:46 +00:00
2022-09-30 18:03:50 +00:00
* WSL1 will not create symlinks that work in Windows if created before the target file exists, such as after `git annex add` or `git annex get`. This can be fixed by recreating them with any method, such as delete them and `git checkout`.
2022-09-27 00:45:22 +00:00
<details>
<summary>Sample script to recreate all symlinks under the current directory</summary>
2022-09-24 22:31:54 +00:00
2022-09-24 23:27:17 +00:00
```
#!/usr/bin/env python3
2022-09-24 22:31:54 +00:00
2022-09-24 23:27:17 +00:00
import pathlib
import os
2022-09-24 22:31:54 +00:00
2022-09-24 23:27:17 +00:00
def do(p):
for c in list(p.iterdir()):
if c.is_symlink() and c.resolve().exists():
target = os.readlink(c) # use readlink here to get the relative link path
c.unlink()
c.symlink_to(target)
elif c.is_dir() and c.name != '.git':
do(c)
2022-09-24 22:31:54 +00:00
2022-09-24 23:27:17 +00:00
do(pathlib.Path('.'))
```
2022-09-27 00:45:22 +00:00
</details>
2022-09-24 22:31:54 +00:00
* Sometimes there will SQLite errors using multiple jobs but retrying will work most of the time.
** Related bugs **
* [[bugs/WSL_adjusted_braches__58___smudge_fails_with_sqlite_thread_crashed_-_locking_protocol]]
* [[bugs/WSL1__58___git-annex-add_fails_in_DrvFs_filesystem]]
* [[bugs/problems_with_SSH_and_relative_paths]]