Ticket #4369 (closed enhancement: fixed)

Opened 23 months ago

Last modified 22 months ago

sqlite 3 view: use 'immutable=1' URI parameter to prevent leaving wal/shm files after viewing sqlite database

Reported by: karlicoss Owned by: andrew_b
Priority: major Milestone: 4.8.29
Component: mc-core Version: master
Keywords: sqlite Cc:
Blocked By: Blocking:
Branch state: no branch Votes for changeset: committed-master


The problem I often had with viewing .sqlite files with mc is that exiting the view mode mid-way may leave .wal/.shm files in the database directory.
This never caused any actual issues, but a bit annoying, since leftover .wal files are often a sign that the program working with the database exited ungracefully.
This effectively reproduces mc's behaviour:

/tmp/testsqlite $ rm -f *-wal *-shm && sqlite3 "/tmp/testsqlite/db file.sqlite" .dump | head >/dev/null && ls -1 /tmp/testsqlite/
'db file.sqlite'
'db file.sqlite-shm'
'db file.sqlite-wal'

After the change -- no shm/wal files:

/tmp/testsqlite $ rm -f *-wal *-shm && sqlite3 "file:/tmp/testsqlite/db file.sqlite?immutable=1" .dump | head >/dev/null && ls -1 /tmp/testsqlite/
'db file.sqlite'

You can find the docs on immutable mode here https://www.sqlite.org/uri.html#uriimmutable
Immutable mode has been supported in sqlite since 2014: https://www.sqlite.org/changes.html#version_3_8_5
In case user's sqlite installation is older, the mode is just quietly ignored, so the change is backwards compatible.


0001-sqlite-3-view-use-immutable-1-URI-parameter-to-preve.patch (1.8 KB) - added by karlicoss 23 months ago.

Change History

comment:1 Changed 23 months ago by karlicoss

The only downside of this change is that now if you're trying to view a database with an uncommitted WAL,the WAL is basically ignored, whereas previously it would also display the changes in WAL.

This may or may not be desirable (personally I'd rather prefer for it not to dump empty WAL files). If we want to preserve the old behaviour, could change the viewer to be adaptive: if there are no existing -wal files, use immutable mode; otherwise open in the default mode which would also display uncommitted changes.

Version 0, edited 23 months ago by karlicoss (next)

comment:2 Changed 23 months ago by karlicoss

also in the meantime, if you want to achieve that behaviour, you can use this in your local ext config (~/.config/mc/mc.ext)

# sqlite3.db
type/^SQLite 3.x database
	Open=/usr/lib/mc/ext.d/misc.sh open sqlite
	View=%view{ascii} sqlite3 file:%f?immutable=1 .dump

comment:3 Changed 22 months ago by andrew_b

  • Status changed from new to accepted
  • Owner set to andrew_b
  • Component changed from mcview to mc-core
  • Milestone changed from Future Releases to 4.8.29

comment:4 Changed 22 months ago by andrew_b

  • Status changed from accepted to testing
  • Votes for changeset set to committed-master
  • Resolution set to fixed

comment:5 Changed 22 months ago by andrew_b

  • Status changed from testing to closed
Note: See TracTickets for help on using tickets.