forked from canonical/snapd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
copydata.go
65 lines (54 loc) · 2 KB
/
copydata.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) 2014-2016 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package backend
import (
"os"
"github.com/snapcore/snapd/logger"
"github.com/snapcore/snapd/progress"
"github.com/snapcore/snapd/snap"
)
// CopySnapData makes a copy of oldSnap data for newSnap in its data directories.
func (b Backend) CopySnapData(newSnap, oldSnap *snap.Info, meter progress.Meter) error {
// deal with the old data or
// otherwise just create a empty data dir
// Make sure the common data directory exists, even if this isn't a new
// install.
if err := os.MkdirAll(newSnap.CommonDataDir(), 0755); err != nil {
return err
}
if oldSnap == nil {
return os.MkdirAll(newSnap.DataDir(), 0755)
}
return copySnapData(oldSnap, newSnap)
}
// UndoCopySnapData removes the copy that may have been done for newInfo snap of oldInfo snap data and also the data directories that may have been created for newInfo snap.
func (b Backend) UndoCopySnapData(newInfo *snap.Info, oldInfo *snap.Info, meter progress.Meter) error {
err1 := b.RemoveSnapData(newInfo)
if err1 != nil {
logger.Noticef("Cannot remove data directories for %q: %v", newInfo.Name(), err1)
}
var err2 error
if oldInfo == nil {
// first install, remove created common data dir
err2 = b.RemoveSnapCommonData(newInfo)
if err2 != nil {
logger.Noticef("Cannot remove common data directories for %q: %v", newInfo.Name(), err2)
}
}
return firstErr(err1, err2)
}