Config, err := os.Open(Home + "/.backup-lightrc", os.O_CREATE, 755)
After running the program I see that it does create the file in
question but running 'ls -l' I this is what it returns:
'--wxr----t 1 vendion users 0 2010-04-09 13:45 /home/vendion/.backup-
lightrc'
It looks like the owner of the file has read and write permissions but
any attempts to access the file, ether by a program written in Go and
vim, gets a permission denied error.
--
To unsubscribe, reply using "remove me" as the subject.
But i'm having similar issues when creating a folder so I make use of
mkdir with Forkexec.
Error: Write has failed: write /home/vendion/.backup-lightrc: bad file
descriptor
The only thing I can think of is in my os.Open line I need to use both
os.O_CREATE and os.O_RDWR but not sure how, to give a better idea of
what I am doing here is a code snipplet:
func CreateConfig() {
var Success int
Home := os.Getenv("HOME")
Config, err := os.Open(Home + "/.backup-lightrc", os.O_CREATE, 0755)
if err != nil {
fmt.Printf("Error: Can't create config file, %s\n", err.String())
os.Exit(1)
}
//Get information for config file and write it
fmt.Println("\nSpecify backup directory [/tmp]: ")
input := bufio.NewReader(os.Stdin)
result, _ := input.ReadString('\n')
backupDir := strings.TrimSpace(result)
if backupDir == "" {
backupDir = "/tmp"
}
Success, err = Config.WriteString(backupDir)
if Success == 0 {
fmt.Printf("Error: Write has failed: %s\n", err.String()) <- Fails
at this point
os.Exit(1)
}
if err != nil { <- For some reason didn't catch the problem with bad
file descriptor, even the the above if proves that err is definitely
not nil
fmt.Printf("Error: Can't write to config file: %s\n", err.String())
os.Exit(1)
}
//Add more config options here
fmt.Println("Configuration file created, please rerun backup-light now
\n")
Config.Close()
os.Exit(0)
}
On Apr 9, 7:02 pm, Daniel Smith <lukenin...@gmail.com> wrote:
It will.
> as for the problem with "err != nil" it is kind of weird as to why that is not
> catching anything, would be nice to know why.
Because there wasn't an error.
The code created a file and opened it for reading
(on Unix, O_RDONLY=0, so O_CREATE == O_CREATE|O_RDONLY).
The only error, from the operating system's vantage point,
is that the program tried to write to a file open only for reading.
Russ
Because there wasn't an error.
The code created a file and opened it for reading
(on Unix, O_RDONLY=0, so O_CREATE == O_CREATE|O_RDONLY).
The only error, from the operating system's vantage point,
is that the program tried to write to a file open only for reading.
The only change I made to my code was the addition of "| os.O_RDWR". I will admit I may have had a typo or something that I fixed without thinking about it, the way I know this because I committed out the line compairing to 0, leaving the err != nil line and it worked.
Sorry for bugging everyone so much, also sorry for any typos I wrote this on my Nexus One.
On Apr 11, 2010 4:55 PM, "Daniel Smith" <luken...@gmail.com> wrote:
On Sun, Apr 11, 2010 at 2:46 PM, Russ Cox <r...@golang.org> wrote:
>
> Because there wasn't an error...