This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-06-29 11:05:43

fetta
New Scratcher
Registered: 2010-06-29
Posts: 1

Sequentially named temporary files saved to network drives

Scratch appears to save temporary files to the same location where the persistent save is directed.  Additionally, it uses a sequential naming scheme -- "tmp0", "tmp1", etc.  This appears to cause problems when the students attempt to save to the same network folder.  Things are being overwritten in some cases.  Other times hangups occur probably due to write access.  Has anyone else run into this issue?

Many other programs will store temporary files locally.  It's also not uncommon for other programs to use a random naming scheme for temporary files -- there's even functions that create file names for you.  Making either of these changes would likely fix the problem.

If this can't be fixed, does anyone have any suggestions to deal with this problem?  One work around is to save locally, then later copy to the network drive.  If edits have to be made later though, the network copy would have to be copied down, and opened locally.  This is quite a cumbersome procedure for young students.

-Chad

Offline

 

#2 2010-06-30 12:25:09

mbates
New Scratcher
Registered: 2010-06-30
Posts: 1

Re: Sequentially named temporary files saved to network drives

We have the same issue in our school. Kids come to the lab, log in to a shared network account, and end up losing their work when their saves interfere. Please advise...thank you,

-- MB

Offline

 

#3 2010-06-30 14:35:33

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: Sequentially named temporary files saved to network drives

I think sometimes, the scratch temporary files are saved to "scratchthumbs.db".

I'm pretty sure when you save a project, the tmp0/tmp1 gets compiled into Scratch Thumbs...
hmm


Hai.

Offline

 

#4 2010-07-13 21:53:21

captainobvious
New Scratcher
Registered: 2010-07-13
Posts: 2

Re: Sequentially named temporary files saved to network drives

I wrote a patch that incorporates fetta's advice to use a random naming scheme for tmp files. The change is in the method System-Files,FileDirectory>>unusedNameStartingWith: (from the Scratch 1.4 source code).

Original code:

Code:

unusedNameStartingWith: prefix
    "Answer an unused file or directory name in this directory starting with the given prefix and ending with one or more digits."
    "FileDirectory default unusedNameStartingWith: 'tmp'"

    | usedNames i result |
    usedNames _ self fileAndDirectoryNames asSet.
    i _ 0.
    result _ prefix, '0'.
    [usedNames includes: result] whileTrue: [
        result _ prefix, (i _ i + 1) printString].
    ^ pathName, self slash, result

Modified code:

Code:

unusedNameStartingWith: prefix
    "Answer an unused file or directory name in this directory starting with the given prefix and ending with one to six random digits."
    "FileDirectory default unusedNameStartingWith: 'tmp'"

    | usedNames result |
    usedNames _ self fileAndDirectoryNames asSet.
    [usedNames includes: (result _ prefix, (1000000 atRandom - 1) printString)] whileTrue: [].
    ^ pathName, self slash, result

The first (unmodified) version will try tmp0, then tmp1 if that fails, etc. The second version will try tmp299266, tmp668132, etc. where the suffix is a random from 1 to 999999.

Regarding what fg123 said, on my computer Scratch does not make any temporary files except for tmp0, tmp1, etc. when saving.

Offline

 

#5 2010-07-14 10:18:57

Lightnin
Scratch Team
Registered: 2008-11-03
Posts: 1000+

Re: Sequentially named temporary files saved to network drives

fg123 wrote:

I think sometimes, the scratch temporary files are saved to "scratchthumbs.db".

I'm pretty sure when you save a project, the tmp0/tmp1 gets compiled into Scratch Thumbs...
hmm

Nope, actually - that's just a file that contains thumbnail versions of any image that is in the folder. Scratch makes it whenever it encounters a folder with images. That way the next time the user browses to that folder, the image thumbnails will be ready (and they won't have to wait for Scratch to generate them).


Help Scratchers make the leap to 2.0!
http://img818.imageshack.us/img818/6844/transitionteam.jpg

Offline

 

#6 2010-07-15 08:00:40

johnm
Scratcher
Registered: 2007-03-08
Posts: 100+

Re: Sequentially named temporary files saved to network drives

Kudos to Fetta for figuring out this problem.

When Scratch saves a project, it writes it to a temporary file to avoid writing over the previous version, which could leave a broken project if the write failed partway through. After the project has been completely written to the temporary file, Scratch deletes the old project file and renames the temporary file. When choosing a temporary file name, it tries to avoid using a temporary file name that already exists. However, in a distributed system, this creates a race condition: two instances of Scratch might both read the directory and choose the same unused temporary file name at the same time. If Windows handles caches remote directories, this problem is more likely (larger time window, so greater chance of two writers choosing the same temporary name).

The fix posted by captainobvious is excellent. It doesn't remove the inherent race condition, but it reduces the probability of name conflicts dramatically. Thanks!

I've added this bug and the fix to our bug database, and we'll include it in Scratch 1.4.1. However, since we are working on a new version of Scratch in Flash, it's not clear when (or even if) we'll do a Scratch 1.4.1 release.

Meanwhile, one way to work around this issue would be to create a folder for each user, and have them save their work there. I realize this is not ideal, but it's better than the risk of losing projects. Fetta's idea of saving locally, then copying the project to the shared drive would also work, although I see how this could be difficult for young users to remember.

  -- John

Offline

 

#7 2011-02-05 10:38:37

captainobvious
New Scratcher
Registered: 2010-07-13
Posts: 2

Re: Sequentially named temporary files saved to network drives

Update: This is a version of my fix above that actually seeds the random numbers (with the time in milliseconds).

Code:

unusedNameStartingWith: prefix
    "Answer an unused file or directory name in this directory starting with the given prefix and ending with one to six random digits."
    "FileDirectory default unusedNameStartingWith: 'tmp'"

    | randomGenerator usedNames result |
    randomGenerator := Random new seed: (Time millisecondClockValue).
    usedNames _ self fileAndDirectoryNames asSet.
    [usedNames includes: (result _ prefix, ((1000000 atRandom: randomGenerator) - 1) printString)] whileTrue: [].
    ^ pathName, self slash, result

The changed method is still System-Files,FileDirectory>>unusedNameStartingWith:

Offline

 

Board footer