Core/Platform: Why AbstractHandler handles only 100 times the same file name?

Hi all,

When attempting to save a complex obs through a handler that saves to disk (= that will leverage on AbstractHandler), it is possible to keep providing the same file name over and over again. The file saved on disk will be appended with a counter suffix:

  • image.jpeg
  • image_01.jpeg
  • image_02.jpeg
  • image_98.jpeg
  • image_99.jpeg

However it won’t go further than a 2-digit suffix:

// If the Obs does not exist, but the File does, append a two-digit
// count number to the filename and save it.
while (obs.getObsId() == null && outputfile.exists() && i < 100) { ...

… as confirmed by the i < 100 condition (and the comment).

(Q.) Why this behaviour, why not just ensure that some unique name will be generated for the file saved on disk?

If there is no good reason for this, we would be keen on seeing this go away as we have painfully hit a wall with this. One of our clients uses iPad to upload images through VDUI and, as it turns out, files generated out of the iPad’s camera app are always wired as ‘image.jpeg’. How unfortunate… We have fixed hastily VDUI so that it time stamps every file anyway, but the damage had to be endured for some time in production :smirk:

1 Like

This was just not implemented in the handler. So you will be the first to ensure that it actually happens. :slight_smile: You can use this method to get a random file name in a given folder:

Here is an example of where i take advantage of it in the xforms module:

1 Like

Note sure what you mean by that. IMHO it is implemented, with a 100 ceiling, and this implementation within AbstractHandler is used by various other handlers (such as by ImageHandler here for example, hence provoking the actual problem for real.) I will create a new ticket addressing this and report its ticket number here.

But before that TRUNK-4977 should be fixed because there is no workaround for that one, and it is also provoking problems (ghost files on disk, see the issue.)

Thanks for pointing me to this OpenmrsUtil helper method, we will use it when fixing the yet-to-be-created ticket.