@@ -41,12 +41,12 @@ type snapshotter struct {
4141
4242// NewSnapshotter returns a new windows snapshotter
4343func NewSnapshotter (root string ) (snapshots.Snapshotter , error ) {
44- fsType , err := getFileSystemType (string ( root [ 0 ]) )
44+ fsType , err := getFileSystemType (root )
4545 if err != nil {
4646 return nil , err
4747 }
48- if strings .ToLower (fsType ) == "refs " {
49- return nil , errors .Wrapf (errdefs .ErrInvalidArgument , "%s is on an ReFS volume - ReFS volumes are not supported" , root )
48+ if strings .ToLower (fsType ) != "ntfs " {
49+ return nil , errors .Wrapf (errdefs .ErrInvalidArgument , "%s is not on an NTFS volume - only NTFS volumes are supported" , root )
5050 }
5151
5252 if err := os .MkdirAll (root , 0700 ); err != nil {
@@ -83,25 +83,15 @@ func (s *snapshotter) Stat(ctx context.Context, key string) (snapshots.Info, err
8383 defer t .Rollback ()
8484
8585 _ , info , _ , err := storage .GetInfo (ctx , key )
86- if err != nil {
87- return snapshots.Info {}, err
88- }
89-
90- return info , nil
86+ return info , err
9187}
9288
9389func (s * snapshotter ) Update (ctx context.Context , info snapshots.Info , fieldpaths ... string ) (snapshots.Info , error ) {
9490 ctx , t , err := s .ms .TransactionContext (ctx , true )
9591 if err != nil {
9692 return snapshots.Info {}, err
9793 }
98-
99- var committed bool
100- defer func () {
101- if committed == false {
102- rollbackWithLogging (ctx , t )
103- }
104- }()
94+ defer t .Rollback ()
10595
10696 info , err = storage .UpdateInfo (ctx , info , fieldpaths ... )
10797 if err != nil {
@@ -111,7 +101,6 @@ func (s *snapshotter) Update(ctx context.Context, info snapshots.Info, fieldpath
111101 if err := t .Commit (); err != nil {
112102 return snapshots.Info {}, err
113103 }
114- committed = true
115104
116105 return info , nil
117106}
@@ -156,6 +145,7 @@ func (s *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, er
156145 return nil , err
157146 }
158147 defer t .Rollback ()
148+
159149 snapshot , err := storage .GetSnapshot (ctx , key )
160150 if err != nil {
161151 return nil , errors .Wrap (err , "failed to get snapshot mount" )
@@ -168,13 +158,8 @@ func (s *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
168158 if err != nil {
169159 return err
170160 }
161+ defer t .Rollback ()
171162
172- var committed bool
173- defer func () {
174- if committed == false {
175- rollbackWithLogging (ctx , t )
176- }
177- }()
178163 usage := fs.Usage {
179164 Size : 0 ,
180165 }
@@ -186,7 +171,6 @@ func (s *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
186171 if err := t .Commit (); err != nil {
187172 return err
188173 }
189- committed = true
190174 return nil
191175}
192176
@@ -197,13 +181,7 @@ func (s *snapshotter) Remove(ctx context.Context, key string) error {
197181 if err != nil {
198182 return err
199183 }
200-
201- var committed bool
202- defer func () {
203- if committed == false {
204- rollbackWithLogging (ctx , t )
205- }
206- }()
184+ defer t .Rollback ()
207185
208186 id , _ , err := storage .Remove (ctx , key )
209187 if err != nil {
@@ -217,15 +195,13 @@ func (s *snapshotter) Remove(ctx context.Context, key string) error {
217195 return err
218196 }
219197
220- err = t .Commit ()
221- if err != nil {
198+ if err := t .Commit (); err != nil {
222199 if err1 := os .Rename (renamed , path ); err1 != nil {
223200 // May cause inconsistent data on disk
224201 log .G (ctx ).WithError (err1 ).WithField ("path" , renamed ).Errorf ("Failed to rename after failed commit" )
225202 }
226203 return errors .Wrap (err , "failed to commit" )
227204 }
228- committed = true
229205
230206 if err := hcsshim .DestroyLayer (s .info , renamedID ); err != nil {
231207 // Must be cleaned up, any "rm-*" could be removed if no active transactions
@@ -242,6 +218,7 @@ func (s *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapsho
242218 return err
243219 }
244220 defer t .Rollback ()
221+
245222 return storage .WalkInfo (ctx , fn )
246223}
247224
@@ -251,9 +228,7 @@ func (s *snapshotter) Close() error {
251228}
252229
253230func (s * snapshotter ) mounts (sn storage.Snapshot ) []mount.Mount {
254- var (
255- roFlag string
256- )
231+ var roFlag string
257232
258233 if sn .Kind == snapshots .KindView {
259234 roFlag = "ro"
@@ -288,13 +263,7 @@ func (s *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
288263 if err != nil {
289264 return nil , err
290265 }
291-
292- var committed bool
293- defer func () {
294- if committed == false {
295- rollbackWithLogging (ctx , t )
296- }
297- }()
266+ defer t .Rollback ()
298267
299268 newSnapshot , err := storage .CreateSnapshot (ctx , kind , key , parent , opts ... )
300269 if err != nil {
@@ -328,7 +297,6 @@ func (s *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
328297 if err := t .Commit (); err != nil {
329298 return nil , errors .Wrap (err , "commit failed" )
330299 }
331- committed = true
332300
333301 return s .mounts (newSnapshot ), nil
334302}
@@ -343,17 +311,19 @@ func (s *snapshotter) parentIDsToParentPaths(parentIDs []string) []string {
343311
344312// getFileSystemType obtains the type of a file system through GetVolumeInformation
345313// https://msdn.microsoft.com/en-us/library/windows/desktop/aa364993(v=vs.85).aspx
346- func getFileSystemType (drive string ) (fsType string , hr error ) {
314+ func getFileSystemType (path string ) (fsType string , hr error ) {
315+ drive := filepath .VolumeName (path )
316+ if len (drive ) != 2 {
317+ return "" , errors .New ("getFileSystemType path must start with a drive letter" )
318+ }
319+
347320 var (
348321 modkernel32 = windows .NewLazySystemDLL ("kernel32.dll" )
349322 procGetVolumeInformation = modkernel32 .NewProc ("GetVolumeInformationW" )
350323 buf = make ([]uint16 , 255 )
351324 size = windows .MAX_PATH + 1
352325 )
353- if len (drive ) != 1 {
354- return "" , errors .New ("getFileSystemType must be called with a drive letter" )
355- }
356- drive += `:\`
326+ drive += `\`
357327 n := uintptr (unsafe .Pointer (nil ))
358328 r0 , _ , _ := syscall .Syscall9 (procGetVolumeInformation .Addr (), 8 , uintptr (unsafe .Pointer (windows .StringToUTF16Ptr (drive ))), n , n , n , n , n , uintptr (unsafe .Pointer (& buf [0 ])), uintptr (size ), 0 )
359329 if int32 (r0 ) < 0 {
0 commit comments