Skip to content

Fix filename uniqueness when using TempfileTask#1917

Merged
mrook merged 57 commits into
phingofficial:mainfrom
jawira:fix-tempfile
Jun 6, 2025
Merged

Fix filename uniqueness when using TempfileTask#1917
mrook merged 57 commits into
phingofficial:mainfrom
jawira:fix-tempfile

Conversation

@jawira
Copy link
Copy Markdown
Contributor

@jawira jawira commented Apr 24, 2025

I have noticed that filenames generate by TempfileTask are not unique when they are called multiple times at high frequency.

For example, given the following target:

<target name="tempfiles">
  <tempfile property="file1"/>
  <tempfile property="file2"/>
  <tempfile property="file3"/>
  <tempfile property="file4"/>
  <tempfile property="file5"/>
  <tempfile property="file6"/>
  <tempfile property="file7"/>
  <tempfile property="file8"/>
  <echo>${file1}</echo>
  <echo>${file2}</echo>
  <echo>${file3}</echo>
  <echo>${file4}</echo>
  <echo>${file5}</echo>
  <echo>${file6}</echo>
  <echo>${file7}</echo>
  <echo>${file8}</echo>
</target>

This is going to be the output:

$ phing tempfiles
Buildfile: /home/jawira/PhpstormProjects/dummy/build.xml

Phing Cookbook > tempfiles:

     [echo] /home/jawira/PhpstormProjects/dummy/1107b2f8
     [echo] /home/jawira/PhpstormProjects/dummy/1107b2f8
     [echo] /home/jawira/PhpstormProjects/dummy/1107b2f8
     [echo] /home/jawira/PhpstormProjects/dummy/1107b2f8
     [echo] /home/jawira/PhpstormProjects/dummy/1107b2f8
     [echo] /home/jawira/PhpstormProjects/dummy/1107b2f8
     [echo] /home/jawira/PhpstormProjects/dummy/1107b2f8
     [echo] /home/jawira/PhpstormProjects/dummy/1107b2f8

BUILD FINISHED

Total time: 0.0428 seconds

As you can see all filenames are identical, the reason is that current implementation uses time() function as seed for filename generation, which only has second-level precision.

I fix this issue replacing time() with microtime().

jawira and others added 30 commits February 11, 2019 14:27
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 53.31%. Comparing base (0493a46) to head (ea49f9b).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/Phing/Io/FileUtils.php 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main    #1917   +/-   ##
=========================================
  Coverage     53.30%   53.31%           
  Complexity     9797     9797           
=========================================
  Files           495      495           
  Lines         24639    24639           
=========================================
+ Hits          13135    13136    +1     
+ Misses        11504    11503    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mrook mrook merged commit 205e390 into phingofficial:main Jun 6, 2025
26 of 31 checks passed
@jawira jawira deleted the fix-tempfile branch June 6, 2025 15:27
@mrook mrook added this to the 3.1.0 milestone Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants