DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD Packages and Ports

OpenBSD Packages and Ports Installation and upgrading of packages and ports on OpenBSD.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 23rd January 2020
gustaf gustaf is offline
Fdisk Soldier
 
Join Date: Dec 2016
Posts: 68
Default /usr/local/share/mime/application--How to delete files?

Scrolling through /usr/local/share/mime/application, I see files that appear to be left over from packages that I installed and later removed. I thought $ doas pkg_delete -ac [package] was supposed to remove all files related to the package, except the configuration files deposited in the user's home folder.

Is there a command to safely clean up this folder?

I don't use a desktop environment or file manager, only jwm for window management.

Thanks.

--------------------------------------------------
UPDATE: I've worked out the answer. See https://daemonforums.org/showthread.php?p=72309, later in this thread.

Last edited by gustaf; 11th April 2022 at 10:47 PM. Reason: Update
Reply With Quote
  #2   (View Single Post)  
Old 23rd January 2020
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 7,977
Default

These files are not part of package packing lists, which is why they are not deleted by pkg_delete. (I know this by using the -E flag of pkg_info(1) on them.)

I don't know their provenance. They appear to all have the same date/time, so may have been created by pkg_add(1). Perhaps pkg_check(8) will inspect the directory and remove extraneous files.
Reply With Quote
  #3   (View Single Post)  
Old 23rd January 2020
shep shep is offline
Real Name: Scott
Arp Constable
 
Join Date: May 2008
Location: Dry and Dusty
Posts: 1,503
Default

Quote:
I don't know their provenance.
Say you are constructing a presentation in Libreoffice and wish to insert a png graphic. After selecting the graphic, Libreoffice allows you to open the graphic in an external editor. Both inkscape and gimp pop-up as choices to edit the png. This is handled by mimetypes. It is kinda like a mailcap in mutt.

Quote:
They appear to all have the same date/time, so may have been created by pkg_add(1)
I think this is done by an update-mime-database command in the PLIST. The consistent time/date stamps likely represent the last time the update-mime-database command was run.

Quote:
Is there a command to safely clean up this folder?
I do not know this for a fact but the update-mime-database(1) would be worth testing.

Note to forum admins: OpenBSD's manpage does not link - I substituted FreeBSD's.

Last edited by shep; 24th January 2020 at 04:00 PM.
Reply With Quote
  #4   (View Single Post)  
Old 24th January 2020
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 7,977
Default

Ah! Thank you! I haven't paid enough attention to freedesktop.org applications.
Reply With Quote
  #5   (View Single Post)  
Old 11th April 2022
gustaf gustaf is offline
Fdisk Soldier
 
Join Date: Dec 2016
Posts: 68
Default

Quote:
Originally Posted by shep View Post
I do not know this for a fact but the update-mime-database(1) would be worth testing.

Note to forum admins: OpenBSD's manpage does not link - I substituted FreeBSD's.
Thanks for this suggestion shep!
Since update-mime-database isn't part of the base system, its man page won't show up on the OpenBSD man page server. The update-mime-database executable and corresponding man page are installed from the misc/shared-mime-info package.

After doing some further experimenting, I was able to peel back the layers created by this package.

For documentation, see:
shared-mime-info-spec overview
shared-mime-info database specification (version 0.21)
update-mime-database(1) - man page installed with the shared-mime-info package

Referenced OpenBSD man pages:
find(1)
grep(1)
pkg_add(1)
pkg_delete(1)
pkg_create(1) (explanation of '@' notation from $ pkg_info -f; '%D' stands for '/usr/local')


1. Install misc/shared-mime-info on a machine with a clean system install and no existing packages:
Code:
$ doas pkg_add -iv shared-mime-info

2. Print a list of files in the installed package along with any package-management instructions:
Code:
$ pkg_info -f shared-mime-info

...
@define-tag update-mime-database at-end %D/bin/update-mime-database %D/share/mime
@cwd /usr/local
@tag update-mime-database
@unexec-delete...   # executed when 'shared-mime-info' is deleted 
@bin bin/update-mime-database   # the program itself
...
@man man/man1/update-mime-database.1   # the man page
...
share/mime/packages/freedesktop.org.xml   # the application-specific XML file
...
In addition to the files explicitely installed by the package, there are hundreds of files inside the newly-created directory structure /usr/local/share/mime/:
Code:
$ ls -F /usr/local/share/mime

XMLnamespaces   generic-icons   inode/          multipart/      types
aliases         globs           magic           packages/       version
application/    globs2          message/        subclasses      video/
audio/          icons           mime.cache      text/           x-content/
font/           image/          model/          treemagic       x-epoc/
Where did these files come from?

The @define-tag and @tag lines from $ pkg_info -f shared-mime-info reveal that, as part of the package installation process, /usr/local/bin/update-mime-database is executed, thus generating these files.

The shared-mime-info database specification explains this further:
Quote:
Each application that wishes to contribute to the MIME database will install a single XML file, named after the application, into...the [/usr/local/share/mime]/packages/ [directory]...After installing, uninstalling or modifying this file, the application MUST run the update-mime-database command...

update-mime-database is passed the [/usr/local/share/mime] directory...as its only argument. It scans all the XML files in the packages subdirectory, combines the information in them, and creates a number of [database] files [in /usr/local/share/mime].
The XML file for shared-mime-info is freedesktop.org.xml.


3. Install a package that updates the shared-mime-info database (for example, productivity/zim):

Code:
# Before installing, search for any possible default zim-related files 
$ grep -aHinoRw zim /usr/local/share/mime/ | sort > mime-default.txt   
$ less mime-default.txt   # Empty; no zim-related files

# Install the package
# To optionally capture the entire output, run '$ doas pkg_add -ivvvvvx zim > zim-add.txt'
$ doas pkg_add -iv zim

4. Check the zim package file list and instructions:
Code:
$ pkg_info -f zim | less

...
@cwd /usr/local
bin/zim
...
@man man/man1/zim.1
...
share/mime/packages/zim.xml
...
@tag update-mime-database
...
zim.xml contains the data that will be added to (or deleted from) the database when '@tag update-mime-database' executes the '@define-tag update-mime-database at-end %D/bin/update-mime-database %D/share/mime' command found in the shared-mime-info package.


5. Search the mime directory a second time to catch the files added or modfied by update-mime-database(1) during the zim install:
Code:
$ grep -aHinoRw zim /usr/local/share/mime/ | sort | > mime-zim.txt
$ less mime-zim.txt  # Line numbers may vary.

/usr/local/share/mime/application/x-zim-notebook.xml:2:zim
/usr/local/share/mime/globs2:837:zim
/usr/local/share/mime/globs2:837:zim
/usr/local/share/mime/globs:835:zim
/usr/local/share/mime/globs:835:zim
/usr/local/share/mime/magic:87:zim
/usr/local/share/mime/mime.cache:1:zim
/usr/local/share/mime/mime.cache:1:zim
/usr/local/share/mime/packages/zim.xml:3:zim
/usr/local/share/mime/subclasses:57:zim
/usr/local/share/mime/text/x-zim-wiki.xml:2:zim
/usr/local/share/mime/types:436:zim
To view any human-readable text in binary files (for example, magic and cache files),
use $ strings file.

Now, it's time to answer the original question:
Quote:
Originally Posted by gustaf View Post
Scrolling through /usr/local/share/mime/application, I see files that appear to be left over from packages that I installed and later removed...

Is there a command to safely clean up this folder?
At this point, it seems clear that shared-mime-info has a mechanism for cleaning up the files in the mime directory, and that any files found there are not, in fact, orphaned.


6.To test if this is true, begin by deleting zim:
Code:
$ doas pkg_delete -civ zim  # Delete zim files and update the mime database
$ doas pkg_delete -aciv  # Clean up any unused dependencies

7. Search the mime directory to determine if zim has deleted its files:
Code:
$ grep -aHinoRw zim /usr/local/share/mime/ | sort > mime-default-restore.txt
$ less mime-default-restore.txt  # Empty file; zim-related files have been deleted

8. Verify that the mime directory stucture still exists:
Code:
$ ls -F /usr/local/share/mime

XMLnamespaces   generic-icons   inode/          multipart/      types
aliases         globs           magic           packages/       version
application/    globs2          message/        subclasses      video/
audio/          icons           mime.cache      text/           x-content/
font/           image/          model/          treemagic       x-epoc/

9. Print the shared-mime-info packing list instructions; note the annotations specifically related to package removal:
Code:
$ pkg_info -f shared-mime-info | less

...
@define-tag update-mime-database at-end %D/bin/update-mime-database %D/share/mime
...
@tag update-mime-database
@unexec-delete find %D/share/mime/* -maxdepth 0 -type d ! -name packages -exec rm -rf '{}' \+
@unexec-delete find %D/share/mime/ -type f ! -name freedesktop.org.xml -exec rm -f '{}' \+
...
@unexec-delete find...-exec rm -rf '{}' \+ removes all directories except packages, then all remaining files except freedesktop.org.xml.


10. Delete the shared-mime-info package (updates the shared-mime database, removes the /usr/local/share/mime/ directory, and deletes the package files):
Code:
$ doas pkg_delete -civ shared-mime-info
# To optionally capture the entire output, run '$ doas pkg_delete -civvvvvx shared-mime-info > mime-delete.txt'

$ doas pkg_delete -aciv   # Clean up any unused dependencies

11. Verify that the entire mime directory has been removed along with the shared-mime-info package:
Code:
$ cd /usr/local/share ; ls -F
...
locale/
misc/
...

$ pkg_info | less  # shared-mime-info is no longer listed

I can now see that there is no need to do any manual housekeeping on the /usr/local/share/mime directory. The commands built into the package management tools will keep things tidy.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
nnn: How do you copy, move and delete files? Prevet OpenBSD Packages and Ports 5 26th May 2019 02:18 PM
pcmanfm-qt requires refresh to determine MIME type of new files brudan OpenBSD Packages and Ports 6 16th April 2019 03:28 PM
Delete Files By Schedule Continued plexter OpenBSD General 4 28th June 2008 03:43 AM
Delete Files By Schedule plexter OpenBSD General 12 4th June 2008 10:15 PM
/usr/local and application directories ducu_00 FreeBSD Ports and Packages 14 23rd May 2008 05:37 PM


All times are GMT. The time now is 05:46 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick