Page MenuHomePhabricator

Clarify temp directory
Closed, ResolvedPublic

Description

Currently we have two ways of getting a temporary directory.

$wgTmpDirectory - used by Math and diffing-related code.

wfTempDir() used by lots of other things, mostly with tempnam()

I tend to prefer the latter (less config is good). Should maybe look at merging the two.


Version: unspecified
Severity: enhancement

Details

Reference
bz24985

Event Timeline

bzimport raised the priority of this task from to Low.Nov 21 2014, 11:09 PM
bzimport set Reference to bz24985.

Hmm, taking a quick look...

$wgTmpDirectory is initialized to "$wgUploadDirectory/tmp", which gives it two important properties:

  • it's in a writable place that's shared across requests
  • nobody else is going to mess with those files
  • it's probably on the same filesystem as our upload area
  • it may be exposed to the web

wfTempDir() is an abstraction to find the system-specific temporary directory (traditionally /tmp on Unixy systems). This has a few other properties:

  • files here might disappear when we're not looking (eg on reboot)
  • there may be lots of other files not under our control, but other users probably can't mess with our files as long as names are unique
  • less likely to be on same filesystem as our upload area

It looks like most code using $wgTmpDirectory doesn't actually need to keep the files around across requests or anything, though. (Math and URL uploading take advantage of being able to rename the output file atomically from the temp location to the final location, but it's probably not a performance-critical path and isn't guaranteed since the dir is renamable.)

Some things that it looks like *do* need/want to keep files across requests:

  • DBABagOStuff (cache implementation; meant for dev use)
  • .... I think that might be it.

Math and easytimeline also don't clean up their temp files very nicely, which is lazy.

(In reply to comment #1)

It looks like most code using $wgTmpDirectory doesn't actually need to keep the
files around across requests or anything, though. (Math and URL uploading take
advantage of being able to rename the output file atomically from the temp
location to the final location, but it's probably not a performance-critical
path and isn't guaranteed since the dir is renamable.)

UploadStash needs this (ability to keep temp files across requests and read them), although it uses the filerepo abstraction so I'm not sure if $wgTmpDirectory is used directly or if the repo uses $wgUploadDirectory/tmp regardless of what $wgTmpDirectory is. I think it's the latter, but it's been too long since I touched it.

Math and easytimeline also don't clean up their temp files very nicely, which
is lazy.

Neither does UploadStash, BTW. Maybe we should supply a cron job for this; we're gonna need it on the cluster for UploadStash anyway, once it's used more often.

Bryan.TongMinh wrote:

*** Bug 27959 has been marked as a duplicate of this bug. ***

Assigning bug to Mark since he is writing the patch :-D