@@ -12,8 +12,8 @@ import (
1212 "io/ioutil"
1313 "os"
1414 "os/exec"
15- "path"
1615 "path/filepath"
16+ "runtime"
1717 "strings"
1818 "syscall"
1919
@@ -291,17 +291,8 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L
291291 file .Close ()
292292
293293 case tar .TypeBlock , tar .TypeChar , tar .TypeFifo :
294- mode := uint32 (hdr .Mode & 07777 )
295- switch hdr .Typeflag {
296- case tar .TypeBlock :
297- mode |= syscall .S_IFBLK
298- case tar .TypeChar :
299- mode |= syscall .S_IFCHR
300- case tar .TypeFifo :
301- mode |= syscall .S_IFIFO
302- }
303-
304- if err := system .Mknod (path , mode , int (system .Mkdev (hdr .Devmajor , hdr .Devminor ))); err != nil {
294+ // Handle this is an OS-specific way
295+ if err := handleTarTypeBlockCharFifo (hdr , path ); err != nil {
305296 return err
306297 }
307298
@@ -337,8 +328,11 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L
337328 return fmt .Errorf ("Unhandled tar header type %d\n " , hdr .Typeflag )
338329 }
339330
340- if err := os .Lchown (path , hdr .Uid , hdr .Gid ); err != nil && Lchown {
341- return err
331+ // Lchown is not supported on Windows
332+ if runtime .GOOS != "windows" {
333+ if err := os .Lchown (path , hdr .Uid , hdr .Gid ); err != nil && Lchown {
334+ return err
335+ }
342336 }
343337
344338 for key , value := range hdr .Xattrs {
@@ -349,20 +343,12 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L
349343
350344 // There is no LChmod, so ignore mode for symlink. Also, this
351345 // must happen after chown, as that can modify the file mode
352- if hdr .Typeflag == tar .TypeLink {
353- if fi , err := os .Lstat (hdr .Linkname ); err == nil && (fi .Mode ()& os .ModeSymlink == 0 ) {
354- if err := os .Chmod (path , hdrInfo .Mode ()); err != nil {
355- return err
356- }
357- }
358- } else if hdr .Typeflag != tar .TypeSymlink {
359- if err := os .Chmod (path , hdrInfo .Mode ()); err != nil {
360- return err
361- }
346+ if err := handleLChmod (hdr , path , hdrInfo ); err != nil {
347+ return err
362348 }
363349
364350 ts := []syscall.Timespec {timeToTimespec (hdr .AccessTime ), timeToTimespec (hdr .ModTime )}
365- // syscall.UtimesNano doesn't support a NOFOLLOW flag atm, and
351+ // syscall.UtimesNano doesn't support a NOFOLLOW flag atm
366352 if hdr .Typeflag == tar .TypeLink {
367353 if fi , err := os .Lstat (hdr .Linkname ); err == nil && (fi .Mode ()& os .ModeSymlink == 0 ) {
368354 if err := system .UtimesNano (path , ts ); err != nil && err != system .ErrNotSupportedPlatform {
@@ -531,7 +517,7 @@ loop:
531517 parent := filepath .Dir (hdr .Name )
532518 parentPath := filepath .Join (dest , parent )
533519 if _ , err := os .Lstat (parentPath ); err != nil && os .IsNotExist (err ) {
534- err = os .MkdirAll (parentPath , 0777 )
520+ err = system .MkdirAll (parentPath , 0777 )
535521 if err != nil {
536522 return err
537523 }
@@ -651,7 +637,7 @@ func (archiver *Archiver) CopyWithTar(src, dst string) error {
651637 }
652638 // Create dst, copy src's content into it
653639 logrus .Debugf ("Creating dest directory: %s" , dst )
654- if err := os .MkdirAll (dst , 0755 ); err != nil && ! os .IsExist (err ) {
640+ if err := system .MkdirAll (dst , 0755 ); err != nil && ! os .IsExist (err ) {
655641 return err
656642 }
657643 logrus .Debugf ("Calling TarUntar(%s, %s)" , src , dst )
@@ -675,12 +661,12 @@ func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) {
675661 if srcSt .IsDir () {
676662 return fmt .Errorf ("Can't copy a directory" )
677663 }
678- // Clean up the trailing /
679- if dst [len (dst )- 1 ] == '/' {
680- dst = path .Join (dst , filepath .Base (src ))
664+ // Clean up the trailing slash
665+ if dst [len (dst )- 1 ] == os . PathSeparator {
666+ dst = filepath .Join (dst , filepath .Base (src ))
681667 }
682668 // Create the holding directory if necessary
683- if err := os .MkdirAll (filepath .Dir (dst ), 0700 ); err != nil && ! os .IsExist (err ) {
669+ if err := system .MkdirAll (filepath .Dir (dst ), 0700 ); err != nil && ! os .IsExist (err ) {
684670 return err
685671 }
686672
0 commit comments