Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: When using gdrive as the schema, create_dir is not working properly #5615

Open
1 task
arianrhodsandlot opened this issue Feb 8, 2025 · 2 comments
Open
1 task
Assignees
Labels
bug Something isn't working

Comments

@arianrhodsandlot
Copy link

Describe the bug

When calling create_dir with gdrive as the schema, the directory is not created with an expected name.
I was using the latest Node.js bindings.

Steps to Reproduce

import { Operator } from 'opendal'

const op = new Operator('gdrive', { access_token: '****' })

// a directory with name 'a/' created since Google Drive treats '/' as a valid character for file name
await op.createDir('a/')

// an error occurred:
// Error: NotADirectory (permanent) at create_dir, context: { service: gdrive, path: a } => the path trying to create should end with `/`
await op.createDir('a')

There seems to be no way to create a directory whose name does not contain a trailing slash.

Image

Expected Behavior

While calling await op.createDir('a/'), a directory named 'a' rather than 'a/' should be created

Additional Context

No response

Are you willing to submit a PR to fix this bug?

  • Yes, I would like to submit a PR.
@arianrhodsandlot arianrhodsandlot added the bug Something isn't working label Feb 8, 2025
@Xuanwo
Copy link
Member

Xuanwo commented Feb 8, 2025

I'm guessing we need to trim the / after name:

async fn create_dir(&self, parent_id: &str, name: &str) -> Result<String> {
let url = "https://www.googleapis.com/drive/v3/files";
let content = serde_json::to_vec(&json!({
"name": name,
"mimeType": "application/vnd.google-apps.folder",
// If the parent is not provided, the folder will be created in the root folder.
"parents": [parent_id],
}))
.map_err(new_json_serialize_error)?;

@arianrhodsandlot
Copy link
Author

It seems create_dir isn't the only method not working as expected with gdrive, a majority of the methods related to gdrive seem to have some issues with the slashes as well. Examples:

code(Node.js) result note
await op.write('/a/b/c.txt', 'hello!') Image the names of parents should be 'a' and 'b' rather than 'a/' and 'b/'
await op.list('/a/')

Image
[] should be ['b2', 'b1', 'b']
await op.read('/a/b/c.txt')

Image
[Error: NotFound (permanent) at read, context: { service: gdrive, path: a/b/c.txt, range: 0- } => path not found: a/b/c.txt] should return the content of the file

@meteorgan meteorgan self-assigned this Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants