Bug 241007

Summary: ports-mgmt/pkg: cannot open sqlite3 db: Not a directory (FreeBSD 13.0-CURRENT)
Product: Ports & Packages Reporter: Nathan <ndowens04>
Component: Individual Port(s)Assignee: freebsd-pkg (Nobody) <pkg>
Status: Closed FIXED    
Severity: Affects Many People CC: 000.fbsd, fernape, grahamperrin, grog, jwb, lists+freebsd, lwhsu, marten, philipp, pkg, please, rob2g2-freebsd, spork, w.schwarzenfeld
Priority: --- Flags: w.schwarzenfeld: maintainer-feedback? (pkg)
Version: Latest   
Hardware: Any   
OS: Any   

Description Nathan 2019-10-02 11:49:22 UTC
Upgraded from 12-RELEASE to 13.0-CURRENT
pkg gives:
FreeBSD% doas su
FreeBSD# pkg update
Updating FreeBSD repository catalogue...
pkg: Repository FreeBSD load error: cannot open sqlite3 db: Not a directory
Fetching meta.txz: 100%    944 B   0.9kB/s    00:01    
Fetching packagesite.txz: 100%    6 MiB   2.2MB/s    00:03    
Unable to create repository FreeBSD
Unable to update repository FreeBSD
Error updating repositories!

Looking at /var/db/pkg the db did exists

The fix is to deinstall/reinstall from ports

After just a bit I have to do it again. Does this in stable pkg and devel version
Comment 1 Nathan 2019-10-02 15:09:49 UTC
Additional note, this seems to happen if one is in a path that no longer exists, I did a pwd a moment ago to see where I was and it gave “.”  I would think pkg should still work nonetheless
Comment 2 Baptiste Daroussin freebsd_committer freebsd_triage 2019-10-02 15:12:16 UTC
Thanks for that precision, that is exactly what I was missing to reproduce. I will fix asap.
Comment 3 Nathan 2019-10-02 15:35:16 UTC
(In reply to Baptiste Daroussin from comment #2)
This may help too. Weirdly I was working in a git dir and switched to master to delete that branch, and tried to use pkg and noticed the dir seemed to disappear and caused pkg issue again. So yeah it is because of current pwd not existing to cause bug it seems; just don’t know what made my dir that existed to disappear  :)
Comment 4 spork 2019-10-16 21:56:07 UTC
Same on 11.3-RELEASE-p3.

In my case I was sitting in a /usr/ports/blah/foo directory that disappeared when a cron job to update the latest tree ran.
Comment 5 Miroslav Lachman 2020-02-19 23:12:34 UTC
I was bitten by this today. 
pkg: Repository codelab load error: cannot open sqlite3 db: No such file or directory

Thank you for the info about non existent current directory. That was the problem.

Can it be fixed in pkg or can be the message more informative about what is going on?
Comment 6 Mårten Lindblad 2020-04-07 07:41:01 UTC
Had the same issue today on 12.1 version 1.13.2.
I was standing in /usr/ports/www/node10 and did portsnap extract and then a pkg install failed with: pkg: Repository FreeBSD load error: cannot open sqlite3 db: Not a directory
Comment 7 rob2g2 2020-05-25 07:17:56 UTC
same problem here.
I was in a directory that did not exist any more
Comment 8 Marin Bernard 2020-12-12 13:39:05 UTC
Met the same issue today in 12.2-STABLE.
Comment 9 Jason W. Bacon freebsd_committer freebsd_triage 2021-02-09 14:37:47 UTC
Just encountered this on 12.2-RELEASE.  Had wiped and reinstalled my ports tree and forgot to cd out of /usr/ports in another window.  Thanks for posting the workaround.
Comment 10 Greg Lehey freebsd_committer freebsd_triage 2021-02-15 02:21:01 UTC
I've had just this problem as well.  In my case, it was due to the current directory having gone away under the shell.  So the error message was Just Plain Wrong: the "Not a directory" refers to the cwd, not the (misspelt) "sqlite3 db".

I don't know if this is related to the other reports, but clearly some better error reporting would help.

While I'm here, based on other reports, change "Affects only me" to "Affects Many People"
Comment 11 Fernando Apesteguía freebsd_committer freebsd_triage 2021-09-01 09:53:21 UTC
Just for the record, this just happened to me.

I was in a git branch which created a new port. I went back to main branch where the port and hence the current directory did not exist and got this error.

This is with pkg 1.17.1
Comment 12 Baptiste Daroussin freebsd_committer freebsd_triage 2021-09-07 08:10:25 UTC
fixed in git, will be in the next release:
https://github.com/freebsd/pkg/commit/cc2f7f96b01a3b11bc83fedc98c1bcdd4d56cbbe