GNU bug report logs -
#76623
[PATCH] filesys.c: Use scm_sendfile to copy files.
Previous Next
Reported by: Tomas Volf <~@wolfsden.cz>
Date: Fri, 28 Feb 2025 01:11:03 UTC
Severity: normal
Tags: patch
Done: Rob Browning <rlb <at> defaultvalue.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your message dated Wed, 19 Mar 2025 21:30:54 -0500
with message-id <87frj8wi01.fsf <at> trouble.defaultvalue.org>
and subject line Re: bug#76623: [PATCH] filesys.c: Use scm_sendfile to copy files.
has caused the debbugs.gnu.org bug report #76623,
regarding [PATCH] filesys.c: Use scm_sendfile to copy files.
to be marked as done.
(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)
--
76623: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=76623
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
Use scm_sendfile instead of read-write loop. This moves the work into
the kernel, improving performance. This implements Ludovic's suggestion
from bug 68504.
* libguile/filesys.c (scm_copy_file2): Use scm_sendfile.
---
libguile/filesys.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/libguile/filesys.c b/libguile/filesys.c
index 3bfa5eb91..8a05f066f 100644
--- a/libguile/filesys.c
+++ b/libguile/filesys.c
@@ -1,7 +1,7 @@
/* Copyright 1996-2002,2004,2006,2009-2019,2021
Free Software Foundation, Inc.
Copyright 2021 Maxime Devos <maximedevos <at> telenet.be>
- Copyright 2024 Tomas Volf <~@wolfsden.cz>
+ Copyright 2024, 2025 Tomas Volf <~@wolfsden.cz>
This file is part of Guile.
@@ -1354,13 +1354,18 @@ SCM_DEFINE (scm_copy_file2, "copy-file", 2, 0, 1,
scm_syserror ("copy-file: copy-on-write failed");
if (clone_res)
- while ((n = read (oldfd, buf, sizeof buf)) > 0)
- if (write (newfd, buf, n) != n)
- {
- close (oldfd);
- close (newfd);
- SCM_SYSERROR;
- }
+ {
+ off_t end;
+ if ((end = lseek_or_lseek64 (oldfd, 0, SEEK_END)) < 0)
+ SCM_SYSERROR;
+ if (lseek_or_lseek64 (oldfd, 0, SEEK_SET) < 0)
+ SCM_SYSERROR;
+
+ scm_sendfile (scm_from_int (newfd),
+ scm_from_int (oldfd),
+ scm_from_off_t (end),
+ SCM_UNDEFINED);
+ }
close (oldfd);
if (close (newfd) == -1)
SCM_SYSERROR;
--
2.48.1
[Message part 3 (message/rfc822, inline)]
Ludovic Courtès <ludo <at> gnu.org> writes:
> The patch LGTM but I realize there’s no real ‘copy-file’ test. Not your
> fault but would you mind adding one or two tests?
I went ahead and added a commit to include some simple tests and pushed
that and this to main.
--
Rob Browning
rlb @defaultvalue.org and @debian.org
GPG as of 2011-07-10 E6A9 DA3C C9FD 1FF8 C676 D2C4 C0F0 39E9 ED1B 597A
GPG as of 2002-11-03 14DD 432F AE39 534D B592 F9A0 25C8 D377 8C7E 73A4
This bug report was last modified 56 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.