Coder Social home page Coder Social logo

flysystem-stream-wrapper's People

Contributors

andruha avatar kbond avatar snapshotpl avatar twistor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

flysystem-stream-wrapper's Issues

is_writable always return false

For me is_writable always returns false because the uid and gid are always set to 0.

Currently Stat::mergeMeta() ignores any uid or gid returned from the adapter; would it not make more sense to use them if they are available?

Incompatible with PHP 8.2

Hi,

I work with Drupal, and in my current project I'm updating the PHP version to PHP 8.2.9

After the updated, I'm receiving the next warning

Deprecated: Creation of dynamic property Drupal\flysystem\FlysystemBridge::$context is deprecated

I am checking and flysystem class extends from https://github.com/twistor/flysystem-stream-wrapper/blob/master/src/FlysystemStreamWrapper.php

And in the latter it does not have that property declared. I think it's a good solution to declare it in this class, since many extend from it. Currently I have added a patch in my project about twistor/flysystem-stream-wrapper and I have fixed the warning. But I don't know how to add that patch here in the github project to create a Pull request.

The only thing I have added is:

/**
* Context value.
*/
public $context = null;

I know it might be another idea to add it directly to the flysystem module, but I'm going here to see if you have any idea what's best.

Greetings,

Injectable Locking interface

Issues such as #16 seem to stem from the inability to inject locking behaviour.

Right now to change the API would seem to break downstream clients, so I propose that a an optional parameter be added to the constructor for the stream wrapper for a locking interface, which would allow those who want network locking and alternative behaviours to create their own implementations and absolve the library of solving locking and stream wrapper bindings.

`fopen($path, 'x')` should not succeed when called twice

The x mode for fopen() should fail when called twice, as the first call should create the file.

$a = fopen('fs://test.flag', 'x');
$b = fopen('fs://test.flag', 'x');
if (is_resource($a)) {
    echo 'a';
    fclose($a);
}
if (is_resource($b)) {
    echo 'b';
    fclose($b);
}

Expected result:

a

fopen(): failed to open stream: File exists

Actual result:

ab

Calls to `uri_stat()` triggers a notice

When checking for directories with is_dir() and the directory exists, the following notice is thrown:

PHP Notice: Undefined offset: 0 in <SOME_PATH>/vendor/twistor/flysystem-stream-wrapper/src/Flysystem/Plugin/Stat.php on line 157

The following code should trigger the error:

<?php

use League\Flysystem\Filesystem;
use League\Flysystem\Memory\MemoryAdapter;
use Twistor\FlysystemStreamWrapper;

require_once 'vendor/autoload.php';

$filesystem = new Filesystem(new MemoryAdapter());
FlysystemStreamWrapper::register('test', $filesystem);

$directory = 'test:///test';
var_dump(is_dir($directory)); // Works as expected, no notice

mkdir($directory);
var_dump(is_dir($directory)); // Works as expected, but a notice is thrown

stream_wrapper_register missing STREAM_IS_URL param

<?php
$sftp = new SftpAdapter([...]);
FlysystemStreamWrapper::register('test', new Filesystem($sftp));

var_dump(ini_get('allow_url_include')); // returns false

include 'test://test.php'; // should trigger the warning - include(): test:// wrapper is disabled in the server configuration by allow_url_include=0

The warning isn't triggered but instead the file will be loaded even per sftp.

I think the problem is here.

stream_wrapper_register() has a third param for flags and flysystem adapters should imho set the flag "STREAM_IS_URL" to prevent loading of php files per stream wrapper when the option allow_url_include is disabled or at least there should be a pass through parameter for the FlysystemStreamWrapper::register() method (or another configuration option).

Unlink returns invalid values with Dropbox adapter

I've been trying to get Drupal's Flysytem_dropbox to work with Filefield_paths for automatic renaming.

It appears to work out of the box for the local adapter, but for Dropbox it moves the file but does not update Drupal's file entity.

My developers pointed me to the issue that is probably responsible:
"The Dropbox adapter returns a missing value when it deletes a file, from the function delete() at /public_html/vendor/league/flysystem-dropbox/src/DropboxAdapter.php:154).
It must return only TRUE or FALSE, since it function is called from FlysystemStreamWrapper::unlink() -
this it wrapper to php function unlink() which can't return another values."

They suggest changing that delete() function from:

public function delete($path) {
  $location = $this->applyPathPrefix($path);
  return $this->client->delete($location); // it returns full result
}

to:

public function delete($path) {
    $location = $this->applyPathPrefix($path);
    $result = $this->client->delete($location);
    if (isset($result['is_deleted'])) {
      return $result['is_deleted'];
    }
    return FALSE;
}

However, it would seem to me to be better to change the unlink() function in this module. Shouldn't the functions here have their outputs validated to ensure they always return values appropriate for the php functions they are emulating?

At the moment we have:

public function unlink($uri)
        {
            $this->uri = $uri;

            return $this->invoke($this->getFilesystem(), 'delete', [$this->getTarget()], 'unlink');
        }

Which seems to trust that the Flysystem adapter is only returning values that it would be acceptable for unlink to return, and that is false in the case of the Dropbox adapter.

(Unrelatedly, my developers also tell me that composer require "guzzle/guzzle:3.x" is needed not just the guzzlehttp/guzzle:6.x in Drupal Core, as flysystem_dropbox uses Url::factory().

Warning: fseek(): supplied resource is not a valid stream resource

yii\base\ErrorException: fseek(): supplied resource is not a valid stream resource in /var/www/vendor/twistor/flysystem-stream-wrapper/src/FlysystemStreamWrapper.php:421
Stack trace:
#0 /var/www/vendor/yiisoft/yii2/web/UploadedFile.php(164): Twistor\FlysystemStreamWrapper->stream_flush()
#1 /var/www/vendor/yiisoft/yii2/web/UploadedFile.php(164): ::move_uploaded_file()
#2 /var/www/vendor/yii-dream-team/yii2-upload-behavior/src/FileUploadBehavior.php(223): yii\web\UploadedFile->saveAs()
#3 /var/www/vendor/yiisoft/yii2/base/Component.php(627): yiidreamteam\upload\ImageUploadBehavior->afterSave()
#4 /var/www/vendor/yiisoft/yii2/base/Component.php(627): ::call_user_func:{/var/www/vendor/yiisoft/yii2/base/Component.php:627}()
#5 /var/www/vendor/yiisoft/yii2/db/BaseActiveRecord.php(991): common\models\Image->trigger()
#6 /var/www/vendor/yiisoft/yii2/db/ActiveRecord.php(526): common\models\Image->afterSave()
#7 /var/www/vendor/yiisoft/yii2/db/ActiveRecord.php(481): common\models\Image->insertInternal()
#8 /var/www/vendor/yiisoft/yii2/db/BaseActiveRecord.php(669): common\models\Image->insert()
#9 /var/www/vendor/yiisoft/yii2/db/BaseActiveRecord.php(1571): common\models\Image->save()
#10 /var/www/vendor/yiisoft/yii2/db/BaseActiveRecord.php(1341): common\models\Product->bindModels()
#11 /var/www/vendor/la-haute-societe/yii2-save-relations-behavior/src/SaveRelationsBehavior.php(427): common\models\Product->link()
#12 /var/www/vendor/yiisoft/yii2/base/Component.php(627): lhs\Yii2SaveRelationsBehavior\SaveRelationsBehavior->afterSave()
#13 /var/www/vendor/yiisoft/yii2/base/Component.php(627): ::call_user_func:{/var/www/vendor/yiisoft/yii2/base/Component.php:627}()
#14 /var/www/vendor/yiisoft/yii2/db/BaseActiveRecord.php(991): common\models\Product->trigger()
#15 /var/www/common/models/Product.php(140): common\models\Product->afterSave()
#16 /var/www/vendor/yiisoft/yii2/db/BaseActiveRecord.php(816): common\models\Product->afterSave()
#17 /var/www/vendor/yiisoft/yii2/db/ActiveRecord.php(596): common\models\Product->updateInternal()
#18 /var/www/vendor/yiisoft/yii2/db/BaseActiveRecord.php(672): common\models\Product->update()
#19 /var/www/backend/forms/ProductForm.php(88): common\models\Product->save()
#20 /var/www/vendor/yii2tech/admin/actions/Update.php(46): backend\forms\ProductForm->save()
#21 /var/www/vendor/yiisoft/yii2/base/Action.php(94): yii2tech\admin\actions\Update->run()
#22 /var/www/vendor/yiisoft/yii2/base/Action.php(94): ::call_user_func_array:{/var/www/vendor/yiisoft/yii2/base/Action.php:94}()
#23 /var/www/vendor/yiisoft/yii2/base/Controller.php(157): yii2tech\admin\actions\Update->runWithParams()
#24 /var/www/vendor/yiisoft/yii2/base/Module.php(528): backend\controllers\ProductController->runAction()
#25 /var/www/vendor/yiisoft/yii2/web/Application.php(103): yii\web\Application->runAction()
#26 /var/www/vendor/yiisoft/yii2/base/Application.php(386): yii\web\Application->handleRequest()
#27 /var/www/backend/web/index.php(17): yii\web\Application->run()
#28 {main}

Flysystem adapter https://github.com/ArgentCrusade/flysystem-selectel
Stream close after request by Guzzle https://github.com/ArgentCrusade/selectel-cloud-storage/blob/master/src/FileUploader.php#L26 and we have such error

Need add check is_resource($this->handle) to stream_flush and stream_close methods

What is the alive status of this project?

Is this project alive?

I was hoping to use it, but I can see some well-pickled PRs from the summer that aren't getting merged, and those fix the functionality that I will be using, which is completely broken without the fixes.

Twistor\FlysystemStreamWrapper::stream_stat() sets size to 0 for at least some remote files, can result in empty files being written

I encountered this issue with https://github.com/thephpleague/flysystem-azure-blob-storage/issues/22 but I believe it could occur for other remote filesystems.

When I attempt copy with a remote file backed by flysystem-azure-blob-storage as the source it always writes 0 byte files at the destination. The culprit seems to be Twistor\FlysystemStreamWrapper::stream_stat() which sets the size of the returned $stat array to zero. This is because it calls Twistor\StreamUtil::getSize() which uses https://www.php.net/manual/en/function.fstat.php. There's a note on the documentation page:

Note: This function will not work on remote files as the file to be examined must be accessible via the server's filesystem.

I'm guessing that's why, though it fails in a much less obvious way than I'd expect from the note.

I'll attach a pull request shortly with a crude fix which ignores the fstat() filesize if it is zero and just uses the original file size from url_stat. I'm not sure if this is the best solution but it seems to work for me.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.