fix(rados): Create OMAP for root directory

When using the RADOS driver, the hierarchy of the files is stored
in OMAPs, but the root OMAP was not created and a call to List("/")
was returning an error instead of returned the first level files
stored. This patches creates an OMAP for "/" and excludes the listed
directory from the list of files returned.

Signed-off-by: Vincent Giersch <vincent@giersch.fr>
This commit is contained in:
Vincent Giersch 2015-08-10 23:11:17 +02:00
parent 3cecbf36d8
commit 6c39af6708
2 changed files with 13 additions and 3 deletions

View file

@ -409,8 +409,10 @@ func (d *driver) List(ctx context.Context, dirPath string) ([]string, error) {
keys := make([]string, 0, len(files)) keys := make([]string, 0, len(files))
for k := range files { for k := range files {
if k != dirPath {
keys = append(keys, path.Join(dirPath, k)) keys = append(keys, path.Join(dirPath, k))
} }
}
return keys, nil return keys, nil
} }
@ -528,7 +530,7 @@ func (d *driver) putOid(objectPath string, oid string) error {
} }
// Esure parent virtual directories // Esure parent virtual directories
if createParentReference && directory != "/" { if createParentReference {
return d.putOid(directory, "") return d.putOid(directory, "")
} }
@ -581,7 +583,7 @@ func (d *driver) deleteOid(objectPath string) error {
} }
// Remove reference on parent omaps // Remove reference on parent omaps
if directory != "/" { if directory != "" {
return d.deleteOid(directory) return d.deleteOid(directory)
} }
} }

View file

@ -87,6 +87,14 @@ func (suite *DriverSuite) TearDownTest(c *check.C) {
} }
} }
// TestRootExists ensures that all storage drivers have a root path by default.
func (suite *DriverSuite) TestRootExists(c *check.C) {
_, err := suite.StorageDriver.List(suite.ctx, "/")
if err != nil {
c.Fatalf(`the root path "/" should always exist: %v`, err)
}
}
// TestValidPaths checks that various valid file paths are accepted by the // TestValidPaths checks that various valid file paths are accepted by the
// storage driver. // storage driver.
func (suite *DriverSuite) TestValidPaths(c *check.C) { func (suite *DriverSuite) TestValidPaths(c *check.C) {