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.
pgp7B0sHDd4nI.pgp
Description: PGP signature
_______________________________________________ Devl mailing list [email protected] http://emu.freenetproject.org/cgi-bin/mailman/listinfo/devl
