Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use FreeBSD extattrs to store file association information #3

Open
probonopd opened this issue Nov 22, 2020 · 7 comments
Open

Use FreeBSD extattrs to store file association information #3

probonopd opened this issue Nov 22, 2020 · 7 comments
Labels
enhancement New feature or request

Comments

@probonopd
Copy link
Member

probonopd commented Nov 22, 2020

Investigate FreeBSD xattrs to store file association information.
Especially how Haiku uses them (hybrid with resources).

Use case:

  • (1) I have 5 versions of LibreOffice. Which one to use to open LibreOffice documents?
  • (2) Then, I have ONE document that needs LibreOffice 3. How do make sure THIS document gets always opened with THIS LibreOffice? This could be addressed by using xattrs...

https://www.freebsd.org/cgi/man.cgi?query=getextattr&sektion=8&apropos=0&manpath=FreeBSD+11.2-RELEASE

@probonopd
Copy link
Member Author

probonopd commented Nov 22, 2020

nephele on IRC suggests:

it's a much nicer alternative than, like... shell scripts to invoke programms with, just put the options, or args you want in an attribute and set the correct mimetype, the programm gets that file and can understand what to do

i.e a link to open a vnc desktop to a specific host or so

haiku just sniffs the mimetyp on the first time around, and then saves it in an xattr
and then opens based on the mimetype

@probonopd
Copy link
Member Author

probonopd commented Nov 22, 2020

Regarding (2) maybe we can set key openWith to value /Applications/LibreOffice 3.app on the file "this.doc"?

This will break when /This/App.app moves. But maybe we can set a UUID attribute on /Applications/LibreOffice 3.app and set an openWithUUID attribute on this.doc...

This needs more thought.

Regarding (1) nephele on IRC suggests:

i would just save the mimetype on the files, and then look up what to launch that mimetype with

For "look up" we might still need a (sqlite)? database.

On the Mac, Launch Services holds information about file types and the applications that should be used to open them in a database stored at /private/var/folders/**/**/-Caches-/com.apple.LaunchServices-*.csstore.

It could hold an ordered list of applications that the user would like to use, if the drive is unmounted prompt them to select the 2nd, or 3rd entry from your list or so. We could even prompt the user "Please insert disk XYZ that contains LibreOffice 3 to open this.doc"... similar to what the Classic Mac could do.

An example of a Haiku sniffer rule:
https://git.haiku-os.org/haiku/tree/src/data/mime_db/video/mp4

There is probably much more to learn from Haiku in this regard:
https://medium.com/@probonopd/my-sixth-day-with-haiku-under-the-hood-of-resources-icons-and-packages-abec8d0e4ec6

@probonopd
Copy link
Member Author

# Write an extended attribute
setextattr user open-with kwrite /home/user/Schreibtisch/TODO.txt

# Read an extended attribute
getextattr -q user open-with /home/user/Schreibtisch/TODO.txt
kwrite

# List extended attributes
lsextattr -q user /home/user/Schreibtisch/TODO.txt
open-with

@probonopd
Copy link
Member Author

This can even be done for multiple files at once:

lsextattr user /home/user/Schreibtisch/* 
/home/user/Schreibtisch/Computer.app
/home/user/Schreibtisch/menu.ui
/home/user/Schreibtisch/proof-of-concept.sh
/home/user/Schreibtisch/TODO.txt        open-with

@probonopd
Copy link
Member Author

probonopd commented Nov 23, 2020

So in a nutshell, extended attributes allow "additional labels to be associated with a file or directory". Like which application to open a document with!

@probonopd probonopd changed the title Investigate FreeBSD xattrs to store file association information Investigate FreeBSD extattrs to store file association information Nov 23, 2020
@probonopd
Copy link
Member Author

probonopd commented Nov 24, 2020

Usage example for how to use this programmatically in a "cross-platform" way:

https://github.com/KDE/kfilemetadata/blob/master/src/xattr_p.h

Looks like it could work on Linux similarly. To be investigated.

@probonopd
Copy link
Member Author

probonopd commented Nov 5, 2022

It's beginning to happen. launch now makes heavy use of extended attributes, and the code seems to be somewhat platform independent since it at least builds on Alpine Linux as well.

Current thinking:
https://github.com/helloSystem/hello/wiki/Project-%22XDG-ng%22

@probonopd probonopd changed the title Investigate FreeBSD extattrs to store file association information Use FreeBSD extattrs to store file association information Nov 5, 2022
@probonopd probonopd added the enhancement New feature or request label Nov 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant