A sanity check to stop you accidentally installing packages to the wrong filesystem.
Robert Bragg
bob at o-hand.com
Wed May 21 19:40:09 CEST 2008
Hi,
I'm currently using opkg-cl to directly install packages to a
development filesystem that is exported from the same machine via NFS. I
specifically don't want to depend on the device being booted to install
packages.
As you can guess, this requires some amount of evil since opkg-cl must
be run as root to do this. (I know I'm evil, so please no need to
explain the potential woes of running as root :-) )
To give me _some_ sense of confidence though that I _probably_ wont
accidentally trash my development machine when passing the wrong -o path
I have added a local sanity check to my opkg that will verify that an
opkg_dir already exists on the target filesystem instead of
automatically trying to create it for me.
Since it seems like a fairly sensible failsafe safe check, I'm posting
the tweak here to see if anyone would object to something similar being
committed?
A noticeable affect this change would have is when creating new
filesystems built of ipks. It becomes your responsibility to ensure this
directory exists first, though I think it should be simple enough to
handle that.
kind regards,
- Robert
Index: libopkg/pkg_dest.c
===================================================================
--- libopkg/pkg_dest.c (revision 4445)
+++ libopkg/pkg_dest.c (working copy)
@@ -24,8 +24,14 @@
#include "opkg_state.h"
#include "opkg_defines.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+
int pkg_dest_init(pkg_dest_t *dest, const char *name, const char
*root_dir,const char * lists_dir)
{
+ struct stat sb;
dest->name = strdup(name);
/* Guarantee that dest->root_dir ends with a '/' */
@@ -38,7 +44,18 @@
sprintf_alloc(&dest->opkg_dir, "%s%s",
dest->root_dir, OPKG_STATE_DIR_PREFIX);
+#if 0
file_mkdir_hier(dest->opkg_dir, 0755);
+#else
+ if (stat(dest->opkg_dir, &sb) == -1 || !S_ISDIR(sb.st_mode)) {
+ fprintf(stderr, "Could not stat opkg state dir %s \n"
+ "You should create it manually: "
+ "This is a sanity check to stop you accidentally
installing "
+ "to the wrong filesystem)\n",
+ dest->opkg_dir);
+ return -1;
+ }
+#endif
if (str_starts_with (lists_dir, "/"))
sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
More information about the opkg-devel
mailing list