aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuanma Barranquero2003-04-29 23:06:50 +0000
committerJuanma Barranquero2003-04-29 23:06:50 +0000
commitf62ebc65ab95313e46326ab1bf9733a028e103ab (patch)
treeacbf4cafa800ffa31a3881b60e2693b716e06327
parentc789e60809a05bfc08c2e87313aa2ccffb167b49 (diff)
downloademacs-f62ebc65ab95313e46326ab1bf9733a028e103ab.tar.gz
emacs-f62ebc65ab95313e46326ab1bf9733a028e103ab.zip
Added a comment explaining the various ways to save a game score on POSIX
systems. (gamegrid-add-score-with-update-game-score): Use `cond' instead of `if'. Provide for the case that FILE is an absolute filename. Create the directory "$HOME/.emacs.d/games", if necessary.
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/play/gamegrid.el75
2 files changed, 61 insertions, 22 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 9c828d92dfa..ba620b86eb0 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12003-04-29 Oliver Scholz <epameinondas@gmx.de>
2
3 * play/gamegrid.el: Added a comment explaining the various ways to
4 save a game score on POSIX systems.
5 (gamegrid-add-score-with-update-game-score): Use `cond' instead of
6 `if'. Provide for the case that FILE is an absolute filename.
7 Create the directory "$HOME/.emacs.d/games", if necessary.
8
12003-04-29 John Paul Wallington <jpw@gnu.org> 92003-04-29 John Paul Wallington <jpw@gnu.org>
2 10
3 * emacs-lisp/bytecomp.el (byte-compile-cl-warn): Use `string-match'. 11 * emacs-lisp/bytecomp.el (byte-compile-cl-warn): Use `string-match'.
diff --git a/lisp/play/gamegrid.el b/lisp/play/gamegrid.el
index 677b3e45268..540498d0971 100644
--- a/lisp/play/gamegrid.el
+++ b/lisp/play/gamegrid.el
@@ -450,6 +450,31 @@ FILE is created there."
450 (t 450 (t
451 (gamegrid-add-score-with-update-game-score file score)))) 451 (gamegrid-add-score-with-update-game-score file score))))
452 452
453
454;; On POSIX systems there are four cases to distinguish:
455
456;; 1. FILE is an absolute filename. Then it should be a file in
457;; temporary file directory. This is the way,
458;; `gamegrid-add-score' was supposed to be used in the past and
459;; is covered here for backward-compatibility.
460;;
461;; 2. The helper program "update-game-score" is setuid and the
462;; file FILE does already exist in a system wide shared game
463;; directory. This should be the normal case on POSIX systems,
464;; if the game was installed system wide. Use
465;; "update-game-score" to add the score to the file in the
466;; shared game directory.
467;;
468;; 3. "update-game-score" is setuid, but the file FILE does *not*
469;; exist in the system wide shared game directory. Use
470;; `gamegrid-add-score-insecure' to create--if necessary--and
471;; update FILE. This is for the case that a user has installed
472;; a game on her own.
473;;
474;; 4. "update-game-score" is not setuid. Use it to create/update
475;; FILE in the user's home directory. There is presumably no
476;; shared game directory.
477
453(defun gamegrid-add-score-with-update-game-score (file score) 478(defun gamegrid-add-score-with-update-game-score (file score)
454 (let* ((result nil) ;; What is this good for? -- os 479 (let* ((result nil) ;; What is this good for? -- os
455 (have-shared-game-dir 480 (have-shared-game-dir
@@ -457,28 +482,34 @@ FILE is created there."
457 (expand-file-name "update-game-score" 482 (expand-file-name "update-game-score"
458 exec-directory)) 483 exec-directory))
459 #o4000))))) 484 #o4000)))))
460 (if (and have-shared-game-dir 485 (cond ((file-name-absolute-p file)
461 (file-exists-p (expand-file-name file shared-game-score-directory))) 486 (gamegrid-add-score-insecure file score))
462 ;; Use the setuid update-gamescore program to update a 487 ((and have-shared-game-dir
463 ;; system-wide score file. 488 (file-exists-p (expand-file-name file shared-game-score-directory)))
464 (gamegrid-add-score-with-update-game-score-1 489 ;; Use the setuid "update-game-score" program to update a
465 (expand-file-name file shared-game-score-directory) score) 490 ;; system-wide score file.
466 ;; Else: Add the score to a score file in the user's home 491 (gamegrid-add-score-with-update-game-score-1
467 ;; directory. If `have-shared-game-dir' is non-nil, the 492 (expand-file-name file shared-game-score-directory) score))
468 ;; "update-gamescore" program is setuid, so don't use it. 493 ;; Else: Add the score to a score file in the user's home
469 (if have-shared-game-dir 494 ;; directory.
470 (gamegrid-add-score-insecure file score 495 (have-shared-game-dir
471 gamegrid-user-score-file-directory) 496 ;; If `have-shared-game-dir' is non-nil, then
472 (let ((f (expand-file-name 497 ;; "update-gamescore" program is setuid, so don't use it.
473 gamegrid-user-score-file-directory))) 498 (unless (file-exists-p
474 (when (file-writable-p f) 499 (directory-file-name gamegrid-user-score-file-directory))
475 (unless (eq (car-safe (file-attributes f)) 500 (make-directory gamegrid-user-score-file-directory t))
476 t) 501 (gamegrid-add-score-insecure file score
477 (make-directory f)) 502 gamegrid-user-score-file-directory))
478 (setq f (expand-file-name file f)) 503 (t (let ((f (expand-file-name
479 (unless (file-exists-p f) 504 gamegrid-user-score-file-directory)))
480 (write-region "" nil f nil 'silent nil 'excl))) 505 (when (file-writable-p f)
481 (gamegrid-add-score-with-update-game-score-1 f score)))))) 506 (unless (eq (car-safe (file-attributes f))
507 t)
508 (make-directory f))
509 (setq f (expand-file-name file f))
510 (unless (file-exists-p f)
511 (write-region "" nil f nil 'silent nil 'excl)))
512 (gamegrid-add-score-with-update-game-score-1 f score))))))
482 513
483(defun gamegrid-add-score-with-update-game-score-1 (target score) 514(defun gamegrid-add-score-with-update-game-score-1 (target score)
484 (let ((default-directory "/") 515 (let ((default-directory "/")