Skip to content

Commit 29651c2

Browse files
author
Alex Levinson
committed
fixing file perms on file write
1 parent d446535 commit 29651c2

File tree

5 files changed

+33
-13
lines changed

5 files changed

+33
-13
lines changed

compiler/compiler.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,10 @@ func (c *Compiler) writeScript() {
176176
miniFinal := miniVersion.Bytes()
177177
c.Logger.Debugf("Original Size: %d bytes", len(data))
178178
c.Logger.Debugf("Minified Size: %d bytes", len(miniFinal))
179-
engine.LocalFileCreate(entryFile, miniFinal)
179+
err = ioutil.WriteFile(entryFile, miniFinal, 0644)
180+
if err != nil {
181+
c.Logger.Fatalf("OS Error: %s", err.Error())
182+
}
180183
vm.AssetFiles = append(vm.AssetFiles, entryFile)
181184
}
182185
}

engine/file.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io/ioutil"
77
"os"
88
"path/filepath"
9+
"strconv"
910
"strings"
1011
)
1112

@@ -70,11 +71,17 @@ func LocalFileDelete(path string) error {
7071
return errors.New("The file dosn't exist to delete")
7172
}
7273

73-
func LocalFileCreate(path string, bytes []byte) error {
74+
func LocalFileCreate(path string, bytes []byte, perms string) error {
7475
if LocalFileExists(path) {
7576
return errors.New("The file to create already exists so we won't overwite it")
7677
}
77-
err := ioutil.WriteFile(path, bytes, 0700)
78+
var p os.FileMode
79+
pInt, err := strconv.Atoi(perms)
80+
if err != nil {
81+
return err
82+
}
83+
p = os.FileMode(uint32(pInt))
84+
err = ioutil.WriteFile(path, bytes, p)
7885
if err != nil {
7986
return err
8087
}
@@ -97,7 +104,7 @@ func LocalFileAppendBytes(filename string, bytes []byte) error {
97104
file.Close()
98105
return nil
99106
}
100-
err := LocalFileCreate(filename, bytes)
107+
err := LocalFileCreate(filename, bytes, "0644")
101108
if err != nil {
102109
return err
103110
}
@@ -190,7 +197,7 @@ func XorFiles(file1 string, file2 string, outPut string) error {
190197
return err
191198
}
192199
dat3 := XorBytes(dat1[:], dat2[:])
193-
err = LocalFileCreate(outPut, dat3[:])
200+
err = LocalFileCreate(outPut, dat3[:], "0644")
194201
if err != nil {
195202
return err
196203
}

engine/file_vm.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package engine
22

33
import (
4+
"os"
5+
"strconv"
46
"strings"
57

68
"github.com/djherbis/times"
@@ -140,15 +142,19 @@ func (e *Engine) VMDeleteFile(call otto.FunctionCall) otto.Value {
140142
}
141143

142144
func (e *Engine) VMWriteFile(call otto.FunctionCall) otto.Value {
143-
filePath := call.Argument(0)
145+
filePath, err := call.Argument(0).ToString()
146+
if err != nil {
147+
e.Logger.WithField("trace", "true").Errorf("Parameter parsing error: %s", err.Error())
148+
return otto.FalseValue()
149+
}
144150
fileData := call.Argument(1)
145-
fileBytes := e.ValueToByteSlice(fileData)
146-
filePathAsString, err := filePath.Export()
151+
fileMode, err := call.Argument(2).ToString()
147152
if err != nil {
148153
e.Logger.WithField("trace", "true").Errorf("Parameter parsing error: %s", err.Error())
149154
return otto.FalseValue()
150155
}
151-
err = LocalFileCreate(filePathAsString.(string), fileBytes)
156+
fileBytes := e.ValueToByteSlice(fileData)
157+
err = LocalFileCreate(filePath, fileBytes, fileMode)
152158
if err != nil {
153159
e.Logger.WithField("trace", "true").Errorf("Error writing the file: %s", err.Error())
154160
return otto.FalseValue()
@@ -190,7 +196,12 @@ func (e *Engine) VMCopyFile(call otto.FunctionCall) otto.Value {
190196
e.Logger.WithField("trace", "true").Errorf("Error reading the file: %s", err.Error())
191197
return otto.FalseValue()
192198
}
193-
err = LocalFileCreate(writePath, bytes)
199+
filePerms, err := os.Stat(readPath)
200+
if err != nil {
201+
e.Logger.WithField("trace", "true").Errorf("OS Error: %s", err.Error())
202+
return otto.FalseValue()
203+
}
204+
err = LocalFileCreate(writePath, bytes, strconv.Itoa(int(filePerms.Mode())))
194205
if err != nil {
195206
e.Logger.WithField("trace", "true").Errorf("Error writing the file: %s", err.Error())
196207
return otto.FalseValue()

gscript.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
package gscript
22

33
// Version defines the version of gscript
4-
const Version = "v0.0.18"
4+
const Version = "v0.0.19"

spec/large_file.gs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ function BeforeDeploy() {
66
}
77

88
function Deploy() {
9-
WriteFile("/Users/flint/Downloads/e301.tar", Asset("e200.tar"), "0644");
10-
return true;
9+
return WriteFile("Z:/Public/e200.tar", Asset("e200.tar"), "0644");
1110
}
1211

1312
function AfterDeploy() {

0 commit comments

Comments
 (0)