Skip to content

Commit

Permalink
Merge pull request #237 from simondeziel/minimize-snap-stage
Browse files Browse the repository at this point in the history
Minimize snap staging and restricted fallback editors
  • Loading branch information
tomponline authored Dec 8, 2023
2 parents cbb3987 + e1ef806 commit 77092b0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
14 changes: 0 additions & 14 deletions snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1024,18 +1024,6 @@ parts:
- bin/tar2sqfs
- lib/libsquashfs.so*

vim:
plugin: nil
stage-packages:
- vim-common
- vim-tiny
organize:
usr/bin/: bin/
usr/share/vim/vim*/debian.vim: etc/vimrc
prime:
- bin/vim.tiny
- etc/vimrc

virtiofsd:
source: https://gitlab.com/virtio-fs/virtiofsd
source-type: git
Expand Down Expand Up @@ -1477,7 +1465,6 @@ parts:
- bin/rsync
- bin/setfacl
- bin/sgdisk
- bin/unsquashfs
- bin/xdelta3

- lib/*/libidn.so.*
Expand Down Expand Up @@ -1586,7 +1573,6 @@ parts:
- sqlite
- squashfs-tools-ng
- swtpm
- vim
- virtiofsd
- xfs
- xz
Expand Down
24 changes: 18 additions & 6 deletions snapcraft/wrappers/editor
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,37 @@ fi
# Try running the editor through the host.
if [ -n "${EDIT_CMD}" ] && [ "${USERNS}" = 1 ]; then
exec 9< /tmp/
EDIT_PATH_HOST="$(echo "${EDIT_PATH}" | sed "s#/tmp/#/proc/self/fd/9/#g")"
# Replace "/tmp/" prefix by exec'ed FD 9.
EDIT_PATH_HOST="/proc/self/fd/9/$(echo "${EDIT_PATH}" | cut -d/ -f2)"
find_and_spawn "${EDIT_CMD}" "${EDIT_PATH_HOST}"
fi

# If the editor's rcfile is not readable, ignore it.
EDIT_IGNORE_RC=""
EDIT_RESTRICT=""
# Default to built-in nano.
if [ -z "${EDIT_CMD}" ]; then
EDIT_CMD="nano"
EDIT_RESTRICT="--restricted"
[ -r "${SNAP}/etc/nanorc" ] || EDIT_IGNORE_RC="--ignorercfiles"
fi

# Setup for VIM.
if [ "$EDIT_CMD" != "nano" ]; then
if [ -e "${SNAP_USER_COMMON}/.vimrc" ]; then
export VIMINIT="source ${SNAP_USER_COMMON}/.vimrc"
else
export VIMINIT="source ${SNAP}/etc/vimrc"
# Find the base use by the LXD snap.
for vimrc in "${SNAP_USER_COMMON}/.vimrc" "/snap/core22/current/etc/vim/vimrc"; do
[ -r "${vimrc}" ] || continue
export VIMINIT="source ${vimrc}"
done

# Ignore vimrc if none was found to be readable.
if [ -z "${VIMINIT:-""}" ]; then
EDIT_IGNORE_RC="--clean"
fi

EDIT_CMD="vim.tiny"
EDIT_RESTRICT="-Z"
fi

# Run the editor.
exec "${EDIT_CMD}" "${EDIT_PATH}"
exec "${EDIT_CMD}" ${EDIT_RESTRICT} ${EDIT_IGNORE_RC} "${EDIT_PATH}"

0 comments on commit 77092b0

Please sign in to comment.