summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/symlinker/main.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/core/symlinker/main.cpp b/core/symlinker/main.cpp
index 96e7f3c..bf53a82 100644
--- a/core/symlinker/main.cpp
+++ b/core/symlinker/main.cpp
@@ -1,185 +1,185 @@
1 1
2/* OPIE */ 2/* OPIE */
3#include <opie2/odebug.h> 3#include <opie2/odebug.h>
4 4
5/* QT */ 5/* QT */
6#include <qapplication.h> 6#include <qapplication.h>
7#include <qfile.h> 7#include <qfile.h>
8#include <qfileinfo.h> 8#include <qfileinfo.h>
9#include <qdir.h> 9#include <qdir.h>
10#include <qtextstream.h> 10#include <qtextstream.h>
11#include <qstringlist.h> 11#include <qstringlist.h>
12 12
13/* STD */ 13/* STD */
14#include <stdlib.h> 14#include <stdlib.h>
15#include <unistd.h> //symlink() 15#include <unistd.h> //symlink()
16#include <sys/stat.h> // mkdir() 16#include <sys/stat.h> // mkdir()
17 17
18#include <sys/vfs.h> 18#include <sys/vfs.h>
19#include <mntent.h> 19#include <mntent.h>
20#include <errno.h> 20#include <errno.h>
21 21
22static const char *listDir = "/usr/lib/ipkg/externinfo/"; 22static const char *listDir = "/usr/lib/ipkg/externinfo/";
23 23
24static void createSymlinks( const QString &location, const QString &package ) 24static void createSymlinks( const QString &location, const QString &package )
25{ 25{
26 26
27 QFile inFile( location + "/usr/lib/ipkg/info/" + package + ".list" ); 27 QFile inFile( location + "/usr/lib/ipkg/info/" + package + ".list" );
28 mkdir( "/usr/lib/ipkg", 0777 ); 28 mkdir( "/usr/lib/ipkg", 0777 );
29 mkdir( listDir, 0777 ); 29 mkdir( listDir, 0777 );
30 30
31 QFile outFile( listDir + package + ".list"); 31 QFile outFile( listDir + package + ".list");
32 32
33// odebug << "createSymlinks " << inFile.name().ascii() << " -> " << outFile.name().ascii() << "" << oendl; 33// odebug << "createSymlinks " << inFile.name().ascii() << " -> " << outFile.name().ascii() << "" << oendl;
34 34
35 35
36 36
37 if ( inFile.open(IO_ReadOnly) && outFile.open(IO_WriteOnly)) { 37 if ( inFile.open(IO_ReadOnly) && outFile.open(IO_WriteOnly)) {
38 QTextStream in(&inFile); 38 QTextStream in(&inFile);
39 QTextStream out(&outFile); 39 QTextStream out(&outFile);
40 40
41 QString s; 41 QString s;
42 while ( !in.eof() ) { // until end of file... 42 while ( !in.eof() ) { // until end of file...
43 s = in.readLine(); // line of text excluding '\n' 43 s = in.readLine(); // line of text excluding '\n'
44// odebug << "Read: " << s.ascii() << "" << oendl; 44// odebug << "Read: " << s.ascii() << "" << oendl;
45 if (s.find(location,0,true) >= 0){ 45 if (s.find(location,0,true) >= 0){
46// odebug << "Found!" << oendl; 46// odebug << "Found!" << oendl;
47 s = s.replace(location,""); 47 s = s.replace(location,"");
48 } 48 }
49// odebug << "Read after: " << s.ascii() << "" << oendl; 49// odebug << "Read after: " << s.ascii() << "" << oendl;
50 50
51 // for s, do link/mkdir. 51 // for s, do link/mkdir.
52 if ( s.right(1) == "/" ) { 52 if ( s.right(1) == "/" ) {
53// odebug << "do mkdir for " << s.ascii() << "" << oendl; 53// odebug << "do mkdir for " << s.ascii() << "" << oendl;
54 mkdir( s.ascii(), 0777 ); 54 mkdir( s.ascii(), 0777 );
55 //possible optimization: symlink directories 55 //possible optimization: symlink directories
56 //that don't exist already. -- Risky. 56 //that don't exist already. -- Risky.
57 } else { 57 } else {
58// odebug << "do symlink for " << s.ascii() << "" << oendl; 58// odebug << "do symlink for " << s.ascii() << "" << oendl;
59 QFileInfo ffi( s ); 59 QFileInfo ffi( s );
60 //Don't try to symlink if a regular file exists already 60 //Don't try to symlink if a regular file exists already
61 if ( !ffi.exists() || ffi.isSymLink() ) { 61 if ( !ffi.exists() || ffi.isSymLink() ) {
62 if (symlink( (location+s).ascii(), s.ascii() ) != 0){ 62 if (symlink( (location+s).ascii(), s.ascii() ) != 0){
63 if (errno == ENOENT){ 63 if (errno == ENOENT){
64// perror("Symlink Failed! "); 64// perror("Symlink Failed! ");
65 QString e=s.ascii(); 65 QString e=s.ascii();
66 e = e.replace(ffi.fileName(),""); 66 e = e.replace(ffi.fileName(),"");
67// odebug << "DirName : " << e.ascii() << "" << oendl; 67// odebug << "DirName : " << e.ascii() << "" << oendl;
68 system ( QString("mkdir -p ")+e.ascii() ); 68 system ( QString("mkdir -p ")+e.ascii() );
69 if (symlink( (location+s).ascii(), s.ascii() ) != 0) 69 if (symlink( (location+s).ascii(), s.ascii() ) != 0)
70 odebug << "Big problem creating symlink and directory" << oendl; 70 odebug << "Big problem creating symlink and directory" << oendl;
71 } 71 }
72 } 72 }
73// qDebug ( "Created %s" ,s.ascii() ); 73// odebug << "Created << s.ascii() << oendl;
74 out << s << "\n"; 74 out << s << "\n";
75 } else { 75 } else {
76 odebug << "" << s.ascii() << " exists already, not symlinked" << oendl; 76 odebug << "" << s.ascii() << " exists already, not symlinked" << oendl;
77 } 77 }
78 } 78 }
79 } 79 }
80 inFile.close(); 80 inFile.close();
81 outFile.close(); 81 outFile.close();
82 } 82 }
83} 83}
84 84
85 85
86 86
87static void removeSymlinks( const QString &package ) 87static void removeSymlinks( const QString &package )
88{ 88{
89 QFile inFile( listDir + package + ".list" ); 89 QFile inFile( listDir + package + ".list" );
90 90
91 if ( inFile.open(IO_ReadOnly) ) { 91 if ( inFile.open(IO_ReadOnly) ) {
92 QTextStream in(&inFile); 92 QTextStream in(&inFile);
93 93
94 QString s; 94 QString s;
95 while ( !in.eof() ) { // until end of file... 95 while ( !in.eof() ) { // until end of file...
96 s = in.readLine(); // line of text excluding '\n' 96 s = in.readLine(); // line of text excluding '\n'
97// odebug << "remove symlink " << s.ascii() << "" << oendl; 97// odebug << "remove symlink " << s.ascii() << "" << oendl;
98 QFileInfo ffi( s ); 98 QFileInfo ffi( s );
99 //Confirm that it's still a symlink. 99 //Confirm that it's still a symlink.
100 if ( ffi.isSymLink() ){ 100 if ( ffi.isSymLink() ){
101 unlink( s.ascii() ); 101 unlink( s.ascii() );
102// qDebug ( "Removed %s", s.ascii() );} 102// odebug << "Removed " << s.ascii() << oendl; }
103// else 103// else
104// odebug << "Not removed " << s.ascii() << "" << oendl; 104// odebug << "Not removed " << s.ascii() << "" << oendl;
105 } 105 }
106 } 106 }
107 inFile.close(); 107 inFile.close();
108 inFile.remove(); 108 inFile.remove();
109 } 109 }
110} 110}
111 111
112 112
113 113
114/* 114/*
115 Slightly hacky: we can't use StorageInfo, since we don't have a 115 Slightly hacky: we can't use StorageInfo, since we don't have a
116 QApplication. We look for filesystems that have the directory 116 QApplication. We look for filesystems that have the directory
117 /usr/lib/ipkg/info, and assume that they are removable media 117 /usr/lib/ipkg/info, and assume that they are removable media
118 with packages installed. This is safe even if eg. /usr is on a 118 with packages installed. This is safe even if eg. /usr is on a
119 separate filesystem, since then we would be testing for 119 separate filesystem, since then we would be testing for
120 /usr/usr/lib/ipkg/info, which should not exist. (And if it 120 /usr/usr/lib/ipkg/info, which should not exist. (And if it
121 does they deserve to have it treated as removable.) 121 does they deserve to have it treated as removable.)
122 */ 122 */
123 123
124static void updateSymlinks() 124static void updateSymlinks()
125{ 125{
126 QDir lists( listDir ); 126 QDir lists( listDir );
127 QStringList knownPackages = lists.entryList( "*.list" ); // No tr 127 QStringList knownPackages = lists.entryList( "*.list" ); // No tr
128 128
129 struct mntent *me; 129 struct mntent *me;
130 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 130 FILE *mntfp = setmntent( "/etc/mtab", "r" );
131 131
132 if ( mntfp ) { 132 if ( mntfp ) {
133 while ( (me = getmntent( mntfp )) != 0 ) { 133 while ( (me = getmntent( mntfp )) != 0 ) {
134 QString root = me->mnt_dir; 134 QString root = me->mnt_dir;
135 if ( root == "/" ) 135 if ( root == "/" )
136 continue; 136 continue;
137 137
138 QString info = root + "/usr/lib/ipkg/info"; 138 QString info = root + "/usr/lib/ipkg/info";
139 QDir infoDir( info ); 139 QDir infoDir( info );
140// odebug << "looking at " << info.ascii() << "" << oendl; 140// odebug << "looking at " << info.ascii() << "" << oendl;
141 if ( infoDir.isReadable() ) { 141 if ( infoDir.isReadable() ) {
142 const QFileInfoList *packages = infoDir.entryInfoList( "*.list" ); // No tr 142 const QFileInfoList *packages = infoDir.entryInfoList( "*.list" ); // No tr
143 QFileInfoListIterator it( *packages ); 143 QFileInfoListIterator it( *packages );
144 QFileInfo *fi; 144 QFileInfo *fi;
145 while (( fi = *it )) { 145 while (( fi = *it )) {
146 ++it; 146 ++it;
147 if ( knownPackages.contains( fi->fileName() ) ) { 147 if ( knownPackages.contains( fi->fileName() ) ) {
148// odebug << "found " << fi->fileName() << " and we've seen it before" << oendl; 148// odebug << "found " << fi->fileName() << " and we've seen it before" << oendl;
149 knownPackages.remove( fi->fileName() ); 149 knownPackages.remove( fi->fileName() );
150 } else { 150 } else {
151 //it's a new one 151 //it's a new one
152 createSymlinks( root, fi->baseName() ); 152 createSymlinks( root, fi->baseName() );
153 } 153 }
154 154
155 } 155 }
156 156
157 } 157 }
158 } 158 }
159 endmntent( mntfp ); 159 endmntent( mntfp );
160 } 160 }
161 161
162 for ( QStringList::Iterator it = knownPackages.begin(); 162 for ( QStringList::Iterator it = knownPackages.begin();
163 it != knownPackages.end(); ++it ) { 163 it != knownPackages.end(); ++it ) {
164 // strip ".info" off the end. 164 // strip ".info" off the end.
165 removeSymlinks( (*it).left((*it).length()-5) ); 165 removeSymlinks( (*it).left((*it).length()-5) );
166 } 166 }
167} 167}
168 168
169 169
170 170
171int main( int argc, char *argv[] ) 171int main( int argc, char *argv[] )
172{ 172{
173 QApplication a( argc, argv, QApplication::Tty ); 173 QApplication a( argc, argv, QApplication::Tty );
174 174
175 QString command = argc > 1 ? argv[1] : "update"; // No tr 175 QString command = argc > 1 ? argv[1] : "update"; // No tr
176 176
177 if ( command == "update" ) // No tr 177 if ( command == "update" ) // No tr
178 updateSymlinks(); 178 updateSymlinks();
179 else if ( command == "create" && argc > 3 ) // No tr 179 else if ( command == "create" && argc > 3 ) // No tr
180 createSymlinks( argv[2], argv[3] ); 180 createSymlinks( argv[2], argv[3] );
181 else if ( command == "remove" && argc > 2 ) // No tr 181 else if ( command == "remove" && argc > 2 ) // No tr
182 removeSymlinks( argv[2] ); 182 removeSymlinks( argv[2] );
183 else 183 else
184 owarn << "Argument error" << oendl; 184 owarn << "Argument error" << oendl;
185} 185}