TheDiscordian / ipfs-sync

A simple daemon which will watch files on your filesystem, mirror them to MFS, automatically update related pins, and update related IPNS keys.
BSD 3-Clause "New" or "Revised" License
95 stars 14 forks source link

Filestore (nocopy) breaks horribly with quick renames #32

Closed TheDiscordian closed 3 years ago

TheDiscordian commented 3 years ago

Currently filestore can break horribly if we do quick renames. For example:

  1. Download file to synced folder with a browser, file will be named Unconfirmed.xyz or something.
  2. After download completes, it'll rename to the desired filename

What happens?

Well filestore will initially store a reference for Unconfirmed.xyz before it gets totally removed from the blockstore, the rename occurs. The causes filestore to ignore the abspath passed in the header on the second add, and instead lookup the hash, and use the abspath used for Unconfirmed.xyz, which no longer exits. This causes errors trying to do just about anything.

How do we fix it?

On pin/update and sometimes files/cp we can get an error:

failed to get block for bafkreidjs72a6h2quuhq7fl4q4aefqxdrioestsci2uoyvns3duzl4nv2q: open /home/user/Documents/IPFS Websites/DiscoNet/documents/riichi_mahjong/Unconfirmed 642720.crdownload: no such file or directory

If we run a block/rm on the CID above, the error is resolved, we simply need to re-add the effected file after, then attempt to update the pin again.

Not totally clear on how we locate the effected file in the pin/update scenario, I suppose we'll just have to hope that doesn't happen, and if it does, a user can re-add the file by simply renaming it to something, then back again. So for this scenario, we'll just remove the block, and hope filestore sorts itself out.

TheDiscordian commented 3 years ago

Perhaps we can use filestore/verify, and remove the blocks for everything with status no-file. Output is like this:

no-file bafkreiayqyens67kpulan5otcunfueoel4y7vgw5fbvqtqrrgeeu4cgczq     21 ipfs/_gfstore/202102/1612899577.0008962/testing/testfolder/Text File.txt 0
no-file bafkreib74263xt6wtwg6c5dnamdh2pewsri2hi2ataq5pexbdask33mdla      4 ipfs/_gfstore/202102/1612897806.4329498/testing/test 0
no-file bafkreicozgazukrqol4w2mfpzlevsc7i3j65zlyg3g3s7sriahbwv3vzqa      8 ipfs/_gfstore/202102/1612899130.9880302/testing/testfolder/Text File.txt 0
no-file bafkreid6hxt3lcont3ig7sp3jpdbnnze3uvknhwshaegedojlysj45zgze 262144 Documents/IPFS Websites/DiscoNet/documents/riichi_mahjong/Unconfirmed 642720.crdownload 262144
no-file bafkreidhnjvrvrpyuzg6j6hwb5yrnkyxq7zlyn4nptdojyom5vpfiy4xhi  65536 Documents/IPFS Websites/DiscoNet/documents/riichi_mahjong/RiichiCheatSheet_FINAL_v2 copy.pdf 262144
no-file bafkreidqyebz5wgoql3nf6mmnvhi22zicfpnxcynbu22gguzyxun4inqc4 144956 Documents/IPFS Websites/DiscoNet/documents/riichi_mahjong/A Beginner’s Guide to Riichi Mahjong.pdf 0
no-file bafkreieb5r4ot6bmhf55jhuw3jwjymgfu7ebsf4xb66v2twbi7iid5ecpe   3997 Documents/IPFS Websites/DiscoNet/documents/riichi_mahjong/Unconfirmed 642720.crdownload 1310720
no-file bafkreiehxpg7zp6jtpcid4yodr7pt77wt2643y6jokwg246lmrzczagrbu 262144 Documents/IPFS Websites/DiscoNet/documents/riichi_mahjong/Unconfirmed 642720.crdownload 1048576
no-file bafkreih36iwdpwsub4kzk4vcuwenwi6ba3wjootppb5tfoi5fuj52qrsm4 233472 Documents/IPFS Websites/DiscoNet/documents/riichi_mahjong/RiichiCheatSheet_FINAL_v2.pdf2 copy 262144
no-file bafkreihg2grr4ltmlwehq3dqiel5kbknc67o76mlxbcmwxy23bvjopaz3q 262144 Documents/IPFS Websites/DiscoNet/documents/riichi_mahjong/Unconfirmed 642720.crdownload 0
no-file bafkreihqkutlcbndcwiigrvg5gvydhonbd4gijoscnue7uku4wdmyjoa7e 262144 Documents/IPFS Websites/DiscoNet/documents/riichi_mahjong/Unconfirmed 642720.crdownload 786432
TheDiscordian commented 3 years ago

Actually just removing the blocks seems to work fine, and unpinning when necessary. Not sure why exactly, because I can't find a reference to the file in the filestore even under ok after, but it does function, so I suppose that's what matters.

I'll try to get something implemented this weekend.

TheDiscordian commented 3 years ago

Json output, no-file is status 11:

{"Status":11,"ErrorMsg":"open /home/user/Documents/IPFS Websites/DiscoNet/documents/Unconfirmed 199898.crdownload: no such file or directory","Key":{"/":"bafkreia3vgy4mjfbphiy5jxoxdm7bgv3t6nlo4yzhm5fnmdnr4gjktcr7i"},"FilePath":"Documents/IPFS Websites/DiscoNet/documents/Unconfirmed 199898.crdownload","Offset":786432,"Size":262144}
TheDiscordian commented 3 years ago

Error if pinned:

{"Hash":"bafkreihqkutlcbndcwiigrvg5gvydhonbd4gijoscnue7uku4wdmyjoa7e","Error":"pinned via QmeXpido4tyRs7gR3QMsWLCjP9BiCLFgPaVs1mhXBLuYSQ"}