001-ipkg.patch 424 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737
  1. diff -Nur busybox-1.17.1.orig/archival/Config.src busybox-1.17.1/archival/Config.src
  2. --- busybox-1.17.1.orig/archival/Config.src 2010-07-25 00:12:56.000000000 +0200
  3. +++ busybox-1.17.1/archival/Config.src 2010-07-28 13:07:49.435987872 +0200
  4. @@ -202,6 +202,12 @@
  5. are actually slower than gzip at equivalent compression ratios
  6. and take up 3.2K of code.
  7. +config IPKG
  8. + bool "ipkg"
  9. + default n
  10. + help
  11. + ipkg is the itsy package management system.
  12. +
  13. config RPM2CPIO
  14. bool "rpm2cpio"
  15. default y
  16. diff -Nur busybox-1.17.1.orig/archival/ipkg.c busybox-1.17.1/archival/ipkg.c
  17. --- busybox-1.17.1.orig/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
  18. +++ busybox-1.17.1/archival/ipkg.c 2010-07-28 13:07:49.439598667 +0200
  19. @@ -0,0 +1,28 @@
  20. +/* ipkg.c - the itsy package management system
  21. +
  22. + Florina Boor
  23. +
  24. + Copyright (C) 2003 kernel concepts
  25. +
  26. + This program is free software; you can redistribute it and/or
  27. + modify it under the terms of the GNU General Public License as
  28. + published by the Free Software Foundation; either version 2, or (at
  29. + your option) any later version.
  30. +
  31. + This program is distributed in the hope that it will be useful, but
  32. + WITHOUT ANY WARRANTY; without even the implied warranty of
  33. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  34. + General Public License for more details.
  35. +
  36. + ipkg command line frontend using libipkg
  37. +
  38. +*/
  39. +
  40. +#include "libbb.h"
  41. +#include "libipkg/libipkg.h"
  42. +
  43. +int ipkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  44. +int ipkg_main(int argc, char **argv)
  45. +{
  46. + return ipkg_op(argc, argv);
  47. +}
  48. diff -Nur busybox-1.17.1.orig/archival/Kbuild.src busybox-1.17.1/archival/Kbuild.src
  49. --- busybox-1.17.1.orig/archival/Kbuild.src 2010-07-06 04:25:53.000000000 +0200
  50. +++ busybox-1.17.1/archival/Kbuild.src 2010-07-28 13:07:49.439598667 +0200
  51. @@ -23,6 +23,7 @@
  52. lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o
  53. lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
  54. lib-$(CONFIG_BZIP2) += bzip2.o bbunzip.o
  55. +lib-$(CONFIG_IPKG) += ipkg.o
  56. lib-$(CONFIG_UNXZ) += bbunzip.o
  57. lib-$(CONFIG_UNLZMA) += bbunzip.o
  58. diff -Nur busybox-1.17.1.orig/archival/libipkg/args.c busybox-1.17.1/archival/libipkg/args.c
  59. --- busybox-1.17.1.orig/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
  60. +++ busybox-1.17.1/archival/libipkg/args.c 2010-07-28 13:07:49.443599457 +0200
  61. @@ -0,0 +1,242 @@
  62. +/* args.c - parse command-line args
  63. +
  64. + Carl D. Worth
  65. +
  66. + Copyright 2001 University of Southern California
  67. +
  68. + This program is free software; you can redistribute it and/or modify
  69. + it under the terms of the GNU General Public License as published by
  70. + the Free Software Foundation; either version 2, or (at your option)
  71. + any later version.
  72. +
  73. + This program is distributed in the hope that it will be useful,
  74. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  75. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  76. + GNU General Public License for more details.
  77. + */
  78. +
  79. +#include <getopt.h>
  80. +#include <stdlib.h>
  81. +#include <string.h>
  82. +#include <unistd.h>
  83. +
  84. +#include "ipkg.h"
  85. +#include "ipkg_message.h"
  86. +
  87. +#include "args.h"
  88. +#include "sprintf_alloc.h"
  89. +
  90. +#include "libbb.h"
  91. +
  92. +
  93. +static void print_version(void);
  94. +
  95. +enum long_args_opt
  96. +{
  97. + ARGS_OPT_FORCE_DEFAULTS = 129,
  98. + ARGS_OPT_FORCE_DEPENDS,
  99. + ARGS_OPT_FORCE_OVERWRITE,
  100. + ARGS_OPT_FORCE_DOWNGRADE,
  101. + ARGS_OPT_FORCE_REINSTALL,
  102. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
  103. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
  104. + ARGS_OPT_FORCE_SPACE,
  105. + ARGS_OPT_NOACTION,
  106. + ARGS_OPT_NODEPS,
  107. + ARGS_OPT_VERBOSE_WGET,
  108. + ARGS_OPT_VERBOSITY,
  109. + ARGS_OPT_MULTIPLE_PROVIDERS
  110. +};
  111. +
  112. +int args_init(args_t *args)
  113. +{
  114. + const char *conf_file_dir;
  115. +
  116. + memset(args, 0, sizeof(args_t));
  117. +
  118. + args->dest = ARGS_DEFAULT_DEST;
  119. +
  120. + conf_file_dir = getenv("IPKG_CONF_DIR");
  121. + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
  122. + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
  123. + }
  124. + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
  125. + ARGS_DEFAULT_CONF_FILE_NAME);
  126. +
  127. + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
  128. + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
  129. + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
  130. + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
  131. + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
  132. + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
  133. + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
  134. + args->noaction = ARGS_DEFAULT_NOACTION;
  135. + args->nodeps = ARGS_DEFAULT_NODEPS;
  136. + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
  137. + args->verbosity = ARGS_DEFAULT_VERBOSITY;
  138. + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
  139. + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
  140. + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
  141. + args->multiple_providers = 0;
  142. + args->nocheckfordirorfile = 0;
  143. + args->noreadfeedsfile = 0;
  144. +
  145. + return 1;
  146. +}
  147. +
  148. +void args_deinit(args_t *args)
  149. +{
  150. + free(args->conf_file);
  151. + args->conf_file = NULL;
  152. +}
  153. +
  154. +int args_parse(args_t *args, int argc, char *argv[])
  155. +{
  156. + int c;
  157. + int option_index = 0;
  158. + int parse_err = 0;
  159. + static struct option long_options[] = {
  160. + {"query-all", 0, 0, 'A'},
  161. + {"conf-file", 1, 0, 'f'},
  162. + {"conf", 1, 0, 'f'},
  163. + {"dest", 1, 0, 'd'},
  164. + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  165. + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  166. + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  167. + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  168. + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  169. + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  170. + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  171. + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  172. + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  173. + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  174. + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
  175. + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
  176. + {"recursive", 0, 0,
  177. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  178. + {"force-removal-of-dependent-packages", 0, 0,
  179. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  180. + {"force_removal_of_dependent_packages", 0, 0,
  181. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  182. + {"force-removal-of-essential-packages", 0, 0,
  183. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  184. + {"force_removal_of_essential_packages", 0, 0,
  185. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  186. + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  187. + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  188. + {"noaction", 0, 0, ARGS_OPT_NOACTION},
  189. + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
  190. + {"offline", 1, 0, 'o'},
  191. + {"offline-root", 1, 0, 'o'},
  192. + {"test", 0, 0, ARGS_OPT_NOACTION},
  193. + {"tmp-dir", 1, 0, 't'},
  194. + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  195. + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  196. + {"verbosity", 2, 0, 'V'},
  197. + {"version", 0, 0, 'v'},
  198. + {0, 0, 0, 0}
  199. + };
  200. +
  201. + while (1) {
  202. + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
  203. + if (c == -1)
  204. + break;
  205. +
  206. + switch (c) {
  207. + case 'A':
  208. + args->query_all = 1;
  209. + break;
  210. + case 'd':
  211. + args->dest = optarg;
  212. + break;
  213. + case 'f':
  214. + free(args->conf_file);
  215. + args->conf_file = strdup(optarg);
  216. + break;
  217. + case 'o':
  218. + args->offline_root = optarg;
  219. + break;
  220. + case 'n':
  221. + args->noaction = 1;
  222. + break;
  223. + case 't':
  224. + args->tmp_dir = strdup(optarg);
  225. + break;
  226. + case 'v':
  227. + print_version();
  228. + exit(0);
  229. + case 'V':
  230. + case ARGS_OPT_VERBOSITY:
  231. + if (optarg)
  232. + args->verbosity = atoi(optarg);
  233. + else
  234. + args->verbosity += 1;
  235. + break;
  236. + case ARGS_OPT_FORCE_DEFAULTS:
  237. + args->force_defaults = 1;
  238. + break;
  239. + case ARGS_OPT_FORCE_DEPENDS:
  240. + args->force_depends = 1;
  241. + break;
  242. + case ARGS_OPT_FORCE_OVERWRITE:
  243. + args->force_overwrite = 1;
  244. + break;
  245. + case ARGS_OPT_FORCE_DOWNGRADE:
  246. + args->force_downgrade = 1;
  247. + break;
  248. + case ARGS_OPT_FORCE_REINSTALL:
  249. + args->force_reinstall = 1;
  250. + break;
  251. + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
  252. + args->force_removal_of_essential_packages = 1;
  253. + break;
  254. + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
  255. + args->force_removal_of_dependent_packages = 1;
  256. + break;
  257. + case ARGS_OPT_FORCE_SPACE:
  258. + args->force_space = 1;
  259. + break;
  260. + case ARGS_OPT_VERBOSE_WGET:
  261. + args->verbose_wget = 1;
  262. + break;
  263. + case ARGS_OPT_MULTIPLE_PROVIDERS:
  264. + args->multiple_providers = 1;
  265. + break;
  266. + case ARGS_OPT_NODEPS:
  267. + args->nodeps = 1;
  268. + break;
  269. + case ARGS_OPT_NOACTION:
  270. + args->noaction = 1;
  271. + break;
  272. + case ':':
  273. + parse_err++;
  274. + break;
  275. + case '?':
  276. + parse_err++;
  277. + break;
  278. + default:
  279. + bb_error_msg("Confusion: getopt_long returned %d\n", c);
  280. + }
  281. + }
  282. +
  283. + if (parse_err) {
  284. + return -parse_err;
  285. + } else {
  286. + return optind;
  287. + }
  288. +}
  289. +
  290. +void args_usage(const char *complaint)
  291. +{
  292. + if (complaint) {
  293. + bb_error_msg("%s\n", complaint);
  294. + }
  295. + print_version();
  296. + bb_show_usage();
  297. + exit(1);
  298. +}
  299. +
  300. +static void print_version(void)
  301. +{
  302. + bb_error_msg("version %s\n", IPKG_VERSION);
  303. +}
  304. diff -Nur busybox-1.17.1.orig/archival/libipkg/args.h busybox-1.17.1/archival/libipkg/args.h
  305. --- busybox-1.17.1.orig/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
  306. +++ busybox-1.17.1/archival/libipkg/args.h 2010-07-28 13:07:49.443599457 +0200
  307. @@ -0,0 +1,72 @@
  308. +/* args.h - parse command-line args
  309. +
  310. + Carl D. Worth
  311. +
  312. + Copyright 2001 University of Southern California
  313. +
  314. + This program is free software; you can redistribute it and/or modify
  315. + it under the terms of the GNU General Public License as published by
  316. + the Free Software Foundation; either version 2, or (at your option)
  317. + any later version.
  318. +
  319. + This program is distributed in the hope that it will be useful,
  320. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  321. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  322. + GNU General Public License for more details.
  323. +*/
  324. +
  325. +#ifndef ARGS_H
  326. +#define ARGS_H
  327. +
  328. +struct args
  329. +{
  330. + char *conf_file;
  331. + char *dest;
  332. + char *tmp_dir;
  333. + int force_defaults;
  334. + int force_depends;
  335. + int force_overwrite;
  336. + int force_downgrade;
  337. + int force_reinstall;
  338. + int force_removal_of_essential_packages;
  339. + int force_removal_of_dependent_packages;
  340. + int force_space;
  341. + int noaction;
  342. + int nodeps;
  343. + int multiple_providers;
  344. + int query_all;
  345. + int verbose_wget;
  346. + int verbosity;
  347. + int nocheckfordirorfile;
  348. + int noreadfeedsfile;
  349. + char *offline_root;
  350. + char *offline_root_pre_script_cmd;
  351. + char *offline_root_post_script_cmd;
  352. +};
  353. +typedef struct args args_t;
  354. +
  355. +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
  356. +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
  357. +#define ARGS_DEFAULT_DEST NULL
  358. +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
  359. +#define ARGS_DEFAULT_FORCE_DEPENDS 0
  360. +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
  361. +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
  362. +#define ARGS_DEFAULT_FORCE_REINSTALL 0
  363. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
  364. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
  365. +#define ARGS_DEFAULT_FORCE_SPACE 0
  366. +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
  367. +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
  368. +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
  369. +#define ARGS_DEFAULT_NOACTION 0
  370. +#define ARGS_DEFAULT_NODEPS 0
  371. +#define ARGS_DEFAULT_VERBOSE_WGET 0
  372. +#define ARGS_DEFAULT_VERBOSITY 1
  373. +
  374. +int args_init(args_t *args);
  375. +void args_deinit(args_t *args);
  376. +int args_parse(args_t *args, int argc, char *argv[]);
  377. +void args_usage(const char *complaint);
  378. +
  379. +#endif
  380. diff -Nur busybox-1.17.1.orig/archival/libipkg/conffile.c busybox-1.17.1/archival/libipkg/conffile.c
  381. --- busybox-1.17.1.orig/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
  382. +++ busybox-1.17.1/archival/libipkg/conffile.c 2010-07-28 13:07:49.443599457 +0200
  383. @@ -0,0 +1,65 @@
  384. +/* conffile.c - the itsy package management system
  385. +
  386. + Carl D. Worth
  387. +
  388. + Copyright (C) 2001 University of Southern California
  389. +
  390. + This program is free software; you can redistribute it and/or
  391. + modify it under the terms of the GNU General Public License as
  392. + published by the Free Software Foundation; either version 2, or (at
  393. + your option) any later version.
  394. +
  395. + This program is distributed in the hope that it will be useful, but
  396. + WITHOUT ANY WARRANTY; without even the implied warranty of
  397. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  398. + General Public License for more details.
  399. +*/
  400. +
  401. +#include <string.h>
  402. +#include <stdlib.h>
  403. +
  404. +#include "libbb.h"
  405. +#include "ipkg.h"
  406. +#include "ipkg_message.h"
  407. +
  408. +#include "conffile.h"
  409. +#include "file_util.h"
  410. +#include "sprintf_alloc.h"
  411. +
  412. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum)
  413. +{
  414. + return nv_pair_init(conffile, file_name, (char *)md5sum);
  415. +}
  416. +
  417. +void conffile_deinit(conffile_t *conffile)
  418. +{
  419. + nv_pair_deinit(conffile);
  420. +}
  421. +
  422. +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
  423. +{
  424. + uint8_t *md5sum;
  425. + char *filename = conffile->name;
  426. + char *root_filename;
  427. + int ret;
  428. +
  429. + if (conffile->value == NULL) {
  430. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
  431. + return 1;
  432. + }
  433. +
  434. + root_filename = root_filename_alloc(conf, filename);
  435. +
  436. + md5sum = file_md5sum_alloc(root_filename);
  437. +
  438. + ret = strcmp((char *)md5sum, conffile->value);
  439. + if (ret) {
  440. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
  441. + conffile->name, md5sum, conffile->value);
  442. + }
  443. +
  444. + free(root_filename);
  445. + free(md5sum);
  446. +
  447. + return ret;
  448. +}
  449. diff -Nur busybox-1.17.1.orig/archival/libipkg/conffile.h busybox-1.17.1/archival/libipkg/conffile.h
  450. --- busybox-1.17.1.orig/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
  451. +++ busybox-1.17.1/archival/libipkg/conffile.h 2010-07-28 13:07:49.451597683 +0200
  452. @@ -0,0 +1,30 @@
  453. +/* conffile.h - the itsy package management system
  454. +
  455. + Carl D. Worth
  456. +
  457. + Copyright (C) 2001 University of Southern California
  458. +
  459. + This program is free software; you can redistribute it and/or
  460. + modify it under the terms of the GNU General Public License as
  461. + published by the Free Software Foundation; either version 2, or (at
  462. + your option) any later version.
  463. +
  464. + This program is distributed in the hope that it will be useful, but
  465. + WITHOUT ANY WARRANTY; without even the implied warranty of
  466. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  467. + General Public License for more details.
  468. +*/
  469. +
  470. +#ifndef CONFFILE_H
  471. +#define CONFFILE_H
  472. +
  473. +#include "nv_pair.h"
  474. +
  475. +typedef struct nv_pair conffile_t;
  476. +
  477. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum);
  478. +void conffile_deinit(conffile_t *conffile);
  479. +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
  480. +
  481. +#endif
  482. +
  483. diff -Nur busybox-1.17.1.orig/archival/libipkg/conffile_list.c busybox-1.17.1/archival/libipkg/conffile_list.c
  484. --- busybox-1.17.1.orig/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
  485. +++ busybox-1.17.1/archival/libipkg/conffile_list.c 2010-07-28 13:07:49.451597683 +0200
  486. @@ -0,0 +1,47 @@
  487. +/* conffile_list.c - the itsy package management system
  488. +
  489. + Carl D. Worth
  490. +
  491. + Copyright (C) 2001 University of Southern California
  492. +
  493. + This program is free software; you can redistribute it and/or
  494. + modify it under the terms of the GNU General Public License as
  495. + published by the Free Software Foundation; either version 2, or (at
  496. + your option) any later version.
  497. +
  498. + This program is distributed in the hope that it will be useful, but
  499. + WITHOUT ANY WARRANTY; without even the implied warranty of
  500. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  501. + General Public License for more details.
  502. +*/
  503. +
  504. +#include "ipkg.h"
  505. +
  506. +#include "conffile_list.h"
  507. +
  508. +int conffile_list_init(conffile_list_t *list)
  509. +{
  510. + return nv_pair_list_init(list);
  511. +}
  512. +
  513. +void conffile_list_deinit(conffile_list_t *list)
  514. +{
  515. + nv_pair_list_deinit(list);
  516. +}
  517. +
  518. +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
  519. + const char *md5sum)
  520. +{
  521. + return nv_pair_list_append(list, file_name, md5sum);
  522. +}
  523. +
  524. +int conffile_list_push(conffile_list_t *list, conffile_t *data)
  525. +{
  526. + return nv_pair_list_push(list, data);
  527. +}
  528. +
  529. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
  530. +{
  531. + return nv_pair_list_pop(list);
  532. +}
  533. +
  534. diff -Nur busybox-1.17.1.orig/archival/libipkg/conffile_list.h busybox-1.17.1/archival/libipkg/conffile_list.h
  535. --- busybox-1.17.1.orig/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
  536. +++ busybox-1.17.1/archival/libipkg/conffile_list.h 2010-07-28 13:07:49.451597683 +0200
  537. @@ -0,0 +1,36 @@
  538. +/* conffile_list.h - the itsy package management system
  539. +
  540. + Carl D. Worth
  541. +
  542. + Copyright (C) 2001 University of Southern California
  543. +
  544. + This program is free software; you can redistribute it and/or
  545. + modify it under the terms of the GNU General Public License as
  546. + published by the Free Software Foundation; either version 2, or (at
  547. + your option) any later version.
  548. +
  549. + This program is distributed in the hope that it will be useful, but
  550. + WITHOUT ANY WARRANTY; without even the implied warranty of
  551. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  552. + General Public License for more details.
  553. +*/
  554. +
  555. +#ifndef CONFFILE_LIST_H
  556. +#define CONFFILE_LIST_H
  557. +
  558. +#include "conffile.h"
  559. +#include "nv_pair_list.h"
  560. +
  561. +typedef struct nv_pair_list_elt conffile_list_elt_t;
  562. +typedef struct nv_pair_list conffile_list_t;
  563. +
  564. +int conffile_list_init(conffile_list_t *list);
  565. +void conffile_list_deinit(conffile_list_t *list);
  566. +
  567. +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
  568. + const char *root_dir);
  569. +int conffile_list_push(conffile_list_t *list, conffile_t *data);
  570. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
  571. +
  572. +#endif
  573. +
  574. diff -Nur busybox-1.17.1.orig/archival/libipkg/file_util.c busybox-1.17.1/archival/libipkg/file_util.c
  575. --- busybox-1.17.1.orig/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
  576. +++ busybox-1.17.1/archival/libipkg/file_util.c 2010-07-28 13:07:49.455597914 +0200
  577. @@ -0,0 +1,186 @@
  578. +/* file_util.c - convenience routines for common stat operations
  579. +
  580. + Carl D. Worth
  581. +
  582. + Copyright (C) 2001 University of Southern California
  583. +
  584. + This program is free software; you can redistribute it and/or
  585. + modify it under the terms of the GNU General Public License as
  586. + published by the Free Software Foundation; either version 2, or (at
  587. + your option) any later version.
  588. +
  589. + This program is distributed in the hope that it will be useful, but
  590. + WITHOUT ANY WARRANTY; without even the implied warranty of
  591. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  592. + General Public License for more details.
  593. +*/
  594. +
  595. +#include "ipkg.h"
  596. +#include <sys/types.h>
  597. +#include <sys/stat.h>
  598. +
  599. +#include "sprintf_alloc.h"
  600. +#include "file_util.h"
  601. +#include "libbb.h"
  602. +#undef strlen
  603. +
  604. +int file_exists(const char *file_name)
  605. +{
  606. + int err;
  607. + struct stat stat_buf;
  608. +
  609. + err = stat(file_name, &stat_buf);
  610. + if (err == 0) {
  611. + return 1;
  612. + } else {
  613. + return 0;
  614. + }
  615. +}
  616. +
  617. +int file_is_dir(const char *file_name)
  618. +{
  619. + int err;
  620. + struct stat stat_buf;
  621. +
  622. + err = stat(file_name, &stat_buf);
  623. + if (err) {
  624. + return 0;
  625. + }
  626. +
  627. + return S_ISDIR(stat_buf.st_mode);
  628. +}
  629. +
  630. +/* read a single line from a file, stopping at a newline or EOF.
  631. + If a newline is read, it will appear in the resulting string.
  632. + Return value is a malloc'ed char * which should be freed at
  633. + some point by the caller.
  634. +
  635. + Return value is NULL if the file is at EOF when called.
  636. +*/
  637. +#define FILE_READ_LINE_BUF_SIZE 1024
  638. +char *file_read_line_alloc(FILE *file)
  639. +{
  640. + char buf[FILE_READ_LINE_BUF_SIZE];
  641. + int buf_len;
  642. + char *line = NULL;
  643. + int line_size = 0;
  644. +
  645. + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
  646. + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
  647. + buf_len = strlen(buf);
  648. + if (line) {
  649. + line_size += buf_len;
  650. + line = realloc(line, line_size);
  651. + if (line == NULL) {
  652. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  653. + break;
  654. + }
  655. + strcat(line, buf);
  656. + } else {
  657. + line_size = buf_len + 1;
  658. + line = strdup(buf);
  659. + }
  660. + if (buf[buf_len - 1] == '\n') {
  661. + break;
  662. + }
  663. + }
  664. +
  665. + return line;
  666. +}
  667. +
  668. +int file_move(const char *src, const char *dest)
  669. +{
  670. + int err;
  671. +
  672. + err = rename(src, dest);
  673. +
  674. + if (err && errno == EXDEV) {
  675. + err = file_copy(src, dest);
  676. + unlink(src);
  677. + } else if (err) {
  678. + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
  679. + __FUNCTION__, src, dest, strerror(errno));
  680. + }
  681. +
  682. + return err;
  683. +}
  684. +
  685. +/* I put these here to keep libbb dependencies from creeping all over
  686. + the ipkg code */
  687. +int file_copy(const char *src, const char *dest)
  688. +{
  689. + int err;
  690. +
  691. + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
  692. + if (err) {
  693. + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
  694. + __FUNCTION__, src, dest);
  695. + }
  696. +
  697. + return err;
  698. +}
  699. +
  700. +int file_mkdir_hier(char *path, long mode)
  701. +{
  702. + return bb_make_directory(path, mode, FILEUTILS_RECUR);
  703. +}
  704. +
  705. +static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
  706. + unsigned hash_length)
  707. +{
  708. + /* xzalloc zero-terminates */
  709. + char *hex_value = xzalloc((hash_length * 2) + 1);
  710. + bin2hex(hex_value, (char*)hash_value, hash_length);
  711. + return (unsigned char *)hex_value;
  712. +}
  713. +
  714. +static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
  715. +{
  716. + int src_fd, hash_len, count;
  717. + union _ctx_ {
  718. + sha1_ctx_t sha1;
  719. + md5_ctx_t md5;
  720. + } context;
  721. + uint8_t *hash_value = NULL;
  722. + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
  723. + void FAST_FUNC (*update)(const void*, size_t, void*);
  724. + void FAST_FUNC (*final)(void*, void*);
  725. +
  726. + src_fd = open_or_warn_stdin(filename);
  727. + if (src_fd < 0) {
  728. + return NULL;
  729. + }
  730. +
  731. + /* figure specific hash algorithims */
  732. + if (ENABLE_MD5SUM && hash_algo == HASH_MD5) {
  733. + md5_begin(&context.md5);
  734. + update = (void*)md5_hash;
  735. + final = (void*)md5_end;
  736. + hash_len = 16;
  737. + } else {
  738. + bb_error_msg_and_die("algorithm not supported");
  739. + }
  740. +
  741. + while (0 < (count = safe_read(src_fd, in_buf, 4096))) {
  742. + update(in_buf, count, &context);
  743. + }
  744. +
  745. + if (count == 0) {
  746. + final(in_buf, &context);
  747. + hash_value = hash_bin_to_hex(in_buf, hash_len);
  748. + }
  749. +
  750. + RELEASE_CONFIG_BUFFER(in_buf);
  751. +
  752. + if (src_fd != STDIN_FILENO) {
  753. + close(src_fd);
  754. + }
  755. +
  756. + return hash_value;
  757. +}
  758. +
  759. +uint8_t *file_md5sum_alloc(const char *file_name)
  760. +{
  761. + return hash_file(file_name, HASH_MD5);
  762. +}
  763. +
  764. diff -Nur busybox-1.17.1.orig/archival/libipkg/file_util.h busybox-1.17.1/archival/libipkg/file_util.h
  765. --- busybox-1.17.1.orig/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
  766. +++ busybox-1.17.1/archival/libipkg/file_util.h 2010-07-28 13:07:49.455597914 +0200
  767. @@ -0,0 +1,29 @@
  768. +/* file_util.h - convenience routines for common file operations
  769. +
  770. + Carl D. Worth
  771. +
  772. + Copyright (C) 2001 University of Southern California
  773. +
  774. + This program is free software; you can redistribute it and/or
  775. + modify it under the terms of the GNU General Public License as
  776. + published by the Free Software Foundation; either version 2, or (at
  777. + your option) any later version.
  778. +
  779. + This program is distributed in the hope that it will be useful, but
  780. + WITHOUT ANY WARRANTY; without even the implied warranty of
  781. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  782. + General Public License for more details.
  783. +*/
  784. +
  785. +#ifndef FILE_UTIL_H
  786. +#define FILE_UTIL_H
  787. +
  788. +int file_exists(const char *file_name);
  789. +int file_is_dir(const char *file_name);
  790. +char *file_read_line_alloc(FILE *file);
  791. +int file_move(const char *src, const char *dest);
  792. +int file_copy(const char *src, const char *dest);
  793. +int file_mkdir_hier(char *path, long mode);
  794. +uint8_t *file_md5sum_alloc(const char *file_name);
  795. +
  796. +#endif
  797. diff -Nur busybox-1.17.1.orig/archival/libipkg/hash_table.c busybox-1.17.1/archival/libipkg/hash_table.c
  798. --- busybox-1.17.1.orig/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
  799. +++ busybox-1.17.1/archival/libipkg/hash_table.c 2010-07-28 13:07:49.455597914 +0200
  800. @@ -0,0 +1,155 @@
  801. +/* hash.c - hash tables for ipkg
  802. +
  803. + Steven M. Ayer, Jamey Hicks
  804. +
  805. + Copyright (C) 2002 Compaq Computer Corporation
  806. +
  807. + This program is free software; you can redistribute it and/or
  808. + modify it under the terms of the GNU General Public License as
  809. + published by the Free Software Foundation; either version 2, or (at
  810. + your option) any later version.
  811. +
  812. + This program is distributed in the hope that it will be useful, but
  813. + WITHOUT ANY WARRANTY; without even the implied warranty of
  814. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  815. + General Public License for more details.
  816. +*/
  817. +
  818. +#include <errno.h>
  819. +#include <stdio.h>
  820. +#include <stdlib.h>
  821. +#include <string.h>
  822. +#include "hash_table.h"
  823. +#include "ipkg_message.h"
  824. +
  825. +
  826. +static int hash_index(hash_table_t *hash, const char *pkg_name);
  827. +static int rotating(const char *key, int len, int prime);
  828. +
  829. +static int hash_index(hash_table_t *hash, const char *pkg_name)
  830. +{
  831. + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
  832. +}
  833. +
  834. +static int rotating(const char *key, int len, int prime)
  835. +{
  836. + unsigned int hash, i;
  837. + for (hash=len, i=0; i<len; ++i)
  838. + hash = (hash<<4)^(hash>>28)^key[i];
  839. + return (hash % prime);
  840. +}
  841. +
  842. +
  843. +/*
  844. + * this is an open table keyed by strings
  845. + */
  846. +int hash_table_init(const char *name, hash_table_t *hash, int len)
  847. +{
  848. + static int primes_table[] = {
  849. + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
  850. + 19471, 23143, 33961, 46499, 49727, 99529, 0
  851. + };
  852. + int *picker;
  853. +
  854. + if (hash->entries != NULL) {
  855. + /* we have been here already */
  856. + return 0;
  857. + }
  858. +
  859. + hash->name = name;
  860. + hash->entries = NULL;
  861. + hash->n_entries = 0;
  862. + hash->hash_entry_key = NULL;
  863. +
  864. + picker = primes_table;
  865. + while(*picker && (*picker++ < len));
  866. + if(!*picker)
  867. + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
  868. + --picker;
  869. +
  870. + hash->n_entries = *picker;
  871. + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
  872. + if (hash->entries == NULL) {
  873. + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
  874. + return ENOMEM;
  875. + }
  876. + return 0;
  877. +}
  878. +
  879. +void hash_table_deinit(hash_table_t *hash)
  880. +{
  881. + free(hash->entries);
  882. + hash->entries = NULL;
  883. + hash->n_entries = 0;
  884. +}
  885. +
  886. +void *hash_table_get(hash_table_t *hash, const char *key)
  887. +{
  888. + int ndx= hash_index(hash, key);
  889. + hash_entry_t *hash_entry = hash->entries + ndx;
  890. + while (hash_entry)
  891. + {
  892. + if (hash_entry->key)
  893. + {
  894. + if (strcmp(key, hash_entry->key) == 0) {
  895. + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
  896. + return hash_entry->data;
  897. + }
  898. + }
  899. + hash_entry = hash_entry->next;
  900. + }
  901. + return NULL;
  902. +}
  903. +
  904. +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
  905. +{
  906. + int ndx= hash_index(hash, key);
  907. + hash_entry_t *hash_entry = hash->entries + ndx;
  908. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
  909. + if (hash_entry->key) {
  910. + if (strcmp(hash_entry->key, key) == 0) {
  911. + /* alread in table, update the value */
  912. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
  913. + hash_entry->data = value;
  914. + return 0;
  915. + } else {
  916. + /*
  917. + * if this is a collision, we have to go to the end of the ll,
  918. + * then add a new entry
  919. + * before we can hook up the value
  920. + */
  921. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
  922. + while (hash_entry->next)
  923. + hash_entry = hash_entry->next;
  924. + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
  925. + if (!hash_entry->next) {
  926. + return -ENOMEM;
  927. + }
  928. + hash_entry = hash_entry->next;
  929. + hash_entry->next = NULL;
  930. + }
  931. + }
  932. + hash->n_elements++;
  933. + hash_entry->key = strdup(key);
  934. + hash_entry->data = value;
  935. +
  936. + return 0;
  937. +}
  938. +
  939. +
  940. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
  941. +{
  942. + int i;
  943. + if (!hash || !f)
  944. + return;
  945. +
  946. + for (i = 0; i < hash->n_entries; i++) {
  947. + hash_entry_t *hash_entry = (hash->entries + i);
  948. + do {
  949. + if(hash_entry->key) {
  950. + f(hash_entry->key, hash_entry->data, data);
  951. + }
  952. + } while((hash_entry = hash_entry->next));
  953. + }
  954. +}
  955. +
  956. diff -Nur busybox-1.17.1.orig/archival/libipkg/hash_table.h busybox-1.17.1/archival/libipkg/hash_table.h
  957. --- busybox-1.17.1.orig/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
  958. +++ busybox-1.17.1/archival/libipkg/hash_table.h 2010-07-28 13:07:49.455597914 +0200
  959. @@ -0,0 +1,44 @@
  960. +/* hash.h - hash tables for ipkg
  961. +
  962. + Steven M. Ayer, Jamey Hicks
  963. +
  964. + Copyright (C) 2002 Compaq Computer Corporation
  965. +
  966. + This program is free software; you can redistribute it and/or
  967. + modify it under the terms of the GNU General Public License as
  968. + published by the Free Software Foundation; either version 2, or (at
  969. + your option) any later version.
  970. +
  971. + This program is distributed in the hope that it will be useful, but
  972. + WITHOUT ANY WARRANTY; without even the implied warranty of
  973. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  974. + General Public License for more details.
  975. +*/
  976. +
  977. +#ifndef _HASH_TABLE_H_
  978. +#define _HASH_TABLE_H_
  979. +
  980. +typedef struct hash_entry hash_entry_t;
  981. +typedef struct hash_table hash_table_t;
  982. +
  983. +struct hash_entry {
  984. + const char * key;
  985. + void * data;
  986. + struct hash_entry * next;
  987. +};
  988. +
  989. +struct hash_table {
  990. + const char *name;
  991. + hash_entry_t * entries;
  992. + int n_entries; /* number of buckets */
  993. + int n_elements;
  994. + const char * (*hash_entry_key)(void * data);
  995. +};
  996. +
  997. +int hash_table_init(const char *name, hash_table_t *hash, int len);
  998. +void hash_table_deinit(hash_table_t *hash);
  999. +void *hash_table_get(hash_table_t *hash, const char *key);
  1000. +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
  1001. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
  1002. +
  1003. +#endif /* _HASH_TABLE_H_ */
  1004. diff -Nur busybox-1.17.1.orig/archival/libipkg/ipkg_cmd.c busybox-1.17.1/archival/libipkg/ipkg_cmd.c
  1005. --- busybox-1.17.1.orig/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
  1006. +++ busybox-1.17.1/archival/libipkg/ipkg_cmd.c 2010-07-28 13:07:49.487607300 +0200
  1007. @@ -0,0 +1,1366 @@
  1008. +/* ipkg_cmd.c - the itsy package management system
  1009. +
  1010. + Carl D. Worth
  1011. +
  1012. + Copyright (C) 2001 University of Southern California
  1013. +
  1014. + This program is free software; you can redistribute it and/or
  1015. + modify it under the terms of the GNU General Public License as
  1016. + published by the Free Software Foundation; either version 2, or (at
  1017. + your option) any later version.
  1018. +
  1019. + This program is distributed in the hope that it will be useful, but
  1020. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1021. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1022. + General Public License for more details.
  1023. +*/
  1024. +
  1025. +#include <string.h>
  1026. +
  1027. +#include "ipkg.h"
  1028. +#include <libgen.h>
  1029. +#include <glob.h>
  1030. +#include <errno.h>
  1031. +#include <stdlib.h>
  1032. +#include <unistd.h>
  1033. +#include <signal.h>
  1034. +#include <stdio.h>
  1035. +#include <dirent.h>
  1036. +
  1037. +#include "ipkg_conf.h"
  1038. +#include "ipkg_cmd.h"
  1039. +#include "ipkg_message.h"
  1040. +#include "pkg.h"
  1041. +#include "pkg_dest.h"
  1042. +#include "pkg_parse.h"
  1043. +#include "sprintf_alloc.h"
  1044. +#include "pkg.h"
  1045. +#include "file_util.h"
  1046. +#include "str_util.h"
  1047. +#include "unarchive.h"
  1048. +
  1049. +#include <fnmatch.h>
  1050. +
  1051. +
  1052. +#include "ipkg_download.h"
  1053. +#include "ipkg_install.h"
  1054. +#include "ipkg_upgrade.h"
  1055. +#include "ipkg_remove.h"
  1056. +#include "ipkg_configure.h"
  1057. +#include "ipkg_message.h"
  1058. +
  1059. +#include "libipkg.h"
  1060. +static void *p_userdata = NULL;
  1061. +
  1062. +static int ipkg_update_cmd(ipkg_conf_t *conf);
  1063. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1064. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1065. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1066. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1067. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf);
  1068. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1069. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1070. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1071. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1072. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1073. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1074. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1075. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1076. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1077. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1078. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1079. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1080. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1081. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1082. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1083. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1084. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1085. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf);
  1086. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1087. +
  1088. +/* XXX: CLEANUP: The usage strings should be incorporated into this
  1089. + array for easier maintenance */
  1090. +static ipkg_cmd_t cmds[] = {
  1091. + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
  1092. + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
  1093. + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
  1094. + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
  1095. + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
  1096. + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
  1097. + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
  1098. + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
  1099. + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
  1100. + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
  1101. + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
  1102. + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
  1103. + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
  1104. + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
  1105. + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
  1106. + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1107. + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1108. + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1109. + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1110. + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1111. + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1112. + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
  1113. + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
  1114. + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
  1115. + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
  1116. + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
  1117. + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
  1118. + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
  1119. + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
  1120. +};
  1121. +
  1122. +int ipkg_state_changed;
  1123. +static void write_status_files_if_changed(ipkg_conf_t *conf)
  1124. +{
  1125. + if (ipkg_state_changed && !conf->noaction) {
  1126. + ipkg_message(conf, IPKG_INFO,
  1127. + " writing status file\n");
  1128. + ipkg_conf_write_status_files(conf);
  1129. + pkg_write_changed_filelists(conf);
  1130. + } else {
  1131. + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
  1132. + }
  1133. +}
  1134. +
  1135. +
  1136. +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
  1137. +
  1138. +ipkg_cmd_t *ipkg_cmd_find(const char *name)
  1139. +{
  1140. + int i;
  1141. + ipkg_cmd_t *cmd;
  1142. +
  1143. + for (i=0; i < num_cmds; i++) {
  1144. + cmd = &cmds[i];
  1145. + if (strcmp(name, cmd->name) == 0) {
  1146. + return cmd;
  1147. + }
  1148. + }
  1149. +
  1150. + return NULL;
  1151. +}
  1152. +
  1153. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
  1154. +{
  1155. + int result;
  1156. + p_userdata = userdata;
  1157. +
  1158. +
  1159. + result = (cmd->fun)(conf, argc, argv);
  1160. + if ( result == 0 ) {
  1161. + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
  1162. + } else {
  1163. + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
  1164. +
  1165. + }
  1166. + if ( error_list ) {
  1167. + reverse_error_list(&error_list);
  1168. +
  1169. + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
  1170. + /* Here we print the errors collected and free the list */
  1171. + while (error_list != NULL) {
  1172. + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
  1173. + error_list = error_list->next;
  1174. +
  1175. + }
  1176. + free_error_list(&error_list);
  1177. +
  1178. + }
  1179. +
  1180. + p_userdata = NULL;
  1181. + return result;
  1182. +}
  1183. +
  1184. +static int ipkg_update_cmd(ipkg_conf_t *conf)
  1185. +{
  1186. + int err;
  1187. + int failures;
  1188. + char *lists_dir;
  1189. + pkg_src_list_elt_t *iter;
  1190. + pkg_src_t *src;
  1191. +
  1192. +
  1193. + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
  1194. +
  1195. + if (! file_is_dir(lists_dir)) {
  1196. + if (file_exists(lists_dir)) {
  1197. + ipkg_message(conf, IPKG_ERROR,
  1198. + "%s: ERROR: %s exists, but is not a directory\n",
  1199. + __FUNCTION__, lists_dir);
  1200. + free(lists_dir);
  1201. + return EINVAL;
  1202. + }
  1203. + err = file_mkdir_hier(lists_dir, 0755);
  1204. + if (err) {
  1205. + ipkg_message(conf, IPKG_ERROR,
  1206. + "%s: ERROR: failed to make directory %s: %s\n",
  1207. + __FUNCTION__, lists_dir, strerror(errno));
  1208. + free(lists_dir);
  1209. + return EINVAL;
  1210. + }
  1211. + }
  1212. +
  1213. + failures = 0;
  1214. + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
  1215. + char *url, *list_file_name;
  1216. +
  1217. + src = iter->data;
  1218. +
  1219. + if (src->extra_data) /* debian style? */
  1220. + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
  1221. + src->gzip ? "Packages.gz" : "Packages");
  1222. + else
  1223. + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
  1224. +
  1225. + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
  1226. + if (src->gzip) {
  1227. + char *tmp;
  1228. + char *tmp_file_name;
  1229. + FILE *in, *out;
  1230. +
  1231. + tmp = strdup ("/tmp/ipkg.XXXXXX");
  1232. +
  1233. + if (mkdtemp (tmp) == NULL) {
  1234. + perror ("mkdtemp");
  1235. + failures++;
  1236. + continue;
  1237. + }
  1238. +
  1239. + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
  1240. + err = ipkg_download(conf, url, tmp_file_name);
  1241. + if (err == 0) {
  1242. + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
  1243. + in = fopen (tmp_file_name, "r");
  1244. + out = fopen (list_file_name, "w");
  1245. + if (in && out) {
  1246. + inflate_unzip_result res;
  1247. + inflate_unzip (&res, 0x8000, fileno(in), fileno(out));
  1248. + } else
  1249. + err = 1;
  1250. + if (in)
  1251. + fclose (in);
  1252. + if (out)
  1253. + fclose (out);
  1254. + unlink (tmp_file_name);
  1255. + rmdir (tmp);
  1256. + free (tmp);
  1257. + }
  1258. + } else
  1259. + err = ipkg_download(conf, url, list_file_name);
  1260. + if (err) {
  1261. + failures++;
  1262. + } else {
  1263. + ipkg_message(conf, IPKG_NOTICE,
  1264. + "Updated list of available packages in %s\n",
  1265. + list_file_name);
  1266. + }
  1267. + free(url);
  1268. + free(list_file_name);
  1269. + }
  1270. + free(lists_dir);
  1271. +
  1272. +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
  1273. +#warning here
  1274. + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
  1275. + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
  1276. + * -Jamey 3/1/03
  1277. + */
  1278. + {
  1279. + int i;
  1280. + int changed = 0;
  1281. + pkg_vec_t *available = pkg_vec_alloc();
  1282. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1283. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
  1284. + for (i = 0; i < available->len; i++) {
  1285. + pkg_t *pkg = available->pkgs[i];
  1286. + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
  1287. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
  1288. + pkg->state_want = SW_UNKNOWN;
  1289. + changed = 1;
  1290. + }
  1291. + }
  1292. + pkg_vec_free(available);
  1293. + if (changed) {
  1294. + write_status_files_if_changed(conf);
  1295. + }
  1296. + }
  1297. +#endif
  1298. +
  1299. + return failures;
  1300. +}
  1301. +
  1302. +
  1303. +/* scan the args passed and cache the local filenames of the packages */
  1304. +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
  1305. +{
  1306. + int i;
  1307. + int err;
  1308. +
  1309. + /*
  1310. + * First scan through package names/urls
  1311. + * For any urls, download the packages and install in database.
  1312. + * For any files, install package info in database.
  1313. + */
  1314. + for (i = 0; i < argc; i ++) {
  1315. + char *filename = argv [i];
  1316. + //char *tmp = basename (tmp);
  1317. + //int tmplen = strlen (tmp);
  1318. +
  1319. + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
  1320. + // continue;
  1321. + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
  1322. + // continue;
  1323. +
  1324. + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
  1325. +
  1326. + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
  1327. + if (err)
  1328. + return err;
  1329. + }
  1330. + return 0;
  1331. +}
  1332. +
  1333. +struct ipkg_intercept
  1334. +{
  1335. + char *oldpath;
  1336. + char *statedir;
  1337. +};
  1338. +
  1339. +typedef struct ipkg_intercept *ipkg_intercept_t;
  1340. +ipkg_intercept_t ipkg_prep_intercepts(void);
  1341. +
  1342. +ipkg_intercept_t ipkg_prep_intercepts(void)
  1343. +{
  1344. + ipkg_intercept_t ctx;
  1345. + char *newpath;
  1346. + int gen;
  1347. +
  1348. + ctx = malloc (sizeof (*ctx));
  1349. + ctx->oldpath = strdup (getenv ("PATH"));
  1350. +
  1351. + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
  1352. + setenv ("PATH", newpath, 1);
  1353. + free (newpath);
  1354. +
  1355. + gen = 0;
  1356. + retry:
  1357. + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
  1358. + if (mkdir (ctx->statedir, 0770) < 0) {
  1359. + if (errno == EEXIST) {
  1360. + free (ctx->statedir);
  1361. + gen++;
  1362. + goto retry;
  1363. + }
  1364. + perror (ctx->statedir);
  1365. + return NULL;
  1366. + }
  1367. + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
  1368. + return ctx;
  1369. +}
  1370. +
  1371. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx);
  1372. +
  1373. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
  1374. +{
  1375. + char *cmd;
  1376. + DIR *dir;
  1377. + int err = 0;
  1378. +
  1379. + setenv ("PATH", ctx->oldpath, 1);
  1380. + free (ctx->oldpath);
  1381. +
  1382. + dir = opendir (ctx->statedir);
  1383. + if (dir) {
  1384. + struct dirent *de;
  1385. + while (de = readdir (dir), de != NULL) {
  1386. + char *path;
  1387. +
  1388. + if (de->d_name[0] == '.')
  1389. + continue;
  1390. +
  1391. + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
  1392. + if (access (path, X_OK) == 0) {
  1393. + if (system (path)) {
  1394. + err = errno;
  1395. + perror (de->d_name);
  1396. + }
  1397. + }
  1398. + free (path);
  1399. + }
  1400. + } else
  1401. + perror (ctx->statedir);
  1402. +
  1403. + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
  1404. + system (cmd);
  1405. + free (cmd);
  1406. +
  1407. + free (ctx->statedir);
  1408. + free (ctx);
  1409. +
  1410. + return err;
  1411. +}
  1412. +
  1413. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
  1414. +{
  1415. + pkg_vec_t *all;
  1416. + int i;
  1417. + pkg_t *pkg;
  1418. + ipkg_intercept_t ic;
  1419. + int r, err = 0;
  1420. +
  1421. + ipkg_message(conf, IPKG_INFO,
  1422. + "Configuring unpacked packages\n");
  1423. + fflush( stdout );
  1424. +
  1425. + all = pkg_vec_alloc();
  1426. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  1427. +
  1428. + ic = ipkg_prep_intercepts();
  1429. +
  1430. + for(i = 0; i < all->len; i++) {
  1431. + pkg = all->pkgs[i];
  1432. +
  1433. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1434. + continue;
  1435. +
  1436. + if (pkg->state_status == SS_UNPACKED) {
  1437. + ipkg_message(conf, IPKG_NOTICE,
  1438. + "Configuring %s\n", pkg->name);
  1439. + fflush( stdout );
  1440. + r = ipkg_configure(conf, pkg);
  1441. + if (r == 0) {
  1442. + pkg->state_status = SS_INSTALLED;
  1443. + pkg->parent->state_status = SS_INSTALLED;
  1444. + pkg->state_flag &= ~SF_PREFER;
  1445. + } else {
  1446. + if (!err)
  1447. + err = r;
  1448. + }
  1449. + }
  1450. + }
  1451. +
  1452. + r = ipkg_finalize_intercepts (ic);
  1453. + if (r && !err)
  1454. + err = r;
  1455. +
  1456. + pkg_vec_free(all);
  1457. + return err;
  1458. +}
  1459. +
  1460. +static void sigint_handler(int sig)
  1461. +{
  1462. + signal(sig, SIG_DFL);
  1463. + ipkg_message(NULL, IPKG_NOTICE,
  1464. + "ipkg: interrupted. writing out status database\n");
  1465. + write_status_files_if_changed(global_conf);
  1466. + exit(128 + sig);
  1467. +}
  1468. +
  1469. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1470. +{
  1471. + int i;
  1472. + char *arg;
  1473. + int err=0;
  1474. +
  1475. + global_conf = conf;
  1476. + signal(SIGINT, sigint_handler);
  1477. +
  1478. + /*
  1479. + * Now scan through package names and install
  1480. + */
  1481. + for (i=0; i < argc; i++) {
  1482. + arg = argv[i];
  1483. +
  1484. + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
  1485. + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
  1486. + if (err != EINVAL && err != 0)
  1487. + return err;
  1488. + }
  1489. + pkg_info_preinstall_check(conf);
  1490. +
  1491. + for (i=0; i < argc; i++) {
  1492. + arg = argv[i];
  1493. + if (conf->multiple_providers)
  1494. + err = ipkg_install_multi_by_name(conf, arg);
  1495. + else{
  1496. + err = ipkg_install_by_name(conf, arg);
  1497. + }
  1498. + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
  1499. + ipkg_message(conf, IPKG_ERROR,
  1500. + "Cannot find package %s.\n"
  1501. + "Check the spelling or perhaps run 'ipkg update'\n",
  1502. + arg);
  1503. + }
  1504. + }
  1505. +
  1506. + /* recheck to verify that all dependences are satisfied */
  1507. + if (0) ipkg_satisfy_all_dependences(conf);
  1508. +
  1509. + ipkg_configure_packages(conf, NULL);
  1510. +
  1511. + write_status_files_if_changed(conf);
  1512. +
  1513. + return err;
  1514. +}
  1515. +
  1516. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1517. +{
  1518. + int i;
  1519. + pkg_t *pkg;
  1520. + int err;
  1521. +
  1522. + global_conf = conf;
  1523. + signal(SIGINT, sigint_handler);
  1524. +
  1525. + if (argc) {
  1526. + for (i=0; i < argc; i++) {
  1527. + char *arg = argv[i];
  1528. +
  1529. + err = ipkg_prepare_url_for_install(conf, arg, &arg);
  1530. + if (err != EINVAL && err != 0)
  1531. + return err;
  1532. + }
  1533. + pkg_info_preinstall_check(conf);
  1534. +
  1535. + for (i=0; i < argc; i++) {
  1536. + char *arg = argv[i];
  1537. + if (conf->restrict_to_default_dest) {
  1538. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1539. + argv[i],
  1540. + conf->default_dest);
  1541. + if (pkg == NULL) {
  1542. + ipkg_message(conf, IPKG_NOTICE,
  1543. + "Package %s not installed in %s\n",
  1544. + argv[i], conf->default_dest->name);
  1545. + continue;
  1546. + }
  1547. + } else {
  1548. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  1549. + argv[i]);
  1550. + }
  1551. + if (pkg)
  1552. + ipkg_upgrade_pkg(conf, pkg);
  1553. + else {
  1554. + ipkg_install_by_name(conf, arg);
  1555. + }
  1556. + }
  1557. + } else {
  1558. + pkg_vec_t *installed = pkg_vec_alloc();
  1559. +
  1560. + pkg_info_preinstall_check(conf);
  1561. +
  1562. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  1563. + for (i = 0; i < installed->len; i++) {
  1564. + pkg = installed->pkgs[i];
  1565. + ipkg_upgrade_pkg(conf, pkg);
  1566. + }
  1567. + pkg_vec_free(installed);
  1568. + }
  1569. +
  1570. + /* recheck to verify that all dependences are satisfied */
  1571. + if (0) ipkg_satisfy_all_dependences(conf);
  1572. +
  1573. + ipkg_configure_packages(conf, NULL);
  1574. +
  1575. + write_status_files_if_changed(conf);
  1576. +
  1577. + return 0;
  1578. +}
  1579. +
  1580. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1581. +{
  1582. + int i, err;
  1583. + char *arg;
  1584. + pkg_t *pkg;
  1585. +
  1586. + pkg_info_preinstall_check(conf);
  1587. + for (i = 0; i < argc; i++) {
  1588. + arg = argv[i];
  1589. +
  1590. + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
  1591. + if (pkg == NULL) {
  1592. + ipkg_message(conf, IPKG_ERROR,
  1593. + "Cannot find package %s.\n"
  1594. + "Check the spelling or perhaps run 'ipkg update'\n",
  1595. + arg);
  1596. + continue;
  1597. + }
  1598. +
  1599. + err = ipkg_download_pkg(conf, pkg, ".");
  1600. +
  1601. + if (err) {
  1602. + ipkg_message(conf, IPKG_ERROR,
  1603. + "Failed to download %s\n", pkg->name);
  1604. + } else {
  1605. + ipkg_message(conf, IPKG_NOTICE,
  1606. + "Downloaded %s as %s\n",
  1607. + pkg->name, pkg->local_filename);
  1608. + }
  1609. + }
  1610. +
  1611. + return 0;
  1612. +}
  1613. +
  1614. +
  1615. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1616. +{
  1617. + int i ;
  1618. + pkg_vec_t *available;
  1619. + pkg_t *pkg;
  1620. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1621. + char *newline;
  1622. + char *pkg_name = NULL;
  1623. + char *version_str;
  1624. +
  1625. + if (argc > 0) {
  1626. + pkg_name = argv[0];
  1627. + }
  1628. + available = pkg_vec_alloc();
  1629. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1630. + for (i=0; i < available->len; i++) {
  1631. + pkg = available->pkgs[i];
  1632. + /* if we have package name or pattern and pkg does not match, then skip it */
  1633. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1634. + continue;
  1635. + if (pkg->description) {
  1636. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1637. + } else {
  1638. + desc_short[0] = '\0';
  1639. + }
  1640. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1641. + newline = strchr(desc_short, '\n');
  1642. + if (newline) {
  1643. + *newline = '\0';
  1644. + }
  1645. + if (ipkg_cb_list) {
  1646. + version_str = pkg_version_str_alloc(pkg);
  1647. + ipkg_cb_list(pkg->name,desc_short,
  1648. + version_str,
  1649. + pkg->state_status,
  1650. + p_userdata);
  1651. + free(version_str);
  1652. + }
  1653. + }
  1654. + pkg_vec_free(available);
  1655. +
  1656. + return 0;
  1657. +}
  1658. +
  1659. +
  1660. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1661. +{
  1662. + int i ;
  1663. + pkg_vec_t *available;
  1664. + pkg_t *pkg;
  1665. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1666. + char *newline;
  1667. + char *pkg_name = NULL;
  1668. + char *version_str;
  1669. +
  1670. + if (argc > 0) {
  1671. + pkg_name = argv[0];
  1672. + }
  1673. + available = pkg_vec_alloc();
  1674. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1675. + for (i=0; i < available->len; i++) {
  1676. + pkg = available->pkgs[i];
  1677. + /* if we have package name or pattern and pkg does not match, then skip it */
  1678. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1679. + continue;
  1680. + if (pkg->description) {
  1681. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1682. + } else {
  1683. + desc_short[0] = '\0';
  1684. + }
  1685. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1686. + newline = strchr(desc_short, '\n');
  1687. + if (newline) {
  1688. + *newline = '\0';
  1689. + }
  1690. + if (ipkg_cb_list) {
  1691. + version_str = pkg_version_str_alloc(pkg);
  1692. + ipkg_cb_list(pkg->name,desc_short,
  1693. + version_str,
  1694. + pkg->state_status,
  1695. + p_userdata);
  1696. + free(version_str);
  1697. + }
  1698. + }
  1699. +
  1700. + return 0;
  1701. +}
  1702. +
  1703. +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
  1704. +{
  1705. + int i;
  1706. + pkg_vec_t *available;
  1707. + pkg_t *pkg;
  1708. + char *pkg_name = NULL;
  1709. + char **pkg_fields = NULL;
  1710. + int n_fields = 0;
  1711. + char *buff ; // = (char *)malloc(1);
  1712. +
  1713. + if (argc > 0) {
  1714. + pkg_name = argv[0];
  1715. + }
  1716. + if (argc > 1) {
  1717. + pkg_fields = &argv[1];
  1718. + n_fields = argc - 1;
  1719. + }
  1720. +
  1721. + available = pkg_vec_alloc();
  1722. + if (installed_only)
  1723. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1724. + else
  1725. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1726. + for (i=0; i < available->len; i++) {
  1727. + pkg = available->pkgs[i];
  1728. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1729. + continue;
  1730. + }
  1731. + buff = pkg_formatted_info(pkg);
  1732. + if ( buff ) {
  1733. + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
  1734. + pkg->state_status,
  1735. + buff,
  1736. + p_userdata);
  1737. + free(buff);
  1738. + }
  1739. + if (conf->verbosity > 1) {
  1740. + conffile_list_elt_t *iter;
  1741. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  1742. + conffile_t *cf = iter->data;
  1743. + int modified = conffile_has_been_modified(conf, cf);
  1744. + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
  1745. + cf->name, cf->value, modified);
  1746. + }
  1747. + }
  1748. + }
  1749. + pkg_vec_free(available);
  1750. +
  1751. + return 0;
  1752. +}
  1753. +
  1754. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1755. +{
  1756. + return ipkg_info_status_cmd(conf, argc, argv, 0);
  1757. +}
  1758. +
  1759. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1760. +{
  1761. + return ipkg_info_status_cmd(conf, argc, argv, 1);
  1762. +}
  1763. +
  1764. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1765. +{
  1766. +
  1767. + int err;
  1768. + if (argc > 0) {
  1769. + char *pkg_name = NULL;
  1770. +
  1771. + pkg_name = argv[0];
  1772. +
  1773. + err = ipkg_configure_packages (conf, pkg_name);
  1774. +
  1775. + } else {
  1776. + err = ipkg_configure_packages (conf, NULL);
  1777. + }
  1778. +
  1779. + write_status_files_if_changed(conf);
  1780. +
  1781. + return err;
  1782. +}
  1783. +
  1784. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf)
  1785. +{
  1786. + int i, err;
  1787. + char *globpattern;
  1788. + glob_t globbuf;
  1789. +
  1790. + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
  1791. + err = glob(globpattern, 0, NULL, &globbuf);
  1792. + free(globpattern);
  1793. + if (err) {
  1794. + return 0;
  1795. + }
  1796. +
  1797. + ipkg_message(conf, IPKG_NOTICE,
  1798. + "The following packages in %s will now be installed.\n",
  1799. + conf->pending_dir);
  1800. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1801. + ipkg_message(conf, IPKG_NOTICE,
  1802. + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
  1803. + }
  1804. + ipkg_message(conf, IPKG_NOTICE, "\n");
  1805. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1806. + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
  1807. + if (err == 0) {
  1808. + err = unlink(globbuf.gl_pathv[i]);
  1809. + if (err) {
  1810. + ipkg_message(conf, IPKG_ERROR,
  1811. + "%s: ERROR: failed to unlink %s: %s\n",
  1812. + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
  1813. + return err;
  1814. + }
  1815. + }
  1816. + }
  1817. + globfree(&globbuf);
  1818. +
  1819. + return err;
  1820. +}
  1821. +
  1822. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1823. +{
  1824. + int i,a,done;
  1825. + pkg_t *pkg;
  1826. + pkg_t *pkg_to_remove;
  1827. + pkg_vec_t *available;
  1828. + char *pkg_name = NULL;
  1829. + global_conf = conf;
  1830. + signal(SIGINT, sigint_handler);
  1831. +
  1832. +// ENH: Add the "no pkg removed" just in case.
  1833. +
  1834. + done = 0;
  1835. +
  1836. + available = pkg_vec_alloc();
  1837. + pkg_info_preinstall_check(conf);
  1838. + if ( argc > 0 ) {
  1839. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1840. + for (i=0; i < argc; i++) {
  1841. + pkg_name = malloc(strlen(argv[i])+2);
  1842. + strcpy(pkg_name,argv[i]);
  1843. + for (a=0; a < available->len; a++) {
  1844. + pkg = available->pkgs[a];
  1845. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1846. + continue;
  1847. + }
  1848. + if (conf->restrict_to_default_dest) {
  1849. + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1850. + pkg->name,
  1851. + conf->default_dest);
  1852. + } else {
  1853. + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
  1854. + }
  1855. +
  1856. + if (pkg == NULL) {
  1857. + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
  1858. + continue;
  1859. + }
  1860. + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
  1861. + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
  1862. + continue;
  1863. + }
  1864. + ipkg_remove_pkg(conf, pkg_to_remove,0);
  1865. + done = 1;
  1866. + }
  1867. + free (pkg_name);
  1868. + }
  1869. + pkg_vec_free(available);
  1870. + } else {
  1871. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  1872. + int flagged_pkg_count = 0;
  1873. + int removed;
  1874. +
  1875. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
  1876. +
  1877. + for (i = 0; i < installed_pkgs->len; i++) {
  1878. + pkg = installed_pkgs->pkgs[i];
  1879. + if (pkg->state_flag & SF_USER) {
  1880. + flagged_pkg_count++;
  1881. + } else {
  1882. + if (!pkg_has_installed_dependents(pkg, NULL))
  1883. + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
  1884. + }
  1885. + }
  1886. + if (!flagged_pkg_count) {
  1887. + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
  1888. + "so refusing to uninstall unflagged non-leaf packages\n");
  1889. + return 0;
  1890. + }
  1891. +
  1892. + /* find packages not flagged SF_USER (i.e., installed to
  1893. + * satisfy a dependence) and not having any dependents, and
  1894. + * remove them */
  1895. + do {
  1896. + removed = 0;
  1897. + for (i = 0; i < installed_pkgs->len; i++) {
  1898. + pkg = installed_pkgs->pkgs[i];
  1899. + if (!(pkg->state_flag & SF_USER)
  1900. + && !pkg_has_installed_dependents(pkg, NULL)) {
  1901. + removed++;
  1902. + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
  1903. + ipkg_remove_pkg(conf, pkg,0);
  1904. + done = 1;
  1905. + }
  1906. + }
  1907. + } while (removed);
  1908. + pkg_vec_free(installed_pkgs);
  1909. + }
  1910. +
  1911. + if ( done == 0 )
  1912. + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
  1913. +
  1914. + write_status_files_if_changed(conf);
  1915. + return 0;
  1916. +}
  1917. +
  1918. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1919. +{
  1920. + int i;
  1921. + pkg_t *pkg;
  1922. +
  1923. + global_conf = conf;
  1924. + signal(SIGINT, sigint_handler);
  1925. +
  1926. + pkg_info_preinstall_check(conf);
  1927. +
  1928. + for (i=0; i < argc; i++) {
  1929. + if (conf->restrict_to_default_dest) {
  1930. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1931. + argv[i],
  1932. + conf->default_dest);
  1933. + } else {
  1934. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1935. + }
  1936. +
  1937. + if (pkg == NULL) {
  1938. + ipkg_message(conf, IPKG_ERROR,
  1939. + "Package %s is not installed.\n", argv[i]);
  1940. + continue;
  1941. + }
  1942. + ipkg_purge_pkg(conf, pkg);
  1943. + }
  1944. +
  1945. + write_status_files_if_changed(conf);
  1946. + return 0;
  1947. +}
  1948. +
  1949. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1950. +{
  1951. + int i;
  1952. + pkg_t *pkg;
  1953. + char *flags = argv[0];
  1954. +
  1955. + global_conf = conf;
  1956. + signal(SIGINT, sigint_handler);
  1957. +
  1958. + for (i=1; i < argc; i++) {
  1959. + if (conf->restrict_to_default_dest) {
  1960. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1961. + argv[i],
  1962. + conf->default_dest);
  1963. + } else {
  1964. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1965. + }
  1966. +
  1967. + if (pkg == NULL) {
  1968. + ipkg_message(conf, IPKG_ERROR,
  1969. + "Package %s is not installed.\n", argv[i]);
  1970. + continue;
  1971. + }
  1972. + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
  1973. + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
  1974. + pkg->state_flag = pkg_state_flag_from_str(flags);
  1975. + }
  1976. +/* pb_ asked this feature 03292004 */
  1977. +/* Actually I will use only this two, but this is an open for various status */
  1978. + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
  1979. + pkg->state_status = pkg_state_status_from_str(flags);
  1980. + }
  1981. + ipkg_state_changed++;
  1982. + ipkg_message(conf, IPKG_NOTICE,
  1983. + "Setting flags for package %s to %s\n",
  1984. + pkg->name, flags);
  1985. + }
  1986. +
  1987. + write_status_files_if_changed(conf);
  1988. + return 0;
  1989. +}
  1990. +
  1991. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1992. +{
  1993. + pkg_t *pkg;
  1994. + str_list_t *installed_files;
  1995. + str_list_elt_t *iter;
  1996. + char *pkg_version;
  1997. + size_t buff_len = 8192;
  1998. + size_t used_len;
  1999. + char *buff ;
  2000. +
  2001. + buff = (char *)malloc(buff_len);
  2002. + if ( buff == NULL ) {
  2003. + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
  2004. + return ENOMEM;
  2005. + }
  2006. +
  2007. + if (argc < 1) {
  2008. + return EINVAL;
  2009. + }
  2010. +
  2011. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  2012. + argv[0]);
  2013. + if (pkg == NULL) {
  2014. + ipkg_message(conf, IPKG_ERROR,
  2015. + "Package %s not installed.\n", argv[0]);
  2016. + return 0;
  2017. + }
  2018. +
  2019. + installed_files = pkg_get_installed_files(pkg);
  2020. + pkg_version = pkg_version_str_alloc(pkg);
  2021. +
  2022. + printf("Package %s (%s) is installed on %s and has the following files:\n",
  2023. + pkg->name, pkg_version, pkg->dest->name);
  2024. + for (iter = installed_files->head; iter; iter = iter->next) {
  2025. + puts(iter->data);
  2026. + }
  2027. +
  2028. + free(pkg_version);
  2029. + pkg_free_installed_files(pkg);
  2030. +
  2031. + return 0;
  2032. +}
  2033. +
  2034. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2035. +{
  2036. +
  2037. + if (argc > 0) {
  2038. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2039. + const char *rel_str = "depends on";
  2040. + int i;
  2041. +
  2042. + pkg_info_preinstall_check(conf);
  2043. +
  2044. + if (conf->query_all)
  2045. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2046. + else
  2047. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2048. + for (i = 0; i < argc; i++) {
  2049. + const char *target = argv[i];
  2050. + int j;
  2051. +
  2052. + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
  2053. +
  2054. + for (j = 0; j < available_pkgs->len; j++) {
  2055. + pkg_t *pkg = available_pkgs->pkgs[j];
  2056. + if (fnmatch(target, pkg->name, 0) == 0) {
  2057. + int k;
  2058. + int count = pkg->depends_count + pkg->pre_depends_count;
  2059. + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
  2060. + target, pkg->architecture, rel_str);
  2061. + for (k = 0; k < count; k++) {
  2062. + compound_depend_t *cdepend = &pkg->depends[k];
  2063. + int l;
  2064. + for (l = 0; l < cdepend->possibility_count; l++) {
  2065. + depend_t *possibility = cdepend->possibilities[l];
  2066. + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
  2067. + if (conf->verbosity > 0) {
  2068. + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
  2069. + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
  2070. + if (possibility->version) {
  2071. + const char *typestr = NULL;
  2072. + switch (possibility->constraint) {
  2073. + case NONE: typestr = "none"; break;
  2074. + case EARLIER: typestr = "<"; break;
  2075. + case EARLIER_EQUAL: typestr = "<="; break;
  2076. + case EQUAL: typestr = "="; break;
  2077. + case LATER_EQUAL: typestr = ">="; break;
  2078. + case LATER: typestr = ">"; break;
  2079. + }
  2080. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2081. + }
  2082. + // free(ver);
  2083. + }
  2084. + ipkg_message(conf, IPKG_ERROR, "\n");
  2085. + }
  2086. + }
  2087. + }
  2088. + }
  2089. + }
  2090. + pkg_vec_free(available_pkgs);
  2091. + }
  2092. + return 0;
  2093. +}
  2094. +
  2095. +enum what_field_type {
  2096. + WHATDEPENDS,
  2097. + WHATCONFLICTS,
  2098. + WHATPROVIDES,
  2099. + WHATREPLACES,
  2100. + WHATRECOMMENDS,
  2101. + WHATSUGGESTS
  2102. +};
  2103. +
  2104. +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
  2105. +{
  2106. +
  2107. + if (argc > 0) {
  2108. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2109. + const char *rel_str = NULL;
  2110. + int i;
  2111. + int changed;
  2112. +
  2113. + switch (what_field_type) {
  2114. + case WHATDEPENDS: rel_str = "depends on"; break;
  2115. + case WHATCONFLICTS: rel_str = "conflicts with"; break;
  2116. + case WHATSUGGESTS: rel_str = "suggests"; break;
  2117. + case WHATRECOMMENDS: rel_str = "recommends"; break;
  2118. + case WHATPROVIDES: rel_str = "provides"; break;
  2119. + case WHATREPLACES: rel_str = "replaces"; break;
  2120. + }
  2121. +
  2122. + if (conf->query_all)
  2123. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2124. + else
  2125. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2126. +
  2127. + /* mark the root set */
  2128. + pkg_vec_clear_marks(available_pkgs);
  2129. + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
  2130. + for (i = 0; i < argc; i++) {
  2131. + const char *dependee_pattern = argv[i];
  2132. + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
  2133. + }
  2134. + for (i = 0; i < available_pkgs->len; i++) {
  2135. + pkg_t *pkg = available_pkgs->pkgs[i];
  2136. + if (pkg->state_flag & SF_MARKED) {
  2137. + /* mark the parent (abstract) package */
  2138. + pkg_mark_provides(pkg);
  2139. + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
  2140. + }
  2141. + }
  2142. +
  2143. + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
  2144. + do {
  2145. + int j;
  2146. + changed = 0;
  2147. +
  2148. + for (j = 0; j < available_pkgs->len; j++) {
  2149. + pkg_t *pkg = available_pkgs->pkgs[j];
  2150. + int k;
  2151. + int count = ((what_field_type == WHATCONFLICTS)
  2152. + ? pkg->conflicts_count
  2153. + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
  2154. + /* skip this package if it is already marked */
  2155. + if (pkg->parent->state_flag & SF_MARKED) {
  2156. + continue;
  2157. + }
  2158. + for (k = 0; k < count; k++) {
  2159. + compound_depend_t *cdepend =
  2160. + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
  2161. + int l;
  2162. + for (l = 0; l < cdepend->possibility_count; l++) {
  2163. + depend_t *possibility = cdepend->possibilities[l];
  2164. + if (possibility->pkg->state_flag & SF_MARKED) {
  2165. + /* mark the depending package so we won't visit it again */
  2166. + pkg->state_flag |= SF_MARKED;
  2167. + pkg_mark_provides(pkg);
  2168. + changed++;
  2169. +
  2170. + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
  2171. + if (conf->verbosity > 0) {
  2172. + char *ver = pkg_version_str_alloc(pkg);
  2173. + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
  2174. + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
  2175. + if (possibility->version) {
  2176. + const char *typestr = NULL;
  2177. + switch (possibility->constraint) {
  2178. + case NONE: typestr = "none"; break;
  2179. + case EARLIER: typestr = "<"; break;
  2180. + case EARLIER_EQUAL: typestr = "<="; break;
  2181. + case EQUAL: typestr = "="; break;
  2182. + case LATER_EQUAL: typestr = ">="; break;
  2183. + case LATER: typestr = ">"; break;
  2184. + }
  2185. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2186. + }
  2187. + free(ver);
  2188. + if (!pkg_dependence_satisfiable(possibility))
  2189. + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
  2190. + }
  2191. + ipkg_message(conf, IPKG_NOTICE, "\n");
  2192. + goto next_package;
  2193. + }
  2194. + }
  2195. + }
  2196. + next_package:
  2197. + ;
  2198. + }
  2199. + } while (changed && recursive);
  2200. + pkg_vec_free(available_pkgs);
  2201. + }
  2202. +
  2203. + return 0;
  2204. +}
  2205. +
  2206. +int pkg_mark_provides(pkg_t *pkg)
  2207. +{
  2208. + int provides_count = pkg->provides_count;
  2209. + abstract_pkg_t **provides = pkg->provides;
  2210. + int i;
  2211. + pkg->parent->state_flag |= SF_MARKED;
  2212. + for (i = 0; i < provides_count; i++) {
  2213. + provides[i]->state_flag |= SF_MARKED;
  2214. + }
  2215. + return 0;
  2216. +}
  2217. +
  2218. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2219. +{
  2220. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
  2221. +}
  2222. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2223. +{
  2224. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
  2225. +}
  2226. +
  2227. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2228. +{
  2229. + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
  2230. +}
  2231. +
  2232. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2233. +{
  2234. + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
  2235. +}
  2236. +
  2237. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2238. +{
  2239. + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
  2240. +}
  2241. +
  2242. +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
  2243. +{
  2244. +
  2245. + if (argc > 0) {
  2246. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2247. + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
  2248. + int i;
  2249. +
  2250. + pkg_info_preinstall_check(conf);
  2251. +
  2252. + if (conf->query_all)
  2253. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2254. + else
  2255. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2256. + for (i = 0; i < argc; i++) {
  2257. + const char *target = argv[i];
  2258. + int j;
  2259. +
  2260. + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
  2261. + rel_str, target);
  2262. + for (j = 0; j < available_pkgs->len; j++) {
  2263. + pkg_t *pkg = available_pkgs->pkgs[j];
  2264. + int k;
  2265. + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
  2266. + for (k = 0; k < count; k++) {
  2267. + abstract_pkg_t *apkg =
  2268. + ((what_field_type == WHATPROVIDES)
  2269. + ? pkg->provides[k]
  2270. + : pkg->replaces[k]);
  2271. + if (fnmatch(target, apkg->name, 0) == 0) {
  2272. + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
  2273. + if (strcmp(target, apkg->name) != 0)
  2274. + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
  2275. + ipkg_message(conf, IPKG_ERROR, "\n");
  2276. + }
  2277. + }
  2278. + }
  2279. + }
  2280. + pkg_vec_free(available_pkgs);
  2281. + }
  2282. + return 0;
  2283. +}
  2284. +
  2285. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2286. +{
  2287. + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
  2288. +}
  2289. +
  2290. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2291. +{
  2292. + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
  2293. +}
  2294. +
  2295. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2296. +{
  2297. + int i;
  2298. +
  2299. + pkg_vec_t *installed;
  2300. + pkg_t *pkg;
  2301. + str_list_t *installed_files;
  2302. + str_list_elt_t *iter;
  2303. + char *installed_file;
  2304. +
  2305. + if (argc < 1) {
  2306. + return EINVAL;
  2307. + }
  2308. +
  2309. + installed = pkg_vec_alloc();
  2310. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  2311. +
  2312. + for (i=0; i < installed->len; i++) {
  2313. + pkg = installed->pkgs[i];
  2314. +
  2315. + installed_files = pkg_get_installed_files(pkg);
  2316. +
  2317. + for (iter = installed_files->head; iter; iter = iter->next) {
  2318. + installed_file = iter->data;
  2319. + if (fnmatch(argv[0], installed_file, 0)==0) {
  2320. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2321. + installed_file,
  2322. + pkg_version_str_alloc(pkg),
  2323. + pkg->state_status, p_userdata);
  2324. + }
  2325. + }
  2326. +
  2327. + pkg_free_installed_files(pkg);
  2328. + }
  2329. +
  2330. + /* XXX: CLEANUP: It's not obvious from the name of
  2331. + pkg_hash_fetch_all_installed that we need to call
  2332. + pkg_vec_free to avoid a memory leak. */
  2333. + pkg_vec_free(installed);
  2334. +
  2335. + return 0;
  2336. +}
  2337. +
  2338. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2339. +{
  2340. + if (argc == 3) {
  2341. + /* this is a bit gross */
  2342. + struct pkg p1, p2;
  2343. + parseVersion(&p1, argv[0]);
  2344. + parseVersion(&p2, argv[2]);
  2345. + return pkg_version_satisfied(&p1, &p2, argv[1]);
  2346. + } else {
  2347. + ipkg_message(conf, IPKG_ERROR,
  2348. + "ipkg compare_versions <v1> <op> <v2>\n"
  2349. + "<op> is one of <= >= << >> =\n");
  2350. + return -1;
  2351. + }
  2352. +}
  2353. +
  2354. +#ifndef HOST_CPU_STR
  2355. +#define HOST_CPU_STR__(X) #X
  2356. +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
  2357. +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
  2358. +#endif
  2359. +
  2360. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf)
  2361. +{
  2362. + nv_pair_list_elt_t *l;
  2363. +
  2364. + l = conf->arch_list.head;
  2365. + while (l) {
  2366. + nv_pair_t *nv = l->data;
  2367. + printf("arch %s %s\n", nv->name, nv->value);
  2368. + l = l->next;
  2369. + }
  2370. + return 0;
  2371. +}
  2372. +
  2373. +
  2374. diff -Nur busybox-1.17.1.orig/archival/libipkg/ipkg_cmd.h busybox-1.17.1/archival/libipkg/ipkg_cmd.h
  2375. --- busybox-1.17.1.orig/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
  2376. +++ busybox-1.17.1/archival/libipkg/ipkg_cmd.h 2010-07-28 13:07:49.491598591 +0200
  2377. @@ -0,0 +1,41 @@
  2378. +/* ipkg_cmd.h - the itsy package management system
  2379. +
  2380. + Carl D. Worth
  2381. +
  2382. + Copyright (C) 2001 University of Southern California
  2383. +
  2384. + This program is free software; you can redistribute it and/or
  2385. + modify it under the terms of the GNU General Public License as
  2386. + published by the Free Software Foundation; either version 2, or (at
  2387. + your option) any later version.
  2388. +
  2389. + This program is distributed in the hope that it will be useful, but
  2390. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2391. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2392. + General Public License for more details.
  2393. +*/
  2394. +
  2395. +#ifndef IPKG_CMD_H
  2396. +#define IPKG_CMD_H
  2397. +
  2398. +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
  2399. +
  2400. +struct ipkg_cmd
  2401. +{
  2402. + const char *name;
  2403. + int requires_args;
  2404. + ipkg_cmd_fun_t fun;
  2405. +};
  2406. +typedef struct ipkg_cmd ipkg_cmd_t;
  2407. +
  2408. +ipkg_cmd_t *ipkg_cmd_find(const char *name);
  2409. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
  2410. + const char **argv, void *userdata);
  2411. +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
  2412. +/* install any packges with state_want == SW_INSTALL */
  2413. +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
  2414. +/* ensure that all dependences are satisfied */
  2415. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
  2416. +int pkg_mark_provides(pkg_t *pkg);
  2417. +
  2418. +#endif
  2419. diff -Nur busybox-1.17.1.orig/archival/libipkg/ipkg_conf.c busybox-1.17.1/archival/libipkg/ipkg_conf.c
  2420. --- busybox-1.17.1.orig/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
  2421. +++ busybox-1.17.1/archival/libipkg/ipkg_conf.c 2010-07-28 13:07:49.495599101 +0200
  2422. @@ -0,0 +1,711 @@
  2423. +/* ipkg_conf.c - the itsy package management system
  2424. +
  2425. + Carl D. Worth
  2426. +
  2427. + Copyright (C) 2001 University of Southern California
  2428. +
  2429. + This program is free software; you can redistribute it and/or
  2430. + modify it under the terms of the GNU General Public License as
  2431. + published by the Free Software Foundation; either version 2, or (at
  2432. + your option) any later version.
  2433. +
  2434. + This program is distributed in the hope that it will be useful, but
  2435. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2436. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2437. + General Public License for more details.
  2438. +*/
  2439. +
  2440. +#include <glob.h>
  2441. +
  2442. +#include "ipkg.h"
  2443. +#include "ipkg_conf.h"
  2444. +
  2445. +#include "xregex.h"
  2446. +#include "sprintf_alloc.h"
  2447. +#include "ipkg_conf.h"
  2448. +#include "ipkg_message.h"
  2449. +#include "file_util.h"
  2450. +#include "str_util.h"
  2451. +#include "xsystem.h"
  2452. +
  2453. +
  2454. +ipkg_conf_t *global_conf;
  2455. +
  2456. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2457. + pkg_src_list_t *pkg_src_list,
  2458. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2459. + char **tmp_lists_dir);
  2460. +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
  2461. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  2462. + const char *name, const char *value);
  2463. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2464. + const char *default_dest_name);
  2465. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
  2466. + pkg_src_list_t *nv_pair_list);
  2467. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
  2468. + nv_pair_list_t *nv_pair_list, char * lists_dir);
  2469. +
  2470. +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
  2471. +{
  2472. + ipkg_option_t tmp[] = {
  2473. + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
  2474. + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
  2475. + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
  2476. + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
  2477. + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
  2478. + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
  2479. + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
  2480. + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
  2481. + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
  2482. + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
  2483. + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
  2484. + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
  2485. + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
  2486. + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
  2487. + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
  2488. + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
  2489. + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
  2490. + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
  2491. + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
  2492. + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
  2493. + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
  2494. + { NULL }
  2495. + };
  2496. +
  2497. + *options = (ipkg_option_t *)malloc(sizeof(tmp));
  2498. + if ( options == NULL ){
  2499. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  2500. + return -1;
  2501. + }
  2502. +
  2503. + memcpy(*options, tmp, sizeof(tmp));
  2504. + return 0;
  2505. +};
  2506. +
  2507. +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
  2508. +{
  2509. + if (arg_str) {
  2510. + if (*conf_str) {
  2511. + free(*conf_str);
  2512. + }
  2513. + *conf_str = strdup(arg_str);
  2514. + }
  2515. +}
  2516. +
  2517. +static void ipkg_conf_free_string(char **conf_str)
  2518. +{
  2519. + if (*conf_str) {
  2520. + free(*conf_str);
  2521. + *conf_str = NULL;
  2522. + }
  2523. +}
  2524. +
  2525. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
  2526. +{
  2527. + int err;
  2528. + char *tmp_dir_base;
  2529. + nv_pair_list_t tmp_dest_nv_pair_list;
  2530. + char * lists_dir =NULL;
  2531. + glob_t globbuf;
  2532. + const char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
  2533. + char *pending_dir =NULL;
  2534. +
  2535. + memset(conf, 0, sizeof(ipkg_conf_t));
  2536. +
  2537. + pkg_src_list_init(&conf->pkg_src_list);
  2538. +
  2539. + nv_pair_list_init(&tmp_dest_nv_pair_list);
  2540. + pkg_dest_list_init(&conf->pkg_dest_list);
  2541. +
  2542. + nv_pair_list_init(&conf->arch_list);
  2543. +
  2544. + conf->restrict_to_default_dest = 0;
  2545. + conf->default_dest = NULL;
  2546. +
  2547. +
  2548. + if (args->tmp_dir)
  2549. + tmp_dir_base = args->tmp_dir;
  2550. + else
  2551. + tmp_dir_base = getenv("TMPDIR");
  2552. + sprintf_alloc(&conf->tmp_dir, "%s/%s",
  2553. + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
  2554. + IPKG_CONF_TMP_DIR_SUFFIX);
  2555. + conf->tmp_dir = mkdtemp(conf->tmp_dir);
  2556. + if (conf->tmp_dir == NULL) {
  2557. + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
  2558. + __FUNCTION__, conf->tmp_dir, strerror(errno));
  2559. + return errno;
  2560. + }
  2561. +
  2562. + conf->force_depends = 0;
  2563. + conf->force_defaults = 0;
  2564. + conf->force_overwrite = 0;
  2565. + conf->force_downgrade = 0;
  2566. + conf->force_reinstall = 0;
  2567. + conf->force_space = 0;
  2568. + conf->force_removal_of_essential_packages = 0;
  2569. + conf->force_removal_of_dependent_packages = 0;
  2570. + conf->nodeps = 0;
  2571. + conf->verbose_wget = 0;
  2572. + conf->offline_root = NULL;
  2573. + conf->offline_root_pre_script_cmd = NULL;
  2574. + conf->offline_root_post_script_cmd = NULL;
  2575. + conf->multiple_providers = 0;
  2576. + conf->verbosity = 1;
  2577. + conf->noaction = 0;
  2578. +
  2579. + conf->http_proxy = NULL;
  2580. + conf->ftp_proxy = NULL;
  2581. + conf->no_proxy = NULL;
  2582. + conf->proxy_user = NULL;
  2583. + conf->proxy_passwd = NULL;
  2584. +
  2585. + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2586. + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2587. + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2588. + lists_dir=(char *)malloc(1);
  2589. + lists_dir[0]='\0';
  2590. + if (args->conf_file) {
  2591. + struct stat stat_buf;
  2592. + err = stat(args->conf_file, &stat_buf);
  2593. + if (err == 0)
  2594. + if (ipkg_conf_parse_file(conf, args->conf_file,
  2595. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2596. + /* Memory leakage from ipkg_conf_parse-file */
  2597. + return -1;
  2598. + }
  2599. +
  2600. + }
  2601. +
  2602. + /* if (!lists_dir ){*/
  2603. + if (strlen(lists_dir)<=1 ){
  2604. + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
  2605. + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
  2606. + }
  2607. +
  2608. + if (args->offline_root) {
  2609. + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
  2610. + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
  2611. + free(lists_dir);
  2612. + lists_dir = tmp;
  2613. + }
  2614. +
  2615. + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
  2616. + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
  2617. +
  2618. + conf->lists_dir = strdup(lists_dir);
  2619. + conf->pending_dir = strdup(pending_dir);
  2620. +
  2621. + if (args->offline_root)
  2622. + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
  2623. + memset(&globbuf, 0, sizeof(globbuf));
  2624. + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
  2625. + if (!err) {
  2626. + int i;
  2627. + for (i = 0; i < globbuf.gl_pathc; i++) {
  2628. + if (globbuf.gl_pathv[i])
  2629. + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
  2630. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2631. + /* Memory leakage from ipkg_conf_parse-file */
  2632. + return -1;
  2633. + }
  2634. + }
  2635. + }
  2636. + globfree(&globbuf);
  2637. +
  2638. + /* if no architectures were defined, then default all, noarch, and host architecture */
  2639. + if (nv_pair_list_empty(&conf->arch_list)) {
  2640. + nv_pair_list_append(&conf->arch_list, "all", "1");
  2641. + nv_pair_list_append(&conf->arch_list, "noarch", "1");
  2642. + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
  2643. + }
  2644. +
  2645. + /* Even if there is no conf file, we'll need at least one dest. */
  2646. + if (tmp_dest_nv_pair_list.head == NULL) {
  2647. + nv_pair_list_append(&tmp_dest_nv_pair_list,
  2648. + IPKG_CONF_DEFAULT_DEST_NAME,
  2649. + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
  2650. + }
  2651. +
  2652. + /* After parsing the file, set options from command-line, (so that
  2653. + command-line arguments take precedence) */
  2654. + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
  2655. + really needs to be cleaned up. There is so much duplication
  2656. + right now it is ridiculous. Maybe ipkg_conf_t should just save
  2657. + a pointer to args_t (which could then not be freed), rather
  2658. + than duplicating every field here? */
  2659. + if (args->force_depends) {
  2660. + conf->force_depends = 1;
  2661. + }
  2662. + if (args->force_defaults) {
  2663. + conf->force_defaults = 1;
  2664. + }
  2665. + if (args->force_overwrite) {
  2666. + conf->force_overwrite = 1;
  2667. + }
  2668. + if (args->force_downgrade) {
  2669. + conf->force_downgrade = 1;
  2670. + }
  2671. + if (args->force_reinstall) {
  2672. + conf->force_reinstall = 1;
  2673. + }
  2674. + if (args->force_removal_of_dependent_packages) {
  2675. + conf->force_removal_of_dependent_packages = 1;
  2676. + }
  2677. + if (args->force_removal_of_essential_packages) {
  2678. + conf->force_removal_of_essential_packages = 1;
  2679. + }
  2680. + if (args->nodeps) {
  2681. + conf->nodeps = 1;
  2682. + }
  2683. + if (args->noaction) {
  2684. + conf->noaction = 1;
  2685. + }
  2686. + if (args->query_all) {
  2687. + conf->query_all = 1;
  2688. + }
  2689. + if (args->verbose_wget) {
  2690. + conf->verbose_wget = 1;
  2691. + }
  2692. + if (args->multiple_providers) {
  2693. + conf->multiple_providers = 1;
  2694. + }
  2695. + if (args->verbosity != conf->verbosity) {
  2696. + conf->verbosity = args->verbosity;
  2697. + }
  2698. +
  2699. + ipkg_conf_override_string(&conf->offline_root,
  2700. + args->offline_root);
  2701. + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
  2702. + args->offline_root_pre_script_cmd);
  2703. + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
  2704. + args->offline_root_post_script_cmd);
  2705. +
  2706. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  2707. + read anything from there.
  2708. +*/
  2709. + if ( !(args->nocheckfordirorfile)){
  2710. + /* need to run load the source list before dest list -Jamey */
  2711. + if ( !(args->noreadfeedsfile))
  2712. + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
  2713. +
  2714. + /* Now that we have resolved conf->offline_root, we can commit to
  2715. + the directory names for the dests and load in all the package
  2716. + lists. */
  2717. + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
  2718. +
  2719. + if (args->dest) {
  2720. + err = ipkg_conf_set_default_dest(conf, args->dest);
  2721. + if (err) {
  2722. + return err;
  2723. + }
  2724. + }
  2725. + }
  2726. + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
  2727. + free(lists_dir);
  2728. + free(pending_dir);
  2729. +
  2730. + return 0;
  2731. +}
  2732. +
  2733. +void ipkg_conf_deinit(ipkg_conf_t *conf)
  2734. +{
  2735. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  2736. +#error
  2737. + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
  2738. + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  2739. + __FUNCTION__, conf->tmp_dir);
  2740. +#else
  2741. + int err;
  2742. +
  2743. + err = rmdir(conf->tmp_dir);
  2744. + if (err) {
  2745. + if (errno == ENOTEMPTY) {
  2746. + char *cmd;
  2747. + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
  2748. + err = xsystem(cmd);
  2749. + free(cmd);
  2750. + }
  2751. + if (err)
  2752. + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
  2753. + }
  2754. +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
  2755. +
  2756. + free(conf->tmp_dir); /*XXX*/
  2757. +
  2758. + pkg_src_list_deinit(&conf->pkg_src_list);
  2759. + pkg_dest_list_deinit(&conf->pkg_dest_list);
  2760. + nv_pair_list_deinit(&conf->arch_list);
  2761. + if (&conf->pkg_hash)
  2762. + pkg_hash_deinit(&conf->pkg_hash);
  2763. + if (&conf->file_hash)
  2764. + hash_table_deinit(&conf->file_hash);
  2765. + if (&conf->obs_file_hash)
  2766. + hash_table_deinit(&conf->obs_file_hash);
  2767. +
  2768. + ipkg_conf_free_string(&conf->offline_root);
  2769. + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
  2770. + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
  2771. +
  2772. + if (conf->verbosity > 1) {
  2773. + int i;
  2774. + hash_table_t *hashes[] = {
  2775. + &conf->pkg_hash,
  2776. + &conf->file_hash,
  2777. + &conf->obs_file_hash };
  2778. + for (i = 0; i < 3; i++) {
  2779. + hash_table_t *hash = hashes[i];
  2780. + int c = 0;
  2781. + int n_conflicts = 0;
  2782. + int j;
  2783. + for (j = 0; j < hash->n_entries; j++) {
  2784. + int len = 0;
  2785. + hash_entry_t *e = &hash->entries[j];
  2786. + if (e->next)
  2787. + n_conflicts++;
  2788. + while (e && e->key) {
  2789. + len++;
  2790. + e = e->next;
  2791. + }
  2792. + if (len > c)
  2793. + c = len;
  2794. + }
  2795. + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
  2796. + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
  2797. + hash_table_deinit(hash);
  2798. + }
  2799. + }
  2800. +}
  2801. +
  2802. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2803. + const char *default_dest_name)
  2804. +{
  2805. + pkg_dest_list_elt_t *iter;
  2806. + pkg_dest_t *dest;
  2807. +
  2808. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  2809. + dest = iter->data;
  2810. + if (strcmp(dest->name, default_dest_name) == 0) {
  2811. + conf->default_dest = dest;
  2812. + conf->restrict_to_default_dest = 1;
  2813. + return 0;
  2814. + }
  2815. + }
  2816. +
  2817. + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
  2818. +
  2819. + return 1;
  2820. +}
  2821. +
  2822. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
  2823. +{
  2824. + pkg_src_list_elt_t *iter;
  2825. + pkg_src_t *src;
  2826. + char *list_file;
  2827. +
  2828. + for (iter = pkg_src_list->head; iter; iter = iter->next) {
  2829. + src = iter->data;
  2830. + if (src == NULL) {
  2831. + continue;
  2832. + }
  2833. +
  2834. + sprintf_alloc(&list_file, "%s/%s",
  2835. + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
  2836. + src->name);
  2837. +
  2838. + if (file_exists(list_file)) {
  2839. + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
  2840. + }
  2841. + free(list_file);
  2842. + }
  2843. +
  2844. + return 0;
  2845. +}
  2846. +
  2847. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
  2848. +{
  2849. + nv_pair_list_elt_t *iter;
  2850. + nv_pair_t *nv_pair;
  2851. + pkg_dest_t *dest;
  2852. + char *root_dir;
  2853. +
  2854. + for (iter = nv_pair_list->head; iter; iter = iter->next) {
  2855. + nv_pair = iter->data;
  2856. +
  2857. + if (conf->offline_root) {
  2858. + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
  2859. + } else {
  2860. + root_dir = strdup(nv_pair->value);
  2861. + }
  2862. + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
  2863. + free(root_dir);
  2864. + if (dest == NULL) {
  2865. + continue;
  2866. + }
  2867. + if (conf->default_dest == NULL) {
  2868. + conf->default_dest = dest;
  2869. + }
  2870. + if (file_exists(dest->status_file_name)) {
  2871. + pkg_hash_add_from_file(conf, dest->status_file_name,
  2872. + NULL, dest, 1);
  2873. + }
  2874. + }
  2875. +
  2876. + return 0;
  2877. +}
  2878. +
  2879. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2880. + pkg_src_list_t *pkg_src_list,
  2881. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2882. + char **lists_dir)
  2883. +{
  2884. + ipkg_option_t * options;
  2885. + FILE *file = fopen(filename, "r");
  2886. + regex_t valid_line_re, comment_re;
  2887. +#define regmatch_size 12
  2888. + regmatch_t regmatch[regmatch_size];
  2889. +
  2890. + if (ipkg_init_options_array(conf, &options)<0)
  2891. + return ENOMEM;
  2892. +
  2893. + if (file == NULL) {
  2894. + fprintf(stderr, "%s: failed to open %s: %s\n",
  2895. + __FUNCTION__, filename, strerror(errno));
  2896. + free(options);
  2897. + return errno;
  2898. + }
  2899. + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
  2900. +
  2901. + xregcomp(&comment_re,
  2902. + "^[[:space:]]*(#.*|[[:space:]]*)$",
  2903. + REG_EXTENDED);
  2904. + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
  2905. +
  2906. + while(1) {
  2907. + int line_num = 0;
  2908. + char *line;
  2909. + char *type, *name, *value, *extra;
  2910. +
  2911. + line = file_read_line_alloc(file);
  2912. + line_num++;
  2913. + if (line == NULL) {
  2914. + break;
  2915. + }
  2916. +
  2917. + str_chomp(line);
  2918. +
  2919. + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
  2920. + goto NEXT_LINE;
  2921. + }
  2922. +
  2923. + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
  2924. + str_chomp(line);
  2925. + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
  2926. + filename, line_num, line);
  2927. + goto NEXT_LINE;
  2928. + }
  2929. +
  2930. + /* This has to be so ugly to deal with optional quotation marks */
  2931. + if (regmatch[2].rm_so > 0) {
  2932. + type = strndup(line + regmatch[2].rm_so,
  2933. + regmatch[2].rm_eo - regmatch[2].rm_so);
  2934. + } else {
  2935. + type = strndup(line + regmatch[3].rm_so,
  2936. + regmatch[3].rm_eo - regmatch[3].rm_so);
  2937. + }
  2938. + if (regmatch[5].rm_so > 0) {
  2939. + name = strndup(line + regmatch[5].rm_so,
  2940. + regmatch[5].rm_eo - regmatch[5].rm_so);
  2941. + } else {
  2942. + name = strndup(line + regmatch[6].rm_so,
  2943. + regmatch[6].rm_eo - regmatch[6].rm_so);
  2944. + }
  2945. + if (regmatch[8].rm_so > 0) {
  2946. + value = strndup(line + regmatch[8].rm_so,
  2947. + regmatch[8].rm_eo - regmatch[8].rm_so);
  2948. + } else {
  2949. + value = strndup(line + regmatch[9].rm_so,
  2950. + regmatch[9].rm_eo - regmatch[9].rm_so);
  2951. + }
  2952. + extra = NULL;
  2953. + if (regmatch[11].rm_so > 0) {
  2954. + extra = strndup (line + regmatch[11].rm_so,
  2955. + regmatch[11].rm_eo - regmatch[11].rm_so);
  2956. + }
  2957. +
  2958. + /* We use the tmp_dest_nv_pair_list below instead of
  2959. + conf->pkg_dest_list because we might encounter an
  2960. + offline_root option later and that would invalidate the
  2961. + directories we would have computed in
  2962. + pkg_dest_list_init. (We do a similar thing with
  2963. + tmp_src_nv_pair_list for sake of symmetry.) */
  2964. + if (strcmp(type, "option") == 0) {
  2965. + ipkg_conf_set_option(options, name, value);
  2966. + } else if (strcmp(type, "src") == 0) {
  2967. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  2968. + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
  2969. + } else {
  2970. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  2971. + name, value);
  2972. + }
  2973. + } else if (strcmp(type, "src/gz") == 0) {
  2974. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  2975. + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
  2976. + } else {
  2977. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  2978. + name, value);
  2979. + }
  2980. + } else if (strcmp(type, "dest") == 0) {
  2981. + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
  2982. + } else if (strcmp(type, "lists_dir") == 0) {
  2983. + *lists_dir = realloc(*lists_dir,strlen(value)+1);
  2984. + if (*lists_dir == NULL) {
  2985. + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
  2986. + free(options);
  2987. + return EINVAL;
  2988. + }
  2989. + sprintf (*lists_dir,"%s",value);
  2990. + } else if (strcmp(type, "arch") == 0) {
  2991. + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
  2992. + if (!value) {
  2993. + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
  2994. + value = strdup("10");
  2995. + }
  2996. + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
  2997. + } else {
  2998. + fprintf(stderr, "WARNING: Ignoring unknown configuration "
  2999. + "parameter: %s %s %s\n", type, name, value);
  3000. + free(options);
  3001. + return EINVAL;
  3002. + }
  3003. +
  3004. + free(type);
  3005. + free(name);
  3006. + free(value);
  3007. + if (extra)
  3008. + free (extra);
  3009. +
  3010. + NEXT_LINE:
  3011. + free(line);
  3012. + }
  3013. +
  3014. + free(options);
  3015. + regfree(&comment_re);
  3016. + regfree(&valid_line_re);
  3017. + fclose(file);
  3018. +
  3019. + return 0;
  3020. +}
  3021. +
  3022. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  3023. + const char *name, const char *value)
  3024. +{
  3025. + int i = 0;
  3026. + while (options[i].name) {
  3027. + if (strcmp(options[i].name, name) == 0) {
  3028. + switch (options[i].type) {
  3029. + case IPKG_OPT_TYPE_BOOL:
  3030. + *((int *)options[i].value) = 1;
  3031. + return 0;
  3032. + case IPKG_OPT_TYPE_INT:
  3033. + if (value) {
  3034. + *((int *)options[i].value) = atoi(value);
  3035. + return 0;
  3036. + } else {
  3037. + printf("%s: Option %s need an argument\n",
  3038. + __FUNCTION__, name);
  3039. + return EINVAL;
  3040. + }
  3041. + case IPKG_OPT_TYPE_STRING:
  3042. + if (value) {
  3043. + *((char **)options[i].value) = strdup(value);
  3044. + return 0;
  3045. + } else {
  3046. + printf("%s: Option %s need an argument\n",
  3047. + __FUNCTION__, name);
  3048. + return EINVAL;
  3049. + }
  3050. + }
  3051. + }
  3052. + i++;
  3053. + }
  3054. +
  3055. + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
  3056. + __FUNCTION__, name, value);
  3057. + return EINVAL;
  3058. +}
  3059. +
  3060. +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
  3061. +{
  3062. + pkg_dest_list_elt_t *iter;
  3063. + pkg_dest_t *dest;
  3064. + pkg_vec_t *all;
  3065. + pkg_t *pkg;
  3066. + register int i;
  3067. + int err;
  3068. +
  3069. + if (conf->noaction)
  3070. + return 0;
  3071. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3072. + dest = iter->data;
  3073. + dest->status_file = fopen(dest->status_file_tmp_name, "w");
  3074. + if (dest->status_file == NULL) {
  3075. + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
  3076. + __FUNCTION__, dest->status_file_name, strerror(errno));
  3077. + }
  3078. + }
  3079. +
  3080. + all = pkg_vec_alloc();
  3081. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  3082. +
  3083. + for(i = 0; i < all->len; i++) {
  3084. + pkg = all->pkgs[i];
  3085. + /* We don't need most uninstalled packages in the status file */
  3086. + if (pkg->state_status == SS_NOT_INSTALLED
  3087. + && (pkg->state_want == SW_UNKNOWN
  3088. + || pkg->state_want == SW_DEINSTALL
  3089. + || pkg->state_want == SW_PURGE)) {
  3090. + continue;
  3091. + }
  3092. + if (!pkg) {
  3093. + fprintf(stderr, "Null package\n");
  3094. + }
  3095. + if (pkg->dest == NULL) {
  3096. + fprintf(stderr, "%s: ERROR: Can't write status for "
  3097. + "package %s since it has a NULL dest\n",
  3098. + __FUNCTION__, pkg->name);
  3099. + continue;
  3100. + }
  3101. + if (pkg->dest->status_file) {
  3102. + pkg_print_status(pkg, pkg->dest->status_file);
  3103. + }
  3104. + }
  3105. +
  3106. + pkg_vec_free(all);
  3107. +
  3108. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3109. + dest = iter->data;
  3110. + if (dest->status_file) {
  3111. + err = ferror(dest->status_file);
  3112. + fclose(dest->status_file);
  3113. + dest->status_file = NULL;
  3114. + if (!err) {
  3115. + file_move(dest->status_file_tmp_name, dest->status_file_name);
  3116. + } else {
  3117. + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
  3118. + "retaining old %s\n", __FUNCTION__,
  3119. + dest->status_file_tmp_name, dest->status_file_name);
  3120. + }
  3121. + }
  3122. + }
  3123. +
  3124. + return 0;
  3125. +}
  3126. +
  3127. +
  3128. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
  3129. +{
  3130. + char *root_filename;
  3131. + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
  3132. + return root_filename;
  3133. +}
  3134. diff -Nur busybox-1.17.1.orig/archival/libipkg/ipkg_conf.h busybox-1.17.1/archival/libipkg/ipkg_conf.h
  3135. --- busybox-1.17.1.orig/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
  3136. +++ busybox-1.17.1/archival/libipkg/ipkg_conf.h 2010-07-28 13:07:49.503598444 +0200
  3137. @@ -0,0 +1,107 @@
  3138. +/* ipkg_conf.h - the itsy package management system
  3139. +
  3140. + Carl D. Worth
  3141. +
  3142. + Copyright (C) 2001 University of Southern California
  3143. +
  3144. + This program is free software; you can redistribute it and/or
  3145. + modify it under the terms of the GNU General Public License as
  3146. + published by the Free Software Foundation; either version 2, or (at
  3147. + your option) any later version.
  3148. +
  3149. + This program is distributed in the hope that it will be useful, but
  3150. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3151. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3152. + General Public License for more details.
  3153. +*/
  3154. +
  3155. +#ifndef IPKG_CONF_H
  3156. +#define IPKG_CONF_H
  3157. +
  3158. +typedef struct ipkg_conf ipkg_conf_t;
  3159. +
  3160. +#include "hash_table.h"
  3161. +#include "ipkg.h"
  3162. +#include "args.h"
  3163. +#include "pkg.h"
  3164. +#include "pkg_hash.h"
  3165. +#include "pkg_src_list.h"
  3166. +#include "pkg_dest_list.h"
  3167. +#include "nv_pair_list.h"
  3168. +
  3169. +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
  3170. +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
  3171. +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
  3172. +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
  3173. +
  3174. +/* In case the config file defines no dest */
  3175. +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
  3176. +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
  3177. +
  3178. +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
  3179. +
  3180. +struct ipkg_conf
  3181. +{
  3182. + pkg_src_list_t pkg_src_list;
  3183. + pkg_dest_list_t pkg_dest_list;
  3184. + nv_pair_list_t arch_list;
  3185. +
  3186. + int restrict_to_default_dest;
  3187. + pkg_dest_t *default_dest;
  3188. +
  3189. + char *tmp_dir;
  3190. + char *lists_dir;
  3191. + char *pending_dir;
  3192. +
  3193. + /* options */
  3194. + int force_depends;
  3195. + int force_defaults;
  3196. + int force_overwrite;
  3197. + int force_downgrade;
  3198. + int force_reinstall;
  3199. + int force_space;
  3200. + int force_removal_of_dependent_packages;
  3201. + int force_removal_of_essential_packages;
  3202. + int nodeps; /* do not follow dependences */
  3203. + int verbose_wget;
  3204. + int multiple_providers;
  3205. + char *offline_root;
  3206. + char *offline_root_pre_script_cmd;
  3207. + char *offline_root_post_script_cmd;
  3208. + int query_all;
  3209. + int verbosity;
  3210. + int noaction;
  3211. +
  3212. + /* proxy options */
  3213. + char *http_proxy;
  3214. + char *ftp_proxy;
  3215. + char *no_proxy;
  3216. + char *proxy_user;
  3217. + char *proxy_passwd;
  3218. +
  3219. + hash_table_t pkg_hash;
  3220. + hash_table_t file_hash;
  3221. + hash_table_t obs_file_hash;
  3222. +};
  3223. +
  3224. +enum ipkg_option_type {
  3225. + IPKG_OPT_TYPE_BOOL,
  3226. + IPKG_OPT_TYPE_INT,
  3227. + IPKG_OPT_TYPE_STRING
  3228. +};
  3229. +typedef enum ipkg_option_type ipkg_option_type_t;
  3230. +
  3231. +typedef struct ipkg_option ipkg_option_t;
  3232. +struct ipkg_option {
  3233. + const char *name;
  3234. + const ipkg_option_type_t type;
  3235. + const void *value;
  3236. +};
  3237. +
  3238. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
  3239. +void ipkg_conf_deinit(ipkg_conf_t *conf);
  3240. +
  3241. +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
  3242. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
  3243. +
  3244. +#endif
  3245. diff -Nur busybox-1.17.1.orig/archival/libipkg/ipkg_configure.c busybox-1.17.1/archival/libipkg/ipkg_configure.c
  3246. --- busybox-1.17.1.orig/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
  3247. +++ busybox-1.17.1/archival/libipkg/ipkg_configure.c 2010-07-28 13:07:49.503598444 +0200
  3248. @@ -0,0 +1,40 @@
  3249. +/* ipkg_configure.c - the itsy package management system
  3250. +
  3251. + Carl D. Worth
  3252. +
  3253. + Copyright (C) 2001 University of Southern California
  3254. +
  3255. + This program is free software; you can redistribute it and/or
  3256. + modify it under the terms of the GNU General Public License as
  3257. + published by the Free Software Foundation; either version 2, or (at
  3258. + your option) any later version.
  3259. +
  3260. + This program is distributed in the hope that it will be useful, but
  3261. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3262. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3263. + General Public License for more details.
  3264. +*/
  3265. +
  3266. +#include "ipkg.h"
  3267. +
  3268. +#include "ipkg_configure.h"
  3269. +
  3270. +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
  3271. +{
  3272. + int err;
  3273. +
  3274. + /* DPKG_INCOMPATIBILITY:
  3275. + dpkg actually does some conffile handling here, rather than at the
  3276. + end of ipkg_install(). Do we care? */
  3277. + /* DPKG_INCOMPATIBILITY:
  3278. + dpkg actually includes a version number to this script call */
  3279. + err = pkg_run_script(conf, pkg, "postinst", "configure");
  3280. + if (err) {
  3281. + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
  3282. + return err;
  3283. + }
  3284. +
  3285. + ipkg_state_changed++;
  3286. + return 0;
  3287. +}
  3288. +
  3289. diff -Nur busybox-1.17.1.orig/archival/libipkg/ipkg_configure.h busybox-1.17.1/archival/libipkg/ipkg_configure.h
  3290. --- busybox-1.17.1.orig/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
  3291. +++ busybox-1.17.1/archival/libipkg/ipkg_configure.h 2010-07-28 13:07:49.503598444 +0200
  3292. @@ -0,0 +1,25 @@
  3293. +/* ipkg_configure.h - the itsy package management system
  3294. +
  3295. + Carl D. Worth
  3296. +
  3297. + Copyright (C) 2001 University of Southern California
  3298. +
  3299. + This program is free software; you can redistribute it and/or
  3300. + modify it under the terms of the GNU General Public License as
  3301. + published by the Free Software Foundation; either version 2, or (at
  3302. + your option) any later version.
  3303. +
  3304. + This program is distributed in the hope that it will be useful, but
  3305. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3306. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3307. + General Public License for more details.
  3308. +*/
  3309. +
  3310. +#ifndef IPKG_CONFIGURE_H
  3311. +#define IPKG_CONFIGURE_H
  3312. +
  3313. +#include "ipkg_conf.h"
  3314. +
  3315. +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
  3316. +
  3317. +#endif
  3318. diff -Nur busybox-1.17.1.orig/archival/libipkg/ipkg_download.c busybox-1.17.1/archival/libipkg/ipkg_download.c
  3319. --- busybox-1.17.1.orig/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
  3320. +++ busybox-1.17.1/archival/libipkg/ipkg_download.c 2010-07-28 13:07:49.503598444 +0200
  3321. @@ -0,0 +1,195 @@
  3322. +/* ipkg_download.c - the itsy package management system
  3323. +
  3324. + Carl D. Worth
  3325. +
  3326. + Copyright (C) 2001 University of Southern California
  3327. +
  3328. + This program is free software; you can redistribute it and/or
  3329. + modify it under the terms of the GNU General Public License as
  3330. + published by the Free Software Foundation; either version 2, or (at
  3331. + your option) any later version.
  3332. +
  3333. + This program is distributed in the hope that it will be useful, but
  3334. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3335. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3336. + General Public License for more details.
  3337. +*/
  3338. +
  3339. +#include "ipkg.h"
  3340. +#include "ipkg_download.h"
  3341. +#include "ipkg_message.h"
  3342. +
  3343. +#include "sprintf_alloc.h"
  3344. +#include "xsystem.h"
  3345. +#include "file_util.h"
  3346. +#include "str_util.h"
  3347. +
  3348. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
  3349. +{
  3350. + int err = 0;
  3351. +
  3352. + char *src_basec = strdup(src);
  3353. + char *src_base = basename(src_basec);
  3354. + char *tmp_file_location;
  3355. + char *cmd;
  3356. +
  3357. + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
  3358. +
  3359. + fflush(stdout);
  3360. +
  3361. + if (str_starts_with(src, "file:")) {
  3362. + int ret;
  3363. + const char *file_src = src + 5;
  3364. + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
  3365. + ret = file_copy(src + 5, dest_file_name);
  3366. + ipkg_message(conf,IPKG_INFO,"Done.\n");
  3367. + return ret;
  3368. + }
  3369. +
  3370. + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
  3371. + err = unlink(tmp_file_location);
  3372. + if (err && errno != ENOENT) {
  3373. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
  3374. + __FUNCTION__, tmp_file_location, strerror(errno));
  3375. + free(tmp_file_location);
  3376. + return errno;
  3377. + }
  3378. +
  3379. + if (conf->http_proxy) {
  3380. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
  3381. + setenv("http_proxy", conf->http_proxy, 1);
  3382. + }
  3383. + if (conf->ftp_proxy) {
  3384. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
  3385. + setenv("ftp_proxy", conf->ftp_proxy, 1);
  3386. + }
  3387. + if (conf->no_proxy) {
  3388. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
  3389. + setenv("no_proxy", conf->no_proxy, 1);
  3390. + }
  3391. +
  3392. + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
  3393. + sprintf_alloc(&cmd, "wget %s %s%s %s%s %s -P %s %s",
  3394. + (conf->http_proxy || conf->ftp_proxy) ? "-Y on" : "",
  3395. + conf->proxy_user ? "--proxy-user=" : "",
  3396. + conf->proxy_user ? conf->proxy_user : "",
  3397. + conf->proxy_passwd ? "--proxy-passwd=" : "",
  3398. + conf->proxy_passwd ? conf->proxy_passwd : "",
  3399. + conf->verbose_wget ? "" : "-q",
  3400. + conf->tmp_dir,
  3401. + src);
  3402. + err = xsystem(cmd);
  3403. + if (err) {
  3404. + if (err != -1) {
  3405. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
  3406. + __FUNCTION__, err, cmd);
  3407. + }
  3408. + unlink(tmp_file_location);
  3409. + free(tmp_file_location);
  3410. + free(src_basec);
  3411. + free(cmd);
  3412. + return EINVAL;
  3413. + }
  3414. + free(cmd);
  3415. +
  3416. + err = file_move(tmp_file_location, dest_file_name);
  3417. +
  3418. + free(tmp_file_location);
  3419. + free(src_basec);
  3420. +
  3421. + if (err) {
  3422. + return err;
  3423. + }
  3424. +
  3425. + return 0;
  3426. +}
  3427. +
  3428. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
  3429. +{
  3430. + int err;
  3431. + char *url;
  3432. +
  3433. + if (pkg->src == NULL) {
  3434. + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
  3435. + pkg->name, pkg->parent->name);
  3436. + return -1;
  3437. + }
  3438. +
  3439. + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
  3440. +
  3441. + /* XXX: BUG: The pkg->filename might be something like
  3442. + "../../foo.ipk". While this is correct, and exactly what we
  3443. + want to use to construct url above, here we actually need to
  3444. + use just the filename part, without any directory. */
  3445. + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
  3446. +
  3447. + err = ipkg_download(conf, url, pkg->local_filename);
  3448. + free(url);
  3449. +
  3450. + return err;
  3451. +}
  3452. +
  3453. +/*
  3454. + * Downloads file from url, installs in package database, return package name.
  3455. + */
  3456. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
  3457. +{
  3458. + int err = 0;
  3459. + pkg_t *pkg;
  3460. + pkg = pkg_new();
  3461. + if (pkg == NULL)
  3462. + return ENOMEM;
  3463. +
  3464. + if (str_starts_with(url, "http://")
  3465. + || str_starts_with(url, "ftp://")) {
  3466. + char *tmp_file;
  3467. + char *file_basec = strdup(url);
  3468. + char *file_base = basename(file_basec);
  3469. +
  3470. + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
  3471. + err = ipkg_download(conf, url, tmp_file);
  3472. + if (err)
  3473. + return err;
  3474. +
  3475. + err = pkg_init_from_file(pkg, tmp_file);
  3476. + if (err)
  3477. + return err;
  3478. + pkg->local_filename = strdup(tmp_file);
  3479. +
  3480. + free(tmp_file);
  3481. + free(file_basec);
  3482. +
  3483. + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
  3484. + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
  3485. +
  3486. + err = pkg_init_from_file(pkg, url);
  3487. + if (err)
  3488. + return err;
  3489. + pkg->local_filename = strdup(url);
  3490. + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
  3491. + pkg->provided_by_hand = 1;
  3492. +
  3493. + } else {
  3494. + pkg_deinit(pkg);
  3495. + free(pkg);
  3496. + return 0;
  3497. + }
  3498. +
  3499. + if (!pkg->architecture) {
  3500. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3501. + return -EINVAL;
  3502. + }
  3503. +
  3504. + pkg->dest = conf->default_dest;
  3505. + pkg->state_want = SW_INSTALL;
  3506. + pkg->state_flag |= SF_PREFER;
  3507. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3508. + if ( pkg == NULL ){
  3509. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  3510. + return 0;
  3511. + }
  3512. + if (namep) {
  3513. + *namep = strdup(pkg->name);
  3514. + }
  3515. + return 0;
  3516. +}
  3517. diff -Nur busybox-1.17.1.orig/archival/libipkg/ipkg_download.h busybox-1.17.1/archival/libipkg/ipkg_download.h
  3518. --- busybox-1.17.1.orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
  3519. +++ busybox-1.17.1/archival/libipkg/ipkg_download.h 2010-07-28 13:07:49.503598444 +0200
  3520. @@ -0,0 +1,30 @@
  3521. +/* ipkg_download.h - the itsy package management system
  3522. +
  3523. + Carl D. Worth
  3524. +
  3525. + Copyright (C) 2001 University of Southern California
  3526. +
  3527. + This program is free software; you can redistribute it and/or
  3528. + modify it under the terms of the GNU General Public License as
  3529. + published by the Free Software Foundation; either version 2, or (at
  3530. + your option) any later version.
  3531. +
  3532. + This program is distributed in the hope that it will be useful, but
  3533. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3534. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3535. + General Public License for more details.
  3536. +*/
  3537. +
  3538. +#ifndef IPKG_DOWNLOAD_H
  3539. +#define IPKG_DOWNLOAD_H
  3540. +
  3541. +#include "ipkg_conf.h"
  3542. +
  3543. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
  3544. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
  3545. +/*
  3546. + * Downloads file from url, installs in package database, return package name.
  3547. + */
  3548. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
  3549. +
  3550. +#endif
  3551. diff -Nur busybox-1.17.1.orig/archival/libipkg/ipkg.h busybox-1.17.1/archival/libipkg/ipkg.h
  3552. --- busybox-1.17.1.orig/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
  3553. +++ busybox-1.17.1/archival/libipkg/ipkg.h 2010-07-28 13:07:49.507597557 +0200
  3554. @@ -0,0 +1,68 @@
  3555. +/* ipkg.h - the itsy package management system
  3556. +
  3557. + Carl D. Worth
  3558. +
  3559. + Copyright (C) 2001 University of Southern California
  3560. +
  3561. + This program is free software; you can redistribute it and/or
  3562. + modify it under the terms of the GNU General Public License as
  3563. + published by the Free Software Foundation; either version 2, or (at
  3564. + your option) any later version.
  3565. +
  3566. + This program is distributed in the hope that it will be useful, but
  3567. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3568. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3569. + General Public License for more details.
  3570. +*/
  3571. +
  3572. +#ifndef IPKG_H
  3573. +#define IPKG_H
  3574. +
  3575. +#include "libbb.h"
  3576. +
  3577. +#include "ipkg_includes.h"
  3578. +#include "ipkg_conf.h"
  3579. +#include "ipkg_message.h"
  3580. +
  3581. +#define IPKG_PKG_EXTENSION ".ipk"
  3582. +#define DPKG_PKG_EXTENSION ".deb"
  3583. +
  3584. +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
  3585. +#define IPKG_PKG_VERSION_SEP_CHAR '_'
  3586. +
  3587. +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
  3588. +#define IPKG_LISTS_DIR_SUFFIX "lists"
  3589. +#define IPKG_INFO_DIR_SUFFIX "info"
  3590. +#define IPKG_STATUS_FILE_SUFFIX "status"
  3591. +
  3592. +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
  3593. +
  3594. +#define IPKG_LIST_DESCRIPTION_LENGTH 128
  3595. +
  3596. +#define IPKG_VERSION "1.00"
  3597. +
  3598. +
  3599. +enum ipkg_error {
  3600. + IPKG_SUCCESS = 0,
  3601. + IPKG_PKG_DEPS_UNSATISFIED,
  3602. + IPKG_PKG_IS_ESSENTIAL,
  3603. + IPKG_PKG_HAS_DEPENDENTS,
  3604. + IPKG_PKG_HAS_NO_CANDIDATE
  3605. +};
  3606. +typedef enum ipkg_error ipkg_error_t;
  3607. +
  3608. +extern int ipkg_state_changed;
  3609. +
  3610. +
  3611. +struct errlist {
  3612. + char * errmsg;
  3613. + struct errlist * next;
  3614. +} ;
  3615. +
  3616. +extern struct errlist* error_list;
  3617. +
  3618. +extern ipkg_conf_t *global_conf;
  3619. +
  3620. +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
  3621. +
  3622. +#endif
  3623. diff -Nur busybox-1.17.1.orig/archival/libipkg/ipkg_includes.h busybox-1.17.1/archival/libipkg/ipkg_includes.h
  3624. --- busybox-1.17.1.orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
  3625. +++ busybox-1.17.1/archival/libipkg/ipkg_includes.h 2010-07-28 13:07:49.507597557 +0200
  3626. @@ -0,0 +1,82 @@
  3627. +#ifndef IPKG_INCLUDES_H
  3628. +#define IPKG_INCLUDES_H
  3629. +
  3630. +/* Define to 1 if you have the <memory.h> header file. */
  3631. +#define HAVE_MEMORY_H 1
  3632. +
  3633. +/* Define to 1 if you have the <regex.h> header file. */
  3634. +#define HAVE_REGEX_H 1
  3635. +
  3636. +/* Define to 1 if you have the <stdlib.h> header file. */
  3637. +#define HAVE_STDLIB_H 1
  3638. +
  3639. +/* Define to 1 if you have the <strings.h> header file. */
  3640. +#define HAVE_STRINGS_H 1
  3641. +
  3642. +/* Define to 1 if you have the <string.h> header file. */
  3643. +#define HAVE_STRING_H 1
  3644. +
  3645. +/* Define to 1 if you have the <sys/stat.h> header file. */
  3646. +#define HAVE_SYS_STAT_H 1
  3647. +
  3648. +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
  3649. +#define HAVE_SYS_WAIT_H 1
  3650. +
  3651. +/* Define to 1 if you have the <unistd.h> header file. */
  3652. +#define HAVE_UNISTD_H 1
  3653. +
  3654. +/* Define to 1 if you have the ANSI C header files. */
  3655. +#define STDC_HEADERS 1
  3656. +
  3657. +
  3658. +#include <stdio.h>
  3659. +
  3660. +#if STDC_HEADERS
  3661. +# include <stdlib.h>
  3662. +# include <stdarg.h>
  3663. +# include <stddef.h>
  3664. +# include <ctype.h>
  3665. +# include <errno.h>
  3666. +#else
  3667. +# if HAVE_STDLIB_H
  3668. +# include <stdlib.h>
  3669. +# endif
  3670. +#endif
  3671. +
  3672. +#if HAVE_REGEX_H
  3673. +# include <regex.h>
  3674. +#endif
  3675. +
  3676. +#if HAVE_STRING_H
  3677. +# if !STDC_HEADERS && HAVE_MEMORY_H
  3678. +# include <memory.h>
  3679. +# endif
  3680. +/* XXX: What's the right way to pick up GNU's strndup declaration? */
  3681. +# if __GNUC__
  3682. +# define __USE_GNU 1
  3683. +# endif
  3684. +# include <string.h>
  3685. +# undef __USE_GNU
  3686. +#endif
  3687. +
  3688. +#if HAVE_STRINGS_H
  3689. +# include <strings.h>
  3690. +#endif
  3691. +
  3692. +#if HAVE_SYS_STAT_H
  3693. +# include <sys/stat.h>
  3694. +#endif
  3695. +
  3696. +#if HAVE_SYS_WAIT_H
  3697. +# include <sys/wait.h>
  3698. +#endif
  3699. +
  3700. +#if HAVE_UNISTD_H
  3701. +# include <sys/types.h>
  3702. +# include <unistd.h>
  3703. +#endif
  3704. +
  3705. +#include <sys/mount.h>
  3706. +#include <mntent.h>
  3707. +
  3708. +#endif /* IPKG_INCLUDES_H */
  3709. diff -Nur busybox-1.17.1.orig/archival/libipkg/ipkg_install.c busybox-1.17.1/archival/libipkg/ipkg_install.c
  3710. --- busybox-1.17.1.orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
  3711. +++ busybox-1.17.1/archival/libipkg/ipkg_install.c 2010-07-28 13:07:49.511600581 +0200
  3712. @@ -0,0 +1,1982 @@
  3713. +/* ipkg_install.c - the itsy package management system
  3714. +
  3715. + Carl D. Worth
  3716. +
  3717. + Copyright (C) 2001 University of Southern California
  3718. +
  3719. + This program is free software; you can redistribute it and/or
  3720. + modify it under the terms of the GNU General Public License as
  3721. + published by the Free Software Foundation; either version 2, or (at
  3722. + your option) any later version.
  3723. +
  3724. + This program is distributed in the hope that it will be useful, but
  3725. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3726. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3727. + General Public License for more details.
  3728. +*/
  3729. +
  3730. +#include "ipkg.h"
  3731. +#include <errno.h>
  3732. +#include <dirent.h>
  3733. +#include <glob.h>
  3734. +#include <time.h>
  3735. +#include <signal.h>
  3736. +typedef void (*sighandler_t)(int);
  3737. +
  3738. +#include "pkg.h"
  3739. +#include "pkg_hash.h"
  3740. +#include "pkg_extract.h"
  3741. +
  3742. +#include "ipkg_install.h"
  3743. +#include "ipkg_configure.h"
  3744. +#include "ipkg_download.h"
  3745. +#include "ipkg_remove.h"
  3746. +
  3747. +#include "ipkg_utils.h"
  3748. +#include "ipkg_message.h"
  3749. +
  3750. +#include "sprintf_alloc.h"
  3751. +#include "file_util.h"
  3752. +#include "str_util.h"
  3753. +#include "xsystem.h"
  3754. +#include "user.h"
  3755. +
  3756. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  3757. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
  3758. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
  3759. +
  3760. +/*
  3761. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3762. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3763. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3764. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3765. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3766. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3767. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3768. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
  3769. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3770. +*/
  3771. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3772. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3773. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg);
  3774. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3775. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg);
  3776. +
  3777. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3778. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3779. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
  3780. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
  3781. +
  3782. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
  3783. +
  3784. +static int user_prefers_old_conffile(const char *file, const char *backup);
  3785. +
  3786. +static char *backup_filename_alloc(const char *file_name);
  3787. +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
  3788. +static int backup_exists_for(const char *file_name);
  3789. +static int backup_remove(const char *file_name);
  3790. +
  3791. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees);
  3792. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3793. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3794. +
  3795. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
  3796. +{
  3797. + int err, cmp;
  3798. + pkg_t *pkg, *old;
  3799. + char *old_version, *new_version;
  3800. +
  3801. + pkg = pkg_new();
  3802. + if (pkg == NULL) {
  3803. + return ENOMEM;
  3804. + }
  3805. +
  3806. + err = pkg_init_from_file(pkg, filename);
  3807. + if (err) {
  3808. + return err;
  3809. + }
  3810. +
  3811. + if (!pkg->architecture) {
  3812. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3813. + return -EINVAL;
  3814. + }
  3815. +
  3816. + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
  3817. + freeing the pkg that we pass in. It might be nice to clean this up
  3818. + if possible. */
  3819. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3820. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  3821. +
  3822. + pkg->local_filename = strdup(filename);
  3823. +
  3824. + if (old) {
  3825. + old_version = pkg_version_str_alloc(old);
  3826. + new_version = pkg_version_str_alloc(pkg);
  3827. +
  3828. + cmp = pkg_compare_versions(old, pkg);
  3829. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3830. + cmp = -1 ; /* then we force ipkg to downgrade */
  3831. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3832. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3833. + }
  3834. + if (cmp > 0) {
  3835. + ipkg_message(conf, IPKG_NOTICE,
  3836. + "Not downgrading package %s on %s from %s to %s.\n",
  3837. + old->name, old->dest->name, old_version, new_version);
  3838. + pkg->state_want = SW_DEINSTALL;
  3839. + pkg->state_flag |= SF_OBSOLETE;
  3840. + free(old_version);
  3841. + free(new_version);
  3842. + return 0;
  3843. + } else {
  3844. + free(old_version);
  3845. + free(new_version);
  3846. + }
  3847. + }
  3848. +
  3849. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3850. + return ipkg_install_pkg(conf, pkg,0);
  3851. +}
  3852. +
  3853. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3854. +{
  3855. + int cmp;
  3856. + pkg_t *old, *new;
  3857. + char *old_version, *new_version;
  3858. +
  3859. + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
  3860. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  3861. + if ( old )
  3862. + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
  3863. +
  3864. + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
  3865. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  3866. + if ( new )
  3867. + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
  3868. +
  3869. +/* Pigi Basically here is broken the version stuff.
  3870. + What's happening is that nothing provide the version to differents
  3871. + functions, so the returned struct is always the latest.
  3872. + That's why the install by name don't work.
  3873. +*/
  3874. + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
  3875. +
  3876. + if ( old )
  3877. + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
  3878. + if ( new )
  3879. + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
  3880. + ipkg_message(conf, IPKG_DEBUG2, " \n");
  3881. +
  3882. + if (new == NULL) {
  3883. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3884. + }
  3885. +
  3886. + new->state_flag |= SF_USER;
  3887. + if (old) {
  3888. + old_version = pkg_version_str_alloc(old);
  3889. + new_version = pkg_version_str_alloc(new);
  3890. +
  3891. + cmp = pkg_compare_versions(old, new);
  3892. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3893. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
  3894. + cmp = -1 ; /* then we force ipkg to downgrade */
  3895. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3896. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3897. + }
  3898. + ipkg_message(conf, IPKG_DEBUG,
  3899. + "Comparing visible versions of pkg %s:"
  3900. + "\n\t%s is installed "
  3901. + "\n\t%s is available "
  3902. + "\n\t%d was comparison result\n",
  3903. + pkg_name, old_version, new_version, cmp);
  3904. + if (cmp == 0 && !conf->force_reinstall) {
  3905. + ipkg_message(conf, IPKG_NOTICE,
  3906. + "Package %s (%s) installed in %s is up to date.\n",
  3907. + old->name, old_version, old->dest->name);
  3908. + free(old_version);
  3909. + free(new_version);
  3910. + return 0;
  3911. + } else if (cmp > 0) {
  3912. + ipkg_message(conf, IPKG_NOTICE,
  3913. + "Not downgrading package %s on %s from %s to %s.\n",
  3914. + old->name, old->dest->name, old_version, new_version);
  3915. + free(old_version);
  3916. + free(new_version);
  3917. + return 0;
  3918. + } else if (cmp < 0) {
  3919. + new->dest = old->dest;
  3920. + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
  3921. + }
  3922. + }
  3923. +
  3924. + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
  3925. + supposed to be an ipkg_error_t, but ipkg_install_pkg could
  3926. + return any kind of integer, (might be errno from a syscall,
  3927. + etc.). This is a real mess and will need to be cleaned up if
  3928. + anyone ever wants to make a nice libipkg. */
  3929. +
  3930. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3931. + return ipkg_install_pkg(conf, new,0);
  3932. +}
  3933. +
  3934. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3935. +{
  3936. + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
  3937. + int i;
  3938. + ipkg_error_t err;
  3939. + abstract_pkg_t *ppkg ;
  3940. +
  3941. + if (providers == NULL)
  3942. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3943. +
  3944. + for (i = 0; i < providers->len; i++) {
  3945. + ppkg = abstract_pkg_vec_get(providers, i);
  3946. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
  3947. + err = ipkg_install_by_name(conf, ppkg->name);
  3948. + if (err)
  3949. + return err;
  3950. +/* XXX Maybe ppkg should be freed ? */
  3951. + }
  3952. + return 0;
  3953. +}
  3954. +
  3955. +/*
  3956. + * Walk dependence graph starting with pkg, collect packages to be
  3957. + * installed into pkgs_needed, in dependence order.
  3958. + */
  3959. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
  3960. +{
  3961. + int i, err;
  3962. + pkg_vec_t *depends = pkg_vec_alloc();
  3963. + char **unresolved = NULL;
  3964. + int ndepends;
  3965. +
  3966. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  3967. + pkg, depends,
  3968. + &unresolved);
  3969. +
  3970. + if (unresolved) {
  3971. + ipkg_message(conf, IPKG_ERROR,
  3972. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  3973. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  3974. + while (*unresolved) {
  3975. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  3976. + unresolved++;
  3977. + }
  3978. + ipkg_message(conf, IPKG_ERROR, "\n");
  3979. + if (! conf->force_depends) {
  3980. + ipkg_message(conf, IPKG_INFO,
  3981. + "This could mean that your package list is out of date or that the packages\n"
  3982. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  3983. + "of this problem try again with the '-force-depends' option.\n");
  3984. + pkg_vec_free(depends);
  3985. + return IPKG_PKG_DEPS_UNSATISFIED;
  3986. + }
  3987. + }
  3988. +
  3989. + if (ndepends <= 0) {
  3990. + pkg_vec_free(depends);
  3991. + return 0;
  3992. + }
  3993. +
  3994. + for (i = 0; i < depends->len; i++) {
  3995. + pkg_t *dep = depends->pkgs[i];
  3996. + /* The package was uninstalled when we started, but another
  3997. + dep earlier in this loop may have depended on it and pulled
  3998. + it in, so check first. */
  3999. + if ((dep->state_status != SS_INSTALLED)
  4000. + && (dep->state_status != SS_UNPACKED)
  4001. + && (dep->state_want != SW_INSTALL)) {
  4002. +
  4003. + /* Mark packages as to-be-installed */
  4004. + dep->state_want = SW_INSTALL;
  4005. +
  4006. + /* Dependencies should be installed the same place as pkg */
  4007. + if (dep->dest == NULL) {
  4008. + dep->dest = pkg->dest;
  4009. + }
  4010. +
  4011. + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
  4012. + if (err) {
  4013. + pkg_vec_free(depends);
  4014. + return err;
  4015. + }
  4016. + }
  4017. + }
  4018. + if (pkgs_needed)
  4019. + pkg_vec_insert(pkgs_needed, pkg);
  4020. +
  4021. + pkg_vec_free(depends);
  4022. +
  4023. + return 0;
  4024. +}
  4025. +
  4026. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
  4027. +{
  4028. + int cmp;
  4029. + pkg_t *old, *new;
  4030. + char *old_version, *new_version;
  4031. +
  4032. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  4033. +
  4034. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  4035. + if (new == NULL) {
  4036. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4037. + }
  4038. + if (old) {
  4039. + old_version = pkg_version_str_alloc(old);
  4040. + new_version = pkg_version_str_alloc(new);
  4041. +
  4042. + cmp = pkg_compare_versions(old, new);
  4043. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4044. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
  4045. + cmp = -1 ; /* then we force ipkg to downgrade */
  4046. + /* We need to use a value < 0 because in the 0 case we are asking to */
  4047. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4048. + }
  4049. + ipkg_message(conf, IPKG_DEBUG,
  4050. + "comparing visible versions of pkg %s:"
  4051. + "\n\t%s is installed "
  4052. + "\n\t%s is available "
  4053. + "\n\t%d was comparison result\n",
  4054. + pkg_name, old_version, new_version, cmp);
  4055. + if (cmp == 0 && !conf->force_reinstall) {
  4056. + ipkg_message(conf, IPKG_NOTICE,
  4057. + "Package %s (%s) installed in %s is up to date.\n",
  4058. + old->name, old_version, old->dest->name);
  4059. + free(old_version);
  4060. + free(new_version);
  4061. + return 0;
  4062. + } else if (cmp > 0) {
  4063. + ipkg_message(conf, IPKG_NOTICE,
  4064. + "Not downgrading package %s on %s from %s to %s.\n",
  4065. + old->name, old->dest->name, old_version, new_version);
  4066. + free(old_version);
  4067. + free(new_version);
  4068. + return 0;
  4069. + } else if (cmp < 0) {
  4070. + new->dest = old->dest;
  4071. + old->state_want = SW_DEINSTALL;
  4072. + old->state_flag |= SF_OBSOLETE;
  4073. + }
  4074. + }
  4075. + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
  4076. +}
  4077. +
  4078. +
  4079. +
  4080. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
  4081. +{
  4082. + int i, err;
  4083. + pkg_vec_t *depends = pkg_vec_alloc();
  4084. + pkg_t *dep;
  4085. + char **unresolved = NULL;
  4086. + int ndepends;
  4087. +
  4088. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4089. + pkg, depends,
  4090. + &unresolved);
  4091. +
  4092. + if (unresolved) {
  4093. + ipkg_message(conf, IPKG_ERROR,
  4094. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4095. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4096. + while (*unresolved) {
  4097. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4098. + unresolved++;
  4099. + }
  4100. + ipkg_message(conf, IPKG_ERROR, "\n");
  4101. + if (! conf->force_depends) {
  4102. + ipkg_message(conf, IPKG_INFO,
  4103. + "This could mean that your package list is out of date or that the packages\n"
  4104. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4105. + "of this problem try again with the '-force-depends' option.\n");
  4106. + pkg_vec_free(depends);
  4107. + return IPKG_PKG_DEPS_UNSATISFIED;
  4108. + }
  4109. + }
  4110. +
  4111. + if (ndepends <= 0) {
  4112. + return 0;
  4113. + }
  4114. +
  4115. + /* Mark packages as to-be-installed */
  4116. + for (i=0; i < depends->len; i++) {
  4117. + /* Dependencies should be installed the same place as pkg */
  4118. + if (depends->pkgs[i]->dest == NULL) {
  4119. + depends->pkgs[i]->dest = pkg->dest;
  4120. + }
  4121. + depends->pkgs[i]->state_want = SW_INSTALL;
  4122. + }
  4123. +
  4124. + for (i = 0; i < depends->len; i++) {
  4125. + dep = depends->pkgs[i];
  4126. + /* The package was uninstalled when we started, but another
  4127. + dep earlier in this loop may have depended on it and pulled
  4128. + it in, so check first. */
  4129. + if ((dep->state_status != SS_INSTALLED)
  4130. + && (dep->state_status != SS_UNPACKED)) {
  4131. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4132. + err = ipkg_install_pkg(conf, dep,0);
  4133. + if (err) {
  4134. + pkg_vec_free(depends);
  4135. + return err;
  4136. + }
  4137. + }
  4138. + }
  4139. +
  4140. + pkg_vec_free(depends);
  4141. +
  4142. + return 0;
  4143. +}
  4144. +
  4145. +
  4146. +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
  4147. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
  4148. +{
  4149. + if (conf->nodeps == 0) {
  4150. + int i;
  4151. + pkg_vec_t *installed = pkg_vec_alloc();
  4152. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  4153. + for (i = 0; i < installed->len; i++) {
  4154. + pkg_t *pkg = installed->pkgs[i];
  4155. + satisfy_dependencies_for(conf, pkg);
  4156. + }
  4157. + pkg_vec_free(installed);
  4158. + }
  4159. + return 0;
  4160. +}
  4161. +
  4162. +
  4163. +
  4164. +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
  4165. +{
  4166. + int i;
  4167. + pkg_vec_t *conflicts = NULL;
  4168. + int level;
  4169. + const char *prefix;
  4170. + if (conf->force_depends) {
  4171. + level = IPKG_NOTICE;
  4172. + prefix = "Warning";
  4173. + } else {
  4174. + level = IPKG_ERROR;
  4175. + prefix = "ERROR";
  4176. + }
  4177. +
  4178. + if (!conf->force_depends)
  4179. + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(pkg);
  4180. +
  4181. + if (conflicts) {
  4182. + ipkg_message(conf, level,
  4183. + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
  4184. + i = 0;
  4185. + while (i < conflicts->len)
  4186. + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
  4187. + ipkg_message(conf, level, "\n");
  4188. + pkg_vec_free(conflicts);
  4189. + return IPKG_PKG_DEPS_UNSATISFIED;
  4190. + }
  4191. + return 0;
  4192. +}
  4193. +
  4194. +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
  4195. +{
  4196. + str_list_t *new_list = pkg_get_installed_files(new_pkg);
  4197. + str_list_elt_t *iter;
  4198. +
  4199. + for (iter = new_list->head; iter; iter = iter->next) {
  4200. + char *new_file = iter->data;
  4201. + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
  4202. + if (!new_file)
  4203. + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
  4204. + if (!owner || (owner == old_pkg))
  4205. + file_hash_set_file_owner(conf, new_file, new_pkg);
  4206. + }
  4207. + if (old_pkg) {
  4208. + str_list_t *old_list = pkg_get_installed_files(old_pkg);
  4209. + for (iter = old_list->head; iter; iter = iter->next) {
  4210. + char *old_file = iter->data;
  4211. + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
  4212. + if (owner == old_pkg) {
  4213. + /* obsolete */
  4214. + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
  4215. + }
  4216. + }
  4217. + }
  4218. + return 0;
  4219. +}
  4220. +
  4221. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
  4222. +{
  4223. + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
  4224. +
  4225. + /* sma 6.20.02: yup; here's the first bit */
  4226. + /*
  4227. + * XXX: BUG easy for cworth
  4228. + * 1) please point the call below to the correct current root destination
  4229. + * 2) we need to resolve how to check the required space for a pending pkg,
  4230. + * my diddling with the .ipk file size below isn't going to cut it.
  4231. + * 3) return a proper error code instead of 1
  4232. + */
  4233. + int comp_size, blocks_available;
  4234. +
  4235. + if (!conf->force_space && pkg->installed_size != NULL) {
  4236. + blocks_available = get_available_blocks(conf->default_dest->root_dir);
  4237. +
  4238. + comp_size = strtoul(pkg->installed_size, NULL, 0);
  4239. + /* round up a blocks count without doing fancy-but-slow casting jazz */
  4240. + comp_size = (int)((comp_size + 1023) / 1024);
  4241. +
  4242. + if (comp_size >= blocks_available) {
  4243. + ipkg_message(conf, IPKG_ERROR,
  4244. + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
  4245. + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
  4246. + return ENOSPC;
  4247. + }
  4248. + }
  4249. + return 0;
  4250. +}
  4251. +
  4252. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
  4253. +{
  4254. + int err;
  4255. + char *conffiles_file_name;
  4256. + char *root_dir;
  4257. + FILE *conffiles_file;
  4258. +
  4259. + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
  4260. +
  4261. + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
  4262. + if (pkg->tmp_unpack_dir == NULL) {
  4263. + ipkg_message(conf, IPKG_ERROR,
  4264. + "%s: Failed to create temporary directory '%s': %s\n",
  4265. + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
  4266. + return errno;
  4267. + }
  4268. +
  4269. + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
  4270. + if (err) {
  4271. + return err;
  4272. + }
  4273. +
  4274. + /* XXX: CLEANUP: There might be a cleaner place to read in the
  4275. + conffiles. Seems like I should be able to get everything to go
  4276. + through pkg_init_from_file. If so, maybe it would make sense to
  4277. + move all of unpack_pkg_control_files to that function. */
  4278. +
  4279. + /* Don't need to re-read conffiles if we already have it */
  4280. + if (pkg->conffiles.head) {
  4281. + return 0;
  4282. + }
  4283. +
  4284. + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
  4285. + if (! file_exists(conffiles_file_name)) {
  4286. + free(conffiles_file_name);
  4287. + return 0;
  4288. + }
  4289. +
  4290. + conffiles_file = fopen(conffiles_file_name, "r");
  4291. + if (conffiles_file == NULL) {
  4292. + fprintf(stderr, "%s: failed to open %s: %s\n",
  4293. + __FUNCTION__, conffiles_file_name, strerror(errno));
  4294. + free(conffiles_file_name);
  4295. + return errno;
  4296. + }
  4297. + free(conffiles_file_name);
  4298. +
  4299. + while (1) {
  4300. + char *cf_name;
  4301. + char *cf_name_in_dest;
  4302. +
  4303. + cf_name = file_read_line_alloc(conffiles_file);
  4304. + if (cf_name == NULL) {
  4305. + break;
  4306. + }
  4307. + str_chomp(cf_name);
  4308. + if (cf_name[0] == '\0') {
  4309. + continue;
  4310. + }
  4311. +
  4312. + /* Prepend dest->root_dir to conffile name.
  4313. + Take pains to avoid multiple slashes. */
  4314. + root_dir = pkg->dest->root_dir;
  4315. + if (conf->offline_root)
  4316. + /* skip the offline_root prefix */
  4317. + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
  4318. + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
  4319. + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
  4320. +
  4321. + /* Can't get an md5sum now, (file isn't extracted yet).
  4322. + We'll wait until resolve_conffiles */
  4323. + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
  4324. +
  4325. + free(cf_name);
  4326. + free(cf_name_in_dest);
  4327. + }
  4328. +
  4329. + fclose(conffiles_file);
  4330. +
  4331. + return 0;
  4332. +}
  4333. +
  4334. +/* returns number of installed replacees */
  4335. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees)
  4336. +{
  4337. + abstract_pkg_t **replaces = pkg->replaces;
  4338. + int replaces_count = pkg->replaces_count;
  4339. + int i, j;
  4340. + for (i = 0; i < replaces_count; i++) {
  4341. + abstract_pkg_t *ab_pkg = replaces[i];
  4342. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  4343. + if (pkg_vec) {
  4344. + for (j = 0; j < pkg_vec->len; j++) {
  4345. + pkg_t *replacee = pkg_vec->pkgs[j];
  4346. + if (!pkg_conflicts(pkg, replacee))
  4347. + continue;
  4348. + if (replacee->state_status == SS_INSTALLED) {
  4349. + pkg_vec_insert(installed_replacees, replacee);
  4350. + }
  4351. + }
  4352. + }
  4353. + }
  4354. + return installed_replacees->len;
  4355. +}
  4356. +
  4357. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4358. +{
  4359. + int i;
  4360. + int replaces_count = replacees->len;
  4361. + for (i = 0; i < replaces_count; i++) {
  4362. + pkg_t *replacee = replacees->pkgs[i];
  4363. + int err;
  4364. + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
  4365. + err = ipkg_remove_pkg(conf, replacee,0);
  4366. + if (err)
  4367. + return err;
  4368. + }
  4369. + return 0;
  4370. +}
  4371. +
  4372. +/* to unwind the removal: make sure they are installed */
  4373. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4374. +{
  4375. + int i, err;
  4376. + int replaces_count = replacees->len;
  4377. + for (i = 0; i < replaces_count; i++) {
  4378. + pkg_t *replacee = replacees->pkgs[i];
  4379. + if (replacee->state_status != SS_INSTALLED) {
  4380. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4381. + err = ipkg_install_pkg(conf, replacee,0);
  4382. + if (err)
  4383. + return err;
  4384. + }
  4385. + }
  4386. + return 0;
  4387. +}
  4388. +
  4389. +int caught_sigint = 0;
  4390. +static void ipkg_install_pkg_sigint_handler(int sig)
  4391. +{
  4392. + caught_sigint = sig;
  4393. +}
  4394. +
  4395. +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
  4396. +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
  4397. +{
  4398. + if (old_pkg) {
  4399. + char message_out[15];
  4400. + char *old_version = pkg_version_str_alloc(old_pkg);
  4401. + char *new_version = pkg_version_str_alloc(pkg);
  4402. + int cmp = pkg_compare_versions(old_pkg, pkg);
  4403. + int rc = 0;
  4404. +
  4405. + memset(message_out,'\x0',15);
  4406. + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
  4407. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4408. + cmp = -1 ; /* then we force ipkg to downgrade */
  4409. + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
  4410. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4411. + }
  4412. +
  4413. + if (cmp > 0) {
  4414. + ipkg_message(conf, IPKG_NOTICE,
  4415. + "Not downgrading package %s on %s from %s to %s.\n",
  4416. + old_pkg->name, old_pkg->dest->name, old_version, new_version);
  4417. + rc = 1;
  4418. + } else if (cmp < 0) {
  4419. + ipkg_message(conf, IPKG_NOTICE,
  4420. + "%s%s on %s from %s to %s...\n",
  4421. + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
  4422. + pkg->dest = old_pkg->dest;
  4423. + rc = 0;
  4424. + } else /* cmp == 0 */ {
  4425. + if (conf->force_reinstall) {
  4426. + ipkg_message(conf, IPKG_NOTICE,
  4427. + "Reinstalling %s (%s) on %s...\n",
  4428. + pkg->name, new_version, old_pkg->dest->name);
  4429. + pkg->dest = old_pkg->dest;
  4430. + rc = 0;
  4431. + } else {
  4432. + ipkg_message(conf, IPKG_NOTICE,
  4433. + "Not installing %s (%s) on %s -- already installed.\n",
  4434. + pkg->name, new_version, old_pkg->dest->name);
  4435. + rc = 1;
  4436. + }
  4437. + }
  4438. + free(old_version);
  4439. + free(new_version);
  4440. + return rc;
  4441. + } else {
  4442. + char message_out[15], *version ;
  4443. + memset(message_out,'\x0',15);
  4444. + if ( message )
  4445. + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
  4446. + else
  4447. + strncpy( message_out,"Installing ",strlen("Installing ") );
  4448. + version = pkg_version_str_alloc(pkg);
  4449. +
  4450. + ipkg_message(conf, IPKG_NOTICE,
  4451. + "%s%s (%s) to %s...\n", message_out,
  4452. + pkg->name, version, pkg->dest->name);
  4453. + free(version);
  4454. + return 0;
  4455. + }
  4456. +}
  4457. +
  4458. +/* and now the meat... */
  4459. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
  4460. +{
  4461. + int err = 0;
  4462. + int message = 0;
  4463. + pkg_t *old_pkg = NULL;
  4464. + pkg_vec_t *replacees;
  4465. + abstract_pkg_t *ab_pkg = NULL;
  4466. + int old_state_flag;
  4467. + uint8_t *file_md5;
  4468. +
  4469. +
  4470. + if ( from_upgrade )
  4471. + message = 1; /* Coming from an upgrade, and should change the output message */
  4472. +
  4473. + if (!pkg) {
  4474. + ipkg_message(conf, IPKG_ERROR,
  4475. + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
  4476. + return -EINVAL;
  4477. + }
  4478. +
  4479. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
  4480. +
  4481. + if (!pkg_arch_supported(conf, pkg)) {
  4482. + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
  4483. + pkg->architecture, pkg->name);
  4484. + return -EINVAL;
  4485. + }
  4486. + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
  4487. + err = satisfy_dependencies_for(conf, pkg);
  4488. + if (err) { return err; }
  4489. +
  4490. + ipkg_message(conf, IPKG_NOTICE,
  4491. + "Package %s is already installed in %s.\n",
  4492. + pkg->name, pkg->dest->name);
  4493. + return 0;
  4494. + }
  4495. +
  4496. + if (pkg->dest == NULL) {
  4497. + pkg->dest = conf->default_dest;
  4498. + }
  4499. +
  4500. + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  4501. +
  4502. + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
  4503. + if (err) { return err; }
  4504. +
  4505. + pkg->state_want = SW_INSTALL;
  4506. + if (old_pkg){
  4507. + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
  4508. + }
  4509. +
  4510. +
  4511. + /* Abhaya: conflicts check */
  4512. + err = check_conflicts_for(conf, pkg);
  4513. + if (err) { return err; }
  4514. +
  4515. + /* this setup is to remove the upgrade scenario in the end when
  4516. + installing pkg A, A deps B & B deps on A. So both B and A are
  4517. + installed. Then A's installation is started resulting in an
  4518. + uncecessary upgrade */
  4519. + if (pkg->state_status == SS_INSTALLED
  4520. + && conf->force_reinstall == 0) return 0;
  4521. +
  4522. + err = verify_pkg_installable(conf, pkg);
  4523. + if (err) { return err; }
  4524. +
  4525. + if (pkg->local_filename == NULL) {
  4526. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  4527. + if (err) {
  4528. + ipkg_message(conf, IPKG_ERROR,
  4529. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  4530. + pkg->name);
  4531. + return err;
  4532. + }
  4533. + }
  4534. +
  4535. +/* Check for md5 values */
  4536. + if (pkg->md5sum)
  4537. + {
  4538. + file_md5 = file_md5sum_alloc(pkg->local_filename);
  4539. + if (strcmp((char *)file_md5, pkg->md5sum))
  4540. + {
  4541. + ipkg_message(conf, IPKG_ERROR,
  4542. + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
  4543. + pkg->name);
  4544. + free(file_md5);
  4545. + return err;
  4546. + }
  4547. + free(file_md5);
  4548. + }
  4549. +
  4550. + if (pkg->tmp_unpack_dir == NULL) {
  4551. + unpack_pkg_control_files(conf, pkg);
  4552. + }
  4553. +
  4554. + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
  4555. +/* Pigi: check if it will pass from here when replacing. It seems to fail */
  4556. +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
  4557. + err = update_file_ownership(conf, pkg, old_pkg);
  4558. + if (err) { return err; }
  4559. +
  4560. + if (conf->nodeps == 0) {
  4561. + err = satisfy_dependencies_for(conf, pkg);
  4562. + if (err) { return err; }
  4563. + }
  4564. +
  4565. + replacees = pkg_vec_alloc();
  4566. + pkg_get_installed_replacees(pkg, replacees);
  4567. +
  4568. + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
  4569. + {
  4570. + sigset_t newset, oldset;
  4571. + sighandler_t old_handler = NULL;
  4572. + int use_signal = 0;
  4573. + caught_sigint = 0;
  4574. + if (use_signal) {
  4575. + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
  4576. + } else {
  4577. + sigemptyset(&newset);
  4578. + sigaddset(&newset, SIGINT);
  4579. + sigprocmask(SIG_BLOCK, &newset, &oldset);
  4580. + }
  4581. +
  4582. + ipkg_state_changed++;
  4583. + pkg->state_flag |= SF_FILELIST_CHANGED;
  4584. +
  4585. + /* XXX: BUG: we really should treat replacement more like an upgrade
  4586. + * Instead, we're going to remove the replacees
  4587. + */
  4588. + err = pkg_remove_installed_replacees(conf, replacees);
  4589. + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
  4590. +
  4591. + /*
  4592. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  4593. + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
  4594. +
  4595. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  4596. + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
  4597. + */
  4598. +
  4599. + err = preinst_configure(conf, pkg, old_pkg);
  4600. + /*
  4601. + if (err) goto UNWIND_PREINST_CONFIGURE;
  4602. + */
  4603. +
  4604. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  4605. + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
  4606. +
  4607. + err = check_data_file_clashes(conf, pkg, old_pkg);
  4608. + /*
  4609. + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
  4610. +
  4611. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  4612. + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
  4613. + */
  4614. +
  4615. + if (conf->noaction) return 0;
  4616. +
  4617. + /* point of no return: no unwinding after this */
  4618. + if (old_pkg && !conf->force_reinstall) {
  4619. + old_pkg->state_want = SW_DEINSTALL;
  4620. +
  4621. + if (old_pkg->state_flag & SF_NOPRUNE) {
  4622. + ipkg_message(conf, IPKG_INFO,
  4623. + " not removing obsolesced files because package marked noprune\n");
  4624. + } else {
  4625. + ipkg_message(conf, IPKG_INFO,
  4626. + " removing obsolesced files\n");
  4627. + remove_obsolesced_files(conf, pkg, old_pkg);
  4628. + }
  4629. + /* removing files from old package, to avoid ghost files */
  4630. + remove_data_files_and_list(conf, old_pkg);
  4631. +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
  4632. + remove_maintainer_scripts_except_postrm(conf, old_pkg);
  4633. + remove_postrm(conf, old_pkg);
  4634. +/* Pigi */
  4635. +
  4636. + }
  4637. +
  4638. +
  4639. + ipkg_message(conf, IPKG_INFO,
  4640. + " installing maintainer scripts\n");
  4641. + install_maintainer_scripts(conf, pkg, old_pkg);
  4642. +
  4643. + /* the following just returns 0
  4644. + remove_disappeared(conf, pkg);
  4645. + */
  4646. +
  4647. + ipkg_message(conf, IPKG_INFO,
  4648. + " installing data files\n");
  4649. + install_data_files(conf, pkg);
  4650. +
  4651. +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
  4652. + err = check_data_file_clashes_change(conf, pkg);
  4653. +
  4654. + ipkg_message(conf, IPKG_INFO,
  4655. + " resolving conf files\n");
  4656. + resolve_conffiles(conf, pkg);
  4657. +
  4658. + pkg->state_status = SS_UNPACKED;
  4659. + old_state_flag = pkg->state_flag;
  4660. + pkg->state_flag &= ~SF_PREFER;
  4661. + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
  4662. +
  4663. + if (old_pkg && !conf->force_reinstall) {
  4664. + old_pkg->state_status = SS_NOT_INSTALLED;
  4665. + }
  4666. +
  4667. + time(&pkg->installed_time);
  4668. +
  4669. + ipkg_message(conf, IPKG_INFO,
  4670. + " cleanup temp files\n");
  4671. + cleanup_temporary_files(conf, pkg);
  4672. +
  4673. + ab_pkg = pkg->parent;
  4674. + if (ab_pkg)
  4675. + ab_pkg->state_status = pkg->state_status;
  4676. +
  4677. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  4678. +
  4679. + if (use_signal)
  4680. + signal(SIGINT, old_handler);
  4681. + else
  4682. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4683. +
  4684. + return 0;
  4685. +
  4686. +
  4687. + /*
  4688. + UNWIND_POSTRM_UPGRADE_OLD_PKG:
  4689. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4690. + UNWIND_CHECK_DATA_FILE_CLASHES:
  4691. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  4692. + */
  4693. + UNWIND_BACKUP_MODIFIED_CONFFILES:
  4694. + backup_modified_conffiles_unwind(pkg, old_pkg);
  4695. + /*
  4696. + UNWIND_PREINST_CONFIGURE:
  4697. + preinst_configure_unwind(conf, pkg, old_pkg);
  4698. + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
  4699. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  4700. + UNWIND_PRERM_UPGRADE_OLD_PKG:
  4701. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4702. + */
  4703. + UNWIND_REMOVE_INSTALLED_REPLACEES:
  4704. + pkg_remove_installed_replacees_unwind(conf, replacees);
  4705. +
  4706. + ipkg_message(conf, IPKG_INFO,
  4707. + " cleanup temp files\n");
  4708. + cleanup_temporary_files(conf, pkg);
  4709. +
  4710. + ipkg_message(conf, IPKG_INFO,
  4711. + "Failed.\n");
  4712. + if (use_signal)
  4713. + signal(SIGINT, old_handler);
  4714. + else
  4715. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4716. +
  4717. + return err;
  4718. + }
  4719. +}
  4720. +
  4721. +/*
  4722. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4723. +{
  4724. + DPKG_INCOMPATIBILITY:
  4725. + dpkg does some things here that we don't do yet. Do we care?
  4726. +
  4727. + 1. If a version of the package is already installed, call
  4728. + old-prerm upgrade new-version
  4729. + 2. If the script runs but exits with a non-zero exit status
  4730. + new-prerm failed-upgrade old-version
  4731. + Error unwind, for both the above cases:
  4732. + old-postinst abort-upgrade new-version
  4733. + return 0;
  4734. +}
  4735. +*/
  4736. +
  4737. +/*
  4738. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4739. +{
  4740. + DPKG_INCOMPATIBILITY:
  4741. + dpkg does some things here that we don't do yet. Do we care?
  4742. + (See prerm_upgrade_old_package for details)
  4743. +
  4744. + return 0;
  4745. +}
  4746. +*/
  4747. +
  4748. +/*
  4749. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4750. +{
  4751. + DPKG_INCOMPATIBILITY:
  4752. + dpkg does some things here that we don't do yet. Do we care?
  4753. + 2. If a 'conflicting' package is being removed at the same time:
  4754. + 1. If any packages depended on that conflicting package and
  4755. + --auto-deconfigure is specified, call, for each such package:
  4756. + deconfigured's-prerm deconfigure \
  4757. + in-favour package-being-installed version \
  4758. + removing conflicting-package version
  4759. + Error unwind:
  4760. + deconfigured's-postinst abort-deconfigure \
  4761. + in-favour package-being-installed-but-failed version \
  4762. + removing conflicting-package version
  4763. +
  4764. + The deconfigured packages are marked as requiring
  4765. + configuration, so that if --install is used they will be
  4766. + configured again if possible.
  4767. + 2. To prepare for removal of the conflicting package, call:
  4768. + conflictor's-prerm remove in-favour package new-version
  4769. + Error unwind:
  4770. + conflictor's-postinst abort-remove in-favour package new-version
  4771. + return 0;
  4772. +}
  4773. +*/
  4774. +
  4775. +/*
  4776. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4777. +{
  4778. + DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
  4779. + do yet. Do we care? (See prerm_deconfigure_conflictors for
  4780. + details)
  4781. + return 0;
  4782. +}
  4783. +*/
  4784. +
  4785. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4786. +{
  4787. + int err;
  4788. + char *preinst_args;
  4789. +
  4790. + if (old_pkg) {
  4791. + char *old_version = pkg_version_str_alloc(old_pkg);
  4792. + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
  4793. + free(old_version);
  4794. + } else if (pkg->state_status == SS_CONFIG_FILES) {
  4795. + char *pkg_version = pkg_version_str_alloc(pkg);
  4796. + sprintf_alloc(&preinst_args, "install %s", pkg_version);
  4797. + free(pkg_version);
  4798. + } else {
  4799. + preinst_args = strdup("install");
  4800. + }
  4801. +
  4802. + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
  4803. + if (err) {
  4804. + ipkg_message(conf, IPKG_ERROR,
  4805. + "Aborting installation of %s\n", pkg->name);
  4806. + return 1;
  4807. + }
  4808. +
  4809. + free(preinst_args);
  4810. +
  4811. + return 0;
  4812. +}
  4813. +
  4814. +/*
  4815. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4816. +{
  4817. + DPKG_INCOMPATIBILITY:
  4818. + dpkg does the following error unwind, should we?
  4819. + pkg->postrm abort-upgrade old-version
  4820. + OR pkg->postrm abort-install old-version
  4821. + OR pkg->postrm abort-install
  4822. + return 0;
  4823. +}
  4824. +*/
  4825. +
  4826. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4827. +{
  4828. + int err;
  4829. + conffile_list_elt_t *iter;
  4830. + conffile_t *cf;
  4831. +
  4832. + if (conf->noaction) return 0;
  4833. +
  4834. + /* Backup all modified conffiles */
  4835. + if (old_pkg) {
  4836. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4837. + char *cf_name;
  4838. +
  4839. + cf = iter->data;
  4840. + cf_name = root_filename_alloc(conf, cf->name);
  4841. +
  4842. + /* Don't worry if the conffile is just plain gone */
  4843. + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
  4844. + err = backup_make_backup(conf, cf_name);
  4845. + if (err) {
  4846. + return err;
  4847. + }
  4848. + }
  4849. + free(cf_name);
  4850. + }
  4851. + }
  4852. +
  4853. + /* Backup all conffiles that were not conffiles in old_pkg */
  4854. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4855. + char *cf_name;
  4856. + cf = iter->data;
  4857. + cf_name = root_filename_alloc(conf, cf->name);
  4858. + /* Ignore if this was a conffile in old_pkg as well */
  4859. + if (pkg_get_conffile(old_pkg, cf->name)) {
  4860. + continue;
  4861. + }
  4862. +
  4863. + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
  4864. + err = backup_make_backup(conf, cf_name);
  4865. + if (err) {
  4866. + return err;
  4867. + }
  4868. + }
  4869. + free(cf_name);
  4870. + }
  4871. +
  4872. + return 0;
  4873. +}
  4874. +
  4875. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg)
  4876. +{
  4877. + conffile_list_elt_t *iter;
  4878. +
  4879. + if (old_pkg) {
  4880. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4881. + backup_remove(iter->data->name);
  4882. + }
  4883. + }
  4884. +
  4885. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4886. + backup_remove(iter->data->name);
  4887. + }
  4888. +
  4889. + return 0;
  4890. +}
  4891. +
  4892. +
  4893. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4894. +{
  4895. + /* DPKG_INCOMPATIBILITY:
  4896. + ipkg takes a slightly different approach than dpkg at this
  4897. + point. dpkg installs each file in the new package while
  4898. + creating a backup for any file that is replaced, (so that it
  4899. + can unwind if necessary). To avoid complexity and redundant
  4900. + storage, ipkg doesn't do any installation until later, (at the
  4901. + point at which dpkg removes the backups.
  4902. +
  4903. + But, we do have to check for data file clashes, since after
  4904. + installing a package with a file clash, removing either of the
  4905. + packages involved in the clash has the potential to break the
  4906. + other package.
  4907. + */
  4908. + str_list_t *files_list;
  4909. + str_list_elt_t *iter;
  4910. +
  4911. + int clashes = 0;
  4912. +
  4913. + files_list = pkg_get_installed_files(pkg);
  4914. + for (iter = files_list->head; iter; iter = iter->next) {
  4915. + char *root_filename;
  4916. + char *filename = iter->data;
  4917. + root_filename = root_filename_alloc(conf, filename);
  4918. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  4919. + pkg_t *owner;
  4920. + pkg_t *obs;
  4921. + /* Pre-existing conffiles are OK */
  4922. + /* @@@@ should have way to check that it is a conffile -Jamey */
  4923. + if (backup_exists_for(root_filename)) {
  4924. + continue;
  4925. + }
  4926. +
  4927. + /* Pre-existing files are OK if force-overwrite was asserted. */
  4928. + if (conf->force_overwrite) {
  4929. + /* but we need to change who owns this file */
  4930. + file_hash_set_file_owner(conf, filename, pkg);
  4931. + continue;
  4932. + }
  4933. +
  4934. + owner = file_hash_get_file_owner(conf, filename);
  4935. +
  4936. + /* Pre-existing files are OK if owned by the pkg being upgraded. */
  4937. + if (owner && old_pkg) {
  4938. + if (strcmp(owner->name, old_pkg->name) == 0) {
  4939. + continue;
  4940. + }
  4941. + }
  4942. +
  4943. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  4944. + if (owner) {
  4945. + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
  4946. + if (pkg_replaces(pkg, owner)) {
  4947. + continue;
  4948. + }
  4949. +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
  4950. + then it's ok to overwrite. */
  4951. + if (strcmp(owner->name,pkg->name)==0){
  4952. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  4953. + continue;
  4954. + }
  4955. + }
  4956. +
  4957. + /* Pre-existing files are OK if they are obsolete */
  4958. + obs = hash_table_get(&conf->obs_file_hash, filename);
  4959. + if (obs) {
  4960. + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
  4961. + continue;
  4962. + }
  4963. +
  4964. + /* We have found a clash. */
  4965. + ipkg_message(conf, IPKG_ERROR,
  4966. + "Package %s wants to install file %s\n"
  4967. + "\tBut that file is already provided by package ",
  4968. + pkg->name, filename);
  4969. + if (owner) {
  4970. + ipkg_message(conf, IPKG_ERROR,
  4971. + "%s\n", owner->name);
  4972. + } else {
  4973. + ipkg_message(conf, IPKG_ERROR,
  4974. + "<no package>\nPlease move this file out of the way and try again.\n");
  4975. + }
  4976. + clashes++;
  4977. + }
  4978. + free(root_filename);
  4979. + }
  4980. + pkg_free_installed_files(pkg);
  4981. +
  4982. + return clashes;
  4983. +}
  4984. +
  4985. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg)
  4986. +{
  4987. + /* Basically that's the worst hack I could do to be able to change ownership of
  4988. + file list, but, being that we have no way to unwind the mods, due to structure
  4989. + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
  4990. + What we do here is change the ownership of file in hash if a replace ( or similar events
  4991. + happens )
  4992. + Only the action that are needed to change name should be considered.
  4993. + @@@ To change after 1.0 release.
  4994. + */
  4995. + str_list_t *files_list;
  4996. + str_list_elt_t *iter;
  4997. +
  4998. + int clashes = 0;
  4999. +
  5000. + files_list = pkg_get_installed_files(pkg);
  5001. + for (iter = files_list->head; iter; iter = iter->next) {
  5002. + char *root_filename;
  5003. + char *filename = iter->data;
  5004. + root_filename = root_filename_alloc(conf, filename);
  5005. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5006. + pkg_t *owner;
  5007. +
  5008. + if (conf->force_overwrite) {
  5009. + /* but we need to change who owns this file */
  5010. + file_hash_set_file_owner(conf, filename, pkg);
  5011. + continue;
  5012. + }
  5013. +
  5014. + owner = file_hash_get_file_owner(conf, filename);
  5015. +
  5016. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5017. + if (owner) {
  5018. + if (pkg_replaces(pkg, owner)) {
  5019. +/* It's now time to change the owner of that file.
  5020. + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
  5021. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5022. + file_hash_set_file_owner(conf, filename, pkg);
  5023. + continue;
  5024. + }
  5025. + }
  5026. +
  5027. + }
  5028. + free(root_filename);
  5029. + }
  5030. + pkg_free_installed_files(pkg);
  5031. +
  5032. + return clashes;
  5033. +}
  5034. +
  5035. +/*
  5036. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5037. +{
  5038. + Nothing to do since check_data_file_clashes doesn't change state
  5039. + return 0;
  5040. +}
  5041. +*/
  5042. +
  5043. +/*
  5044. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5045. +{
  5046. + DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
  5047. + 1. If the package is being upgraded, call
  5048. + old-postrm upgrade new-version
  5049. + 2. If this fails, attempt:
  5050. + new-postrm failed-upgrade old-version
  5051. + Error unwind, for both cases:
  5052. + old-preinst abort-upgrade new-version
  5053. + return 0;
  5054. +}
  5055. +*/
  5056. +
  5057. +/*
  5058. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5059. +{
  5060. + DPKG_INCOMPATIBILITY:
  5061. + dpkg does some things here that we don't do yet. Do we care?
  5062. + (See postrm_upgrade_old_pkg for details)
  5063. + return 0;
  5064. +}
  5065. +*/
  5066. +
  5067. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5068. +{
  5069. + int err;
  5070. + str_list_t *old_files;
  5071. + str_list_elt_t *of;
  5072. + str_list_t *new_files;
  5073. + str_list_elt_t *nf;
  5074. +
  5075. + if (old_pkg == NULL) {
  5076. + return 0;
  5077. + }
  5078. +
  5079. + old_files = pkg_get_installed_files(old_pkg);
  5080. + new_files = pkg_get_installed_files(pkg);
  5081. +
  5082. + for (of = old_files->head; of; of = of->next) {
  5083. + pkg_t *owner;
  5084. + char *old, *new;
  5085. + old = of->data;
  5086. + for (nf = new_files->head; nf; nf = nf->next) {
  5087. + new = nf->data;
  5088. + if (strcmp(old, new) == 0) {
  5089. + goto NOT_OBSOLETE;
  5090. + }
  5091. + }
  5092. + if (file_is_dir(old)) {
  5093. + continue;
  5094. + }
  5095. + owner = file_hash_get_file_owner(conf, old);
  5096. + if (owner != old_pkg) {
  5097. + /* in case obsolete file no longer belongs to old_pkg */
  5098. + continue;
  5099. + }
  5100. +
  5101. + /* old file is obsolete */
  5102. + ipkg_message(conf, IPKG_INFO,
  5103. + " removing obsolete file %s\n", old);
  5104. + if (!conf->noaction) {
  5105. + err = unlink(old);
  5106. + if (err) {
  5107. + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
  5108. + strerror(errno));
  5109. + }
  5110. + }
  5111. +
  5112. + NOT_OBSOLETE:
  5113. + ;
  5114. + }
  5115. +
  5116. + pkg_free_installed_files(old_pkg);
  5117. + pkg_free_installed_files(pkg);
  5118. +
  5119. + return 0;
  5120. +}
  5121. +
  5122. +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5123. +{
  5124. + int i;
  5125. + int err = 0;
  5126. + char *globpattern;
  5127. + glob_t globbuf;
  5128. + if (0) {
  5129. + if (!pkg->dest) {
  5130. + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
  5131. + return -1;
  5132. + }
  5133. + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
  5134. + err = glob(globpattern, 0, NULL, &globbuf);
  5135. + free(globpattern);
  5136. + if (err) {
  5137. + return err;
  5138. + }
  5139. + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
  5140. + for (i = 0; i < globbuf.gl_pathc; i++) {
  5141. + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
  5142. + globbuf.gl_pathv[i], old_pkg->name);
  5143. + if (!conf->noaction)
  5144. + unlink(globbuf.gl_pathv[i]);
  5145. + }
  5146. + globfree(&globbuf);
  5147. + }
  5148. + return err;
  5149. +}
  5150. +
  5151. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5152. +{
  5153. + int ret;
  5154. + char *prefix;
  5155. +
  5156. + if (old_pkg)
  5157. + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
  5158. + sprintf_alloc(&prefix, "%s.", pkg->name);
  5159. + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
  5160. + pkg->dest->info_dir,
  5161. + prefix);
  5162. + free(prefix);
  5163. + return ret;
  5164. +}
  5165. +
  5166. +/*
  5167. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
  5168. +{
  5169. + DPKG_INCOMPATIBILITY:
  5170. + This is a fairly sophisticated dpkg operation. Shall we
  5171. + skip it?
  5172. +
  5173. + Any packages all of whose files have been overwritten during the
  5174. + installation, and which aren't required for dependencies, are
  5175. + considered to have been removed. For each such package
  5176. + 1. disappearer's-postrm disappear overwriter overwriter-version
  5177. + 2. The package's maintainer scripts are removed
  5178. + 3. It is noted in the status database as being in a sane state,
  5179. + namely not installed (any conffiles it may have are ignored,
  5180. + rather than being removed by dpkg). Note that disappearing
  5181. + packages do not have their prerm called, because dpkg doesn't
  5182. + know in advance that the package is going to vanish.
  5183. +
  5184. +
  5185. + return 0;
  5186. +}
  5187. +*/
  5188. +
  5189. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
  5190. +{
  5191. + int err;
  5192. +
  5193. + /* ipkg takes a slightly different approach to data file backups
  5194. + than dpkg. Rather than removing backups at this point, we
  5195. + actually do the data file installation now. See comments in
  5196. + check_data_file_clashes() for more details. */
  5197. +
  5198. + ipkg_message(conf, IPKG_INFO,
  5199. + " extracting data files to %s\n", pkg->dest->root_dir);
  5200. + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
  5201. + if (err) {
  5202. + return err;
  5203. + }
  5204. +
  5205. + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
  5206. + so we can't save ourself from removing important packages
  5207. + At this point we (should) have extracted the .control file, so it
  5208. + would be a good idea to reload the data in it, and set the Essential
  5209. + state in *pkg. From now on the Essential is back in status file and
  5210. + we can protect again.
  5211. + We should operate this way:
  5212. + fopen the file ( pkg->dest->root_dir/pkg->name.control )
  5213. + check for "Essential" in it
  5214. + set the value in pkg->essential.
  5215. + This new routine could be useful also for every other flag
  5216. + Pigi: 16/03/2004 */
  5217. + set_flags_from_control(conf, pkg) ;
  5218. +
  5219. + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
  5220. + err = pkg_write_filelist(conf, pkg);
  5221. + if (err)
  5222. + return err;
  5223. +
  5224. + /* XXX: FEATURE: ipkg should identify any files which existed
  5225. + before installation and which were overwritten, (see
  5226. + check_data_file_clashes()). What it must do is remove any such
  5227. + files from the filelist of the old package which provided the
  5228. + file. Otherwise, if the old package were removed at some point
  5229. + it would break the new package. Removing the new package will
  5230. + also break the old one, but this cannot be helped since the old
  5231. + package's file has already been deleted. This is the importance
  5232. + of check_data_file_clashes(), and only allowing ipkg to install
  5233. + a clashing package with a user force. */
  5234. +
  5235. + return 0;
  5236. +}
  5237. +
  5238. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
  5239. +{
  5240. + conffile_list_elt_t *iter;
  5241. + conffile_t *cf;
  5242. + char *cf_backup;
  5243. + uint8_t *md5sum;
  5244. +
  5245. +
  5246. + if (conf->noaction) return 0;
  5247. +
  5248. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  5249. + char *root_filename;
  5250. + cf = iter->data;
  5251. + root_filename = root_filename_alloc(conf, cf->name);
  5252. +
  5253. + /* Might need to initialize the md5sum for each conffile */
  5254. + if (cf->value == NULL) {
  5255. + cf->value = (char *)file_md5sum_alloc(root_filename);
  5256. + }
  5257. +
  5258. + if (!file_exists(root_filename)) {
  5259. + free(root_filename);
  5260. + continue;
  5261. + }
  5262. +
  5263. + cf_backup = backup_filename_alloc(root_filename);
  5264. +
  5265. +
  5266. + if (file_exists(cf_backup)) {
  5267. + /* Let's compute md5 to test if files are changed */
  5268. + md5sum = file_md5sum_alloc(cf_backup);
  5269. + if (strcmp( cf->value, (char *)md5sum) != 0 ) {
  5270. + if (conf->force_defaults
  5271. + || user_prefers_old_conffile(cf->name, cf_backup) ) {
  5272. + rename(cf_backup, root_filename);
  5273. + }
  5274. + }
  5275. + unlink(cf_backup);
  5276. + free(md5sum);
  5277. + }
  5278. +
  5279. + free(cf_backup);
  5280. + free(root_filename);
  5281. + }
  5282. +
  5283. + return 0;
  5284. +}
  5285. +
  5286. +static int user_prefers_old_conffile(const char *file_name, const char *backup)
  5287. +{
  5288. + char *response;
  5289. + const char *short_file_name;
  5290. +
  5291. + short_file_name = strrchr(file_name, '/');
  5292. + if (short_file_name) {
  5293. + short_file_name++;
  5294. + } else {
  5295. + short_file_name = file_name;
  5296. + }
  5297. +
  5298. + while (1) {
  5299. + response = get_user_response(" Configuration file '%s'\n"
  5300. + " ==> File on system created by you or by a script.\n"
  5301. + " ==> File also in package provided by package maintainer.\n"
  5302. + " What would you like to do about it ? Your options are:\n"
  5303. + " Y or I : install the package maintainer's version\n"
  5304. + " N or O : keep your currently-installed version\n"
  5305. +#ifdef CONFIG_DIFF
  5306. + " D : show the differences between the versions\n"
  5307. +#endif
  5308. + " The default action is to keep your current version.\n"
  5309. + " *** %s (Y/I/N/O"
  5310. +#ifdef CONFIG_DIFF
  5311. + "/D"
  5312. +#endif
  5313. + ") [default=N] ? ", file_name, short_file_name);
  5314. + if (strcmp(response, "y") == 0
  5315. + || strcmp(response, "i") == 0
  5316. + || strcmp(response, "yes") == 0) {
  5317. + free(response);
  5318. + return 0;
  5319. + }
  5320. +
  5321. +#ifdef CONFIG_DIFF
  5322. + if (strcmp(response, "d") == 0) {
  5323. + char *cmd;
  5324. +
  5325. + free(response);
  5326. + /* XXX: BUG rewrite to use exec or busybox's internal diff */
  5327. + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
  5328. + xsystem(cmd);
  5329. + free(cmd);
  5330. + printf(" [Press ENTER to continue]\n");
  5331. + response = file_read_line_alloc(stdin);
  5332. + free(response);
  5333. + continue;
  5334. + }
  5335. +#endif
  5336. +
  5337. + free(response);
  5338. + return 1;
  5339. + }
  5340. +}
  5341. +
  5342. +/* XXX: CLEANUP: I'd like to move all of the code for
  5343. + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
  5344. + it would make sense to cleanup pkg->tmp_unpack_dir directly from
  5345. + pkg_deinit for example). */
  5346. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
  5347. +{
  5348. + DIR *tmp_dir;
  5349. + struct dirent *dirent;
  5350. + char *tmp_file;
  5351. +
  5352. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  5353. +#error
  5354. + ipkg_message(conf, IPKG_DEBUG,
  5355. + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  5356. + __FUNCTION__, pkg->tmp_unpack_dir);
  5357. + return 0;
  5358. +#endif
  5359. +
  5360. + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
  5361. + tmp_dir = opendir(pkg->tmp_unpack_dir);
  5362. + if (tmp_dir) {
  5363. + while (1) {
  5364. + dirent = readdir(tmp_dir);
  5365. + if (dirent == NULL) {
  5366. + break;
  5367. + }
  5368. + sprintf_alloc(&tmp_file, "%s/%s",
  5369. + pkg->tmp_unpack_dir, dirent->d_name);
  5370. + if (! file_is_dir(tmp_file)) {
  5371. + unlink(tmp_file);
  5372. + }
  5373. + free(tmp_file);
  5374. + }
  5375. + closedir(tmp_dir);
  5376. + rmdir(pkg->tmp_unpack_dir);
  5377. + free(pkg->tmp_unpack_dir);
  5378. + pkg->tmp_unpack_dir = NULL;
  5379. + }
  5380. + }
  5381. +
  5382. + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
  5383. + pkg->name, pkg->local_filename, conf->tmp_dir);
  5384. + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
  5385. + unlink(pkg->local_filename);
  5386. + free(pkg->local_filename);
  5387. + pkg->local_filename = NULL;
  5388. + }
  5389. +
  5390. + return 0;
  5391. +}
  5392. +
  5393. +static char *backup_filename_alloc(const char *file_name)
  5394. +{
  5395. + char *backup;
  5396. +
  5397. + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
  5398. +
  5399. + return backup;
  5400. +}
  5401. +
  5402. +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
  5403. +{
  5404. + int err;
  5405. + char *backup;
  5406. +
  5407. + backup = backup_filename_alloc(file_name);
  5408. + err = file_copy(file_name, backup);
  5409. + if (err) {
  5410. + ipkg_message(conf, IPKG_ERROR,
  5411. + "%s: Failed to copy %s to %s\n",
  5412. + __FUNCTION__, file_name, backup);
  5413. + }
  5414. +
  5415. + free(backup);
  5416. +
  5417. + return err;
  5418. +}
  5419. +
  5420. +static int backup_exists_for(const char *file_name)
  5421. +{
  5422. + int ret;
  5423. + char *backup;
  5424. +
  5425. + backup = backup_filename_alloc(file_name);
  5426. +
  5427. + ret = file_exists(backup);
  5428. +
  5429. + free(backup);
  5430. +
  5431. + return ret;
  5432. +}
  5433. +
  5434. +static int backup_remove(const char *file_name)
  5435. +{
  5436. + char *backup;
  5437. +
  5438. + backup = backup_filename_alloc(file_name);
  5439. + unlink(backup);
  5440. + free(backup);
  5441. +
  5442. + return 0;
  5443. +}
  5444. +
  5445. +
  5446. +
  5447. +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
  5448. +
  5449. +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
  5450. +{
  5451. + /* first, remove the packages that need removing */
  5452. + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
  5453. + pkg_t *pkg = pkgs_to_remove->pkgs[i];
  5454. + err = ipkg_remove_pkg(conf, pkg,0);
  5455. + if (err) return err;
  5456. + }
  5457. + return 0;
  5458. +}
  5459. +
  5460. +int ipkg_process_actions_sanity_check(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install)
  5461. +{
  5462. + int i;
  5463. + /* now one more pass checking on the ones that need to be installed */
  5464. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5465. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5466. + if (pkg->dest == NULL)
  5467. + pkg->dest = conf->default_dest;
  5468. +
  5469. + pkg->state_want = SW_INSTALL;
  5470. +
  5471. + /* Abhaya: conflicts check */
  5472. + err = check_conflicts_for(conf, pkg);
  5473. + if (err) { return err; }
  5474. + }
  5475. + return 0;
  5476. +}
  5477. +
  5478. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5479. +{
  5480. + int i;
  5481. + /* now one more pass checking on the ones that need to be installed */
  5482. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5483. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5484. +
  5485. + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
  5486. + pkg_vec_t *replacees = pkg_vec_alloc();
  5487. + pkg_get_installed_replacees(pkg, replacees);
  5488. +
  5489. + /* XXX: BUG: we really should treat replacement more like an upgrade
  5490. + * Instead, we're going to remove the replacees
  5491. + */
  5492. + err = pkg_remove_installed_replacees(conf, replacees);
  5493. + if (err) return err;
  5494. + pkg->state_flag |= SF_REMOVED_REPLACEES;
  5495. + }
  5496. + return 0;
  5497. +}
  5498. +
  5499. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5500. +{
  5501. + int i;
  5502. + /* now one more pass checking on the ones that need to be installed */
  5503. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5504. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5505. + if (pkg->local_filename == NULL) {
  5506. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  5507. + if (err) {
  5508. + ipkg_message(conf, IPKG_ERROR,
  5509. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  5510. + pkg->name);
  5511. + return err;
  5512. + }
  5513. + }
  5514. + if (pkg->tmp_unpack_dir == NULL) {
  5515. + err = unpack_pkg_control_files(conf, pkg);
  5516. + if (err) return err;
  5517. + }
  5518. + }
  5519. + return 0;
  5520. +}
  5521. +
  5522. +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5523. +{
  5524. + int i;
  5525. + /* now one more pass checking on the ones that need to be installed */
  5526. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5527. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5528. + pkg_t *old_pkg = pkg->old_pkg;
  5529. +
  5530. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  5531. + if (err) return err;
  5532. +
  5533. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  5534. + if (err) return err;
  5535. +
  5536. + err = preinst_configure(conf, pkg, old_pkg);
  5537. + if (err) return err;
  5538. +
  5539. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  5540. + if (err) return err;
  5541. +
  5542. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  5543. + if (err) return err;
  5544. + }
  5545. + return 0;
  5546. +}
  5547. +
  5548. +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5549. +{
  5550. + int i;
  5551. + /* now one more pass checking on the ones that need to be installed */
  5552. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5553. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5554. + pkg_t *old_pkg = pkg->old_pkg;
  5555. +
  5556. + if (old_pkg) {
  5557. + old_pkg->state_want = SW_DEINSTALL;
  5558. +
  5559. + if (old_pkg->state_flag & SF_NOPRUNE) {
  5560. + ipkg_message(conf, IPKG_INFO,
  5561. + " not removing obsolesced files because package marked noprune\n");
  5562. + } else {
  5563. + ipkg_message(conf, IPKG_INFO,
  5564. + " removing obsolesced files\n");
  5565. + remove_obsolesced_files(conf, pkg, old_pkg);
  5566. + }
  5567. + }
  5568. +
  5569. + ipkg_message(conf, IPKG_INFO,
  5570. + " installing maintainer scripts\n");
  5571. + install_maintainer_scripts(conf, pkg, old_pkg);
  5572. +
  5573. + /* the following just returns 0 */
  5574. + remove_disappeared(conf, pkg);
  5575. +
  5576. + ipkg_message(conf, IPKG_INFO,
  5577. + " installing data files\n");
  5578. + install_data_files(conf, pkg);
  5579. +
  5580. + ipkg_message(conf, IPKG_INFO,
  5581. + " resolving conf files\n");
  5582. + resolve_conffiles(conf, pkg);
  5583. +
  5584. + pkg->state_status = SS_UNPACKED;
  5585. +
  5586. + if (old_pkg) {
  5587. + old_pkg->state_status = SS_NOT_INSTALLED;
  5588. + }
  5589. +
  5590. + time(&pkg->installed_time);
  5591. +
  5592. + ipkg_message(conf, IPKG_INFO,
  5593. + " cleanup temp files\n");
  5594. + cleanup_temporary_files(conf, pkg);
  5595. +
  5596. + if (pkg->parent)
  5597. + pkg->parent->state_status = pkg->state_status;
  5598. + }
  5599. + return 0;
  5600. +}
  5601. +
  5602. +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5603. +{
  5604. + int i;
  5605. + /* now one more pass checking on the ones that need to be installed */
  5606. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5607. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5608. + pkg_t *old_pkg = pkg->old_pkg;
  5609. +
  5610. + if (old_pkg) {
  5611. + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
  5612. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5613. + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
  5614. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  5615. + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
  5616. + backup_modified_conffiles_unwind(pkg, old_pkg);
  5617. + */
  5618. + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
  5619. + preinst_configure_unwind(conf, pkg, old_pkg);
  5620. + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
  5621. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  5622. + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
  5623. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5624. + */
  5625. +
  5626. + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
  5627. + remove_installed_replacees_unwind(conf, pkg, old_pkg);
  5628. +
  5629. + }
  5630. + }
  5631. + return 0;
  5632. +}
  5633. +
  5634. +/*
  5635. + * Perform all the actions.
  5636. + *
  5637. + * pkgs_to_remove are packages marked for removal.
  5638. + * pkgs_superseded are the old packages being replaced by upgrades.
  5639. + *
  5640. + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
  5641. + */
  5642. +int ipkg_process_actions(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install)
  5643. +{
  5644. + int err;
  5645. + int i;
  5646. +
  5647. + err = ipkg_remove_packages(conf, pkgs_to_remove);
  5648. + if (err) return err;
  5649. +
  5650. + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
  5651. + if (err) return err;
  5652. +
  5653. + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
  5654. + if (err) goto UNWIND;
  5655. +
  5656. + /* @@@@ look at ipkg_install_pkg for handling replacements */
  5657. + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
  5658. + if (err) goto UNWIND;
  5659. +
  5660. + /*
  5661. + * Now that we have the packages unpacked, we can look for data
  5662. + * file clashes. First, we mark the files from the superseded
  5663. + * packages as obsolete. Then we scan the files in
  5664. + * pkgs_to_install, and only complain about clashes with
  5665. + * non-obsolete files.
  5666. + */
  5667. +
  5668. + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
  5669. + if (err) goto UNWIND;
  5670. +
  5671. + /* this was before checking data file clashes */
  5672. + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
  5673. + if (err) goto UNWIND;
  5674. +
  5675. + /* point of no return: no unwinding after this */
  5676. + err = ipkg_process_actions_install(conf, pkgs_to_install);
  5677. + if (err) return err;
  5678. +
  5679. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  5680. + return 0;
  5681. +
  5682. + UNWIND:
  5683. + ipkg_process_actions_unwind(conf, pkgs_to_install);
  5684. +
  5685. + ipkg_message(conf, IPKG_INFO,
  5686. + " cleanup temp files\n");
  5687. + cleanup_temporary_files(conf, pkg);
  5688. +
  5689. + ipkg_message(conf, IPKG_INFO,
  5690. + "Failed.\n");
  5691. + return err;
  5692. +}
  5693. +
  5694. +#endif
  5695. diff -Nur busybox-1.17.1.orig/archival/libipkg/ipkg_install.h busybox-1.17.1/archival/libipkg/ipkg_install.h
  5696. --- busybox-1.17.1.orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
  5697. +++ busybox-1.17.1/archival/libipkg/ipkg_install.h 2010-07-28 13:07:49.511600581 +0200
  5698. @@ -0,0 +1,35 @@
  5699. +/* ipkg_install.h - the itsy package management system
  5700. +
  5701. + Carl D. Worth
  5702. +
  5703. + Copyright (C) 2001 University of Southern California
  5704. +
  5705. + This program is free software; you can redistribute it and/or
  5706. + modify it under the terms of the GNU General Public License as
  5707. + published by the Free Software Foundation; either version 2, or (at
  5708. + your option) any later version.
  5709. +
  5710. + This program is distributed in the hope that it will be useful, but
  5711. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5712. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5713. + General Public License for more details.
  5714. +*/
  5715. +
  5716. +#ifndef IPKG_INSTALL_H
  5717. +#define IPKG_INSTALL_H
  5718. +
  5719. +#include "pkg.h"
  5720. +#include "ipkg_conf.h"
  5721. +
  5722. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5723. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5724. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
  5725. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
  5726. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  5727. +
  5728. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
  5729. +
  5730. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
  5731. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
  5732. +
  5733. +#endif
  5734. diff -Nur busybox-1.17.1.orig/archival/libipkg/ipkg_message.c busybox-1.17.1/archival/libipkg/ipkg_message.c
  5735. --- busybox-1.17.1.orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
  5736. +++ busybox-1.17.1/archival/libipkg/ipkg_message.c 2010-07-28 13:07:49.515599694 +0200
  5737. @@ -0,0 +1,35 @@
  5738. +/* ipkg_message.c - the itsy package management system
  5739. +
  5740. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5741. +
  5742. + This program is free software; you can redistribute it and/or
  5743. + modify it under the terms of the GNU General Public License as
  5744. + published by the Free Software Foundation; either version 2, or (at
  5745. + your option) any later version.
  5746. +
  5747. + This program is distributed in the hope that it will be useful, but
  5748. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5749. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5750. + General Public License for more details.
  5751. +*/
  5752. +
  5753. +
  5754. +#include "ipkg.h"
  5755. +#include "ipkg_conf.h"
  5756. +#include "ipkg_message.h"
  5757. +#include "libipkg.h"
  5758. +
  5759. +void
  5760. +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
  5761. +{
  5762. + va_list ap;
  5763. + char ts[256];
  5764. +
  5765. + if (ipkg_cb_message)
  5766. + {
  5767. + va_start (ap, fmt);
  5768. + vsnprintf (ts,256,fmt, ap);
  5769. + va_end (ap);
  5770. + ipkg_cb_message(conf,level,ts);
  5771. + }
  5772. +}
  5773. diff -Nur busybox-1.17.1.orig/archival/libipkg/ipkg_message.h busybox-1.17.1/archival/libipkg/ipkg_message.h
  5774. --- busybox-1.17.1.orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
  5775. +++ busybox-1.17.1/archival/libipkg/ipkg_message.h 2010-07-28 13:07:49.515599694 +0200
  5776. @@ -0,0 +1,32 @@
  5777. +/* ipkg_message.h - the itsy package management system
  5778. +
  5779. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5780. +
  5781. + This program is free software; you can redistribute it and/or
  5782. + modify it under the terms of the GNU General Public License as
  5783. + published by the Free Software Foundation; either version 2, or (at
  5784. + your option) any later version.
  5785. +
  5786. + This program is distributed in the hope that it will be useful, but
  5787. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5788. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5789. + General Public License for more details.
  5790. +*/
  5791. +
  5792. +#ifndef _IPKG_MESSAGE_H_
  5793. +#define _IPKG_MESSAGE_H_
  5794. +
  5795. +#include "ipkg.h"
  5796. +#include "ipkg_conf.h"
  5797. +
  5798. +typedef enum {
  5799. + IPKG_ERROR, /* error conditions */
  5800. + IPKG_NOTICE, /* normal but significant condition */
  5801. + IPKG_INFO, /* informational message */
  5802. + IPKG_DEBUG, /* debug level message */
  5803. + IPKG_DEBUG2, /* more debug level message */
  5804. +} message_level_t;
  5805. +
  5806. +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
  5807. +
  5808. +#endif /* _IPKG_MESSAGE_H_ */
  5809. diff -Nur busybox-1.17.1.orig/archival/libipkg/ipkg_remove.c busybox-1.17.1/archival/libipkg/ipkg_remove.c
  5810. --- busybox-1.17.1.orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
  5811. +++ busybox-1.17.1/archival/libipkg/ipkg_remove.c 2010-07-28 13:07:49.515599694 +0200
  5812. @@ -0,0 +1,385 @@
  5813. +/* ipkg_remove.c - the itsy package management system
  5814. +
  5815. + Carl D. Worth
  5816. +
  5817. + Copyright (C) 2001 University of Southern California
  5818. +
  5819. + This program is free software; you can redistribute it and/or
  5820. + modify it under the terms of the GNU General Public License as
  5821. + published by the Free Software Foundation; either version 2, or (at
  5822. + your option) any later version.
  5823. +
  5824. + This program is distributed in the hope that it will be useful, but
  5825. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5826. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5827. + General Public License for more details.
  5828. +*/
  5829. +
  5830. +#include "ipkg.h"
  5831. +#include "ipkg_message.h"
  5832. +
  5833. +#include <glob.h>
  5834. +
  5835. +#include "ipkg_remove.h"
  5836. +
  5837. +#include "file_util.h"
  5838. +#include "sprintf_alloc.h"
  5839. +#include "str_util.h"
  5840. +
  5841. +#include "ipkg_cmd.h"
  5842. +
  5843. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents);
  5844. +
  5845. +/*
  5846. + * Returns number of the number of packages depending on the packages provided by this package.
  5847. + * Every package implicitly provides itself.
  5848. + */
  5849. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents)
  5850. +{
  5851. + int nprovides = pkg->provides_count;
  5852. + abstract_pkg_t **provides = pkg->provides;
  5853. + int n_installed_dependents = 0;
  5854. + int i;
  5855. + for (i = 0; i <= nprovides; i++) {
  5856. + abstract_pkg_t *providee = provides[i];
  5857. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5858. + abstract_pkg_t *dep_ab_pkg;
  5859. + if (dependers == NULL)
  5860. + continue;
  5861. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5862. + if (dep_ab_pkg->state_status == SS_INSTALLED){
  5863. + n_installed_dependents++;
  5864. + }
  5865. + }
  5866. +
  5867. + }
  5868. + /* if caller requested the set of installed dependents */
  5869. + if (pdependents) {
  5870. + int p = 0;
  5871. + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
  5872. +
  5873. + if ( dependents == NULL ){
  5874. + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
  5875. + return -1;
  5876. + }
  5877. +
  5878. + *pdependents = dependents;
  5879. + for (i = 0; i <= nprovides; i++) {
  5880. + abstract_pkg_t *providee = provides[i];
  5881. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5882. + abstract_pkg_t *dep_ab_pkg;
  5883. + if (dependers == NULL)
  5884. + continue;
  5885. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5886. + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
  5887. + dependents[p++] = dep_ab_pkg;
  5888. + dep_ab_pkg->state_flag |= SF_MARKED;
  5889. + }
  5890. + }
  5891. + }
  5892. + dependents[p] = NULL;
  5893. + /* now clear the marks */
  5894. + for (i = 0; i < p; i++) {
  5895. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5896. + dep_ab_pkg->state_flag &= ~SF_MARKED;
  5897. + }
  5898. + }
  5899. + return n_installed_dependents;
  5900. +}
  5901. +
  5902. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5903. +{
  5904. + int i;
  5905. + int a;
  5906. + int count;
  5907. + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
  5908. + abstract_pkg_t * ab_pkg;
  5909. +
  5910. + if((ab_pkg = pkg->parent) == NULL){
  5911. + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
  5912. + __FUNCTION__, pkg->name);
  5913. + return 0;
  5914. + }
  5915. +
  5916. + if (dependents == NULL)
  5917. + return 0;
  5918. +
  5919. + // here i am using the dependencies_checked
  5920. + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
  5921. + return 0; // has already been encountered in the process
  5922. + // of marking packages for removal - Karthik
  5923. + ab_pkg->dependencies_checked = 2;
  5924. +
  5925. + i = 0;
  5926. + count = 1;
  5927. + while (dependents [i] != NULL) {
  5928. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5929. +
  5930. + if (dep_ab_pkg->dependencies_checked == 2){
  5931. + i++;
  5932. + continue;
  5933. + }
  5934. + if (dep_ab_pkg->state_status == SS_INSTALLED) {
  5935. + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
  5936. + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
  5937. + if (dep_pkg->state_status == SS_INSTALLED) {
  5938. + pkg_vec_insert(dependent_pkgs, dep_pkg);
  5939. + count++;
  5940. + }
  5941. + }
  5942. + }
  5943. + i++;
  5944. + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
  5945. + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
  5946. + }
  5947. +
  5948. + if (count == 1)
  5949. + return 0;
  5950. +
  5951. +
  5952. + for (i = 0; i < dependent_pkgs->len; i++) {
  5953. + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
  5954. + if (err)
  5955. + return err;
  5956. + }
  5957. + return 0;
  5958. +}
  5959. +
  5960. +static int user_prefers_removing_dependents(ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5961. +{
  5962. + abstract_pkg_t *dep_ab_pkg;
  5963. + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
  5964. + while ((dep_ab_pkg = *dependents++) != NULL) {
  5965. + if (dep_ab_pkg->state_status == SS_INSTALLED)
  5966. + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
  5967. + }
  5968. + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
  5969. + ipkg_message(conf, IPKG_ERROR, "");
  5970. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
  5971. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
  5972. + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
  5973. + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
  5974. + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
  5975. + return 0;
  5976. +}
  5977. +
  5978. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
  5979. +{
  5980. +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
  5981. + thus I wan't check for essential, as I'm upgrading.
  5982. + I hope it won't break anything :)
  5983. +*/
  5984. + int err;
  5985. + abstract_pkg_t *parent_pkg = NULL;
  5986. +
  5987. + if (pkg->essential && !message) {
  5988. + if (conf->force_removal_of_essential_packages) {
  5989. + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
  5990. + "\tIf your system breaks, you get to keep both pieces\n",
  5991. + pkg->name);
  5992. + } else {
  5993. + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
  5994. + "\tRemoving an essential package may lead to an unusable system, but if\n"
  5995. + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
  5996. + "\tits will with the option: -force-removal-of-essential-packages\n",
  5997. + pkg->name);
  5998. + return IPKG_PKG_IS_ESSENTIAL;
  5999. + }
  6000. + }
  6001. +
  6002. + if ((parent_pkg = pkg->parent) == NULL)
  6003. + return 0;
  6004. +
  6005. + /* only attempt to remove dependent installed packages if
  6006. + * force_depends is not specified or the package is being
  6007. + * replaced.
  6008. + */
  6009. + if (!conf->force_depends
  6010. + && !(pkg->state_flag & SF_REPLACE)) {
  6011. + abstract_pkg_t **dependents;
  6012. + int has_installed_dependents =
  6013. + pkg_has_installed_dependents(pkg, &dependents);
  6014. +
  6015. + if (has_installed_dependents) {
  6016. + /*
  6017. + * if this package is depended up by others, then either we should
  6018. + * not remove it or we should remove it and all of its dependents
  6019. + */
  6020. +
  6021. + if (!conf->force_removal_of_dependent_packages
  6022. + && !user_prefers_removing_dependents(conf, pkg, dependents)) {
  6023. + return IPKG_PKG_HAS_DEPENDENTS;
  6024. + }
  6025. +
  6026. + /* remove packages depending on this package - Karthik */
  6027. + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
  6028. + free(dependents);
  6029. + if (err) return err;
  6030. + }
  6031. + }
  6032. +
  6033. + if ( message==0 ){
  6034. + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
  6035. + fflush(stdout);
  6036. + }
  6037. + pkg->state_flag |= SF_FILELIST_CHANGED;
  6038. +
  6039. + pkg->state_want = SW_DEINSTALL;
  6040. + ipkg_state_changed++;
  6041. +
  6042. + pkg_run_script(conf, pkg, "prerm", "remove");
  6043. +
  6044. + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
  6045. + maintains an empty filelist rather than deleting it. That seems
  6046. + like a big pain, and I don't see that that should make a big
  6047. + difference, but for anyone who wants tighter compatibility,
  6048. + feel free to fix this. */
  6049. + remove_data_files_and_list(conf, pkg);
  6050. +
  6051. + pkg_run_script(conf, pkg, "postrm", "remove");
  6052. +
  6053. + remove_maintainer_scripts_except_postrm(conf, pkg);
  6054. +
  6055. + /* Aman Gupta - Since ipkg is made for handheld devices with limited
  6056. + * space, it doesn't make sense to leave extra configurations, files,
  6057. + * and maintainer scripts left around. So, we make remove like purge,
  6058. + * and take out all the crap :) */
  6059. +
  6060. + remove_postrm(conf, pkg);
  6061. + pkg->state_status = SS_NOT_INSTALLED;
  6062. +
  6063. + if (parent_pkg)
  6064. + parent_pkg->state_status = SS_NOT_INSTALLED;
  6065. +
  6066. + return 0;
  6067. +}
  6068. +
  6069. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
  6070. +{
  6071. + ipkg_remove_pkg(conf, pkg,0);
  6072. + return 0;
  6073. +}
  6074. +
  6075. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
  6076. +{
  6077. + str_list_t installed_dirs;
  6078. + str_list_t *installed_files;
  6079. + str_list_elt_t *iter;
  6080. + char *file_name;
  6081. + conffile_t *conffile;
  6082. + int removed_a_dir;
  6083. + pkg_t *owner;
  6084. +
  6085. + str_list_init(&installed_dirs);
  6086. + installed_files = pkg_get_installed_files(pkg);
  6087. +
  6088. + for (iter = installed_files->head; iter; iter = iter->next) {
  6089. + file_name = iter->data;
  6090. +
  6091. + if (file_is_dir(file_name)) {
  6092. + str_list_append(&installed_dirs, strdup(file_name));
  6093. + continue;
  6094. + }
  6095. +
  6096. + conffile = pkg_get_conffile(pkg, file_name);
  6097. + if (conffile) {
  6098. + /* XXX: QUESTION: Is this right? I figure we only need to
  6099. + save the conffile if it has been modified. Is that what
  6100. + dpkg does? Or does dpkg preserve all conffiles? If so,
  6101. + this seems like a better thing to do to conserve
  6102. + space. */
  6103. + if (conffile_has_been_modified(conf, conffile)) {
  6104. + printf(" not deleting modified conffile %s\n", file_name);
  6105. + fflush(stdout);
  6106. + continue;
  6107. + }
  6108. + }
  6109. +
  6110. + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
  6111. + if (!conf->noaction)
  6112. + unlink(file_name);
  6113. + }
  6114. +
  6115. + if (!conf->noaction) {
  6116. + do {
  6117. + removed_a_dir = 0;
  6118. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6119. + file_name = iter->data;
  6120. +
  6121. + if (rmdir(file_name) == 0) {
  6122. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
  6123. + removed_a_dir = 1;
  6124. + str_list_remove(&installed_dirs, &iter);
  6125. + }
  6126. + }
  6127. + } while (removed_a_dir);
  6128. + }
  6129. +
  6130. + pkg_free_installed_files(pkg);
  6131. + /* We have to remove the file list now, so that
  6132. + find_pkg_owning_file does not always just report this package */
  6133. + pkg_remove_installed_files_list(conf, pkg);
  6134. +
  6135. + /* Don't print warning for dirs that are provided by other packages */
  6136. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6137. + file_name = iter->data;
  6138. +
  6139. + owner = file_hash_get_file_owner(conf, file_name);
  6140. + if (owner) {
  6141. + free(iter->data);
  6142. + iter->data = NULL;
  6143. + str_list_remove(&installed_dirs, &iter);
  6144. + }
  6145. + }
  6146. +
  6147. + /* cleanup */
  6148. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6149. + free(iter->data);
  6150. + iter->data = NULL;
  6151. + }
  6152. + str_list_deinit(&installed_dirs);
  6153. +
  6154. + return 0;
  6155. +}
  6156. +
  6157. +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6158. +{
  6159. + int i, err;
  6160. + char *globpattern;
  6161. + glob_t globbuf;
  6162. +
  6163. + if (conf->noaction) return 0;
  6164. +
  6165. + sprintf_alloc(&globpattern, "%s/%s.*",
  6166. + pkg->dest->info_dir, pkg->name);
  6167. + err = glob(globpattern, 0, NULL, &globbuf);
  6168. + free(globpattern);
  6169. + if (err) {
  6170. + return 0;
  6171. + }
  6172. +
  6173. + for (i = 0; i < globbuf.gl_pathc; i++) {
  6174. + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
  6175. + continue;
  6176. + }
  6177. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
  6178. + unlink(globbuf.gl_pathv[i]);
  6179. + }
  6180. + globfree(&globbuf);
  6181. +
  6182. + return 0;
  6183. +}
  6184. +
  6185. +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6186. +{
  6187. + char *postrm_file_name;
  6188. +
  6189. + if (conf->noaction) return 0;
  6190. +
  6191. + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
  6192. + pkg->dest->info_dir, pkg->name);
  6193. + unlink(postrm_file_name);
  6194. + free(postrm_file_name);
  6195. +
  6196. + return 0;
  6197. +}
  6198. diff -Nur busybox-1.17.1.orig/archival/libipkg/ipkg_remove.h busybox-1.17.1/archival/libipkg/ipkg_remove.h
  6199. --- busybox-1.17.1.orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
  6200. +++ busybox-1.17.1/archival/libipkg/ipkg_remove.h 2010-07-28 13:07:49.515599694 +0200
  6201. @@ -0,0 +1,33 @@
  6202. +/* ipkg_remove.h - the itsy package management system
  6203. +
  6204. + Carl D. Worth
  6205. +
  6206. + Copyright (C) 2001 University of Southern California
  6207. +
  6208. + This program is free software; you can redistribute it and/or
  6209. + modify it under the terms of the GNU General Public License as
  6210. + published by the Free Software Foundation; either version 2, or (at
  6211. + your option) any later version.
  6212. +
  6213. + This program is distributed in the hope that it will be useful, but
  6214. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6215. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6216. + General Public License for more details.
  6217. +*/
  6218. +
  6219. +#ifndef IPKG_REMOVE_H
  6220. +#define IPKG_REMOVE_H
  6221. +
  6222. +#include "pkg.h"
  6223. +#include "ipkg_conf.h"
  6224. +
  6225. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
  6226. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
  6227. +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
  6228. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents);
  6229. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
  6230. +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6231. +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6232. +
  6233. +
  6234. +#endif
  6235. diff -Nur busybox-1.17.1.orig/archival/libipkg/ipkg_upgrade.c busybox-1.17.1/archival/libipkg/ipkg_upgrade.c
  6236. --- busybox-1.17.1.orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
  6237. +++ busybox-1.17.1/archival/libipkg/ipkg_upgrade.c 2010-07-28 13:07:49.515599694 +0200
  6238. @@ -0,0 +1,79 @@
  6239. +/* ipkg_upgrade.c - the itsy package management system
  6240. +
  6241. + Carl D. Worth
  6242. + Copyright (C) 2001 University of Southern California
  6243. +
  6244. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6245. +
  6246. + This program is free software; you can redistribute it and/or
  6247. + modify it under the terms of the GNU General Public License as
  6248. + published by the Free Software Foundation; either version 2, or (at
  6249. + your option) any later version.
  6250. +
  6251. + This program is distributed in the hope that it will be useful, but
  6252. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6253. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6254. + General Public License for more details.
  6255. +*/
  6256. +
  6257. +#include "ipkg.h"
  6258. +#include "ipkg_install.h"
  6259. +#include "ipkg_message.h"
  6260. +
  6261. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6262. +
  6263. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
  6264. +{
  6265. + pkg_t *new;
  6266. + int cmp;
  6267. + char *old_version, *new_version;
  6268. +
  6269. + if (old->state_flag & SF_HOLD) {
  6270. + ipkg_message(conf, IPKG_NOTICE,
  6271. + "Not upgrading package %s which is marked "
  6272. + "hold (flags=%#x)\n", old->name, old->state_flag);
  6273. + return 0;
  6274. + }
  6275. +
  6276. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
  6277. + if (new == NULL) {
  6278. + old_version = pkg_version_str_alloc(old);
  6279. + ipkg_message(conf, IPKG_NOTICE,
  6280. + "Assuming locally installed package %s (%s) "
  6281. + "is up to date.\n", old->name, old_version);
  6282. + free(old_version);
  6283. + return 0;
  6284. + }
  6285. +
  6286. + old_version = pkg_version_str_alloc(old);
  6287. + new_version = pkg_version_str_alloc(new);
  6288. +
  6289. + cmp = pkg_compare_versions(old, new);
  6290. + ipkg_message(conf, IPKG_DEBUG,
  6291. + "comparing visible versions of pkg %s:"
  6292. + "\n\t%s is installed "
  6293. + "\n\t%s is available "
  6294. + "\n\t%d was comparison result\n",
  6295. + old->name, old_version, new_version, cmp);
  6296. + if (cmp == 0) {
  6297. + ipkg_message(conf, IPKG_INFO,
  6298. + "Package %s (%s) installed in %s is up to date.\n",
  6299. + old->name, old_version, old->dest->name);
  6300. + free(old_version);
  6301. + free(new_version);
  6302. + return 0;
  6303. + } else if (cmp > 0) {
  6304. + ipkg_message(conf, IPKG_NOTICE,
  6305. + "Not downgrading package %s on %s from %s to %s.\n",
  6306. + old->name, old->dest->name, old_version, new_version);
  6307. + free(old_version);
  6308. + free(new_version);
  6309. + return 0;
  6310. + } else if (cmp < 0) {
  6311. + new->dest = old->dest;
  6312. + old->state_want = SW_DEINSTALL;
  6313. + }
  6314. +
  6315. + new->state_flag |= SF_USER;
  6316. + return ipkg_install_pkg(conf, new,1);
  6317. +}
  6318. diff -Nur busybox-1.17.1.orig/archival/libipkg/ipkg_upgrade.h busybox-1.17.1/archival/libipkg/ipkg_upgrade.h
  6319. --- busybox-1.17.1.orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
  6320. +++ busybox-1.17.1/archival/libipkg/ipkg_upgrade.h 2010-07-28 13:07:49.519597690 +0200
  6321. @@ -0,0 +1,18 @@
  6322. +/* ipkg_upgrade.c - the itsy package management system
  6323. +
  6324. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6325. +
  6326. + This program is free software; you can redistribute it and/or
  6327. + modify it under the terms of the GNU General Public License as
  6328. + published by the Free Software Foundation; either version 2, or (at
  6329. + your option) any later version.
  6330. +
  6331. + This program is distributed in the hope that it will be useful, but
  6332. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6333. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6334. + General Public License for more details.
  6335. +*/
  6336. +
  6337. +#include "ipkg.h"
  6338. +
  6339. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6340. diff -Nur busybox-1.17.1.orig/archival/libipkg/ipkg_utils.c busybox-1.17.1/archival/libipkg/ipkg_utils.c
  6341. --- busybox-1.17.1.orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
  6342. +++ busybox-1.17.1/archival/libipkg/ipkg_utils.c 2010-07-28 13:07:49.519597690 +0200
  6343. @@ -0,0 +1,185 @@
  6344. +/* ipkg_utils.c - the itsy package management system
  6345. +
  6346. + Steven M. Ayer
  6347. +
  6348. + Copyright (C) 2002 Compaq Computer Corporation
  6349. +
  6350. + This program is free software; you can redistribute it and/or
  6351. + modify it under the terms of the GNU General Public License as
  6352. + published by the Free Software Foundation; either version 2, or (at
  6353. + your option) any later version.
  6354. +
  6355. + This program is distributed in the hope that it will be useful, but
  6356. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6357. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6358. + General Public License for more details.
  6359. +*/
  6360. +
  6361. +#include "ipkg.h"
  6362. +#include <errno.h>
  6363. +#include <ctype.h>
  6364. +#include <sys/vfs.h>
  6365. +
  6366. +#include "ipkg_utils.h"
  6367. +#include "pkg.h"
  6368. +#include "pkg_hash.h"
  6369. +
  6370. +void push_error_list(struct errlist ** errors, char * msg);
  6371. +void reverse_error_list(struct errlist **errors);
  6372. +void free_error_list(struct errlist **errors);
  6373. +
  6374. +struct errlist* error_list;
  6375. +
  6376. +int get_available_blocks(char * filesystem)
  6377. +{
  6378. + struct statfs sfs;
  6379. +
  6380. + if(statfs(filesystem, &sfs)){
  6381. + fprintf(stderr, "bad statfs\n");
  6382. + return 0;
  6383. + }
  6384. + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
  6385. + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
  6386. +}
  6387. +
  6388. +char **read_raw_pkgs_from_file(const char *file_name)
  6389. +{
  6390. + FILE *fp;
  6391. + char **ret;
  6392. +
  6393. + if(!(fp = fopen(file_name, "r"))){
  6394. + fprintf(stderr, "can't get %s open for read\n", file_name);
  6395. + return NULL;
  6396. + }
  6397. +
  6398. + ret = read_raw_pkgs_from_stream(fp);
  6399. +
  6400. + fclose(fp);
  6401. +
  6402. + return ret;
  6403. +}
  6404. +
  6405. +char **read_raw_pkgs_from_stream(FILE *fp)
  6406. +{
  6407. + char **raw = NULL, *buf, *scout;
  6408. + int count = 0;
  6409. + size_t size = 512;
  6410. +
  6411. + buf = malloc (size);
  6412. +
  6413. + while (fgets(buf, size, fp)) {
  6414. + while (strlen (buf) == (size - 1)
  6415. + && buf[size-2] != '\n') {
  6416. + size_t o = size - 1;
  6417. + size *= 2;
  6418. + buf = realloc (buf, size);
  6419. + if (fgets (buf + o, size - o, fp) == NULL)
  6420. + break;
  6421. + }
  6422. +
  6423. + if(!(count % 50))
  6424. + raw = realloc(raw, (count + 50) * sizeof(char *));
  6425. +
  6426. + if((scout = strchr(buf, '\n')))
  6427. + *scout = '\0';
  6428. +
  6429. + raw[count++] = strdup(buf);
  6430. + }
  6431. +
  6432. + raw = realloc(raw, (count + 1) * sizeof(char *));
  6433. + raw[count] = NULL;
  6434. +
  6435. + free (buf);
  6436. +
  6437. + return raw;
  6438. +}
  6439. +
  6440. +/* something to remove whitespace, a hash pooper */
  6441. +char *trim_alloc(char *line)
  6442. +{
  6443. + char *new;
  6444. + char *dest, *src, *end;
  6445. +
  6446. + new = malloc(strlen(line) + 1);
  6447. + if ( new == NULL ){
  6448. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  6449. + return NULL;
  6450. + }
  6451. + dest = new, src = line, end = line + (strlen(line) - 1);
  6452. +
  6453. + /* remove it from the front */
  6454. + while(src &&
  6455. + isspace(*src) &&
  6456. + *src)
  6457. + src++;
  6458. + /* and now from the back */
  6459. + while((end > src) &&
  6460. + isspace(*end))
  6461. + end--;
  6462. + end++;
  6463. + *end = '\0';
  6464. + strcpy(new, src);
  6465. + /* this does from the first space
  6466. + * blasting away any versions stuff in depends
  6467. + while(src &&
  6468. + !isspace(*src) &&
  6469. + *src)
  6470. + *dest++ = *src++;
  6471. + *dest = '\0';
  6472. + */
  6473. +
  6474. + return new;
  6475. +}
  6476. +
  6477. +int line_is_blank(const char *line)
  6478. +{
  6479. + const char *s;
  6480. +
  6481. + for (s = line; *s; s++) {
  6482. + if (!isspace(*s))
  6483. + return 0;
  6484. + }
  6485. + return 1;
  6486. +}
  6487. +
  6488. +void push_error_list(struct errlist ** errors, char * msg){
  6489. + struct errlist *err_lst_tmp;
  6490. +
  6491. +
  6492. + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
  6493. + err_lst_tmp->errmsg=strdup(msg) ;
  6494. + err_lst_tmp->next = *errors;
  6495. + *errors = err_lst_tmp;
  6496. +}
  6497. +
  6498. +
  6499. +void reverse_error_list(struct errlist **errors){
  6500. + struct errlist *result=NULL;
  6501. + struct errlist *current= *errors;
  6502. + struct errlist *next;
  6503. +
  6504. + while ( current != NULL ) {
  6505. + next = current->next;
  6506. + current->next=result;
  6507. + result=current;
  6508. + current=next;
  6509. + }
  6510. + *errors=result;
  6511. +
  6512. +}
  6513. +
  6514. +
  6515. +void free_error_list(struct errlist **errors){
  6516. + struct errlist *current = *errors;
  6517. +
  6518. + while (current != NULL) {
  6519. + free(current->errmsg);
  6520. + current = (*errors)->next;
  6521. + free(*errors);
  6522. + *errors = current;
  6523. + }
  6524. +
  6525. +
  6526. +}
  6527. +
  6528. +
  6529. diff -Nur busybox-1.17.1.orig/archival/libipkg/ipkg_utils.h busybox-1.17.1/archival/libipkg/ipkg_utils.h
  6530. --- busybox-1.17.1.orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
  6531. +++ busybox-1.17.1/archival/libipkg/ipkg_utils.h 2010-07-28 13:07:49.519597690 +0200
  6532. @@ -0,0 +1,29 @@
  6533. +/* ipkg_utils.h - the itsy package management system
  6534. +
  6535. + Steven M. Ayer
  6536. +
  6537. + Copyright (C) 2002 Compaq Computer Corporation
  6538. +
  6539. + This program is free software; you can redistribute it and/or
  6540. + modify it under the terms of the GNU General Public License as
  6541. + published by the Free Software Foundation; either version 2, or (at
  6542. + your option) any later version.
  6543. +
  6544. + This program is distributed in the hope that it will be useful, but
  6545. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6546. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6547. + General Public License for more details.
  6548. +*/
  6549. +
  6550. +#ifndef IPKG_UTILS_H
  6551. +#define IPKG_UTILS_H
  6552. +
  6553. +#include "pkg.h"
  6554. +
  6555. +int get_available_blocks(char * filesystem);
  6556. +char **read_raw_pkgs_from_file(const char *file_name);
  6557. +char **read_raw_pkgs_from_stream(FILE *fp);
  6558. +char *trim_alloc(char * line);
  6559. +int line_is_blank(const char *line);
  6560. +
  6561. +#endif
  6562. diff -Nur busybox-1.17.1.orig/archival/libipkg/Kbuild busybox-1.17.1/archival/libipkg/Kbuild
  6563. --- busybox-1.17.1.orig/archival/libipkg/Kbuild 1970-01-01 01:00:00.000000000 +0100
  6564. +++ busybox-1.17.1/archival/libipkg/Kbuild 2010-07-28 13:07:49.519597690 +0200
  6565. @@ -0,0 +1,60 @@
  6566. +# Makefile for busybox
  6567. +#
  6568. +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  6569. +# Copyright (C) 2006 OpenWrt.org
  6570. +#
  6571. +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  6572. +
  6573. +LIBIPKG_CORE_OBJS:= \
  6574. + args.o \
  6575. + libipkg.o \
  6576. + user.o \
  6577. +
  6578. +LIBIPKG_CMD_OBJS:= \
  6579. + ipkg_cmd.o \
  6580. + ipkg_configure.o \
  6581. + ipkg_download.o \
  6582. + ipkg_install.o \
  6583. + ipkg_remove.o \
  6584. + ipkg_upgrade.o \
  6585. +
  6586. +LIBIPKG_DB_OBJS:= \
  6587. + hash_table.o \
  6588. + ipkg_conf.o \
  6589. + ipkg_utils.o \
  6590. + pkg.o \
  6591. + pkg_depends.o \
  6592. + pkg_extract.o \
  6593. + pkg_hash.o \
  6594. + pkg_parse.o \
  6595. + pkg_vec.o \
  6596. +
  6597. +LIBIPKG_LIST_OBJS:= \
  6598. + conffile.o \
  6599. + conffile_list.o \
  6600. + nv_pair.o \
  6601. + nv_pair_list.o \
  6602. + pkg_dest.o \
  6603. + pkg_dest_list.o \
  6604. + pkg_src.o \
  6605. + pkg_src_list.o \
  6606. + str_list.o \
  6607. + void_list.o \
  6608. +
  6609. +LIBIPKG_UTIL_OBJS:= \
  6610. + file_util.o \
  6611. + ipkg_message.o \
  6612. + str_util.o \
  6613. + xsystem.o \
  6614. +
  6615. +lib-y :=
  6616. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
  6617. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
  6618. +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
  6619. +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
  6620. +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
  6621. +
  6622. +ifeq ($(strip $(IPKG_ARCH)),)
  6623. +IPKG_ARCH:=$(TARGET_ARCH)
  6624. +endif
  6625. +CFLAGS += -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
  6626. diff -Nur busybox-1.17.1.orig/archival/libipkg/libipkg.c busybox-1.17.1/archival/libipkg/libipkg.c
  6627. --- busybox-1.17.1.orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
  6628. +++ busybox-1.17.1/archival/libipkg/libipkg.c 2010-07-28 18:54:37.592513964 +0200
  6629. @@ -0,0 +1,583 @@
  6630. +/* ipkglib.c - the itsy package management system
  6631. +
  6632. + Florina Boor
  6633. +
  6634. + Copyright (C) 2003 kernel concepts
  6635. +
  6636. + This program is free software; you can redistribute it and/or
  6637. + modify it under the terms of the GNU General Public License as
  6638. + published by the Free Software Foundation; either version 2, or (at
  6639. + your option) any later version.
  6640. +
  6641. + This program is distributed in the hope that it will be useful, but
  6642. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6643. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6644. + General Public License for more details.
  6645. +*/
  6646. +
  6647. +#include "ipkg.h"
  6648. +#include "ipkg_includes.h"
  6649. +#include "libipkg.h"
  6650. +
  6651. +#include "args.h"
  6652. +#include "ipkg_conf.h"
  6653. +#include "ipkg_cmd.h"
  6654. +#include "file_util.h"
  6655. +
  6656. +int ipkg_file_what(args_t *args, const char *file, const char* command);
  6657. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  6658. + char *msg);
  6659. +int default_ipkg_list_callback(char *name, char *desc, char *version);
  6660. +int default_ipkg_files_callback(char *desc);
  6661. +int default_ipkg_status_callback(char *desc);
  6662. +char* default_ipkg_response_callback(char *question);
  6663. +
  6664. +
  6665. +ipkg_message_callback ipkg_cb_message = NULL;
  6666. +ipkg_response_callback ipkg_cb_response = NULL;
  6667. +ipkg_status_callback ipkg_cb_status = NULL;
  6668. +ipkg_list_callback ipkg_cb_list = NULL;
  6669. +
  6670. +
  6671. +int
  6672. +ipkg_init (ipkg_message_callback mcall,
  6673. + ipkg_response_callback rcall,
  6674. + args_t * args)
  6675. +{
  6676. + ipkg_cb_message = mcall;
  6677. + ipkg_cb_response = rcall;
  6678. +
  6679. + args_init (args);
  6680. +
  6681. + return 0;
  6682. +}
  6683. +
  6684. +
  6685. +int
  6686. +ipkg_deinit (args_t * args)
  6687. +{
  6688. + args_deinit (args);
  6689. + ipkg_cb_message = NULL;
  6690. + ipkg_cb_response = NULL;
  6691. +
  6692. + /* place other cleanup stuff here */
  6693. +
  6694. + return 0;
  6695. +}
  6696. +
  6697. +
  6698. +int
  6699. +ipkg_packages_list(args_t *args,
  6700. + const char *packages,
  6701. + ipkg_list_callback cblist,
  6702. + void *userdata)
  6703. +{
  6704. + ipkg_cmd_t *cmd;
  6705. + ipkg_conf_t ipkg_conf;
  6706. + int err;
  6707. +
  6708. + err = ipkg_conf_init (&ipkg_conf, args);
  6709. + if (err)
  6710. + {
  6711. + return err;
  6712. + }
  6713. +
  6714. + ipkg_cb_list = cblist;
  6715. + /* we need to do this because of static declarations,
  6716. + * maybe a good idea to change */
  6717. + cmd = ipkg_cmd_find ("list");
  6718. + if (packages)
  6719. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6720. + else
  6721. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6722. + ipkg_cb_list = NULL;
  6723. + ipkg_conf_deinit (&ipkg_conf);
  6724. + return (err);
  6725. +}
  6726. +
  6727. +
  6728. +int
  6729. +ipkg_packages_status(args_t *args,
  6730. + const char *packages,
  6731. + ipkg_status_callback cbstatus,
  6732. + void *userdata)
  6733. +{
  6734. + ipkg_cmd_t *cmd;
  6735. + ipkg_conf_t ipkg_conf;
  6736. + int err;
  6737. +
  6738. + err = ipkg_conf_init (&ipkg_conf, args);
  6739. + if (err)
  6740. + {
  6741. + return err;
  6742. + }
  6743. +
  6744. + ipkg_cb_status = cbstatus;
  6745. +
  6746. + /* we need to do this because of static declarations,
  6747. + * maybe a good idea to change */
  6748. + cmd = ipkg_cmd_find ("status");
  6749. + if (packages)
  6750. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6751. + else
  6752. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6753. +
  6754. + ipkg_cb_status = NULL;
  6755. + ipkg_conf_deinit (&ipkg_conf);
  6756. + return (err);
  6757. +}
  6758. +
  6759. +
  6760. +int
  6761. +ipkg_packages_info(args_t *args,
  6762. + const char *packages,
  6763. + ipkg_status_callback cbstatus,
  6764. + void *userdata)
  6765. +{
  6766. + ipkg_cmd_t *cmd;
  6767. + ipkg_conf_t ipkg_conf;
  6768. + int err;
  6769. +
  6770. + err = ipkg_conf_init (&ipkg_conf, args);
  6771. + if (err)
  6772. + {
  6773. + return err;
  6774. + }
  6775. +
  6776. + ipkg_cb_status = cbstatus;
  6777. +
  6778. + /* we need to do this because of static declarations,
  6779. + * maybe a good idea to change */
  6780. + cmd = ipkg_cmd_find ("info");
  6781. + if (packages)
  6782. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6783. + else
  6784. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6785. +
  6786. + ipkg_cb_status = NULL;
  6787. + ipkg_conf_deinit (&ipkg_conf);
  6788. + return (err);
  6789. +}
  6790. +
  6791. +
  6792. +int
  6793. +ipkg_packages_install (args_t * args, const char *name)
  6794. +{
  6795. + ipkg_cmd_t *cmd;
  6796. + ipkg_conf_t ipkg_conf;
  6797. + int err;
  6798. +
  6799. + /* this error should be handled in application */
  6800. + if (!name || !strlen (name))
  6801. + return (-1);
  6802. +
  6803. + err = ipkg_conf_init (&ipkg_conf, args);
  6804. + if (err)
  6805. + {
  6806. + return err;
  6807. + }
  6808. +
  6809. + /* we need to do this because of static declarations,
  6810. + * maybe a good idea to change */
  6811. + cmd = ipkg_cmd_find ("install");
  6812. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6813. +
  6814. + ipkg_conf_deinit(&ipkg_conf);
  6815. + return (err);
  6816. +}
  6817. +
  6818. +
  6819. +int
  6820. +ipkg_packages_remove(args_t *args, const char *name, int purge)
  6821. +{
  6822. + ipkg_cmd_t *cmd;
  6823. + ipkg_conf_t ipkg_conf;
  6824. + int err;
  6825. +
  6826. + /* this error should be handled in application */
  6827. + if (!name || !strlen (name))
  6828. + return (-1);
  6829. +
  6830. + err = ipkg_conf_init (&ipkg_conf, args);
  6831. + if (err)
  6832. + {
  6833. + return err;
  6834. + }
  6835. +
  6836. + /* we need to do this because of static declarations,
  6837. + * maybe a good idea to change */
  6838. + if (purge)
  6839. + cmd = ipkg_cmd_find ("purge");
  6840. + else
  6841. + cmd = ipkg_cmd_find ("remove");
  6842. +
  6843. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6844. +
  6845. + ipkg_conf_deinit(&ipkg_conf);
  6846. + return (err);
  6847. +}
  6848. +
  6849. +
  6850. +int
  6851. +ipkg_lists_update(args_t *args)
  6852. +{
  6853. + ipkg_cmd_t *cmd;
  6854. + ipkg_conf_t ipkg_conf;
  6855. + int err;
  6856. +
  6857. + err = ipkg_conf_init (&ipkg_conf, args);
  6858. + if (err)
  6859. + {
  6860. + return err;
  6861. + }
  6862. +
  6863. + /* we need to do this because of static declarations,
  6864. + * maybe a good idea to change */
  6865. + cmd = ipkg_cmd_find ("update");
  6866. +
  6867. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6868. +
  6869. + ipkg_conf_deinit(&ipkg_conf);
  6870. + return (err);
  6871. +}
  6872. +
  6873. +
  6874. +int
  6875. +ipkg_packages_upgrade(args_t *args)
  6876. +{
  6877. + ipkg_cmd_t *cmd;
  6878. + ipkg_conf_t ipkg_conf;
  6879. + int err;
  6880. +
  6881. + err = ipkg_conf_init (&ipkg_conf, args);
  6882. + if (err)
  6883. + {
  6884. + return err;
  6885. + }
  6886. +
  6887. + /* we need to do this because of static declarations,
  6888. + * maybe a good idea to change */
  6889. + cmd = ipkg_cmd_find ("upgrade");
  6890. +
  6891. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6892. +
  6893. + ipkg_conf_deinit(&ipkg_conf);
  6894. + return (err);
  6895. +}
  6896. +
  6897. +
  6898. +int
  6899. +ipkg_packages_download (args_t * args, const char *name)
  6900. +{
  6901. + ipkg_cmd_t *cmd;
  6902. + ipkg_conf_t ipkg_conf;
  6903. + int err;
  6904. +
  6905. + /* this error should be handled in application */
  6906. + if (!name || !strlen (name))
  6907. + return (-1);
  6908. +
  6909. + err = ipkg_conf_init (&ipkg_conf, args);
  6910. + if (err)
  6911. + {
  6912. + return err;
  6913. + }
  6914. +
  6915. + /* we need to do this because of static declarations,
  6916. + * maybe a good idea to change */
  6917. + cmd = ipkg_cmd_find ("download");
  6918. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6919. +
  6920. + ipkg_conf_deinit(&ipkg_conf);
  6921. + return (err);
  6922. +}
  6923. +
  6924. +
  6925. +int
  6926. +ipkg_package_files(args_t *args,
  6927. + const char *name,
  6928. + ipkg_list_callback cblist,
  6929. + void *userdata)
  6930. +{
  6931. + ipkg_cmd_t *cmd;
  6932. + ipkg_conf_t ipkg_conf;
  6933. + int err;
  6934. +
  6935. + /* this error should be handled in application */
  6936. + if (!name || !strlen (name))
  6937. + return (-1);
  6938. +
  6939. + err = ipkg_conf_init (&ipkg_conf, args);
  6940. + if (err)
  6941. + {
  6942. + return err;
  6943. + }
  6944. +
  6945. + ipkg_cb_list = cblist;
  6946. +
  6947. + /* we need to do this because of static declarations,
  6948. + * maybe a good idea to change */
  6949. + cmd = ipkg_cmd_find ("files");
  6950. +
  6951. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
  6952. +
  6953. + ipkg_cb_list = NULL;
  6954. + ipkg_conf_deinit(&ipkg_conf);
  6955. + return (err);
  6956. +}
  6957. +
  6958. +
  6959. +int
  6960. +ipkg_file_search(args_t *args,
  6961. + const char *file,
  6962. + ipkg_list_callback cblist,
  6963. + void *userdata)
  6964. +{
  6965. + ipkg_cmd_t *cmd;
  6966. + ipkg_conf_t ipkg_conf;
  6967. + int err;
  6968. +
  6969. + /* this error should be handled in application */
  6970. + if (!file || !strlen (file))
  6971. + return (-1);
  6972. +
  6973. + err = ipkg_conf_init (&ipkg_conf, args);
  6974. + if (err)
  6975. + {
  6976. + return err;
  6977. + }
  6978. +
  6979. + ipkg_cb_list = cblist;
  6980. +
  6981. + /* we need to do this because of static declarations,
  6982. + * maybe a good idea to change */
  6983. + cmd = ipkg_cmd_find ("search");
  6984. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
  6985. +
  6986. + ipkg_cb_list = NULL;
  6987. + ipkg_conf_deinit(&ipkg_conf);
  6988. + return(err);
  6989. +}
  6990. +
  6991. +
  6992. +int
  6993. +ipkg_file_what(args_t *args, const char *file, const char* command)
  6994. +{
  6995. + ipkg_cmd_t *cmd;
  6996. + ipkg_conf_t ipkg_conf;
  6997. + int err;
  6998. +
  6999. + /* this error should be handled in application */
  7000. + if (!file || !strlen (file))
  7001. + return (-1);
  7002. +
  7003. + err = ipkg_conf_init (&ipkg_conf, args);
  7004. + if (err)
  7005. + {
  7006. + return err;
  7007. + }
  7008. +
  7009. + /* we need to do this because of static declarations,
  7010. + * maybe a good idea to change */
  7011. + cmd = ipkg_cmd_find (command);
  7012. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
  7013. +
  7014. + ipkg_conf_deinit(&ipkg_conf);
  7015. + return(err);
  7016. +}
  7017. +
  7018. +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
  7019. +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
  7020. +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
  7021. +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
  7022. +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
  7023. +
  7024. +
  7025. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  7026. + char *msg)
  7027. +{
  7028. + if (conf && (conf->verbosity < level)) {
  7029. + return 0;
  7030. + } else {
  7031. + if ( level == IPKG_ERROR )
  7032. + push_error_list(&error_list, msg);
  7033. + else
  7034. + printf(msg);
  7035. + }
  7036. + return 0;
  7037. +}
  7038. +
  7039. +int default_ipkg_list_callback(char *name, char *desc, char *version)
  7040. +{
  7041. + if (desc)
  7042. + printf("%s - %s - %s\n", name, version, desc);
  7043. + else
  7044. + printf("%s - %s\n", name, version);
  7045. + return 0;
  7046. +}
  7047. +
  7048. +int default_ipkg_files_callback(char *desc)
  7049. +{
  7050. + if (desc)
  7051. + printf("%s\n", desc);
  7052. + return 0;
  7053. +}
  7054. +
  7055. +int default_ipkg_status_callback(char *desc)
  7056. +{
  7057. + printf("%s\n", desc);
  7058. + return 0;
  7059. +}
  7060. +
  7061. +char* default_ipkg_response_callback(char *question)
  7062. +{
  7063. + char *response = NULL;
  7064. + printf(question);
  7065. + fflush(stdout);
  7066. + do {
  7067. + response = (char *)file_read_line_alloc(stdin);
  7068. + } while (response == NULL);
  7069. + return response;
  7070. +}
  7071. +
  7072. +/* This is used for backward compatibility */
  7073. +int
  7074. +ipkg_op (int argc, char *argv[])
  7075. +{
  7076. + int err, optind_;
  7077. + args_t args;
  7078. + char *cmd_name;
  7079. + ipkg_cmd_t *cmd;
  7080. + ipkg_conf_t ipkg_conf;
  7081. + const char *message = "ipkg must have one sub-command argument";
  7082. + FILE *f;
  7083. + struct mntent *mnt;
  7084. + int remountroot;
  7085. +
  7086. + args_init (&args);
  7087. +
  7088. + optind_ = args_parse (&args, argc, argv);
  7089. + if (optind_ == argc || optind_ < 0)
  7090. + {
  7091. + args_usage(message);
  7092. + }
  7093. +
  7094. + cmd_name = argv[optind_++];
  7095. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  7096. + read anything from there.
  7097. +*/
  7098. + if ( !strcmp(cmd_name,"print-architecture") ||
  7099. + !strcmp(cmd_name,"print_architecture") ||
  7100. + !strcmp(cmd_name,"print-installation-architecture") ||
  7101. + !strcmp(cmd_name,"print_installation_architecture") )
  7102. + args.nocheckfordirorfile = 1;
  7103. +
  7104. +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
  7105. + read anything from there.
  7106. +*/
  7107. + if ( !strcmp(cmd_name,"flag") ||
  7108. + !strcmp(cmd_name,"configure") ||
  7109. + !strcmp(cmd_name,"remove") ||
  7110. + !strcmp(cmd_name,"files") ||
  7111. + !strcmp(cmd_name,"search") ||
  7112. + !strcmp(cmd_name,"compare_versions") ||
  7113. + !strcmp(cmd_name,"compare-versions") ||
  7114. + !strcmp(cmd_name,"list_installed") ||
  7115. + !strcmp(cmd_name,"list-installed") ||
  7116. + !strcmp(cmd_name,"status") )
  7117. + args.noreadfeedsfile = 1;
  7118. +
  7119. +
  7120. +
  7121. +
  7122. + err = ipkg_conf_init (&ipkg_conf, &args);
  7123. + if (err)
  7124. + {
  7125. + return err;
  7126. + }
  7127. +
  7128. + args_deinit (&args);
  7129. +
  7130. + ipkg_cb_message = default_ipkg_message_callback;
  7131. + ipkg_cb_response = default_ipkg_response_callback;
  7132. + ipkg_cb_status = (ipkg_status_callback)default_ipkg_status_callback;
  7133. + if ( strcmp(cmd_name, "files")==0)
  7134. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_files_callback;
  7135. + else
  7136. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_list_callback;
  7137. +
  7138. + cmd = ipkg_cmd_find (cmd_name);
  7139. + if (cmd == NULL)
  7140. + {
  7141. + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
  7142. + cmd_name);
  7143. + args_usage (NULL);
  7144. + }
  7145. +
  7146. + if (cmd->requires_args && optind_ == argc)
  7147. + {
  7148. + fprintf (stderr,
  7149. + "%s: the ``%s'' command requires at least one argument\n",
  7150. + __FUNCTION__, cmd_name);
  7151. + args_usage (NULL);
  7152. + }
  7153. +
  7154. + remountroot = 0;
  7155. + /* check if /dev/root is mounted read-only */
  7156. + if ((f = setmntent("/proc/mounts", "r")) == NULL)
  7157. + fprintf (stderr, "Checking /proc/mounts failed\n");
  7158. +
  7159. + while ((mnt = getmntent(f)) != NULL) {
  7160. + if (strcmp(mnt->mnt_fsname, "/dev/root") == 0 &&
  7161. + hasmntopt(mnt, MNTOPT_RO) != NULL) {
  7162. + remountroot = 1;
  7163. + }
  7164. + }
  7165. +
  7166. + endmntent(f);
  7167. +
  7168. + if (remountroot) {
  7169. + if ( !strcmp(cmd_name,"install") ||
  7170. + !strcmp(cmd_name,"update") ||
  7171. + !strcmp(cmd_name,"upgrade") ||
  7172. + !strcmp(cmd_name,"flag") ||
  7173. + !strcmp(cmd_name,"configure") ||
  7174. + !strcmp(cmd_name,"remove") ) {
  7175. + /* mount rootfs read-write */
  7176. + if (mount("","/",0,MS_REMOUNT,0)<0)
  7177. + fprintf (stderr, "Mounting rootfs read-write failed\n");
  7178. + }
  7179. + }
  7180. +
  7181. + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind_, (const char **) (argv + optind_), NULL);
  7182. +
  7183. + ipkg_conf_deinit (&ipkg_conf);
  7184. +
  7185. + if (remountroot) {
  7186. + if ( !strcmp(cmd_name,"install") ||
  7187. + !strcmp(cmd_name,"update") ||
  7188. + !strcmp(cmd_name,"upgrade") ||
  7189. + !strcmp(cmd_name,"flag") ||
  7190. + !strcmp(cmd_name,"configure") ||
  7191. + !strcmp(cmd_name,"remove") ) {
  7192. + sync();
  7193. + /* mount rootfs read-only */
  7194. + if (mount("","/",0,MS_REMOUNT|MS_RDONLY,0)<0)
  7195. + fprintf (stderr, "Mounting rootfs read-only failed\n");
  7196. + }
  7197. + }
  7198. +
  7199. + /* check if cfgfs exists */
  7200. + if (access("/sbin/cfgfs", X_OK) == 0) {
  7201. + if ( !strcmp(cmd_name,"install") ||
  7202. + !strcmp(cmd_name,"update") ||
  7203. + !strcmp(cmd_name,"upgrade")) {
  7204. + if (system("cfgfs status -q") != 0) {
  7205. + fprintf (stdout, "Updates in /etc, please review changes\n");
  7206. + fprintf (stdout, "You can check via cfgfs status\n");
  7207. + }
  7208. + }
  7209. + }
  7210. +
  7211. + return err;
  7212. +}
  7213. diff -Nur busybox-1.17.1.orig/archival/libipkg/libipkg.h busybox-1.17.1/archival/libipkg/libipkg.h
  7214. --- busybox-1.17.1.orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
  7215. +++ busybox-1.17.1/archival/libipkg/libipkg.h 2010-07-28 13:07:49.523597362 +0200
  7216. @@ -0,0 +1,78 @@
  7217. +/* ipkglib.h - the itsy package management system
  7218. +
  7219. + Florian Boor <florian.boor@kernelconcepts.de>
  7220. +
  7221. + This program is free software; you can redistribute it and/or
  7222. + modify it under the terms of the GNU General Public License as
  7223. + published by the Free Software Foundation; either version 2, or (at
  7224. + your option) any later version.
  7225. +
  7226. + This program is distributed in the hope that it will be useful, but
  7227. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7228. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7229. + General Public License for more details.
  7230. +*/
  7231. +
  7232. +#ifndef IPKGLIB_H
  7233. +#define IPKGLIB_H
  7234. +
  7235. +#include "ipkg_conf.h"
  7236. +#include "ipkg_message.h"
  7237. +
  7238. +#include "args.h"
  7239. +#include "pkg.h"
  7240. +
  7241. +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
  7242. + char *msg);
  7243. +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
  7244. + pkg_state_status_t status, void *userdata);
  7245. +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
  7246. + void *userdata);
  7247. +typedef char* (*ipkg_response_callback)(char *question);
  7248. +
  7249. +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
  7250. +extern int ipkg_init (ipkg_message_callback mcall,
  7251. + ipkg_response_callback rcall,
  7252. + args_t * args);
  7253. +
  7254. +extern int ipkg_deinit (args_t *args);
  7255. +extern int ipkg_packages_list(args_t *args,
  7256. + const char *packages,
  7257. + ipkg_list_callback cblist,
  7258. + void *userdata);
  7259. +extern int ipkg_packages_status(args_t *args,
  7260. + const char *packages,
  7261. + ipkg_status_callback cbstatus,
  7262. + void *userdata);
  7263. +extern int ipkg_packages_info(args_t *args,
  7264. + const char *packages,
  7265. + ipkg_status_callback cbstatus,
  7266. + void *userdata);
  7267. +extern int ipkg_packages_install(args_t *args, const char *name);
  7268. +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
  7269. +extern int ipkg_lists_update(args_t *args);
  7270. +extern int ipkg_packages_upgrade(args_t *args);
  7271. +extern int ipkg_packages_download(args_t *args, const char *name);
  7272. +extern int ipkg_package_files(args_t *args,
  7273. + const char *name,
  7274. + ipkg_list_callback cblist,
  7275. + void *userdata);
  7276. +extern int ipkg_file_search(args_t *args,
  7277. + const char *file,
  7278. + ipkg_list_callback cblist,
  7279. + void *userdata);
  7280. +extern int ipkg_package_whatdepends(args_t *args, const char *file);
  7281. +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
  7282. +extern int ipkg_package_whatprovides(args_t *args, const char *file);
  7283. +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
  7284. +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
  7285. +
  7286. +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
  7287. +extern ipkg_response_callback ipkg_cb_response;
  7288. +extern ipkg_status_callback ipkg_cb_status;
  7289. +extern ipkg_list_callback ipkg_cb_list;
  7290. +extern void push_error_list(struct errlist **errors,char * msg);
  7291. +extern void reverse_error_list(struct errlist **errors);
  7292. +extern void free_error_list(struct errlist **errors);
  7293. +
  7294. +#endif
  7295. diff -Nur busybox-1.17.1.orig/archival/libipkg/nv_pair.c busybox-1.17.1/archival/libipkg/nv_pair.c
  7296. --- busybox-1.17.1.orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
  7297. +++ busybox-1.17.1/archival/libipkg/nv_pair.c 2010-07-28 13:07:49.523597362 +0200
  7298. @@ -0,0 +1,40 @@
  7299. +/* nv_pair.c - the itsy package management system
  7300. +
  7301. + Carl D. Worth
  7302. +
  7303. + Copyright (C) 2001 University of Southern California
  7304. +
  7305. + This program is free software; you can redistribute it and/or
  7306. + modify it under the terms of the GNU General Public License as
  7307. + published by the Free Software Foundation; either version 2, or (at
  7308. + your option) any later version.
  7309. +
  7310. + This program is distributed in the hope that it will be useful, but
  7311. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7312. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7313. + General Public License for more details.
  7314. +*/
  7315. +
  7316. +#include "ipkg.h"
  7317. +
  7318. +#include "nv_pair.h"
  7319. +#include "str_util.h"
  7320. +
  7321. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
  7322. +{
  7323. + nv_pair->name = str_dup_safe(name);
  7324. + nv_pair->value = str_dup_safe(value);
  7325. +
  7326. + return 0;
  7327. +}
  7328. +
  7329. +void nv_pair_deinit(nv_pair_t *nv_pair)
  7330. +{
  7331. + free(nv_pair->name);
  7332. + nv_pair->name = NULL;
  7333. +
  7334. + free(nv_pair->value);
  7335. + nv_pair->value = NULL;
  7336. +}
  7337. +
  7338. +
  7339. diff -Nur busybox-1.17.1.orig/archival/libipkg/nv_pair.h busybox-1.17.1/archival/libipkg/nv_pair.h
  7340. --- busybox-1.17.1.orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
  7341. +++ busybox-1.17.1/archival/libipkg/nv_pair.h 2010-07-28 13:07:49.523597362 +0200
  7342. @@ -0,0 +1,32 @@
  7343. +/* nv_pair.h - the itsy package management system
  7344. +
  7345. + Carl D. Worth
  7346. +
  7347. + Copyright (C) 2001 University of Southern California
  7348. +
  7349. + This program is free software; you can redistribute it and/or
  7350. + modify it under the terms of the GNU General Public License as
  7351. + published by the Free Software Foundation; either version 2, or (at
  7352. + your option) any later version.
  7353. +
  7354. + This program is distributed in the hope that it will be useful, but
  7355. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7356. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7357. + General Public License for more details.
  7358. +*/
  7359. +
  7360. +#ifndef NV_PAIR_H
  7361. +#define NV_PAIR_H
  7362. +
  7363. +typedef struct nv_pair nv_pair_t;
  7364. +struct nv_pair
  7365. +{
  7366. + char *name;
  7367. + char *value;
  7368. +};
  7369. +
  7370. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
  7371. +void nv_pair_deinit(nv_pair_t *nv_pair);
  7372. +
  7373. +#endif
  7374. +
  7375. diff -Nur busybox-1.17.1.orig/archival/libipkg/nv_pair_list.c busybox-1.17.1/archival/libipkg/nv_pair_list.c
  7376. --- busybox-1.17.1.orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
  7377. +++ busybox-1.17.1/archival/libipkg/nv_pair_list.c 2010-07-28 13:07:49.523597362 +0200
  7378. @@ -0,0 +1,98 @@
  7379. +/* nv_pair_list.c - the itsy package management system
  7380. +
  7381. + Carl D. Worth
  7382. +
  7383. + Copyright (C) 2001 University of Southern California
  7384. +
  7385. + This program is free software; you can redistribute it and/or
  7386. + modify it under the terms of the GNU General Public License as
  7387. + published by the Free Software Foundation; either version 2, or (at
  7388. + your option) any later version.
  7389. +
  7390. + This program is distributed in the hope that it will be useful, but
  7391. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7392. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7393. + General Public License for more details.
  7394. +*/
  7395. +
  7396. +#include "ipkg.h"
  7397. +
  7398. +#include "nv_pair.h"
  7399. +#include "void_list.h"
  7400. +#include "nv_pair_list.h"
  7401. +
  7402. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
  7403. +{
  7404. + return void_list_elt_init((void_list_elt_t *) elt, data);
  7405. +}
  7406. +
  7407. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
  7408. +{
  7409. + void_list_elt_deinit((void_list_elt_t *) elt);
  7410. +}
  7411. +
  7412. +int nv_pair_list_init(nv_pair_list_t *list)
  7413. +{
  7414. + return void_list_init((void_list_t *) list);
  7415. +}
  7416. +
  7417. +void nv_pair_list_deinit(nv_pair_list_t *list)
  7418. +{
  7419. + nv_pair_list_elt_t *iter;
  7420. + nv_pair_t *nv_pair;
  7421. +
  7422. + for (iter = list->head; iter; iter = iter->next) {
  7423. + nv_pair = iter->data;
  7424. + nv_pair_deinit(nv_pair);
  7425. +
  7426. + /* malloced in nv_pair_list_append */
  7427. + free(nv_pair);
  7428. + iter->data = NULL;
  7429. + }
  7430. + void_list_deinit((void_list_t *) list);
  7431. +}
  7432. +
  7433. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
  7434. +{
  7435. + int err;
  7436. +
  7437. + /* freed in nv_pair_list_deinit */
  7438. + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
  7439. +
  7440. + if (nv_pair == NULL) {
  7441. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7442. + return NULL;
  7443. + }
  7444. + nv_pair_init(nv_pair, name, value);
  7445. +
  7446. + err = void_list_append((void_list_t *) list, nv_pair);
  7447. + if (err) {
  7448. + return NULL;
  7449. + }
  7450. +
  7451. + return nv_pair;
  7452. +}
  7453. +
  7454. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
  7455. +{
  7456. + return void_list_push((void_list_t *) list, data);
  7457. +}
  7458. +
  7459. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
  7460. +{
  7461. + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
  7462. +}
  7463. +
  7464. +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
  7465. +{
  7466. + nv_pair_list_elt_t *iter;
  7467. + nv_pair_t *nv_pair;
  7468. +
  7469. + for (iter = list->head; iter; iter = iter->next) {
  7470. + nv_pair = iter->data;
  7471. + if (strcmp(nv_pair->name, name) == 0) {
  7472. + return nv_pair->value;
  7473. + }
  7474. + }
  7475. + return NULL;
  7476. +}
  7477. diff -Nur busybox-1.17.1.orig/archival/libipkg/nv_pair_list.h busybox-1.17.1/archival/libipkg/nv_pair_list.h
  7478. --- busybox-1.17.1.orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
  7479. +++ busybox-1.17.1/archival/libipkg/nv_pair_list.h 2010-07-28 13:07:49.523597362 +0200
  7480. @@ -0,0 +1,60 @@
  7481. +/* nv_pair_list.h - the itsy package management system
  7482. +
  7483. + Carl D. Worth
  7484. +
  7485. + Copyright (C) 2001 University of Southern California
  7486. +
  7487. + This program is free software; you can redistribute it and/or
  7488. + modify it under the terms of the GNU General Public License as
  7489. + published by the Free Software Foundation; either version 2, or (at
  7490. + your option) any later version.
  7491. +
  7492. + This program is distributed in the hope that it will be useful, but
  7493. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7494. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7495. + General Public License for more details.
  7496. +*/
  7497. +
  7498. +#ifndef NV_PAIR_LIST_H
  7499. +#define NV_PAIR_LIST_H
  7500. +
  7501. +#include "nv_pair.h"
  7502. +#include "void_list.h"
  7503. +
  7504. +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
  7505. +struct nv_pair_list_elt
  7506. +{
  7507. + nv_pair_list_elt_t *next;
  7508. + nv_pair_t *data;
  7509. +};
  7510. +
  7511. +typedef struct nv_pair_list nv_pair_list_t;
  7512. +struct nv_pair_list
  7513. +{
  7514. + nv_pair_list_elt_t pre_head;
  7515. + nv_pair_list_elt_t *head;
  7516. + nv_pair_list_elt_t *tail;
  7517. +};
  7518. +
  7519. +static inline int nv_pair_list_empty(nv_pair_list_t *list)
  7520. +{
  7521. + if (list->head == NULL)
  7522. + return 1;
  7523. + else
  7524. + return 0;
  7525. +}
  7526. +
  7527. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
  7528. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
  7529. +
  7530. +int nv_pair_list_init(nv_pair_list_t *list);
  7531. +void nv_pair_list_deinit(nv_pair_list_t *list);
  7532. +
  7533. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
  7534. + const char *name, const char *value);
  7535. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
  7536. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
  7537. +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
  7538. +
  7539. +#endif
  7540. +
  7541. diff -Nur busybox-1.17.1.orig/archival/libipkg/pkg.c busybox-1.17.1/archival/libipkg/pkg.c
  7542. --- busybox-1.17.1.orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
  7543. +++ busybox-1.17.1/archival/libipkg/pkg.c 2010-07-28 13:07:49.543596278 +0200
  7544. @@ -0,0 +1,1757 @@
  7545. +/* pkg.c - the itsy package management system
  7546. +
  7547. + Carl D. Worth
  7548. +
  7549. + Copyright (C) 2001 University of Southern California
  7550. +
  7551. + This program is free software; you can redistribute it and/or
  7552. + modify it under the terms of the GNU General Public License as
  7553. + published by the Free Software Foundation; either version 2, or (at
  7554. + your option) any later version.
  7555. +
  7556. + This program is distributed in the hope that it will be useful, but
  7557. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7558. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7559. + General Public License for more details.
  7560. +*/
  7561. +
  7562. +#include "ipkg.h"
  7563. +#include <ctype.h>
  7564. +#include <string.h>
  7565. +#include <errno.h>
  7566. +
  7567. +#include "pkg.h"
  7568. +
  7569. +#include "pkg_parse.h"
  7570. +#include "pkg_extract.h"
  7571. +#include "ipkg_message.h"
  7572. +#include "ipkg_utils.h"
  7573. +
  7574. +#include "sprintf_alloc.h"
  7575. +#include "file_util.h"
  7576. +#include "str_util.h"
  7577. +#include "xsystem.h"
  7578. +#include "ipkg_conf.h"
  7579. +
  7580. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname);
  7581. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_);
  7582. +
  7583. +typedef struct enum_map enum_map_t;
  7584. +struct enum_map
  7585. +{
  7586. + int value;
  7587. + const char *str;
  7588. +};
  7589. +
  7590. +static const enum_map_t pkg_state_want_map[] = {
  7591. + { SW_UNKNOWN, "unknown"},
  7592. + { SW_INSTALL, "install"},
  7593. + { SW_DEINSTALL, "deinstall"},
  7594. + { SW_PURGE, "purge"}
  7595. +};
  7596. +
  7597. +static const enum_map_t pkg_state_flag_map[] = {
  7598. + { SF_OK, "ok"},
  7599. + { SF_REINSTREQ, "reinstreq"},
  7600. + { SF_HOLD, "hold"},
  7601. + { SF_REPLACE, "replace"},
  7602. + { SF_NOPRUNE, "noprune"},
  7603. + { SF_PREFER, "prefer"},
  7604. + { SF_OBSOLETE, "obsolete"},
  7605. + { SF_USER, "user"},
  7606. +};
  7607. +
  7608. +static const enum_map_t pkg_state_status_map[] = {
  7609. + { SS_NOT_INSTALLED, "not-installed" },
  7610. + { SS_UNPACKED, "unpacked" },
  7611. + { SS_HALF_CONFIGURED, "half-configured" },
  7612. + { SS_INSTALLED, "installed" },
  7613. + { SS_HALF_INSTALLED, "half-installed" },
  7614. + { SS_CONFIG_FILES, "config-files" },
  7615. + { SS_POST_INST_FAILED, "post-inst-failed" },
  7616. + { SS_REMOVAL_FAILED, "removal-failed" }
  7617. +};
  7618. +
  7619. +static int verrevcmp(const char *val, const char *ref);
  7620. +
  7621. +
  7622. +pkg_t *pkg_new(void)
  7623. +{
  7624. + pkg_t *pkg;
  7625. +
  7626. + pkg = malloc(sizeof(pkg_t));
  7627. + if (pkg == NULL) {
  7628. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7629. + return NULL;
  7630. + }
  7631. +
  7632. + pkg_init(pkg);
  7633. +
  7634. + return pkg;
  7635. +}
  7636. +
  7637. +int pkg_init(pkg_t *pkg)
  7638. +{
  7639. + memset(pkg, 0, sizeof(pkg_t));
  7640. + pkg->name = NULL;
  7641. + pkg->epoch = 0;
  7642. + pkg->version = NULL;
  7643. + pkg->revision = NULL;
  7644. + pkg->familiar_revision = NULL;
  7645. + pkg->dest = NULL;
  7646. + pkg->src = NULL;
  7647. + pkg->architecture = NULL;
  7648. + pkg->maintainer = NULL;
  7649. + pkg->section = NULL;
  7650. + pkg->description = NULL;
  7651. + pkg->state_want = SW_UNKNOWN;
  7652. + pkg->state_flag = SF_OK;
  7653. + pkg->state_status = SS_NOT_INSTALLED;
  7654. + pkg->depends_str = NULL;
  7655. + pkg->provides_str = NULL;
  7656. + pkg->depends_count = 0;
  7657. + pkg->depends = NULL;
  7658. + pkg->suggests_str = NULL;
  7659. + pkg->recommends_str = NULL;
  7660. + pkg->suggests_count = 0;
  7661. + pkg->recommends_count = 0;
  7662. +
  7663. + /* Abhaya: added init for conflicts fields */
  7664. + pkg->conflicts = NULL;
  7665. + pkg->conflicts_count = 0;
  7666. +
  7667. + /* added for replaces. Jamey 7/23/2002 */
  7668. + pkg->replaces = NULL;
  7669. + pkg->replaces_count = 0;
  7670. +
  7671. + pkg->pre_depends_count = 0;
  7672. + pkg->pre_depends_str = NULL;
  7673. + pkg->provides_count = 0;
  7674. + pkg->provides = NULL;
  7675. + pkg->filename = NULL;
  7676. + pkg->local_filename = NULL;
  7677. + pkg->tmp_unpack_dir = NULL;
  7678. + pkg->md5sum = NULL;
  7679. + pkg->size = NULL;
  7680. + pkg->installed_size = NULL;
  7681. + pkg->priority = NULL;
  7682. + pkg->source = NULL;
  7683. + conffile_list_init(&pkg->conffiles);
  7684. + pkg->installed_files = NULL;
  7685. + pkg->installed_files_ref_cnt = 0;
  7686. + pkg->essential = 0;
  7687. + pkg->provided_by_hand = 0;
  7688. +
  7689. + return 0;
  7690. +}
  7691. +
  7692. +void pkg_deinit(pkg_t *pkg)
  7693. +{
  7694. + free(pkg->name);
  7695. + pkg->name = NULL;
  7696. + pkg->epoch = 0;
  7697. + free(pkg->version);
  7698. + pkg->version = NULL;
  7699. + /* revision and familiar_revision share storage with version, so
  7700. + don't free */
  7701. + pkg->revision = NULL;
  7702. + pkg->familiar_revision = NULL;
  7703. + /* owned by ipkg_conf_t */
  7704. + pkg->dest = NULL;
  7705. + /* owned by ipkg_conf_t */
  7706. + pkg->src = NULL;
  7707. + free(pkg->architecture);
  7708. + pkg->architecture = NULL;
  7709. + free(pkg->maintainer);
  7710. + pkg->maintainer = NULL;
  7711. + free(pkg->section);
  7712. + pkg->section = NULL;
  7713. + free(pkg->description);
  7714. + pkg->description = NULL;
  7715. + pkg->state_want = SW_UNKNOWN;
  7716. + pkg->state_flag = SF_OK;
  7717. + pkg->state_status = SS_NOT_INSTALLED;
  7718. + free(pkg->depends_str);
  7719. + pkg->depends_str = NULL;
  7720. + free(pkg->provides_str);
  7721. + pkg->provides_str = NULL;
  7722. + pkg->depends_count = 0;
  7723. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
  7724. + pkg->pre_depends_count = 0;
  7725. + free(pkg->pre_depends_str);
  7726. + pkg->pre_depends_str = NULL;
  7727. + pkg->provides_count = 0;
  7728. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
  7729. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
  7730. + free(pkg->filename);
  7731. + pkg->filename = NULL;
  7732. + free(pkg->local_filename);
  7733. + pkg->local_filename = NULL;
  7734. + /* CLEANUP: It'd be nice to pullin the cleanup function from
  7735. + ipkg_install.c here. See comment in
  7736. + ipkg_install.c:cleanup_temporary_files */
  7737. + free(pkg->tmp_unpack_dir);
  7738. + pkg->tmp_unpack_dir = NULL;
  7739. + free(pkg->md5sum);
  7740. + pkg->md5sum = NULL;
  7741. + free(pkg->size);
  7742. + pkg->size = NULL;
  7743. + free(pkg->installed_size);
  7744. + pkg->installed_size = NULL;
  7745. + free(pkg->priority);
  7746. + pkg->priority = NULL;
  7747. + free(pkg->source);
  7748. + pkg->source = NULL;
  7749. + conffile_list_deinit(&pkg->conffiles);
  7750. + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
  7751. + since if they are calling deinit, they should know. Maybe do an
  7752. + assertion here instead? */
  7753. + pkg->installed_files_ref_cnt = 1;
  7754. + pkg_free_installed_files(pkg);
  7755. + pkg->essential = 0;
  7756. +}
  7757. +
  7758. +int pkg_init_from_file(pkg_t *pkg, const char *filename)
  7759. +{
  7760. + int err;
  7761. + char **raw;
  7762. + FILE *control_file;
  7763. +
  7764. + err = pkg_init(pkg);
  7765. + if (err) { return err; }
  7766. +
  7767. + pkg->local_filename = strdup(filename);
  7768. +
  7769. + control_file = tmpfile();
  7770. + err = pkg_extract_control_file_to_stream(pkg, control_file);
  7771. + if (err) { return err; }
  7772. +
  7773. + rewind(control_file);
  7774. + raw = read_raw_pkgs_from_stream(control_file);
  7775. + pkg_parse_raw(pkg, &raw, NULL, NULL);
  7776. +
  7777. + fclose(control_file);
  7778. +
  7779. + return 0;
  7780. +}
  7781. +
  7782. +/* Merge any new information in newpkg into oldpkg */
  7783. +/* XXX: CLEANUP: This function shouldn't actually modify anything in
  7784. + newpkg, but should leave it usable. This rework is so that
  7785. + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
  7786. +/*
  7787. + * uh, i thought that i had originally written this so that it took
  7788. + * two pkgs and returned a new one? we can do that again... -sma
  7789. + */
  7790. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
  7791. +{
  7792. + if (oldpkg == newpkg) {
  7793. + return 0;
  7794. + }
  7795. +
  7796. + if (!oldpkg->src)
  7797. + oldpkg->src = newpkg->src;
  7798. + if (!oldpkg->dest)
  7799. + oldpkg->dest = newpkg->dest;
  7800. + if (!oldpkg->architecture)
  7801. + oldpkg->architecture = str_dup_safe(newpkg->architecture);
  7802. + if (!oldpkg->arch_priority)
  7803. + oldpkg->arch_priority = newpkg->arch_priority;
  7804. + if (!oldpkg->section)
  7805. + oldpkg->section = str_dup_safe(newpkg->section);
  7806. + if(!oldpkg->maintainer)
  7807. + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
  7808. + if(!oldpkg->description)
  7809. + oldpkg->description = str_dup_safe(newpkg->description);
  7810. + if (set_status) {
  7811. + /* merge the state_flags from the new package */
  7812. + oldpkg->state_want = newpkg->state_want;
  7813. + oldpkg->state_status = newpkg->state_status;
  7814. + oldpkg->state_flag = newpkg->state_flag;
  7815. + } else {
  7816. + if (oldpkg->state_want == SW_UNKNOWN)
  7817. + oldpkg->state_want = newpkg->state_want;
  7818. + if (oldpkg->state_status == SS_NOT_INSTALLED)
  7819. + oldpkg->state_status = newpkg->state_status;
  7820. + oldpkg->state_flag |= newpkg->state_flag;
  7821. + }
  7822. +
  7823. + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
  7824. + oldpkg->depends_str = newpkg->depends_str;
  7825. + newpkg->depends_str = NULL;
  7826. + oldpkg->depends_count = newpkg->depends_count;
  7827. + newpkg->depends_count = 0;
  7828. +
  7829. + oldpkg->depends = newpkg->depends;
  7830. + newpkg->depends = NULL;
  7831. +
  7832. + oldpkg->pre_depends_str = newpkg->pre_depends_str;
  7833. + newpkg->pre_depends_str = NULL;
  7834. + oldpkg->pre_depends_count = newpkg->pre_depends_count;
  7835. + newpkg->pre_depends_count = 0;
  7836. +
  7837. + oldpkg->recommends_str = newpkg->recommends_str;
  7838. + newpkg->recommends_str = NULL;
  7839. + oldpkg->recommends_count = newpkg->recommends_count;
  7840. + newpkg->recommends_count = 0;
  7841. +
  7842. + oldpkg->suggests_str = newpkg->suggests_str;
  7843. + newpkg->suggests_str = NULL;
  7844. + oldpkg->suggests_count = newpkg->suggests_count;
  7845. + newpkg->suggests_count = 0;
  7846. + }
  7847. +
  7848. + if (!oldpkg->provides_str) {
  7849. + oldpkg->provides_str = newpkg->provides_str;
  7850. + newpkg->provides_str = NULL;
  7851. + oldpkg->provides_count = newpkg->provides_count;
  7852. + newpkg->provides_count = 0;
  7853. +
  7854. + oldpkg->provides = newpkg->provides;
  7855. + newpkg->provides = NULL;
  7856. + }
  7857. +
  7858. + if (!oldpkg->conflicts_str) {
  7859. + oldpkg->conflicts_str = newpkg->conflicts_str;
  7860. + newpkg->conflicts_str = NULL;
  7861. + oldpkg->conflicts_count = newpkg->conflicts_count;
  7862. + newpkg->conflicts_count = 0;
  7863. +
  7864. + oldpkg->conflicts = newpkg->conflicts;
  7865. + newpkg->conflicts = NULL;
  7866. + }
  7867. +
  7868. + if (!oldpkg->replaces_str) {
  7869. + oldpkg->replaces_str = newpkg->replaces_str;
  7870. + newpkg->replaces_str = NULL;
  7871. + oldpkg->replaces_count = newpkg->replaces_count;
  7872. + newpkg->replaces_count = 0;
  7873. +
  7874. + oldpkg->replaces = newpkg->replaces;
  7875. + newpkg->replaces = NULL;
  7876. + }
  7877. +
  7878. + if (!oldpkg->filename)
  7879. + oldpkg->filename = str_dup_safe(newpkg->filename);
  7880. + if (0)
  7881. + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
  7882. + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
  7883. + if (!oldpkg->local_filename)
  7884. + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
  7885. + if (!oldpkg->tmp_unpack_dir)
  7886. + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
  7887. + if (!oldpkg->md5sum)
  7888. + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
  7889. + if (!oldpkg->size)
  7890. + oldpkg->size = str_dup_safe(newpkg->size);
  7891. + if (!oldpkg->installed_size)
  7892. + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
  7893. + if (!oldpkg->priority)
  7894. + oldpkg->priority = str_dup_safe(newpkg->priority);
  7895. + if (!oldpkg->source)
  7896. + oldpkg->source = str_dup_safe(newpkg->source);
  7897. + if (oldpkg->conffiles.head == NULL){
  7898. + oldpkg->conffiles = newpkg->conffiles;
  7899. + conffile_list_init(&newpkg->conffiles);
  7900. + }
  7901. + if (!oldpkg->installed_files){
  7902. + oldpkg->installed_files = newpkg->installed_files;
  7903. + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
  7904. + newpkg->installed_files = NULL;
  7905. + }
  7906. + if (!oldpkg->essential)
  7907. + oldpkg->essential = newpkg->essential;
  7908. +
  7909. + return 0;
  7910. +}
  7911. +
  7912. +abstract_pkg_t *abstract_pkg_new(void)
  7913. +{
  7914. + abstract_pkg_t * ab_pkg;
  7915. +
  7916. + ab_pkg = malloc(sizeof(abstract_pkg_t));
  7917. +
  7918. + if (ab_pkg == NULL) {
  7919. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7920. + return NULL;
  7921. + }
  7922. +
  7923. + if ( abstract_pkg_init(ab_pkg) < 0 )
  7924. + return NULL;
  7925. +
  7926. + return ab_pkg;
  7927. +}
  7928. +
  7929. +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
  7930. +{
  7931. + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
  7932. +
  7933. + ab_pkg->provided_by = abstract_pkg_vec_alloc();
  7934. + if (ab_pkg->provided_by==NULL){
  7935. + return -1;
  7936. + }
  7937. + ab_pkg->dependencies_checked = 0;
  7938. + ab_pkg->state_status = SS_NOT_INSTALLED;
  7939. +
  7940. + return 0;
  7941. +}
  7942. +
  7943. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
  7944. + char * temp_str;
  7945. + char **raw =NULL;
  7946. + char **raw_start=NULL;
  7947. +
  7948. + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
  7949. + if (temp_str == NULL ){
  7950. + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
  7951. + return;
  7952. + }
  7953. + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
  7954. +
  7955. + raw = raw_start = read_raw_pkgs_from_file(temp_str);
  7956. + if (raw == NULL ){
  7957. + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
  7958. + return;
  7959. + }
  7960. +
  7961. + while(*raw){
  7962. + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
  7963. + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
  7964. + }
  7965. + }
  7966. + raw = raw_start;
  7967. + while (*raw) {
  7968. + if (raw!=NULL)
  7969. + free(*raw++);
  7970. + }
  7971. +
  7972. + free(raw_start);
  7973. + free(temp_str);
  7974. +
  7975. + return ;
  7976. +
  7977. +}
  7978. +
  7979. +char * pkg_formatted_info(pkg_t *pkg )
  7980. +{
  7981. + char *line;
  7982. + char * buff;
  7983. +
  7984. + buff = malloc(8192);
  7985. + if (buff == NULL) {
  7986. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7987. + return NULL;
  7988. + }
  7989. +
  7990. + buff[0] = '\0';
  7991. +
  7992. + line = pkg_formatted_field(pkg, "Package");
  7993. + strncat(buff ,line, strlen(line));
  7994. + free(line);
  7995. +
  7996. + line = pkg_formatted_field(pkg, "Version");
  7997. + strncat(buff ,line, strlen(line));
  7998. + free(line);
  7999. +
  8000. + line = pkg_formatted_field(pkg, "Depends");
  8001. + strncat(buff ,line, strlen(line));
  8002. + free(line);
  8003. +
  8004. + line = pkg_formatted_field(pkg, "Recommends");
  8005. + strncat(buff ,line, strlen(line));
  8006. + free(line);
  8007. +
  8008. + line = pkg_formatted_field(pkg, "Suggests");
  8009. + strncat(buff ,line, strlen(line));
  8010. + free(line);
  8011. +
  8012. + line = pkg_formatted_field(pkg, "Provides");
  8013. + strncat(buff ,line, strlen(line));
  8014. + free(line);
  8015. +
  8016. + line = pkg_formatted_field(pkg, "Replaces");
  8017. + strncat(buff ,line, strlen(line));
  8018. + free(line);
  8019. +
  8020. + line = pkg_formatted_field(pkg, "Conflicts");
  8021. + strncat(buff ,line, strlen(line));
  8022. + free(line);
  8023. +
  8024. + line = pkg_formatted_field(pkg, "Status");
  8025. + strncat(buff ,line, strlen(line));
  8026. + free(line);
  8027. +
  8028. + line = pkg_formatted_field(pkg, "Section");
  8029. + strncat(buff ,line, strlen(line));
  8030. + free(line);
  8031. +
  8032. + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
  8033. + strncat(buff ,line, strlen(line));
  8034. + free(line);
  8035. +
  8036. + line = pkg_formatted_field(pkg, "Architecture");
  8037. + strncat(buff ,line, strlen(line));
  8038. + free(line);
  8039. +
  8040. + line = pkg_formatted_field(pkg, "Maintainer");
  8041. + strncat(buff ,line, strlen(line));
  8042. + free(line);
  8043. +
  8044. + line = pkg_formatted_field(pkg, "MD5sum");
  8045. + strncat(buff ,line, strlen(line));
  8046. + free(line);
  8047. +
  8048. + line = pkg_formatted_field(pkg, "Size");
  8049. + strncat(buff ,line, strlen(line));
  8050. + free(line);
  8051. +
  8052. + line = pkg_formatted_field(pkg, "Filename");
  8053. + strncat(buff ,line, strlen(line));
  8054. + free(line);
  8055. +
  8056. + line = pkg_formatted_field(pkg, "Conffiles");
  8057. + strncat(buff ,line, strlen(line));
  8058. + free(line);
  8059. +
  8060. + line = pkg_formatted_field(pkg, "Source");
  8061. + strncat(buff ,line, strlen(line));
  8062. + free(line);
  8063. +
  8064. + line = pkg_formatted_field(pkg, "Description");
  8065. + strncat(buff ,line, strlen(line));
  8066. + free(line);
  8067. +
  8068. + line = pkg_formatted_field(pkg, "Installed-Time");
  8069. + strncat(buff ,line, strlen(line));
  8070. + free(line);
  8071. +
  8072. + return buff;
  8073. +}
  8074. +
  8075. +char * pkg_formatted_field(pkg_t *pkg, const char *field )
  8076. +{
  8077. + static size_t LINE_LEN = 128;
  8078. + char * temp = (char *)malloc(1);
  8079. + int len = 0;
  8080. + int flag_provide_false = 0;
  8081. +
  8082. +/*
  8083. + Pigi: After some discussion with Florian we decided to modify the full procedure in
  8084. + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
  8085. +*/
  8086. +
  8087. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8088. + goto UNKNOWN_FMT_FIELD;
  8089. + }
  8090. +
  8091. + temp[0]='\0';
  8092. +
  8093. + switch (field[0])
  8094. + {
  8095. + case 'a':
  8096. + case 'A':
  8097. + if (strcasecmp(field, "Architecture") == 0) {
  8098. + /* Architecture */
  8099. + if (pkg->architecture) {
  8100. + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
  8101. + if ( temp == NULL ){
  8102. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8103. + return NULL;
  8104. + }
  8105. + temp[0]='\0';
  8106. + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
  8107. + }
  8108. + } else {
  8109. + goto UNKNOWN_FMT_FIELD;
  8110. + }
  8111. + break;
  8112. + case 'c':
  8113. + case 'C':
  8114. + if (strcasecmp(field, "Conffiles") == 0) {
  8115. + /* Conffiles */
  8116. + conffile_list_elt_t *iter;
  8117. + char confstr_[LINE_LEN];
  8118. +
  8119. + if (pkg->conffiles.head == NULL) {
  8120. + return temp;
  8121. + }
  8122. +
  8123. + len = 14 ;
  8124. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8125. + if (iter->data->name && iter->data->value) {
  8126. + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
  8127. + }
  8128. + }
  8129. + temp = (char *)realloc(temp,len);
  8130. + if ( temp == NULL ){
  8131. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8132. + return NULL;
  8133. + }
  8134. + temp[0]='\0';
  8135. + strncpy(temp, "Conffiles:\n", 12);
  8136. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8137. + if (iter->data->name && iter->data->value) {
  8138. + snprintf(confstr_, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
  8139. + strncat(temp, confstr_, strlen(confstr_));
  8140. + }
  8141. + }
  8142. + } else if (strcasecmp(field, "Conflicts") == 0) {
  8143. + int i;
  8144. +
  8145. + if (pkg->conflicts_count) {
  8146. + char conflictstr[LINE_LEN];
  8147. + len = 14 ;
  8148. + for(i = 0; i < pkg->conflicts_count; i++) {
  8149. + len = len + (strlen(pkg->conflicts_str[i])+5);
  8150. + }
  8151. + temp = (char *)realloc(temp,len);
  8152. + if ( temp == NULL ){
  8153. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8154. + return NULL;
  8155. + }
  8156. + temp[0]='\0';
  8157. + strncpy(temp, "Conflicts:", 11);
  8158. + for(i = 0; i < pkg->conflicts_count; i++) {
  8159. + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
  8160. + strncat(temp, conflictstr, strlen(conflictstr));
  8161. + }
  8162. + strncat(temp, "\n", strlen("\n"));
  8163. + }
  8164. + } else {
  8165. + goto UNKNOWN_FMT_FIELD;
  8166. + }
  8167. + break;
  8168. + case 'd':
  8169. + case 'D':
  8170. + if (strcasecmp(field, "Depends") == 0) {
  8171. + /* Depends */
  8172. + int i;
  8173. +
  8174. + if (pkg->depends_count) {
  8175. + char depstr[LINE_LEN];
  8176. + len = 14 ;
  8177. + for(i = 0; i < pkg->depends_count; i++) {
  8178. + len = len + (strlen(pkg->depends_str[i])+4);
  8179. + }
  8180. + temp = (char *)realloc(temp,len);
  8181. + if ( temp == NULL ){
  8182. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8183. + return NULL;
  8184. + }
  8185. + temp[0]='\0';
  8186. + strncpy(temp, "Depends:", 10);
  8187. + for(i = 0; i < pkg->depends_count; i++) {
  8188. + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
  8189. + strncat(temp, depstr, strlen(depstr));
  8190. + }
  8191. + strncat(temp, "\n", strlen("\n"));
  8192. + }
  8193. + } else if (strcasecmp(field, "Description") == 0) {
  8194. + /* Description */
  8195. + if (pkg->description) {
  8196. + temp = (char *)realloc(temp,strlen(pkg->description)+16);
  8197. + if ( temp == NULL ){
  8198. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8199. + return NULL;
  8200. + }
  8201. + temp[0]='\0';
  8202. + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
  8203. + }
  8204. + } else {
  8205. + goto UNKNOWN_FMT_FIELD;
  8206. + }
  8207. + break;
  8208. + case 'e':
  8209. + case 'E': {
  8210. + /* Essential */
  8211. + if (pkg->essential) {
  8212. + temp = (char *)realloc(temp,16);
  8213. + if ( temp == NULL ){
  8214. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8215. + return NULL;
  8216. + }
  8217. + temp[0]='\0';
  8218. + snprintf(temp, (16), "Essential: yes\n");
  8219. + }
  8220. + }
  8221. + break;
  8222. + case 'f':
  8223. + case 'F': {
  8224. + /* Filename */
  8225. + if (pkg->filename) {
  8226. + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
  8227. + if ( temp == NULL ){
  8228. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8229. + return NULL;
  8230. + }
  8231. + temp[0]='\0';
  8232. + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
  8233. + }
  8234. + }
  8235. + break;
  8236. + case 'i':
  8237. + case 'I': {
  8238. + if (strcasecmp(field, "Installed-Size") == 0) {
  8239. + /* Installed-Size */
  8240. + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
  8241. + if ( temp == NULL ){
  8242. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8243. + return NULL;
  8244. + }
  8245. + temp[0]='\0';
  8246. + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
  8247. + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
  8248. + temp = (char *)realloc(temp,29);
  8249. + if ( temp == NULL ){
  8250. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8251. + return NULL;
  8252. + }
  8253. + temp[0]='\0';
  8254. + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
  8255. + }
  8256. + }
  8257. + break;
  8258. + case 'm':
  8259. + case 'M': {
  8260. + /* Maintainer | MD5sum */
  8261. + if (strcasecmp(field, "Maintainer") == 0) {
  8262. + /* Maintainer */
  8263. + if (pkg->maintainer) {
  8264. + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
  8265. + if ( temp == NULL ){
  8266. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8267. + return NULL;
  8268. + }
  8269. + temp[0]='\0';
  8270. + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
  8271. + }
  8272. + } else if (strcasecmp(field, "MD5sum") == 0) {
  8273. + /* MD5sum */
  8274. + if (pkg->md5sum) {
  8275. + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
  8276. + if ( temp == NULL ){
  8277. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8278. + return NULL;
  8279. + }
  8280. + temp[0]='\0';
  8281. + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
  8282. + }
  8283. + } else {
  8284. + goto UNKNOWN_FMT_FIELD;
  8285. + }
  8286. + }
  8287. + break;
  8288. + case 'p':
  8289. + case 'P': {
  8290. + if (strcasecmp(field, "Package") == 0) {
  8291. + /* Package */
  8292. + temp = (char *)realloc(temp,strlen(pkg->name)+11);
  8293. + if ( temp == NULL ){
  8294. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8295. + return NULL;
  8296. + }
  8297. + temp[0]='\0';
  8298. + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
  8299. + } else if (strcasecmp(field, "Priority") == 0) {
  8300. + /* Priority */
  8301. + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
  8302. + if ( temp == NULL ){
  8303. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8304. + return NULL;
  8305. + }
  8306. + temp[0]='\0';
  8307. + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
  8308. + } else if (strcasecmp(field, "Provides") == 0) {
  8309. + /* Provides */
  8310. + int i;
  8311. +
  8312. + if (pkg->provides_count) {
  8313. + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
  8314. + for ( i=0; i < pkg->provides_count; i++ ){
  8315. + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
  8316. + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
  8317. + flag_provide_false = 1;
  8318. + }
  8319. + }
  8320. + if ( !flag_provide_false || /* Pigi there is not my trick flag */
  8321. + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
  8322. + char provstr[LINE_LEN];
  8323. + len = 15;
  8324. + for(i = 0; i < pkg->provides_count; i++) {
  8325. + len = len + (strlen(pkg->provides_str[i])+5);
  8326. + }
  8327. + temp = (char *)realloc(temp,len);
  8328. + if ( temp == NULL ){
  8329. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8330. + return NULL;
  8331. + }
  8332. + temp[0]='\0';
  8333. + strncpy(temp, "Provides:", 12);
  8334. + for(i = 0; i < pkg->provides_count; i++) {
  8335. + if (strlen(pkg->provides_str[i])>0){;
  8336. + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
  8337. + strncat(temp, provstr, strlen(provstr));
  8338. + }
  8339. + }
  8340. + strncat(temp, "\n", strlen("\n"));
  8341. + }
  8342. + }
  8343. + } else {
  8344. + goto UNKNOWN_FMT_FIELD;
  8345. + }
  8346. + }
  8347. + break;
  8348. + case 'r':
  8349. + case 'R': {
  8350. + int i;
  8351. + /* Replaces | Recommends*/
  8352. + if (strcasecmp (field, "Replaces") == 0) {
  8353. + if (pkg->replaces_count) {
  8354. + char replstr[LINE_LEN];
  8355. + len = 14;
  8356. + for (i = 0; i < pkg->replaces_count; i++) {
  8357. + len = len + (strlen(pkg->replaces_str[i])+5);
  8358. + }
  8359. + temp = (char *)realloc(temp,len);
  8360. + if ( temp == NULL ){
  8361. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8362. + return NULL;
  8363. + }
  8364. + temp[0]='\0';
  8365. + strncpy(temp, "Replaces:", 12);
  8366. + for (i = 0; i < pkg->replaces_count; i++) {
  8367. + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
  8368. + strncat(temp, replstr, strlen(replstr));
  8369. + }
  8370. + strncat(temp, "\n", strlen("\n"));
  8371. + }
  8372. + } else if (strcasecmp (field, "Recommends") == 0) {
  8373. + if (pkg->recommends_count) {
  8374. + char recstr[LINE_LEN];
  8375. + len = 15;
  8376. + for(i = 0; i < pkg->recommends_count; i++) {
  8377. + len = len + (strlen( pkg->recommends_str[i])+5);
  8378. + }
  8379. + temp = (char *)realloc(temp,len);
  8380. + if ( temp == NULL ){
  8381. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8382. + return NULL;
  8383. + }
  8384. + temp[0]='\0';
  8385. + strncpy(temp, "Recommends:", 13);
  8386. + for(i = 0; i < pkg->recommends_count; i++) {
  8387. + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
  8388. + strncat(temp, recstr, strlen(recstr));
  8389. + }
  8390. + strncat(temp, "\n", strlen("\n"));
  8391. + }
  8392. + } else {
  8393. + goto UNKNOWN_FMT_FIELD;
  8394. + }
  8395. + }
  8396. + break;
  8397. + case 's':
  8398. + case 'S': {
  8399. + /* Section | Size | Source | Status | Suggests */
  8400. + if (strcasecmp(field, "Section") == 0) {
  8401. + /* Section */
  8402. + if (pkg->section) {
  8403. + temp = (char *)realloc(temp,strlen(pkg->section)+11);
  8404. + if ( temp == NULL ){
  8405. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8406. + return NULL;
  8407. + }
  8408. + temp[0]='\0';
  8409. + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
  8410. + }
  8411. + } else if (strcasecmp(field, "Size") == 0) {
  8412. + /* Size */
  8413. + if (pkg->size) {
  8414. + temp = (char *)realloc(temp,strlen(pkg->size)+8);
  8415. + if ( temp == NULL ){
  8416. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8417. + return NULL;
  8418. + }
  8419. + temp[0]='\0';
  8420. + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
  8421. + }
  8422. + } else if (strcasecmp(field, "Source") == 0) {
  8423. + /* Source */
  8424. + if (pkg->source) {
  8425. + temp = (char *)realloc(temp,strlen(pkg->source)+10);
  8426. + if ( temp == NULL ){
  8427. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8428. + return NULL;
  8429. + }
  8430. + temp[0]='\0';
  8431. + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
  8432. + }
  8433. + } else if (strcasecmp(field, "Status") == 0) {
  8434. + /* Status */
  8435. + /* Benjamin Pineau note: we should avoid direct usage of
  8436. + * strlen(arg) without keeping "arg" for later free()
  8437. + */
  8438. + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
  8439. + char *pstat=pkg_state_status_to_str(pkg->state_status);
  8440. + char *pwant=pkg_state_want_to_str(pkg->state_want);
  8441. +
  8442. + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
  8443. + temp = (char *)realloc(temp,sum_of_sizes);
  8444. + if ( temp == NULL ){
  8445. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8446. + return NULL;
  8447. + }
  8448. + temp[0]='\0';
  8449. + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
  8450. + free(pflag);
  8451. + free(pwant);
  8452. + if(pstat) /* pfstat can be NULL if ENOMEM */
  8453. + free(pstat);
  8454. + } else if (strcasecmp(field, "Suggests") == 0) {
  8455. + if (pkg->suggests_count) {
  8456. + int i;
  8457. + char sugstr[LINE_LEN];
  8458. + len = 13;
  8459. + for(i = 0; i < pkg->suggests_count; i++) {
  8460. + len = len + (strlen(pkg->suggests_str[i])+5);
  8461. + }
  8462. + temp = (char *)realloc(temp,len);
  8463. + if ( temp == NULL ){
  8464. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8465. + return NULL;
  8466. + }
  8467. + temp[0]='\0';
  8468. + strncpy(temp, "Suggests:", 10);
  8469. + for(i = 0; i < pkg->suggests_count; i++) {
  8470. + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
  8471. + strncat(temp, sugstr, strlen(sugstr));
  8472. + }
  8473. + strncat(temp, "\n", strlen("\n"));
  8474. + }
  8475. + } else {
  8476. + goto UNKNOWN_FMT_FIELD;
  8477. + }
  8478. + }
  8479. + break;
  8480. + case 'v':
  8481. + case 'V': {
  8482. + /* Version */
  8483. + char *version = pkg_version_str_alloc(pkg);
  8484. + temp = (char *)realloc(temp,strlen(version)+14);
  8485. + if ( temp == NULL ){
  8486. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8487. + return NULL;
  8488. + }
  8489. + temp[0]='\0';
  8490. + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
  8491. + free(version);
  8492. + }
  8493. + break;
  8494. + default:
  8495. + goto UNKNOWN_FMT_FIELD;
  8496. + }
  8497. +
  8498. + if ( strlen(temp)<2 ) {
  8499. + temp[0]='\0';
  8500. + }
  8501. + return temp;
  8502. +
  8503. + UNKNOWN_FMT_FIELD:
  8504. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
  8505. + if ( strlen(temp)<2 ) {
  8506. + temp[0]='\0';
  8507. + }
  8508. +
  8509. + return temp;
  8510. +}
  8511. +
  8512. +void pkg_print_info(pkg_t *pkg, FILE *file)
  8513. +{
  8514. + char * buff;
  8515. + if (pkg == NULL) {
  8516. + return;
  8517. + }
  8518. +
  8519. + buff = pkg_formatted_info(pkg);
  8520. + if ( buff == NULL )
  8521. + return;
  8522. + if (strlen(buff)>2){
  8523. + fwrite(buff, 1, strlen(buff), file);
  8524. + }
  8525. + free(buff);
  8526. +}
  8527. +
  8528. +void pkg_print_status(pkg_t * pkg, FILE * file)
  8529. +{
  8530. + if (pkg == NULL) {
  8531. + return;
  8532. + }
  8533. +
  8534. + /* XXX: QUESTION: Do we actually want more fields here? The
  8535. + original idea was to save space by installing only what was
  8536. + needed for actual computation, (package, version, status,
  8537. + essential, conffiles). The assumption is that all other fields
  8538. + can be found in th available file.
  8539. +
  8540. + But, someone proposed the idea to make it possible to
  8541. + reconstruct a .ipk from an installed package, (ie. for beaming
  8542. + from one handheld to another). So, maybe we actually want a few
  8543. + more fields here, (depends, suggests, etc.), so that that would
  8544. + be guaranteed to work even in the absence of more information
  8545. + from the available file.
  8546. +
  8547. + 28-MAR-03: kergoth and I discussed this yesterday. We think
  8548. + the essential info needs to be here for all installed packages
  8549. + because they may not appear in the Packages files on various
  8550. + feeds. Furthermore, one should be able to install from URL or
  8551. + local storage without requiring a Packages file from any feed.
  8552. + -Jamey
  8553. + */
  8554. + pkg_print_field(pkg, file, "Package");
  8555. + pkg_print_field(pkg, file, "Version");
  8556. + pkg_print_field(pkg, file, "Depends");
  8557. + pkg_print_field(pkg, file, "Recommends");
  8558. + pkg_print_field(pkg, file, "Suggests");
  8559. + pkg_print_field(pkg, file, "Provides");
  8560. + pkg_print_field(pkg, file, "Replaces");
  8561. + pkg_print_field(pkg, file, "Conflicts");
  8562. + pkg_print_field(pkg, file, "Status");
  8563. + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
  8564. + pkg_print_field(pkg, file, "Architecture");
  8565. + pkg_print_field(pkg, file, "Conffiles");
  8566. + pkg_print_field(pkg, file, "Installed-Time");
  8567. + fputs("\n", file);
  8568. +}
  8569. +
  8570. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
  8571. +{
  8572. + char *buff;
  8573. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8574. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
  8575. + __FUNCTION__, field);
  8576. + }
  8577. + buff = pkg_formatted_field(pkg, field);
  8578. + if (strlen(buff)>2) {
  8579. + fprintf(file, "%s", buff);
  8580. + fflush(file);
  8581. + }
  8582. + free(buff);
  8583. + return;
  8584. +}
  8585. +
  8586. +/*
  8587. + * libdpkg - Debian packaging suite library routines
  8588. + * vercmp.c - comparison of version numbers
  8589. + *
  8590. + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  8591. + */
  8592. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
  8593. +{
  8594. + int r;
  8595. +
  8596. + if (pkg->epoch > ref_pkg->epoch) {
  8597. + return 1;
  8598. + }
  8599. +
  8600. + if (pkg->epoch < ref_pkg->epoch) {
  8601. + return -1;
  8602. + }
  8603. +
  8604. + r = verrevcmp(pkg->version, ref_pkg->version);
  8605. + if (r) {
  8606. + return r;
  8607. + }
  8608. +
  8609. +#ifdef USE_DEBVERSION
  8610. + r = verrevcmp(pkg->revision, ref_pkg->revision);
  8611. + if (r) {
  8612. + return r;
  8613. + }
  8614. +
  8615. + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
  8616. +#endif
  8617. +
  8618. + return r;
  8619. +}
  8620. +
  8621. +int verrevcmp(const char *val, const char *ref)
  8622. +{
  8623. + int vc, rc;
  8624. + long vl, rl;
  8625. + const char *vp, *rp;
  8626. + const char *vsep, *rsep;
  8627. +
  8628. + if (!val) val= "";
  8629. + if (!ref) ref= "";
  8630. + for (;;) {
  8631. + vp= val; while (*vp && !isdigit(*vp)) vp++;
  8632. + rp= ref; while (*rp && !isdigit(*rp)) rp++;
  8633. + for (;;) {
  8634. + vc= (val == vp) ? 0 : *val++;
  8635. + rc= (ref == rp) ? 0 : *ref++;
  8636. + if (!rc && !vc) break;
  8637. + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
  8638. + if (rc && !isalpha(rc)) rc += 256;
  8639. + if (vc != rc) return vc - rc;
  8640. + }
  8641. + val= vp;
  8642. + ref= rp;
  8643. + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
  8644. + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
  8645. + if (vl != rl) return vl - rl;
  8646. +
  8647. + vc = *val;
  8648. + rc = *ref;
  8649. + vsep = strchr(".-", vc);
  8650. + rsep = strchr(".-", rc);
  8651. + if (vsep && !rsep) return -1;
  8652. + if (!vsep && rsep) return +1;
  8653. +
  8654. + if (!*val && !*ref) return 0;
  8655. + if (!*val) return -1;
  8656. + if (!*ref) return +1;
  8657. + }
  8658. +}
  8659. +
  8660. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
  8661. +{
  8662. + int r;
  8663. +
  8664. + r = pkg_compare_versions(it, ref);
  8665. +
  8666. + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
  8667. + return r <= 0;
  8668. + }
  8669. +
  8670. + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
  8671. + return r >= 0;
  8672. + }
  8673. +
  8674. + if (strcmp(op, "<<") == 0) {
  8675. + return r < 0;
  8676. + }
  8677. +
  8678. + if (strcmp(op, ">>") == 0) {
  8679. + return r > 0;
  8680. + }
  8681. +
  8682. + if (strcmp(op, "=") == 0) {
  8683. + return r == 0;
  8684. + }
  8685. +
  8686. + fprintf(stderr, "unknown operator: %s", op);
  8687. + return 0;
  8688. +}
  8689. +
  8690. +int pkg_name_version_and_architecture_compare(pkg_t *p1, pkg_t *p2)
  8691. +{
  8692. + const pkg_t *a = *(const pkg_t **)p1;
  8693. + const pkg_t *b = *(const pkg_t **)p2;
  8694. + int namecmp;
  8695. + int vercmp;
  8696. + if (!a->name || !b->name) {
  8697. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8698. + a, a->name, b, b->name);
  8699. + return 0;
  8700. + }
  8701. +
  8702. + namecmp = strcmp(a->name, b->name);
  8703. + if (namecmp)
  8704. + return namecmp;
  8705. + vercmp = pkg_compare_versions(a, b);
  8706. + if (vercmp)
  8707. + return vercmp;
  8708. + if (!a->arch_priority || !b->arch_priority) {
  8709. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
  8710. + a, a->arch_priority, b, b->arch_priority);
  8711. + return 0;
  8712. + }
  8713. + if (a->arch_priority > b->arch_priority)
  8714. + return 1;
  8715. + if (a->arch_priority < b->arch_priority)
  8716. + return -1;
  8717. + return 0;
  8718. +}
  8719. +
  8720. +int abstract_pkg_name_compare(abstract_pkg_t *p1, abstract_pkg_t *p2)
  8721. +{
  8722. + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
  8723. + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
  8724. + if (!a->name || !b->name) {
  8725. + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8726. + a, a->name, b, b->name);
  8727. + return 0;
  8728. + }
  8729. + return strcmp(a->name, b->name);
  8730. +}
  8731. +
  8732. +
  8733. +char *pkg_version_str_alloc(pkg_t *pkg)
  8734. +{
  8735. + char *complete_version;
  8736. + char *epoch_str;
  8737. +#ifdef USE_DEBVERSION
  8738. + char *revision_str;
  8739. + char *familiar_revision_str;
  8740. +#endif
  8741. +
  8742. + if (pkg->epoch) {
  8743. + sprintf_alloc(&epoch_str, "%lu:", (unsigned long)pkg->epoch);
  8744. + } else {
  8745. + epoch_str = strdup("");
  8746. + }
  8747. +
  8748. +#ifdef USE_DEBVERSION
  8749. + if (pkg->revision && strlen(pkg->revision)) {
  8750. + sprintf_alloc(&revision_str, "-%s", pkg->revision);
  8751. + } else {
  8752. + revision_str = strdup("");
  8753. + }
  8754. +
  8755. + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
  8756. + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
  8757. + } else {
  8758. + familiar_revision_str = strdup("");
  8759. + }
  8760. +#endif
  8761. +
  8762. +#ifdef USE_DEBVERSION
  8763. + sprintf_alloc(&complete_version, "%s%s%s%s",
  8764. + epoch_str, pkg->version, revision_str, familiar_revision_str);
  8765. +#else
  8766. + sprintf_alloc(&complete_version, "%s%s",
  8767. + epoch_str, pkg->version);
  8768. +#endif
  8769. +
  8770. + free(epoch_str);
  8771. +#ifdef USE_DEBVERSION
  8772. + free(revision_str);
  8773. + free(familiar_revision_str);
  8774. +#endif
  8775. +
  8776. + return complete_version;
  8777. +}
  8778. +
  8779. +str_list_t *pkg_get_installed_files(pkg_t *pkg)
  8780. +{
  8781. + int err;
  8782. + char *list_file_name = NULL;
  8783. + FILE *list_file = NULL;
  8784. + char *line;
  8785. + char *installed_file_name;
  8786. + int rootdirlen;
  8787. +
  8788. + pkg->installed_files_ref_cnt++;
  8789. +
  8790. + if (pkg->installed_files) {
  8791. + return pkg->installed_files;
  8792. + }
  8793. +
  8794. + pkg->installed_files = str_list_alloc();
  8795. + if (pkg->installed_files == NULL) {
  8796. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8797. + return NULL;
  8798. + }
  8799. +
  8800. + /* For uninstalled packages, get the file list firectly from the package.
  8801. + For installed packages, look at the package.list file in the database.
  8802. + */
  8803. + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
  8804. + if (pkg->local_filename == NULL) {
  8805. + return pkg->installed_files;
  8806. + }
  8807. + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
  8808. + file. In other words, change deb_extract so that it can
  8809. + simply return the file list as a char *[] rather than
  8810. + insisting on writing in to a FILE * as it does now. */
  8811. + list_file = tmpfile();
  8812. + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
  8813. + if (err) {
  8814. + fclose(list_file);
  8815. + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
  8816. + __FUNCTION__, pkg->local_filename, strerror(err));
  8817. + return pkg->installed_files;
  8818. + }
  8819. + rewind(list_file);
  8820. + } else {
  8821. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8822. + pkg->dest->info_dir, pkg->name);
  8823. + if (! file_exists(list_file_name)) {
  8824. + free(list_file_name);
  8825. + return pkg->installed_files;
  8826. + }
  8827. +
  8828. + list_file = fopen(list_file_name, "r");
  8829. + if (list_file == NULL) {
  8830. + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
  8831. + list_file_name, strerror(errno));
  8832. + free(list_file_name);
  8833. + return pkg->installed_files;
  8834. + }
  8835. + free(list_file_name);
  8836. + }
  8837. +
  8838. + rootdirlen = strlen( pkg->dest->root_dir );
  8839. + while (1) {
  8840. + char *file_name;
  8841. +
  8842. + line = file_read_line_alloc(list_file);
  8843. + if (line == NULL) {
  8844. + break;
  8845. + }
  8846. + str_chomp(line);
  8847. + file_name = line;
  8848. +
  8849. + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
  8850. + if( strncmp( pkg->dest->root_dir,
  8851. + file_name,
  8852. + rootdirlen ) ) {
  8853. + if (*file_name == '.') {
  8854. + file_name++;
  8855. + }
  8856. + if (*file_name == '/') {
  8857. + file_name++;
  8858. + }
  8859. +
  8860. + /* Freed in pkg_free_installed_files */
  8861. + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
  8862. + } else {
  8863. + // already contains root_dir as header -> ABSOLUTE
  8864. + sprintf_alloc(&installed_file_name, "%s", file_name);
  8865. + }
  8866. + str_list_append(pkg->installed_files, installed_file_name);
  8867. + free(line);
  8868. + }
  8869. +
  8870. + fclose(list_file);
  8871. +
  8872. + return pkg->installed_files;
  8873. +}
  8874. +
  8875. +/* XXX: CLEANUP: This function and it's counterpart,
  8876. + (pkg_get_installed_files), do not match our init/deinit naming
  8877. + convention. Nor the alloc/free convention. But, then again, neither
  8878. + of these conventions currrently fit the way these two functions
  8879. + work. */
  8880. +int pkg_free_installed_files(pkg_t *pkg)
  8881. +{
  8882. + str_list_elt_t *iter;
  8883. +
  8884. + pkg->installed_files_ref_cnt--;
  8885. + if (pkg->installed_files_ref_cnt > 0) {
  8886. + return 0;
  8887. + }
  8888. +
  8889. + if (pkg->installed_files) {
  8890. +
  8891. + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
  8892. + /* malloced in pkg_get_installed_files */
  8893. + free (iter->data);
  8894. + iter->data = NULL;
  8895. + }
  8896. +
  8897. + str_list_deinit(pkg->installed_files);
  8898. + }
  8899. +
  8900. + pkg->installed_files = NULL;
  8901. +
  8902. + return 0;
  8903. +}
  8904. +
  8905. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
  8906. +{
  8907. + int err;
  8908. + char *list_file_name;
  8909. +
  8910. + //I don't think pkg_free_installed_files should be called here. Jamey
  8911. + //pkg_free_installed_files(pkg);
  8912. +
  8913. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8914. + pkg->dest->info_dir, pkg->name);
  8915. + if (!conf->noaction) {
  8916. + err = unlink(list_file_name);
  8917. + free(list_file_name);
  8918. +
  8919. + if (err) {
  8920. + return errno;
  8921. + }
  8922. + }
  8923. + return 0;
  8924. +}
  8925. +
  8926. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
  8927. +{
  8928. + conffile_list_elt_t *iter;
  8929. + conffile_t *conffile;
  8930. +
  8931. + if (pkg == NULL) {
  8932. + return NULL;
  8933. + }
  8934. +
  8935. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8936. + conffile = iter->data;
  8937. +
  8938. + if (strcmp(conffile->name, file_name) == 0) {
  8939. + return conffile;
  8940. + }
  8941. + }
  8942. +
  8943. + return NULL;
  8944. +}
  8945. +
  8946. +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
  8947. + const char *script, const char *args)
  8948. +{
  8949. + int err;
  8950. + char *path;
  8951. + char *cmd;
  8952. +
  8953. + /* XXX: FEATURE: When conf->offline_root is set, we should run the
  8954. + maintainer script within a chroot environment. */
  8955. +
  8956. + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
  8957. + have scripts in pkg->tmp_unpack_dir. */
  8958. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  8959. + if (pkg->dest == NULL) {
  8960. + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
  8961. + __FUNCTION__, pkg->name);
  8962. + return EINVAL;
  8963. + }
  8964. + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
  8965. + } else {
  8966. + if (pkg->tmp_unpack_dir == NULL) {
  8967. + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
  8968. + __FUNCTION__, pkg->name);
  8969. + return EINVAL;
  8970. + }
  8971. + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
  8972. + }
  8973. +
  8974. + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
  8975. + if (conf->noaction) return 0;
  8976. +
  8977. + /* XXX: CLEANUP: There must be a better way to handle maintainer
  8978. + scripts when running with offline_root mode and/or a dest other
  8979. + than '/'. I've been playing around with some clever chroot
  8980. + tricks and I might come up with something workable. */
  8981. + if (conf->offline_root) {
  8982. + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
  8983. + }
  8984. +
  8985. + setenv("PKG_ROOT",
  8986. + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
  8987. +
  8988. + if (! file_exists(path)) {
  8989. + free(path);
  8990. + return 0;
  8991. + }
  8992. +
  8993. + if (conf->offline_root) {
  8994. + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
  8995. + free(path);
  8996. + return 0;
  8997. + }
  8998. +
  8999. + sprintf_alloc(&cmd, "%s %s", path, args);
  9000. + free(path);
  9001. +
  9002. + err = xsystem(cmd);
  9003. + free(cmd);
  9004. +
  9005. + if (err) {
  9006. + fprintf(stderr, "%s script returned status %d\n", script, err);
  9007. + return err;
  9008. + }
  9009. +
  9010. + return 0;
  9011. +}
  9012. +
  9013. +char *pkg_state_want_to_str(pkg_state_want_t sw)
  9014. +{
  9015. + int i;
  9016. +
  9017. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9018. + if (pkg_state_want_map[i].value == sw) {
  9019. + return strdup(pkg_state_want_map[i].str);
  9020. + }
  9021. + }
  9022. +
  9023. + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
  9024. + __FUNCTION__, sw);
  9025. + return strdup("<STATE_WANT_UNKNOWN>");
  9026. +}
  9027. +
  9028. +pkg_state_want_t pkg_state_want_from_str(char *str)
  9029. +{
  9030. + int i;
  9031. +
  9032. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9033. + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
  9034. + return pkg_state_want_map[i].value;
  9035. + }
  9036. + }
  9037. +
  9038. + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
  9039. + __FUNCTION__, str);
  9040. + return SW_UNKNOWN;
  9041. +}
  9042. +
  9043. +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
  9044. +{
  9045. + int i;
  9046. + int len = 3; /* ok\000 is minimum */
  9047. + char *str = NULL;
  9048. +
  9049. + /* clear the temporary flags before converting to string */
  9050. + sf &= SF_NONVOLATILE_FLAGS;
  9051. +
  9052. + if (sf == 0) {
  9053. + return strdup("ok");
  9054. + } else {
  9055. +
  9056. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9057. + if (sf & pkg_state_flag_map[i].value) {
  9058. + len += strlen(pkg_state_flag_map[i].str) + 1;
  9059. + }
  9060. + }
  9061. + str = malloc(len);
  9062. + if ( str == NULL ) {
  9063. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9064. + return NULL;
  9065. + }
  9066. + str[0] = 0;
  9067. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9068. + if (sf & pkg_state_flag_map[i].value) {
  9069. + strcat(str, pkg_state_flag_map[i].str);
  9070. + strcat(str, ",");
  9071. + }
  9072. + }
  9073. + len = strlen(str);
  9074. + str[len-1] = 0; /* squash last comma */
  9075. + return str;
  9076. + }
  9077. +}
  9078. +
  9079. +pkg_state_flag_t pkg_state_flag_from_str(char *str)
  9080. +{
  9081. + int i;
  9082. + int sf = SF_OK;
  9083. +
  9084. + if (strcmp(str, "ok") == 0) {
  9085. + return SF_OK;
  9086. + }
  9087. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9088. + const char *sfname = pkg_state_flag_map[i].str;
  9089. + int sfname_len = strlen(sfname);
  9090. + if (strncmp(str, sfname, sfname_len) == 0) {
  9091. + sf |= pkg_state_flag_map[i].value;
  9092. + str += sfname_len;
  9093. + if (str[0] == ',') {
  9094. + str++;
  9095. + } else {
  9096. + break;
  9097. + }
  9098. + }
  9099. + }
  9100. +
  9101. + return sf;
  9102. +}
  9103. +
  9104. +char *pkg_state_status_to_str(pkg_state_status_t ss)
  9105. +{
  9106. + int i;
  9107. +
  9108. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9109. + if (pkg_state_status_map[i].value == ss) {
  9110. + return strdup(pkg_state_status_map[i].str);
  9111. + }
  9112. + }
  9113. +
  9114. + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
  9115. + __FUNCTION__, ss);
  9116. + return strdup("<STATE_STATUS_UNKNOWN>");
  9117. +}
  9118. +
  9119. +pkg_state_status_t pkg_state_status_from_str(char *str)
  9120. +{
  9121. + int i;
  9122. +
  9123. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9124. + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
  9125. + return pkg_state_status_map[i].value;
  9126. + }
  9127. + }
  9128. +
  9129. + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
  9130. + __FUNCTION__, str);
  9131. + return SS_NOT_INSTALLED;
  9132. +}
  9133. +
  9134. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
  9135. +{
  9136. + nv_pair_list_elt_t *l;
  9137. +
  9138. + if (!pkg->architecture)
  9139. + return 1;
  9140. +
  9141. + l = conf->arch_list.head;
  9142. +
  9143. + while (l) {
  9144. + nv_pair_t *nv = l->data;
  9145. + if (strcmp(nv->name, pkg->architecture) == 0) {
  9146. + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
  9147. + return 1;
  9148. + }
  9149. + l = l->next;
  9150. + }
  9151. +
  9152. + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
  9153. + return 0;
  9154. +}
  9155. +
  9156. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
  9157. +{
  9158. + nv_pair_list_elt_t *l;
  9159. +
  9160. + l = conf->arch_list.head;
  9161. +
  9162. + while (l) {
  9163. + nv_pair_t *nv = l->data;
  9164. + if (strcmp(nv->name, archname) == 0) {
  9165. + int priority = strtol(nv->value, NULL, 0);
  9166. + return priority;
  9167. + }
  9168. + l = l->next;
  9169. + }
  9170. + return 0;
  9171. +}
  9172. +
  9173. +int pkg_info_preinstall_check(ipkg_conf_t *conf)
  9174. +{
  9175. + int i;
  9176. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9177. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  9178. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9179. +
  9180. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
  9181. + pkg_hash_fetch_available(pkg_hash, available_pkgs);
  9182. + /* update arch_priority for each package */
  9183. + for (i = 0; i < available_pkgs->len; i++) {
  9184. + pkg_t *pkg = available_pkgs->pkgs[i];
  9185. + int arch_priority = 1;
  9186. + if (!pkg)
  9187. + continue;
  9188. + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
  9189. + if (pkg->architecture)
  9190. + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
  9191. + else
  9192. + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
  9193. + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
  9194. + pkg->arch_priority = arch_priority;
  9195. + }
  9196. +
  9197. + for (i = 0; i < available_pkgs->len; i++) {
  9198. + pkg_t *pkg = available_pkgs->pkgs[i];
  9199. + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
  9200. + /* clear flags and want for any uninstallable package */
  9201. + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
  9202. + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
  9203. + pkg->state_want = SW_UNKNOWN;
  9204. + pkg->state_flag = 0;
  9205. + }
  9206. + }
  9207. + pkg_vec_free(available_pkgs);
  9208. +
  9209. + /* update the file owner data structure */
  9210. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
  9211. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9212. + for (i = 0; i < installed_pkgs->len; i++) {
  9213. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9214. + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
  9215. + str_list_elt_t *iter;
  9216. + if (installed_files == NULL) {
  9217. + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
  9218. + break;
  9219. + }
  9220. + for (iter = installed_files->head; iter; iter = iter->next) {
  9221. + char *installed_file = iter->data;
  9222. + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
  9223. + file_hash_set_file_owner(conf, installed_file, pkg);
  9224. + }
  9225. + }
  9226. + pkg_vec_free(installed_pkgs);
  9227. +
  9228. + return 0;
  9229. +}
  9230. +
  9231. +struct pkg_write_filelist_data {
  9232. + ipkg_conf_t *conf;
  9233. + pkg_t *pkg;
  9234. + FILE *stream;
  9235. +};
  9236. +
  9237. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
  9238. +{
  9239. + struct pkg_write_filelist_data *data = data_;
  9240. + pkg_t *entry = entry_;
  9241. + if (entry == data->pkg) {
  9242. + fprintf(data->stream, "%s\n", key);
  9243. + }
  9244. +}
  9245. +
  9246. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
  9247. +{
  9248. + struct pkg_write_filelist_data data;
  9249. + char *list_file_name = NULL;
  9250. + int err = 0;
  9251. +
  9252. + if (!pkg) {
  9253. + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
  9254. + return -EINVAL;
  9255. + }
  9256. + ipkg_message(conf, IPKG_INFO,
  9257. + " creating %s.list file\n", pkg->name);
  9258. + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
  9259. + if (!list_file_name) {
  9260. + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
  9261. + return -ENOMEM;
  9262. + }
  9263. + ipkg_message(conf, IPKG_INFO,
  9264. + " creating %s file for pkg %s\n", list_file_name, pkg->name);
  9265. + data.stream = fopen(list_file_name, "w");
  9266. + if (!data.stream) {
  9267. + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
  9268. + list_file_name, strerror(errno));
  9269. + return errno;
  9270. + }
  9271. + data.pkg = pkg;
  9272. + data.conf = conf;
  9273. + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
  9274. + fclose(data.stream);
  9275. + free(list_file_name);
  9276. +
  9277. + return err;
  9278. +}
  9279. +
  9280. +int pkg_write_changed_filelists(ipkg_conf_t *conf)
  9281. +{
  9282. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9283. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9284. + int i;
  9285. + int err;
  9286. + if (conf->noaction)
  9287. + return 0;
  9288. +
  9289. + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
  9290. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9291. + for (i = 0; i < installed_pkgs->len; i++) {
  9292. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9293. + if (pkg->state_flag & SF_FILELIST_CHANGED) {
  9294. + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
  9295. + err = pkg_write_filelist(conf, pkg);
  9296. + if (err)
  9297. + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
  9298. + }
  9299. + }
  9300. + return 0;
  9301. +}
  9302. diff -Nur busybox-1.17.1.orig/archival/libipkg/pkg_depends.c busybox-1.17.1/archival/libipkg/pkg_depends.c
  9303. --- busybox-1.17.1.orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
  9304. +++ busybox-1.17.1/archival/libipkg/pkg_depends.c 2010-07-28 13:07:49.547597626 +0200
  9305. @@ -0,0 +1,1032 @@
  9306. +/* pkg_depends.c - the itsy package management system
  9307. +
  9308. + Steven M. Ayer
  9309. +
  9310. + Copyright (C) 2002 Compaq Computer Corporation
  9311. +
  9312. + This program is free software; you can redistribute it and/or
  9313. + modify it under the terms of the GNU General Public License as
  9314. + published by the Free Software Foundation; either version 2, or (at
  9315. + your option) any later version.
  9316. +
  9317. + This program is distributed in the hope that it will be useful, but
  9318. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9319. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9320. + General Public License for more details.
  9321. +*/
  9322. +
  9323. +#include "ipkg.h"
  9324. +#include <errno.h>
  9325. +#include <ctype.h>
  9326. +
  9327. +#include "pkg.h"
  9328. +#include "ipkg_utils.h"
  9329. +#include "pkg_hash.h"
  9330. +#include "ipkg_message.h"
  9331. +#include "pkg_parse.h"
  9332. +#include "hash_table.h"
  9333. +
  9334. +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
  9335. +static depend_t * depend_init(void);
  9336. +static void depend_deinit(depend_t *d);
  9337. +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
  9338. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
  9339. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
  9340. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg);
  9341. +
  9342. +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
  9343. +{
  9344. + depend_t *depend = (depend_t *)cdata;
  9345. + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
  9346. + return 1;
  9347. + else
  9348. + return 0;
  9349. +}
  9350. +
  9351. +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
  9352. +{
  9353. + depend_t *depend = (depend_t *)cdata;
  9354. +#if 0
  9355. + pkg_t * temp = pkg_new();
  9356. + int comparison;
  9357. + parseVersion(temp, depend->version);
  9358. + comparison = pkg_compare_versions(pkg, temp);
  9359. + free(temp);
  9360. +
  9361. + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
  9362. + __FUNCTION__, pkg->name, pkg->version,
  9363. + depend, depend->constraint, depend->version,
  9364. + comparison, version_constraints_satisfied(depend, pkg));
  9365. +#endif
  9366. + if (version_constraints_satisfied(depend, pkg))
  9367. + return 1;
  9368. + else
  9369. + return 0;
  9370. +}
  9371. +
  9372. +/* returns ndependences or negative error value */
  9373. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
  9374. + pkg_vec_t *unsatisfied, char *** unresolved)
  9375. +{
  9376. + pkg_t * satisfier_entry_pkg;
  9377. + register int i, j, k, l;
  9378. + int count, found;
  9379. + char ** the_lost;
  9380. + abstract_pkg_t * ab_pkg;
  9381. +
  9382. + /*
  9383. + * this is a setup to check for redundant/cyclic dependency checks,
  9384. + * which are marked at the abstract_pkg level
  9385. + */
  9386. + if (!(ab_pkg = pkg->parent)) {
  9387. + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
  9388. + *unresolved = NULL;
  9389. + return 0;
  9390. + }
  9391. + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
  9392. + *unresolved = NULL;
  9393. + return 0;
  9394. + } else {
  9395. + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
  9396. + }
  9397. + /**/
  9398. +
  9399. + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
  9400. + if (!count){
  9401. + *unresolved = NULL;
  9402. + return 0;
  9403. + }
  9404. +
  9405. + the_lost = NULL;
  9406. +
  9407. + /* foreach dependency */
  9408. + for (i = 0; i < count; i++) {
  9409. + compound_depend_t * compound_depend = &pkg->depends[i];
  9410. + depend_t ** possible_satisfiers = compound_depend->possibilities;;
  9411. + found = 0;
  9412. + satisfier_entry_pkg = NULL;
  9413. +
  9414. + if (compound_depend->type == GREEDY_DEPEND) {
  9415. + /* foreach possible satisfier */
  9416. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9417. + /* foreach provided_by, which includes the abstract_pkg itself */
  9418. + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
  9419. + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
  9420. + int nposs = ab_provider_vec->len;
  9421. + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
  9422. + for (l = 0; l < nposs; l++) {
  9423. + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
  9424. + /* if no depends on this one, try the first package that Provides this one */
  9425. + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
  9426. + continue;
  9427. + }
  9428. +
  9429. + /* cruise this possiblity's pkg_vec looking for an installed version */
  9430. + for (k = 0; k < test_vec->len; k++) {
  9431. + pkg_t *pkg_scout = test_vec->pkgs[k];
  9432. + /* not installed, and not already known about? */
  9433. + if ((pkg_scout->state_want != SW_INSTALL)
  9434. + && !pkg_scout->parent->dependencies_checked
  9435. + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
  9436. + char ** newstuff = NULL;
  9437. + int rc;
  9438. + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
  9439. + /* check for not-already-installed dependencies */
  9440. + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
  9441. + pkg_scout,
  9442. + tmp_vec,
  9443. + &newstuff);
  9444. + if (newstuff == NULL) {
  9445. + int ok = 1;
  9446. + for (i = 0; i < rc; i++) {
  9447. + pkg_t *p = tmp_vec->pkgs[i];
  9448. + if (p->state_want == SW_INSTALL)
  9449. + continue;
  9450. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
  9451. + ok = 0;
  9452. + break;
  9453. + }
  9454. + pkg_vec_free (tmp_vec);
  9455. + if (ok) {
  9456. + /* mark this one for installation */
  9457. + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
  9458. + pkg_vec_insert(unsatisfied, pkg_scout);
  9459. + }
  9460. + } else {
  9461. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
  9462. + free (newstuff);
  9463. + }
  9464. + }
  9465. + }
  9466. + }
  9467. + }
  9468. +
  9469. + continue;
  9470. + }
  9471. +
  9472. + /* foreach possible satisfier, look for installed package */
  9473. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9474. + /* foreach provided_by, which includes the abstract_pkg itself */
  9475. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9476. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9477. + pkg_t *satisfying_pkg =
  9478. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9479. + pkg_installed_and_constraint_satisfied,
  9480. + dependence_to_satisfy, 1);
  9481. + /* Being that I can't test constraing in pkg_hash, I will test it here */
  9482. + if (satisfying_pkg != NULL) {
  9483. + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9484. + satisfying_pkg = NULL;
  9485. + }
  9486. + }
  9487. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
  9488. + if (satisfying_pkg != NULL) {
  9489. + found = 1;
  9490. + break;
  9491. + }
  9492. +
  9493. + }
  9494. + /* if nothing installed matches, then look for uninstalled satisfier */
  9495. + if (!found) {
  9496. + /* foreach possible satisfier, look for installed package */
  9497. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9498. + /* foreach provided_by, which includes the abstract_pkg itself */
  9499. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9500. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9501. + pkg_t *satisfying_pkg =
  9502. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9503. + pkg_constraint_satisfied,
  9504. + dependence_to_satisfy, 1);
  9505. + /* Being that I can't test constraing in pkg_hash, I will test it here too */
  9506. + if (satisfying_pkg != NULL) {
  9507. + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9508. + satisfying_pkg = NULL;
  9509. + }
  9510. + }
  9511. +
  9512. + /* user request overrides package recommendation */
  9513. + if (satisfying_pkg != NULL
  9514. + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
  9515. + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
  9516. + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
  9517. + pkg->name, satisfying_pkg->name);
  9518. + continue;
  9519. + }
  9520. +
  9521. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
  9522. + if (satisfying_pkg != NULL) {
  9523. + satisfier_entry_pkg = satisfying_pkg;
  9524. + break;
  9525. + }
  9526. + }
  9527. + }
  9528. +
  9529. + /* we didn't find one, add something to the unsatisfied vector */
  9530. + if (!found) {
  9531. + if (!satisfier_entry_pkg) {
  9532. + /* failure to meet recommendations is not an error */
  9533. + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
  9534. + the_lost = add_unresolved_dep(pkg, the_lost, i);
  9535. + else
  9536. + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
  9537. + pkg->name, compound_depend->possibilities[0]->pkg->name);
  9538. + }
  9539. + else {
  9540. + if (compound_depend->type == SUGGEST) {
  9541. + /* just mention it politely */
  9542. + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
  9543. + pkg->name, satisfier_entry_pkg->name);
  9544. + } else {
  9545. + char ** newstuff = NULL;
  9546. +
  9547. + if (satisfier_entry_pkg != pkg &&
  9548. + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
  9549. + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
  9550. + pkg_hash_fetch_unsatisfied_dependencies(conf,
  9551. + satisfier_entry_pkg,
  9552. + unsatisfied,
  9553. + &newstuff);
  9554. + the_lost = merge_unresolved(the_lost, newstuff);
  9555. + }
  9556. + }
  9557. + }
  9558. + }
  9559. + }
  9560. + *unresolved = the_lost;
  9561. +
  9562. + return unsatisfied->len;
  9563. +}
  9564. +
  9565. +/*checking for conflicts !in replaces
  9566. + If a packages conflicts with another but is also replacing it, I should not consider it a
  9567. + really conflicts
  9568. + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
  9569. +*/
  9570. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
  9571. +{
  9572. + int i ;
  9573. + int replaces_count = pkg->replaces_count;
  9574. + abstract_pkg_t **replaces;
  9575. +
  9576. + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
  9577. + return 0;
  9578. +
  9579. + replaces = pkg->replaces;
  9580. +
  9581. + for (i = 0; i < replaces_count; i++) {
  9582. + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
  9583. + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
  9584. + return 1;
  9585. + }
  9586. + }
  9587. + return 0;
  9588. +
  9589. +}
  9590. +
  9591. +
  9592. +/* Abhaya: added support for conflicts */
  9593. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg)
  9594. +{
  9595. + pkg_vec_t * installed_conflicts, * test_vec;
  9596. + compound_depend_t * conflicts;
  9597. + depend_t ** possible_satisfiers;
  9598. + depend_t * possible_satisfier;
  9599. + register int i, j, k;
  9600. + int count;
  9601. + abstract_pkg_t * ab_pkg;
  9602. + pkg_t **pkg_scouts;
  9603. + pkg_t *pkg_scout;
  9604. +
  9605. + /*
  9606. + * this is a setup to check for redundant/cyclic dependency checks,
  9607. + * which are marked at the abstract_pkg level
  9608. + */
  9609. + if(!(ab_pkg = pkg->parent)){
  9610. + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
  9611. + return (pkg_vec_t *)NULL;
  9612. + }
  9613. +
  9614. + conflicts = pkg->conflicts;
  9615. + if(!conflicts){
  9616. + return (pkg_vec_t *)NULL;
  9617. + }
  9618. + installed_conflicts = pkg_vec_alloc();
  9619. +
  9620. + count = pkg->conflicts_count;
  9621. +
  9622. +
  9623. +
  9624. + /* foreach conflict */
  9625. + for(i = 0; i < pkg->conflicts_count; i++){
  9626. +
  9627. + possible_satisfiers = conflicts->possibilities;
  9628. +
  9629. + /* foreach possible satisfier */
  9630. + for(j = 0; j < conflicts->possibility_count; j++){
  9631. + possible_satisfier = possible_satisfiers[j];
  9632. + if (!possible_satisfier)
  9633. + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
  9634. + if (!possible_satisfier->pkg)
  9635. + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
  9636. + test_vec = possible_satisfier->pkg->pkgs;
  9637. + if (test_vec) {
  9638. + /* pkg_vec found, it is an actual package conflict
  9639. + * cruise this possiblity's pkg_vec looking for an installed version */
  9640. + pkg_scouts = test_vec->pkgs;
  9641. + for(k = 0; k < test_vec->len; k++){
  9642. + pkg_scout = pkg_scouts[k];
  9643. + if (!pkg_scout) {
  9644. + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
  9645. + continue;
  9646. + }
  9647. + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
  9648. + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
  9649. + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
  9650. + pkg_vec_insert(installed_conflicts, pkg_scout);
  9651. + }
  9652. + }
  9653. + }
  9654. + }
  9655. + }
  9656. + conflicts++;
  9657. + }
  9658. +
  9659. + if (installed_conflicts->len)
  9660. + return installed_conflicts;
  9661. + pkg_vec_free(installed_conflicts);
  9662. + return (pkg_vec_t *)NULL;
  9663. +}
  9664. +
  9665. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
  9666. +{
  9667. + pkg_t * temp;
  9668. + int comparison;
  9669. +
  9670. + if(depends->constraint == NONE)
  9671. + return 1;
  9672. +
  9673. + temp = pkg_new();
  9674. +
  9675. + parseVersion(temp, depends->version);
  9676. +
  9677. + comparison = pkg_compare_versions(pkg, temp);
  9678. +
  9679. + free(temp);
  9680. +
  9681. + if((depends->constraint == EARLIER) &&
  9682. + (comparison < 0))
  9683. + return 1;
  9684. + else if((depends->constraint == LATER) &&
  9685. + (comparison > 0))
  9686. + return 1;
  9687. + else if(comparison == 0)
  9688. + return 1;
  9689. + else if((depends->constraint == LATER_EQUAL) &&
  9690. + (comparison >= 0))
  9691. + return 1;
  9692. + else if((depends->constraint == EARLIER_EQUAL) &&
  9693. + (comparison <= 0))
  9694. + return 1;
  9695. +
  9696. + return 0;
  9697. +}
  9698. +
  9699. +int pkg_dependence_satisfiable(depend_t *depend)
  9700. +{
  9701. + abstract_pkg_t *apkg = depend->pkg;
  9702. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9703. + int n_providers = provider_apkgs->len;
  9704. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9705. + pkg_vec_t *pkg_vec;
  9706. + int n_pkgs ;
  9707. + int i;
  9708. + int j;
  9709. +
  9710. + for (i = 0; i < n_providers; i++) {
  9711. + abstract_pkg_t *papkg = apkgs[i];
  9712. + pkg_vec = papkg->pkgs;
  9713. + if (pkg_vec) {
  9714. + n_pkgs = pkg_vec->len;
  9715. + for (j = 0; j < n_pkgs; j++) {
  9716. + pkg_t *pkg = pkg_vec->pkgs[j];
  9717. + if (version_constraints_satisfied(depend, pkg)) {
  9718. + return 1;
  9719. + }
  9720. + }
  9721. + }
  9722. + }
  9723. + return 0;
  9724. +}
  9725. +
  9726. +int pkg_dependence_satisfied(depend_t *depend)
  9727. +{
  9728. + abstract_pkg_t *apkg = depend->pkg;
  9729. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9730. + int n_providers = provider_apkgs->len;
  9731. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9732. + int i;
  9733. + int n_pkgs;
  9734. + int j;
  9735. +
  9736. + for (i = 0; i < n_providers; i++) {
  9737. + abstract_pkg_t *papkg = apkgs[i];
  9738. + pkg_vec_t *pkg_vec = papkg->pkgs;
  9739. + if (pkg_vec) {
  9740. + n_pkgs = pkg_vec->len;
  9741. + for (j = 0; j < n_pkgs; j++) {
  9742. + pkg_t *pkg = pkg_vec->pkgs[j];
  9743. + if (version_constraints_satisfied(depend, pkg)) {
  9744. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
  9745. + return 1;
  9746. + }
  9747. + }
  9748. + }
  9749. + }
  9750. + return 0;
  9751. +}
  9752. +
  9753. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
  9754. +{
  9755. + register int i;
  9756. + pkg_t ** pkgs = vec->pkgs;
  9757. +
  9758. + for(i = 0; i < vec->len; i++)
  9759. + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
  9760. + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
  9761. + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
  9762. + return 1;
  9763. + return 0;
  9764. +}
  9765. +
  9766. +
  9767. +#ifdef DeadCode
  9768. +/**
  9769. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  9770. + * the same abstract package and 0 otherwise.
  9771. + */
  9772. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
  9773. +{
  9774. + abstract_pkg_t **provides = pkg->provides;
  9775. + int provides_count = pkg->provides_count;
  9776. + abstract_pkg_t **replacee_provides = replacee->provides;
  9777. + int replacee_provides_count = replacee->provides_count;
  9778. + int i, j;
  9779. + for (i = 0; i < provides_count; i++) {
  9780. + abstract_pkg_t *apkg = provides[i];
  9781. + for (j = 0; j < replacee_provides_count; j++) {
  9782. + abstract_pkg_t *replacee_apkg = replacee_provides[i];
  9783. + if (apkg == replacee_apkg)
  9784. + return 1;
  9785. + }
  9786. + }
  9787. + return 0;
  9788. +}
  9789. +#endif
  9790. +
  9791. +/**
  9792. + * pkg_provides_abstract returns 1 if pkg->provides contains providee
  9793. + * and 0 otherwise.
  9794. + */
  9795. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
  9796. +{
  9797. + abstract_pkg_t **provides = pkg->provides;
  9798. + int provides_count = pkg->provides_count;
  9799. + int i;
  9800. + for (i = 0; i < provides_count; i++) {
  9801. + if (provides[i] == providee)
  9802. + return 1;
  9803. + }
  9804. + return 0;
  9805. +}
  9806. +
  9807. +/**
  9808. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  9809. + * otherwise.
  9810. + */
  9811. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
  9812. +{
  9813. + abstract_pkg_t **replaces = pkg->replaces;
  9814. + int replaces_count = pkg->replaces_count;
  9815. + /* abstract_pkg_t **replacee_provides = pkg->provides;
  9816. + int replacee_provides_count = pkg->provides_count; */
  9817. + int i, j;
  9818. + for (i = 0; i < replaces_count; i++) {
  9819. + abstract_pkg_t *abstract_replacee = replaces[i];
  9820. + for (j = 0; j < replaces_count; j++) {
  9821. + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
  9822. + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
  9823. + if (replacee->provides[j] == abstract_replacee)
  9824. + return 1;
  9825. + }
  9826. + }
  9827. + return 0;
  9828. +}
  9829. +
  9830. +
  9831. +/**
  9832. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
  9833. + * otherwise.
  9834. + */
  9835. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
  9836. +{
  9837. + compound_depend_t *conflicts = pkg->conflicts;
  9838. + int conflicts_count = pkg->conflicts_count;
  9839. + int i, j;
  9840. + for (i = 0; i < conflicts_count; i++) {
  9841. + int possibility_count = conflicts[i].possibility_count;
  9842. + struct depend **possibilities = conflicts[i].possibilities;
  9843. + for (j = 0; j < possibility_count; j++) {
  9844. + if (possibilities[j]->pkg == conflictee) {
  9845. + return 1;
  9846. + }
  9847. + }
  9848. + }
  9849. + return 0;
  9850. +}
  9851. +
  9852. +/**
  9853. + * pkg_conflicts returns 1 if pkg->conflicts contains one of
  9854. + * conflictee's provides and 0 otherwise.
  9855. + */
  9856. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
  9857. +{
  9858. + compound_depend_t *conflicts = pkg->conflicts;
  9859. + int conflicts_count = pkg->conflicts_count;
  9860. + abstract_pkg_t **conflictee_provides = conflictee->provides;
  9861. + int conflictee_provides_count = conflictee->provides_count;
  9862. + int i, j, k;
  9863. + int possibility_count;
  9864. + struct depend **possibilities;
  9865. + abstract_pkg_t *possibility ;
  9866. +
  9867. + for (i = 0; i < conflicts_count; i++) {
  9868. + possibility_count = conflicts[i].possibility_count;
  9869. + possibilities = conflicts[i].possibilities;
  9870. + for (j = 0; j < possibility_count; j++) {
  9871. + possibility = possibilities[j]->pkg;
  9872. + for (k = 0; k < conflictee_provides_count; k++) {
  9873. + if (possibility == conflictee_provides[k]) {
  9874. + return 1;
  9875. + }
  9876. + }
  9877. + }
  9878. + }
  9879. + return 0;
  9880. +}
  9881. +
  9882. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
  9883. +{
  9884. + int oldlen = 0, newlen = 0;
  9885. + char ** result;
  9886. + register int i, j;
  9887. +
  9888. + if(!newstuff)
  9889. + return oldstuff;
  9890. +
  9891. + while(oldstuff && oldstuff[oldlen]) oldlen++;
  9892. + while(newstuff && newstuff[newlen]) newlen++;
  9893. +
  9894. + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
  9895. + if (result == NULL) {
  9896. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9897. + return NULL;
  9898. + }
  9899. +
  9900. + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
  9901. + *(result + i) = *(newstuff + j);
  9902. +
  9903. + *(result + i) = NULL;
  9904. +
  9905. + return result;
  9906. +}
  9907. +
  9908. +/*
  9909. + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
  9910. + * this is null terminated, no count is carried around
  9911. + */
  9912. +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
  9913. +{
  9914. + int count;
  9915. + char ** resized;
  9916. + char *depend_str = pkg_depend_str(pkg, ref_ndx);
  9917. +
  9918. + count = 0;
  9919. + while(the_lost && the_lost[count]) count++;
  9920. +
  9921. + count++; /* need one to hold the null */
  9922. + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
  9923. + if (resized == NULL) {
  9924. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9925. + return NULL;
  9926. + }
  9927. + resized[count - 1] = strdup(depend_str);
  9928. + resized[count] = NULL;
  9929. +
  9930. + return resized;
  9931. +}
  9932. +
  9933. +void printDepends(pkg_t * pkg)
  9934. +{
  9935. + register int i, j;
  9936. + compound_depend_t * depend;
  9937. + int count;
  9938. +
  9939. + count = pkg->pre_depends_count + pkg->depends_count;
  9940. +
  9941. + depend = pkg->depends;
  9942. + if(!depend){
  9943. + fprintf(stderr, "Depends pointer is NULL\n");
  9944. + return;
  9945. + }
  9946. + for(i = 0; i < count; i++){
  9947. + fprintf(stderr, "%s has %d possibilities:\n",
  9948. + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
  9949. + depend->possibility_count);
  9950. + for(j = 0; j < depend->possibility_count; j++)
  9951. + fprintf(stderr, "\t%s version %s (%d)\n",
  9952. + depend->possibilities[j]->pkg->name,
  9953. + depend->possibilities[j]->version,
  9954. + depend->possibilities[j]->constraint);
  9955. + depend++;
  9956. + }
  9957. +}
  9958. +
  9959. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  9960. +{
  9961. + register int i, j;
  9962. +
  9963. + /* every pkg provides itself */
  9964. + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
  9965. +
  9966. + if (!pkg->provides_count)
  9967. + return 0;
  9968. +
  9969. + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
  9970. + if (pkg->provides == NULL) {
  9971. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9972. + return -1 ;
  9973. + }
  9974. + pkg->provides[0] = ab_pkg;
  9975. +
  9976. + // if (strcmp(ab_pkg->name, pkg->name))
  9977. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  9978. +
  9979. + for(i = 0; i < pkg->provides_count; i++){
  9980. + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
  9981. +
  9982. + pkg->provides[i+1] = provided_abpkg;
  9983. +
  9984. + j = 0;
  9985. + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
  9986. + }
  9987. + return 0;
  9988. +}
  9989. +
  9990. +/* Abhaya: added conflicts support */
  9991. +int buildConflicts(hash_table_t * hash, pkg_t * pkg)
  9992. +{
  9993. + register int i;
  9994. + compound_depend_t * conflicts;
  9995. +
  9996. + if (!pkg->conflicts_count)
  9997. + return 0;
  9998. +
  9999. + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
  10000. + pkg->conflicts_count);
  10001. + if (conflicts == NULL) {
  10002. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10003. + return -1;
  10004. + }
  10005. + for (i = 0; i < pkg->conflicts_count; i++) {
  10006. + conflicts->type = CONFLICTS;
  10007. + parseDepends(conflicts, hash,
  10008. + pkg->conflicts_str[i]);
  10009. +#if 0
  10010. + for (j = 0; j < conflicts->possibility_count; j++) {
  10011. + depend_t *possibility = conflicts->possibilities[j];
  10012. + abstract_pkg_t *conflicting_apkg = possibility->pkg;
  10013. + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
  10014. + }
  10015. +#endif
  10016. + conflicts++;
  10017. + }
  10018. + return 0;
  10019. +}
  10020. +
  10021. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10022. +{
  10023. + register int i, j;
  10024. +
  10025. + if (!pkg->replaces_count)
  10026. + return 0;
  10027. +
  10028. + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
  10029. + if (pkg->replaces == NULL) {
  10030. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10031. + return -1;
  10032. + }
  10033. +
  10034. + // if (strcmp(ab_pkg->name, pkg->name))
  10035. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10036. +
  10037. + for(i = 0; i < pkg->replaces_count; i++){
  10038. + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
  10039. +
  10040. + pkg->replaces[i] = old_abpkg;
  10041. +
  10042. + j = 0;
  10043. + if (!old_abpkg->replaced_by)
  10044. + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
  10045. + if ( old_abpkg->replaced_by == NULL ){
  10046. + return -1;
  10047. + }
  10048. + /* if a package pkg both replaces and conflicts old_abpkg,
  10049. + * then add it to the replaced_by vector so that old_abpkg
  10050. + * will be upgraded to ab_pkg automatically */
  10051. + if (pkg_conflicts_abstract(pkg, old_abpkg))
  10052. + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
  10053. + }
  10054. + return 0;
  10055. +}
  10056. +
  10057. +int buildDepends(hash_table_t * hash, pkg_t * pkg)
  10058. +{
  10059. + int count;
  10060. + register int i;
  10061. + compound_depend_t * depends;
  10062. +
  10063. + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
  10064. + return 0;
  10065. +
  10066. + if (0 && pkg->pre_depends_count)
  10067. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10068. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10069. + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
  10070. + if (depends == NULL) {
  10071. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10072. + return -1;
  10073. + }
  10074. +
  10075. +
  10076. + for(i = 0; i < pkg->pre_depends_count; i++){
  10077. + parseDepends(depends, hash, pkg->pre_depends_str[i]);
  10078. + if (0 && pkg->pre_depends_count)
  10079. + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
  10080. + pkg->pre_depends_str[i], depends, depends->possibility_count);
  10081. + depends->type = PREDEPEND;
  10082. + depends++;
  10083. + }
  10084. +
  10085. + for(i = 0; i < pkg->recommends_count; i++){
  10086. + parseDepends(depends, hash, pkg->recommends_str[i]);
  10087. + if (0 && pkg->recommends_count)
  10088. + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
  10089. + pkg->recommends_str[i], depends, depends->possibility_count);
  10090. + depends->type = RECOMMEND;
  10091. + depends++;
  10092. + }
  10093. +
  10094. + for(i = 0; i < pkg->suggests_count; i++){
  10095. + parseDepends(depends, hash, pkg->suggests_str[i]);
  10096. + if (0 && pkg->suggests_count)
  10097. + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
  10098. + pkg->suggests_str[i], depends, depends->possibility_count);
  10099. + depends->type = SUGGEST;
  10100. + depends++;
  10101. + }
  10102. +
  10103. + for(i = 0; i < pkg->depends_count; i++){
  10104. + parseDepends(depends, hash, pkg->depends_str[i]);
  10105. + if (0 && pkg->depends_count)
  10106. + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
  10107. + pkg->depends_str[i], depends, depends->possibility_count);
  10108. + depends++;
  10109. + }
  10110. + return 0;
  10111. +}
  10112. +
  10113. +/*
  10114. + * pkg_depend_string: returns the depends string specified by index_.
  10115. + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
  10116. + * [0,npredepends) -> returns pre_depends_str[index_]
  10117. + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index_]
  10118. + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index_]
  10119. + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index_]
  10120. + */
  10121. +char *pkg_depend_str(pkg_t *pkg, int index_)
  10122. +{
  10123. + if (index_ < pkg->pre_depends_count) {
  10124. + return pkg->pre_depends_str[index_];
  10125. + }
  10126. + index_ -= pkg->pre_depends_count;
  10127. +
  10128. + if (index_ < pkg->recommends_count) {
  10129. + return pkg->recommends_str[index_];
  10130. + }
  10131. + index_ -= pkg->recommends_count;
  10132. +
  10133. + if (index_ < pkg->suggests_count) {
  10134. + return pkg->suggests_str[index_];
  10135. + }
  10136. + index_ -= pkg->suggests_count;
  10137. +
  10138. + if (index_ < pkg->depends_count) {
  10139. + return pkg->depends_str[index_];
  10140. + }
  10141. + fprintf(stderr, "pkg_depend_str: index_ %d out of range for pkg=%s\n", index_, pkg->name);
  10142. + return NULL;
  10143. +}
  10144. +
  10145. +void freeDepends(pkg_t *pkg)
  10146. +{
  10147. + int i;
  10148. +
  10149. + if (pkg == NULL || pkg->depends == NULL) {
  10150. + return;
  10151. + }
  10152. +
  10153. + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
  10154. + for (i=0; i < pkg->depends->possibility_count; i++) {
  10155. + depend_deinit(pkg->depends->possibilities[i]);
  10156. + }
  10157. + free(pkg->depends->possibilities);
  10158. + free(pkg->depends);
  10159. + pkg->depends = NULL;
  10160. +}
  10161. +
  10162. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
  10163. +{
  10164. + compound_depend_t * depends;
  10165. + int count, othercount;
  10166. + register int i, j;
  10167. + abstract_pkg_t * ab_depend;
  10168. + abstract_pkg_t ** temp;
  10169. +
  10170. + count = pkg->pre_depends_count + pkg->depends_count;
  10171. + depends = pkg->depends;
  10172. +
  10173. + if (0 && pkg->pre_depends_count)
  10174. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10175. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10176. + for (i = 0; i < count; i++) {
  10177. + if (0 && pkg->pre_depends_count)
  10178. + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
  10179. + for (j = 0; j < depends->possibility_count; j++){
  10180. + ab_depend = depends->possibilities[j]->pkg;
  10181. + if(!ab_depend->depended_upon_by)
  10182. + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
  10183. +
  10184. + temp = ab_depend->depended_upon_by;
  10185. + othercount = 1;
  10186. + while(*temp){
  10187. + temp++;
  10188. + othercount++;
  10189. + }
  10190. + *temp = ab_pkg;
  10191. +
  10192. + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
  10193. + (othercount + 1) * sizeof(abstract_pkg_t *));
  10194. + /* the array may have moved */
  10195. + temp = ab_depend->depended_upon_by + othercount;
  10196. + *temp = NULL;
  10197. + }
  10198. + depends++;
  10199. + }
  10200. +}
  10201. +
  10202. +static depend_t * depend_init(void)
  10203. +{
  10204. + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
  10205. + if ( d==NULL ){
  10206. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10207. + return NULL;
  10208. + }
  10209. + d->constraint = NONE;
  10210. + d->version = NULL;
  10211. + d->pkg = NULL;
  10212. +
  10213. + return d;
  10214. +}
  10215. +
  10216. +static void depend_deinit(depend_t *d)
  10217. +{
  10218. + free(d);
  10219. +}
  10220. +
  10221. +static int parseDepends(compound_depend_t *compound_depend,
  10222. + hash_table_t * hash, char * depend_str)
  10223. +{
  10224. + char * pkg_name, buffer[2048];
  10225. + int num_of_ors = 0;
  10226. + register int i;
  10227. + register char * src, * dest;
  10228. + depend_t ** possibilities;
  10229. +
  10230. + /* first count the number of ored possibilities for satisfying dependency */
  10231. + src = depend_str;
  10232. + while(*src)
  10233. + if(*src++ == '|')
  10234. + num_of_ors++;
  10235. +
  10236. + compound_depend->type = DEPEND;
  10237. +
  10238. + compound_depend->possibility_count = num_of_ors + 1;
  10239. + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
  10240. + if (!possibilities)
  10241. + return -ENOMEM;
  10242. + compound_depend->possibilities = possibilities;
  10243. +
  10244. + src = depend_str;
  10245. + for(i = 0; i < num_of_ors + 1; i++){
  10246. + possibilities[i] = depend_init();
  10247. + if (!possibilities[i])
  10248. + return -ENOMEM;
  10249. + /* gobble up just the name first */
  10250. + dest = buffer;
  10251. + while(*src &&
  10252. + !isspace(*src) &&
  10253. + (*src != '(') &&
  10254. + (*src != '*') &&
  10255. + (*src != '|'))
  10256. + *dest++ = *src++;
  10257. + *dest = '\0';
  10258. + pkg_name = trim_alloc(buffer);
  10259. + if (pkg_name == NULL )
  10260. + return -ENOMEM;
  10261. +
  10262. + /* now look at possible version info */
  10263. +
  10264. + /* skip to next chars */
  10265. + if(isspace(*src))
  10266. + while(*src && isspace(*src)) src++;
  10267. +
  10268. + /* extract constraint and version */
  10269. + if(*src == '('){
  10270. + src++;
  10271. + if(!strncmp(src, "<<", 2)){
  10272. + possibilities[i]->constraint = EARLIER;
  10273. + src += 2;
  10274. + }
  10275. + else if(!strncmp(src, "<=", 2)){
  10276. + possibilities[i]->constraint = EARLIER_EQUAL;
  10277. + src += 2;
  10278. + }
  10279. + else if(!strncmp(src, ">=", 2)){
  10280. + possibilities[i]->constraint = LATER_EQUAL;
  10281. + src += 2;
  10282. + }
  10283. + else if(!strncmp(src, ">>", 2)){
  10284. + possibilities[i]->constraint = LATER;
  10285. + src += 2;
  10286. + }
  10287. + else if(!strncmp(src, "=", 1)){
  10288. + possibilities[i]->constraint = EQUAL;
  10289. + src++;
  10290. + }
  10291. + /* should these be here to support deprecated designations; dpkg does */
  10292. + else if(!strncmp(src, "<", 1)){
  10293. + possibilities[i]->constraint = EARLIER_EQUAL;
  10294. + src++;
  10295. + }
  10296. + else if(!strncmp(src, ">", 1)){
  10297. + possibilities[i]->constraint = LATER_EQUAL;
  10298. + src++;
  10299. + }
  10300. +
  10301. + /* now we have any constraint, pass space to version string */
  10302. + while(isspace(*src)) src++;
  10303. +
  10304. + /* this would be the version string */
  10305. + dest = buffer;
  10306. + while(*src && *src != ')')
  10307. + *dest++ = *src++;
  10308. + *dest = '\0';
  10309. +
  10310. + possibilities[i]->version = trim_alloc(buffer);
  10311. + /* fprintf(stderr, "let's print the depends version string:");
  10312. + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
  10313. + if (possibilities[i]->version == NULL )
  10314. + return -ENOMEM;
  10315. +
  10316. +
  10317. + }
  10318. + /* hook up the dependency to its abstract pkg */
  10319. + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
  10320. +
  10321. + free(pkg_name);
  10322. +
  10323. + /* now get past the ) and any possible | chars */
  10324. + while(*src &&
  10325. + (isspace(*src) ||
  10326. + (*src == ')') ||
  10327. + (*src == '|')))
  10328. + src++;
  10329. + if (*src == '*')
  10330. + {
  10331. + compound_depend->type = GREEDY_DEPEND;
  10332. + src++;
  10333. + }
  10334. + }
  10335. +
  10336. + return 0;
  10337. +}
  10338. diff -Nur busybox-1.17.1.orig/archival/libipkg/pkg_depends.h busybox-1.17.1/archival/libipkg/pkg_depends.h
  10339. --- busybox-1.17.1.orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
  10340. +++ busybox-1.17.1/archival/libipkg/pkg_depends.h 2010-07-28 13:07:49.547597626 +0200
  10341. @@ -0,0 +1,105 @@
  10342. +/* pkg_depends.h - the itsy package management system
  10343. +
  10344. + Steven M. Ayer
  10345. +
  10346. + Copyright (C) 2002 Compaq Computer Corporation
  10347. +
  10348. + This program is free software; you can redistribute it and/or
  10349. + modify it under the terms of the GNU General Public License as
  10350. + published by the Free Software Foundation; either version 2, or (at
  10351. + your option) any later version.
  10352. +
  10353. + This program is distributed in the hope that it will be useful, but
  10354. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10355. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10356. + General Public License for more details.
  10357. +*/
  10358. +
  10359. +#ifndef PKG_DEPENDS_H
  10360. +#define PKG_DEPENDS_H
  10361. +
  10362. +#include "pkg.h"
  10363. +#include "pkg_hash.h"
  10364. +
  10365. +enum depend_type {
  10366. + PREDEPEND,
  10367. + DEPEND,
  10368. + CONFLICTS,
  10369. + GREEDY_DEPEND,
  10370. + RECOMMEND,
  10371. + SUGGEST
  10372. +};
  10373. +typedef enum depend_type depend_type_t;
  10374. +
  10375. +enum version_constraint {
  10376. + NONE,
  10377. + EARLIER,
  10378. + EARLIER_EQUAL,
  10379. + EQUAL,
  10380. + LATER_EQUAL,
  10381. + LATER
  10382. +};
  10383. +typedef enum version_constraint version_constraint_t;
  10384. +
  10385. +struct depend{
  10386. + version_constraint_t constraint;
  10387. + char * version;
  10388. + abstract_pkg_t * pkg;
  10389. +};
  10390. +typedef struct depend depend_t;
  10391. +
  10392. +struct compound_depend{
  10393. + depend_type_t type;
  10394. + int possibility_count;
  10395. + struct depend ** possibilities;
  10396. +};
  10397. +typedef struct compound_depend compound_depend_t;
  10398. +
  10399. +#include "hash_table.h"
  10400. +
  10401. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10402. +int buildConflicts(hash_table_t * hash, pkg_t * pkg);
  10403. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10404. +int buildDepends(hash_table_t * hash, pkg_t * pkg);
  10405. +
  10406. +/**
  10407. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10408. + * the same abstract package and 0 otherwise.
  10409. + */
  10410. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
  10411. +
  10412. +/**
  10413. + * pkg_provides returns 1 if pkg->provides contains providee and 0
  10414. + * otherwise.
  10415. + */
  10416. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
  10417. +
  10418. +/**
  10419. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10420. + * otherwise.
  10421. + */
  10422. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
  10423. +
  10424. +/**
  10425. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
  10426. + * otherwise.
  10427. + */
  10428. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
  10429. +
  10430. +/**
  10431. + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
  10432. + * otherwise.
  10433. + */
  10434. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
  10435. +
  10436. +char *pkg_depend_str(pkg_t *pkg, int index_);
  10437. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
  10438. +void freeDepends(pkg_t *pkg);
  10439. +void printDepends(pkg_t * pkg);
  10440. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
  10441. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
  10442. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
  10443. +int pkg_dependence_satisfiable(depend_t *depend);
  10444. +int pkg_dependence_satisfied(depend_t *depend);
  10445. +
  10446. +#endif
  10447. diff -Nur busybox-1.17.1.orig/archival/libipkg/pkg_dest.c busybox-1.17.1/archival/libipkg/pkg_dest.c
  10448. --- busybox-1.17.1.orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
  10449. +++ busybox-1.17.1/archival/libipkg/pkg_dest.c 2010-07-28 13:07:49.551597019 +0200
  10450. @@ -0,0 +1,92 @@
  10451. +/* pkg_dest.c - the itsy package management system
  10452. +
  10453. + Carl D. Worth
  10454. +
  10455. + Copyright (C) 2001 University of Southern California
  10456. +
  10457. + This program is free software; you can redistribute it and/or
  10458. + modify it under the terms of the GNU General Public License as
  10459. + published by the Free Software Foundation; either version 2, or (at
  10460. + your option) any later version.
  10461. +
  10462. + This program is distributed in the hope that it will be useful, but
  10463. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10464. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10465. + General Public License for more details.
  10466. +*/
  10467. +
  10468. +#include "ipkg.h"
  10469. +
  10470. +#include "pkg_dest.h"
  10471. +#include "file_util.h"
  10472. +#include "str_util.h"
  10473. +#include "sprintf_alloc.h"
  10474. +
  10475. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
  10476. +{
  10477. + dest->name = strdup(name);
  10478. +
  10479. + /* Guarantee that dest->root_dir ends with a '/' */
  10480. + if (str_ends_with(root_dir, "/")) {
  10481. + dest->root_dir = strdup(root_dir);
  10482. + } else {
  10483. + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
  10484. + }
  10485. + file_mkdir_hier(dest->root_dir, 0755);
  10486. +
  10487. + sprintf_alloc(&dest->ipkg_dir, "%s%s",
  10488. + dest->root_dir, IPKG_STATE_DIR_PREFIX);
  10489. + file_mkdir_hier(dest->ipkg_dir, 0755);
  10490. +
  10491. + if (str_starts_with (lists_dir, "/"))
  10492. + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
  10493. + else
  10494. + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
  10495. +
  10496. + file_mkdir_hier(dest->lists_dir, 0755);
  10497. +
  10498. + sprintf_alloc(&dest->info_dir, "%s/%s",
  10499. + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
  10500. + file_mkdir_hier(dest->info_dir, 0755);
  10501. +
  10502. + sprintf_alloc(&dest->status_file_name, "%s/%s",
  10503. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10504. +
  10505. + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
  10506. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10507. +
  10508. + dest->status_file = NULL;
  10509. +
  10510. + return 0;
  10511. +}
  10512. +
  10513. +void pkg_dest_deinit(pkg_dest_t *dest)
  10514. +{
  10515. + free(dest->name);
  10516. + dest->name = NULL;
  10517. +
  10518. + free(dest->root_dir);
  10519. + dest->root_dir = NULL;
  10520. +
  10521. + free(dest->ipkg_dir);
  10522. + dest->ipkg_dir = NULL;
  10523. +
  10524. + free(dest->lists_dir);
  10525. + dest->lists_dir = NULL;
  10526. +
  10527. + free(dest->info_dir);
  10528. + dest->info_dir = NULL;
  10529. +
  10530. + free(dest->status_file_name);
  10531. + dest->status_file_name = NULL;
  10532. +
  10533. + free(dest->status_file_tmp_name);
  10534. + dest->status_file_tmp_name = NULL;
  10535. +
  10536. + if (dest->status_file) {
  10537. + fclose(dest->status_file);
  10538. + }
  10539. + dest->status_file = NULL;
  10540. +
  10541. + dest->root_dir = NULL;
  10542. +}
  10543. diff -Nur busybox-1.17.1.orig/archival/libipkg/pkg_dest.h busybox-1.17.1/archival/libipkg/pkg_dest.h
  10544. --- busybox-1.17.1.orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
  10545. +++ busybox-1.17.1/archival/libipkg/pkg_dest.h 2010-07-28 13:07:49.551597019 +0200
  10546. @@ -0,0 +1,38 @@
  10547. +/* pkg_dest.h - the itsy package management system
  10548. +
  10549. + Carl D. Worth
  10550. +
  10551. + Copyright (C) 2001 University of Southern California
  10552. +
  10553. + This program is free software; you can redistribute it and/or
  10554. + modify it under the terms of the GNU General Public License as
  10555. + published by the Free Software Foundation; either version 2, or (at
  10556. + your option) any later version.
  10557. +
  10558. + This program is distributed in the hope that it will be useful, but
  10559. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10560. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10561. + General Public License for more details.
  10562. +*/
  10563. +
  10564. +#ifndef PKG_DEST_H
  10565. +#define PKG_DEST_H
  10566. +
  10567. +typedef struct pkg_dest pkg_dest_t;
  10568. +struct pkg_dest
  10569. +{
  10570. + char *name;
  10571. + char *root_dir;
  10572. + char *ipkg_dir;
  10573. + char *lists_dir;
  10574. + char *info_dir;
  10575. + char *status_file_name;
  10576. + char *status_file_tmp_name;
  10577. + FILE *status_file;
  10578. +};
  10579. +
  10580. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
  10581. +void pkg_dest_deinit(pkg_dest_t *dest);
  10582. +
  10583. +#endif
  10584. +
  10585. diff -Nur busybox-1.17.1.orig/archival/libipkg/pkg_dest_list.c busybox-1.17.1/archival/libipkg/pkg_dest_list.c
  10586. --- busybox-1.17.1.orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
  10587. +++ busybox-1.17.1/archival/libipkg/pkg_dest_list.c 2010-07-28 13:07:49.551597019 +0200
  10588. @@ -0,0 +1,85 @@
  10589. +/* pkg_dest_list.c - the itsy package management system
  10590. +
  10591. + Carl D. Worth
  10592. +
  10593. + Copyright (C) 2001 University of Southern California
  10594. +
  10595. + This program is free software; you can redistribute it and/or
  10596. + modify it under the terms of the GNU General Public License as
  10597. + published by the Free Software Foundation; either version 2, or (at
  10598. + your option) any later version.
  10599. +
  10600. + This program is distributed in the hope that it will be useful, but
  10601. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10602. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10603. + General Public License for more details.
  10604. +*/
  10605. +
  10606. +#include "ipkg.h"
  10607. +
  10608. +#include "pkg_dest.h"
  10609. +#include "void_list.h"
  10610. +#include "pkg_dest_list.h"
  10611. +
  10612. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
  10613. +{
  10614. + return void_list_elt_init((void_list_elt_t *) elt, data);
  10615. +}
  10616. +
  10617. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
  10618. +{
  10619. + void_list_elt_deinit((void_list_elt_t *) elt);
  10620. +}
  10621. +
  10622. +int pkg_dest_list_init(pkg_dest_list_t *list)
  10623. +{
  10624. + return void_list_init((void_list_t *) list);
  10625. +}
  10626. +
  10627. +void pkg_dest_list_deinit(pkg_dest_list_t *list)
  10628. +{
  10629. + pkg_dest_list_elt_t *iter;
  10630. + pkg_dest_t *pkg_dest;
  10631. +
  10632. + for (iter = list->head; iter; iter = iter->next) {
  10633. + pkg_dest = iter->data;
  10634. + pkg_dest_deinit(pkg_dest);
  10635. +
  10636. + /* malloced in pkg_dest_list_append */
  10637. + free(pkg_dest);
  10638. + iter->data = NULL;
  10639. + }
  10640. + void_list_deinit((void_list_t *) list);
  10641. +}
  10642. +
  10643. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10644. + const char *root_dir,const char *lists_dir)
  10645. +{
  10646. + int err;
  10647. + pkg_dest_t *pkg_dest;
  10648. +
  10649. + /* freed in plg_dest_list_deinit */
  10650. + pkg_dest = malloc(sizeof(pkg_dest_t));
  10651. + if (pkg_dest == NULL) {
  10652. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10653. + return NULL;
  10654. + }
  10655. +
  10656. + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
  10657. + err = void_list_append((void_list_t *) list, pkg_dest);
  10658. + if (err) {
  10659. + return NULL;
  10660. + }
  10661. +
  10662. + return pkg_dest;
  10663. +}
  10664. +
  10665. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
  10666. +{
  10667. + return void_list_push((void_list_t *) list, data);
  10668. +}
  10669. +
  10670. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
  10671. +{
  10672. + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
  10673. +}
  10674. diff -Nur busybox-1.17.1.orig/archival/libipkg/pkg_dest_list.h busybox-1.17.1/archival/libipkg/pkg_dest_list.h
  10675. --- busybox-1.17.1.orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
  10676. +++ busybox-1.17.1/archival/libipkg/pkg_dest_list.h 2010-07-28 13:07:49.551597019 +0200
  10677. @@ -0,0 +1,50 @@
  10678. +/* pkg_dest_list.h - the itsy package management system
  10679. +
  10680. + Carl D. Worth
  10681. +
  10682. + Copyright (C) 2001 University of Southern California
  10683. +
  10684. + This program is free software; you can redistribute it and/or
  10685. + modify it under the terms of the GNU General Public License as
  10686. + published by the Free Software Foundation; either version 2, or (at
  10687. + your option) any later version.
  10688. +
  10689. + This program is distributed in the hope that it will be useful, but
  10690. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10691. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10692. + General Public License for more details.
  10693. +*/
  10694. +
  10695. +#ifndef PKG_DEST_LIST_H
  10696. +#define PKG_DEST_LIST_H
  10697. +
  10698. +#include "pkg_dest.h"
  10699. +
  10700. +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
  10701. +struct pkg_dest_list_elt
  10702. +{
  10703. + pkg_dest_list_elt_t *next;
  10704. + pkg_dest_t *data;
  10705. +};
  10706. +
  10707. +typedef struct pkg_dest_list pkg_dest_list_t;
  10708. +struct pkg_dest_list
  10709. +{
  10710. + pkg_dest_list_elt_t pre_head;
  10711. + pkg_dest_list_elt_t *head;
  10712. + pkg_dest_list_elt_t *tail;
  10713. +};
  10714. +
  10715. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
  10716. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
  10717. +
  10718. +int pkg_dest_list_init(pkg_dest_list_t *list);
  10719. +void pkg_dest_list_deinit(pkg_dest_list_t *list);
  10720. +
  10721. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10722. + const char *root_dir,const char* lists_dir);
  10723. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
  10724. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
  10725. +
  10726. +#endif
  10727. +
  10728. diff -Nur busybox-1.17.1.orig/archival/libipkg/pkg_extract.c busybox-1.17.1/archival/libipkg/pkg_extract.c
  10729. --- busybox-1.17.1.orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
  10730. +++ busybox-1.17.1/archival/libipkg/pkg_extract.c 2010-07-28 13:07:49.555597807 +0200
  10731. @@ -0,0 +1,255 @@
  10732. +/* pkg_extract.c - the itsy package management system
  10733. +
  10734. + Carl D. Worth
  10735. +
  10736. + Copyright (C) 2001 University of Southern California
  10737. +
  10738. + This program is free software; you can redistribute it and/or
  10739. + modify it under the terms of the GNU General Public License as
  10740. + published by the Free Software Foundation; either version 2, or (at
  10741. + your option) any later version.
  10742. +
  10743. + This program is distributed in the hope that it will be useful, but
  10744. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10745. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10746. + General Public License for more details.
  10747. +*/
  10748. +
  10749. +#include "ipkg.h"
  10750. +#include <errno.h>
  10751. +#include <fcntl.h>
  10752. +#include <stdio.h>
  10753. +
  10754. +#include "pkg_extract.h"
  10755. +
  10756. +#include "libbb.h"
  10757. +#include "file_util.h"
  10758. +#include "sprintf_alloc.h"
  10759. +#include "unarchive.h"
  10760. +
  10761. +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
  10762. +#define IPKG_DATA_ARCHIVE "data.tar.gz"
  10763. +#define IPKG_CONTROL_FILE "control"
  10764. +
  10765. +static void FAST_FUNC ipkg_data_extract_all_prefix(archive_handle_t *archive_handle)
  10766. +{
  10767. + char *name_ptr = archive_handle->file_header->name;
  10768. +
  10769. + /* Skip all leading "/" */
  10770. + while (*name_ptr == '/')
  10771. + name_ptr++;
  10772. + /* Skip all leading "./" and "../" */
  10773. + while (name_ptr[0] == '.') {
  10774. + if (name_ptr[1] == '.' && name_ptr[2] == '/')
  10775. + name_ptr++;
  10776. + if (name_ptr[1] != '/')
  10777. + break;
  10778. + name_ptr += 2;
  10779. + }
  10780. +
  10781. + if (name_ptr[0] != '\0') {
  10782. + archive_handle->file_header->name = xasprintf("%s%s", archive_handle->dpkg__buffer, name_ptr);
  10783. + data_extract_all(archive_handle);
  10784. + }
  10785. +}
  10786. +
  10787. +static void FAST_FUNC ipkg_data_extract_to_buffer(archive_handle_t *archive_handle)
  10788. +{
  10789. + unsigned size = archive_handle->file_header->size;
  10790. +
  10791. + archive_handle->dpkg__buffer = xzalloc(size + 1);
  10792. + xread(archive_handle->src_fd, archive_handle->dpkg__buffer, size);
  10793. +}
  10794. +
  10795. +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
  10796. +{
  10797. + archive_handle_t *archive;
  10798. + char *path;
  10799. +
  10800. + sprintf_alloc(&path, "%s/", dir);
  10801. + archive = init_handle();
  10802. + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
  10803. + archive->filter = filter_accept_list;
  10804. + llist_add_to(&(archive->accept), (char *)filename);
  10805. + archive->dpkg__buffer = path;
  10806. + archive->action_data = ipkg_data_extract_all_prefix;
  10807. + archive->ah_flags |= ARCHIVE_UNLINK_OLD;
  10808. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10809. + close(archive->src_fd);
  10810. + free(archive->accept);
  10811. + free(archive);
  10812. + free(path);
  10813. +}
  10814. +
  10815. +static void FAST_FUNC data_extract_file_name_to_buffer(archive_handle_t *archive)
  10816. +{
  10817. + unsigned int size = strlen(archive->file_header->name) + 2;
  10818. +
  10819. + if (archive->dpkg__buffer == NULL) {
  10820. + archive->dpkg__buffer = xmalloc(size);
  10821. + strcpy(archive->dpkg__buffer, archive->file_header->name);
  10822. + } else {
  10823. + size += strlen(archive->dpkg__buffer);
  10824. + archive->dpkg__buffer = xrealloc(archive->dpkg__buffer, size);
  10825. + strcat(archive->dpkg__buffer, archive->file_header->name);
  10826. + }
  10827. + strcat(archive->dpkg__buffer, "\n");
  10828. + data_skip(archive);
  10829. +}
  10830. +
  10831. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
  10832. +{
  10833. + archive_handle_t *archive;
  10834. + char *name;
  10835. + const char *filename = "./" IPKG_CONTROL_FILE;
  10836. +
  10837. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10838. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10839. + archive = init_handle();
  10840. + archive->src_fd = xopen(name, O_RDONLY);
  10841. + archive->filter = filter_accept_list;
  10842. + llist_add_to(&(archive->accept), (char *)filename);
  10843. + archive->action_data = ipkg_data_extract_to_buffer;
  10844. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10845. + close(archive->src_fd);
  10846. + fputs(archive->dpkg__buffer, stream);
  10847. + free(archive->dpkg__buffer);
  10848. + free(archive->accept);
  10849. + free(archive);
  10850. + free(name);
  10851. +
  10852. + return 0;
  10853. +}
  10854. +
  10855. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
  10856. +{
  10857. + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
  10858. +}
  10859. +
  10860. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
  10861. +{
  10862. + archive_handle_t *archive;
  10863. + char *name;
  10864. + char *path;
  10865. +
  10866. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10867. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10868. + sprintf_alloc(&path, "%s/%s", dir, prefix);
  10869. + archive = init_handle();
  10870. + archive->src_fd = xopen(name, O_RDONLY);
  10871. + archive->filter = filter_accept_all;
  10872. + archive->dpkg__buffer = path;
  10873. + archive->action_data = ipkg_data_extract_all_prefix;
  10874. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  10875. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10876. + close(archive->src_fd);
  10877. + free(archive);
  10878. + free(path);
  10879. + free(name);
  10880. +
  10881. + return 0;
  10882. +}
  10883. +
  10884. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
  10885. +{
  10886. + archive_handle_t *archive;
  10887. + char *name;
  10888. + char *path;
  10889. +
  10890. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  10891. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  10892. + sprintf_alloc(&path, "%s/", dir);
  10893. + archive = init_handle();
  10894. + archive->src_fd = xopen(name, O_RDONLY);
  10895. + archive->filter = filter_accept_all;
  10896. + archive->dpkg__buffer = path;
  10897. + archive->action_data = ipkg_data_extract_all_prefix;
  10898. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  10899. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10900. + close(archive->src_fd);
  10901. + free(archive);
  10902. + free(path);
  10903. + free(name);
  10904. +
  10905. + return 0;
  10906. +}
  10907. +
  10908. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
  10909. +{
  10910. + int err=0;
  10911. + char *line, *data_file;
  10912. + FILE *file;
  10913. + FILE *tmp;
  10914. +
  10915. + file = fopen(file_name, "w");
  10916. + if (file == NULL) {
  10917. + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
  10918. + __FUNCTION__, file_name);
  10919. + return EINVAL;
  10920. + }
  10921. +
  10922. + tmp = tmpfile();
  10923. + if (pkg->installed_files) {
  10924. + str_list_elt_t *elt;
  10925. + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
  10926. + fprintf(file, "%s\n", elt->data);
  10927. + }
  10928. + } else {
  10929. + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
  10930. + if (err) {
  10931. + fclose(file);
  10932. + fclose(tmp);
  10933. + return err;
  10934. + }
  10935. +
  10936. + /* Fixup data file names by removing the initial '.' */
  10937. + rewind(tmp);
  10938. + while (1) {
  10939. + line = file_read_line_alloc(tmp);
  10940. + if (line == NULL) {
  10941. + break;
  10942. + }
  10943. +
  10944. + data_file = line;
  10945. + if (*data_file == '.') {
  10946. + data_file++;
  10947. + }
  10948. +
  10949. + if (*data_file != '/') {
  10950. + fputs("/", file);
  10951. + }
  10952. +
  10953. + /* I have no idea why, but this is what dpkg does */
  10954. + if (strcmp(data_file, "/\n") == 0) {
  10955. + fputs("/.\n", file);
  10956. + } else {
  10957. + fputs(data_file, file);
  10958. + }
  10959. + }
  10960. + }
  10961. + fclose(tmp);
  10962. + fclose(file);
  10963. +
  10964. + return err;
  10965. +}
  10966. +
  10967. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
  10968. +{
  10969. + archive_handle_t *archive;
  10970. + char *name;
  10971. +
  10972. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  10973. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  10974. + archive = init_handle();
  10975. + archive->src_fd = xopen(name, O_RDONLY);
  10976. + archive->filter = filter_accept_all;
  10977. + archive->action_data = data_extract_file_name_to_buffer;
  10978. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10979. + close(archive->src_fd);
  10980. + fputs(archive->dpkg__buffer, file);
  10981. + free(archive->dpkg__buffer);
  10982. + free(archive);
  10983. + free(name);
  10984. +
  10985. + return 0;
  10986. +}
  10987. diff -Nur busybox-1.17.1.orig/archival/libipkg/pkg_extract.h busybox-1.17.1/archival/libipkg/pkg_extract.h
  10988. --- busybox-1.17.1.orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
  10989. +++ busybox-1.17.1/archival/libipkg/pkg_extract.h 2010-07-28 13:07:49.555597807 +0200
  10990. @@ -0,0 +1,32 @@
  10991. +/* pkg_extract.c - the itsy package management system
  10992. +
  10993. + Carl D. Worth
  10994. +
  10995. + Copyright (C) 2001 University of Southern California
  10996. +
  10997. + This program is free software; you can redistribute it and/or
  10998. + modify it under the terms of the GNU General Public License as
  10999. + published by the Free Software Foundation; either version 2, or (at
  11000. + your option) any later version.
  11001. +
  11002. + This program is distributed in the hope that it will be useful, but
  11003. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11004. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11005. + General Public License for more details.
  11006. +*/
  11007. +
  11008. +#ifndef PKG_EXTRACT_H
  11009. +#define PKG_EXTRACT_H
  11010. +
  11011. +#include "pkg.h"
  11012. +
  11013. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
  11014. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
  11015. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
  11016. + const char *dir,
  11017. + const char *prefix);
  11018. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
  11019. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
  11020. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
  11021. +
  11022. +#endif
  11023. diff -Nur busybox-1.17.1.orig/archival/libipkg/pkg.h busybox-1.17.1/archival/libipkg/pkg.h
  11024. --- busybox-1.17.1.orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
  11025. +++ busybox-1.17.1/archival/libipkg/pkg.h 2010-07-28 13:07:49.555597807 +0200
  11026. @@ -0,0 +1,229 @@
  11027. +/* pkg.h - the itsy package management system
  11028. +
  11029. + Carl D. Worth
  11030. +
  11031. + Copyright (C) 2001 University of Southern California
  11032. +
  11033. + This program is free software; you can redistribute it and/or
  11034. + modify it under the terms of the GNU General Public License as
  11035. + published by the Free Software Foundation; either version 2, or (at
  11036. + your option) any later version.
  11037. +
  11038. + This program is distributed in the hope that it will be useful, but
  11039. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11040. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11041. + General Public License for more details.
  11042. +*/
  11043. +
  11044. +#ifndef PKG_H
  11045. +#define PKG_H
  11046. +
  11047. +#include <sys/types.h>
  11048. +#include <sys/stat.h>
  11049. +#include <unistd.h>
  11050. +
  11051. +#include "pkg_vec.h"
  11052. +#include "str_list.h"
  11053. +#include "pkg_src.h"
  11054. +#include "pkg_dest.h"
  11055. +#include "ipkg_conf.h"
  11056. +#include "conffile_list.h"
  11057. +
  11058. +struct ipkg_conf;
  11059. +
  11060. +/* I think "Size" is currently the shortest field name */
  11061. +#define PKG_MINIMUM_FIELD_NAME_LEN 4
  11062. +
  11063. +enum pkg_state_want
  11064. +{
  11065. + SW_UNKNOWN = 1,
  11066. + SW_INSTALL,
  11067. + SW_DEINSTALL,
  11068. + SW_PURGE,
  11069. + SW_LAST_STATE_WANT
  11070. +};
  11071. +typedef enum pkg_state_want pkg_state_want_t;
  11072. +
  11073. +enum pkg_state_flag
  11074. +{
  11075. + SF_OK = 0,
  11076. + SF_REINSTREQ = 1,
  11077. + SF_HOLD = 2, /* do not upgrade version */
  11078. + SF_REPLACE = 4, /* replace this package */
  11079. + SF_NOPRUNE = 8, /* do not remove obsolete files */
  11080. + SF_PREFER = 16, /* prefer this version */
  11081. + SF_OBSOLETE = 32, /* old package in upgrade pair */
  11082. + SF_MARKED = 64, /* temporary mark */
  11083. + SF_FILELIST_CHANGED = 128, /* needs filelist written */
  11084. + SF_USER = 256,
  11085. + SF_LAST_STATE_FLAG
  11086. +};
  11087. +typedef enum pkg_state_flag pkg_state_flag_t;
  11088. +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
  11089. +
  11090. +enum pkg_state_status
  11091. +{
  11092. + SS_NOT_INSTALLED = 1,
  11093. + SS_UNPACKED,
  11094. + SS_HALF_CONFIGURED,
  11095. + SS_INSTALLED,
  11096. + SS_HALF_INSTALLED,
  11097. + SS_CONFIG_FILES,
  11098. + SS_POST_INST_FAILED,
  11099. + SS_REMOVAL_FAILED,
  11100. + SS_LAST_STATE_STATUS
  11101. +};
  11102. +typedef enum pkg_state_status pkg_state_status_t;
  11103. +
  11104. +struct abstract_pkg{
  11105. + char * name;
  11106. + int dependencies_checked;
  11107. + pkg_vec_t * pkgs;
  11108. + pkg_state_status_t state_status;
  11109. + pkg_state_flag_t state_flag;
  11110. + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
  11111. + abstract_pkg_vec_t * provided_by;
  11112. + abstract_pkg_vec_t * replaced_by;
  11113. +};
  11114. +
  11115. +#include "pkg_depends.h"
  11116. +
  11117. +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
  11118. +
  11119. + The 3 version fields should go into a single version struct. (This
  11120. + is especially important since, currently, pkg->version can easily
  11121. + be mistaken for pkg_verson_str_alloc(pkg) although they are very
  11122. + distinct. This has been the source of multiple bugs.
  11123. +
  11124. + The 3 state fields could possibly also go into their own struct.
  11125. +
  11126. + All fields which deal with lists of packages, (Depends,
  11127. + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
  11128. + be handled by a single struct in pkg_t
  11129. +
  11130. + All string fields for which there is a small set of possible
  11131. + values, (section, maintainer, architecture, maybe version?), that
  11132. + are reused among different packages -- for all such packages we
  11133. + should move from "char *"s to some atom datatype to share data
  11134. + storage and use less memory. We might even do reference counting,
  11135. + but probably not since most often we only create new pkg_t structs,
  11136. + we don't often free them. */
  11137. +struct pkg
  11138. +{
  11139. + char *name;
  11140. + unsigned long epoch;
  11141. + char *version;
  11142. + char *revision;
  11143. + char *familiar_revision;
  11144. + pkg_src_t *src;
  11145. + pkg_dest_t *dest;
  11146. + char *architecture;
  11147. + char *section;
  11148. + char *maintainer;
  11149. + char *description;
  11150. + pkg_state_want_t state_want;
  11151. + pkg_state_flag_t state_flag;
  11152. + pkg_state_status_t state_status;
  11153. + char **depends_str;
  11154. + int depends_count;
  11155. + char **pre_depends_str;
  11156. + int pre_depends_count;
  11157. + char **recommends_str;
  11158. + int recommends_count;
  11159. + char **suggests_str;
  11160. + int suggests_count;
  11161. + compound_depend_t * depends;
  11162. +
  11163. + /* Abhaya: new conflicts */
  11164. + char **conflicts_str;
  11165. + compound_depend_t * conflicts;
  11166. + int conflicts_count;
  11167. +
  11168. + char **replaces_str;
  11169. + int replaces_count;
  11170. + abstract_pkg_t ** replaces;
  11171. +
  11172. + char **provides_str;
  11173. + int provides_count;
  11174. + abstract_pkg_t ** provides;
  11175. +
  11176. + abstract_pkg_t *parent;
  11177. +
  11178. + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
  11179. +
  11180. + char *filename;
  11181. + char *local_filename;
  11182. + char *url;
  11183. + char *tmp_unpack_dir;
  11184. + char *md5sum;
  11185. + char *size;
  11186. + char *installed_size;
  11187. + char *priority;
  11188. + char *source;
  11189. + conffile_list_t conffiles;
  11190. + time_t installed_time;
  11191. + /* As pointer for lazy evaluation */
  11192. + str_list_t *installed_files;
  11193. + /* XXX: CLEANUP: I'd like to perhaps come up with a better
  11194. + mechanism to avoid the problem here, (which is that the
  11195. + installed_files list was being freed from an inner loop while
  11196. + still being used within an outer loop. */
  11197. + int installed_files_ref_cnt;
  11198. + int essential;
  11199. + int arch_priority;
  11200. +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
  11201. + int provided_by_hand;
  11202. +};
  11203. +
  11204. +pkg_t *pkg_new(void);
  11205. +int pkg_init(pkg_t *pkg);
  11206. +void pkg_deinit(pkg_t *pkg);
  11207. +int pkg_init_from_file(pkg_t *pkg, const char *filename);
  11208. +abstract_pkg_t *abstract_pkg_new(void);
  11209. +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
  11210. +
  11211. +/*
  11212. + * merges fields from newpkg into oldpkg.
  11213. + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
  11214. + */
  11215. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
  11216. +
  11217. +char *pkg_version_str_alloc(pkg_t *pkg);
  11218. +
  11219. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
  11220. +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
  11221. +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
  11222. +
  11223. +char * pkg_formatted_info(pkg_t *pkg );
  11224. +char * pkg_formatted_field(pkg_t *pkg, const char *field );
  11225. +
  11226. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
  11227. +
  11228. +void pkg_print_info(pkg_t *pkg, FILE *file);
  11229. +void pkg_print_status(pkg_t * pkg, FILE * file);
  11230. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
  11231. +str_list_t *pkg_get_installed_files(pkg_t *pkg);
  11232. +int pkg_free_installed_files(pkg_t *pkg);
  11233. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
  11234. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
  11235. +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
  11236. + const char *script, const char *args);
  11237. +
  11238. +/* enum mappings */
  11239. +char *pkg_state_want_to_str(pkg_state_want_t sw);
  11240. +pkg_state_want_t pkg_state_want_from_str(char *str);
  11241. +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
  11242. +pkg_state_flag_t pkg_state_flag_from_str(char *str);
  11243. +char *pkg_state_status_to_str(pkg_state_status_t ss);
  11244. +pkg_state_status_t pkg_state_status_from_str(char *str);
  11245. +
  11246. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
  11247. +
  11248. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
  11249. +int pkg_info_preinstall_check(ipkg_conf_t *conf);
  11250. +int pkg_free_installed_files(pkg_t *pkg);
  11251. +
  11252. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
  11253. +int pkg_write_changed_filelists(ipkg_conf_t *conf);
  11254. +
  11255. +#endif
  11256. diff -Nur busybox-1.17.1.orig/archival/libipkg/pkg_hash.c busybox-1.17.1/archival/libipkg/pkg_hash.c
  11257. --- busybox-1.17.1.orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
  11258. +++ busybox-1.17.1/archival/libipkg/pkg_hash.c 2010-07-28 13:07:49.555597807 +0200
  11259. @@ -0,0 +1,623 @@
  11260. +/* ipkg_hash.c - the itsy package management system
  11261. +
  11262. + Steven M. Ayer
  11263. +
  11264. + Copyright (C) 2002 Compaq Computer Corporation
  11265. +
  11266. + This program is free software; you can redistribute it and/or
  11267. + modify it under the terms of the GNU General Public License as
  11268. + published by the Free Software Foundation; either version 2, or (at
  11269. + your option) any later version.
  11270. +
  11271. + This program is distributed in the hope that it will be useful, but
  11272. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11273. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11274. + General Public License for more details.
  11275. +*/
  11276. +
  11277. +#include "ipkg.h"
  11278. +#include <errno.h>
  11279. +#include <ctype.h>
  11280. +#include <stdlib.h>
  11281. +#include <string.h>
  11282. +
  11283. +#include "hash_table.h"
  11284. +#include "pkg.h"
  11285. +#include "ipkg_message.h"
  11286. +#include "pkg_vec.h"
  11287. +#include "pkg_hash.h"
  11288. +#include "pkg_parse.h"
  11289. +#include "ipkg_utils.h"
  11290. +
  11291. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11292. +
  11293. +/*
  11294. + * this will talk to both feeds-lists files and installed status files
  11295. + * example api:
  11296. + *
  11297. + * hash_table_t hash;
  11298. + * pkg_hash_init(name, &hash, 1000);
  11299. + * pkg_hash_add_from_file(<feed filename>);
  11300. + *
  11301. + * the query function is just there as a shell to prove to me that this
  11302. + * sort of works, but isn't far from doing something useful
  11303. + *
  11304. + * -sma, 12/21/01
  11305. + * modified: CDW 3 Jan. 2002
  11306. + */
  11307. +
  11308. +
  11309. +
  11310. +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
  11311. +{
  11312. + return hash_table_init(name, hash, len);
  11313. +}
  11314. +
  11315. +void pkg_hash_deinit(hash_table_t *hash)
  11316. +{
  11317. + hash_table_deinit(hash);
  11318. +}
  11319. +
  11320. +
  11321. +/* Find the default arch for a given package status file if none is given. */
  11322. +static char *pkg_get_default_arch(ipkg_conf_t *conf)
  11323. +{
  11324. + nv_pair_list_elt_t *l;
  11325. + const char *def_arch = HOST_CPU_STR; /* Default arch */
  11326. + int def_prio = 0; /* Other archs override this */
  11327. +
  11328. + l = conf->arch_list.head;
  11329. +
  11330. + while (l) {
  11331. + nv_pair_t *nv = l->data;
  11332. + int priority = strtol(nv->value, NULL, 0);
  11333. +
  11334. + /* Check if this arch has higher priority, and is valid */
  11335. + if ((priority > def_prio) &&
  11336. + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
  11337. + /* Our new default */
  11338. + def_prio = priority;
  11339. + def_arch = nv->name;
  11340. + }
  11341. + l = l->next;
  11342. + }
  11343. +
  11344. + return strdup(def_arch);
  11345. +}
  11346. +
  11347. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11348. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
  11349. +{
  11350. + hash_table_t *hash = &conf->pkg_hash;
  11351. + char **raw;
  11352. + char **raw_start;
  11353. + pkg_t *pkg;
  11354. +
  11355. + raw = raw_start = read_raw_pkgs_from_file(file_name);
  11356. + if (!raw)
  11357. + return -ENOMEM;
  11358. +
  11359. + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
  11360. + pkg = pkg_new();
  11361. + if (!pkg)
  11362. + return -ENOMEM;
  11363. +
  11364. + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
  11365. + if (!pkg->architecture) {
  11366. + char *version_str = pkg_version_str_alloc(pkg);
  11367. + pkg->architecture = pkg_get_default_arch(conf);
  11368. + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
  11369. + pkg->name, version_str, pkg->architecture);
  11370. + free(version_str);
  11371. + }
  11372. + hash_insert_pkg(hash, pkg, is_status_file,conf);
  11373. + } else {
  11374. + free(pkg);
  11375. + }
  11376. + }
  11377. +
  11378. + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
  11379. + memory after read_raw_pkgs_from_file */
  11380. + raw = raw_start;
  11381. + while (*raw) {
  11382. + free(*raw++);
  11383. + }
  11384. + free(raw_start);
  11385. + return 0;
  11386. +}
  11387. +
  11388. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
  11389. +{
  11390. + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
  11391. +}
  11392. +
  11393. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
  11394. +{
  11395. + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
  11396. + if (apkg)
  11397. + return NULL;
  11398. + return apkg->provided_by;
  11399. +}
  11400. +
  11401. +
  11402. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11403. + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
  11404. +{
  11405. + int i;
  11406. + int nprovides = 0;
  11407. + int nmatching = 0;
  11408. + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
  11409. + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
  11410. + abstract_pkg_vec_t *provided_apkg_vec;
  11411. + abstract_pkg_t **provided_apkgs;
  11412. + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
  11413. + pkg_t *latest_installed_parent = NULL;
  11414. + pkg_t *latest_matching = NULL;
  11415. + pkg_t *held_pkg = NULL;
  11416. + pkg_t *good_pkg_by_name = NULL;
  11417. +
  11418. + if (matching_apkgs == NULL || providers == NULL ||
  11419. + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
  11420. + return NULL;
  11421. +
  11422. + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
  11423. +
  11424. + provided_apkg_vec = apkg->provided_by;
  11425. + nprovides = provided_apkg_vec->len;
  11426. + provided_apkgs = provided_apkg_vec->pkgs;
  11427. + if (nprovides > 1)
  11428. + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
  11429. +
  11430. + /* accumulate all the providers */
  11431. + for (i = 0; i < nprovides; i++) {
  11432. + abstract_pkg_t *provider_apkg = provided_apkgs[i];
  11433. + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
  11434. + abstract_pkg_vec_insert(providers, provider_apkg);
  11435. + }
  11436. + nprovides = providers->len;
  11437. +
  11438. + for (i = 0; i < nprovides; i++) {
  11439. + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
  11440. + abstract_pkg_t *replacement_apkg = NULL;
  11441. + pkg_vec_t *vec;
  11442. +
  11443. + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
  11444. + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
  11445. + if (provider_apkg->replaced_by->len > 1) {
  11446. + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
  11447. + provider_apkg->name, replacement_apkg->name);
  11448. + }
  11449. + }
  11450. +
  11451. + if (replacement_apkg)
  11452. + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
  11453. + replacement_apkg->name, provider_apkg->name);
  11454. +
  11455. + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
  11456. + if (abstract_pkg_vec_contains(providers, replacement_apkg))
  11457. + continue;
  11458. + else
  11459. + provider_apkg = replacement_apkg;
  11460. + }
  11461. +
  11462. + if (!(vec = provider_apkg->pkgs)) {
  11463. + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
  11464. + continue;
  11465. + }
  11466. +
  11467. +
  11468. + /* now check for supported architecture */
  11469. + {
  11470. + int max_count = 0;
  11471. + int j;
  11472. +
  11473. + /* count packages matching max arch priority and keep track of last one */
  11474. + for (j = 0; j < vec->len; j++) {
  11475. + pkg_t *maybe = vec->pkgs[j];
  11476. + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
  11477. + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
  11478. + if (maybe->arch_priority > 0) {
  11479. + max_count++;
  11480. + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
  11481. + pkg_vec_insert(matching_pkgs, maybe);
  11482. + }
  11483. + }
  11484. + }
  11485. + }
  11486. +
  11487. + if (matching_pkgs->len > 1)
  11488. + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
  11489. + if (matching_apkgs->len > 1)
  11490. + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
  11491. +
  11492. +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
  11493. + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
  11494. +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
  11495. + Until now I always got the latest, but that breaks the downgrade option.
  11496. + If I stop at the first one, I would probably miss the new ones
  11497. + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
  11498. + or from a Packages feed.
  11499. + It it is from a file it always need to be checked whatever version I have in feeds or everywhere, according to force-down or whatever options*/
  11500. +/*Pigi*/
  11501. +
  11502. + for (i = 0; i < matching_pkgs->len; i++) {
  11503. + pkg_t *matching = matching_pkgs->pkgs[i];
  11504. + if (constraint_fcn(matching, cdata)) { /* We found it */
  11505. + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
  11506. + good_pkg_by_name = matching;
  11507. + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
  11508. + break;
  11509. + }
  11510. + }
  11511. +
  11512. +
  11513. + for (i = 0; i < matching_pkgs->len; i++) {
  11514. + pkg_t *matching = matching_pkgs->pkgs[i];
  11515. + latest_matching = matching;
  11516. + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
  11517. + latest_installed_parent = matching;
  11518. + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
  11519. + if (held_pkg)
  11520. + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
  11521. + held_pkg->name, matching->name);
  11522. + held_pkg = matching;
  11523. + }
  11524. + }
  11525. +
  11526. + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
  11527. + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
  11528. + apkg->name, matching_apkgs->len);
  11529. + for (i = 0; i < matching_apkgs->len; i++) {
  11530. + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
  11531. + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
  11532. + }
  11533. + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
  11534. + }
  11535. +
  11536. + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
  11537. + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
  11538. + __FUNCTION__, apkg->name, matching_pkgs->len);
  11539. + for (i = 0; i < matching_pkgs->len; i++) {
  11540. + pkg_t *matching = matching_pkgs->pkgs[i];
  11541. + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
  11542. + matching->name, matching->version, matching->architecture);
  11543. + }
  11544. + }
  11545. +
  11546. + nmatching = matching_apkgs->len;
  11547. +
  11548. + pkg_vec_free(matching_pkgs);
  11549. + abstract_pkg_vec_free(matching_apkgs);
  11550. + abstract_pkg_vec_free(providers);
  11551. +
  11552. + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
  11553. + return good_pkg_by_name;
  11554. + }
  11555. + if (held_pkg) {
  11556. + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
  11557. + return held_pkg;
  11558. + }
  11559. + if (latest_installed_parent) {
  11560. + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
  11561. + return latest_installed_parent;
  11562. + }
  11563. + if (nmatching > 1) {
  11564. + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
  11565. + return NULL;
  11566. + }
  11567. + if (latest_matching) {
  11568. + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
  11569. + latest_matching->name, latest_matching->version, latest_matching->architecture);
  11570. + return latest_matching;
  11571. + }
  11572. + return NULL;
  11573. +}
  11574. +
  11575. +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
  11576. +{
  11577. + const char *name = (const char *)cdata;
  11578. + if (strcmp(pkg->name, name) == 0)
  11579. + return 1;
  11580. + else
  11581. + return 0;
  11582. +}
  11583. +
  11584. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
  11585. +{
  11586. + hash_table_t *hash = &conf->pkg_hash;
  11587. + abstract_pkg_t *apkg = NULL;
  11588. +
  11589. + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
  11590. + return NULL;
  11591. +
  11592. + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
  11593. +}
  11594. +
  11595. +
  11596. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11597. + const char *pkg_name,
  11598. + const char * version)
  11599. +{
  11600. + pkg_vec_t * vec;
  11601. + register int i;
  11602. + char *version_str = NULL;
  11603. +
  11604. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
  11605. + return NULL;
  11606. +
  11607. + for(i = 0; i < vec->len; i++) {
  11608. + version_str = pkg_version_str_alloc(vec->pkgs[i]);
  11609. + if(!strcmp(version_str, version)) {
  11610. + free(version_str);
  11611. + break;
  11612. + }
  11613. + free(version_str);
  11614. + }
  11615. +
  11616. + if(i == vec->len)
  11617. + return NULL;
  11618. +
  11619. + return vec->pkgs[i];
  11620. +}
  11621. +
  11622. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11623. + const char *pkg_name,
  11624. + pkg_dest_t *dest)
  11625. +{
  11626. + pkg_vec_t * vec;
  11627. + register int i;
  11628. +
  11629. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
  11630. + return NULL;
  11631. + }
  11632. +
  11633. + for(i = 0; i < vec->len; i++)
  11634. + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
  11635. + return vec->pkgs[i];
  11636. + }
  11637. + return NULL;
  11638. +}
  11639. +
  11640. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11641. + const char *pkg_name)
  11642. +{
  11643. + pkg_vec_t * vec;
  11644. + register int i;
  11645. +
  11646. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
  11647. + return NULL;
  11648. + }
  11649. +
  11650. + for(i = 0; i < vec->len; i++)
  11651. + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
  11652. + return vec->pkgs[i];
  11653. + }
  11654. +
  11655. + return NULL;
  11656. +}
  11657. +
  11658. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
  11659. +{
  11660. + abstract_pkg_t * ab_pkg;
  11661. +
  11662. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
  11663. + return NULL;
  11664. + }
  11665. +
  11666. + if (ab_pkg->pkgs) {
  11667. + return ab_pkg->pkgs;
  11668. + } else if (ab_pkg->provided_by) {
  11669. + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
  11670. + if (abpkg != NULL){
  11671. + return abpkg->pkgs;
  11672. + } else {
  11673. + return ab_pkg->pkgs;
  11674. + }
  11675. + } else {
  11676. + return NULL;
  11677. + }
  11678. +}
  11679. +
  11680. +static int pkg_compare_names(const void *p1, const void *p2)
  11681. +{
  11682. + const pkg_t *pkg1 = *(const pkg_t **)p1;
  11683. + const pkg_t *pkg2 = *(const pkg_t **)p2;
  11684. + if (pkg1->name == NULL)
  11685. + return 1;
  11686. + if (pkg2->name == NULL)
  11687. + return -1;
  11688. + return(strcmp(pkg1->name, pkg2->name));
  11689. +}
  11690. +
  11691. +
  11692. +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
  11693. +{
  11694. + int j;
  11695. + const char *name;
  11696. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11697. + pkg_vec_t *all = (pkg_vec_t *)data;
  11698. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11699. + name = pkg_name;
  11700. + if (pkg_vec) {
  11701. + for (j = 0; j < pkg_vec->len; j++) {
  11702. + pkg_t *pkg = pkg_vec->pkgs[j];
  11703. + pkg_vec_insert(all, pkg);
  11704. + }
  11705. + }
  11706. +}
  11707. +
  11708. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
  11709. +{
  11710. + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
  11711. + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
  11712. +}
  11713. +
  11714. +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
  11715. +{
  11716. + const char *name;
  11717. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11718. + pkg_vec_t *all = (pkg_vec_t *)data;
  11719. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11720. + int j;
  11721. + name = pkg_name;
  11722. + if (pkg_vec) {
  11723. + for (j = 0; j < pkg_vec->len; j++) {
  11724. + pkg_t *pkg = pkg_vec->pkgs[j];
  11725. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  11726. + pkg_vec_insert(all, pkg);
  11727. + }
  11728. + }
  11729. + }
  11730. +}
  11731. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
  11732. +{
  11733. + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
  11734. + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
  11735. +}
  11736. +
  11737. +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
  11738. +{
  11739. + int i;
  11740. + pkg_t *pkg;
  11741. + const char *name;
  11742. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11743. + ipkg_conf_t *conf = (ipkg_conf_t *)data;
  11744. + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
  11745. + name = pkg_name;
  11746. + fprintf(stdout, "%s\n", ab_pkg->name);
  11747. + i = 0;
  11748. + if (dependents != NULL)
  11749. + while (dependents [i] != NULL)
  11750. + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
  11751. + dependents = ab_pkg->provided_by->pkgs;
  11752. + i = 0;
  11753. + if (dependents != NULL)
  11754. + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
  11755. + printf ("\tprovided by - %s\n", dependents [i ++]->name);
  11756. + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
  11757. + if (pkg) {
  11758. + i = 0;
  11759. + while (i < pkg->depends_count)
  11760. + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
  11761. + }
  11762. +}
  11763. +void pkg_hash_dump(hash_table_t *hash, void *data)
  11764. +{
  11765. +
  11766. + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
  11767. + hash_table_foreach(hash, pkg_hash_dump_helper, data);
  11768. + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
  11769. +}
  11770. +
  11771. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11772. +{
  11773. + abstract_pkg_t * ab_pkg;
  11774. +
  11775. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
  11776. + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
  11777. +
  11778. + return ab_pkg;
  11779. +}
  11780. +
  11781. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  11782. +{
  11783. + abstract_pkg_t * ab_pkg;
  11784. + int arch_priority;
  11785. +
  11786. + if(!pkg)
  11787. + return pkg;
  11788. +
  11789. + arch_priority = pkg->arch_priority;
  11790. +
  11791. + if (buildDepends(hash, pkg)<0){
  11792. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11793. + return NULL;
  11794. + }
  11795. + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
  11796. +
  11797. + if (set_status) {
  11798. + if (pkg->state_status == SS_INSTALLED) {
  11799. + ab_pkg->state_status = SS_INSTALLED;
  11800. + } else if (pkg->state_status == SS_UNPACKED) {
  11801. + ab_pkg->state_status = SS_UNPACKED;
  11802. + }
  11803. + }
  11804. +
  11805. + if(!ab_pkg->pkgs)
  11806. + ab_pkg->pkgs = pkg_vec_alloc();
  11807. +
  11808. + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
  11809. + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
  11810. + pkg->parent = ab_pkg;
  11811. +
  11812. + if (buildProvides(hash, ab_pkg, pkg)<0){
  11813. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11814. + return NULL;
  11815. + }
  11816. + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
  11817. + if (buildConflicts(hash, pkg)<0){
  11818. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11819. + return NULL;
  11820. + }
  11821. + if (buildReplaces(hash, ab_pkg, pkg)<0) {
  11822. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11823. + return NULL;
  11824. + }
  11825. +
  11826. + buildDependedUponBy(pkg, ab_pkg);
  11827. + return pkg;
  11828. +}
  11829. +
  11830. +/*
  11831. + * this will assume that we've already determined that
  11832. + * the abstract pkg doesn't exist, 'cause we should know these things...
  11833. + */
  11834. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11835. +{
  11836. + abstract_pkg_t * ab_pkg;
  11837. +
  11838. + ab_pkg = abstract_pkg_new();
  11839. + if (ab_pkg == NULL) { return NULL; }
  11840. +
  11841. + ab_pkg->name = strdup(pkg_name);
  11842. + hash_table_insert(hash, pkg_name, ab_pkg);
  11843. +
  11844. + return ab_pkg;
  11845. +}
  11846. +
  11847. +
  11848. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
  11849. +{
  11850. + hash_table_t *file_hash = &conf->file_hash;
  11851. +
  11852. + return hash_table_get(file_hash, file_name);
  11853. +}
  11854. +
  11855. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
  11856. +{
  11857. + hash_table_t *file_hash = &conf->file_hash;
  11858. + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
  11859. + int file_name_len = strlen(file_name);
  11860. +
  11861. + if (file_name[file_name_len -1] == '/')
  11862. + return 0;
  11863. +
  11864. + if (conf->offline_root) {
  11865. + int len = strlen(conf->offline_root);
  11866. + if (strncmp(file_name, conf->offline_root, len) == 0) {
  11867. + file_name += len;
  11868. + }
  11869. + }
  11870. +
  11871. + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
  11872. + hash_table_insert(file_hash, file_name, owning_pkg);
  11873. + if (old_owning_pkg) {
  11874. + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
  11875. + /* mark this package to have its filelist written */
  11876. + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11877. + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11878. + }
  11879. + return 0;
  11880. +}
  11881. +
  11882. +
  11883. diff -Nur busybox-1.17.1.orig/archival/libipkg/pkg_hash.h busybox-1.17.1/archival/libipkg/pkg_hash.h
  11884. --- busybox-1.17.1.orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
  11885. +++ busybox-1.17.1/archival/libipkg/pkg_hash.h 2010-07-28 13:07:49.563598547 +0200
  11886. @@ -0,0 +1,61 @@
  11887. +/* pkg_hash.h - the itsy package management system
  11888. +
  11889. + Steven M. Ayer
  11890. +
  11891. + Copyright (C) 2002 Compaq Computer Corporation
  11892. +
  11893. + This program is free software; you can redistribute it and/or
  11894. + modify it under the terms of the GNU General Public License as
  11895. + published by the Free Software Foundation; either version 2, or (at
  11896. + your option) any later version.
  11897. +
  11898. + This program is distributed in the hope that it will be useful, but
  11899. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11900. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11901. + General Public License for more details.
  11902. +*/
  11903. +
  11904. +#ifndef PKG_HASH_H
  11905. +#define PKG_HASH_H
  11906. +
  11907. +#include "pkg.h"
  11908. +#include "pkg_vec.h"
  11909. +#include "hash_table.h"
  11910. +
  11911. +
  11912. +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
  11913. +void pkg_hash_deinit(hash_table_t *hash);
  11914. +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
  11915. +
  11916. +void pkg_hash_dump(hash_table_t *hash, void *data);
  11917. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
  11918. +
  11919. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11920. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
  11921. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
  11922. +
  11923. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11924. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
  11925. +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11926. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
  11927. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11928. + const char *pkg_name,
  11929. + const char * version);
  11930. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
  11931. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11932. + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
  11933. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
  11934. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11935. + const char *pkg_name);
  11936. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11937. + const char *pkg_name,
  11938. + pkg_dest_t *dest);
  11939. +
  11940. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
  11941. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
  11942. +
  11943. +/* XXX: shouldn't this go in pkg_vec.[ch]? */
  11944. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11945. +
  11946. +#endif
  11947. +
  11948. diff -Nur busybox-1.17.1.orig/archival/libipkg/pkg_parse.c busybox-1.17.1/archival/libipkg/pkg_parse.c
  11949. --- busybox-1.17.1.orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
  11950. +++ busybox-1.17.1/archival/libipkg/pkg_parse.c 2010-07-28 13:07:49.603597497 +0200
  11951. @@ -0,0 +1,368 @@
  11952. +/* pkg_parse.c - the itsy package management system
  11953. +
  11954. + Steven M. Ayer
  11955. +
  11956. + Copyright (C) 2002 Compaq Computer Corporation
  11957. +
  11958. + This program is free software; you can redistribute it and/or
  11959. + modify it under the terms of the GNU General Public License as
  11960. + published by the Free Software Foundation; either version 2, or (at
  11961. + your option) any later version.
  11962. +
  11963. + This program is distributed in the hope that it will be useful, but
  11964. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11965. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11966. + General Public License for more details.
  11967. +*/
  11968. +
  11969. +#include "ipkg.h"
  11970. +#include <errno.h>
  11971. +#include <ctype.h>
  11972. +
  11973. +#include "pkg.h"
  11974. +#include "ipkg_utils.h"
  11975. +#include "pkg_parse.h"
  11976. +
  11977. +int alterProvidesLine(char *raw, char *temp);
  11978. +
  11979. +int isGenericFieldType(char * type, char * line)
  11980. +{
  11981. + if(!strncmp(line, type, strlen(type)))
  11982. + return 1;
  11983. + return 0;
  11984. +}
  11985. +
  11986. +char * parseGenericFieldType(char * type, char * raw)
  11987. +{
  11988. + char * field_value = raw + (strlen(type) + 1);
  11989. + return trim_alloc(field_value);
  11990. +}
  11991. +
  11992. +void parseStatus(pkg_t *pkg, char * raw)
  11993. +{
  11994. + char sw_str[64], sf_str[64], ss_str[64];
  11995. +
  11996. + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
  11997. + pkg->state_want = pkg_state_want_from_str(sw_str);
  11998. + pkg->state_flag = pkg_state_flag_from_str(sf_str);
  11999. + pkg->state_status = pkg_state_status_from_str(ss_str);
  12000. +}
  12001. +
  12002. +char ** parseDependsString(char * raw, int * depends_count)
  12003. +{
  12004. + char ** depends = NULL;
  12005. + int line_count = 0;
  12006. + char buff[2048], * dest;
  12007. +
  12008. + while(raw && *raw && !isspace(*raw)) {
  12009. + raw++;
  12010. + }
  12011. +
  12012. + if(line_is_blank(raw)){
  12013. + *depends_count = line_count;
  12014. + return NULL;
  12015. + }
  12016. + while(raw && *raw){
  12017. + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
  12018. +
  12019. + while(isspace(*raw)) raw++;
  12020. +
  12021. + dest = buff;
  12022. + while((*raw != ',') && *raw)
  12023. + *dest++ = *raw++;
  12024. +
  12025. + *dest = '\0';
  12026. + depends[line_count] = trim_alloc(buff);
  12027. + if(depends[line_count] ==NULL)
  12028. + return NULL;
  12029. + line_count++;
  12030. + if(*raw == ',')
  12031. + raw++;
  12032. + }
  12033. + *depends_count = line_count;
  12034. + return depends;
  12035. +}
  12036. +
  12037. +void parseConffiles(pkg_t * pkg, char * raw)
  12038. +{
  12039. + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
  12040. +
  12041. + if(!strncmp(raw, "Conffiles:", 10))
  12042. + raw += strlen("Conffiles:");
  12043. +
  12044. + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
  12045. + conffile_list_append(&pkg->conffiles, file_name, md5sum);
  12046. + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
  12047. + while (*raw && isspace(*raw)) {
  12048. + raw++;
  12049. + }
  12050. + raw += strlen(file_name);
  12051. + while (*raw && isspace(*raw)) {
  12052. + raw++;
  12053. + }
  12054. + raw += strlen(md5sum);
  12055. + }
  12056. +}
  12057. +
  12058. +int parseVersion(pkg_t *pkg, char *raw)
  12059. +{
  12060. + char *colon, *eepochcolon;
  12061. +#ifdef USE_DEBVERSION
  12062. + char *hyphen;
  12063. +#endif
  12064. + unsigned long epoch;
  12065. +
  12066. + if (!*raw) {
  12067. + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
  12068. + return EINVAL;
  12069. + }
  12070. +
  12071. + if (strncmp(raw, "Version:", 8) == 0) {
  12072. + raw += 8;
  12073. + }
  12074. + while (*raw && isspace(*raw)) {
  12075. + raw++;
  12076. + }
  12077. +
  12078. + colon= strchr(raw,':');
  12079. + if (colon) {
  12080. + epoch= strtoul(raw,&eepochcolon,10);
  12081. + if (colon != eepochcolon) {
  12082. + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
  12083. + return EINVAL;
  12084. + }
  12085. + if (!*++colon) {
  12086. + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
  12087. + return EINVAL;
  12088. + }
  12089. + raw= colon;
  12090. + pkg->epoch= epoch;
  12091. + } else {
  12092. + pkg->epoch= 0;
  12093. + }
  12094. +
  12095. + pkg->revision = (char *)"";
  12096. + pkg->familiar_revision = (char *)"";
  12097. +
  12098. + pkg->version= malloc(strlen(raw)+1);
  12099. + if ( pkg->version == NULL ) {
  12100. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12101. + return ENOMEM;
  12102. + }
  12103. + strcpy(pkg->version, raw);
  12104. +
  12105. +#ifdef USE_DEBVERSION
  12106. + hyphen= strrchr(pkg->version,'-');
  12107. +
  12108. + if (hyphen) {
  12109. + *hyphen++= 0;
  12110. + if (strncmp("fam", hyphen, 3) == 0) {
  12111. + pkg->familiar_revision=hyphen+3;
  12112. + hyphen= strrchr(pkg->version,'-');
  12113. + if (hyphen) {
  12114. + *hyphen++= 0;
  12115. + pkg->revision = hyphen;
  12116. + }
  12117. + } else {
  12118. + pkg->revision = hyphen;
  12119. + }
  12120. + }
  12121. +#endif
  12122. +
  12123. +/*
  12124. + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
  12125. + pkg->epoch,
  12126. + pkg->version,
  12127. + pkg->revision,
  12128. + pkg->familiar_revision);
  12129. +*/
  12130. +
  12131. + return 0;
  12132. +}
  12133. +
  12134. +
  12135. +/* This code is needed to insert in first position the keyword for the aligning bug */
  12136. +
  12137. +int alterProvidesLine(char *raw, char *temp)
  12138. +{
  12139. +
  12140. +
  12141. + if (!*raw) {
  12142. + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
  12143. + return -EINVAL;
  12144. + }
  12145. +
  12146. + if ( temp == NULL ) {
  12147. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12148. + return -ENOMEM;
  12149. + }
  12150. +
  12151. + if (strncmp(raw, "Provides:", 9) == 0) {
  12152. + raw += 9;
  12153. + }
  12154. + while (*raw && isspace(*raw)) {
  12155. + raw++;
  12156. + }
  12157. +
  12158. + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
  12159. + while (*raw) {
  12160. + strncat( temp, raw++, 1);
  12161. + }
  12162. + return 0;
  12163. +
  12164. +}
  12165. +
  12166. +/* Some random thoughts from Carl:
  12167. +
  12168. + This function could be considerably simplified if we just kept
  12169. + an array of all the generic string-valued field names, and looped
  12170. + through those looking for a match. Also, these fields could perhaps
  12171. + be stored in the package as an array as well, (or, probably better,
  12172. + as an nv_pair_list_t).
  12173. +
  12174. + Fields which require special parsing or storage, (such as Depends:
  12175. + and Status:) could be handled as they are now.
  12176. +*/
  12177. +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
  12178. + to a dependency list. And, since we already have
  12179. + Depends/Pre-Depends and need to add Conflicts, Recommends, and
  12180. + Enhances, perhaps we could generalize all of these and save some
  12181. + code duplication.
  12182. +*/
  12183. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
  12184. +{
  12185. + int reading_conffiles, reading_description;
  12186. + int pkg_false_provides=1;
  12187. + char ** lines;
  12188. + char * provide=NULL;
  12189. +
  12190. + pkg->src = src;
  12191. + pkg->dest = dest;
  12192. +
  12193. + reading_conffiles = reading_description = 0;
  12194. +
  12195. + for (lines = *raw; *lines; lines++) {
  12196. + /* fprintf(stderr, "PARSING %s\n", *lines);*/
  12197. + if(isGenericFieldType((char *)"Package:", *lines))
  12198. + pkg->name = parseGenericFieldType((char *)"Package", *lines);
  12199. + else if(isGenericFieldType((char *)"Architecture:", *lines))
  12200. + pkg->architecture = parseGenericFieldType((char *)"Architecture", *lines);
  12201. + else if(isGenericFieldType((char *)"Filename:", *lines))
  12202. + pkg->filename = parseGenericFieldType((char *)"Filename", *lines);
  12203. + else if(isGenericFieldType((char *)"Section:", *lines))
  12204. + pkg->section = parseGenericFieldType((char *)"Section", *lines);
  12205. + else if(isGenericFieldType((char *)"MD5sum:", *lines))
  12206. + pkg->md5sum = parseGenericFieldType((char *)"MD5sum", *lines);
  12207. + /* The old ipkg wrote out status files with the wrong case for MD5sum,
  12208. + let's parse it either way */
  12209. + else if(isGenericFieldType((char *)"MD5Sum:", *lines))
  12210. + pkg->md5sum = parseGenericFieldType((char *)"MD5Sum", *lines);
  12211. + else if(isGenericFieldType((char *)"Size:", *lines))
  12212. + pkg->size = parseGenericFieldType((char *)"Size", *lines);
  12213. + else if(isGenericFieldType((char *)"Source:", *lines))
  12214. + pkg->source = parseGenericFieldType((char *)"Source", *lines);
  12215. + else if(isGenericFieldType((char *)"Installed-Size:", *lines))
  12216. + pkg->installed_size = parseGenericFieldType((char *)"Installed-Size", *lines);
  12217. + else if(isGenericFieldType((char *)"Installed-Time:", *lines)) {
  12218. + char *time_str = parseGenericFieldType((char *)"Installed-Time", *lines);
  12219. + pkg->installed_time = strtoul(time_str, NULL, 0);
  12220. + } else if(isGenericFieldType((char *)"Priority:", *lines))
  12221. + pkg->priority = parseGenericFieldType((char *)"Priority", *lines);
  12222. + else if(isGenericFieldType((char *)"Essential:", *lines)) {
  12223. + char *essential_value;
  12224. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12225. + if (strcmp(essential_value, "yes") == 0) {
  12226. + pkg->essential = 1;
  12227. + }
  12228. + free(essential_value);
  12229. + }
  12230. + else if(isGenericFieldType((char *)"Status", *lines))
  12231. + parseStatus(pkg, *lines);
  12232. + else if(isGenericFieldType((char *)"Version", *lines))
  12233. + parseVersion(pkg, *lines);
  12234. + else if(isGenericFieldType((char *)"Maintainer", *lines))
  12235. + pkg->maintainer = parseGenericFieldType((char *)"Maintainer", *lines);
  12236. + else if(isGenericFieldType((char *)"Conffiles", *lines)){
  12237. + parseConffiles(pkg, *lines);
  12238. + reading_conffiles = 1;
  12239. + }
  12240. + else if(isGenericFieldType((char *)"Description", *lines)) {
  12241. + pkg->description = parseGenericFieldType((char *)"Description", *lines);
  12242. + reading_conffiles = 0;
  12243. + reading_description = 1;
  12244. + }
  12245. +
  12246. + else if(isGenericFieldType((char *)"Provides", *lines)){
  12247. +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
  12248. + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
  12249. + if ( alterProvidesLine(*lines,provide) ){
  12250. + return EINVAL;
  12251. + }
  12252. + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
  12253. +/* Let's try to hack a bit here.
  12254. + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
  12255. + in alot of other places. We will remove it before writing down the status database */
  12256. + pkg_false_provides=0;
  12257. + free(provide);
  12258. + }
  12259. +
  12260. + else if(isGenericFieldType((char *)"Depends", *lines))
  12261. + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
  12262. + else if(isGenericFieldType((char *)"Pre-Depends", *lines))
  12263. + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
  12264. + else if(isGenericFieldType((char *)"Recommends", *lines))
  12265. + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
  12266. + else if(isGenericFieldType((char *)"Suggests", *lines))
  12267. + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
  12268. + /* Abhaya: support for conflicts */
  12269. + else if(isGenericFieldType((char *)"Conflicts", *lines))
  12270. + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
  12271. + else if(isGenericFieldType((char *)"Replaces", *lines))
  12272. + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
  12273. + else if(line_is_blank(*lines)) {
  12274. + lines++;
  12275. + break;
  12276. + }
  12277. + else if(**lines == ' '){
  12278. + if(reading_description) {
  12279. + /* we already know it's not blank, so the rest of description */
  12280. + pkg->description = realloc(pkg->description,
  12281. + strlen(pkg->description)
  12282. + + 1 + strlen(*lines) + 1);
  12283. + strcat(pkg->description, "\n");
  12284. + strcat(pkg->description, (*lines));
  12285. + }
  12286. + else if(reading_conffiles)
  12287. + parseConffiles(pkg, *lines);
  12288. + }
  12289. + }
  12290. + *raw = lines;
  12291. +/* If the ipk has not a Provides line, we insert our false line */
  12292. + if ( pkg_false_provides==1)
  12293. + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
  12294. +
  12295. + if (pkg->name) {
  12296. + return 0;
  12297. + } else {
  12298. + return EINVAL;
  12299. + }
  12300. +}
  12301. +
  12302. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
  12303. +{
  12304. + char ** lines;
  12305. +
  12306. + for (lines = *raw; *lines; lines++) {
  12307. + if(isGenericFieldType((char *)"Essential:", *lines)) {
  12308. + char *essential_value;
  12309. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12310. + if (strcmp(essential_value, "yes") == 0) {
  12311. + pkg->essential = 1;
  12312. + }
  12313. + free(essential_value);
  12314. + }
  12315. + }
  12316. + *raw = lines;
  12317. +
  12318. + return 0;
  12319. +}
  12320. diff -Nur busybox-1.17.1.orig/archival/libipkg/pkg_parse.h busybox-1.17.1/archival/libipkg/pkg_parse.h
  12321. --- busybox-1.17.1.orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
  12322. +++ busybox-1.17.1/archival/libipkg/pkg_parse.h 2010-07-28 13:07:49.607598006 +0200
  12323. @@ -0,0 +1,31 @@
  12324. +/* pkg_parse.h - the itsy package management system
  12325. +
  12326. + Steven M. Ayer
  12327. +
  12328. + Copyright (C) 2002 Compaq Computer Corporation
  12329. +
  12330. + This program is free software; you can redistribute it and/or
  12331. + modify it under the terms of the GNU General Public License as
  12332. + published by the Free Software Foundation; either version 2, or (at
  12333. + your option) any later version.
  12334. +
  12335. + This program is distributed in the hope that it will be useful, but
  12336. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12337. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12338. + General Public License for more details.
  12339. +*/
  12340. +
  12341. +#ifndef PKG_PARSE_H
  12342. +#define PKG_PARSE_H
  12343. +
  12344. +int isGenericFieldType(char * type, char * line);
  12345. +char * parseGenericFieldType(char * type, char * raw);
  12346. +void parseStatus(pkg_t *pkg, char * raw);
  12347. +int parseVersion(pkg_t *pkg, char *raw);
  12348. +char ** parseDependsString(char * raw, int * depends_count);
  12349. +int parseVersion(pkg_t *pkg, char *raw);
  12350. +void parseConffiles(pkg_t * pkg, char * raw);
  12351. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
  12352. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
  12353. +
  12354. +#endif
  12355. diff -Nur busybox-1.17.1.orig/archival/libipkg/pkg_src.c busybox-1.17.1/archival/libipkg/pkg_src.c
  12356. --- busybox-1.17.1.orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
  12357. +++ busybox-1.17.1/archival/libipkg/pkg_src.c 2010-07-28 13:07:49.607598006 +0200
  12358. @@ -0,0 +1,43 @@
  12359. +/* pkg_src.c - the itsy package management system
  12360. +
  12361. + Carl D. Worth
  12362. +
  12363. + Copyright (C) 2001 University of Southern California
  12364. +
  12365. + This program is free software; you can redistribute it and/or
  12366. + modify it under the terms of the GNU General Public License as
  12367. + published by the Free Software Foundation; either version 2, or (at
  12368. + your option) any later version.
  12369. +
  12370. + This program is distributed in the hope that it will be useful, but
  12371. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12372. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12373. + General Public License for more details.
  12374. +*/
  12375. +
  12376. +#include "ipkg.h"
  12377. +
  12378. +#include "pkg_src.h"
  12379. +#include "str_util.h"
  12380. +
  12381. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
  12382. +{
  12383. + src->gzip = gzip;
  12384. + src->name = str_dup_safe (name);
  12385. + src->value = str_dup_safe (base_url);
  12386. + if (extra_data)
  12387. + src->extra_data = str_dup_safe (extra_data);
  12388. + else
  12389. + src->extra_data = NULL;
  12390. + return 0;
  12391. +}
  12392. +
  12393. +void pkg_src_deinit(pkg_src_t *src)
  12394. +{
  12395. + free (src->name);
  12396. + free (src->value);
  12397. + if (src->extra_data)
  12398. + free (src->extra_data);
  12399. +}
  12400. +
  12401. +
  12402. diff -Nur busybox-1.17.1.orig/archival/libipkg/pkg_src.h busybox-1.17.1/archival/libipkg/pkg_src.h
  12403. --- busybox-1.17.1.orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
  12404. +++ busybox-1.17.1/archival/libipkg/pkg_src.h 2010-07-28 13:07:49.611599074 +0200
  12405. @@ -0,0 +1,34 @@
  12406. +/* pkg_src.h - the itsy package management system
  12407. +
  12408. + Carl D. Worth
  12409. +
  12410. + Copyright (C) 2001 University of Southern California
  12411. +
  12412. + This program is free software; you can redistribute it and/or
  12413. + modify it under the terms of the GNU General Public License as
  12414. + published by the Free Software Foundation; either version 2, or (at
  12415. + your option) any later version.
  12416. +
  12417. + This program is distributed in the hope that it will be useful, but
  12418. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12419. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12420. + General Public License for more details.
  12421. +*/
  12422. +
  12423. +#ifndef PKG_SRC_H
  12424. +#define PKG_SRC_H
  12425. +
  12426. +#include "nv_pair.h"
  12427. +
  12428. +typedef struct
  12429. +{
  12430. + char *name;
  12431. + char *value;
  12432. + char *extra_data;
  12433. + int gzip;
  12434. +} pkg_src_t;
  12435. +
  12436. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
  12437. +void pkg_src_deinit(pkg_src_t *src);
  12438. +
  12439. +#endif
  12440. diff -Nur busybox-1.17.1.orig/archival/libipkg/pkg_src_list.c busybox-1.17.1/archival/libipkg/pkg_src_list.c
  12441. --- busybox-1.17.1.orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
  12442. +++ busybox-1.17.1/archival/libipkg/pkg_src_list.c 2010-07-28 13:07:49.611599074 +0200
  12443. @@ -0,0 +1,75 @@
  12444. +/* pkg_src_list.c - the itsy package management system
  12445. +
  12446. + Carl D. Worth
  12447. +
  12448. + Copyright (C) 2001 University of Southern California
  12449. +
  12450. + This program is free software; you can redistribute it and/or
  12451. + modify it under the terms of the GNU General Public License as
  12452. + published by the Free Software Foundation; either version 2, or (at
  12453. + your option) any later version.
  12454. +
  12455. + This program is distributed in the hope that it will be useful, but
  12456. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12457. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12458. + General Public License for more details.
  12459. +*/
  12460. +
  12461. +#include "ipkg.h"
  12462. +
  12463. +#include "pkg_src_list.h"
  12464. +#include "void_list.h"
  12465. +
  12466. +int pkg_src_list_init(pkg_src_list_t *list)
  12467. +{
  12468. + return void_list_init((void_list_t *) list);
  12469. +}
  12470. +
  12471. +void pkg_src_list_deinit(pkg_src_list_t *list)
  12472. +{
  12473. + pkg_src_list_elt_t *iter;
  12474. + pkg_src_t *pkg_src;
  12475. +
  12476. + for (iter = list->head; iter; iter = iter->next) {
  12477. + pkg_src = iter->data;
  12478. + pkg_src_deinit(pkg_src);
  12479. +
  12480. + /* malloced in pkg_src_list_append */
  12481. + free(pkg_src);
  12482. + iter->data = NULL;
  12483. + }
  12484. + void_list_deinit((void_list_t *) list);
  12485. +}
  12486. +
  12487. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
  12488. + const char *name, const char *base_url, const char *extra_data,
  12489. + int gzip)
  12490. +{
  12491. + int err;
  12492. +
  12493. + /* freed in pkg_src_list_deinit */
  12494. + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
  12495. +
  12496. + if (pkg_src == NULL) {
  12497. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12498. + return NULL;
  12499. + }
  12500. + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
  12501. +
  12502. + err = void_list_append((void_list_t *) list, pkg_src);
  12503. + if (err) {
  12504. + return NULL;
  12505. + }
  12506. +
  12507. + return pkg_src;
  12508. +}
  12509. +
  12510. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
  12511. +{
  12512. + return void_list_push((void_list_t *) list, data);
  12513. +}
  12514. +
  12515. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
  12516. +{
  12517. + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
  12518. +}
  12519. diff -Nur busybox-1.17.1.orig/archival/libipkg/pkg_src_list.h busybox-1.17.1/archival/libipkg/pkg_src_list.h
  12520. --- busybox-1.17.1.orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
  12521. +++ busybox-1.17.1/archival/libipkg/pkg_src_list.h 2010-07-28 13:07:49.660190465 +0200
  12522. @@ -0,0 +1,57 @@
  12523. +/* pkg_src_list.h - the itsy package management system
  12524. +
  12525. + Carl D. Worth
  12526. +
  12527. + Copyright (C) 2001 University of Southern California
  12528. +
  12529. + This program is free software; you can redistribute it and/or
  12530. + modify it under the terms of the GNU General Public License as
  12531. + published by the Free Software Foundation; either version 2, or (at
  12532. + your option) any later version.
  12533. +
  12534. + This program is distributed in the hope that it will be useful, but
  12535. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12536. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12537. + General Public License for more details.
  12538. +*/
  12539. +
  12540. +#ifndef PKG_SRC_LIST_H
  12541. +#define PKG_SRC_LIST_H
  12542. +
  12543. +#include "pkg_src.h"
  12544. +
  12545. +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
  12546. +struct pkg_src_list_elt
  12547. +{
  12548. + pkg_src_list_elt_t *next;
  12549. + pkg_src_t *data;
  12550. +};
  12551. +
  12552. +typedef struct pkg_src_list pkg_src_list_t;
  12553. +struct pkg_src_list
  12554. +{
  12555. + pkg_src_list_elt_t pre_head;
  12556. + pkg_src_list_elt_t *head;
  12557. + pkg_src_list_elt_t *tail;
  12558. +};
  12559. +
  12560. +static inline int pkg_src_list_empty(pkg_src_list_t *list)
  12561. +{
  12562. + if (list->head == NULL)
  12563. + return 1;
  12564. + else
  12565. + return 0;
  12566. +}
  12567. +
  12568. +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
  12569. +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
  12570. +
  12571. +int pkg_src_list_init(pkg_src_list_t *list);
  12572. +void pkg_src_list_deinit(pkg_src_list_t *list);
  12573. +
  12574. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list, const char *name, const char *root_dir, const char *extra_data, int gzip);
  12575. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
  12576. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
  12577. +
  12578. +#endif
  12579. +
  12580. diff -Nur busybox-1.17.1.orig/archival/libipkg/pkg_vec.c busybox-1.17.1/archival/libipkg/pkg_vec.c
  12581. --- busybox-1.17.1.orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
  12582. +++ busybox-1.17.1/archival/libipkg/pkg_vec.c 2010-07-28 13:07:49.660190465 +0200
  12583. @@ -0,0 +1,231 @@
  12584. +/* pkg_vec.c - the itsy package management system
  12585. +
  12586. + Steven M. Ayer
  12587. +
  12588. + Copyright (C) 2002 Compaq Computer Corporation
  12589. +
  12590. + This program is free software; you can redistribute it and/or
  12591. + modify it under the terms of the GNU General Public License as
  12592. + published by the Free Software Foundation; either version 2, or (at
  12593. + your option) any later version.
  12594. +
  12595. + This program is distributed in the hope that it will be useful, but
  12596. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12597. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12598. + General Public License for more details.
  12599. +*/
  12600. +
  12601. +#include <stdlib.h>
  12602. +#include <fnmatch.h>
  12603. +#include "libbb.h"
  12604. +#include "xregex.h"
  12605. +#include "ipkg.h"
  12606. +#include "pkg.h"
  12607. +
  12608. +pkg_vec_t * pkg_vec_alloc(void)
  12609. +{
  12610. + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
  12611. + if (!vec) {
  12612. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12613. + return NULL;
  12614. + }
  12615. + vec->pkgs = NULL;
  12616. + vec->len = 0;
  12617. +
  12618. + return vec;
  12619. +}
  12620. +
  12621. +void pkg_vec_free(pkg_vec_t *vec)
  12622. +{
  12623. + free(vec->pkgs);
  12624. + free(vec);
  12625. +}
  12626. +
  12627. +/*
  12628. + * assumption: all names in a vector are identical
  12629. + * assumption: all version strings are trimmed,
  12630. + * so identical versions have identical version strings,
  12631. + * implying identical packages; let's marry these
  12632. + */
  12633. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  12634. +{
  12635. + int i;
  12636. + int found = 0;
  12637. +
  12638. + /* look for a duplicate pkg by name, version, and architecture */
  12639. + for (i = 0; i < vec->len; i++){
  12640. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
  12641. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
  12642. + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
  12643. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12644. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12645. + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
  12646. + found = 1;
  12647. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
  12648. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12649. + break;
  12650. + }
  12651. + }
  12652. +
  12653. + /* we didn't find one, add it */
  12654. + if (!found){
  12655. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
  12656. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12657. +
  12658. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12659. + vec->pkgs[vec->len] = pkg;
  12660. + vec->len++;
  12661. + return pkg;
  12662. + }
  12663. + /* update the one that we have */
  12664. + else {
  12665. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
  12666. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12667. + if (set_status) {
  12668. + /* this is from the status file, so need to merge with existing database */
  12669. + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
  12670. + pkg_merge(vec->pkgs[i], pkg, set_status);
  12671. + /* XXX: CLEANUP: It's not so polite to free something here
  12672. + that was passed in from above. */
  12673. + pkg_deinit(pkg);
  12674. + free(pkg);
  12675. + } else {
  12676. + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
  12677. + /* just overwrite the old one */
  12678. + pkg_deinit(vec->pkgs[i]);
  12679. + free(vec->pkgs[i]);
  12680. + vec->pkgs[i] = pkg;
  12681. + }
  12682. + return vec->pkgs[i];
  12683. + }
  12684. +}
  12685. +
  12686. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
  12687. +{
  12688. + int i;
  12689. + int found = 0;
  12690. +
  12691. + /* look for a duplicate pkg by name, version, and architecture */
  12692. + for (i = 0; i < vec->len; i++)
  12693. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12694. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12695. + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
  12696. + found = 1;
  12697. + break;
  12698. + }
  12699. +
  12700. + /* we didn't find one, add it */
  12701. + if(!found){
  12702. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12703. + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
  12704. + vec->len++;
  12705. + }
  12706. +}
  12707. +
  12708. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
  12709. +{
  12710. + int i;
  12711. + for (i = 0; i < vec->len; i++)
  12712. + if (vec->pkgs[i] == apkg)
  12713. + return 1;
  12714. + return 0;
  12715. +}
  12716. +
  12717. +typedef int (*compare_fcn_t)(const void *, const void *);
  12718. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
  12719. +{
  12720. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12721. +}
  12722. +
  12723. +int pkg_vec_clear_marks(pkg_vec_t *vec)
  12724. +{
  12725. + int npkgs = vec->len;
  12726. + int i;
  12727. + for (i = 0; i < npkgs; i++) {
  12728. + pkg_t *pkg = vec->pkgs[i];
  12729. + pkg->state_flag &= ~SF_MARKED;
  12730. + }
  12731. + return 0;
  12732. +}
  12733. +
  12734. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
  12735. +{
  12736. + int matching_count = 0;
  12737. + pkg_t **pkgs = vec->pkgs;
  12738. + int npkgs = vec->len;
  12739. + int i;
  12740. + for (i = 0; i < npkgs; i++) {
  12741. + pkg_t *pkg = pkgs[i];
  12742. + if (fnmatch(pattern, pkg->name, 0)==0) {
  12743. + pkg->state_flag |= SF_MARKED;
  12744. + matching_count++;
  12745. + }
  12746. + }
  12747. + return matching_count;
  12748. +}
  12749. +
  12750. +
  12751. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
  12752. +{
  12753. + abstract_pkg_vec_t * vec ;
  12754. + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
  12755. + if (!vec) {
  12756. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12757. + return NULL;
  12758. + }
  12759. + vec->pkgs = NULL;
  12760. + vec->len = 0;
  12761. +
  12762. + return vec;
  12763. +}
  12764. +
  12765. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
  12766. +{
  12767. + free(vec->pkgs);
  12768. + free(vec);
  12769. +}
  12770. +
  12771. +/*
  12772. + * assumption: all names in a vector are unique
  12773. + */
  12774. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
  12775. +{
  12776. + int i;
  12777. +
  12778. + /* look for a duplicate pkg by name */
  12779. + for(i = 0; i < vec->len; i++)
  12780. + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12781. + break;
  12782. +
  12783. + /* we didn't find one, add it */
  12784. + if(i == vec->len){
  12785. + vec->pkgs =
  12786. + (abstract_pkg_t **)
  12787. + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
  12788. + vec->pkgs[vec->len] = pkg;
  12789. + vec->len++;
  12790. + }
  12791. +}
  12792. +
  12793. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
  12794. +{
  12795. + if (vec->len > i)
  12796. + return vec->pkgs[i];
  12797. + else
  12798. + return NULL;
  12799. +}
  12800. +
  12801. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
  12802. +{
  12803. + int i;
  12804. + for (i = 0; i < vec->len; i++)
  12805. + if (vec->pkgs[i] == apkg)
  12806. + return 1;
  12807. + return 0;
  12808. +}
  12809. +
  12810. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
  12811. +{
  12812. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12813. +}
  12814. +
  12815. diff -Nur busybox-1.17.1.orig/archival/libipkg/pkg_vec.h busybox-1.17.1/archival/libipkg/pkg_vec.h
  12816. --- busybox-1.17.1.orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
  12817. +++ busybox-1.17.1/archival/libipkg/pkg_vec.h 2010-07-28 13:07:49.663598721 +0200
  12818. @@ -0,0 +1,62 @@
  12819. +/* pkg_vec.h - the itsy package management system
  12820. +
  12821. + Steven M. Ayer
  12822. +
  12823. + Copyright (C) 2002 Compaq Computer Corporation
  12824. +
  12825. + This program is free software; you can redistribute it and/or
  12826. + modify it under the terms of the GNU General Public License as
  12827. + published by the Free Software Foundation; either version 2, or (at
  12828. + your option) any later version.
  12829. +
  12830. + This program is distributed in the hope that it will be useful, but
  12831. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12832. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12833. + General Public License for more details.
  12834. +*/
  12835. +
  12836. +#ifndef PKG_VEC_H
  12837. +#define PKG_VEC_H
  12838. +
  12839. +typedef struct pkg pkg_t;
  12840. +typedef struct abstract_pkg abstract_pkg_t;
  12841. +
  12842. +struct pkg_vec
  12843. +{
  12844. + pkg_t **pkgs;
  12845. + int len;
  12846. +};
  12847. +typedef struct pkg_vec pkg_vec_t;
  12848. +
  12849. +struct abstract_pkg_vec
  12850. +{
  12851. + abstract_pkg_t **pkgs;
  12852. + int len;
  12853. +};
  12854. +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
  12855. +
  12856. +
  12857. +pkg_vec_t * pkg_vec_alloc(void);
  12858. +void pkg_vec_free(pkg_vec_t *vec);
  12859. +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
  12860. +
  12861. +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
  12862. +/* pkg_vec_insert_merge: might munge pkg.
  12863. +* returns the pkg that is in the pkg graph */
  12864. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
  12865. +/* this one never munges pkg */
  12866. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
  12867. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
  12868. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
  12869. +
  12870. +int pkg_vec_clear_marks(pkg_vec_t *vec);
  12871. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
  12872. +
  12873. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
  12874. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
  12875. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
  12876. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
  12877. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
  12878. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
  12879. +#endif
  12880. +
  12881. diff -Nur busybox-1.17.1.orig/archival/libipkg/sprintf_alloc.h busybox-1.17.1/archival/libipkg/sprintf_alloc.h
  12882. --- busybox-1.17.1.orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
  12883. +++ busybox-1.17.1/archival/libipkg/sprintf_alloc.h 2010-07-28 13:07:49.663598721 +0200
  12884. @@ -0,0 +1,25 @@
  12885. +/* sprintf_alloca.c -- like sprintf with memory allocation
  12886. +
  12887. + Carl D. Worth
  12888. +
  12889. + Copyright (C) 2001 University of Southern California
  12890. +
  12891. + This program is free software; you can redistribute it and/or modify
  12892. + it under the terms of the GNU General Public License as published by
  12893. + the Free Software Foundation; either version 2, or (at your option)
  12894. + any later version.
  12895. +
  12896. + This program is distributed in the hope that it will be useful,
  12897. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  12898. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12899. + GNU General Public License for more details.
  12900. +*/
  12901. +
  12902. +#ifndef SPRINTF_ALLOC_H
  12903. +#define SPRINTF_ALLOC_H
  12904. +
  12905. +#include "libbb.h"
  12906. +
  12907. +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
  12908. +
  12909. +#endif
  12910. diff -Nur busybox-1.17.1.orig/archival/libipkg/str_list.c busybox-1.17.1/archival/libipkg/str_list.c
  12911. --- busybox-1.17.1.orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
  12912. +++ busybox-1.17.1/archival/libipkg/str_list.c 2010-07-28 13:07:49.667598672 +0200
  12913. @@ -0,0 +1,76 @@
  12914. +/* str_list.c - the itsy package management system
  12915. +
  12916. + Carl D. Worth
  12917. +
  12918. + Copyright (C) 2001 University of Southern California
  12919. +
  12920. + This program is free software; you can redistribute it and/or
  12921. + modify it under the terms of the GNU General Public License as
  12922. + published by the Free Software Foundation; either version 2, or (at
  12923. + your option) any later version.
  12924. +
  12925. + This program is distributed in the hope that it will be useful, but
  12926. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12927. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12928. + General Public License for more details.
  12929. +*/
  12930. +
  12931. +#include "ipkg.h"
  12932. +
  12933. +#include "str_list.h"
  12934. +
  12935. +int str_list_elt_init(str_list_elt_t *elt, char *data)
  12936. +{
  12937. + return void_list_elt_init((void_list_elt_t *) elt, data);
  12938. +}
  12939. +
  12940. +void str_list_elt_deinit(str_list_elt_t *elt)
  12941. +{
  12942. + void_list_elt_deinit((void_list_elt_t *) elt);
  12943. +}
  12944. +
  12945. +str_list_t *str_list_alloc(void)
  12946. +{
  12947. + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
  12948. + if (list)
  12949. + str_list_init(list);
  12950. + return list;
  12951. +}
  12952. +
  12953. +int str_list_init(str_list_t *list)
  12954. +{
  12955. + return void_list_init((void_list_t *) list);
  12956. +}
  12957. +
  12958. +void str_list_deinit(str_list_t *list)
  12959. +{
  12960. + void_list_deinit((void_list_t *) list);
  12961. +}
  12962. +
  12963. +int str_list_append(str_list_t *list, char *data)
  12964. +{
  12965. + return void_list_append((void_list_t *) list, data);
  12966. +}
  12967. +
  12968. +int str_list_push(str_list_t *list, char *data)
  12969. +{
  12970. + return void_list_push((void_list_t *) list, data);
  12971. +}
  12972. +
  12973. +str_list_elt_t *str_list_pop(str_list_t *list)
  12974. +{
  12975. + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
  12976. +}
  12977. +
  12978. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
  12979. +{
  12980. + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
  12981. + (void_list_elt_t **) iter);
  12982. +}
  12983. +
  12984. +char *str_list_remove_elt(str_list_t *list, const char *target_str)
  12985. +{
  12986. + return (char *)void_list_remove_elt((void_list_t *) list,
  12987. + (void *)target_str,
  12988. + (void_list_cmp_t)strcmp);
  12989. +}
  12990. diff -Nur busybox-1.17.1.orig/archival/libipkg/str_list.h busybox-1.17.1/archival/libipkg/str_list.h
  12991. --- busybox-1.17.1.orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
  12992. +++ busybox-1.17.1/archival/libipkg/str_list.h 2010-07-28 13:07:49.667598672 +0200
  12993. @@ -0,0 +1,51 @@
  12994. +/* str_list.h - the itsy package management system
  12995. +
  12996. + Carl D. Worth
  12997. +
  12998. + Copyright (C) 2001 University of Southern California
  12999. +
  13000. + This program is free software; you can redistribute it and/or
  13001. + modify it under the terms of the GNU General Public License as
  13002. + published by the Free Software Foundation; either version 2, or (at
  13003. + your option) any later version.
  13004. +
  13005. + This program is distributed in the hope that it will be useful, but
  13006. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13007. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13008. + General Public License for more details.
  13009. +*/
  13010. +
  13011. +#ifndef STR_LIST_H
  13012. +#define STR_LIST_H
  13013. +
  13014. +#include "void_list.h"
  13015. +
  13016. +typedef struct str_list_elt str_list_elt_t;
  13017. +struct str_list_elt
  13018. +{
  13019. + str_list_elt_t *next;
  13020. + char *data;
  13021. +};
  13022. +
  13023. +typedef struct xstr_list str_list_t;
  13024. +struct xstr_list
  13025. +{
  13026. + str_list_elt_t pre_head;
  13027. + str_list_elt_t *head;
  13028. + str_list_elt_t *tail;
  13029. +};
  13030. +
  13031. +int str_list_elt_init(str_list_elt_t *elt, char *data);
  13032. +void str_list_elt_deinit(str_list_elt_t *elt);
  13033. +
  13034. +str_list_t *str_list_alloc(void);
  13035. +int str_list_init(str_list_t *list);
  13036. +void str_list_deinit(str_list_t *list);
  13037. +
  13038. +int str_list_append(str_list_t *list, char *data);
  13039. +int str_list_push(str_list_t *list, char *data);
  13040. +str_list_elt_t *str_list_pop(str_list_t *list);
  13041. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
  13042. +char *str_list_remove_elt(str_list_t *list, const char *target_str);
  13043. +
  13044. +#endif
  13045. diff -Nur busybox-1.17.1.orig/archival/libipkg/str_util.c busybox-1.17.1/archival/libipkg/str_util.c
  13046. --- busybox-1.17.1.orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
  13047. +++ busybox-1.17.1/archival/libipkg/str_util.c 2010-07-28 13:07:49.671598344 +0200
  13048. @@ -0,0 +1,69 @@
  13049. +/* str_utils.c - the itsy package management system
  13050. +
  13051. + Carl D. Worth
  13052. +
  13053. + Copyright (C) 2001 University of Southern California
  13054. +
  13055. + This program is free software; you can redistribute it and/or
  13056. + modify it under the terms of the GNU General Public License as
  13057. + published by the Free Software Foundation; either version 2, or (at
  13058. + your option) any later version.
  13059. +
  13060. + This program is distributed in the hope that it will be useful, but
  13061. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13062. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13063. + General Public License for more details.
  13064. +*/
  13065. +
  13066. +#include "ipkg.h"
  13067. +
  13068. +int str_starts_with(const char *str, const char *prefix);
  13069. +int str_ends_with(const char *str, const char *suffix);
  13070. +int str_chomp(char *str);
  13071. +int str_toupper(char *str);
  13072. +char *str_dup_safe(const char *str);
  13073. +
  13074. +int str_starts_with(const char *str, const char *prefix)
  13075. +{
  13076. + return (strncmp(str, prefix, strlen(prefix)) == 0);
  13077. +}
  13078. +
  13079. +int str_ends_with(const char *str, const char *suffix)
  13080. +{
  13081. + int suffix_len;
  13082. + int str_len;
  13083. +
  13084. + str_len = strlen(str);
  13085. + suffix_len = strlen(suffix);
  13086. +
  13087. + if (str_len < suffix_len) {
  13088. + return 0;
  13089. + }
  13090. +
  13091. + return (strcmp(str + str_len - suffix_len, suffix) == 0);
  13092. +}
  13093. +
  13094. +int str_chomp(char *str)
  13095. +{
  13096. + if (str[strlen(str) - 1] == '\n') {
  13097. + str[strlen(str) - 1] = '\0';
  13098. + return 1;
  13099. + }
  13100. + return 0;
  13101. +}
  13102. +
  13103. +int str_toupper(char *str)
  13104. +{
  13105. + while (*str) {
  13106. + *str = toupper(*str);
  13107. + str++;
  13108. + }
  13109. +
  13110. + return 0;
  13111. +}
  13112. +
  13113. +char *str_dup_safe(const char *str)
  13114. +{
  13115. + return str ? strdup(str) : NULL;
  13116. +}
  13117. +
  13118. diff -Nur busybox-1.17.1.orig/archival/libipkg/str_util.h busybox-1.17.1/archival/libipkg/str_util.h
  13119. --- busybox-1.17.1.orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
  13120. +++ busybox-1.17.1/archival/libipkg/str_util.h 2010-07-28 13:07:49.671598344 +0200
  13121. @@ -0,0 +1,27 @@
  13122. +/* str_utils.h - the itsy package management system
  13123. +
  13124. + Carl D. Worth
  13125. +
  13126. + Copyright (C) 2001 University of Southern California
  13127. +
  13128. + This program is free software; you can redistribute it and/or
  13129. + modify it under the terms of the GNU General Public License as
  13130. + published by the Free Software Foundation; either version 2, or (at
  13131. + your option) any later version.
  13132. +
  13133. + This program is distributed in the hope that it will be useful, but
  13134. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13135. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13136. + General Public License for more details.
  13137. +*/
  13138. +
  13139. +#ifndef STR_UTILS_H
  13140. +#define STR_UTILS_H
  13141. +
  13142. +int str_starts_with(const char *str, const char *prefix);
  13143. +int str_ends_with(const char *str, const char *suffix);
  13144. +int str_chomp(char *str);
  13145. +int str_toupper(char *str);
  13146. +char *str_dup_safe(const char *str);
  13147. +
  13148. +#endif
  13149. diff -Nur busybox-1.17.1.orig/archival/libipkg/user.c busybox-1.17.1/archival/libipkg/user.c
  13150. --- busybox-1.17.1.orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
  13151. +++ busybox-1.17.1/archival/libipkg/user.c 2010-07-28 13:07:49.671598344 +0200
  13152. @@ -0,0 +1,49 @@
  13153. +/* user.c - the itsy package management system
  13154. +
  13155. + Jamey Hicks
  13156. +
  13157. + Copyright (C) 2002 Hewlett Packard Company
  13158. + Copyright (C) 2001 University of Southern California
  13159. +
  13160. + This program is free software; you can redistribute it and/or
  13161. + modify it under the terms of the GNU General Public License as
  13162. + published by the Free Software Foundation; either version 2, or (at
  13163. + your option) any later version.
  13164. +
  13165. + This program is distributed in the hope that it will be useful, but
  13166. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13167. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13168. + General Public License for more details.
  13169. +*/
  13170. +
  13171. +#include <stdio.h>
  13172. +#include <stdarg.h>
  13173. +#include "libbb.h"
  13174. +#include "file_util.h"
  13175. +#include "str_util.h"
  13176. +#include "libipkg.h"
  13177. +
  13178. +char *get_user_response(const char *format, ...);
  13179. +static char *question = NULL;
  13180. +static int question_len = 255;
  13181. +
  13182. +char *get_user_response(const char *format, ...)
  13183. +{
  13184. + int len = question_len;
  13185. + va_list ap;
  13186. + char *response;
  13187. + va_start(ap, format);
  13188. +
  13189. + do {
  13190. + if (question == NULL || len > question_len) {
  13191. + question = realloc(question, len + 1);
  13192. + question_len = len;
  13193. + }
  13194. + len = vsnprintf(question,question_len,format,ap);
  13195. + } while (len > question_len);
  13196. + response = strdup(ipkg_cb_response(question));
  13197. + str_chomp(response);
  13198. + str_tolower(response);
  13199. +
  13200. + return response;
  13201. +}
  13202. diff -Nur busybox-1.17.1.orig/archival/libipkg/user.h busybox-1.17.1/archival/libipkg/user.h
  13203. --- busybox-1.17.1.orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
  13204. +++ busybox-1.17.1/archival/libipkg/user.h 2010-07-28 13:07:49.675598296 +0200
  13205. @@ -0,0 +1,23 @@
  13206. +/* user.c - the itsy package management system
  13207. +
  13208. + Jamey Hicks
  13209. +
  13210. + Copyright (C) 2002 Hewlett Packard Company
  13211. + Copyright (C) 2001 University of Southern California
  13212. +
  13213. + This program is free software; you can redistribute it and/or
  13214. + modify it under the terms of the GNU General Public License as
  13215. + published by the Free Software Foundation; either version 2, or (at
  13216. + your option) any later version.
  13217. +
  13218. + This program is distributed in the hope that it will be useful, but
  13219. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13220. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13221. + General Public License for more details.
  13222. +*/
  13223. +
  13224. +#include <stdio.h>
  13225. +#include <stdarg.h>
  13226. +
  13227. +char *get_user_response(const char *format, ...);
  13228. +
  13229. diff -Nur busybox-1.17.1.orig/archival/libipkg/void_list.c busybox-1.17.1/archival/libipkg/void_list.c
  13230. --- busybox-1.17.1.orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
  13231. +++ busybox-1.17.1/archival/libipkg/void_list.c 2010-07-28 13:07:49.675598296 +0200
  13232. @@ -0,0 +1,194 @@
  13233. +/* void_list.c - the itsy package management system
  13234. +
  13235. + Carl D. Worth
  13236. +
  13237. + Copyright (C) 2001 University of Southern California
  13238. +
  13239. + This program is free software; you can redistribute it and/or
  13240. + modify it under the terms of the GNU General Public License as
  13241. + published by the Free Software Foundation; either version 2, or (at
  13242. + your option) any later version.
  13243. +
  13244. + This program is distributed in the hope that it will be useful, but
  13245. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13246. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13247. + General Public License for more details.
  13248. +*/
  13249. +
  13250. +#include "ipkg.h"
  13251. +#include <errno.h>
  13252. +
  13253. +#include "void_list.h"
  13254. +
  13255. +int void_list_elt_init(void_list_elt_t *elt, void *data)
  13256. +{
  13257. + elt->next = NULL;
  13258. + elt->data = data;
  13259. +
  13260. + return 0;
  13261. +}
  13262. +
  13263. +void void_list_elt_deinit(void_list_elt_t *elt)
  13264. +{
  13265. + void_list_elt_init(elt, NULL);
  13266. +}
  13267. +
  13268. +int void_list_init(void_list_t *list)
  13269. +{
  13270. + void_list_elt_init(&list->pre_head, NULL);
  13271. + list->head = NULL;
  13272. + list->pre_head.next = list->head;
  13273. + list->tail = NULL;
  13274. +
  13275. + return 0;
  13276. +}
  13277. +
  13278. +void void_list_deinit(void_list_t *list)
  13279. +{
  13280. + void_list_elt_t *elt;
  13281. +
  13282. + while (list->head) {
  13283. + elt = void_list_pop(list);
  13284. + void_list_elt_deinit(elt);
  13285. + /* malloced in void_list_append */
  13286. + free(elt);
  13287. + }
  13288. +}
  13289. +
  13290. +int void_list_append(void_list_t *list, void *data)
  13291. +{
  13292. + void_list_elt_t *elt;
  13293. +
  13294. + /* freed in void_list_deinit */
  13295. + elt = malloc(sizeof(void_list_elt_t));
  13296. + if (elt == NULL) {
  13297. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13298. + return ENOMEM;
  13299. + }
  13300. +
  13301. + void_list_elt_init(elt, data);
  13302. +
  13303. + if (list->tail) {
  13304. + list->tail->next = elt;
  13305. + list->tail = elt;
  13306. + } else {
  13307. + list->head = elt;
  13308. + list->pre_head.next = list->head;
  13309. + list->tail = elt;
  13310. + }
  13311. +
  13312. + return 0;
  13313. +}
  13314. +
  13315. +int void_list_push(void_list_t *list, void *data)
  13316. +{
  13317. + void_list_elt_t *elt;
  13318. +
  13319. + elt = malloc(sizeof(void_list_elt_t));
  13320. + if (elt == NULL) {
  13321. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13322. + return ENOMEM;
  13323. + }
  13324. +
  13325. + void_list_elt_init(elt, data);
  13326. +
  13327. + elt->next = list->head;
  13328. + list->head->next = elt;
  13329. + if (list->tail == NULL) {
  13330. + list->tail = list->head;
  13331. + }
  13332. +
  13333. + return 0;
  13334. +}
  13335. +
  13336. +void_list_elt_t *void_list_pop(void_list_t *list)
  13337. +{
  13338. + void_list_elt_t *elt;
  13339. +
  13340. + elt = list->head;
  13341. +
  13342. + if (list->head) {
  13343. + list->head = list->head->next;
  13344. + list->pre_head.next = list->head;
  13345. + if (list->head == NULL) {
  13346. + list->tail = NULL;
  13347. + }
  13348. + }
  13349. +
  13350. + return elt;
  13351. +}
  13352. +
  13353. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
  13354. +{
  13355. + void_list_elt_t *prior;
  13356. + void_list_elt_t *old_elt;
  13357. + void *old_data;
  13358. +
  13359. + old_elt = *iter;
  13360. + old_data = old_elt->data;
  13361. +
  13362. + if (old_elt == list->head) {
  13363. + prior = &list->pre_head;
  13364. + void_list_pop(list);
  13365. + } else {
  13366. + for (prior = list->head; prior; prior = prior->next) {
  13367. + if (prior->next == old_elt) {
  13368. + break;
  13369. + }
  13370. + }
  13371. + if (prior == NULL || prior->next != old_elt) {
  13372. + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
  13373. + return NULL;
  13374. + }
  13375. + prior->next = old_elt->next;
  13376. +
  13377. + if (old_elt == list->tail) {
  13378. + list->tail = prior;
  13379. + }
  13380. + }
  13381. +
  13382. + void_list_elt_deinit(old_elt);
  13383. + *iter = prior;
  13384. +
  13385. + return old_data;
  13386. +}
  13387. +
  13388. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13389. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
  13390. +{
  13391. + void_list_elt_t *prior;
  13392. + void_list_elt_t *old_elt = NULL;
  13393. + void *old_data = NULL;
  13394. +
  13395. + /* first element */
  13396. + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
  13397. + old_elt = list->head;
  13398. + old_data = list->head->data;
  13399. + void_list_pop(list);
  13400. + } else {
  13401. + int found = 0;
  13402. + for (prior = list->head; prior && prior->next; prior = prior->next) {
  13403. + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
  13404. + old_elt = prior->next;
  13405. + old_data = old_elt->data;
  13406. + found = 1;
  13407. + break;
  13408. + }
  13409. + }
  13410. + if (!found) {
  13411. + return NULL;
  13412. + }
  13413. + prior->next = old_elt->next;
  13414. +
  13415. + if (old_elt == list->tail) {
  13416. + list->tail = prior;
  13417. + }
  13418. + }
  13419. + if (old_elt)
  13420. + void_list_elt_deinit(old_elt);
  13421. +
  13422. + if (old_data)
  13423. + return old_data;
  13424. + else
  13425. + return NULL;
  13426. +}
  13427. diff -Nur busybox-1.17.1.orig/archival/libipkg/void_list.h busybox-1.17.1/archival/libipkg/void_list.h
  13428. --- busybox-1.17.1.orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
  13429. +++ busybox-1.17.1/archival/libipkg/void_list.h 2010-07-28 13:07:49.675598296 +0200
  13430. @@ -0,0 +1,59 @@
  13431. +/* void_list.h - the itsy package management system
  13432. +
  13433. + Carl D. Worth
  13434. +
  13435. + Copyright (C) 2001 University of Southern California
  13436. +
  13437. + This program is free software; you can redistribute it and/or
  13438. + modify it under the terms of the GNU General Public License as
  13439. + published by the Free Software Foundation; either version 2, or (at
  13440. + your option) any later version.
  13441. +
  13442. + This program is distributed in the hope that it will be useful, but
  13443. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13444. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13445. + General Public License for more details.
  13446. +*/
  13447. +
  13448. +#ifndef VOID_LIST_H
  13449. +#define VOID_LIST_H
  13450. +
  13451. +typedef struct void_list_elt void_list_elt_t;
  13452. +struct void_list_elt
  13453. +{
  13454. + void_list_elt_t *next;
  13455. + void *data;
  13456. +};
  13457. +
  13458. +typedef struct void_list void_list_t;
  13459. +struct void_list
  13460. +{
  13461. + void_list_elt_t pre_head;
  13462. + void_list_elt_t *head;
  13463. + void_list_elt_t *tail;
  13464. +};
  13465. +
  13466. +static inline int void_list_empty(void_list_t *list)
  13467. +{
  13468. + if (list->head == NULL)
  13469. + return 1;
  13470. + else
  13471. + return 0;
  13472. +}
  13473. +
  13474. +int void_list_elt_init(void_list_elt_t *elt, void *data);
  13475. +void void_list_elt_deinit(void_list_elt_t *elt);
  13476. +
  13477. +int void_list_init(void_list_t *list);
  13478. +void void_list_deinit(void_list_t *list);
  13479. +
  13480. +int void_list_append(void_list_t *list, void *data);
  13481. +int void_list_push(void_list_t *list, void *data);
  13482. +void_list_elt_t *void_list_pop(void_list_t *list);
  13483. +
  13484. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
  13485. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13486. +typedef int (*void_list_cmp_t)(const void *, const void *);
  13487. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
  13488. +
  13489. +#endif
  13490. diff -Nur busybox-1.17.1.orig/archival/libipkg/xsystem.c busybox-1.17.1/archival/libipkg/xsystem.c
  13491. --- busybox-1.17.1.orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
  13492. +++ busybox-1.17.1/archival/libipkg/xsystem.c 2010-07-28 13:07:49.675598296 +0200
  13493. @@ -0,0 +1,64 @@
  13494. +/* xsystem.c - system(3) with error messages
  13495. +
  13496. + Carl D. Worth
  13497. +
  13498. + Copyright (C) 2001 University of Southern California
  13499. +
  13500. + This program is free software; you can redistribute it and/or
  13501. + modify it under the terms of the GNU General Public License as
  13502. + published by the Free Software Foundation; either version 2, or (at
  13503. + your option) any later version.
  13504. +
  13505. + This program is distributed in the hope that it will be useful, but
  13506. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13507. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13508. + General Public License for more details.
  13509. +*/
  13510. +
  13511. +#include "ipkg.h"
  13512. +#include <sys/wait.h>
  13513. +
  13514. +#include "xsystem.h"
  13515. +
  13516. +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
  13517. + really need the /bin/sh invocation which takes resources and
  13518. + introduces security problems. I should switch all of this to a sort
  13519. + of execl() or execv() interface/implementation.
  13520. +*/
  13521. +
  13522. +/* Like system(3), but with error messages printed if the fork fails
  13523. + or if the child process dies due to an uncaught signal. Also, the
  13524. + return value is a bit simpler:
  13525. +
  13526. + -1 if there was any problem
  13527. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13528. + as defined in <sys/wait.h>.
  13529. +*/
  13530. +int xsystem(const char *cmd)
  13531. +{
  13532. + int err;
  13533. +
  13534. + err = system(cmd);
  13535. +
  13536. + if (err == -1) {
  13537. + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
  13538. + __FUNCTION__, cmd);
  13539. + return -1;
  13540. + }
  13541. +
  13542. + if (WIFSIGNALED(err)) {
  13543. + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
  13544. + __FUNCTION__, WTERMSIG(err), cmd);
  13545. + return -1;
  13546. + }
  13547. +
  13548. + if (WIFEXITED(err)) {
  13549. + /* Normal child exit */
  13550. + return WEXITSTATUS(err);
  13551. + }
  13552. +
  13553. + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
  13554. + __FUNCTION__, err);
  13555. + return -1;
  13556. +}
  13557. +
  13558. diff -Nur busybox-1.17.1.orig/archival/libipkg/xsystem.h busybox-1.17.1/archival/libipkg/xsystem.h
  13559. --- busybox-1.17.1.orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
  13560. +++ busybox-1.17.1/archival/libipkg/xsystem.h 2010-07-28 13:07:49.675598296 +0200
  13561. @@ -0,0 +1,34 @@
  13562. +/* xsystem.h - system(3) with error messages
  13563. +
  13564. + Carl D. Worth
  13565. +
  13566. + Copyright (C) 2001 University of Southern California
  13567. +
  13568. + This program is free software; you can redistribute it and/or
  13569. + modify it under the terms of the GNU General Public License as
  13570. + published by the Free Software Foundation; either version 2, or (at
  13571. + your option) any later version.
  13572. +
  13573. + This program is distributed in the hope that it will be useful, but
  13574. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13575. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13576. + General Public License for more details.
  13577. +*/
  13578. +
  13579. +#ifndef XSYSTEM_H
  13580. +#define XSYSTEM_H
  13581. +
  13582. +#include <stdlib.h>
  13583. +
  13584. +/* Like system(3), but with error messages printed if the fork fails
  13585. + or if the child process dies due to an uncaught signal. Also, the
  13586. + return value is a bit simpler:
  13587. +
  13588. + -1 if there was any problem
  13589. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13590. + as defined in <sys/wait.h>.
  13591. +*/
  13592. +int xsystem(const char *cmd);
  13593. +
  13594. +#endif
  13595. +
  13596. diff -Nur busybox-1.17.1.orig/archival/libunarchive/Kbuild.src busybox-1.17.1/archival/libunarchive/Kbuild.src
  13597. --- busybox-1.17.1.orig/archival/libunarchive/Kbuild.src 2010-07-06 04:25:53.000000000 +0200
  13598. +++ busybox-1.17.1/archival/libunarchive/Kbuild.src 2010-07-28 13:07:49.675598296 +0200
  13599. @@ -43,6 +43,7 @@
  13600. lib-$(CONFIG_DPKG) += $(DPKG_FILES)
  13601. lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
  13602. lib-$(CONFIG_GUNZIP) += decompress_unzip.o
  13603. +lib-$(CONFIG_IPKG) += open_transformer.o get_header_tar.o get_header_tar_gz.o
  13604. lib-$(CONFIG_RPM2CPIO) += decompress_unzip.o get_header_cpio.o
  13605. lib-$(CONFIG_RPM) += open_transformer.o decompress_unzip.o get_header_cpio.o
  13606. lib-$(CONFIG_TAR) += get_header_tar.o
  13607. diff -Nur busybox-1.17.1.orig/include/applets.src.h busybox-1.17.1/include/applets.src.h
  13608. --- busybox-1.17.1.orig/include/applets.src.h 2010-07-25 00:12:43.000000000 +0200
  13609. +++ busybox-1.17.1/include/applets.src.h 2010-07-28 13:07:49.679607187 +0200
  13610. @@ -209,6 +209,7 @@
  13611. IF_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_DROP))
  13612. IF_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
  13613. IF_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
  13614. +IF_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_DROP))
  13615. IF_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_DROP))
  13616. IF_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_DROP))
  13617. IF_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_DROP))
  13618. diff -Nur busybox-1.17.1.orig/include/unarchive.h busybox-1.17.1/include/unarchive.h
  13619. --- busybox-1.17.1.orig/include/unarchive.h 2010-07-06 04:25:54.000000000 +0200
  13620. +++ busybox-1.17.1/include/unarchive.h 2010-07-28 13:07:49.679607187 +0200
  13621. @@ -76,7 +76,7 @@
  13622. off_t offset;
  13623. /* Archiver specific. Can make it a union if it ever gets big */
  13624. -#if ENABLE_TAR || ENABLE_DPKG || ENABLE_DPKG_DEB
  13625. +#if ENABLE_TAR || ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13626. smallint tar__end;
  13627. # if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
  13628. char* tar__longname;
  13629. @@ -95,7 +95,7 @@
  13630. struct hardlinks_t *cpio__hardlinks_to_create;
  13631. struct hardlinks_t *cpio__created_hardlinks;
  13632. #endif
  13633. -#if ENABLE_DPKG || ENABLE_DPKG_DEB
  13634. +#if ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13635. /* Temporary storage */
  13636. char *dpkg__buffer;
  13637. /* How to process any sub archive, e.g. get_header_tar_gz */
  13638. diff -Nur busybox-1.17.1.orig/include/usage.src.h busybox-1.17.1/include/usage.src.h
  13639. --- busybox-1.17.1.orig/include/usage.src.h 2010-07-25 00:12:43.000000000 +0200
  13640. +++ busybox-1.17.1/include/usage.src.h 2010-07-28 13:07:49.683599037 +0200
  13641. @@ -1556,6 +1556,82 @@
  13642. "$ ls -la /tmp/busybox*\n" \
  13643. "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
  13644. +#define ipkg_trivial_usage \
  13645. + "[options]... sub-command [arguments]..."
  13646. +#define ipkg_full_usage \
  13647. + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
  13648. + "\n" \
  13649. + "Sub-commands:\n" \
  13650. + "\nPackage Manipulation:\n" \
  13651. + "\tupdate Update list of available packages\n" \
  13652. + "\tupgrade Upgrade all installed packages to latest version\n" \
  13653. + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
  13654. + "\tinstall <file.ipk> Install package <file.ipk>\n" \
  13655. + "\tconfigure [<pkg>] Configure unpacked packages\n" \
  13656. + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
  13657. + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
  13658. + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
  13659. + "\n" \
  13660. + "Informational Commands:\n" \
  13661. + "\tlist List available packages and descriptions\n" \
  13662. + "\tlist_installed List all and only the installed packages and description \n" \
  13663. + "\tfiles <pkg> List all files belonging to <pkg>\n" \
  13664. + "\tsearch <file|regexp> Search for a package providing <file>\n" \
  13665. + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
  13666. + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
  13667. + "\tdownload <pkg> Download <pkg> to current directory.\n" \
  13668. + "\tcompare_versions <v1> <op> <v2>\n" \
  13669. + "\t compare versions using <= < > >= = << >>\n" \
  13670. + "\tprint_architecture prints the architecture.\n" \
  13671. + "\tprint_installation_architecture\n" \
  13672. + "\twhatdepends [-A] [pkgname|pat]+\n" \
  13673. + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
  13674. + "\twhatprovides [-A] [pkgname|pat]+\n" \
  13675. + "\twhatconflicts [-A] [pkgname|pat]+\n" \
  13676. + "\twhatreplaces [-A] [pkgname|pat]+\n" \
  13677. + "\t prints the installation architecture.\n" \
  13678. + "\n" \
  13679. + "\nOptions:\n" \
  13680. + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
  13681. + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
  13682. + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
  13683. + "\t 0 errors only\n" \
  13684. + "\t 1 normal messages (default)\n" \
  13685. + "\t 2 informative messages\n" \
  13686. + "\t 3 debug output\n" \
  13687. + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
  13688. + "\t-conf <conf_file> Default configuration file location\n" \
  13689. + " is /etc/ipkg.conf\n" \
  13690. + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
  13691. + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
  13692. + " <dest_name> should be a defined dest name from\n" \
  13693. + " the configuration file, (but can also be a\n" \
  13694. + " directory name in a pinch).\n" \
  13695. + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
  13696. + "\t-offline <offline_root> offline installation of packages.\n" \
  13697. + "\t-verbose_wget more wget messages\n" \
  13698. + "\n" \
  13699. + "Force Options (use when ipkg is too smart for its own good):\n" \
  13700. + "\t-force-depends Make dependency checks warnings instead of errors\n" \
  13701. + "\t Install/remove package in spite of failed dependences\n" \
  13702. + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
  13703. + " (no prompts). Note that this will not prevent\n" \
  13704. + " package installation scripts from prompting.\n" \
  13705. + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
  13706. + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
  13707. + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
  13708. + "\t-force_space Install even if there does not seem to be enough space.\n" \
  13709. + "\t-noaction No action -- test only\n" \
  13710. + "\t-nodeps Do not follow dependences\n" \
  13711. + "\t-force-removal-of-dependent-packages\n" \
  13712. + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
  13713. + "\t-test No action -- test only\n" \
  13714. + "\t-t Specify tmp-dir.\n" \
  13715. + "\t--tmp-dir Specify tmp-dir.\n" \
  13716. + "\n" \
  13717. + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
  13718. + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
  13719. +
  13720. #define halt_trivial_usage \
  13721. "[-d DELAY] [-n] [-f]" IF_FEATURE_WTMP(" [-w]")
  13722. #define halt_full_usage "\n\n" \
  13723. diff -Nur busybox-1.17.1.orig/Makefile busybox-1.17.1/Makefile
  13724. --- busybox-1.17.1.orig/Makefile 2010-07-25 00:13:44.000000000 +0200
  13725. +++ busybox-1.17.1/Makefile 2010-07-28 13:07:49.683599037 +0200
  13726. @@ -459,6 +459,7 @@
  13727. libs-y := \
  13728. archival/ \
  13729. + archival/libipkg/ \
  13730. archival/libunarchive/ \
  13731. console-tools/ \
  13732. coreutils/ \