gilesknap / gphotos-sync

Google Photos and Albums backup with Google Photos Library API
Apache License 2.0
1.97k stars 161 forks source link

Escape special characters #475

Open GChalony opened 4 months ago

GChalony commented 4 months ago

gphotos-sync is crashing with an OsError when trying to create an album folder with a < in its name. Would it be possible to escape special characters in album (and photos?) names, so that the sync can be performed ? Alternatively, can we at least catch the error and skip this folder, rather than interrupting the sync altogether ?

Logs

02-13 22:31:13 WARNING  Creating album folder links to media ... 
02-13 22:31:18 ERROR    
Process failed. 
Traceback (most recent call last):
  File "/home/chalony/.local/lib/python3.12/site-packages/gphotos_sync/__main__.py", line 510, in main
    self.start(args)
  File "/home/chalony/.local/lib/python3.12/site-packages/gphotos_sync/__main__.py", line 450, in start
    self.do_sync(args)
  File "/home/chalony/.local/lib/python3.12/site-packages/gphotos_sync/__main__.py", line 439, in do_sync
    self.google_albums_sync.create_album_content_links()
  File "/home/chalony/.local/lib/python3.12/site-packages/gphotos_sync/GoogleAlbumsSync.py", line 322, in create_album_content_links
    link_folder.mkdir(parents=True)
  File "/usr/lib64/python3.12/pathlib.py", line 1312, in mkdir
    os.mkdir(self, mode)
OSError: [Errno 22] Invalid argument: '/run/media/***/Google Photo/albums/2018/1027 My Album <3'
02-13 22:31:18 WARNING  Done. 

I could write the PR if that's accepted

gilesknap commented 4 months ago

Happy to accept PRs. There is supposed to be code to handle invalid characters in filenames, this includes a different regex for windows and linux. Maybe there is an issue with identifying which filesystem is in use?

GChalony commented 4 months ago

Hi ! Sorry for the late reply, I just had time to dig a little more.

As you suggested, the filesystem is not detected as NTFS. psutil.disk_partitions() describes it as fuseblk , which does not help much in deciding what actual filesystem it is. df -T also reports fuseblk. After a bit of digging, it appears that lsblk --fs will indeed print ntfs, but I havent found a "pythonic" way to do it. Do you have any idea ?

At least for my specific issue, I can simply run it with --ntfs to bypass the problem.

gilesknap commented 4 months ago

I think I must have given up on this when I looked at it - bear in mind that the solution needs to work on windows and linux.

My simple workaround was adding the --ntfs flag.