Hello Stan, Thanks for your fix. I have applied the patch and created a new release of filepath (1.7). All the best,
Ivan On Fri, Dec 12, 2025 at 7:42 AM Stanislav Kljuhhin via Chicken-users <[email protected]> wrote: > > Hi, > > There’s a silly bug in Ivan Raikov’s filpath egg, which causes > filepath:replace-file-name to simply drop the filename from path, > regardless of the value of the file argument. The attached patch > amends that. > > Before the fix: > > (filepath:replace-file-name "/tmp/file" "another") => "/tmp/file/" > > After the fix: > > (filepath:replace-file-name "/tmp/file" "another") => "/tmp/another” > > -- > Stan > > ----8<---- > > From 1f476f7a09fdb53e405ed4e3d234bfd50c97bcdf Mon Sep 17 00:00:00 2001 > From: Stanislav Kljuhhin <[email protected]> > Date: Fri, 12 Dec 2025 16:20:57 +0100 > Subject: [PATCH] Fix silly bug in filepath:replace-file-name > > Due to a wrong order of operations the implementation was just dropping > the file name from path, regardless of the value of the file argument. > > Before the fix: > > (filepath:replace-file-name "/tmp/file" "another") => "/tmp/file/" > > After the fix: > > (filepath:replace-file-name "/tmp/file" "another") => "/tmp/another" > --- > filepath.scm | 2 +- > tests/run.scm | 13 +++++++++++++ > 2 files changed, 14 insertions(+), 1 deletion(-) > > diff --git a/filepath.scm b/filepath.scm > index c19c520..7468768 100644 > --- a/filepath.scm > +++ b/filepath.scm > @@ -336,7 +336,7 @@ > (list (append c (reverse b)) (reverse a)))))) > > (define (replace-file-name p r) > - (drop-file-name (combine p r))) > + (combine (drop-file-name p) r)) > > (define (drop-file-name p) (first (split-file-name p))) > > diff --git a/tests/run.scm b/tests/run.scm > index 4270a39..f43d4b3 100644 > --- a/tests/run.scm > +++ b/tests/run.scm > @@ -46,6 +46,19 @@ > res (apply filepath:replace-extension p)))) > replace-extension-tests)) > > +(define replace-file-name-tests > + `((("file.txt" "file.pdf") "file.pdf") > + (("file" "another") "another") > + (("/tmp/file" "another") "/tmp/another") > + (("/tmp/" "file") "/tmp/file"))) > + > +(test-group "replace-file-name" > + (for-each (lambda (pr) > + (let ((p (first pr)) (res (second pr))) > + (test (sprintf "~S => ~S" (cons 'replace-file-name > p) res) > + res (apply filepath:replace-file-name p)))) > + replace-file-name-tests)) > + > (define add-extension-tests > `((("file.txt" "bib") "file.txt.bib") > (("file." ".bib") "file..bib") > -- > 2.52.0 > > ----8<---- > >
