On Tuesday 20 November 2007 19:15, you wrote:
> +    private void storeBookmarks() {
> +        Logger.normal(this, "Attempting to save bookmarks to " + 
bookmarksFile.toString());
> +        SimpleFieldSet sfs;
> +        synchronized (bookmarks) {
> +            if (isSavingBookmarks) {
> +                return;
> +            }
> +            isSavingBookmarks = true;
> +            
> +            SimpleFieldSet toSave = MAIN_CATEGORY.toSimpleFieldSet();
> +            if(toSave.isEmpty()) {
> +                isSavingBookmarks = false;
> +                return;
> +            }
> +            sfs = toSave;
> +        }
> +        FileWriter fw = null;
> +        try {
> +            File tmp = File.createTempFile("bookmark", ".bak", 
bookmarksFile.getParentFile());
> +            fw = new FileWriter(tmp);
> +            sfs.writeTo(fw);
> +            if (!tmp.renameTo(bookmarksFile)) {
> +                Logger.error(this, "Unable to rename " + tmp.toString() + " 
to " + bookmarksFile.toString());

Only works on *nix. The correct cross platform procedure is to write to 
filename.bak, try to move to filename, if it doesn't work, then delete 
filename and try again. Then when starting up we check first filename, then 
filename.bak. And if you're worried about race conditions with symlinks, then 
write to a random-named temp file first and rename it to .bak after 
removing .bak. The temp buckets code will do all this for you.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 
<https://emu.freenetproject.org/pipermail/devl/attachments/20071120/9381e07d/attachment.pgp>

Reply via email to