mirror of
https://github.com/stumpwm/stumpwm.git
synced 2026-09-10 07:26:20 -04:00
Merge pull request #1209 from zmyrgel/better-default-data-dir
Some checks failed
Build and Test / build_and_test (push) Has been cancelled
Some checks failed
Build and Test / build_and_test (push) Has been cancelled
Better default data dir
This commit is contained in:
commit
019e44a110
20
debug.lisp
20
debug.lisp
|
|
@ -68,23 +68,3 @@ do:
|
|||
*standard-output* *redirect-stream*
|
||||
*trace-output* *redirect-stream*
|
||||
*debug-stream* *redirect-stream*))
|
||||
|
||||
(defun rotate-log ()
|
||||
(let ((log-filename (merge-pathnames "stumpwm.log"
|
||||
(data-dir)))
|
||||
(bkp-log-filename (merge-pathnames "stumpwm.log.1"
|
||||
(data-dir))))
|
||||
(when (probe-file log-filename)
|
||||
(rename-file log-filename bkp-log-filename))))
|
||||
|
||||
(defun open-log ()
|
||||
(rotate-log)
|
||||
(let ((log-filename (merge-pathnames "stumpwm.log"
|
||||
(data-dir))))
|
||||
(setf *debug-stream* (open log-filename :direction :output
|
||||
:if-exists :supersede
|
||||
:if-does-not-exist :create))))
|
||||
(defun close-log ()
|
||||
(when (boundp '*debug-stream*)
|
||||
(close *debug-stream*)
|
||||
(makunbound '*debug-stream*)))
|
||||
|
|
|
|||
|
|
@ -1538,9 +1538,22 @@ sync-all-frame-windows to see the change.")
|
|||
(defvar *data-dir* nil
|
||||
"The directory used by stumpwm to store data between sessions.")
|
||||
|
||||
(defun ensure-data-dir ()
|
||||
(ensure-directories-exist *data-dir* :mode #o700))
|
||||
|
||||
(defun default-data-dir ()
|
||||
"Return the default data dir pathname based on the loaded StumpWM configuration file."
|
||||
(let ((rc-file (or
|
||||
(probe-file (merge-pathnames #p".stumpwmrc" (user-homedir-pathname)))
|
||||
(probe-file (merge-pathnames #p".stumpwm.d/init.lisp" (user-homedir-pathname)))
|
||||
(probe-file (uiop:xdg-config-home #p"stumpwm/config")))))
|
||||
(if rc-file
|
||||
(make-pathname :name nil :type nil :defaults rc-file)
|
||||
(merge-pathnames ".stumpwm.d/" (user-homedir-pathname)))))
|
||||
|
||||
(defun data-dir-file (name &optional type)
|
||||
"Return a pathname inside stumpwm's data dir with the specified name and type"
|
||||
(ensure-directories-exist *data-dir*)
|
||||
(ensure-data-dir)
|
||||
(make-pathname :name name :type type :defaults *data-dir*))
|
||||
|
||||
(defmacro with-data-file ((s file &rest keys &key (if-exists :supersede) &allow-other-keys) &body body)
|
||||
|
|
@ -1549,10 +1562,27 @@ directly to OPEN. Note that IF-EXISTS defaults to :supersede, instead
|
|||
of :error."
|
||||
(declare (ignorable if-exists))
|
||||
`(progn
|
||||
(ensure-directories-exist *data-dir*)
|
||||
(ensure-data-dir)
|
||||
(with-open-file (,s ,(merge-pathnames file *data-dir*)
|
||||
,@keys)
|
||||
,@body)))
|
||||
,@body)))
|
||||
|
||||
(defun rotate-log ()
|
||||
(let ((log-filename (merge-pathnames "stumpwm.log" *data-dir*))
|
||||
(bkp-log-filename (merge-pathnames "stumpwm.log.1" *data-dir*)))
|
||||
(when (probe-file log-filename)
|
||||
(rename-file log-filename bkp-log-filename))))
|
||||
|
||||
(defun open-log ()
|
||||
(rotate-log)
|
||||
(let ((log-filename (merge-pathnames "stumpwm.log" *data-dir*)))
|
||||
(setf *debug-stream* (open log-filename :direction :output
|
||||
:if-exists :supersede
|
||||
:if-does-not-exist :create))))
|
||||
(defun close-log ()
|
||||
(when (boundp '*debug-stream*)
|
||||
(close *debug-stream*)
|
||||
(makunbound '*debug-stream*)))
|
||||
|
||||
(defmacro move-to-head (list elt)
|
||||
"Move the specified element in in LIST to the head of the list."
|
||||
|
|
|
|||
10
stumpwm.lisp
10
stumpwm.lisp
|
|
@ -219,12 +219,6 @@ further up. "
|
|||
:local)
|
||||
(t :internet)))))
|
||||
|
||||
(defun ensure-data-dir ()
|
||||
(ensure-directories-exist (data-dir) :mode #o700))
|
||||
|
||||
(defun data-dir ()
|
||||
(merge-pathnames ".stumpwm.d/" (user-homedir-pathname)))
|
||||
|
||||
(defun close-resources ()
|
||||
(xlib:close-display *display*)
|
||||
(close-log))
|
||||
|
|
@ -318,9 +312,7 @@ further up. "
|
|||
(dformat 0 "SIGHUP received: forcing immediate restart of stumpwm~%") ;; debug level 0 to "force" logging
|
||||
(force-stumpwm-restart))
|
||||
(let ((*in-main-thread* t))
|
||||
(setf *data-dir*
|
||||
(make-pathname :directory (append (pathname-directory (user-homedir-pathname))
|
||||
(list ".stumpwm.d"))))
|
||||
(setf *data-dir* (default-data-dir))
|
||||
(init-load-path *module-dir*)
|
||||
(loop
|
||||
(let ((ret (catch :top-level
|
||||
|
|
|
|||
Loading…
Reference in a new issue