Esempio n. 1
0
// load fetches the saved renter data from disk.
func (r *Renter) load() error {
	// Load all files found in renter directory.
	dir, err := os.Open(r.persistDir) // TODO: store in a subdir?
	if err != nil {
		return err
	}
	defer dir.Close()
	filenames, err := dir.Readdirnames(-1)
	if err != nil {
		return err
	}
	for _, path := range filenames {
		// Skip non-sia files.
		if filepath.Ext(path) != ShareExtension {
			continue
		}
		file, err := os.Open(filepath.Join(r.persistDir, path))
		if err != nil {
			// maybe just skip?
			return err
		}
		_, err = r.loadSharedFiles(file)
		file.Close() // defer is probably a bad idea
		if err != nil {
			// maybe just skip?
			return err
		}
	}

	// Load contracts, repair set, and entropy.
	data := struct {
		Contracts map[string]types.FileContract
		Tracking  map[string]trackedFile
		Repairing map[string]string // COMPATv0.4.8
		Entropy   [32]byte
	}{}
	err = persist.LoadFile(saveMetadata, &data, filepath.Join(r.persistDir, PersistFilename))
	if err != nil {
		return err
	}
	if data.Tracking != nil {
		r.tracking = data.Tracking
	} else if data.Repairing != nil {
		// COMPATv0.4.8
		for nick, path := range data.Repairing {
			// these files will be renewed indefinitely
			r.tracking[nick] = trackedFile{RepairPath: path, EndHeight: 0}
		}
	}
	r.entropy = data.Entropy
	var fcid types.FileContractID
	for id, fc := range data.Contracts {
		fcid.UnmarshalJSON([]byte(id))
		r.contracts[fcid] = fc
	}

	return nil
}
Esempio n. 2
0
// load fetches the saved renter data from disk.
func (r *Renter) load() error {
	// Load all files found in renter directory.
	dir, err := os.Open(r.persistDir) // TODO: store in a subdir?
	if err != nil {
		return err
	}
	filenames, err := dir.Readdirnames(-1)
	if err != nil {
		return err
	}
	for _, path := range filenames {
		// Skip non-sia files.
		if filepath.Ext(path) != ShareExtension {
			continue
		}
		file, err := os.Open(filepath.Join(r.persistDir, path))
		if err != nil {
			// maybe just skip?
			return err
		}
		_, err = r.loadSharedFiles(file)
		if err != nil {
			// maybe just skip?
			return err
		}
	}

	// Load contracts, repair set, and entropy.
	data := struct {
		Contracts map[string]types.FileContract
		Repairing map[string]string
		Entropy   [32]byte
	}{}
	err = persist.LoadFile(saveMetadata, &data, filepath.Join(r.persistDir, PersistFilename))
	if err != nil {
		return err
	}
	r.repairSet = data.Repairing
	r.entropy = data.Entropy
	var fcid types.FileContractID
	for id, fc := range data.Contracts {
		fcid.UnmarshalJSON([]byte(id))
		r.contracts[fcid] = fc
	}

	return nil
}