func (sr *StoreRoot) GetProps(name string, r interface{}) (interface{}, error) {

    switch r.(type) {
    case RepoProps:
    case ReposetProps:
    default:
        // Ok as well.
        return nil, fmt.Errorf("upsupported index property type")
    }

    rootdir := sr.GetDirectory()

    fsn, err := rootdir.Child(name)
    if err != nil {
        return nil, err
    }

    fi := fsn.(*mfs.File)

    if fi.Type() != mfs.TFile {
        return nil, fmt.Errorf("expected index property file, invalid type %v", fi.Type())
    }

    wfd, err := fi.Open(mfs.OpenReadWrite, true)
    if err != nil {
        return nil, err
    }
    defer wfd.Close()

    // sync file
    err = wfd.Sync()
    if err != nil {
        return nil, err
    }

    // make sure size has not changed
    size, err := wfd.Size()
    if err != nil {
        return nil, err
    }

    // seek back to beginning
    ns, err := wfd.Seek(0, io.SeekStart)
    if err != nil {
        return nil, err
    }

    if ns != 0 {
        return nil, fmt.Errorf("failed to seek to beginning.")
    }

    // read back bytes we wrote
    buf := make([]byte, size)
    n, err := wfd.Read(buf)
    if err != nil {
        return nil, err
    }

    if n != len(buf) {
        return nil, fmt.Errorf("did not read enough.")
    }

    if _, ok := r.(RepoProps); ok {

        rp2 := NewRepoProps()
        if err := rp2.Unmarshal(buf); err != nil {
            return nil, fmt.Errorf("failed to unmarshal repoprops file with error %v", err)
        }
        return rp2, nil

    } else if _, ok := r.(ReposetProps); ok {

        rp2 := NewReposetProps()
        if err := rp2.Unmarshal(buf); err != nil {
            return nil, fmt.Errorf("failed to unmarshal repoprops file with error %v", err)
        }
        return rp2, nil

    } else {
        return nil, fmt.Errorf("upsupported index property type")
    }
}
// Read file and return repoprops
Read file and return repoprops
// Read file and return repoprops
func (sr *StoreRoot) GetProps(name string, r interface{}) (interface{}, error) {
    switch r.(type) {
    case RepoProps:
    case ReposetProps:
    default:
        return nil, fmt.Errorf("upsupported index property type")
    }
    rootdir := sr.GetDirectory()
    fsn, err := rootdir.Child(name)
    if err != nil {
        return nil, err
    }
    fi := fsn.(*mfs.File)
    if fi.Type() != mfs.TFile {
        return nil, fmt.Errorf("expected index property file, invalid type %v", fi.Type())
    }
    wfd, err := fi.Open(mfs.OpenReadWrite, true)
    if err != nil {
        return nil, err
    }
    defer wfd.Close()
    err = wfd.Sync()
    if err != nil {
        return nil, err
    }
    size, err := wfd.Size()
    if err != nil {
        return nil, err
    }
    ns, err := wfd.Seek(0, io.SeekStart)
    if err != nil {
        return nil, err
    }
    if ns != 0 {
        return nil, fmt.Errorf("failed to seek to beginning.")
    }
    buf := make([]byte, size)
    n, err := wfd.Read(buf)
    if err != nil {
        return nil, err
    }
    if n != len(buf) {
        return nil, fmt.Errorf("did not read enough.")
    }
    if _, ok := r.(RepoProps); ok {
        rp2 := NewRepoProps()
        if err := rp2.Unmarshal(buf); err != nil {
            return nil, fmt.Errorf("failed to unmarshal repoprops file with error %v", err)
        }
        return rp2, nil
    } else if _, ok := r.(ReposetProps); ok {
        rp2 := NewReposetProps()
        if err := rp2.Unmarshal(buf); err != nil {
            return nil, fmt.Errorf("failed to unmarshal repoprops file with error %v", err)
        }
        return rp2, nil
    } else {
        return nil, fmt.Errorf("upsupported index property type")
    }
}
func ( sr * StoreRoot ) GetProps ( name string , r interface { } ) ( interface { } , error ) { switch r . ( type ) { case RepoProps : case ReposetProps : default : return nil , fmt . Errorf ( " " ) } rootdir := sr . GetDirectory ( ) fsn , err := rootdir . Child ( name ) if err != nil { return nil , err } fi := fsn . ( * mfs . File ) if fi . Type ( ) != mfs . TFile { return nil , fmt . Errorf ( " " , fi . Type ( ) ) } wfd , err := fi . Open ( mfs . OpenReadWrite , true ) if err != nil { return nil , err } defer wfd . Close ( ) err = wfd . Sync ( ) if err != nil { return nil , err } size , err := wfd . Size ( ) if err != nil { return nil , err } ns , err := wfd . Seek ( 0 , io . SeekStart ) if err != nil { return nil , err } if ns != 0 { return nil , fmt . Errorf ( " " ) } buf := make ( [ ] byte , size ) n , err := wfd . Read ( buf ) if err != nil { return nil , err } if n != len ( buf ) { return nil , fmt . Errorf ( " " ) } if _ , ok := r . ( RepoProps ) ; ok { rp2 := NewRepoProps ( ) if err := rp2 . Unmarshal ( buf ) ; err != nil { return nil , fmt . Errorf ( " " , err ) } return rp2 , nil } else if _ , ok := r . ( ReposetProps ) ; ok { rp2 := NewReposetProps ( ) if err := rp2 . Unmarshal ( buf ) ; err != nil { return nil , fmt . Errorf ( " " , err ) } return rp2 , nil } else { return nil , fmt . Errorf ( " " ) } }
Read file and return repoprops
Read file and return repoprops
// Ok as well. // sync file // make sure size has not changed // seek back to beginning // read back bytes we wrote