func (d *DistroInfo) Refresh() error {
	// On non-Ubuntu systems this file won't exist but that's expected.
	if !d.fileSystem.Exists(d.path) {
		return nil
	}
	f, err := d.fileSystem.Open(d.path)
	if err != nil {
		return errors.Trace(err)
	}
	defer func() {
		_ = f.Close()
	}()

	csvReader := csv.NewReader(f)
	csvReader.FieldsPerRecord = -1
	records, err := csvReader.ReadAll()
	if err != nil {
		return errors.Annotatef(err, "reading %s", d.path)
	}

	fieldNames := records[0]
	records = records[1:]

	result := make(map[string]DistroInfoSerie)

	// We ignore all series prior to precise.
	var foundPrecise bool
	for _, fields := range records {
		record, ok := consumeRecord(fieldNames, fields)
		if !ok {
			continue
		}

		createdDate, err := time.Parse(dateFormat, record.Created)
		if err != nil {
			continue
		}
		releasedDate, err := time.Parse(dateFormat, record.Released)
		if err != nil {
			continue
		}
		eolDate, err := time.Parse(dateFormat, record.EOL)
		if err != nil {
			continue
		}

		if !foundPrecise {
			if record.Series != "precise" {
				continue
			}
			foundPrecise = true
		}

		result[record.Series] = DistroInfoSerie{
			Version:  record.Version,
			CodeName: record.CodeName,
			Series:   record.Series,
			Created:  createdDate,
			Released: releasedDate,
			EOL:      eolDate,
		}
	}

	// Lock the distro info, as we're going to be updating it.
	d.mutex.Lock()
	d.info = result
	d.mutex.Unlock()

	return nil
}
// Refresh will attempt to update the information it has about each distro and
// if the distro is supported or not.
Refresh will attempt to update the information it has about each distro and
if the distro is supported or not.
// Refresh will attempt to update the information it has about each distro and // if the distro is supported or not .
func (d *DistroInfo) Refresh() error {
	if !d.fileSystem.Exists(d.path) {
		return nil
	}
	f, err := d.fileSystem.Open(d.path)
	if err != nil {
		return errors.Trace(err)
	}
	defer func() {
		_ = f.Close()
	}()
	csvReader := csv.NewReader(f)
	csvReader.FieldsPerRecord = -1
	records, err := csvReader.ReadAll()
	if err != nil {
		return errors.Annotatef(err, "reading %s", d.path)
	}
	fieldNames := records[0]
	records = records[1:]
	result := make(map[string]DistroInfoSerie)
	var foundPrecise bool
	for _, fields := range records {
		record, ok := consumeRecord(fieldNames, fields)
		if !ok {
			continue
		}
		createdDate, err := time.Parse(dateFormat, record.Created)
		if err != nil {
			continue
		}
		releasedDate, err := time.Parse(dateFormat, record.Released)
		if err != nil {
			continue
		}
		eolDate, err := time.Parse(dateFormat, record.EOL)
		if err != nil {
			continue
		}
		if !foundPrecise {
			if record.Series != "precise" {
				continue
			}
			foundPrecise = true
		}
		result[record.Series] = DistroInfoSerie{
			Version:  record.Version,
			CodeName: record.CodeName,
			Series:   record.Series,
			Created:  createdDate,
			Released: releasedDate,
			EOL:      eolDate,
		}
	}
	d.mutex.Lock()
	d.info = result
	d.mutex.Unlock()
	return nil
}
func ( d * DistroInfo ) Refresh ( ) error { if ! d . fileSystem . Exists ( d . path ) { return nil } f , err := d . fileSystem . Open ( d . path ) if err != nil { return errors . Trace ( err ) } defer func ( ) { _ = f . Close ( ) } ( ) csvReader := csv . NewReader ( f ) csvReader . FieldsPerRecord = - 1 records , err := csvReader . ReadAll ( ) if err != nil { return errors . Annotatef ( err , " " , d . path ) } fieldNames := records [ 0 ] records = records [ 1 : ] result := make ( map [ string ] DistroInfoSerie ) var foundPrecise bool for _ , fields := range records { record , ok := consumeRecord ( fieldNames , fields ) if ! ok { continue } createdDate , err := time . Parse ( dateFormat , record . Created ) if err != nil { continue } releasedDate , err := time . Parse ( dateFormat , record . Released ) if err != nil { continue } eolDate , err := time . Parse ( dateFormat , record . EOL ) if err != nil { continue } if ! foundPrecise { if record . Series != " " { continue } foundPrecise = true } result [ record . Series ] = DistroInfoSerie { Version : record . Version , CodeName : record . CodeName , Series : record . Series , Created : createdDate , Released : releasedDate , EOL : eolDate , } } d . mutex . Lock ( ) d . info = result d . mutex . Unlock ( ) return nil }
Refresh will attempt to update the information it has about each distro and
if the distro is supported or not.
Refresh will attempt to update the information it has about each distro and if the distro is supported or not .
// On non-Ubuntu systems this file won't exist but that's expected. // We ignore all series prior to precise. // Lock the distro info, as we're going to be updating it.