Esempio n. 1
0
File: persist.go Progetto: dlmac/Sia
// saveFile saves a file to the renter directory.
func (r *Renter) saveFile(f *file) error {
	handle, err := persist.NewSafeFile(filepath.Join(r.persistDir, f.name+ShareExtension))
	if err != nil {
		return err
	}
	defer handle.Close()

	enc := encoding.NewEncoder(handle)

	// Write header.
	enc.Encode(shareHeader)
	enc.Encode(shareVersion)

	// Write length of 1.
	err = enc.Encode(uint64(1))
	if err != nil {
		return err
	}

	// Write file.
	err = f.save(handle)
	if err != nil {
		return err
	}

	return nil
}
Esempio n. 2
0
// saveFile saves a file to the renter directory.
func (r *Renter) saveFile(f *file) error {
	handle, err := persist.NewSafeFile(filepath.Join(r.persistDir, f.name+ShareExtension))
	if err != nil {
		return err
	}
	defer handle.Close()

	// Write header with length of 1.
	err = encoding.NewEncoder(handle).EncodeAll(
		shareHeader,
		shareVersion,
		uint64(1),
	)
	if err != nil {
		return err
	}

	// Write file.
	err = f.save(handle)
	if err != nil {
		return err
	}

	// Commit the SafeFile.
	return handle.Commit()
}
Esempio n. 3
0
// saveFile saves a file to the renter directory.
func (r *Renter) saveFile(f *file) error {
	// Create directory structure specified in nickname.
	fullPath := filepath.Join(r.persistDir, f.name+ShareExtension)
	err := os.MkdirAll(filepath.Dir(fullPath), 0700)
	if err != nil {
		return err
	}

	handle, err := persist.NewSafeFile(filepath.Join(r.persistDir, f.name+ShareExtension))
	if err != nil {
		return err
	}
	defer handle.Close()

	// Write header with length of 1.
	err = encoding.NewEncoder(handle).EncodeAll(
		shareHeader,
		shareVersion,
		uint64(1),
	)
	if err != nil {
		return err
	}

	// Write file.
	err = f.save(handle)
	if err != nil {
		return err
	}

	// Commit the SafeFile.
	return handle.Commit()
}
Esempio n. 4
0
// saveFile saves a file to the renter directory.
func (r *Renter) saveFile(f *file) error {
	// Create directory structure specified in nickname.
	fullPath := filepath.Join(r.persistDir, f.name+ShareExtension)
	err := os.MkdirAll(filepath.Dir(fullPath), 0700)
	if err != nil {
		return err
	}

	// Open SafeFile handle.
	handle, err := persist.NewSafeFile(filepath.Join(r.persistDir, f.name+ShareExtension))
	if err != nil {
		return err
	}
	defer handle.Close()

	// Write file data.
	err = shareFiles([]*file{f}, handle)
	if err != nil {
		return err
	}

	// Commit the SafeFile.
	return handle.Commit()
}