Problem/Motivation

When a stream wrapper path (e.g. private://some-path, temporary://some-path, etc) is passed as the $directory parameter to
FileSystem::tempnam() (or drupal_tempnam() in D7), the unique filename returned is always in the root path of the file system represented by the stream wrapper without any of the subdirectory paths included in the $directory parameter.

Steps to reproduce

Create a filename for stream wrapper path using FileSystem::tempnam():

// Create a filename in '/tmp/some-path'.
$filename = \Drupal::service('file_system')->tempnam('temporary://some-path', 'prefix_');

Expected $filename value: /tmp/some-path/prefix_random-filename
Actual $filename value: /tmp/prefix_random-filename

Proposed resolution

Modify FileSystem::tempnam() to return a filename that includes any subdirectories passed as part of $directory parameter containing stream wrapper paths.

Remaining tasks

Review submited patches.

User interface changes

None.

API changes

Currently if stream wrapper path including a non-existant / invalid subdirectory (e.g. private://non-existant-path) is passed as the $directory parameter to FileSystem::tempnam() a valid filename in the root path for the stream wrapper will be returned. After the proposed changes, FileSystem::tempname() will return FALSE when a stream wrapper path containing invalid subdirectories is used.

Data model changes

None.

Original report by Steven Jones

I was trying to do this:

// Create a file in '/tmp/some-path'.
$file = drupal_tempnam('temporary://some-path', 'prefix');

But the returned filename will always reside in the base directory of the 'temporary' wrapper, because the implementation of drupal_tempnam uses the wrappers getDirectoryPath method, which basically returns the root of the filesystem represented by the wrapper.

Is this on purpose? Or a bug that needs fixing?
If the former, the docs need changing.

CommentFileSizeAuthor
#76 985384-nr-bot.txt168 bytesneeds-review-queue-bot
#69 drupal-drupal_tempnam-985384-69-D9.patch7.17 KBliam morland
#68 drupal-drupal_tempnam-985384-68-D9.patch7.17 KBliam morland
#62 drupal-drupal_tempnam-985384-62-D8.patch7.17 KBliam morland
#60 drupal-drupal_tempnam-985384-60-D8.patch7.15 KBliam morland
#57 drupal-drupal_tempnam-985384-57-D8.patch7.13 KBliam morland
#54 drupal-drupal_tempnam-985384-54-D8.patch7.1 KBliam morland
#52 drupal-drupal_tempnam-985384-52-D8.patch7.08 KBliam morland
#49 drupal-drupal_tempnam-985384-49-D8.patch7.01 KBliam morland
#48 drupal-drupal_tempnam-985384-48-D7.patch2.42 KBliam morland
#43 drupal-7.x-drupal_tempnam-985384-43.patch2.96 KBludo.r
#40 drupal-fix-file-system-tempnam-985384-40-D8.patch7.06 KBAnonymous (not verified)
#40 interdiff-985384-37-40.txt1.86 KBAnonymous (not verified)
#37 drupal-fix-file-system-tempnam-985384-37-D8.patch7.06 KBAnonymous (not verified)
#37 interdiff-985384-36-37.txt1.11 KBAnonymous (not verified)
#2 drupal-drupal_tempnam-985384.patch1.68 KBsteven jones
#3 drupal-drupal_tempnam-985384_with_tests.patch3.37 KBsteven jones
#6 drupal-drupal_tempnam-985384_with_tests.patch2.93 KBsteven jones
#7 drupal-drupal_tempnam-985384_with_tests.patch3.45 KBsteven jones
#8 drupal-drupal_tempnam-985384_with_tests.patch3.45 KBsteven jones
#11 drupal-drupal_tempnam-985384-11.patch3.13 KBmfernea
#13 drupal-drupal_tempnam-985384-13_with_tests.patch2.58 KBloopduplicate
#14 interdiff-985384-8-13.txt3.62 KBloopduplicate
#14 interdiff-985384-11-13.txt1.91 KBloopduplicate
#19 drupal-drupal_tempnam-985384-19_with_tests.patch2.58 KBloopduplicate
#19 interdiff-985384-13-19.txt464 bytesloopduplicate
#24 drupal-tempnam-doesnt-respect-subdirectories-for-stream-wrappers-985384-24.patch887 bytesmmrares
#27 interdiff-985384-24-27.txt1.48 KBloopduplicate
#27 drupal-tempnam-doesnt-respect-subdirectories-for-stream-wrappers-985384-27-test-only.patch1.48 KBloopduplicate
#27 drupal-tempnam-doesnt-respect-subdirectories-for-stream-wrappers-985384-27.patch2.34 KBloopduplicate
#30 interdiff-27-30.txt3.68 KBAnonymous (not verified)
#30 drupal-fix-file-system-tempnam-985384-30-D8.patch3.5 KBAnonymous (not verified)
#33 interdiff-985384-30-33.txt1.25 KBAnonymous (not verified)
#33 drupal-fix-file-system-tempnam-985384-33-D8.patch4.75 KBAnonymous (not verified)
#36 interdiff-985384-33-36--testonly.txt3.8 KBAnonymous (not verified)
#36 interdiff-985384-33-36.txt6.59 KBAnonymous (not verified)
#36 drupal-fix-file-system-tempnam-985384-36-D8--testonly.patch3.32 KBAnonymous (not verified)
#36 drupal-fix-file-system-tempnam-985384-36-D8.patch7.03 KBAnonymous (not verified)

Issue fork drupal-985384

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

steven jones’s picture

Title: drupal_tempnam can't create files in subdirectories » drupal_tempnam doesn't respect subdirectories for stream wrappers

So it gets a little messy if you start trying to work out the actual directory created by drupal_realpath() for temp directories, because if the directory doesn't exist, then you just end up with strange results.

But, this function otherwise (with an actual path) has different behaviour, and is not a drop in replacement for tempnam.

Maybe something like:

function drupal_tempnam($directory, $prefix) {
  $scheme = file_uri_scheme($directory);

  if ($scheme && file_stream_wrapper_valid_scheme($scheme)) {

    if ($filename = tempnam(drupal_realpath($wrapper), $prefix)) {
      return $scheme .'://' . file_uri_target($directory) . '/' . basename($filename);
    }
    else {
      return FALSE;
    }
  }
  else {
    // Handle as a normal tempnam() call.
    return tempnam($directory, $prefix);
  }
}

Would 'fix' the issue?

steven jones’s picture

Status: Active » Needs work
StatusFileSize
new1.68 KB

Patch attached, that should address the issue I think, of course there are no tests in core for this. So these will need writing.

steven jones’s picture

Status: Needs work » Needs review
StatusFileSize
new3.37 KB

Above patch, re-rolled for HEAD, and with tests.

damien tournoud’s picture

Good catch, but this feels a little messy:

   if ($scheme && file_stream_wrapper_valid_scheme($scheme)) {
-    $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);
+    $local_directory = drupal_realpath($directory);
 
-    if ($filename = tempnam($wrapper->getDirectoryPath(), $prefix)) {
-      return $scheme . '://' . basename($filename);
+    if ($filename = tempnam(drupal_realpath($directory), $prefix)) {
+      // If the specified directory doesn't exist then PHP's tempname may return
+      // a file in the system temporary directory, but then we can't assume that
+      // we can just use the same name in our returned URI, so we return failure
+      // in this case.
+      if (dirname($filename) != $local_directory) {
+        return FALSE;
+      }
+      else {
+        $uri = $scheme .'://' . file_uri_target($directory) . '/' . basename($filename);
+        return file_stream_wrapper_uri_normalize($uri);
+      }
     }
     else {
       return FALSE;

I think we just want:

$local_directory = drupal_realpath($directory);
if (is_writable($local_directory) && ($filename = tempnam($local_directory, $prefix))) {
  return $directory . '/' . basename($filename);
}
damien tournoud’s picture

Status: Needs review » Needs work
steven jones’s picture

Status: Needs work » Needs review
StatusFileSize
new2.93 KB

Something like the attached then.

steven jones’s picture

Scrap that last patch, needed a file_stream_wrapper_uri_normalize() also. Added a test for that case too.

steven jones’s picture

Screwed that patch up.

dawehner’s picture

Issue summary: View changes

Sounds like a bug we have in D8 as well, see #2304461: KernelTestBaseTNG™

chalk’s picture

Bug is still reproduced in latest DEV version of Drupal 7.
Patch is a little bit incorrect (2 'returns' after applying), but it works.

mfernea’s picture

StatusFileSize
new3.13 KB

It works for us. I rerolled the patch.

Status: Needs review » Needs work

The last submitted patch, 11: drupal-drupal_tempnam-985384-11.patch, failed testing.

loopduplicate’s picture

Here's a reroll. I couldn't do an interdiff between this and #8 because it appears that the patch file in #8 is corrupt (Edit: because I wasn't used to the patch format. I added interdiffs in #14)

#11 doesn't use file_stream_wrapper_uri_normalize().

loopduplicate’s picture

StatusFileSize
new3.62 KB
new1.91 KB

Here's interdiffs for 8-13 and 11-13

loopduplicate’s picture

Status: Needs work » Needs review

Marking as needs review.

loopduplicate’s picture

I left the PHP doc blocks alone and didn't rename the test class. The new patch is very simple and focuses only on the task at hand. If doc blocks need updating and/or the test class needs to be renamed, I think those should be separate issues. Anyway, that's a minor thing.

Status: Needs review » Needs work

The last submitted patch, 13: drupal-drupal_tempnam-985384-13_with_tests.patch, failed testing.

loopduplicate’s picture

Status: Needs work » Needs review

Based on the test results from #13, it looks like the testbot had a malfunction. Re-marking as needs review and re-queueing test.

loopduplicate’s picture

+++ b/modules/simpletest/tests/file.test
@@ -2766,4 +2766,24 @@ function testGetValidStreamScheme() {
+

Argh, I added an extra line on accident. Updating patch.

oadaeh’s picture

Status: Needs review » Reviewed & tested by the community

The patch in #19 looks good, applies cleanly, and executes the desired behavior.

kristen pol’s picture

RTBC++ that the patch is working for us. Thanks.

stefan.r’s picture

Version: 7.x-dev » 8.3.x-dev
Status: Reviewed & tested by the community » Active

Don't we have this issue in Drupal 8 as well? See FileSystem::tempnam()

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mmrares’s picture

I've created a port of the patch for Drupal 8.

mfernea’s picture

Status: Active » Needs review

Updated the status for tests.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

loopduplicate’s picture

Anonymous’s picture

Status: Needs review » Needs work

To properly fix FileSystem::tempnam(), the code needs to be able to run on operating systems that use SystemD with a PrivateTmp=true, like recent RHEL/CentOS v7+.

Even if you delete the `path.temporary` value from `system.file` config, the default temporary directory resolved by `TemporaryStream` wrapper class points to the global /tmp directory, instead of the private, per service directory like:

/tmp/systemd-private-0683739bc66749bf9f29f4cb63248ba5-httpd.service-MztTot/tmp

EDIT 1: From what I can tell, in the context of a web service running on a SystemD powered systems, the `sys_get_temp_dir()` function should work just fine, and the path should be transparently resolved to the private directory, but this doesn't seem to be the case and the `is_writable()` call from FileSystem::tempnam() fails, because it tries to check the main OS temporary directory.

EDIT 2: It looks like tempnam($local_directory, $prefix) is able to create a file in the proper location, e.g.:

/tmp/systemd-private-0683739bc66749bf9f29f4cb63248ba5-httpd.service-MztTot/tmp/MY-PREFIX-M8RNNm

But the call to is_writable($local_directory) returns FALSE.

EDIT 3: Nevermind, looks like the destination directory for tempnam() needs to exist before calling it, otherwise:

If the directory does not exist or is not writable, tempnam() may generate a file in the system's temporary directory, and return the full path to that file, including its name.

http://php.net/manual/en/function.tempnam.php

Anonymous’s picture

Here's my attempt at this. I've updated the FileSystem::tempnam() method to behave like the PHP function and fallback to using the temporary directory, although I'm not sure if I should use the temporary:// prefix, since the fallback directory can be different from the directory resolved from temporary://.

I've also added an extra test for this case.

Anonymous’s picture

Title: drupal_tempnam doesn't respect subdirectories for stream wrappers » FileSystem::tempnam() doesn't respect subdirectories for stream wrappers
miroslavbanov’s picture

If the directory does not exist or is not writable, tempnam() may generate a file in the system's temporary directory, and return the full path to that file, including its name.

I guess this behavior is documented in php.net, but not documented in Drupal. But the behavior is so confusing, it might be a good idea to document it here. It is after all a reasonable assumption, to expect that the path is not changed.

Anonymous’s picture

Status: Needs work » Needs review
StatusFileSize
new1.25 KB
new4.75 KB

Please let me know what you think of the documentation changes.

Could you please comment on this line? Think that it might be wrong and I'm not exactly sure how this should be handled. Should we diverge from PHP's tempnam() function behavior or how should we handle it's fallback case? The system temp directory used as fallback must not be equivalent to this URI here.

    // NOTE: tempnam() can ignore the $realpath and use the system temp directory.
    return $scheme . '://' . $this->basename($temp_file_path);

How can we convert it to a proper scheme? Should we just fail if it isn't in the same scheme?

Status: Needs review » Needs work

The last submitted patch, 33: drupal-fix-file-system-tempnam-985384-33-D8.patch, failed testing. View results

miroslavbanov’s picture

On doc change, it is better than before, but it might use @link definition. Also I think it could make clear that this function can return 3 different things, and that's the behavior of php tempnam(). I mean - it is written already, but it could be written in a way that's very hard to miss.

---

Is it correct to keep the php tempnam() behavior, or can we have something better? I think it doesn't need to keep to php tempnam(), but it's already in use, so now is a different matter.

---

    // NOTE: tempnam() can ignore the $realpath and use the system temp directory.
    return $scheme . '://' . $this->basename($temp_file_path);
How can we convert it to a proper scheme? Should we just fail if it isn't in the same scheme?

We can't be sure there even is a proper scheme. This may work:

if ($this->realpath('temporary://') === sys_get_temp_dir()) {
  $scheme = 'temporary';
}

Other things we can do is 1. return FALSE or 2. return $temp_file_path despite it not containing a scheme.

Anonymous’s picture

About that @link definition, I'm not sure what you want to link to and from where? Maybe you want me to link to the `tempnam()` docs page instead of just @see tempnam()?

I think the method should only return the fallback temporary file only when the requested directory is on the temporary stream wrapper. Otherwise, you return a different stream wrapper and this can get you into problems.

I've also normalized the returned stream wrapper and added a test for the temporary stream wrapper to deal with the differences.

But I think that we should have a consistent behavior in a different method and just deprecate FileSystem::tempnam().

Anonymous’s picture

Status: Needs work » Needs review
StatusFileSize
new1.11 KB
new7.06 KB

Fixed test.

Status: Needs review » Needs work

The last submitted patch, 37: drupal-fix-file-system-tempnam-985384-37-D8.patch, failed testing. View results

miroslavbanov’s picture

I think it is pretty good already. At the very least, much more sensible then what was before. I will try to find time to review and test this - maybe this weekend.

Edit1:
The last failing test may produce different results on different environments. I mean this:
$this->assertNotEquals($temporary_scheme . '://', $file_system->dirname($tempnam), 'Temporary file was created in the root of the temporary stream wrapper.');

in fact the two strings will be equal if sys_get_temp_dir() === $file_system->realpath('temporary://')

Edit2:
Actually from looking at the test, maybe you meant to do assertEquals.

Anonymous’s picture

Status: Needs work » Needs review
StatusFileSize
new1.86 KB
new7.06 KB

Yes, that should be it. Thanks.

Sorry for the test flip-flops, I currently don't have a setup to run them.

Anonymous’s picture

Issue tags: -Drupalaton 2017

Does this count as breaking change or not? Should it go into D9 or D8.6/8.5?

After this patch, there is a case when the method doesn't create a temporary file where it used to.

Maybe this change"should be added back as a "deprecated" feature that is behind a flag (controllable via an extra parameter).

miroslavbanov’s picture

About #41

Does this count as breaking change or not? Should it go into D9 or D8.6/8.5?

After this patch, there is a case when the method doesn't create a temporary file where it used to.

Maybe this change"should be added back as a "deprecated" feature that is behind a flag (controllable via an extra parameter)

That temporary file's path wasn't returned correctly so it was never useful as far as I know. But this will surely be reviewed by others, so we'll know if the method can't be changed. If we end up deprecating things, the whole method should be deprecated, and a better new one should be created in my opinion.

ludo.r’s picture

StatusFileSize
new2.96 KB

This patch is a re-roll from #11 against Drupal core 7.65

Status: Needs review » Needs work

The last submitted patch, 43: drupal-7.x-drupal_tempnam-985384-43.patch, failed testing. View results

vinmassaro’s picture

Can someone explain how the D7 patch is supposed to work?

It seems that the patch in #43 still doesn't return subdirectories because they are not being added in any way, and drupal_basename() is going to always only return a filename. I came here from #2402663: Excel and CSV export randomly empty since webform uses drupal_tempnam() and isn't returning the expected path when sending subdirectories to drupal_tempnam(). Here is a simple code sample I am using with devel that shows the subdirectory is not returned from drupal_tempnam() after applying this patch:

// webform_export_path set to private://tmp/webform_results in settings.php
$webform_export_path = variable_get('webform_export_path', 'temporary://');
dpm($webform_export_path);  // prints private://tmp/webform_results
dpm(drupal_tempnam($webform_export_path, 'webform_')); // prints private://webform_zlXpNF

Thanks.

steven jones’s picture

@vinmassaro does that temporary directory exist on disk already? drupal_tempnam won't make new directories afaik, but should make files within those directories with the patch in #43.

As for how does the patch work:

+++ b/includes/file.inc
@@ -2544,9 +2545,9 @@ function drupal_tempnam($directory, $prefix) {
-    $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);
+    $local_directory = drupal_realpath($directory);
 
-    if ($filename = tempnam($wrapper->getDirectoryPath(), $prefix)) {
+    if (is_writable($local_directory) && ($filename = tempnam($local_directory, $prefix))) {

This is the crux of the patch.

$wrapper->getDirectoryPath() would always return the root path of the configured stream wrapper, but now we convert it to a local directory using drupal_realpath this directory is then hopefully writeable, and since it's a local directory, the call to tempnam should work.

Note that PHP reserves the right to generate and return a temporary file the system's temporary directory as per the docs on tempnam https://php.net/manual/en/function.tempnam.php.

steven jones’s picture

Issue tags: +Needs issue summary update, +Needs reroll

@vinmassaro so sorry, you are totally right. The patch in #11 was an incorrect re-roll. The patch in #13 has the correct code, and probably needs a re-roll for Drupal 7.

@SchnWalter I don't think this is a 'breaking change' since callers ask for a URI to a temporary file, and we still return one, just one that's more in-line with what they want really. But happy to take a steer from the Drupal 8 maintainers.

liam morland’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new2.42 KB

This is a re-roll of #13.

liam morland’s picture

Version: 8.6.x-dev » 8.8.x-dev
StatusFileSize
new7.01 KB

This is a re-roll of #40.

The last submitted patch, 43: drupal-7.x-drupal_tempnam-985384-43.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 49: drupal-drupal_tempnam-985384-49-D8.patch, failed testing. View results

liam morland’s picture

Status: Needs work » Needs review
StatusFileSize
new7.08 KB

Patch #49 with deprecated file_stream_wrapper_uri_normalize() replaced.

Status: Needs review » Needs work

The last submitted patch, 52: drupal-drupal_tempnam-985384-52-D8.patch, failed testing. View results

liam morland’s picture

Status: Needs work » Needs review
StatusFileSize
new7.1 KB

Patch #52 with deprecated FileSystem::validScheme() replaced.

liam morland’s picture

Status: Needs review » Needs work

The last submitted patch, 54: drupal-drupal_tempnam-985384-54-D8.patch, failed testing. View results

liam morland’s picture

Status: Needs work » Needs review
StatusFileSize
new7.13 KB

Patch #54 with deprecated file_default_scheme() replaced.

Status: Needs review » Needs work

The last submitted patch, 57: drupal-drupal_tempnam-985384-57-D8.patch, failed testing. View results

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

liam morland’s picture

Status: Needs work » Needs review
StatusFileSize
new7.15 KB

Re-roll.

Status: Needs review » Needs work

The last submitted patch, 60: drupal-drupal_tempnam-985384-60-D8.patch, failed testing. View results

liam morland’s picture

Status: Needs work » Needs review
StatusFileSize
new7.17 KB

Deprecations fixed.

Status: Needs review » Needs work

The last submitted patch, 62: drupal-drupal_tempnam-985384-62-D8.patch, failed testing. View results

liam morland’s picture

Status: Needs work » Needs review
liam morland’s picture

Is a version of this for 9.0.x required?

renguer0’s picture

Last patch is working on 8.8.5, I really don't understand why it isn't added to core.

Thanks for all you people that are contributing to this, specially to @Liam Morland that keeps that alive from last year.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

liam morland’s picture

StatusFileSize
new7.17 KB

Re-roll for 9.1.x.

liam morland’s picture

StatusFileSize
new7.17 KB

Re-roll.

joegraduate’s picture

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new168 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kim.pepper made their first commit to this issue’s fork.

kim.pepper’s picture

Created a MR from the patch in #69 and hid patch files.

kim.pepper’s picture

Left some feedback. NW for that and coding standard issue.

liam morland’s picture

Status: Needs work » Needs review

Addressed feedback and coding standards.

kim.pepper’s picture

Status: Needs review » Needs work

Confirmed the test-only job correctly failed with:

Drupal\KernelTests\Core\File\StreamWrapperTest::testTempnam
Temporary file was created in the default stream wrapper subdirectory
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'public://vxdio1mu'
+'public://'

core/tests/Drupal/KernelTests/Core/File/StreamWrapperTest.php:174

NW for the test location.

liam morland’s picture

Status: Needs work » Needs review

The test cannot easily be moved because it uses ::createDirectory(), which is not available in any of FileSystem*Test.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

smustgrave made their first commit to this issue’s fork.

mohit_aghera made their first commit to this issue’s fork.

mohit_aghera’s picture

Looking good to me.
MR is updated with latest main branch and is green.
I reviewed the changes and all the feedback seems addressed.

I reviewed the comment https://git.drupalcode.org/project/drupal/-/merge_requests/11681#note_48... related to moving class to `FileSystem*Test`
For testing, I tried to move test to `FileSystemTempDirectoryTest` and extended that class from `FileTestBase`
The test worked fine.
Although I am not quite sure whether we should move it to `FileSystemTempDirectoryTest` because based on name it seems like it is restricted to TempDirectoryTest.

Happy to update based on inputs from folks.
I'm keeping this in needs review for now.

Otherwise, all good from me.

kim.pepper’s picture

Status: Needs review » Reviewed & tested by the community

Did another review and everything looks good. I'm happy not to move FileSystemTempDirectoryTest.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Nice old issue - I think we need to use Drupal's FileSystemComponent::getOsTemporaryDirectory(); rather than sys_get_temp_dir() - especially if you look at \Drupal\Core\StreamWrapper\TemporaryStream

... or maybe we should be using $this->getTempDirectory()

alexpott’s picture

Issue tags: -Needs backport to D7