user/file.go
func _edit(name string, _row row, remove bool) (err error) {
	filename := _row.filename()

	dbf, err := openDBFile(filename, os.O_RDWR)
	if err != nil {
		return err
	}
	defer func() {
		e := dbf.close()
		if e != nil && err == nil {
			err = e
		}
	}()

	var buf bytes.Buffer
	name_b := []byte(name)
	isFound := false

	for {
		line, err2 := dbf.rd.ReadBytes('\n')
		if err2 == io.EOF {
			break
		}

		if !isFound && bytes.HasPrefix(line, name_b) {
			isFound = true
			if remove { // skip user
				continue
			}

			line = []byte(_row.String())
		}
		if _, err = buf.Write(line); err != nil {
			return err
		}
	}

	if isFound {
		if err = backup(filename); err != nil {
			return
		}

		if _, err = dbf.file.Seek(0, os.SEEK_SET); err != nil {
			return
		}

		var n int
		n, err = dbf.file.Write(buf.Bytes())
		if err != nil {
			return
		}
		err = dbf.file.Truncate(int64(n))
	}

	return
}
func _edit(name string, _row row, remove bool) (err error) {
	filename := _row.filename()

	dbf, err := openDBFile(filename, os.O_RDWR)
	if err != nil {
		return err
	}
	defer func() {
		e := dbf.close()
		if e != nil && err == nil {
			err = e
		}
	}()

	var buf bytes.Buffer
	name_b := []byte(name)
	isFound := false

	for {
		line, err2 := dbf.rd.ReadBytes('\n')
		if err2 == io.EOF {
			break
		}

		if !isFound && bytes.HasPrefix(line, name_b) {
			isFound = true
			if remove { // skip user
				continue
			}

			line = []byte(_row.String())
		}
		if _, err = buf.Write(line); err != nil {
			return err
		}
	}

	if isFound {
		if err = backup(filename); err != nil {
			return
		}

		if _, err = dbf.file.Seek(0, os.SEEK_SET); err != nil {
			return
		}

		var n int
		n, err = dbf.file.Write(buf.Bytes())
		if err != nil {
			return
		}
		err = dbf.file.Truncate(int64(n))
	}

	return
}
func _edit ( name string , _row row , remove bool ) ( err error ) { filename := _row . filename ( ) dbf , err := openDBFile ( filename , os . O_RDWR ) if err != nil { return err } defer func ( ) { e := dbf . close ( ) if e != nil && err == nil { err = e } } ( ) var buf bytes . Buffer name_b := [ ] byte ( name ) isFound := false for { line , err2 := dbf . rd . ReadBytes ( '\n' ) if err2 == io . EOF { break } if ! isFound && bytes . HasPrefix ( line , name_b ) { isFound = true if remove { // skip user continue } line = [ ] byte ( _row . String ( ) ) } if _ , err = buf . Write ( line ) ; err != nil { return err } } if isFound { if err = backup ( filename ) ; err != nil { return } if _ , err = dbf . file . Seek ( 0 , os . SEEK_SET ) ; err != nil { return } var n int n , err = dbf . file . Write ( buf . Bytes ( ) ) if err != nil { return } err = dbf . file . Truncate ( int64 ( n ) ) } return }
// _edit is a generic editor for the given user/group name.
// If remove is true, it removes the structure of the user/group name.
//
// TODO: get better performance if start to store since when the file is edited.
// So there is to store the size of all lines read until that point to seek from
// there.
_edit is a generic editor for the given user / group name . If remove is true it removes the structure of the user / group name . TODO : get better performance if start to store since when the file is edited . So there is to store the size of all lines read until that point to seek from there .