Changeset 3321 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-builder.php
- Timestamp:
- 06/09/2016 04:37:58 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-builder.php
r3291 r3321 58 58 public function build() { 59 59 try { 60 // The name must have at least 1 `.` in it for CLI `zip` not to complain. 61 $this->tmp_build_file = tempnam( dirname( $this->zip_file ), "tmp-{$this->slug}.{$this->version}" ); 60 $this->tmp_build_file = $this->generate_temporary_filename( dirname( $this->zip_file ), "tmp-{$this->slug}.{$this->version}", '.zip' ); 62 61 $this->tmp_build_dir = $this->tmp_build_file . '-files'; 63 62 mkdir( $this->tmp_build_dir, 0777, true ); … … 78 77 $this->cleanup(); 79 78 }*/ 79 } 80 81 /** 82 * Generates a temporary unique file in a given directory 83 * 84 * Performs a similar job to `tempnam()` with an added suffix and doesn't 85 * cut off the $prefix at 60 characters. 86 * As with `tempnam()` the caller is responsible for removing the temorarily file. 87 * 88 * Note: `strlen( $prefix . $suffix )` shouldn't exceed 238 characters. 89 * 90 * @param string $dir The directory to create the file in. 91 * @param string $prefix The file prefix. 92 * @param string $suffix The file suffix, optional. 93 * 94 * @return string Filename of unique temporary file. 95 */ 96 protected function generate_temporary_filename( $dir, $prefix, $suffix = '' ) { 97 $i = 0; 98 do { 99 $rand = uniqid(); 100 $filename = "{$dir}/{$prefix}-{$rand}{$i}{$suffix}"; 101 } while ( false === ($fp = @fopen( $filename, 'x' ) ) && $i++ < 50 ); 102 103 if ( $i >= 50 ) { 104 throw new Exception( __METHOD__ . ': Could not find unique filename.' ); 105 } 106 107 fclose( $fp ); 108 109 return $filename; 80 110 } 81 111
Note: See TracChangeset
for help on using the changeset viewer.