Mercurial > emacs
comparison lisp/play/gamegrid.el @ 50734:17be3e4887ea
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.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Tue, 29 Apr 2003 23:02:27 +0000 |
parents | 755c2ca7f6cf |
children | 695cf19ef79e |
comparison
equal
deleted
inserted
replaced
50733:f038a895a805 | 50734:17be3e4887ea |
---|---|
448 ((ms-dos windows-nt) | 448 ((ms-dos windows-nt) |
449 (gamegrid-add-score-insecure file score)) | 449 (gamegrid-add-score-insecure file score)) |
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 |
456 (not (zerop (logand (file-modes | 481 (not (zerop (logand (file-modes |
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 "/") |
485 (errbuf (generate-new-buffer " *update-game-score loss*"))) | 516 (errbuf (generate-new-buffer " *update-game-score loss*"))) |
486 (apply | 517 (apply |