Re: [Chicken-hackers] [PATCH] Make setting of the file modification time saner

2017-06-06 Thread Peter Bex
On Mon, Jun 05, 2017 at 11:11:06PM +0200, Kooda wrote:
> Both changes signed off and pushed. :)
> 
> Sorry for the delay.

No worries, and many thanks for taking a look!

Cheers,
Peter


signature.asc
Description: Digital signature
___
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers


Re: [Chicken-hackers] [PATCH] Make setting of the file modification time saner

2017-06-05 Thread Kooda
Both changes signed off and pushed. :)

Sorry for the delay.

___
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers


Re: [Chicken-hackers] [PATCH] Make setting of the file modification time saner

2017-05-14 Thread Peter Bex
On Wed, May 10, 2017 at 10:51:52PM +0200, Peter Bex wrote:
> Hi all,
> 
> While working on the docs for (chicken file posix), I noticed some
> discrepancies:
> 
> - file-access-time and file-change-time have no associated setter,
>but file-modification-time does.
> - The setter for file-modification-time sets both mtime AND atime,
>even though (set! (file-modification-time f) x) implies that
>we're setting ONLY the mtime.
> - The getters all accept strings, ports and file descriptors; the
>setter only accepts a string.

A similar thing applies to change-file-owner and change-file-mode:

- The "setters" change-file-owner and change-file-mode are in
   (chicken file), whereas the "getters" file-owner and
   file-permissions are in (chicken file posix)
- The getters and setters aren't named similarly: it makes more
   sense for change-file-mode to be named set-file-permissions!
   and for change-file-owner to be named set-file-owner!
- The "file-permissions" getter returns the raw _st_mode value,
   which also includes the file type.  It's better to mask out
   the file type, so that it's symmetric with the values accepted
   by the setter.
- The setter for file ownership sets both the uid AND the gid.
   If we want to make this consistent with the getter, it makes
   more sense to set only the uid.
- While we can set the gid, we can't get it; "file-group" is missing.
- The getters all accept strings, ports and file descriptors; the
   setter only accepts a string.

The attached patches make all of this more consistent.

Cheers,
Peter
From 64ecffb31e22c1513c6bbfae7551452efbe4a868 Mon Sep 17 00:00:00 2001
From: Peter Bex 
Date: Sat, 13 May 2017 20:51:14 +0200
Subject: [PATCH 1/3] Move common change-file-mode and file-*-access? code to
 posix-common

The only difference is that in Windows, we don't have [RWX]_OK, but
that we can easily define them in an #ifdef check.
---
 posix-common.scm | 37 +
 posixunix.scm| 25 -
 posixwin.scm | 30 --
 3 files changed, 37 insertions(+), 55 deletions(-)

diff --git a/posix-common.scm b/posix-common.scm
index e3e6739..89eeec2 100644
--- a/posix-common.scm
+++ b/posix-common.scm
@@ -47,6 +47,17 @@ static C_TLS struct stat C_statbuf;
 # define S_IFSOCK   014
 #endif
 
+/* For Windows */
+#ifndef R_OK
+#define R_OK			2
+#endif
+#ifndef W_OK
+#define W_OK			4
+#endif
+#ifndef X_OK
+#define X_OK			2
+#endif
+
 #define cpy_tmvec_to_tmstc08(ptm, v) \
 ((ptm)->tm_sec = C_unfix(C_block_item((v), 0)), \
 (ptm)->tm_min = C_unfix(C_block_item((v), 1)), \
@@ -311,6 +322,32 @@ EOF
   (eq? 'directory (file-type file #f #f)))
 
 
+(define change-file-mode
+  (lambda (fname m)
+(##sys#check-string fname 'change-file-mode)
+(##sys#check-fixnum m 'change-file-mode)
+(when (fx< (##core#inline "C_chmod" (##sys#make-c-string fname 'change-file-mode) m) 0)
+  (posix-error #:file-error 'change-file-mode "cannot change file mode" fname m) ) ) )
+
+(define file-read-access?)
+(define file-write-access?)
+(define file-execute-access?)
+
+(define-foreign-variable _r_ok int "R_OK")
+(define-foreign-variable _w_ok int "W_OK")
+(define-foreign-variable _x_ok int "X_OK")
+
+(let ()
+  (define (check filename acc loc)
+(##sys#check-string filename loc)
+(let ((r (fx= 0 (##core#inline "C_test_access" (##sys#make-c-string filename loc) acc
+  (unless r (##sys#update-errno))
+  r) )
+  (set! file-read-access? (lambda (filename) (check filename _r_ok 'file-read-access?)))
+  (set! file-write-access? (lambda (filename) (check filename _w_ok 'file-write-access?)))
+  (set! file-execute-access? (lambda (filename) (check filename _x_ok 'file-execute-access?))) )
+
+
 ;;; File position access:
 
 (define-foreign-variable _seek_set int "SEEK_SET")
diff --git a/posixunix.scm b/posixunix.scm
index 40b5b75..6b01857 100644
--- a/posixunix.scm
+++ b/posixunix.scm
@@ -911,13 +911,6 @@ EOF
 
 ;;; Permissions and owners:
 
-(define change-file-mode
-  (lambda (fname m)
-(##sys#check-string fname 'change-file-mode)
-(##sys#check-fixnum m 'change-file-mode)
-(when (fx< (##core#inline "C_chmod" (##sys#make-c-string fname 'change-file-mode) m) 0)
-  (posix-error #:file-error 'change-file-mode "cannot change file mode" fname m) ) ) )
-
 (define change-file-owner
   (lambda (fn uid gid)
 (##sys#check-string fn 'change-file-owner)
@@ -926,24 +919,6 @@ EOF
 (when (fx< (##core#inline "C_chown" (##sys#make-c-string fn 'change-file-owner) uid gid) 0)
   (posix-error #:file-error 'change-file-owner "cannot change file owner" fn uid gid) ) ) )
 
-(define-foreign-variable _r_ok int "R_OK")
-(define-foreign-variable _w_ok int "W_OK")
-(define-foreign-variable _x_ok int "X_OK")
-
-(define file-read-access?)
-(define file-write-access?)
-(define file-execute-access?)
-
-(let ()
-  (define (check filename acc loc)
-