func (pfs *azureFS) Get(filename string) (fs.File, error) { fullpath := filename if fullpath[0] != '/' { fullpath = "/" + pfs.currentRealDirectory + "/" + filename } toks := splitAndCleanPath(fullpath) log.WithFields(log.Fields{"pfs": pfs, "filename": filename, "fullpath": fullpath, "toks": toks}).Debug("azureFS::azureFS::Get called") if len(toks) == 0 { // root return azureContainer.New("", time.Now(), pfs.client), nil } if len(toks) == 1 { // containter return azureContainer.New(filename, time.Now(), pfs.client), nil } // else blob props, err := pfs.client.GetBlobProperties(toks[0], strings.Join(toks[1:], "/")) if err != nil { return nil, err } return azureBlob.New(strings.Join(toks[1:], "/"), toks[0], props.ContentLength, parseAzureTime(props.LastModified), 0666, pfs.client), nil }
func (pfs *azureFS) New(filename string, isDirectory bool) (fs.File, error) { fullpath := filename if fullpath[0] != '/' { fullpath = "/" + pfs.currentRealDirectory + "/" + filename } log.WithFields(log.Fields{"pfs": pfs, "filename": filename, "fullpath": fullpath, "isDirectory": isDirectory}).Debug("azureFS::azureFS::New called") toks := splitAndCleanPath(fullpath) if len(toks) == 1 { // container return azureContainer.New(filename, time.Now(), pfs.client), nil } return azureBlob.New(strings.Join(toks[1:], "/"), toks[0], 0, time.Now(), 0666, pfs.client), nil }
func (pfs *azureFS) List() ([]fs.File, error) { if pfs.CurrentDirectory() == "/" { // list containers // TODO // we should check for more than 1000 entries lcParams := storage.ListContainersParameters{MaxResults: 1000} lbr, err := pfs.client.ListContainers(lcParams) if err != nil { return nil, err } cnts := make([]fs.File, len(lbr.Containers)) for i, item := range lbr.Containers { cnts[i] = azureContainer.New(item.Name, parseAzureTime(item.Properties.LastModified), pfs.client) } return cnts, nil } // files! toks := splitAndCleanPath(pfs.currentRealDirectory) var lbParams storage.ListBlobsParameters if len(toks) == 1 { lbParams = storage.ListBlobsParameters{MaxResults: 1000, Delimiter: "/"} } else { lbParams = storage.ListBlobsParameters{MaxResults: 1000, Prefix: strings.Join(toks[1:], "/") + "/", Delimiter: "/"} } lbr, err := pfs.client.ListBlobs(toks[0], lbParams) if err != nil { return nil, err } blobs := make([]fs.File, len(lbr.Blobs)) for i, item := range lbr.Blobs { toks := splitAndCleanPath(item.Name) blobs[i] = azureBlob.New(toks[len(toks)-1], pfs.currentRealDirectory, item.Properties.ContentLength, parseAzureTime(item.Properties.LastModified), 0666, pfs.client) } return blobs, nil }