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

Introduce public storage class for extending #26675

Merged
merged 1 commit into from
Nov 29, 2016
Merged

Conversation

PVince81
Copy link
Contributor

@PVince81 PVince81 commented Nov 21, 2016

Description

When writing external storage it is complicated to reimplement IStorage
and many others. This PR provides public classes to be extended to
provider storage specific implementations.

Related Issue

Because apps need to be able to extend the common storage class or use the flysystem adapter without accessing the private namespaces.

Also see owncloud-archive/documentation#2721

Motivation and Context

How Has This Been Tested?

  • TODO: use it in files_external_ftp

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@DeepDiver1975 @jvillafanez @labkode FYI

@PVince81
Copy link
Contributor Author

Tested with this PR owncloud/files_external_ftp#11 from the FTP app.

To make it a bit better I'll also make the storages from files_external extend that one.

@PVince81
Copy link
Contributor Author

Ok, done. The storages from files_external now extend OCP\Files\Storage\StorageAdapter.
I've tested with Dropbox and it still works.

@jvillafanez
Copy link
Member

We should define the abstract methods required to be implemented, first in OC\Files\Storage\Common and then in the public adapter. That way is way easier for anyone to know what he should implement.

It's REALLY annoying creating a new subclass, implementing a couple of methods and when you consider it's finally ready then you notice that an additional method should be implemented because the class explodes.

@PVince81
Copy link
Contributor Author

@jvillafanez do you mean checking all abstract methods from the interface and redefine these as abstract within the StorageAdapter class ?

Indeed, the Common class doesn't implement ALL the methods, there are still a few remaining... (me really longing for a better simplified storage API in the future)

@jvillafanez
Copy link
Member

Yes. In case of the stat method, you have to check the new public class (not defined there), check the Common class (again not defined there) and finally the interface. The same happens with the getId method. Those are a lot of "jumps" to know what are the methods that should be implemented.

There is also a weird inheritance chain: if you want to implement the new public storage, you have to check the Common class, which is private, and then the interface, which is public again. Maybe the Common class should be moved to the public library....

I think it would be better if the abstract classes define the list of abstract methods and they also document how they should be implemented. That way, just looking at the class, you have all the information you need to implement the class.

@PVince81
Copy link
Contributor Author

I think it would be better if the abstract classes define the list of abstract methods and they also document how they should be implemented. That way, just looking at the class, you have all the information you need to implement the class.

Ok, I'll do that short term.

Middle to long term we should probably move all methods from Common into StorageAdapter and make every other storage, even the internal ones, extend from it.

@PVince81 PVince81 force-pushed the public-storage-adapter branch from eda8081 to cf6aef6 Compare November 24, 2016 10:52
@PVince81
Copy link
Contributor Author

@jvillafanez I've added the abstract methods that a storage must implement in StorageAdapter and FlysystemStorageAdapter.

@PVince81
Copy link
Contributor Author

Okay, the code checker wants me to add @since tags for this "new" public APIs, will do...

@PVince81 PVince81 force-pushed the public-storage-adapter branch from cf6aef6 to 3fce43c Compare November 24, 2016 15:05
@jvillafanez
Copy link
Member

The only thing I miss is the expected exceptions the methods are supposed to throw. The rest is really nice!!.

Should we include some documentation of common methods that might be overwritten for performance? I'm thinking about the rename, isReadable, isCreatable, etc.

@PVince81
Copy link
Contributor Author

Ahem ahem, there are no expected exceptions in this API... 😢
Do you mean adding StorageNotAvailableException in every method signature ?

As for the docs, we could extend what I already posted to mention best practices when implementing an ext storage: owncloud-archive/documentation#2728

@jvillafanez
Copy link
Member

Do you mean adding StorageNotAvailableException in every method signature ?

At least that is being taken into account I think.

The problem is that if nobody tells you that you should throw an StorageNotAvailableException when you can't connect to the server, what I'd return is a false or any other value that could be interpreted as an error, which might cause some issues.

If there is no expected exceptions, throwing that exception is conceptually wrong 😢

@PVince81
Copy link
Contributor Author

In the long term I hope we can redefine the storage APIs completely to be more simply and base them on our own concept (#22388 (comment)), not mimic PHP's system functions, which means exceptions for any errors.

@jvillafanez do you want me to add StorageNotAvailableException in the PHPDoc of the adapters for now ?

@jvillafanez
Copy link
Member

If it's being handled I think it's good to have it documented

@PVince81
Copy link
Contributor Author

@jvillafanez added here 4208efc

I took the opportunity to also add these on the IStorage interface where they were missing...

* @since 9.0.0
*/
public function isSharable($path);

/**
* get the full permissions of a path.
* Should return a combination of the PERMISSION_ constants defined in lib/public/constants.php
* @throws StorageNotAvailableException if the storage is temporarily not available
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicated below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my copy-paste skills have failed me 😢

@jvillafanez
Copy link
Member

Other than that, 👍

When writing external storage it is complicated to reimplement IStorage
and many others. This PR provides public classes to be extended to
provider storage specific implementations.
@PVince81 PVince81 force-pushed the public-storage-adapter branch from 4208efc to c72c159 Compare November 25, 2016 13:16
@PVince81
Copy link
Contributor Author

Fixed and squashed

@PVince81 PVince81 merged commit bfc7f16 into master Nov 29, 2016
@PVince81 PVince81 deleted the public-storage-adapter branch November 29, 2016 12:05
@lock
Copy link

lock bot commented Aug 4, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants