Closed feep closed 4 years ago
Looks like this is caused by the os.ModePerm
constant being used when the files are created. I'm not really sure why this is, as I think this constant is supposed to be a bit-mask used to separate the permission bits from other parts of a file mode. The line that causes this specific issue seems to be https://github.com/qri-io/qri/blob/924157c253bf571ec9df92b0fd63e316e67bc6ad/base/component/kinds.go#L502
@Hackerpilot your diagnosis sounds correct, that should be a relatively easy fix. I think it should be 0644 instead of the current value. It would be great to have a test updated to check for this behavior, for example TestInitStatusSave
in the file cmd/fsi_integration_test.go
is listing the directory and checking the filenames; it could also check the permissions on those files.
This verification was added into TestInitStatusSave
to validate the permission of each file,
// Verify the permissions for each generated file.
files := filesDirectory(workDir)
mode := int(0644)
expectPermission := os.FileMode(mode)
for _, file := range files {
if file.Mode() != expectPermission {
t.Errorf("%s does not have the correct permission", file.Name())
}
}
...
func filesDirectory(path string) []os.FileInfo {
finfos, err := ioutil.ReadDir(path)
if err != nil {
return nil
}
return finfos
}
Moreover, the following modifications can be added to kinds.go
, so the correct permission can be assigned for the file.
const Perm = os.FileMode(int(0644))
...
func (bc *BodyComponent) WriteTo(dirPath string) (targetFile string, err error) {
if bc.Value == nil {
err = bc.LoadAndFill(nil)
if err != nil {
return
}
}
body := bc.Value
if bc.Structure == nil {
return "", fmt.Errorf("cannot write body without a structure")
}
data, err := SerializeBody(body, bc.Structure)
if err != nil {
return "", err
}
bodyFilename := fmt.Sprintf("body.%s", bc.Format)
targetFile = filepath.Join(dirPath, bodyFilename)
return targetFile, ioutil.WriteFile(targetFile, data, Perm)
}
...
func writeComponentFile(value interface{}, dirPath string, basefile string) (string, error) {
data, err := json.MarshalIndent(value, "", " ")
if err != nil {
return "", err
}
// TODO(dlong): How does this relate to Base.SourceFile? Should respect that.
targetFile := filepath.Join(dirPath, basefile)
err = ioutil.WriteFile(targetFile, data, Perm)
if err != nil {
return "", err
}
return targetFile, nil
}
There are two other files readme
and transform
which are probably being generated with the wrong permissions due to the os.ModePerm
.
If the above points are good, I can open a PR with the changes.
This has been fixed, thanks to @mecm1993
Wrong permissions?