Skip to content

Commit c3071ab

Browse files
committed
Move changes.go and changes_unix.go to utils
Signed-off-by: Lei Jitang <[email protected]>
1 parent 66e6cc3 commit c3071ab

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

image/layer.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"io"
2020
"os"
2121
"path/filepath"
22+
23+
"github.com/opencontainers/image-tools/utils"
2224
)
2325

2426
// CreateLayer cretes filesystem changset from child and parent
@@ -43,12 +45,12 @@ func CreateLayer(child, parent, dest string) error {
4345

4446
// Diff produces an archive of the changes between the specified
4547
// layer and its parent layer which may be "".
46-
func Diff(child, parent string) (arch io.ReadCloser, err error) {
47-
changes, err := ChangesDirs(child, parent)
48+
func Diff(child, parent string) (rc io.ReadCloser, err error) {
49+
changes, err := utils.ChangesDirs(child, parent)
4850
if err != nil {
4951
return nil, err
5052
}
51-
archive, err := exportChanges(child, changes)
53+
archive, err := utils.ExportChanges(child, changes)
5254
if err != nil {
5355
return nil, err
5456
}

image/change.go renamed to utils/change.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package image
15+
package utils
1616

1717
import (
1818
"archive/tar"
@@ -27,7 +27,6 @@ import (
2727
"time"
2828

2929
"github.com/Sirupsen/logrus"
30-
"github.com/opencontainers/image-tools/utils"
3130
)
3231

3332
// ChangeType represents the change type.
@@ -67,7 +66,7 @@ func sameFsTimeSpec(a, b syscall.Timespec) bool {
6766
type FileInfo struct {
6867
parent *FileInfo
6968
name string
70-
stat *utils.StatT
69+
stat *StatT
7170
children map[string]*FileInfo
7271
capability []byte
7372
added bool
@@ -225,16 +224,16 @@ func ChangesDirs(newDir, oldDir string) ([]Change, error) {
225224
}
226225

227226
// ExportChanges produces an Archive from the provided changes, relative to dir.
228-
func exportChanges(dir string, changes []Change) (io.ReadCloser, error) {
227+
func ExportChanges(dir string, changes []Change) (io.ReadCloser, error) {
229228
reader, writer := io.Pipe()
230229
go func() {
231-
ta := &utils.TarAppender{
230+
ta := &TarAppender{
232231
TarWriter: tar.NewWriter(writer),
233-
Buffer: utils.BufioWriter32KPool.Get(nil),
232+
Buffer: BufioWriter32KPool.Get(nil),
234233
SeenFiles: make(map[uint64]string),
235234
}
236235
// this buffer is needed for the duration of this piped stream
237-
defer utils.BufioWriter32KPool.Put(ta.Buffer)
236+
defer BufioWriter32KPool.Put(ta.Buffer)
238237

239238
sort.Sort(changesByPath(changes))
240239

image/change_unix.go renamed to utils/change_unix.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package image
15+
package utils
1616

1717
import (
1818
"bytes"
@@ -22,8 +22,6 @@ import (
2222
"sort"
2323
"syscall"
2424
"unsafe"
25-
26-
"github.com/opencontainers/image-tools/utils"
2725
)
2826

2927
// walker is used to implement collectFileInfoForChanges on linux. Where this
@@ -87,12 +85,12 @@ func walkchunk(path string, fi os.FileInfo, dir string, root *FileInfo) error {
8785
parent: parent,
8886
}
8987
cpath := filepath.Join(dir, path)
90-
stat, err := utils.FromStatT(fi.Sys().(*syscall.Stat_t))
88+
stat, err := FromStatT(fi.Sys().(*syscall.Stat_t))
9189
if err != nil {
9290
return err
9391
}
9492
info.stat = stat
95-
info.capability, _ = utils.Lgetxattr(cpath, "security.capability") // lgetxattr(2): fs access
93+
info.capability, _ = Lgetxattr(cpath, "security.capability") // lgetxattr(2): fs access
9694
parent.children[info.name] = info
9795
return nil
9896
}
@@ -298,7 +296,7 @@ func clen(n []byte) int {
298296
return len(n)
299297
}
300298

301-
func statDifferent(oldStat *utils.StatT, newStat *utils.StatT) bool {
299+
func statDifferent(oldStat *StatT, newStat *StatT) bool {
302300
// Don't look at size for dirs, its not a good measure of change
303301
if oldStat.Mode() != newStat.Mode() ||
304302
oldStat.UID() != newStat.UID() ||

0 commit comments

Comments
 (0)