Text files opened from mount saved as binary

Hi, I got a new (fedora) laptop and I am trying to migrate to Google Drive from Dropbox because of their new three device policy (https://help.dropbox.com/accounts-billing/settings-sign-in/computer-limit).

I created the remote with rclone config (name gdrive, full access/scope 1).
Created a mount point:
$ mkdir gdrive
mount it at login:
$ echo rclone mount gdrive: gdrive --vfs-cache-mode full --daemon >> .bash_profile

I can then open and edit text files from the mount point (~/gdrive) using gedit. However, when I save the file, it is saved to Google Drive as a binary file, so when opening it from a browser on another fedora laptop it says 'no preview available', and prompts me to open it with a 3rd party app. Google Drive details for the file shows 'created Oct. xx with rclone'.

Opening it from Windows with the Google Drive client works fine.

Is there a way to save the file as text?


Hmmm, I would assume that the spesific format used is the problem here.
If it can not generate a preview that is probably because the backend does not have support for reading the format. "binary" in context just means raw data, so it's not actually changing the format or anything. It just doesn't really know what the bits represent so it just refers to the general term binary (which really all files are).

Test what happens if you use a universally supported format, like .txt
If preview works on that, then you just have to research what formats are supported.

Here are the google docs supported formats, so I assume the Gdrive preview is probably the same or at least very similar in what it supports:

I should mention that the files in question all have a .txt suffix, e.g. postgresql.txt.

$ rclone lsl gdrive/IT/postgresql.txt
10459 2019-10-22 16:11:49.922000000 postgresql.txt

Hmm, ok then my hunch is wrong I guess.

Just to be perfectly clear here - the file still has the .txt extension after it has been moved to Gdrive right? It's not an actual .bin file or no-extension ?

I did verify for you that uploading a simple .txt via rclone on a very standard Gdrive setup seems to work. I can open that file "natively" in the google browser UI.

So I ma not quite sure what to check next then... Here comes Nick to the rescue anyway :slight_smile:

What does this say?

rclone lsf -F mp  gdrive/IT/postgresql.txt

I suspect the mime type has got confused somehow.

Looks like the problem happens on editing an existing file with gedit

$ gedit /mnt/tmp/newfile.txt
$ rclone lsf -F mp TestDrive:newfile.txt
$ gedit /mnt/tmp/newfile.txt
$ rclone lsf -F mp TestDrive:newfile.txt

The problem is that gedit saves the file with a name like this goutputstream-0QB99Z then renames it to file.txt. If you can stop gedit doing that then it will work just fine.

The inital upload is when the file gets its mime type and rclone doesn't know what mimetype a file called goutputstream-0QB99Z should have.

Hi Nick, it looks OK with 'rclone lsf', but still shows as binary in the browser (https://drive.google.com).

$ rclone lsf -F mp gdrive/IT/postgresql.txt
text/plain; charset=utf-8;postgresql.txt

I checked the other files modified since I started using rclone/gedit, they are all text/plain, but all show as type: binary in the browser.

When I edit a file with gedit it stays as text/plain:
$ echo grrr > gdrive/foo.txt
$ rclone lsf -F mp gdrive/foo.txt
text/plain; charset=utf-8;foo.txt
$ gedit gdrive/foo.txt
$ cat gdrive/foo.txt
$ rclone lsf -F mp gdrive/foo.txt
text/plain; charset=utf-8;foo.txt

BTW there is no link to https://rclone.org/commands/rclone_lsf/ on https://rclone.org/docs/.

$ find gdrive -name *.txt -mtime -10 -exec rclone lsf -F m {} ;
text/plain; charset=utf-8
text/plain; charset=utf-8
text/plain; charset=utf-8
text/plain; charset=utf-8
text/plain; charset=utf-8
text/plain; charset=utf-8

:confused: I thought the mime type was how google drive worked out what files are what.

If the mime type is text/plain and the file has ending .txt then I would have thought google drive would show it as a text file.

Which ones I can edit correspond to which ones have mimetype text/plain for me


$ rclone lsf -F mp --include "*.txt" --files-only TestDrive:

So all are editable except newfile.txt

It might be that drive has something cached in your browser?

Can you check again after unmounting and mounting the drive again? Could be the vfs-cache is returning the mime-type of the local file instead of the file on the remote?

I cleared the browser (Firefox) cache/cookies/data and unmounted and remounted the drive, but no difference - mime-type still shows text/plain, browser shows type: binary, created by rclone.

I also tried in Chrome (on Fedora), same result. Same for Firefox on Windows.

Am I doing this right? I thought that by mounting the drive I would be able to edit the files directly, without having to manually sync. How should this be done?

FYI I do update a local copy once an hour:

$ crontab -l
0 * * * * rclone sync gdrive: Google

I also see issues with spreadsheets, e.g. if I try to open it from the mount point (~/gdrive) in Nautilus I sometimes get 'Read Error. Unknown or unsupported Excel file format.' I also sometimes get warnings that the file has been changed by another program, even though it has not.

You should be able to edit the files directly...

Have you tried a different text editor?

These files aren't google docs originally are they?

What about the spreadsheets - are they google docs? If so these don't behave very well in rclone mount because rclone doesn't know how big they are and file systems don't deal well with files of indeterminate size.

But to add to what NCW said, you would probably need --vfs-cache-mode writes , or at least minimal to do this. No cache would have issues when files are opened for READ+WRITE.

These are text files. On a Windows PC, I copied them from Dropbox to Google (using the Google backup and sync app). The ones that have not been changed are fine - they all show as text files in the browser. Any text files that have been changed with gedit (saved to the rclone mount point ~/gdrive) show as binary.

I tried vi, that works:
$ vi gdrive/foo2.txt
$ rclone lsf -F mp gdrive/foo2.txt
text/plain; charset=utf-8;foo2.txt
It shows as type text in the browser.

If I open a (binary) file with vi, make a change and save it, it then appears as text in the browser.
$ vi gdrive/IT/postgresql.txt

So yes, it seems to be an issue with gedit.

The spreadsheet files are Excel or LibreOffice format (.xls, .xlsx), not Google docs.

I am mounting with 'rclone mount gdrive: gdrive --vfs-cache-mode full --daemon' (via .bash_profile)

$ df -Th gdrive
Filesystem Type Size Used Avail Use% Mounted on
gdrive: fuse.rclone 15G 64M 15G 1% /home/xxx/gdrive

FYI I have some scripts in Google Drive, but I can't execute them. I get '/bin/bash: bad interpreter: Permission denied'. I can't set them executable, so I chmod the local copy and use that. The rsync does not change the mode of the local file, so if I need to update the script I can change it on gdrive and let it sync locally.

The cloud backends can only store basic attributes, so any other attributes like permissions will be lost in the cloud.

Nick may have a solution for that eventually (looking at the idea of saving metadata to the crypt format) but for now that is just how it is unfortunately. It's a technical limitation.

EDIT: You can however globally set permissions for all files in a FUSE mount, if that works for you. THen the FUSE mount just fakes the permissions for you when read back.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.