@@ -1476,17 +1476,17 @@ func (b *builder) build(a *action) (err error) {
1476
1476
switch {
1477
1477
case strings .HasSuffix (name , _goos_goarch ):
1478
1478
targ := file [:len (name )- len (_goos_goarch )] + "_GOOS_GOARCH." + ext
1479
- if err := b .copyFile (a , obj + targ , filepath .Join (a .p .Dir , file ), 0644 , true ); err != nil {
1479
+ if err := b .copyFile (a , obj + targ , filepath .Join (a .p .Dir , file ), 0666 , true ); err != nil {
1480
1480
return err
1481
1481
}
1482
1482
case strings .HasSuffix (name , _goarch ):
1483
1483
targ := file [:len (name )- len (_goarch )] + "_GOARCH." + ext
1484
- if err := b .copyFile (a , obj + targ , filepath .Join (a .p .Dir , file ), 0644 , true ); err != nil {
1484
+ if err := b .copyFile (a , obj + targ , filepath .Join (a .p .Dir , file ), 0666 , true ); err != nil {
1485
1485
return err
1486
1486
}
1487
1487
case strings .HasSuffix (name , _goos ):
1488
1488
targ := file [:len (name )- len (_goos )] + "_GOOS." + ext
1489
- if err := b .copyFile (a , obj + targ , filepath .Join (a .p .Dir , file ), 0644 , true ); err != nil {
1489
+ if err := b .copyFile (a , obj + targ , filepath .Join (a .p .Dir , file ), 0666 , true ); err != nil {
1490
1490
return err
1491
1491
}
1492
1492
}
@@ -1575,7 +1575,7 @@ func (b *builder) getPkgConfigFlags(p *Package) (cflags, ldflags []string, err e
1575
1575
1576
1576
func (b * builder ) installShlibname (a * action ) error {
1577
1577
a1 := a .deps [0 ]
1578
- err := ioutil .WriteFile (a .target , []byte (filepath .Base (a1 .target )+ "\n " ), 0644 )
1578
+ err := ioutil .WriteFile (a .target , []byte (filepath .Base (a1 .target )+ "\n " ), 0666 )
1579
1579
if err != nil {
1580
1580
return err
1581
1581
}
@@ -1599,12 +1599,12 @@ func (b *builder) install(a *action) (err error) {
1599
1599
}
1600
1600
}()
1601
1601
a1 := a .deps [0 ]
1602
- perm := os .FileMode (0644 )
1602
+ perm := os .FileMode (0666 )
1603
1603
if a1 .link {
1604
1604
switch buildBuildmode {
1605
1605
case "c-archive" , "c-shared" :
1606
1606
default :
1607
- perm = 0755
1607
+ perm = 0777
1608
1608
}
1609
1609
}
1610
1610
@@ -1678,7 +1678,25 @@ func (b *builder) moveOrCopyFile(a *action, dst, src string, perm os.FileMode, f
1678
1678
1679
1679
// If we can update the mode and rename to the dst, do it.
1680
1680
// Otherwise fall back to standard copy.
1681
- if err := os .Chmod (src , perm ); err == nil {
1681
+
1682
+ // The perm argument is meant to be adjusted according to umask,
1683
+ // but we don't know what the umask is.
1684
+ // Create a dummy file to find out.
1685
+ // This avoids build tags and works even on systems like Plan 9
1686
+ // where the file mask computation incorporates other information.
1687
+ mode := perm
1688
+ f , err := os .OpenFile (filepath .Clean (dst )+ "-go-tmp-umask" , os .O_WRONLY | os .O_CREATE | os .O_EXCL , perm )
1689
+ if err == nil {
1690
+ fi , err := f .Stat ()
1691
+ if err == nil {
1692
+ mode = fi .Mode () & 0777
1693
+ }
1694
+ name := f .Name ()
1695
+ f .Close ()
1696
+ os .Remove (name )
1697
+ }
1698
+
1699
+ if err := os .Chmod (src , mode ); err == nil {
1682
1700
if err := os .Rename (src , dst ); err == nil {
1683
1701
if buildX {
1684
1702
b .showcmd ("" , "mv %s %s" , src , dst )
@@ -1765,7 +1783,7 @@ func (b *builder) installHeader(a *action) error {
1765
1783
}
1766
1784
}
1767
1785
1768
- return b .moveOrCopyFile (a , a .target , src , 0644 , true )
1786
+ return b .moveOrCopyFile (a , a .target , src , 0666 , true )
1769
1787
}
1770
1788
1771
1789
// cover runs, in effect,
@@ -3258,7 +3276,7 @@ func (b *builder) swigIntSize(obj string) (intsize string, err error) {
3258
3276
return "$INTBITS" , nil
3259
3277
}
3260
3278
src := filepath .Join (b .work , "swig_intsize.go" )
3261
- if err = ioutil .WriteFile (src , []byte (swigIntSizeCode ), 0644 ); err != nil {
3279
+ if err = ioutil .WriteFile (src , []byte (swigIntSizeCode ), 0666 ); err != nil {
3262
3280
return
3263
3281
}
3264
3282
srcs := []string {src }
0 commit comments