mirror of
https://codeberg.org/cage/tinmop/
synced 2025-02-17 08:10:36 +01:00
- added 'temporary-directory'.
This commit is contained in:
parent
1e37af8772
commit
50cc7727e6
@ -307,6 +307,34 @@
|
||||
`(delete-file-if-exists temp-file)
|
||||
nil))))
|
||||
|
||||
(defparameter *temporary-directories-created* ())
|
||||
|
||||
(defun temporary-directory (&optional (temp-parent-directory nil))
|
||||
(let ((tmpdir (or temp-parent-directory
|
||||
(os-utils:default-temp-dir))))
|
||||
(let ((directory-path (if tmpdir
|
||||
(nix:mkdtemp (format nil "~a~a"
|
||||
tmpdir
|
||||
config:+program-name+))
|
||||
(nix:mkdtemp (format nil "~atmp~a"
|
||||
*directory-sep*
|
||||
config:+program-name+)))))
|
||||
(push directory-path *temporary-directories-created*)
|
||||
directory-path)))
|
||||
|
||||
(defun clean-temporary-directories ()
|
||||
(dolist (temporary-directory *temporary-directories-created*)
|
||||
(labels ((recursive-delete (dir)
|
||||
(let ((children (collect-children dir)))
|
||||
(dolist (file-or-dir children)
|
||||
(cond
|
||||
((file-exists-p file-or-dir)
|
||||
(delete-file-if-exists file-or-dir))
|
||||
((and (directory-exists-p file-or-dir)
|
||||
(not (cl-ppcre:scan "\\.$" file-or-dir)))
|
||||
(recursive-delete file-or-dir)))))))
|
||||
(recursive-delete temporary-directory))))
|
||||
|
||||
(defun has-file-permission-p (file permission)
|
||||
(find permission (osicat:file-permissions file) :test #'eq))
|
||||
|
||||
|
@ -305,6 +305,9 @@
|
||||
:*temporary-files-created*
|
||||
:temporary-file
|
||||
:clean-temporary-files
|
||||
:*temporary-directories-created*
|
||||
:temporary-directory
|
||||
:clean-temporary-directories
|
||||
:with-anaphoric-temp-file
|
||||
:temp-file
|
||||
:file-can-write-p
|
||||
|
@ -31,6 +31,7 @@
|
||||
"Use this to close the program"
|
||||
(flet ((on-input-complete (maybe-accepted)
|
||||
(when (boolean-input-accepted-p maybe-accepted)
|
||||
(fs:clean-temporary-directories)
|
||||
(fs:clean-temporary-files))
|
||||
(push-event (make-instance 'quit-program-event))))
|
||||
(let ((temporary-text (strcat (format nil
|
||||
@ -38,7 +39,10 @@
|
||||
(swconf:gemini-h1-prefix))
|
||||
(format nil
|
||||
"~{- ~a~%~}"
|
||||
fs:*temporary-files-created*)))
|
||||
fs:*temporary-files-created*)
|
||||
(format nil
|
||||
"~{- ~a~%~}"
|
||||
fs:*temporary-directories-created*)))
|
||||
(temporary-files-count (length fs:*temporary-files-created*)))
|
||||
(if (> temporary-files-count 0)
|
||||
(progn
|
||||
|
Loading…
x
Reference in New Issue
Block a user