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

oc.mkdir with subfolders HTTP error 409. Solution? #213

Open
MoonPie88 opened this issue Jan 22, 2018 · 6 comments
Open

oc.mkdir with subfolders HTTP error 409. Solution? #213

MoonPie88 opened this issue Jan 22, 2018 · 6 comments

Comments

@MoonPie88
Copy link

Hello,

when trying to create a folder, for example /folder1/folder2/folder3, I get a HTTP error 409 if the "main folders", folder1/folder2, don't exist.
So I have to create folder1 and folder2 before creating folder3, but it is also possible that folder1 already exists.

Is it possible to check if the folder aleady exists without getting a HTTP error?

Or do you have any other solution?

@PVince81
Copy link
Contributor

409 is a Webdav thing if you try to create a folder where the parent doesn't exist.

One idea would be to extend pyocclient to add an argument create_parents=True to the mkdir() function which could automatically do such checks.

Marking as enhancement.

In the meantime you can use file_info on the parents to check whether they exist before doing a mkdir or simply catch the 409 and implement the parent creation logic yourself.

@PVince81
Copy link
Contributor

of course you're also welcome to contribute to pyocclient by improving mkdir as specified above and sending pull requests 😄

@MoonPie88
Copy link
Author

Thank you for the quick answer.
When calling oc.file_info(path) and the parent doesn't exist I get a 404 :(
I will try to catch the 409 but perhaps someone has a better idea.

@PVince81
Copy link
Contributor

I mean call oc.file_info() on all parents directly in which case you'll get "None" if it doesn't exist.

I'd rather suggest catching 409 explicitly and then trying to create parent. If 409 as well, continue recursively up to root.

@MoonPie88
Copy link
Author

I made a simple quick and dirty code to create the folders revursivly.

I made a pull request but I don't know if I'd done it right because it doesn't show here?
Thanks for the help!

@PVince81
Copy link
Contributor

@MoonPie88 you need to select this repository owncloud/pyocclient as the target of your PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants