Skip to content

Commit b54058b

Browse files
committed
Windows: revendor Microsoft/hcsshim to v0.1.0
This (the first tagged hcsshim release) fixes long-path bugs on Windows TP5 that affect commit and save. These bugs were blocking commit of Windows containers that had node.js installed. Signed-off-by: John Starks <jostarks@microsoft.com>
1 parent 41c1c65 commit b54058b

File tree

3 files changed

+80
-15
lines changed

3 files changed

+80
-15
lines changed

hack/vendor.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ source 'hack/.vendor-helpers.sh'
77

88
# the following lines are in sorted order, FYI
99
clone git github.com/Azure/go-ansiterm 70b2c90b260171e829f1ebd7c17f600c11858dbe
10-
clone git github.com/Microsoft/hcsshim 116e0e9f5ced0cec94ae46d0aa1b3002a325f532
10+
clone git github.com/Microsoft/hcsshim v0.1.0
1111
clone git github.com/Microsoft/go-winio v0.1.0
1212
clone git github.com/Sirupsen/logrus v0.9.0 # logrus is a common dependency among multiple deps
1313
clone git github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a130610adc62a

vendor/src/github.com/Microsoft/hcsshim/importlayer.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package hcsshim
33
import (
44
"io/ioutil"
55
"os"
6+
"path/filepath"
67
"runtime"
78

89
"github.com/Microsoft/go-winio"
@@ -110,13 +111,22 @@ type legacyLayerWriterWrapper struct {
110111
*LegacyLayerWriter
111112
info DriverInfo
112113
layerId string
114+
path string
113115
parentLayerPaths []string
114116
}
115117

116118
func (r *legacyLayerWriterWrapper) Close() error {
117119
err := r.LegacyLayerWriter.Close()
118120
if err == nil {
119-
err = ImportLayer(r.info, r.layerId, r.root, r.parentLayerPaths)
121+
// Use the original path here because ImportLayer does not support long paths for the source in TP5.
122+
// But do use a long path for the destination to work around another bug with directories
123+
// with MAX_PATH - 12 < length < MAX_PATH.
124+
info := r.info
125+
fullPath, err := makeLongAbsPath(filepath.Join(info.HomeDir, r.layerId))
126+
if err == nil {
127+
info.HomeDir = ""
128+
err = ImportLayer(info, fullPath, r.path, r.parentLayerPaths)
129+
}
120130
}
121131
os.RemoveAll(r.root)
122132
return err
@@ -131,7 +141,13 @@ func NewLayerWriter(info DriverInfo, layerId string, parentLayerPaths []string)
131141
if err != nil {
132142
return nil, err
133143
}
134-
return &legacyLayerWriterWrapper{NewLegacyLayerWriter(path), info, layerId, parentLayerPaths}, nil
144+
return &legacyLayerWriterWrapper{
145+
LegacyLayerWriter: NewLegacyLayerWriter(path),
146+
info: info,
147+
layerId: layerId,
148+
path: path,
149+
parentLayerPaths: parentLayerPaths,
150+
}, nil
135151
}
136152
layers, err := layerPathsToDescriptors(parentLayerPaths)
137153
if err != nil {

vendor/src/github.com/Microsoft/hcsshim/legacy.go

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@ func openFileOrDir(path string, mode uint32, createDisposition uint32) (file *os
2929
return
3030
}
3131

32+
func makeLongAbsPath(path string) (string, error) {
33+
if strings.HasPrefix(path, `\\?\`) || strings.HasPrefix(path, `\\.\`) {
34+
return path, nil
35+
}
36+
if !filepath.IsAbs(path) {
37+
absPath, err := filepath.Abs(path)
38+
if err != nil {
39+
return "", err
40+
}
41+
path = absPath
42+
}
43+
if strings.HasPrefix(path, `\\`) {
44+
return `\\?\UNC\` + path[2:], nil
45+
}
46+
return `\\?\` + path, nil
47+
}
48+
3249
type fileEntry struct {
3350
path string
3451
fi os.FileInfo
@@ -81,15 +98,16 @@ func readTombstones(path string) (map[string]([]string), error) {
8198
return ts, nil
8299
}
83100

84-
func (r *LegacyLayerReader) walk() {
85-
defer close(r.result)
86-
if !<-r.proceed {
87-
return
101+
func (r *LegacyLayerReader) walkUntilCancelled() error {
102+
root, err := makeLongAbsPath(r.root)
103+
if err != nil {
104+
return err
88105
}
89106

107+
r.root = root
90108
ts, err := readTombstones(r.root)
91109
if err != nil {
92-
goto ErrorLoop
110+
return err
93111
}
94112

95113
err = filepath.Walk(r.root, func(path string, info os.FileInfo, err error) error {
@@ -122,17 +140,27 @@ func (r *LegacyLayerReader) walk() {
122140
return nil
123141
})
124142
if err == errorIterationCanceled {
125-
return
143+
return nil
126144
}
127145
if err == nil {
128-
err = io.EOF
146+
return io.EOF
129147
}
148+
return err
149+
}
130150

131-
ErrorLoop:
132-
for {
133-
r.result <- &fileEntry{err: err}
134-
if !<-r.proceed {
135-
break
151+
func (r *LegacyLayerReader) walk() {
152+
defer close(r.result)
153+
if !<-r.proceed {
154+
return
155+
}
156+
157+
err := r.walkUntilCancelled()
158+
if err != nil {
159+
for {
160+
r.result <- &fileEntry{err: err}
161+
if !<-r.proceed {
162+
return
163+
}
136164
}
137165
}
138166
}
@@ -287,6 +315,7 @@ type LegacyLayerWriter struct {
287315
backupWriter *winio.BackupFileWriter
288316
tombstones []string
289317
isTP4Format bool
318+
pathFixed bool
290319
}
291320

292321
// NewLegacyLayerWriter returns a LayerWriter that can write the TP4 transport format
@@ -298,6 +327,18 @@ func NewLegacyLayerWriter(root string) *LegacyLayerWriter {
298327
}
299328
}
300329

330+
func (w *LegacyLayerWriter) init() error {
331+
if !w.pathFixed {
332+
path, err := makeLongAbsPath(w.root)
333+
if err != nil {
334+
return err
335+
}
336+
w.root = path
337+
w.pathFixed = true
338+
}
339+
return nil
340+
}
341+
301342
func (w *LegacyLayerWriter) reset() {
302343
if w.backupWriter != nil {
303344
w.backupWriter.Close()
@@ -311,6 +352,10 @@ func (w *LegacyLayerWriter) reset() {
311352

312353
func (w *LegacyLayerWriter) Add(name string, fileInfo *winio.FileBasicInfo) error {
313354
w.reset()
355+
err := w.init()
356+
if err != nil {
357+
return err
358+
}
314359
path := filepath.Join(w.root, name)
315360

316361
createDisposition := uint32(syscall.CREATE_NEW)
@@ -374,6 +419,10 @@ func (w *LegacyLayerWriter) Write(b []byte) (int, error) {
374419

375420
func (w *LegacyLayerWriter) Close() error {
376421
w.reset()
422+
err := w.init()
423+
if err != nil {
424+
return err
425+
}
377426
tf, err := os.Create(filepath.Join(w.root, "tombstones.txt"))
378427
if err != nil {
379428
return err

0 commit comments

Comments
 (0)