Beispiel #1
0
func main() {
	if len(os.Args) == 1 {
		fmt.Fprintf(os.Stderr, `%s: missing operand\n
Usage: %s [-rf] FILE...
		`, os.Args[0], os.Args[0])
		os.Exit(1)
	}
	exitCode := 0
	if os.Args[1] == "-rf" {
		for _, path := range os.Args[2:] {
			if err := shred.RemoveAll(path); err != nil {
				fmt.Fprintf(os.Stderr, "%s: %s\n", path, err)
				exitCode = 1
			}
		}
	} else {
		for i, path := range os.Args[1:] {
			if i == 1 && path == "--" {
				continue
			}
			if err := shred.Remove(path); err != nil {
				fmt.Fprintf(os.Stderr, "%s: %s\n", path, err)
				exitCode = 1
			}
		}
	}
	os.Exit(exitCode)
}
func (p *Paths) AtomicWriteFile(path string, bs []byte, perm os.FileMode) error {
	tempfile, err := p.TempFile()
	defer shred.Remove(tempfile)
	if err != nil {
		return err
	}
	if err = ioutil.WriteFile(tempfile, []byte(bs), perm); err != nil {
		return err
	}
	return os.Rename(filepath.Join(tempfile), path)
}
func (p *Paths) MessageToOutbox(conversationName, message string) error {
	tempfile, err := p.TempFile()
	defer shred.Remove(tempfile)
	if err != nil {
		return err
	}
	if err = ioutil.WriteFile(tempfile, []byte(message), 0600); err != nil {
		return err
	}

	conv_outbox := filepath.Join(p.OutboxDir(), conversationName)

	base := filepath.Base(tempfile)
	return os.Rename(filepath.Join(p.TempDir(), base), filepath.Join(conv_outbox, base))
}