utils: Use 'scandir' instead of custom 'for-each-file'
* src/mcron/utils.scm (for-each-file): Delete. * src/mcron/scripts/cron.scm (process-files-in-system-directory): Use 'scandir' which has the benefit of being deterministic. * src/mcron/scripts/mcron.scm (process-files-in-user-directory): Likewise. * tests/schedule.sh: Update expected output which is now more reliable. * NEWS: Update. Suggested-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
		
					parent
					
						
							
								09e452b62a
							
						
					
				
			
			
				commit
				
					
						f908c5395c
					
				
			
		
					 5 changed files with 26 additions and 36 deletions
				
			
		
							
								
								
									
										2
									
								
								NEWS
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								NEWS
									
										
									
									
									
								
							| 
						 | 
					@ -15,6 +15,8 @@ GNU Mcron NEWS                                    -*- outline -*-
 | 
				
			||||||
  Some basic tests for the installed programs can be run after 'make install'
 | 
					  Some basic tests for the installed programs can be run after 'make install'
 | 
				
			||||||
  with 'make installcheck'.
 | 
					  with 'make installcheck'.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  The configuration files are now processed using a deterministic order.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* Noteworthy changes in release 1.1 (2018-03-19) [stable]
 | 
					* Noteworthy changes in release 1.1 (2018-03-19) [stable]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
** New features
 | 
					** New features
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
;;;; cron -- daemon for running jobs at scheduled times
 | 
					;;;; cron -- daemon for running jobs at scheduled times
 | 
				
			||||||
;;; Copyright © 2003, 2012 Dale Mellor <dale_mellor@users.sourceforge.net>
 | 
					;;; Copyright © 2003, 2012 Dale Mellor <dale_mellor@users.sourceforge.net>
 | 
				
			||||||
;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org>
 | 
					;;; Copyright © 2015, 2016, 2018 Mathieu Lirzin <mthl@gnu.org>
 | 
				
			||||||
;;;
 | 
					;;;
 | 
				
			||||||
;;; This file is part of GNU Mcron.
 | 
					;;; This file is part of GNU Mcron.
 | 
				
			||||||
;;;
 | 
					;;;
 | 
				
			||||||
| 
						 | 
					@ -18,6 +18,7 @@
 | 
				
			||||||
;;; along with GNU Mcron.  If not, see <http://www.gnu.org/licenses/>.
 | 
					;;; along with GNU Mcron.  If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define-module (mcron scripts cron)
 | 
					(define-module (mcron scripts cron)
 | 
				
			||||||
 | 
					  #:use-module (ice-9 ftw)
 | 
				
			||||||
  #:use-module (mcron base)
 | 
					  #:use-module (mcron base)
 | 
				
			||||||
  #:use-module (mcron config)
 | 
					  #:use-module (mcron config)
 | 
				
			||||||
  #:use-module (mcron job-specifier)
 | 
					  #:use-module (mcron job-specifier)
 | 
				
			||||||
| 
						 | 
					@ -84,13 +85,13 @@ operation.  The permissions on the /var/cron/tabs directory enforce this."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  (catch #t
 | 
					  (catch #t
 | 
				
			||||||
    (λ ()
 | 
					    (λ ()
 | 
				
			||||||
      (for-each-file
 | 
					      (for-each
 | 
				
			||||||
       (λ (user)
 | 
					       (λ (user)
 | 
				
			||||||
         (and-let* ((entry (user-entry user))) ;crontab without user?
 | 
					         (and-let* ((entry (user-entry user))) ;crontab without user?
 | 
				
			||||||
           (set-configuration-user entry)
 | 
					           (set-configuration-user entry)
 | 
				
			||||||
           (catch-mcron-error
 | 
					           (catch-mcron-error
 | 
				
			||||||
            (read-vixie-file (string-append config-spool-dir "/" user)))))
 | 
					            (read-vixie-file (string-append config-spool-dir "/" user)))))
 | 
				
			||||||
       config-spool-dir))
 | 
					       (scandir config-spool-dir)))
 | 
				
			||||||
    (λ (key . args)
 | 
					    (λ (key . args)
 | 
				
			||||||
      (mcron-error 4
 | 
					      (mcron-error 4
 | 
				
			||||||
        "You do not have permission to access the system crontabs."))))
 | 
					        "You do not have permission to access the system crontabs."))))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
;;;; mcron -- run jobs at scheduled times
 | 
					;;;; mcron -- run jobs at scheduled times
 | 
				
			||||||
;;; Copyright © 2003, 2012 Dale Mellor <dale_mellor@users.sourceforge.net>
 | 
					;;; Copyright © 2003, 2012 Dale Mellor <dale_mellor@users.sourceforge.net>
 | 
				
			||||||
;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org>
 | 
					;;; Copyright © 2015, 2016, 2018 Mathieu Lirzin <mthl@gnu.org>
 | 
				
			||||||
;;;
 | 
					;;;
 | 
				
			||||||
;;; This file is part of GNU Mcron.
 | 
					;;; This file is part of GNU Mcron.
 | 
				
			||||||
;;;
 | 
					;;;
 | 
				
			||||||
| 
						 | 
					@ -18,6 +18,7 @@
 | 
				
			||||||
;;; along with GNU Mcron.  If not, see <http://www.gnu.org/licenses/>.
 | 
					;;; along with GNU Mcron.  If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define-module (mcron scripts mcron)
 | 
					(define-module (mcron scripts mcron)
 | 
				
			||||||
 | 
					  #:use-module (ice-9 ftw)
 | 
				
			||||||
  #:use-module (mcron base)
 | 
					  #:use-module (mcron base)
 | 
				
			||||||
  #:use-module (mcron config)
 | 
					  #:use-module (mcron config)
 | 
				
			||||||
  #:use-module (mcron job-specifier)    ;for user/system files
 | 
					  #:use-module (mcron job-specifier)    ;for user/system files
 | 
				
			||||||
| 
						 | 
					@ -49,11 +50,10 @@ $XDG_CONFIG_HOME is not defined uses ~/.config/cron instead)."
 | 
				
			||||||
    (map (λ (dir)
 | 
					    (map (λ (dir)
 | 
				
			||||||
           (catch #t
 | 
					           (catch #t
 | 
				
			||||||
             (λ ()
 | 
					             (λ ()
 | 
				
			||||||
               (for-each-file
 | 
					               (for-each (λ (file)
 | 
				
			||||||
                (λ (file)
 | 
					 | 
				
			||||||
                           (process-user-file (string-append dir "/" file)
 | 
					                           (process-user-file (string-append dir "/" file)
 | 
				
			||||||
                                              #:input input-type))
 | 
					                                              #:input input-type))
 | 
				
			||||||
                dir))
 | 
					                         (scandir dir)))
 | 
				
			||||||
             (λ (key . args)
 | 
					             (λ (key . args)
 | 
				
			||||||
               (set! errors (1+ errors)))))
 | 
					               (set! errors (1+ errors)))))
 | 
				
			||||||
         (list (string-append home-directory "/.cron")
 | 
					         (list (string-append home-directory "/.cron")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
;;;; utils.scm -- helper procedures
 | 
					;;;; utils.scm -- helper procedures
 | 
				
			||||||
;;; Copyright © 2003, 2012 Dale Mellor <dale_mellor@users.sourceforge.net>
 | 
					;;; Copyright © 2003, 2012 Dale Mellor <dale_mellor@users.sourceforge.net>
 | 
				
			||||||
;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org>
 | 
					;;; Copyright © 2015, 2016, 2018 Mathieu Lirzin <mthl@gnu.org>
 | 
				
			||||||
;;;
 | 
					;;;
 | 
				
			||||||
;;; This file is part of GNU Mcron.
 | 
					;;; This file is part of GNU Mcron.
 | 
				
			||||||
;;;
 | 
					;;;
 | 
				
			||||||
| 
						 | 
					@ -29,7 +29,6 @@
 | 
				
			||||||
            parse-args
 | 
					            parse-args
 | 
				
			||||||
            show-version
 | 
					            show-version
 | 
				
			||||||
            show-package-information
 | 
					            show-package-information
 | 
				
			||||||
            for-each-file
 | 
					 | 
				
			||||||
            process-update-request)
 | 
					            process-update-request)
 | 
				
			||||||
  #:re-export (option-ref
 | 
					  #:re-export (option-ref
 | 
				
			||||||
               read-string))
 | 
					               read-string))
 | 
				
			||||||
| 
						 | 
					@ -81,18 +80,6 @@ General help using GNU software: <http://www.gnu.org/gethelp/>\n"
 | 
				
			||||||
		 config-package-name
 | 
							 config-package-name
 | 
				
			||||||
		 config-package-url))
 | 
							 config-package-url))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define (for-each-file proc directory)
 | 
					 | 
				
			||||||
  "Apply PROC to each file in DIRECTORY.  DIRECTORY must be a valid directory name.
 | 
					 | 
				
			||||||
PROC must be a procedure that take one file name argument.  The return value
 | 
					 | 
				
			||||||
is not specified"
 | 
					 | 
				
			||||||
  (let ((dir (opendir directory)))
 | 
					 | 
				
			||||||
    (let loop ((file-name (readdir dir)))
 | 
					 | 
				
			||||||
      (if (eof-object? file-name)
 | 
					 | 
				
			||||||
          (closedir dir)
 | 
					 | 
				
			||||||
          (begin
 | 
					 | 
				
			||||||
            (proc file-name)
 | 
					 | 
				
			||||||
            (loop (readdir dir)))))))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
(define (process-update-request fdes-list)
 | 
					(define (process-update-request fdes-list)
 | 
				
			||||||
  "Read a user name from the socket, dealing with the /etc/crontab special
 | 
					  "Read a user name from the socket, dealing with the /etc/crontab special
 | 
				
			||||||
case, remove all the user's jobs from the job list, and then re-read the
 | 
					case, remove all the user's jobs from the job list, and then re-read the
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -41,14 +41,10 @@ EOF
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cat > expected <<EOF
 | 
					cat > expected <<EOF
 | 
				
			||||||
Thu Jan  1 00:00:01 1970 +0000
 | 
					Thu Jan  1 00:00:01 1970 +0000
 | 
				
			||||||
(display foo
 | 
					(display bar
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Thu Jan  1 00:00:01 1970 +0000
 | 
					Thu Jan  1 00:00:01 1970 +0000
 | 
				
			||||||
(display bar
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Thu Jan  1 00:00:02 1970 +0000
 | 
					 | 
				
			||||||
(display foo
 | 
					(display foo
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -56,7 +52,7 @@ Thu Jan  1 00:00:02 1970 +0000
 | 
				
			||||||
(display bar
 | 
					(display bar
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Thu Jan  1 00:00:03 1970 +0000
 | 
					Thu Jan  1 00:00:02 1970 +0000
 | 
				
			||||||
(display foo
 | 
					(display foo
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -64,7 +60,7 @@ Thu Jan  1 00:00:03 1970 +0000
 | 
				
			||||||
(display bar
 | 
					(display bar
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Thu Jan  1 00:00:04 1970 +0000
 | 
					Thu Jan  1 00:00:03 1970 +0000
 | 
				
			||||||
(display foo
 | 
					(display foo
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -72,7 +68,7 @@ Thu Jan  1 00:00:04 1970 +0000
 | 
				
			||||||
(display bar
 | 
					(display bar
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Thu Jan  1 00:00:05 1970 +0000
 | 
					Thu Jan  1 00:00:04 1970 +0000
 | 
				
			||||||
(display foo
 | 
					(display foo
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -80,7 +76,7 @@ Thu Jan  1 00:00:05 1970 +0000
 | 
				
			||||||
(display bar
 | 
					(display bar
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Thu Jan  1 00:00:06 1970 +0000
 | 
					Thu Jan  1 00:00:05 1970 +0000
 | 
				
			||||||
(display foo
 | 
					(display foo
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -88,7 +84,7 @@ Thu Jan  1 00:00:06 1970 +0000
 | 
				
			||||||
(display bar
 | 
					(display bar
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Thu Jan  1 00:00:07 1970 +0000
 | 
					Thu Jan  1 00:00:06 1970 +0000
 | 
				
			||||||
(display foo
 | 
					(display foo
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -96,7 +92,7 @@ Thu Jan  1 00:00:07 1970 +0000
 | 
				
			||||||
(display bar
 | 
					(display bar
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Thu Jan  1 00:00:08 1970 +0000
 | 
					Thu Jan  1 00:00:07 1970 +0000
 | 
				
			||||||
(display foo
 | 
					(display foo
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -104,7 +100,7 @@ Thu Jan  1 00:00:08 1970 +0000
 | 
				
			||||||
(display bar
 | 
					(display bar
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Thu Jan  1 00:00:09 1970 +0000
 | 
					Thu Jan  1 00:00:08 1970 +0000
 | 
				
			||||||
(display foo
 | 
					(display foo
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -112,7 +108,7 @@ Thu Jan  1 00:00:09 1970 +0000
 | 
				
			||||||
(display bar
 | 
					(display bar
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Thu Jan  1 00:00:10 1970 +0000
 | 
					Thu Jan  1 00:00:09 1970 +0000
 | 
				
			||||||
(display foo
 | 
					(display foo
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -120,6 +116,10 @@ Thu Jan  1 00:00:10 1970 +0000
 | 
				
			||||||
(display bar
 | 
					(display bar
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Thu Jan  1 00:00:10 1970 +0000
 | 
				
			||||||
 | 
					(display foo
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
EOF
 | 
					EOF
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mcron --schedule=10 > output
 | 
					mcron --schedule=10 > output
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue