Commit graph

1812 commits

Author SHA1 Message Date
Joey Hess
6fcccbba19
clean up imports needed by old versions of ghc
Now that ghc 9.0.2 is the oldest supported version.

Eg cruft from
https://web.archive.org/web/20190424185034/https://prime.haskell.org/wiki/Libraries/Proposals/SemigroupMonoid

Sponsored-by: Jack Hill
2025-09-23 13:55:13 -04:00
Joey Hess
06a813ad44
set locale encoding after fdTohandle
fdToHandle does not set the usual system locale encoding,
so when the Handle is used for any String IO, it needs to be done
manually for correctness.

I don't know if this fixes any bugs. It might eg, fix a bug with
multicast receive of a file.

Sponsored-by: Leon Schuermann
2025-09-15 21:35:38 -04:00
Joey Hess
3e9807bc03
work around file-io not setting locale encoding when opening a Handle
Works around this bug https://github.com/haskell/file-io/issues/45

The fix is in Utility.FileIO.CloseOnExec because all use of file-io is
already wrapped through that module. Although perhaps that ought to be
refactored at this point.

I'd hope that file-io will eventually fix this bug, and also provide
CloseOnExec variants of its functions. That would allow depending on the
fixed version, and removing this ugly code.

Note that, functions like readFile that don't care about the encoding
due to reading/writing a ByteString were kept optimally fast by not
setting the encoding. This avoids an IORef read and write per open.

Sponsored-by: Graham Spencer
2025-09-15 19:25:03 -04:00
Joey Hess
829223a6e7
small optimisation 2025-09-15 13:49:14 -04:00
Joey Hess
11e7211d7b
drop problem end characters from filename operating on String not RawFilePath
Fix bug that could cause an invalid utf-8 sequence to be used in a
temporary filename when the input filename was valid utf-8.

Sponsored-by: k0ld
2025-09-15 13:42:50 -04:00
Joey Hess
38786a4e5e
noCreateProcessWhile to fix close-on-exec races
Sponsored-by: the NIH-funded NICEMAN (ReproNim TR&D3) project
2025-09-10 14:29:15 -04:00
Joey Hess
adf1dbb5ca
always import Utility.Process rather than System.Process
This is groundwork for Utility.Process doing some extra locking, for
which it's important that it's always used for process creation.
2025-09-10 13:53:50 -04:00
Joey Hess
3c1975ce7e
windows build fixes 2025-09-10 13:34:17 -04:00
Joey Hess
0fc822f707
Removed support for building with cryptonite, use crypton.
cryptonite is not maintained and has security problems.
Debian stable includes crypton by now.
2025-09-10 13:21:06 -04:00
Joey Hess
6f9a9c81f6
convert all readFile, writeFile, and appendFile to close-on-exec safe versions
Even in the Build system. This allows grepping to make sure that there
are none left un-converted:

git grep "writeFile" |grep -v F\\.| grep -v doc/|grep -v writeFileString | grep -v writeFileProtected |grep -v Utility/FileIO
git grep "readFile" |grep -v F\\.| grep -v doc/|grep -v readFileString |grep -v Utility/FileIO
git grep "appendFile" |grep -v F\\.| grep -v doc/|grep -v appendFileString |grep -v Utility/FileIO

Might be nice to automate that to prevent future mistakes...

Sponsored-by: the NIH-funded NICEMAN (ReproNim TR&D3) project
2025-09-05 15:44:32 -04:00
Joey Hess
867110e9ee
add readFileString, writeFileString, appendFileString
Exported by Common, so they will be available everywhere.
These are the same as readFile, writeFile, appendFile.
But have two benefits:

* They take OsPath, so using them avoids converting back and forth
  unncessarily.
* They use the close-on-exec flag so can't leak FDs to child processes.
  Unlike the standard Haskell versions which unfortunately have that
  wart currently. (I do hope the standard versions get fixed
  eventually.)

Sponsored-by: the NIH-funded NICEMAN (ReproNim TR&D3) project
2025-09-05 14:54:36 -04:00
Joey Hess
c18581c356
Utility.FileIO: set close-on-exec flag for all functions
Utility.FileIO.CloseOnExec is largely copied from
System.File.OsPath.Internal with the simple modification of
setting the flag.

Unfortunately, openTempFile does not set the flag when
opening the file, but afterwards, leaving it vulnerable to a race.
A lot of code, including posix and windows specific code,
would need to be copied from file-io in order to fix that.
Still, I consider this implementation a placeholder, it doesn't truely
fix all instances of the problem.

I hope that this will be addressed in file-io itself, see
https://github.com/haskell/file-io/issues/44

Utility.FileIO.CloseOnExec could form the basis of a
file-io-closeonexec library, depending on how things go with that
issue.

Sponsored-by: the NIH-funded NICEMAN (ReproNim TR&D3) project
2025-09-05 13:36:50 -04:00
Joey Hess
6662b49d35
convert all bytestring readFile/writeFile to use Utility.FileIO
This is groundwork for setting the close-on-exec flag when opening
files, which will be done in Utility.FileIO or a similar module using the same
function names. The bytestring library does not set that flag, even though it
could, and IMHO should.

Note that there are many calls to the Prelude's readFile/writeFile/appendFile
still in git-annex, and this does not address those.

Sponsored-by: the NIH-funded NICEMAN (ReproNim TR&D3) project
2025-09-05 12:13:28 -04:00
Joey Hess
033e4b086f
audit all openFd and dupping for close-on-exec
Made all uses of openFd and dup set the close-on-exec flag, with a few
exceptions when starting a git-annex daemon.

Made openFdWithMode be used everywhere, rather than openFd.
Adding a new parameter to it ensures I checked everything.
And will help to make sure this gets considered in the future when
opening fds.

In lockPidFile, the only thing that keeps the pid file locked, once
daemonize re-runs the command in a new session, is that the fd is
inherited.

In Utility.LogFile.redir, the new fd it dups to does not have the
close-on-exec flag set, because this is used to set up the stdout and
stderr fds, which need to be inherited by child processes.

Same in Assistant.startDaemon where the browser gets started with the
original stdout and stderr.

This does nothing about uses of openFile and similar!

Sponsored-By: mycroft
2025-09-04 16:01:41 -04:00
Joey Hess
6ba848d275
avoid overhead of fcntl when setting close-on-exec
unix-2.8.0 adds cloexec to OpenFileFlags, rather than needing to call
setFdOption after opening.

This also might avoid a race, if another thread started a process at
just the wrong time, before the flag got set, it could inherit the FD.

Unfortunately, the arm64-ancient build needs support for older versions
of unix than that, so had to ifdef. That build is still needed to
support using git-annex in termux on phones like mine, I have confirmed
today.

Sponsored-by: Luke T. Shumaker
2025-09-04 15:04:03 -04:00
Joey Hess
67f00027d1
avoid relatedTemplate ever returning ""
add: Fix crash adding filenames that are exactly 21 bytes long and begin
with a utf-8 character.

Also longer filenames that start with "....." would cause the same crash.

I also audited for other calls to truncateFilePath that could truncate it
to "". Most use pathmax so are not a problem. Backend.Utilities.genKeyName
could possibly truncate it like that, but appends the md5 so would not be a
problem either.

Sponsored-by: Kevin Mueller
2025-09-04 13:02:46 -04:00
Joey Hess
c15dad6040
improve AuthToken display in P2P --debug
Using an empty string to obscure the AuthToken made it impossible to
tell if one was really being presented or not.
2025-08-01 12:58:03 -04:00
Joey Hess
f1781d01d8
remotedaemon support for generic P2P transports
RemoteDaemon.Transport.Tor was refactored into this, and most of the
code is reused between them.

getSocketFile does not yet deal with repositories on crippled
filesystems that don't support sockets. Annex.Ssh detects that and
allows the user to set an environment variable, and something similar
could be done here.

And it does not deal with a situation where there is no path to the
socket file that is not too long. In that situation it would crash out
I suppose. Probably though, remotedaemon is ran from the top of the
repo, and in that case the path is just ".git/annex/p2p/<md5>" so nice
and short.

This seems to mostly work. But I don't yet have a working git-annex-p2p-
command to test it with.

And with my not quite working git-annex-p2p-foo test script, running
remotedaemon results in an ever-growing number of zombie processes
that it's not waiting on.
2025-07-31 14:45:32 -04:00
Joey Hess
2007507e2b
prevent relatedTemplate from truncating a filename to end in whitespace
Avoid a problem with temp file names ending in whitespace on filesystems
like VFAT that don't support such filenames.

See a6eb7d7339 previously for the same but
with "."

At some point relatedTemplate is more bother than it's worth and it would
be simpler to just use "temp" as the basename of all temp files. We seem to
be approaching that point, since my interest in absurd ancient filesystem
limitations is limited.

Sponsored-by: unqueued on Patreon
2025-06-23 13:31:15 -04:00
Joey Hess
73060eea51
annex.fastcopy
Added annex.fastcopy and remote.name.annex-fastcopy config setting. When
set, this allows the copy_file_range syscall to be used, which can eg allow
for server-side copies on NFS. (For fastest copying, also disable
annex.verify or remote.name.annex-verify.)

This is a simple implementation, that does not handle resuming as well as
it possibly could.

It can be used with both local git remotes (including on NFS), and
directory special remotes. Other types of remotes could in theory also
support it, so I've left the config documented as a general thing.
2025-06-03 15:01:38 -04:00
Joey Hess
b111009868
moveFile on windows forgot to delete src file in fallback case
This dates back to commit 625303226d,
where a cross-device moveFile on Windows was made to fall back to copying
to the destination, but forgot to delete the source file.

Should fix the following test suite failure on Windows:

    import:                                FAIL (2.52s)
      .\Test\Framework.hs:383:
      C:\Users\RUNNER~1\AppData\Local\Temp\importtest.0\import1\f exists unexpectedly
      Use -p '/import/' to rerun this test only.

Which was seen here, running the test suite in the github action environment.
https://github.com/psychoinformatics-de/git-annex-wheel/issues/5
2025-05-30 13:18:26 -04:00
Joey Hess
dbc00906bf
Fix build without the assistant. 2025-03-26 10:17:03 -04:00
Joey Hess
81ce4264df
compute: add response to OUTPUT
This allows rejecting output filenames that are outside the repository,
and also handles converting eg "-foo" to "./-foo" to prevent a command
that it's passed to interpreting the output filename as a dashed option.
2025-03-07 14:47:34 -04:00
Joey Hess
9f2ce19858
OSX build fix 2025-02-17 14:01:54 -04:00
Joey Hess
66b8ba8fb0
OSX build fixes 2025-02-17 13:59:52 -04:00
Joey Hess
25e4f84e8f
push down OsPath into CopyFile 2025-02-12 13:11:27 -04:00
Joey Hess
0f47eceacf
stop exporting RawFilePath 2025-02-12 12:59:30 -04:00
Joey Hess
fb0ecb997f
Merge branch 'ospathwin2' into ospath 2025-02-11 16:46:01 -04:00
Joey Hess
6653e000f0 fix convertToWindowsNativeNameSpace bug
This fixes a test suite failure. The OsPath conversion made that be used
in more places, including addurl, which exposed an existing bug.
2025-02-11 20:37:40 -08:00
Joey Hess
769c7b3e65
avoid build warning on windows 2025-02-11 16:31:35 -04:00
Joey Hess
a149336a59
OsPath transition Windows build fixes
This gets it building on Windows again, with 1 test suite failure
(addurl).

Sponsored-by: Kevin Mueller
2025-02-11 15:40:53 -04:00
Joey Hess
19dea33f57
more OsPath conversion 2025-02-11 14:00:01 -04:00
Joey Hess
a5eaf3d4d2
use to/fromOsPath
Just to reduce the number of from/toRawFilePath calls, which I would
like to minimize.

In this build path, the two are the same though.
2025-02-11 13:54:51 -04:00
Joey Hess
780a379ab1
remove unused functions from Utility.RawFilePath 2025-02-11 13:49:17 -04:00
Joey Hess
c85d5a0dc8
OsPath conversion of linuxstandalone builder
Sponsored-by: Joshua Antonishen
2025-02-11 12:12:27 -04:00
Joey Hess
2ff716be30
OsPath build flag no longer depends on filepath-bytestring
However, filepath-bytestring is still in Setup-Depends.
That's because Utility.OsPath uses it when not built with OsPath.
It would be maybe possible to make Utility.OsPath fall back to using
filepath, and eliminate that dependency too, but it would mean either
wrapping all of System.FilePath's functions, or using `type OsPath = FilePath`

Annex.Import uses ifdefs to avoid converting back to FilePath when not
on windows. On windows it's a bit slower due to that conversion.
Utility.Path.Windows.convertToWindowsNativeNamespace got a bit
slower too, but not really worth optimising I think.

Note that importing Utility.FileSystemEncoding at the same time as
System.Posix.ByteString will result in conflicting definitions for
RawFilePath. filepath-bytestring avoids that by importing RawFilePath
from System.Posix.ByteString, but that's not possible in
Utility.FileSystemEncoding, since Setup-Depends does not include unix.
This turned out not to affect any code in git-annex though.

Sponsored-by: Leon Schuermann
2025-02-10 16:39:55 -04:00
Joey Hess
c730d00b6e
more OsPath conversion (749/749)
Builds with and without OsPath build flag.

Unfortunately, the test suite fails.

Sponsored-by: unqueued on Patreon
2025-02-10 14:59:20 -04:00
Joey Hess
20ed039d59
don't export pack and unpack
These are too widly used for other things to make sense to export OsPath
versions of them. And OsString also provides them and gets imported
qualified when needed.
2025-02-10 12:34:13 -04:00
Joey Hess
2d224e0d28
more OsPath conversion (658/749)
At this point the test suite builds, and mostly the assistant is left.

Sponsored-by: unqueued
2025-02-08 15:27:44 -04:00
Joey Hess
c74c75b352
more OsPath conversion (639/749)
Sponsored-by: k0ld
2025-02-07 16:07:05 -04:00
Joey Hess
a5d48edd94
more OsPath conversion (602/749)
Sponsored-by: Brock Spratlen
2025-02-07 14:46:11 -04:00
Joey Hess
2d1db7986c
more OsPath conversion (572/749)
Sponsored-by: Jack Hill
2025-02-06 16:18:52 -04:00
Joey Hess
0811531b59
more OsPath conversion (542/749)
Sponsored-by: Luke T. Shumaker
2025-02-06 11:38:14 -04:00
Joey Hess
9394197621
Merge branch 'master' into ospath 2025-02-05 13:31:07 -04:00
Joey Hess
4dc904bbad
more OsPath conversion
Sponsored-by: Leon Schuermann
2025-02-04 16:09:47 -04:00
Joey Hess
5cc8d9d03b
replace removeLink with removeFile
removeFile calls unlink so removes anything not a directory. So these
are replaceable in order to convert to OsPath.
2025-02-02 14:16:58 -04:00
Joey Hess
71195cce13
more OsPath conversion
Sponsored-by: k0ld
2025-02-01 14:06:38 -04:00
Joey Hess
474cf3bc8b
more OsPath conversion
Sponsored-by: Brock Spratlen
2025-02-01 11:54:19 -04:00
Joey Hess
0c0f4a20f4
move windows test suite workaround to relatedTemplate 2025-01-30 19:06:06 -04:00
Joey Hess
773115fd5f
fix truncateFilePath edge case on windows
If the filepath starts with something that is not valid utf-8, it would
have returned "". And if the filepath was all non-valid utf-8, it would
also return "".
2025-01-30 16:53:10 -04:00