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

add test for . in path with no extension, fix smb #26143

Closed
wants to merge 4 commits into from

Conversation

butonic
Copy link
Member

@butonic butonic commented Sep 19, 2016

Description

  • No longer try to append the original file extension to a temp file used when uploading to an SMB storage.
  • Implement recursive mkdir
  • Add unit test.

Related Issue

#25994 (comment)

Motivation and Context

removes unnecessary code which might lead to problems

How Has This Been Tested?

new unit test

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.

@mention-bot
Copy link

@butonic, thanks for your PR! By analyzing the annotation information on this pull request, we identified @icewind1991, @blizzz, @PVince81 and @Xenopathic to be potential reviewers

@butonic
Copy link
Member Author

butonic commented Sep 19, 2016

cc @VicDeo

@butonic
Copy link
Member Author

butonic commented Sep 19, 2016

backport to 9.1 needed

@PVince81
Copy link
Contributor

@butonic don't forget to mention the other SMB master @jvillafanez

@PVince81
Copy link
Contributor

might lead to problems

Was about to ask about severity, seems this didn't cause any issues.

Still 👍 for removing this unnecessary logic

@@ -517,9 +512,18 @@ public function filetype($path) {
public function mkdir($path) {
$this->log('enter: '.__FUNCTION__."($path)");
$result = false;
$path = $this->buildPath($path);
$dirs = explode('/', $path);
Copy link
Member

Choose a reason for hiding this comment

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

How do the rest of the implementations work? Are the implementations expected to create the directories recursively?

Copy link
Member Author

Choose a reason for hiding this comment

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

The API says it should be recursive: https://github.com/owncloud/core/blob/master/lib/public/Files/Storage/IStorage.php#L66

I tried using a recursive mkdir ... that at least also breaks webdav ... looking at the other implementations nearly none does it recursively.

will send a separate PR for that. for now I'll use 5 mkdirs ... jeez

Copy link
Member Author

Choose a reason for hiding this comment

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

#7324 oh boy

@jvillafanez
Copy link
Member

We'll have to check if the mimetypes are properly sent to the clients. I think this was set to help mimetype detection.

@butonic
Copy link
Member Author

butonic commented Sep 20, 2016

@jvillafanez hm:

14:00:36 There were 2 failures:
14:00:36 
14:00:36 1) OCA\Files_Sharing\Tests\CacheTest::testSearchByMime
14:00:36 Failed asserting that 4 matches expected 3.
14:00:36 
14:00:36 /var/lib/jenkins/workspace/owncloud-core/core/PR-26143/apps/files_sharing/tests/CacheTest.php:444
14:00:36 /var/lib/jenkins/workspace/owncloud-core/core/PR-26143/apps/files_sharing/tests/CacheTest.php:231
14:00:36 
14:00:36 2) OCA\Files_Sharing\Tests\CacheTest::testGetFolderContentsWhenSubSubdirShared
14:00:36 Failed asserting that two strings are equal.
14:00:36 --- Expected
14:00:36 +++ Actual
14:00:36 @@ @@
14:00:36 -'application/xml'
14:00:36 +'text/plain'
14:00:36 
14:00:36 /var/lib/jenkins/workspace/owncloud-core/core/PR-26143/apps/files_sharing/tests/CacheTest.php:465
14:00:36 /var/lib/jenkins/workspace/owncloud-core/core/PR-26143/apps/files_sharing/tests/CacheTest.php:449
14:00:36 /var/lib/jenkins/workspace/owncloud-core/core/PR-26143/apps/files_sharing/tests/CacheTest.php:426

investigating ...

@@ -413,6 +408,7 @@ public function fopen($path, $mode) {
if (!$this->isCreatable(dirname($path))) {
break;
}
$ext = pathinfo($path, PATHINFO_EXTENSION);
Copy link
Member

Choose a reason for hiding this comment

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

My trust level in these kind of functions is usually low. I've checked http://php.net/manual/en/function.pathinfo.php and I'm not sure if this is what we really want here...

Copy link
Member Author

Choose a reason for hiding this comment

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

pathinfo actually implements the extension extraction correctly. In contrast to the php mess used before.

Copy link
Member Author

Choose a reason for hiding this comment

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

we may need additional handling because we have different mimetypes for .tar.bz2/.bz2 and .tar.gz/.gz, see

"tar.bz2": ["application/x-bzip2"],

Copy link
Member

Choose a reason for hiding this comment

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

If the basename of the path starts with a dot, the following characters are interpreted as extension, and the filename is empty

This is what worries me, in addition to the .tar.bz2 problem.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add a test for '/path/to a/hidden/.file', '/path/to a/hidden/.file.php', '/path/to a/hidden/.file.gz' and '/path/to a/hidden/.file.tar.gz' to https://github.com/owncloud/core/pull/26143/files#diff-5513e31c79d843ab51b3af2a528af6ddR138

Copy link
Member Author

@butonic butonic Sep 22, 2016

Choose a reason for hiding this comment

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

@jvillafanez pathinfo treats .files correctly:
pathinfo('.hidden')

Array
(
    [dirname] => .
    [basename] => .hidden
    [extension] => hidden
    [filename] => 
)

pathinfo('.hidden.gz')

Array
(
    [dirname] => .
    [basename] => .hidden.gz
    [extension] => gz
    [filename] => .hidden
)

perfectly fine IMO.

Copy link
Member

Choose a reason for hiding this comment

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

Am I the only one who think that for the ".hidden" file the filename should be ".hidden" and the extension should be empty? If I'm the only one, then let's move on.

@butonic
Copy link
Member Author

butonic commented Sep 20, 2016

@PVince81 @VicDeo @jvillafanez jenkins is green.

  • additional handling for .tar.bz2/.bz2 and .tar.gz/.gz: add test for . in path with no extension, fix smb #26143 (comment)
  • ignore . at beginning of basename for hidden files tests show that pathinfo treats .hidden and .hidden.txt correctly
  • submit separate PR to test and implement recursive mkdir
  • backport to stable9.1
  • backport to stable9.0

@butonic butonic force-pushed the extension-fixes branch 3 times, most recently from 2e021f8 to d59b6af Compare September 21, 2016 21:36
* @return array|string|null
* @since 9.2.0
*/
static function pathinfo( $path, $options = PATHINFO_DIRNAME | PATHINFO_BASENAME | PATHINFO_EXTENSION | PATHINFO_FILENAME ) {
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to simplify this code? Scrutinizer reports a complexity value of 17 for this function, which is pretty high: https://scrutinizer-ci.com/g/owncloud/core/inspections/a866f5ac-174c-4d40-af68-2a73fc3059f1/code-structure/class/OCP%5CFiles

At least we have tests for this function, but this is a black box for me...

Copy link
Member

Choose a reason for hiding this comment

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

Could you simplify this? Maybe:

if ($path endswith 'tar.gz') {
    $result = handleTarGzPaths($path);
} else if ($path endswith 'tar.bz2') {
    $result = handleTarBz2Paths($path)
} else {
    $result = pathinfo($path);
}

Whether those "handle" function are public or private is just to be decided, but at least the complexity of this function is reduced and it should also be easier to extend with other custom extensions such as ".tar.gzip", ".jra.gz" or ".hbm.xml" which we might want to add at some point.

Maybe we should consider to introduce a "ExtensionHandling" class or similar for these kind of functions.

Copy link
Member

Choose a reason for hiding this comment

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

I absolutly agree on moving this to a class on its own - we don't want static APIs in OCP and ocp files shall die.

@butonic
Copy link
Member Author

butonic commented Oct 14, 2016

@jvillafanez @PVince81 @PhilippSchaffrath jenkins is green after a rebase again

@PVince81
Copy link
Contributor

PVince81 commented Dec 6, 2016

@jvillafanez @DeepDiver1975 rereview ? Not sure if your points were addressed though.

@jvillafanez
Copy link
Member

Except for my comment, the rest of the code is fine.

@PVince81
Copy link
Contributor

PVince81 commented Apr 6, 2017

finish this or defer ?

@jvillafanez
Copy link
Member

I'm not sure if we have tested with different locales (http://php.net/manual/es/function.pathinfo.php#119468). If not I'd rather defer this. Code should be fine otherwise.

@PVince81 PVince81 modified the milestones: triage, 10.0 May 17, 2017
@mmattel
Copy link
Contributor

mmattel commented Jul 13, 2017

Any update on this?

@jvillafanez
Copy link
Member

I'd wait for @butonic status report on this.

@PVince81
Copy link
Contributor

any update ?

@PVince81
Copy link
Contributor

PVince81 commented Feb 8, 2019

@jvillafanez @butonic please evaluate if investing time in this provides enough value

I'd vote for closing unless there are strong arguments for keeping this

@butonic
Copy link
Member Author

butonic commented Feb 8, 2019

we should probably move the test cases to an acceptance test that we can also use with phoenix and OCIS

@jvillafanez
Copy link
Member

If we want to keep this I'd prefer to make a new PR based on this one. This way we don't need to deal with the conflicts.
There are also a couple of changes I'd do:

  • Create a IPathOperator class (name to be agreed on) to handle path operations.
  • Create the implementation. The base would be the OCP\Files::pathinfo, and might include some other functions (thinking about the Filesystem::normalizePath).

In any case, fixing all those conflicts will be a pain, so I don't think it's a good idea.

@PVince81
Copy link
Contributor

raised #34442 for acceptance test cases

@PVince81
Copy link
Contributor

I can't find the original comment/reason for this PR as the link in OP doesn't work.

If this was important, please re-raise as new ticket.

@PVince81 PVince81 closed this Feb 11, 2019
@PVince81 PVince81 deleted the extension-fixes branch February 11, 2019 15:00
@lock lock bot locked as resolved and limited conversation to collaborators Feb 12, 2020
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.

7 participants