making temporary files

Showing 1-13 of 13 messages
making temporary files Jason Proctor 10/3/08 3:02 PM
is there a good spot in the filesystem to park temporary files?

i notice from rummaging around that there is no /tmp on this Linux
box, and File.getTempFile() fails, with the error "can't create
/sdcard/$filename".

(and android error messages should be more informative in general, IMHO.)

Re: making temporary files Justin (Google Employee) 10/3/08 5:04 PM
You should put temporary files somewhere in /sdcard, as generally this
will have more available space than a device's internal storage. For
this to work you need to use emulator options to specify an sdcard
image that was created with the mksdcard utility.

You're getting the error you're getting because /sdcard doesn't exist
since you haven't specified an sdcard image file.

Cheers,
Justin
Android Team @ Google
[android-developers] Re: making temporary files Jason Proctor 10/3/08 5:12 PM
hi justin,

thanks for the response.

supposing i'm running on a real device and the user doesn't have an
SD card. then what?

thanks,
j

Re: making temporary files MrSnowflake 10/5/08 5:47 AM
The G1 from t-mobile will be delivered with a 1GB MicroSD, but when
it's not present you could make an error dialog which says you program
needs an SD card.
Re: making temporary files hackbod 10/6/08 12:15 AM
Well...  you can make a temp file wherever you want.  Depending on
what you want to do, either the SD card or your own internal data
directory would make sense.  The trade-offs are:

(1) The internal data directory is secure, so if you are putting ANY
private information (passwords, mail messages, chat data, etc) in the
temp file you should put it in internal storage.
(2) The SD card generally has a lot more storage available, so if you
are going to be writing multiple megabytes of data then the SD card is
a better choice.
(3) The SD card may not be available...  but in that state the camera
can't take pictures, etc, so it should be unlikely.
[android-developers] Re: making temporary files Jason Proctor 10/6/08 1:17 PM
thanks for the response.

IMHO the Android filesystem should have a /tmp directory, which is
used for temporary files when /sdcard isn't connected to anything. i
realise that Android is very much a bazaar rather than a cathedral,
but advising people to put temp files wherever they want is asking
for a big mess.

also IMHO, File.createTempFile() should *always* create a file which
is writable, regardless of underlying platform specifics such as a
lack of something connected to /sdcard. if no /sdcard, use /tmp. like
most other linuxen known to man.

tx
j


>Well...  you can make a temp file wherever you want.  Depending on
>what you want to do, either the SD card or your own internal data
>directory would make sense.  The trade-offs are:
>
>(1) The internal data directory is secure, so if you are putting ANY
>private information (passwords, mail messages, chat data, etc) in the
>temp file you should put it in internal storage.
>(2) The SD card generally has a lot more storage available, so if you
>are going to be writing multiple megabytes of data then the SD card is
>a better choice.
>(3) The SD card may not be available...  but in that state the camera
>can't take pictures, etc, so it should be unlikely.

Re: making temporary files hackbod 10/6/08 3:03 PM
No it shouldn't. :)

Temp directories suck.  When do you remove those files?  If it's on
the SD card, who owns them?  Especially with a limited out of storage
space, it's just a big nasty mess that is best to avoid.

So you can make your own temp files, and if you want them in internal
flash then you have to put them in your own directory, where the
system can appropriately bill them against your use of storage.  And
you can decide when to delete them, when you are done with them.
[android-developers] Re: making temporary files Jason Proctor 10/7/08 1:54 AM
oh yes it should :-)

ok so maybe the unconventional Android application lifecycle changes
the game a bit wrt temporary files, in the sense that "system
startup" (etc), with accompanying cleanup, doesn't happen that often.

but still, trusting those applications to keep track of their
temporary files is a bit naive, especially since application, er,
termination may happen unexpectedly. but then if Android has some way
of associating files with applications, via that unique
application/user ID thing (if i'm reading it right), then anything
created by File.createTempFile() could be deleted when the associated
process "exits".

and none of this changes the fact that File.createTempFile() should
create a writable temporary file whether or not an sdcard is inserted
or not. createTempFile() has some handy benefits including ensuring
uniqueness, be a shame to lose that. that's the deal with
createTempFile(), and bugging out breaks the contract.

if in doubt, have a convention. that way there will be at least a
little organisation in the chaos that will be Android.

tx


>No it shouldn't. :)
>
>Temp directories suck.  When do you remove those files?  If it's on
>the SD card, who owns them?  Especially with a limited out of storage
>space, it's just a big nasty mess that is best to avoid.
>
>So you can make your own temp files, and if you want them in internal
>flash then you have to put them in your own directory, where the
>system can appropriately bill them against your use of storage.  And
>you can decide when to delete them, when you are done with them.

Re: [android-developers] making temporary files Tom Gibara 10/7/08 2:14 AM
I have to disagree with your disagreeing :)

There are two fairly common and well defined situations:


Situation: You need a temp file to do some processing that won't necessarily fit into memory.

Solution: Create the file, use it, delete it when you're done*

Caveat: The file may be exceptionally large: demand an SDCard. The file contains sensitive information: use app storage.


Situation: You are operating a cache.

Solution: maintain the files in the supplied cache directory (Context.getCacheDir()), the system knows these can be deleted**

Caveat: Big ticket items (like songs and videos) go to the sdcard (the user can treat these types as useful files anyway)


How does the availability of createTempFile() effect any solution in these two cases?

* Concerned about termination? Persist the name of your temporary file before starting work, clear it when you're done, check for it on start-up and delete it if present.

** I'm only assuming this is what the system will do.

Tom

2008/10/7 Jason Proctor <ja...@redfish.net>

Re: making temporary files hackbod 10/7/08 10:10 AM
You can just as well do those things yourself without
createTempFile().  I am strongly against createTempFile() because it
has no idea what you are doing with your file, how long to keep it
around, who you might share it with, etc.  Note that the API doesn't
even meet the requirements you are giving, where you store the file
either on the SD card or internal storage based on what you are doing
with it.
Re: [android-developers] Re: making temporary files Tom Gibara 10/7/08 2:07 PM
Was that reply aimed at me? I was in agreement!

I've seen several server apps collapse through abuse of createTempFile(). The semantics are weak: almost to the point of being dangerous :)

Tom.

2008/10/7 hackbod <hac...@gmail.com>

Re: making temporary files hackbod 10/7/08 3:18 PM
Whoops!  Sorry, yeah it was incorrectly aimed at you, I thought you
were disagreeing with me. :)

On Oct 7, 2:07 pm, "Tom Gibara" <m...@tomgibara.com> wrote:
> Was that reply aimed at me? I was in agreement!
> I've seen several server apps collapse through abuse of createTempFile().
> The semantics are weak: almost to the point of being dangerous :)
>
> Tom.
>
> 2008/10/7 hackbod <hack...@gmail.com>
[android-developers] Re: making temporary files Jason Proctor 10/9/08 11:34 PM
OK i basically give in on the temporary file issue.

i still think it's idealistic to expect applications to clean up
their old temporary files *on startup*, but i'll admit that, as
usual, developer discipline is the best solution to the temporary
file, if not *any*, issue!

on the subject of File.createTempFile(), i still think that the
android implementation should pass back something suitable in the
event that /sdcard isn't connected to anything. that's the contract
with java.io.File, and it shouldn't be broken.

so there ;-)

>Was that reply aimed at me? I was in agreement!
>
>I've seen several server apps collapse through abuse of
>createTempFile(). The semantics are weak: almost to the point of
>being dangerous :)
>
>Tom.