Expand description
Create dir
- Proposal Name:
create-dir - Start Date: 2022-04-06
- RFC PR: apache/opendal#221
- Tracking Issue: apache/opendal#222
§Summary
Add creating dir support for OpenDAL.
§Motivation
Interoperability between OpenDAL services requires dir support. The object storage system will simulate dir operations with / via object ends. But we can’t share the same behavior with fs, as mkdir is a separate syscall.
So we need to unify the behavior about dir across different services.
§Guide-level explanation
After this proposal got merged, we will treat all paths that end with / as a dir.
For example:
read("abc/")will return anIsDirerror.write("abc/")will return anIsDirerror.stat("abc/")will be guaranteed to return a dir or aNotDirerror.delete("abc/")will be guaranteed to delete a dir orNotDir/NotEmptyerror.list("abc/")will be guaranteed to list a dir or aNotDirerror.
And we will support create an empty object:
// create a dir object "abc/"
let _ = op.object("abc/").create().await?;
// create a file object "abc"
let _ = op.object("abc").create().await?;§Reference-level explanation
And we will add a new API called create to create an empty object.
struct OpCreate {
path: String,
mode: ObjectMode,
}
pub trait Accessor: Send + Sync + Debug {
async fn create(&self, args: &OpCreate) -> Result<Metadata>;
}Object will expose API like create which will call Accessor::create() internally.
§Drawbacks
None
§Rationale and alternatives
None
§Prior art
None
§Unresolved questions
When writing this proposal, io_error_more is not stabilized yet. We can’t use NotADirectory nor IsADirectory directly.
Using from_raw_os_error is unacceptable because we can’t carry our error context.
use std::io;
let error = io::Error::from_raw_os_error(22);
assert_eq!(error.kind(), io::ErrorKind::InvalidInput);So we will use ErrorKind::Other for now, which means our users can’t check the following errors:
IsADirectoryDirectoryNotEmptyNotADirectory
Until they get stabilized.
§Future possibilities
None