summaryrefslogtreecommitdiff
authorandyq <andyq>2002-10-16 16:27:00 (UTC)
committer andyq <andyq>2002-10-16 16:27:00 (UTC)
commitea11ae7dc31e23578d13f30315a3697cbce99c05 (patch) (unidiff)
tree38391e8c5d681a2bad804ec32aececd62befa19c
parentdf5c9a60e2ee3484f424b4d6aa2f158a9aade93b (diff)
downloadopie-ea11ae7dc31e23578d13f30315a3697cbce99c05.zip
opie-ea11ae7dc31e23578d13f30315a3697cbce99c05.tar.gz
opie-ea11ae7dc31e23578d13f30315a3697cbce99c05.tar.bz2
Fixed bug with reading ipkg.conf (ignored src lines that were commented out
with # src Also, now writes a nice comment out to the ipkg.conf file
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/aqpkg/datamgr.cpp53
1 files changed, 45 insertions, 8 deletions
diff --git a/noncore/settings/aqpkg/datamgr.cpp b/noncore/settings/aqpkg/datamgr.cpp
index b9ce227..b6e6e37 100644
--- a/noncore/settings/aqpkg/datamgr.cpp
+++ b/noncore/settings/aqpkg/datamgr.cpp
@@ -1,202 +1,239 @@
1/*************************************************************************** 1/***************************************************************************
2 datamgr.cpp - description 2 datamgr.cpp - description
3 ------------------- 3 -------------------
4 begin : Thu Aug 29 2002 4 begin : Thu Aug 29 2002
5 copyright : (C) 2002 by Andy Qua 5 copyright : (C) 2002 by Andy Qua
6 email : andy.qua@blueyonder.co.uk 6 email : andy.qua@blueyonder.co.uk
7 ***************************************************************************/ 7 ***************************************************************************/
8 8
9/*************************************************************************** 9/***************************************************************************
10 * * 10 * *
11 * This program is free software; you can redistribute it and/or modify * 11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by * 12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or * 13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. * 14 * (at your option) any later version. *
15 * * 15 * *
16 ***************************************************************************/ 16 ***************************************************************************/
17#include <fstream> 17#include <fstream>
18#include <iostream> 18#include <iostream>
19using namespace std; 19using namespace std;
20 20
21#include <stdio.h> 21#include <stdio.h>
22 22
23#include "datamgr.h" 23#include "datamgr.h"
24#include "global.h" 24#include "global.h"
25 25
26 26
27DataManager::DataManager() 27DataManager::DataManager()
28{ 28{
29 activeServer = ""; 29 activeServer = "";
30} 30}
31 31
32DataManager::~DataManager() 32DataManager::~DataManager()
33{ 33{
34} 34}
35 35
36Server *DataManager :: getServer( const char *name ) 36Server *DataManager :: getServer( const char *name )
37{ 37{
38 Server *s = 0; 38 Server *s = 0;
39 vector<Server>::iterator it = serverList.begin(); 39 vector<Server>::iterator it = serverList.begin();
40 while ( it != serverList.end() && s == 0 ) 40 while ( it != serverList.end() && s == 0 )
41 { 41 {
42 if ( it->getServerName() == name ) 42 if ( it->getServerName() == name )
43 s = &(*it); 43 s = &(*it);
44 44
45 ++it; 45 ++it;
46 } 46 }
47 47
48 return s; 48 return s;
49} 49}
50 50
51Destination *DataManager :: getDestination( const char *name ) 51Destination *DataManager :: getDestination( const char *name )
52{ 52{
53 Destination *d = 0; 53 Destination *d = 0;
54 vector<Destination>::iterator it = destList.begin(); 54 vector<Destination>::iterator it = destList.begin();
55 while ( it != destList.end() && d == 0 ) 55 while ( it != destList.end() && d == 0 )
56 { 56 {
57 if ( it->getDestinationName() == name ) 57 if ( it->getDestinationName() == name )
58 d = &(*it); 58 d = &(*it);
59 59
60 ++it; 60 ++it;
61 } 61 }
62 62
63 return d; 63 return d;
64} 64}
65 65
66void DataManager :: loadServers() 66void DataManager :: loadServers()
67{ 67{
68 // First add our local server - not really a server but 68 // First add our local server - not really a server but
69 // the local config (which packages are installed) 69 // the local config (which packages are installed)
70 serverList.push_back( Server( LOCAL_SERVER, "" ) ); 70 serverList.push_back( Server( LOCAL_SERVER, "" ) );
71 serverList.push_back( Server( LOCAL_IPKGS, "" ) ); 71 serverList.push_back( Server( LOCAL_IPKGS, "" ) );
72 72
73 // Read file from /etc/ipkg.conf 73 // Read file from /etc/ipkg.conf
74 QString ipkg_conf = IPKG_CONF; 74 QString ipkg_conf = IPKG_CONF;
75 FILE *fp; 75 FILE *fp;
76 fp = fopen( ipkg_conf, "r" ); 76 fp = fopen( ipkg_conf, "r" );
77 char line[130]; 77 char line[130];
78 QString lineStr; 78 QString lineStr;
79 if ( fp == NULL ) 79 if ( fp == NULL )
80 { 80 {
81 cout << "Couldn't open " << ipkg_conf << "! err = " << fp << endl; 81 cout << "Couldn't open " << ipkg_conf << "! err = " << fp << endl;
82 return; 82 return;
83 } 83 }
84 else 84 else
85 { 85 {
86 {
87 cout << "Before ipkg.conf read" << endl;
88 vector<Server>::iterator it;
89 for ( it = serverList.begin() ; it != serverList.end() ; ++it )
90 cout << "servername - " << it->getServerName() << endl;
91 }
92
86 while ( fgets( line, sizeof line, fp) != NULL ) 93 while ( fgets( line, sizeof line, fp) != NULL )
87 { 94 {
88 lineStr = line; 95 lineStr = line;
89 if ( lineStr.startsWith( "src" ) || lineStr.startsWith( "#src" ) ) 96 if ( lineStr.startsWith( "src" ) || lineStr.startsWith( "#src" ) || lineStr.startsWith( "# src" ) )
90 { 97 {
91 char alias[20]; 98 char alias[20];
92 char url[100]; 99 char url[100];
93 sscanf( lineStr, "%*[^ ] %s %s", alias, url ); 100
101
102 // Looks a little wierd but read up to the r of src (throwing it away),
103 // then read up to the next space and throw that away, the alias
104 // is next.
105 // Should Handle #src, # src, src, and combinations of
106 sscanf( lineStr, "%*[^r]%*[^ ] %s %s", alias, url );
107 cout << "Adding alias " << alias << " to list" << endl;
108 cout << lineStr << endl;
94 Server s( alias, url ); 109 Server s( alias, url );
95 serverList.push_back( s ); 110 serverList.push_back( s );
96 111
97 if ( lineStr.startsWith( "src" ) ) 112 if ( lineStr.startsWith( "src" ) )
98 setActiveServer( alias ); 113 setActiveServer( alias );
99 } 114 }
100 else if ( lineStr.startsWith( "dest" ) ) 115 else if ( lineStr.startsWith( "dest" ) )
101 { 116 {
102 char alias[20]; 117 char alias[20];
103 char path[50]; 118 char path[50];
104 sscanf( lineStr, "%*[^ ] %s %s", alias, path ); 119 sscanf( lineStr, "%*[^ ] %s %s", alias, path );
105 Destination d( alias, path ); 120 Destination d( alias, path );
106 destList.push_back( d ); 121 destList.push_back( d );
107 } 122 }
108 } 123 }
124 {
125 cout << "After ipkg.conf read" << endl;
126 vector<Server>::iterator it;
127 for ( it = serverList.begin() ; it != serverList.end() ; ++it )
128 cout << "servername - " << it->getServerName() << endl;
129 }
130
109 } 131 }
110 fclose( fp ); 132 fclose( fp );
111 133
112 // Go through the server destination list and add root, cf and card if they 134 // Go through the server destination list and add root, cf and card if they
113 // don't already exist 135 // don't already exist
114 /* AQ - commented out as if you don't have a CF or SD card in then 136/* AQ - commented out as if you don't have a CF or SD card in then
115 * this causes IPKG to try to create directories on non existant devices 137 * this causes IPKG to try to create directories on non existant devices
116 * (which of course fails), gives a nasty error message and can cause ipkg 138 * (which of course fails), gives a nasty error message and can cause ipkg
117 * to seg fault. 139 * to seg fault.
118 * 140 *
119 vector<Destination>::iterator dit; 141 vector<Destination>::iterator dit;
120 bool foundRoot = false; 142 bool foundRoot = false;
121 bool foundCF = false; 143 bool foundCF = false;
122 bool foundCard = false; 144 bool foundCard = false;
123 for ( dit = destList.begin() ; dit != destList.end() ; ++dit ) 145 for ( dit = destList.begin() ; dit != destList.end() ; ++dit )
124 { 146 {
125 if ( dit->getDestinationPath() == "/" ) 147 if ( dit->getDestinationPath() == "/" )
126 foundRoot = true; 148 foundRoot = true;
127 if ( dit->getDestinationPath() == "/mnt/cf" ) 149 if ( dit->getDestinationPath() == "/mnt/cf" )
128 foundCF = true; 150 foundCF = true;
129 if ( dit->getDestinationPath() == "/mnt/card" ) 151 if ( dit->getDestinationPath() == "/mnt/card" )
130 foundCard = true; 152 foundCard = true;
131 } 153 }
132 154
133 // If running on a Zaurus (arm) then if we didn't find root, CF or card 155 // If running on a Zaurus (arm) then if we didn't find root, CF or card
134 // destinations, add them as default 156 // destinations, add them as default
135#ifdef QWS 157#ifdef QWS
136#ifndef X86 158#ifndef X86
137 if ( !foundRoot ) 159 if ( !foundRoot )
138 destList.push_back( Destination( "root", "/" ) ); 160 destList.push_back( Destination( "root", "/" ) );
139 if ( !foundCF ) 161 if ( !foundCF )
140 destList.push_back( Destination( "cf", "/mnt/cf" ) ); 162 destList.push_back( Destination( "cf", "/mnt/cf" ) );
141 if ( !foundCF ) 163 if ( !foundCF )
142 destList.push_back( Destination( "card", "/mnt/card" ) ); 164 destList.push_back( Destination( "card", "/mnt/card" ) );
143#endif 165#endif
144#endif 166#endif
145*/ 167*/
146 vector<Server>::iterator it; 168 vector<Server>::iterator it;
147 for ( it = serverList.begin() ; it != serverList.end() ; ++it ) 169 for ( it = serverList.begin() ; it != serverList.end() ; ++it )
148 reloadServerData( it->getServerName() ); 170 reloadServerData( it->getServerName() );
149} 171}
150 172
151void DataManager :: reloadServerData( const char *serverName ) 173void DataManager :: reloadServerData( const char *serverName )
152{ 174{
153 Server *s = getServer( serverName ); 175 Server *s = getServer( serverName );
154 // Now we've read the config file in we need to read the servers 176 // Now we've read the config file in we need to read the servers
155 // The local server is a special case. This holds the contents of the 177 // The local server is a special case. This holds the contents of the
156 // status files the number of which depends on how many destinations 178 // status files the number of which depends on how many destinations
157 // we've set up 179 // we've set up
158 // The other servers files hold the contents of the server package list 180 // The other servers files hold the contents of the server package list
159 if ( s->getServerName() == LOCAL_SERVER ) 181 if ( s->getServerName() == LOCAL_SERVER )
160 s->readStatusFile( destList ); 182 s->readStatusFile( destList );
161 else if ( s->getServerName() == LOCAL_IPKGS ) 183 else if ( s->getServerName() == LOCAL_IPKGS )
162 s->readLocalIpks( getServer( LOCAL_SERVER ) ); 184 s->readLocalIpks( getServer( LOCAL_SERVER ) );
163 else 185 else
164 s->readPackageFile( getServer( LOCAL_SERVER ) ); 186 s->readPackageFile( getServer( LOCAL_SERVER ) );
165 187
166} 188}
167 189
168void DataManager :: writeOutIpkgConf() 190void DataManager :: writeOutIpkgConf()
169{ 191{
170 QString ipkg_conf = IPKG_CONF; 192 QString ipkg_conf = IPKG_CONF;
171 ofstream out( ipkg_conf ); 193 ofstream out( ipkg_conf );
172 194
173 out << "# Written by NetworkPackageManager Package Manager" << endl; 195 out << "# Written by AQPkg" << endl;
196 out << "# Must have one or more source entries of the form:" << endl;
197 out << "#" << endl;
198 out << "# src <src-name> <source-url>" << endl;
199 out << "#" << endl;
200 out << "# and one or more destination entries of the form:" << endl;
201 out << "#" << endl;
202 out << "# dest <dest-name> <target-path>" << endl;
203 out << "#" << endl;
204 out << "# where <src-name> and <dest-names> are identifiers that" << endl;
205 out << "# should match [a-zA-Z0-9._-]+, <source-url> should be a" << endl;
206 out << "# URL that points to a directory containing a Familiar" << endl;
207 out << "# Packages file, and <target-path> should be a directory" << endl;
208 out << "# that exists on the target system." << endl << endl;
174 209
175 // Write out servers 210 // Write out servers
176 vector<Server>::iterator it = serverList.begin(); 211 vector<Server>::iterator it = serverList.begin();
177 while ( it != serverList.end() ) 212 while ( it != serverList.end() )
178 { 213 {
179 QString alias = it->getServerName(); 214 QString alias = it->getServerName();
180 // Don't write out local as its a dummy 215 // Don't write out local as its a dummy
181 if ( alias != LOCAL_SERVER && alias != LOCAL_IPKGS ) 216 if ( alias != LOCAL_SERVER && alias != LOCAL_IPKGS )
182 { 217 {
183 QString url = it->getServerUrl();; 218 QString url = it->getServerUrl();;
184 219
185 if ( !activeServer || alias != activeServer ) 220 if ( !activeServer || alias != activeServer )
186 out << "#"; 221 out << "#";
187 out << "src " << alias << " " << url << endl; 222 out << "src " << alias << " " << url << endl;
188 } 223 }
189 224
190 it++; 225 it++;
191 } 226 }
192 227
228 out << endl;
229
193 // Write out destinations 230 // Write out destinations
194 vector<Destination>::iterator it2 = destList.begin(); 231 vector<Destination>::iterator it2 = destList.begin();
195 while ( it2 != destList.end() ) 232 while ( it2 != destList.end() )
196 { 233 {
197 out << "dest " << it2->getDestinationName() << " " << it2->getDestinationPath() << endl; 234 out << "dest " << it2->getDestinationName() << " " << it2->getDestinationPath() << endl;
198 it2++; 235 it2++;
199 } 236 }
200 237
201 out.close(); 238 out.close();
202} 239}