Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Filesystem] Add $suffix argument to tempnam()#33003

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:masterfromjdufresne:tempnam
Feb 4, 2020
Merged

[Filesystem] Add $suffix argument to tempnam()#33003

fabpot merged 1 commit intosymfony:masterfromjdufresne:tempnam
Feb 4, 2020

Conversation

jdufresne
Copy link
Contributor

@jdufresnejdufresne commentedAug 7, 2019
edited
Loading

QA
Branch?4.4
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#33002
LicenseMIT
Doc PRsymfony/symfony-docs#12108

Description

Thetempnam() interface was previously:

tempnam($dir,$prefix)

This adds a third argument,$suffix, that is appended to the filename after the random component. This defaults to'' for backwards compatibility. This is quite useful when the temporary file is consumed for a specific purpose that expects a suffix.

Example

$filesystem->tempnam('/tmp','prefix_','.png');

Would create a file like:/tmp/prefix_abcd1234.png.

@jdufresne
Copy link
ContributorAuthor

Thanks for the reviews. I have made the suggested changes.

@derrabus
Copy link
Member

The test failures on Travis seem to be related to your changes.

@jdufresne
Copy link
ContributorAuthor

Thanks. I fixed my code/tests so they are passing again. Travis is now failing for reasons that appear to be unrelated to this PR.

@yceruto
Copy link
Member

@jdufresne is your current branch up to date with 4.4?

@jdufresne
Copy link
ContributorAuthor

jdufresne commentedAug 7, 2019
edited
Loading

The parent commit isd3a7be8 (a few new commits landed minutes ago).

Looks like the 4.4 branch is also failing with the same errors as of today.

yceruto reacted with thumbs up emoji

@derrabus
Copy link
Member

The test failures have been caused by Twig. The issue should be fixed withtwigphp/Twig@debc5c3

yceruto reacted with thumbs up emoji

@jdufresne
Copy link
ContributorAuthor

Thanks for the review! I've followed the linked example by dropping the argument and using the shim.

@javiereguiluz
Copy link
Member

I'm divided about this proposal. Theprefix is needed because this method returns an absolute path to a file, so it's not trivial to prefix only the file name.

But, adding a suffix should always be simple because it's safe to append a string to the value returned by this function. So, I'd probably close this as "won't fix".

However, another option would be to change the current "prefix" option to be a "pattern" option with only one placeholder called{filename}, so you can do this:

// Before$fs->tempnam('/tmp','prefix_');$fs->tempnam('/tmp','prefix_','.png');// After$fs->tempnam('/tmp','prefix_{filename}');$fs->tempnam('/tmp','prefix_{filename}.png');

@pierredup
Copy link
Contributor

The prefix is needed because this method returns an absolute path to a file, so it's not trivial to prefix only the file name.

The prefix is actually a required parameter in the nativetempnam function which this method uses, so it's not just about the path.

adding a suffix should always be simple because it's safe to append a string to the value returned by this function

The problem here is that you will then manually need to create the file and remove the original file (as the method creates the file as well and doesn't just return a path).

So going from

$file = $fs->tempnam('/tmp', 'prefix_', '.png');

to this

$file = $fs->tempnam('/tmp', 'prefix_');$fs->remove($file); // remove created file$file .= '.png';$fs->touch($file); // create new file

@javiereguiluz
Copy link
Member

@pierredup you explained it well. I think I'm now a bit more 👍 about this proposal.

@jdufresne
Copy link
ContributorAuthor

I've made the suggested change from@stof and dropped the deprecation warning so thatDebugClassLoader handles it.

@jdufresne
Copy link
ContributorAuthor

Thanks. I understand now. I have applied the suggested patch in the latest revision.

@jdufresne
Copy link
ContributorAuthor

fabbot is suggesting that I should remove$suffix from the docblock. Is this expected? Should I remove it? Or should I alter it a specific way to appease the bot?

@OskarStark
Copy link
Contributor

Should I remove it? Or should I alter it a specific way to appease the bot?

I would say its a false/positive

@jdufresne
Copy link
ContributorAuthor

Thanks. At this stage is there anything I should do to move this PR forward?

@fabpotfabpot changed the base branch from4.4 tomasterFebruary 4, 2020 08:10
@fabpot
Copy link
Member

Thank you@jdufresne.

@fabpotfabpot merged commitef12069 intosymfony:masterFeb 4, 2020
@nicolas-grekasnicolas-grekas modified the milestones:next,5.1May 4, 2020
@fabpotfabpot mentioned this pull requestMay 5, 2020
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@stofstofstof left review comments

@pierreduppierreduppierredup requested changes

@derrabusderrabusderrabus requested changes

@ycerutoycerutoyceruto requested changes

@fabpotfabpotfabpot approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
5.1
Development

Successfully merging this pull request may close these issues.

10 participants
@jdufresne@derrabus@yceruto@javiereguiluz@pierredup@OskarStark@fabpot@stof@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp