github.com/hugh712/snapd@v0.0.0-20200910133618-1a99902bd583/overlord/snapstate/readme.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2017 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package snapstate 21 22 import ( 23 "os" 24 "strings" 25 26 "github.com/snapcore/snapd/dirs" 27 "github.com/snapcore/snapd/osutil" 28 ) 29 30 const snapREADME = ` 31 This directory presents installed snap packages. 32 33 It has the following structure: 34 35 @SNAP_MOUNT_DIR@/bin - Symlinks to snap applications. 36 @SNAP_MOUNT_DIR@/<snapname>/<revision> - Mountpoint for snap content. 37 @SNAP_MOUNT_DIR@/<snapname>/current - Symlink to current revision, if enabled. 38 39 DISK SPACE USAGE 40 41 The disk space consumed by the content under this directory is 42 minimal as the real snap content never leaves the .snap file. 43 Snaps are *mounted* rather than unpacked. 44 45 For further details please visit 46 https://forum.snapcraft.io/t/the-snap-directory/2817 47 ` 48 49 func snapReadme() string { 50 return strings.Replace(snapREADME, "@SNAP_MOUNT_DIR@", dirs.SnapMountDir, -1) 51 } 52 53 func writeSnapReadme() error { 54 const fname = "README" 55 content := map[string]osutil.FileState{ 56 fname: &osutil.MemoryFileState{Content: []byte(snapReadme()), Mode: 0444}, 57 } 58 if err := os.MkdirAll(dirs.SnapMountDir, 0755); err != nil { 59 return err 60 } 61 // NOTE: We are using EnsureDirState to not unconditionally write to flash 62 // and thus prolong life of the device. 63 _, _, err := osutil.EnsureDirState(dirs.SnapMountDir, fname, content) 64 return err 65 }