Looking into adding wildcard support

I’m trying to solve an issue syncing multiple systems where files of different extensions reside in different folders on the different systems. I am considering modifying Syncthing to add support for this.

Specifically, I have several instances of Retrobat running on PCs, and several instances of Batocera running on different types of hardware. I want to sync the save files between the systems.

On the Batocera machines, all the files I care about live in /userdata/saves/snes (.srm,.state,.png). On the retrobat systems, some of the files live in J:/RetroBat/saves/snes (.srm), some live in J:/RetroBat/saves/snes/libretro.snes9x (.state,.png)

I can’t find a clean way to make Syncthing do what I want with either the .stignore file, or with symbolic links

What I’m considering doing (I’ve only done a brief dive into the code so far, so this may be a horrible idea) is modify the Folder Path to support multiple folders and wildcards.

With that setup, the Syncthing Folder Path description on the PC would be something like:

J:/RetroBat/saves/snes/[*.srm];J:/RetroBat/saves/snes/libretro.snes9x/[*.state;*.png]

And on the Batocera systems, Folder Path would be:

/userdata/saves/snes

My questions:

  • Does this seem like a reasonable approach?
    • Is there a solution that already exists?
    • Is there a better way to modify Syncthing to add this support?
  • Does this seem like a reasonably achievable task, or am I in for a big surprise when I dig into the code?
  • My use case is really specific. My other alternative is to just write a more bespoke file sync system with one of my PCs as the server and everything else as a client, but it seems like Syncthing is close to doing what I want it to do, though I will end up having to add a lot of synced folders to my Syncthing configurations to get it all to work.

Welcome here @YourUncleBob !

To me the solution is obvious:

  • Create a Syncthing folder for /userdata/saves/snes which is shared between the Batocera machines.
  • Create a Syncthing folder for J:/RetroBat/saves/snes which is shared between the RetroBat machines.

Or is there something I am missing?

If I understand what you’re saying, that would sync the systems separately and wouldn’t have the retrobat systems sharing the files with the Batocera systems.

I probably didn’t describe what I’m trying to do clearly.

I want to sync the same files between all of the systems. The complication is that on the Batocera systems, all of the files are in one directory. In the retrobat systems, those same files are split between two directories.

So if a new file is created on the Batocera system, how does Syncthing know where it belongs?

I think if you want to make this generic there needs to be a very deterministic way to identify what belongs where.

I can’t wrap my head around how this would work in real life.

It’s all known by file extension. So for instance, on batocera, I have the files:

/userdata/saves/snes/a.srm

/userdata/saves/snes/a.state

/userdata/saves/snes/a.state.png

/userdata/saves/snes/a.state1

/userdata/saves/snes/a.state1.png

….

On the retrobat machines, I would have:

J:/RetroBat/saves/snes/a.srm

J:/RetroBat/saves/snes/libretro.snes9x/a.state

J:/RetroBat/saves/snes/libretro.snes9x/a.state.png

J:/RetroBat/saves/snes/libretro.snes9x/a.state1

J:/RetroBat/saves/snes/libretro.snes9x/a.state1.png

….

So, I was thinking that it would have a single sync rule that on the Batocera machine would collect everything in /userdata/saves/snes, and then the retrobat machine’s sync rule for that same Folder ID would know by file extension to place some of those files into J:/RetroBat/saves/snes and some into J:/RetroBat/saves/snes/libretro.snes9x

When syncing from the retrobat machines the rule for the Folder ID would tell it to collect all the files from J:/RetroBat/saves/snes and J:/RetroBat/saves/snes/libretro.snes9x, and the rule on the Batocera side would place them all into /userdata/saves/snes

I guess what it’s doing is abusing the idea of Folder and turning it into a description of files to sync based on foldernames and wildcards where each machine can have that “Folder” be a different set of rules for where to place those files based on how they match the wildcards (in the case I’m using, just by file extension, but I imagine it could be any sort of wildcard).

It would be syncing several folders to one, or one to several, depending on which the source and destination of the sync are.

So on the Retrobat side, the “Folder Path” field would be:

J:/RetroBat/saves/snes/[*.srm];J:/RetroBat/saves/snes/libretro.snes9x/[*.state;*.png]

Telling it to collect or place the srm files from one folder and the state and png files from another

I would think this would be doable with two syncthing folders with a very carefully defined set of excludes/includes.

on one machine the two syncthing folders would point to the same filesystem folder and on the other machine they would point to the two filesystem folders.

you’ll get a warning that you’re Sharing a folder twice but I think it could work. Definitely try this on copies of the folders initially to be sure.

Maybe one of the other experts could comment whether they agree.

3 Likes

What Mike said.

I’ll give that a shot and see what happens, thanks.

In the meantime, I threw together a bespoke sync program for this use case (by threw together I mean mostly Claude-coded, I’m digging into the generated code now and making sure it does what I want, so far it’s looking good). I don’t expect it will be as bullet-proof as Syncthing, but for my simple use-case, it may end up being a better approach. Plus, it’s just a fun small project.