Skip to content

Commit

Permalink
Add `straight-prune-build'
Browse files Browse the repository at this point in the history
See #50.
  • Loading branch information
raxod502 committed Aug 16, 2017
1 parent 41de7f4 commit b427709
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,19 @@ Note that this will probably take a while. There are also `M-x
straight-check-package` and `M-x straight-rebuild-package`, which
allow you to select a particular package to check or rebuild.

Finally, you may use `M-x straight-prune-build` in order to tell
`straight.el` to forget about any packages which were not registered
since the last init transaction
(see [the transaction system][transactions]). This may improve
performance, although only slightly, and will clean up stale entries
in the `build` directory. You can call this function in your init-file
if you really wish your filesystem to be as clean as possible,
although it's not particularly recommended as the performance
implications are uninvestigated. If you do call it in your init-file,
be sure to only call it on a fully successful init; otherwise, an
error during init will result in some packages' build information
being discarded, and they will need to be rebuilt next time.

### Version control operations

`straight.el` provides a number of highly interactive workflows for
Expand Down
30 changes: 30 additions & 0 deletions straight.el
Original file line number Diff line number Diff line change
Expand Up @@ -3046,6 +3046,36 @@ See also `straight-check-all' and `straight-rebuild-package'."
(dolist (package (hash-table-keys straight--recipe-cache))
(straight-use-package (intern package))))))

;;;;; Cleanup

;;;###autoload
(defun straight-prune-build ()
"Prune the build cache and build directory.
This means that only packages that were built in the last init
run and subsequent interactive session will remain; other
packages will have their build mtime information discarded and
their build directory deleted."
(interactive)
(straight-transaction
(straight--transaction-exec
'build-cache
#'straight--load-build-cache
#'straight--save-build-cache)
(dolist (package (hash-table-keys straight--build-cache))
(unless (gethash package straight--profile-cache)
(remhash package straight--build-cache)))
(dolist (package (directory-files
(straight--dir "build")
nil nil 'nosort))
;; So, let me tell you a funny story. Once upon a time I didn't
;; have this `string-match-p' condition. But Emacs helpfully
;; returns . and .. from the call to `list-directory', resulting
;; in the entire build directory and its parent directory also
;; being deleted. Fun fun fun.
(unless (or (string-match-p "^\\.\\.?$" package)
(gethash package straight--profile-cache))
(delete-directory (straight--dir "build" package) 'recursive)))))

;;;;; Normalization, pushing, pulling

;;;###autoload
Expand Down

0 comments on commit b427709

Please sign in to comment.