[0.18.18] Blueprint Book File Symlink Overwritten

Post your ideas and suggestions how to improve the game.

Moderator: ickputzdirwech

Post Reply
dpacbach
Inserter
Inserter
Posts: 40
Joined: Sun Apr 22, 2018 1:09 am
Contact:

[0.18.18] Blueprint Book File Symlink Overwritten

Post by dpacbach »

OS: Linux

I have my blueprint-storage.dat file as a symlink into another folder (it's a symlink into a git repo so that I can version my blueprint book). This has always worked fine in that Factorio, when saving blueprint book changes, would follow the symlink. But in recent versions (I jumped from 0.16 to 0.18) this is no longer the case, and the symlink is replaced with a file. Why is this and can it be restored to previous behavior? Thanks

User avatar
invisus
Filter Inserter
Filter Inserter
Posts: 284
Joined: Fri Sep 21, 2018 5:33 pm
Contact:

Re: [0.18.18] Blueprint Book File Symlink Overwritten

Post by invisus »

I would love to do this too. However, my guess is that this changed sometime in 0.17.x around when 68499 was reported.

posila
Factorio Staff
Factorio Staff
Posts: 5201
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [0.18.18] Blueprint Book File Symlink Overwritten

Post by posila »

Hmm, I thought it was also caused by our update to newer C++ which as it turned out has more nightmarish implementation of statndard filesystem library, but it turns out it is because of our WriteFileGuard, which saves file under temporary name, renames old file, renames new file to final name and then deletes the old file. We do this in order to not corrupt your good old file in case something goes wring while saving new one. But we use this for blueprint storage since 0.16.33

dpacbach
Inserter
Inserter
Posts: 40
Joined: Sun Apr 22, 2018 1:09 am
Contact:

Re: [0.18.18] Blueprint Book File Symlink Overwritten

Post by dpacbach »

I think that you could continue using that copy/tmp methodology -- all you have to do is first resolve the symlink pointed to by blueprint-storage.dat. So logic to fix this would be like this:

Code: Select all

let f = "blueprint-storage.dat"
if on platform supporting symlinks {
  f = realpath(f) // resolve symlink if it is a symlink, otherwise no-op.
}
// Now just write the file using the existing tmp/copy methodology.
WriteFile(f)
@posila do you think it could be done?
David

SilentWarrior
Manual Inserter
Manual Inserter
Posts: 3
Joined: Thu Apr 16, 2020 3:20 pm
Contact:

Re: [0.18.18] Blueprint Book File Symlink Overwritten

Post by SilentWarrior »

Symlinks in Windows do exist. I wonder if this is a "thing" people do. As a programmer, this sounds ideal. Version your blueprint book. Although.. perhaps it should be part of the game itself.

Koub
Global Moderator
Global Moderator
Posts: 7198
Joined: Fri May 30, 2014 8:54 am
Contact:

Re: [0.18.18] Blueprint Book File Symlink Overwritten

Post by Koub »

SilentWarrior wrote:
Sat Jul 18, 2020 10:28 pm
Symlinks in Windows do exist. I wonder if this is a "thing" people do.
Symlinks were added to unix (BSD) somewhere in the mid 80s, and unix have always been a command line interfaced OSes. People using UNIX-like OSes have symlinks in their blood.
Microsoft-side, they were only added in Windows XP (2001), the command to create them with Windows Vista (2006) AND they only work on NTFS (I wouldn't be surprised some people still play on potatoes with FAT32 filesystem). Moreover, the command is command-line only, can't create it directly from an explorer Window.
People using Windows OSes are not "culturally" accustomed to fiddling with command-lines in a shell. I work in a moderately sized IT support team, and I'd be surprised anyone apart me in the ~100 techies has ever heard of symbolic links. And I only know of them because 1) I'm old, and 2) I've already used UNIX/linux OSes.
Koub - Please consider English is not my native language.

User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12888
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: [0.18.18] Blueprint Book File Symlink Overwritten

Post by ssilk »

In the moment when you export a Unix filesystem with many symlinks to a Windows, the dark rises. :twisted:
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...

mrwacko
Manual Inserter
Manual Inserter
Posts: 1
Joined: Wed Aug 09, 2017 7:02 am
Contact:

Re: [0.18.18] Blueprint Book File Symlink Overwritten

Post by mrwacko »

I have observed this behavior on my two windows machines (10 and 11) as well, with the most recent stable version of factorio (1.1.60 as of this writing). I use symlinks to point at my relocated blueprint-storage.dat file, which is in a sync'd drive. Any time changes are made, the symlink is broken. If this could be changed back to intended symlink behavior that would be amazing, and thanks.

User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12888
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: [0.18.18] Blueprint Book File Symlink Overwritten

Post by ssilk »

When I understand this correct, this is — as already mentioned by Posila — because a file is not written to its real path, it’s written as tmpfile, then the old file is renamed, the new file is renamed to the old file and the old file is removed.

Correct way is explained by dpacbach.

I’m not sure, if this works in any case. I think this is not so simple. If the file is symlinked into a directory where it has no write-rights it cannot do this.

IMHO the better way to make a copy of the blueprint book so that a player can use it from anywhere would be to have some kind of cloud functionality.
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...

Nidan
Fast Inserter
Fast Inserter
Posts: 227
Joined: Sat Nov 21, 2015 1:40 am
Contact:

Re: [0.18.18] Blueprint Book File Symlink Overwritten

Post by Nidan »

There are basically two options how to replace an existing file with a new version: a) truncate the old file and write the new content or b) write the new content into a new file and then move it on top of the old one.

a) preserves symlinks, but risks corruption in case of a crash. b) can recover from a crash since the old version is still around, but breaks symlinks. Therefore b) is often seen as the better approach.

Instead of only putting the blueprint file elsewhere, why not adjust the write-data path in config.ini so saves are included as well? Or configure your backup or versioning tool to only grab the one file and ignore the rest.

SoShootMe
Filter Inserter
Filter Inserter
Posts: 475
Joined: Mon Aug 03, 2020 4:16 pm
Contact:

Re: [0.18.18] Blueprint Book File Symlink Overwritten

Post by SoShootMe »

Nidan wrote:
Wed Jun 08, 2022 8:47 pm
There are basically two options how to replace an existing file with a new version: a) truncate the old file and write the new content or b) write the new content into a new file and then move it on top of the old one.

a) preserves symlinks, but risks corruption in case of a crash. b) can recover from a crash since the old version is still around, but breaks symlinks. Therefore b) is often seen as the better approach.
There is a bit more to the latter approach than just crash recovery. The fundamental benefit is that it allows the new file to be completely written before anything else happens. This obviously provides safety (eg if the writer crashes) - which is all that matters for Factorio. More generally, it also allows you to ensure a reader will never see a partially-written file and, with POSIX rename(), will see either old or new file (never no file).
Instead of only putting the blueprint file elsewhere, why not adjust the write-data path in config.ini so saves are included as well? Or configure your backup or versioning tool to only grab the one file and ignore the rest.
I think these are better (and actually more obvious) solutions than expecting Factorio to be changed to write through a symbolic link (risks corruption as mentioned) or use realpath() (why should it, when it "owns" the file?).

Post Reply

Return to “Ideas and Suggestions”