001-ipkg.patch 423 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717
  1. diff -Nur busybox-1.18.1.orig/Makefile busybox-1.18.1/Makefile
  2. --- busybox-1.18.1.orig/Makefile 2010-12-21 05:31:43.000000000 +0100
  3. +++ busybox-1.18.1/Makefile 2010-12-25 22:38:55.000000000 +0100
  4. @@ -465,6 +465,7 @@
  5. libs-y := \
  6. archival/ \
  7. archival/libarchive/ \
  8. + archival/libipkg/ \
  9. console-tools/ \
  10. coreutils/ \
  11. coreutils/libcoreutils/ \
  12. diff -Nur busybox-1.18.1.orig/archival/Config.src busybox-1.18.1/archival/Config.src
  13. --- busybox-1.18.1.orig/archival/Config.src 2010-12-20 01:41:26.000000000 +0100
  14. +++ busybox-1.18.1/archival/Config.src 2010-12-25 22:38:07.000000000 +0100
  15. @@ -202,6 +202,12 @@
  16. are actually slower than gzip at equivalent compression ratios
  17. and take up 3.2K of code.
  18. +config IPKG
  19. + bool "ipkg"
  20. + default n
  21. + help
  22. + ipkg is the itsy package management system.
  23. +
  24. config RPM2CPIO
  25. bool "rpm2cpio"
  26. default y
  27. diff -Nur busybox-1.18.1.orig/archival/Kbuild.src busybox-1.18.1/archival/Kbuild.src
  28. --- busybox-1.18.1.orig/archival/Kbuild.src 2010-12-20 01:41:26.000000000 +0100
  29. +++ busybox-1.18.1/archival/Kbuild.src 2010-12-25 22:38:07.000000000 +0100
  30. @@ -22,6 +22,7 @@
  31. lib-$(CONFIG_LZOP) += lzop.o bbunzip.o
  32. lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
  33. lib-$(CONFIG_BZIP2) += bzip2.o bbunzip.o
  34. +lib-$(CONFIG_IPKG) += ipkg.o
  35. lib-$(CONFIG_UNXZ) += bbunzip.o
  36. lib-$(CONFIG_UNLZMA) += bbunzip.o
  37. diff -Nur busybox-1.18.1.orig/archival/ipkg.c busybox-1.18.1/archival/ipkg.c
  38. --- busybox-1.18.1.orig/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
  39. +++ busybox-1.18.1/archival/ipkg.c 2010-12-25 22:38:07.000000000 +0100
  40. @@ -0,0 +1,28 @@
  41. +/* ipkg.c - the itsy package management system
  42. +
  43. + Florina Boor
  44. +
  45. + Copyright (C) 2003 kernel concepts
  46. +
  47. + This program is free software; you can redistribute it and/or
  48. + modify it under the terms of the GNU General Public License as
  49. + published by the Free Software Foundation; either version 2, or (at
  50. + your option) any later version.
  51. +
  52. + This program is distributed in the hope that it will be useful, but
  53. + WITHOUT ANY WARRANTY; without even the implied warranty of
  54. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  55. + General Public License for more details.
  56. +
  57. + ipkg command line frontend using libipkg
  58. +
  59. +*/
  60. +
  61. +#include "libbb.h"
  62. +#include "libipkg/libipkg.h"
  63. +
  64. +int ipkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  65. +int ipkg_main(int argc, char **argv)
  66. +{
  67. + return ipkg_op(argc, argv);
  68. +}
  69. diff -Nur busybox-1.18.1.orig/archival/libipkg/Kbuild busybox-1.18.1/archival/libipkg/Kbuild
  70. --- busybox-1.18.1.orig/archival/libipkg/Kbuild 1970-01-01 01:00:00.000000000 +0100
  71. +++ busybox-1.18.1/archival/libipkg/Kbuild 2010-12-25 22:38:07.000000000 +0100
  72. @@ -0,0 +1,60 @@
  73. +# Makefile for busybox
  74. +#
  75. +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  76. +# Copyright (C) 2006 OpenWrt.org
  77. +#
  78. +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  79. +
  80. +LIBIPKG_CORE_OBJS:= \
  81. + args.o \
  82. + libipkg.o \
  83. + user.o \
  84. +
  85. +LIBIPKG_CMD_OBJS:= \
  86. + ipkg_cmd.o \
  87. + ipkg_configure.o \
  88. + ipkg_download.o \
  89. + ipkg_install.o \
  90. + ipkg_remove.o \
  91. + ipkg_upgrade.o \
  92. +
  93. +LIBIPKG_DB_OBJS:= \
  94. + hash_table.o \
  95. + ipkg_conf.o \
  96. + ipkg_utils.o \
  97. + pkg.o \
  98. + pkg_depends.o \
  99. + pkg_extract.o \
  100. + pkg_hash.o \
  101. + pkg_parse.o \
  102. + pkg_vec.o \
  103. +
  104. +LIBIPKG_LIST_OBJS:= \
  105. + conffile.o \
  106. + conffile_list.o \
  107. + nv_pair.o \
  108. + nv_pair_list.o \
  109. + pkg_dest.o \
  110. + pkg_dest_list.o \
  111. + pkg_src.o \
  112. + pkg_src_list.o \
  113. + str_list.o \
  114. + void_list.o \
  115. +
  116. +LIBIPKG_UTIL_OBJS:= \
  117. + file_util.o \
  118. + ipkg_message.o \
  119. + str_util.o \
  120. + xsystem.o \
  121. +
  122. +lib-y :=
  123. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
  124. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
  125. +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
  126. +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
  127. +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
  128. +
  129. +ifeq ($(strip $(IPKG_ARCH)),)
  130. +IPKG_ARCH:=$(TARGET_ARCH)
  131. +endif
  132. +CFLAGS += -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
  133. diff -Nur busybox-1.18.1.orig/archival/libipkg/args.c busybox-1.18.1/archival/libipkg/args.c
  134. --- busybox-1.18.1.orig/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
  135. +++ busybox-1.18.1/archival/libipkg/args.c 2010-12-25 22:38:07.000000000 +0100
  136. @@ -0,0 +1,242 @@
  137. +/* args.c - parse command-line args
  138. +
  139. + Carl D. Worth
  140. +
  141. + Copyright 2001 University of Southern California
  142. +
  143. + This program is free software; you can redistribute it and/or modify
  144. + it under the terms of the GNU General Public License as published by
  145. + the Free Software Foundation; either version 2, or (at your option)
  146. + any later version.
  147. +
  148. + This program is distributed in the hope that it will be useful,
  149. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  150. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  151. + GNU General Public License for more details.
  152. + */
  153. +
  154. +#include <getopt.h>
  155. +#include <stdlib.h>
  156. +#include <string.h>
  157. +#include <unistd.h>
  158. +
  159. +#include "ipkg.h"
  160. +#include "ipkg_message.h"
  161. +
  162. +#include "args.h"
  163. +#include "sprintf_alloc.h"
  164. +
  165. +#include "libbb.h"
  166. +
  167. +
  168. +static void print_version(void);
  169. +
  170. +enum long_args_opt
  171. +{
  172. + ARGS_OPT_FORCE_DEFAULTS = 129,
  173. + ARGS_OPT_FORCE_DEPENDS,
  174. + ARGS_OPT_FORCE_OVERWRITE,
  175. + ARGS_OPT_FORCE_DOWNGRADE,
  176. + ARGS_OPT_FORCE_REINSTALL,
  177. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
  178. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
  179. + ARGS_OPT_FORCE_SPACE,
  180. + ARGS_OPT_NOACTION,
  181. + ARGS_OPT_NODEPS,
  182. + ARGS_OPT_VERBOSE_WGET,
  183. + ARGS_OPT_VERBOSITY,
  184. + ARGS_OPT_MULTIPLE_PROVIDERS
  185. +};
  186. +
  187. +int args_init(args_t *args)
  188. +{
  189. + const char *conf_file_dir;
  190. +
  191. + memset(args, 0, sizeof(args_t));
  192. +
  193. + args->dest = ARGS_DEFAULT_DEST;
  194. +
  195. + conf_file_dir = getenv("IPKG_CONF_DIR");
  196. + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
  197. + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
  198. + }
  199. + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
  200. + ARGS_DEFAULT_CONF_FILE_NAME);
  201. +
  202. + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
  203. + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
  204. + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
  205. + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
  206. + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
  207. + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
  208. + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
  209. + args->noaction = ARGS_DEFAULT_NOACTION;
  210. + args->nodeps = ARGS_DEFAULT_NODEPS;
  211. + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
  212. + args->verbosity = ARGS_DEFAULT_VERBOSITY;
  213. + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
  214. + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
  215. + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
  216. + args->multiple_providers = 0;
  217. + args->nocheckfordirorfile = 0;
  218. + args->noreadfeedsfile = 0;
  219. +
  220. + return 1;
  221. +}
  222. +
  223. +void args_deinit(args_t *args)
  224. +{
  225. + free(args->conf_file);
  226. + args->conf_file = NULL;
  227. +}
  228. +
  229. +int args_parse(args_t *args, int argc, char *argv[])
  230. +{
  231. + int c;
  232. + int option_index = 0;
  233. + int parse_err = 0;
  234. + static struct option long_options[] = {
  235. + {"query-all", 0, 0, 'A'},
  236. + {"conf-file", 1, 0, 'f'},
  237. + {"conf", 1, 0, 'f'},
  238. + {"dest", 1, 0, 'd'},
  239. + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  240. + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  241. + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  242. + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  243. + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  244. + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  245. + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  246. + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  247. + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  248. + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  249. + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
  250. + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
  251. + {"recursive", 0, 0,
  252. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  253. + {"force-removal-of-dependent-packages", 0, 0,
  254. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  255. + {"force_removal_of_dependent_packages", 0, 0,
  256. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  257. + {"force-removal-of-essential-packages", 0, 0,
  258. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  259. + {"force_removal_of_essential_packages", 0, 0,
  260. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  261. + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  262. + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  263. + {"noaction", 0, 0, ARGS_OPT_NOACTION},
  264. + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
  265. + {"offline", 1, 0, 'o'},
  266. + {"offline-root", 1, 0, 'o'},
  267. + {"test", 0, 0, ARGS_OPT_NOACTION},
  268. + {"tmp-dir", 1, 0, 't'},
  269. + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  270. + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  271. + {"verbosity", 2, 0, 'V'},
  272. + {"version", 0, 0, 'v'},
  273. + {0, 0, 0, 0}
  274. + };
  275. +
  276. + while (1) {
  277. + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
  278. + if (c == -1)
  279. + break;
  280. +
  281. + switch (c) {
  282. + case 'A':
  283. + args->query_all = 1;
  284. + break;
  285. + case 'd':
  286. + args->dest = optarg;
  287. + break;
  288. + case 'f':
  289. + free(args->conf_file);
  290. + args->conf_file = strdup(optarg);
  291. + break;
  292. + case 'o':
  293. + args->offline_root = optarg;
  294. + break;
  295. + case 'n':
  296. + args->noaction = 1;
  297. + break;
  298. + case 't':
  299. + args->tmp_dir = strdup(optarg);
  300. + break;
  301. + case 'v':
  302. + print_version();
  303. + exit(0);
  304. + case 'V':
  305. + case ARGS_OPT_VERBOSITY:
  306. + if (optarg)
  307. + args->verbosity = atoi(optarg);
  308. + else
  309. + args->verbosity += 1;
  310. + break;
  311. + case ARGS_OPT_FORCE_DEFAULTS:
  312. + args->force_defaults = 1;
  313. + break;
  314. + case ARGS_OPT_FORCE_DEPENDS:
  315. + args->force_depends = 1;
  316. + break;
  317. + case ARGS_OPT_FORCE_OVERWRITE:
  318. + args->force_overwrite = 1;
  319. + break;
  320. + case ARGS_OPT_FORCE_DOWNGRADE:
  321. + args->force_downgrade = 1;
  322. + break;
  323. + case ARGS_OPT_FORCE_REINSTALL:
  324. + args->force_reinstall = 1;
  325. + break;
  326. + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
  327. + args->force_removal_of_essential_packages = 1;
  328. + break;
  329. + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
  330. + args->force_removal_of_dependent_packages = 1;
  331. + break;
  332. + case ARGS_OPT_FORCE_SPACE:
  333. + args->force_space = 1;
  334. + break;
  335. + case ARGS_OPT_VERBOSE_WGET:
  336. + args->verbose_wget = 1;
  337. + break;
  338. + case ARGS_OPT_MULTIPLE_PROVIDERS:
  339. + args->multiple_providers = 1;
  340. + break;
  341. + case ARGS_OPT_NODEPS:
  342. + args->nodeps = 1;
  343. + break;
  344. + case ARGS_OPT_NOACTION:
  345. + args->noaction = 1;
  346. + break;
  347. + case ':':
  348. + parse_err++;
  349. + break;
  350. + case '?':
  351. + parse_err++;
  352. + break;
  353. + default:
  354. + bb_error_msg("Confusion: getopt_long returned %d\n", c);
  355. + }
  356. + }
  357. +
  358. + if (parse_err) {
  359. + return -parse_err;
  360. + } else {
  361. + return optind;
  362. + }
  363. +}
  364. +
  365. +void args_usage(const char *complaint)
  366. +{
  367. + if (complaint) {
  368. + bb_error_msg("%s\n", complaint);
  369. + }
  370. + print_version();
  371. + bb_show_usage();
  372. + exit(1);
  373. +}
  374. +
  375. +static void print_version(void)
  376. +{
  377. + bb_error_msg("version %s\n", IPKG_VERSION);
  378. +}
  379. diff -Nur busybox-1.18.1.orig/archival/libipkg/args.h busybox-1.18.1/archival/libipkg/args.h
  380. --- busybox-1.18.1.orig/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
  381. +++ busybox-1.18.1/archival/libipkg/args.h 2010-12-25 22:38:07.000000000 +0100
  382. @@ -0,0 +1,72 @@
  383. +/* args.h - parse command-line args
  384. +
  385. + Carl D. Worth
  386. +
  387. + Copyright 2001 University of Southern California
  388. +
  389. + This program is free software; you can redistribute it and/or modify
  390. + it under the terms of the GNU General Public License as published by
  391. + the Free Software Foundation; either version 2, or (at your option)
  392. + any later version.
  393. +
  394. + This program is distributed in the hope that it will be useful,
  395. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  396. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  397. + GNU General Public License for more details.
  398. +*/
  399. +
  400. +#ifndef ARGS_H
  401. +#define ARGS_H
  402. +
  403. +struct args
  404. +{
  405. + char *conf_file;
  406. + char *dest;
  407. + char *tmp_dir;
  408. + int force_defaults;
  409. + int force_depends;
  410. + int force_overwrite;
  411. + int force_downgrade;
  412. + int force_reinstall;
  413. + int force_removal_of_essential_packages;
  414. + int force_removal_of_dependent_packages;
  415. + int force_space;
  416. + int noaction;
  417. + int nodeps;
  418. + int multiple_providers;
  419. + int query_all;
  420. + int verbose_wget;
  421. + int verbosity;
  422. + int nocheckfordirorfile;
  423. + int noreadfeedsfile;
  424. + char *offline_root;
  425. + char *offline_root_pre_script_cmd;
  426. + char *offline_root_post_script_cmd;
  427. +};
  428. +typedef struct args args_t;
  429. +
  430. +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
  431. +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
  432. +#define ARGS_DEFAULT_DEST NULL
  433. +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
  434. +#define ARGS_DEFAULT_FORCE_DEPENDS 0
  435. +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
  436. +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
  437. +#define ARGS_DEFAULT_FORCE_REINSTALL 0
  438. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
  439. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
  440. +#define ARGS_DEFAULT_FORCE_SPACE 0
  441. +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
  442. +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
  443. +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
  444. +#define ARGS_DEFAULT_NOACTION 0
  445. +#define ARGS_DEFAULT_NODEPS 0
  446. +#define ARGS_DEFAULT_VERBOSE_WGET 0
  447. +#define ARGS_DEFAULT_VERBOSITY 1
  448. +
  449. +int args_init(args_t *args);
  450. +void args_deinit(args_t *args);
  451. +int args_parse(args_t *args, int argc, char *argv[]);
  452. +void args_usage(const char *complaint);
  453. +
  454. +#endif
  455. diff -Nur busybox-1.18.1.orig/archival/libipkg/conffile.c busybox-1.18.1/archival/libipkg/conffile.c
  456. --- busybox-1.18.1.orig/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
  457. +++ busybox-1.18.1/archival/libipkg/conffile.c 2010-12-25 22:38:07.000000000 +0100
  458. @@ -0,0 +1,65 @@
  459. +/* conffile.c - the itsy package management system
  460. +
  461. + Carl D. Worth
  462. +
  463. + Copyright (C) 2001 University of Southern California
  464. +
  465. + This program is free software; you can redistribute it and/or
  466. + modify it under the terms of the GNU General Public License as
  467. + published by the Free Software Foundation; either version 2, or (at
  468. + your option) any later version.
  469. +
  470. + This program is distributed in the hope that it will be useful, but
  471. + WITHOUT ANY WARRANTY; without even the implied warranty of
  472. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  473. + General Public License for more details.
  474. +*/
  475. +
  476. +#include <string.h>
  477. +#include <stdlib.h>
  478. +
  479. +#include "libbb.h"
  480. +#include "ipkg.h"
  481. +#include "ipkg_message.h"
  482. +
  483. +#include "conffile.h"
  484. +#include "file_util.h"
  485. +#include "sprintf_alloc.h"
  486. +
  487. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum)
  488. +{
  489. + return nv_pair_init(conffile, file_name, (char *)md5sum);
  490. +}
  491. +
  492. +void conffile_deinit(conffile_t *conffile)
  493. +{
  494. + nv_pair_deinit(conffile);
  495. +}
  496. +
  497. +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
  498. +{
  499. + uint8_t *md5sum;
  500. + char *filename = conffile->name;
  501. + char *root_filename;
  502. + int ret;
  503. +
  504. + if (conffile->value == NULL) {
  505. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
  506. + return 1;
  507. + }
  508. +
  509. + root_filename = root_filename_alloc(conf, filename);
  510. +
  511. + md5sum = file_md5sum_alloc(root_filename);
  512. +
  513. + ret = strcmp((char *)md5sum, conffile->value);
  514. + if (ret) {
  515. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
  516. + conffile->name, md5sum, conffile->value);
  517. + }
  518. +
  519. + free(root_filename);
  520. + free(md5sum);
  521. +
  522. + return ret;
  523. +}
  524. diff -Nur busybox-1.18.1.orig/archival/libipkg/conffile.h busybox-1.18.1/archival/libipkg/conffile.h
  525. --- busybox-1.18.1.orig/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
  526. +++ busybox-1.18.1/archival/libipkg/conffile.h 2010-12-25 22:38:07.000000000 +0100
  527. @@ -0,0 +1,30 @@
  528. +/* conffile.h - the itsy package management system
  529. +
  530. + Carl D. Worth
  531. +
  532. + Copyright (C) 2001 University of Southern California
  533. +
  534. + This program is free software; you can redistribute it and/or
  535. + modify it under the terms of the GNU General Public License as
  536. + published by the Free Software Foundation; either version 2, or (at
  537. + your option) any later version.
  538. +
  539. + This program is distributed in the hope that it will be useful, but
  540. + WITHOUT ANY WARRANTY; without even the implied warranty of
  541. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  542. + General Public License for more details.
  543. +*/
  544. +
  545. +#ifndef CONFFILE_H
  546. +#define CONFFILE_H
  547. +
  548. +#include "nv_pair.h"
  549. +
  550. +typedef struct nv_pair conffile_t;
  551. +
  552. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum);
  553. +void conffile_deinit(conffile_t *conffile);
  554. +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
  555. +
  556. +#endif
  557. +
  558. diff -Nur busybox-1.18.1.orig/archival/libipkg/conffile_list.c busybox-1.18.1/archival/libipkg/conffile_list.c
  559. --- busybox-1.18.1.orig/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
  560. +++ busybox-1.18.1/archival/libipkg/conffile_list.c 2010-12-25 22:38:07.000000000 +0100
  561. @@ -0,0 +1,47 @@
  562. +/* conffile_list.c - the itsy package management system
  563. +
  564. + Carl D. Worth
  565. +
  566. + Copyright (C) 2001 University of Southern California
  567. +
  568. + This program is free software; you can redistribute it and/or
  569. + modify it under the terms of the GNU General Public License as
  570. + published by the Free Software Foundation; either version 2, or (at
  571. + your option) any later version.
  572. +
  573. + This program is distributed in the hope that it will be useful, but
  574. + WITHOUT ANY WARRANTY; without even the implied warranty of
  575. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  576. + General Public License for more details.
  577. +*/
  578. +
  579. +#include "ipkg.h"
  580. +
  581. +#include "conffile_list.h"
  582. +
  583. +int conffile_list_init(conffile_list_t *list)
  584. +{
  585. + return nv_pair_list_init(list);
  586. +}
  587. +
  588. +void conffile_list_deinit(conffile_list_t *list)
  589. +{
  590. + nv_pair_list_deinit(list);
  591. +}
  592. +
  593. +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
  594. + const char *md5sum)
  595. +{
  596. + return nv_pair_list_append(list, file_name, md5sum);
  597. +}
  598. +
  599. +int conffile_list_push(conffile_list_t *list, conffile_t *data)
  600. +{
  601. + return nv_pair_list_push(list, data);
  602. +}
  603. +
  604. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
  605. +{
  606. + return nv_pair_list_pop(list);
  607. +}
  608. +
  609. diff -Nur busybox-1.18.1.orig/archival/libipkg/conffile_list.h busybox-1.18.1/archival/libipkg/conffile_list.h
  610. --- busybox-1.18.1.orig/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
  611. +++ busybox-1.18.1/archival/libipkg/conffile_list.h 2010-12-25 22:38:07.000000000 +0100
  612. @@ -0,0 +1,36 @@
  613. +/* conffile_list.h - the itsy package management system
  614. +
  615. + Carl D. Worth
  616. +
  617. + Copyright (C) 2001 University of Southern California
  618. +
  619. + This program is free software; you can redistribute it and/or
  620. + modify it under the terms of the GNU General Public License as
  621. + published by the Free Software Foundation; either version 2, or (at
  622. + your option) any later version.
  623. +
  624. + This program is distributed in the hope that it will be useful, but
  625. + WITHOUT ANY WARRANTY; without even the implied warranty of
  626. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  627. + General Public License for more details.
  628. +*/
  629. +
  630. +#ifndef CONFFILE_LIST_H
  631. +#define CONFFILE_LIST_H
  632. +
  633. +#include "conffile.h"
  634. +#include "nv_pair_list.h"
  635. +
  636. +typedef struct nv_pair_list_elt conffile_list_elt_t;
  637. +typedef struct nv_pair_list conffile_list_t;
  638. +
  639. +int conffile_list_init(conffile_list_t *list);
  640. +void conffile_list_deinit(conffile_list_t *list);
  641. +
  642. +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
  643. + const char *root_dir);
  644. +int conffile_list_push(conffile_list_t *list, conffile_t *data);
  645. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
  646. +
  647. +#endif
  648. +
  649. diff -Nur busybox-1.18.1.orig/archival/libipkg/file_util.c busybox-1.18.1/archival/libipkg/file_util.c
  650. --- busybox-1.18.1.orig/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
  651. +++ busybox-1.18.1/archival/libipkg/file_util.c 2010-12-25 22:38:07.000000000 +0100
  652. @@ -0,0 +1,186 @@
  653. +/* file_util.c - convenience routines for common stat operations
  654. +
  655. + Carl D. Worth
  656. +
  657. + Copyright (C) 2001 University of Southern California
  658. +
  659. + This program is free software; you can redistribute it and/or
  660. + modify it under the terms of the GNU General Public License as
  661. + published by the Free Software Foundation; either version 2, or (at
  662. + your option) any later version.
  663. +
  664. + This program is distributed in the hope that it will be useful, but
  665. + WITHOUT ANY WARRANTY; without even the implied warranty of
  666. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  667. + General Public License for more details.
  668. +*/
  669. +
  670. +#include "ipkg.h"
  671. +#include <sys/types.h>
  672. +#include <sys/stat.h>
  673. +
  674. +#include "sprintf_alloc.h"
  675. +#include "file_util.h"
  676. +#include "libbb.h"
  677. +#undef strlen
  678. +
  679. +int file_exists(const char *file_name)
  680. +{
  681. + int err;
  682. + struct stat stat_buf;
  683. +
  684. + err = stat(file_name, &stat_buf);
  685. + if (err == 0) {
  686. + return 1;
  687. + } else {
  688. + return 0;
  689. + }
  690. +}
  691. +
  692. +int file_is_dir(const char *file_name)
  693. +{
  694. + int err;
  695. + struct stat stat_buf;
  696. +
  697. + err = stat(file_name, &stat_buf);
  698. + if (err) {
  699. + return 0;
  700. + }
  701. +
  702. + return S_ISDIR(stat_buf.st_mode);
  703. +}
  704. +
  705. +/* read a single line from a file, stopping at a newline or EOF.
  706. + If a newline is read, it will appear in the resulting string.
  707. + Return value is a malloc'ed char * which should be freed at
  708. + some point by the caller.
  709. +
  710. + Return value is NULL if the file is at EOF when called.
  711. +*/
  712. +#define FILE_READ_LINE_BUF_SIZE 1024
  713. +char *file_read_line_alloc(FILE *file)
  714. +{
  715. + char buf[FILE_READ_LINE_BUF_SIZE];
  716. + int buf_len;
  717. + char *line = NULL;
  718. + int line_size = 0;
  719. +
  720. + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
  721. + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
  722. + buf_len = strlen(buf);
  723. + if (line) {
  724. + line_size += buf_len;
  725. + line = realloc(line, line_size);
  726. + if (line == NULL) {
  727. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  728. + break;
  729. + }
  730. + strcat(line, buf);
  731. + } else {
  732. + line_size = buf_len + 1;
  733. + line = strdup(buf);
  734. + }
  735. + if (buf[buf_len - 1] == '\n') {
  736. + break;
  737. + }
  738. + }
  739. +
  740. + return line;
  741. +}
  742. +
  743. +int file_move(const char *src, const char *dest)
  744. +{
  745. + int err;
  746. +
  747. + err = rename(src, dest);
  748. +
  749. + if (err && errno == EXDEV) {
  750. + err = file_copy(src, dest);
  751. + unlink(src);
  752. + } else if (err) {
  753. + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
  754. + __FUNCTION__, src, dest, strerror(errno));
  755. + }
  756. +
  757. + return err;
  758. +}
  759. +
  760. +/* I put these here to keep libbb dependencies from creeping all over
  761. + the ipkg code */
  762. +int file_copy(const char *src, const char *dest)
  763. +{
  764. + int err;
  765. +
  766. + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
  767. + if (err) {
  768. + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
  769. + __FUNCTION__, src, dest);
  770. + }
  771. +
  772. + return err;
  773. +}
  774. +
  775. +int file_mkdir_hier(char *path, long mode)
  776. +{
  777. + return bb_make_directory(path, mode, FILEUTILS_RECUR);
  778. +}
  779. +
  780. +static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
  781. + unsigned hash_length)
  782. +{
  783. + /* xzalloc zero-terminates */
  784. + char *hex_value = xzalloc((hash_length * 2) + 1);
  785. + bin2hex(hex_value, (char*)hash_value, hash_length);
  786. + return (unsigned char *)hex_value;
  787. +}
  788. +
  789. +static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
  790. +{
  791. + int src_fd, hash_len, count;
  792. + union _ctx_ {
  793. + sha1_ctx_t sha1;
  794. + md5_ctx_t md5;
  795. + } context;
  796. + uint8_t *hash_value = NULL;
  797. + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
  798. + void FAST_FUNC (*update)(const void*, size_t, void*);
  799. + void FAST_FUNC (*final)(void*, void*);
  800. +
  801. + src_fd = open_or_warn_stdin(filename);
  802. + if (src_fd < 0) {
  803. + return NULL;
  804. + }
  805. +
  806. + /* figure specific hash algorithims */
  807. + if (ENABLE_MD5SUM && hash_algo == HASH_MD5) {
  808. + md5_begin(&context.md5);
  809. + update = (void*)md5_hash;
  810. + final = (void*)md5_end;
  811. + hash_len = 16;
  812. + } else {
  813. + bb_error_msg_and_die("algorithm not supported");
  814. + }
  815. +
  816. + while (0 < (count = safe_read(src_fd, in_buf, 4096))) {
  817. + update(in_buf, count, &context);
  818. + }
  819. +
  820. + if (count == 0) {
  821. + final(in_buf, &context);
  822. + hash_value = hash_bin_to_hex(in_buf, hash_len);
  823. + }
  824. +
  825. + RELEASE_CONFIG_BUFFER(in_buf);
  826. +
  827. + if (src_fd != STDIN_FILENO) {
  828. + close(src_fd);
  829. + }
  830. +
  831. + return hash_value;
  832. +}
  833. +
  834. +uint8_t *file_md5sum_alloc(const char *file_name)
  835. +{
  836. + return hash_file(file_name, HASH_MD5);
  837. +}
  838. +
  839. diff -Nur busybox-1.18.1.orig/archival/libipkg/file_util.h busybox-1.18.1/archival/libipkg/file_util.h
  840. --- busybox-1.18.1.orig/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
  841. +++ busybox-1.18.1/archival/libipkg/file_util.h 2010-12-25 22:38:07.000000000 +0100
  842. @@ -0,0 +1,29 @@
  843. +/* file_util.h - convenience routines for common file operations
  844. +
  845. + Carl D. Worth
  846. +
  847. + Copyright (C) 2001 University of Southern California
  848. +
  849. + This program is free software; you can redistribute it and/or
  850. + modify it under the terms of the GNU General Public License as
  851. + published by the Free Software Foundation; either version 2, or (at
  852. + your option) any later version.
  853. +
  854. + This program is distributed in the hope that it will be useful, but
  855. + WITHOUT ANY WARRANTY; without even the implied warranty of
  856. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  857. + General Public License for more details.
  858. +*/
  859. +
  860. +#ifndef FILE_UTIL_H
  861. +#define FILE_UTIL_H
  862. +
  863. +int file_exists(const char *file_name);
  864. +int file_is_dir(const char *file_name);
  865. +char *file_read_line_alloc(FILE *file);
  866. +int file_move(const char *src, const char *dest);
  867. +int file_copy(const char *src, const char *dest);
  868. +int file_mkdir_hier(char *path, long mode);
  869. +uint8_t *file_md5sum_alloc(const char *file_name);
  870. +
  871. +#endif
  872. diff -Nur busybox-1.18.1.orig/archival/libipkg/hash_table.c busybox-1.18.1/archival/libipkg/hash_table.c
  873. --- busybox-1.18.1.orig/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
  874. +++ busybox-1.18.1/archival/libipkg/hash_table.c 2010-12-25 22:38:07.000000000 +0100
  875. @@ -0,0 +1,155 @@
  876. +/* hash.c - hash tables for ipkg
  877. +
  878. + Steven M. Ayer, Jamey Hicks
  879. +
  880. + Copyright (C) 2002 Compaq Computer Corporation
  881. +
  882. + This program is free software; you can redistribute it and/or
  883. + modify it under the terms of the GNU General Public License as
  884. + published by the Free Software Foundation; either version 2, or (at
  885. + your option) any later version.
  886. +
  887. + This program is distributed in the hope that it will be useful, but
  888. + WITHOUT ANY WARRANTY; without even the implied warranty of
  889. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  890. + General Public License for more details.
  891. +*/
  892. +
  893. +#include <errno.h>
  894. +#include <stdio.h>
  895. +#include <stdlib.h>
  896. +#include <string.h>
  897. +#include "hash_table.h"
  898. +#include "ipkg_message.h"
  899. +
  900. +
  901. +static int hash_index(hash_table_t *hash, const char *pkg_name);
  902. +static int rotating(const char *key, int len, int prime);
  903. +
  904. +static int hash_index(hash_table_t *hash, const char *pkg_name)
  905. +{
  906. + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
  907. +}
  908. +
  909. +static int rotating(const char *key, int len, int prime)
  910. +{
  911. + unsigned int hash, i;
  912. + for (hash=len, i=0; i<len; ++i)
  913. + hash = (hash<<4)^(hash>>28)^key[i];
  914. + return (hash % prime);
  915. +}
  916. +
  917. +
  918. +/*
  919. + * this is an open table keyed by strings
  920. + */
  921. +int hash_table_init(const char *name, hash_table_t *hash, int len)
  922. +{
  923. + static int primes_table[] = {
  924. + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
  925. + 19471, 23143, 33961, 46499, 49727, 99529, 0
  926. + };
  927. + int *picker;
  928. +
  929. + if (hash->entries != NULL) {
  930. + /* we have been here already */
  931. + return 0;
  932. + }
  933. +
  934. + hash->name = name;
  935. + hash->entries = NULL;
  936. + hash->n_entries = 0;
  937. + hash->hash_entry_key = NULL;
  938. +
  939. + picker = primes_table;
  940. + while(*picker && (*picker++ < len));
  941. + if(!*picker)
  942. + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
  943. + --picker;
  944. +
  945. + hash->n_entries = *picker;
  946. + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
  947. + if (hash->entries == NULL) {
  948. + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
  949. + return ENOMEM;
  950. + }
  951. + return 0;
  952. +}
  953. +
  954. +void hash_table_deinit(hash_table_t *hash)
  955. +{
  956. + free(hash->entries);
  957. + hash->entries = NULL;
  958. + hash->n_entries = 0;
  959. +}
  960. +
  961. +void *hash_table_get(hash_table_t *hash, const char *key)
  962. +{
  963. + int ndx= hash_index(hash, key);
  964. + hash_entry_t *hash_entry = hash->entries + ndx;
  965. + while (hash_entry)
  966. + {
  967. + if (hash_entry->key)
  968. + {
  969. + if (strcmp(key, hash_entry->key) == 0) {
  970. + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
  971. + return hash_entry->data;
  972. + }
  973. + }
  974. + hash_entry = hash_entry->next;
  975. + }
  976. + return NULL;
  977. +}
  978. +
  979. +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
  980. +{
  981. + int ndx= hash_index(hash, key);
  982. + hash_entry_t *hash_entry = hash->entries + ndx;
  983. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
  984. + if (hash_entry->key) {
  985. + if (strcmp(hash_entry->key, key) == 0) {
  986. + /* alread in table, update the value */
  987. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
  988. + hash_entry->data = value;
  989. + return 0;
  990. + } else {
  991. + /*
  992. + * if this is a collision, we have to go to the end of the ll,
  993. + * then add a new entry
  994. + * before we can hook up the value
  995. + */
  996. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
  997. + while (hash_entry->next)
  998. + hash_entry = hash_entry->next;
  999. + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
  1000. + if (!hash_entry->next) {
  1001. + return -ENOMEM;
  1002. + }
  1003. + hash_entry = hash_entry->next;
  1004. + hash_entry->next = NULL;
  1005. + }
  1006. + }
  1007. + hash->n_elements++;
  1008. + hash_entry->key = strdup(key);
  1009. + hash_entry->data = value;
  1010. +
  1011. + return 0;
  1012. +}
  1013. +
  1014. +
  1015. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
  1016. +{
  1017. + int i;
  1018. + if (!hash || !f)
  1019. + return;
  1020. +
  1021. + for (i = 0; i < hash->n_entries; i++) {
  1022. + hash_entry_t *hash_entry = (hash->entries + i);
  1023. + do {
  1024. + if(hash_entry->key) {
  1025. + f(hash_entry->key, hash_entry->data, data);
  1026. + }
  1027. + } while((hash_entry = hash_entry->next));
  1028. + }
  1029. +}
  1030. +
  1031. diff -Nur busybox-1.18.1.orig/archival/libipkg/hash_table.h busybox-1.18.1/archival/libipkg/hash_table.h
  1032. --- busybox-1.18.1.orig/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
  1033. +++ busybox-1.18.1/archival/libipkg/hash_table.h 2010-12-25 22:38:07.000000000 +0100
  1034. @@ -0,0 +1,44 @@
  1035. +/* hash.h - hash tables for ipkg
  1036. +
  1037. + Steven M. Ayer, Jamey Hicks
  1038. +
  1039. + Copyright (C) 2002 Compaq Computer Corporation
  1040. +
  1041. + This program is free software; you can redistribute it and/or
  1042. + modify it under the terms of the GNU General Public License as
  1043. + published by the Free Software Foundation; either version 2, or (at
  1044. + your option) any later version.
  1045. +
  1046. + This program is distributed in the hope that it will be useful, but
  1047. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1048. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1049. + General Public License for more details.
  1050. +*/
  1051. +
  1052. +#ifndef _HASH_TABLE_H_
  1053. +#define _HASH_TABLE_H_
  1054. +
  1055. +typedef struct hash_entry hash_entry_t;
  1056. +typedef struct hash_table hash_table_t;
  1057. +
  1058. +struct hash_entry {
  1059. + const char * key;
  1060. + void * data;
  1061. + struct hash_entry * next;
  1062. +};
  1063. +
  1064. +struct hash_table {
  1065. + const char *name;
  1066. + hash_entry_t * entries;
  1067. + int n_entries; /* number of buckets */
  1068. + int n_elements;
  1069. + const char * (*hash_entry_key)(void * data);
  1070. +};
  1071. +
  1072. +int hash_table_init(const char *name, hash_table_t *hash, int len);
  1073. +void hash_table_deinit(hash_table_t *hash);
  1074. +void *hash_table_get(hash_table_t *hash, const char *key);
  1075. +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
  1076. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
  1077. +
  1078. +#endif /* _HASH_TABLE_H_ */
  1079. diff -Nur busybox-1.18.1.orig/archival/libipkg/ipkg.h busybox-1.18.1/archival/libipkg/ipkg.h
  1080. --- busybox-1.18.1.orig/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
  1081. +++ busybox-1.18.1/archival/libipkg/ipkg.h 2010-12-25 22:38:07.000000000 +0100
  1082. @@ -0,0 +1,68 @@
  1083. +/* ipkg.h - the itsy package management system
  1084. +
  1085. + Carl D. Worth
  1086. +
  1087. + Copyright (C) 2001 University of Southern California
  1088. +
  1089. + This program is free software; you can redistribute it and/or
  1090. + modify it under the terms of the GNU General Public License as
  1091. + published by the Free Software Foundation; either version 2, or (at
  1092. + your option) any later version.
  1093. +
  1094. + This program is distributed in the hope that it will be useful, but
  1095. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1096. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1097. + General Public License for more details.
  1098. +*/
  1099. +
  1100. +#ifndef IPKG_H
  1101. +#define IPKG_H
  1102. +
  1103. +#include "libbb.h"
  1104. +
  1105. +#include "ipkg_includes.h"
  1106. +#include "ipkg_conf.h"
  1107. +#include "ipkg_message.h"
  1108. +
  1109. +#define IPKG_PKG_EXTENSION ".ipk"
  1110. +#define DPKG_PKG_EXTENSION ".deb"
  1111. +
  1112. +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
  1113. +#define IPKG_PKG_VERSION_SEP_CHAR '_'
  1114. +
  1115. +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
  1116. +#define IPKG_LISTS_DIR_SUFFIX "lists"
  1117. +#define IPKG_INFO_DIR_SUFFIX "info"
  1118. +#define IPKG_STATUS_FILE_SUFFIX "status"
  1119. +
  1120. +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
  1121. +
  1122. +#define IPKG_LIST_DESCRIPTION_LENGTH 128
  1123. +
  1124. +#define IPKG_VERSION "1.00"
  1125. +
  1126. +
  1127. +enum ipkg_error {
  1128. + IPKG_SUCCESS = 0,
  1129. + IPKG_PKG_DEPS_UNSATISFIED,
  1130. + IPKG_PKG_IS_ESSENTIAL,
  1131. + IPKG_PKG_HAS_DEPENDENTS,
  1132. + IPKG_PKG_HAS_NO_CANDIDATE
  1133. +};
  1134. +typedef enum ipkg_error ipkg_error_t;
  1135. +
  1136. +extern int ipkg_state_changed;
  1137. +
  1138. +
  1139. +struct errlist {
  1140. + char * errmsg;
  1141. + struct errlist * next;
  1142. +} ;
  1143. +
  1144. +extern struct errlist* error_list;
  1145. +
  1146. +extern ipkg_conf_t *global_conf;
  1147. +
  1148. +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
  1149. +
  1150. +#endif
  1151. diff -Nur busybox-1.18.1.orig/archival/libipkg/ipkg_cmd.c busybox-1.18.1/archival/libipkg/ipkg_cmd.c
  1152. --- busybox-1.18.1.orig/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
  1153. +++ busybox-1.18.1/archival/libipkg/ipkg_cmd.c 2010-12-25 22:47:47.000000000 +0100
  1154. @@ -0,0 +1,1366 @@
  1155. +/* ipkg_cmd.c - the itsy package management system
  1156. +
  1157. + Carl D. Worth
  1158. +
  1159. + Copyright (C) 2001 University of Southern California
  1160. +
  1161. + This program is free software; you can redistribute it and/or
  1162. + modify it under the terms of the GNU General Public License as
  1163. + published by the Free Software Foundation; either version 2, or (at
  1164. + your option) any later version.
  1165. +
  1166. + This program is distributed in the hope that it will be useful, but
  1167. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1168. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1169. + General Public License for more details.
  1170. +*/
  1171. +
  1172. +#include <string.h>
  1173. +
  1174. +#include "ipkg.h"
  1175. +#include <libgen.h>
  1176. +#include <glob.h>
  1177. +#include <errno.h>
  1178. +#include <stdlib.h>
  1179. +#include <unistd.h>
  1180. +#include <signal.h>
  1181. +#include <stdio.h>
  1182. +#include <dirent.h>
  1183. +
  1184. +#include "ipkg_conf.h"
  1185. +#include "ipkg_cmd.h"
  1186. +#include "ipkg_message.h"
  1187. +#include "pkg.h"
  1188. +#include "pkg_dest.h"
  1189. +#include "pkg_parse.h"
  1190. +#include "sprintf_alloc.h"
  1191. +#include "pkg.h"
  1192. +#include "file_util.h"
  1193. +#include "str_util.h"
  1194. +#include "archive.h"
  1195. +
  1196. +#include <fnmatch.h>
  1197. +
  1198. +
  1199. +#include "ipkg_download.h"
  1200. +#include "ipkg_install.h"
  1201. +#include "ipkg_upgrade.h"
  1202. +#include "ipkg_remove.h"
  1203. +#include "ipkg_configure.h"
  1204. +#include "ipkg_message.h"
  1205. +
  1206. +#include "libipkg.h"
  1207. +static void *p_userdata = NULL;
  1208. +
  1209. +static int ipkg_update_cmd(ipkg_conf_t *conf);
  1210. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1211. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1212. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1213. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1214. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf);
  1215. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1216. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1217. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1218. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1219. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1220. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1221. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1222. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1223. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1224. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1225. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1226. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1227. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1228. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1229. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1230. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1231. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1232. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf);
  1233. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1234. +
  1235. +/* XXX: CLEANUP: The usage strings should be incorporated into this
  1236. + array for easier maintenance */
  1237. +static ipkg_cmd_t cmds[] = {
  1238. + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
  1239. + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
  1240. + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
  1241. + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
  1242. + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
  1243. + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
  1244. + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
  1245. + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
  1246. + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
  1247. + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
  1248. + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
  1249. + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
  1250. + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
  1251. + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
  1252. + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
  1253. + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1254. + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1255. + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1256. + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1257. + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1258. + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1259. + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
  1260. + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
  1261. + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
  1262. + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
  1263. + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
  1264. + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
  1265. + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
  1266. + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
  1267. +};
  1268. +
  1269. +int ipkg_state_changed;
  1270. +static void write_status_files_if_changed(ipkg_conf_t *conf)
  1271. +{
  1272. + if (ipkg_state_changed && !conf->noaction) {
  1273. + ipkg_message(conf, IPKG_INFO,
  1274. + " writing status file\n");
  1275. + ipkg_conf_write_status_files(conf);
  1276. + pkg_write_changed_filelists(conf);
  1277. + } else {
  1278. + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
  1279. + }
  1280. +}
  1281. +
  1282. +
  1283. +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
  1284. +
  1285. +ipkg_cmd_t *ipkg_cmd_find(const char *name)
  1286. +{
  1287. + int i;
  1288. + ipkg_cmd_t *cmd;
  1289. +
  1290. + for (i=0; i < num_cmds; i++) {
  1291. + cmd = &cmds[i];
  1292. + if (strcmp(name, cmd->name) == 0) {
  1293. + return cmd;
  1294. + }
  1295. + }
  1296. +
  1297. + return NULL;
  1298. +}
  1299. +
  1300. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
  1301. +{
  1302. + int result;
  1303. + p_userdata = userdata;
  1304. +
  1305. +
  1306. + result = (cmd->fun)(conf, argc, argv);
  1307. + if ( result == 0 ) {
  1308. + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
  1309. + } else {
  1310. + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
  1311. +
  1312. + }
  1313. + if ( error_list ) {
  1314. + reverse_error_list(&error_list);
  1315. +
  1316. + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
  1317. + /* Here we print the errors collected and free the list */
  1318. + while (error_list != NULL) {
  1319. + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
  1320. + error_list = error_list->next;
  1321. +
  1322. + }
  1323. + free_error_list(&error_list);
  1324. +
  1325. + }
  1326. +
  1327. + p_userdata = NULL;
  1328. + return result;
  1329. +}
  1330. +
  1331. +static int ipkg_update_cmd(ipkg_conf_t *conf)
  1332. +{
  1333. + int err;
  1334. + int failures;
  1335. + char *lists_dir;
  1336. + pkg_src_list_elt_t *iter;
  1337. + pkg_src_t *src;
  1338. +
  1339. +
  1340. + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
  1341. +
  1342. + if (! file_is_dir(lists_dir)) {
  1343. + if (file_exists(lists_dir)) {
  1344. + ipkg_message(conf, IPKG_ERROR,
  1345. + "%s: ERROR: %s exists, but is not a directory\n",
  1346. + __FUNCTION__, lists_dir);
  1347. + free(lists_dir);
  1348. + return EINVAL;
  1349. + }
  1350. + err = file_mkdir_hier(lists_dir, 0755);
  1351. + if (err) {
  1352. + ipkg_message(conf, IPKG_ERROR,
  1353. + "%s: ERROR: failed to make directory %s: %s\n",
  1354. + __FUNCTION__, lists_dir, strerror(errno));
  1355. + free(lists_dir);
  1356. + return EINVAL;
  1357. + }
  1358. + }
  1359. +
  1360. + failures = 0;
  1361. + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
  1362. + char *url, *list_file_name;
  1363. +
  1364. + src = iter->data;
  1365. +
  1366. + if (src->extra_data) /* debian style? */
  1367. + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
  1368. + src->gzip ? "Packages.gz" : "Packages");
  1369. + else
  1370. + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
  1371. +
  1372. + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
  1373. + if (src->gzip) {
  1374. + char *tmp;
  1375. + char *tmp_file_name;
  1376. + FILE *in, *out;
  1377. +
  1378. + tmp = strdup ("/tmp/ipkg.XXXXXX");
  1379. +
  1380. + if (mkdtemp (tmp) == NULL) {
  1381. + perror ("mkdtemp");
  1382. + failures++;
  1383. + continue;
  1384. + }
  1385. +
  1386. + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
  1387. + err = ipkg_download(conf, url, tmp_file_name);
  1388. + if (err == 0) {
  1389. + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
  1390. + in = fopen (tmp_file_name, "r");
  1391. + out = fopen (list_file_name, "w");
  1392. + if (in && out) {
  1393. + inflate_unzip_result res;
  1394. + inflate_unzip (&res, 0x8000, fileno(in), fileno(out));
  1395. + } else
  1396. + err = 1;
  1397. + if (in)
  1398. + fclose (in);
  1399. + if (out)
  1400. + fclose (out);
  1401. + unlink (tmp_file_name);
  1402. + rmdir (tmp);
  1403. + free (tmp);
  1404. + }
  1405. + } else
  1406. + err = ipkg_download(conf, url, list_file_name);
  1407. + if (err) {
  1408. + failures++;
  1409. + } else {
  1410. + ipkg_message(conf, IPKG_NOTICE,
  1411. + "Updated list of available packages in %s\n",
  1412. + list_file_name);
  1413. + }
  1414. + free(url);
  1415. + free(list_file_name);
  1416. + }
  1417. + free(lists_dir);
  1418. +
  1419. +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
  1420. +#warning here
  1421. + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
  1422. + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
  1423. + * -Jamey 3/1/03
  1424. + */
  1425. + {
  1426. + int i;
  1427. + int changed = 0;
  1428. + pkg_vec_t *available = pkg_vec_alloc();
  1429. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1430. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
  1431. + for (i = 0; i < available->len; i++) {
  1432. + pkg_t *pkg = available->pkgs[i];
  1433. + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
  1434. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
  1435. + pkg->state_want = SW_UNKNOWN;
  1436. + changed = 1;
  1437. + }
  1438. + }
  1439. + pkg_vec_free(available);
  1440. + if (changed) {
  1441. + write_status_files_if_changed(conf);
  1442. + }
  1443. + }
  1444. +#endif
  1445. +
  1446. + return failures;
  1447. +}
  1448. +
  1449. +
  1450. +/* scan the args passed and cache the local filenames of the packages */
  1451. +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
  1452. +{
  1453. + int i;
  1454. + int err;
  1455. +
  1456. + /*
  1457. + * First scan through package names/urls
  1458. + * For any urls, download the packages and install in database.
  1459. + * For any files, install package info in database.
  1460. + */
  1461. + for (i = 0; i < argc; i ++) {
  1462. + char *filename = argv [i];
  1463. + //char *tmp = basename (tmp);
  1464. + //int tmplen = strlen (tmp);
  1465. +
  1466. + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
  1467. + // continue;
  1468. + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
  1469. + // continue;
  1470. +
  1471. + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
  1472. +
  1473. + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
  1474. + if (err)
  1475. + return err;
  1476. + }
  1477. + return 0;
  1478. +}
  1479. +
  1480. +struct ipkg_intercept
  1481. +{
  1482. + char *oldpath;
  1483. + char *statedir;
  1484. +};
  1485. +
  1486. +typedef struct ipkg_intercept *ipkg_intercept_t;
  1487. +ipkg_intercept_t ipkg_prep_intercepts(void);
  1488. +
  1489. +ipkg_intercept_t ipkg_prep_intercepts(void)
  1490. +{
  1491. + ipkg_intercept_t ctx;
  1492. + char *newpath;
  1493. + int gen;
  1494. +
  1495. + ctx = malloc (sizeof (*ctx));
  1496. + ctx->oldpath = strdup (getenv ("PATH"));
  1497. +
  1498. + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
  1499. + setenv ("PATH", newpath, 1);
  1500. + free (newpath);
  1501. +
  1502. + gen = 0;
  1503. + retry:
  1504. + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
  1505. + if (mkdir (ctx->statedir, 0770) < 0) {
  1506. + if (errno == EEXIST) {
  1507. + free (ctx->statedir);
  1508. + gen++;
  1509. + goto retry;
  1510. + }
  1511. + perror (ctx->statedir);
  1512. + return NULL;
  1513. + }
  1514. + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
  1515. + return ctx;
  1516. +}
  1517. +
  1518. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx);
  1519. +
  1520. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
  1521. +{
  1522. + char *cmd;
  1523. + DIR *dir;
  1524. + int err = 0;
  1525. +
  1526. + setenv ("PATH", ctx->oldpath, 1);
  1527. + free (ctx->oldpath);
  1528. +
  1529. + dir = opendir (ctx->statedir);
  1530. + if (dir) {
  1531. + struct dirent *de;
  1532. + while (de = readdir (dir), de != NULL) {
  1533. + char *path;
  1534. +
  1535. + if (de->d_name[0] == '.')
  1536. + continue;
  1537. +
  1538. + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
  1539. + if (access (path, X_OK) == 0) {
  1540. + if (system (path)) {
  1541. + err = errno;
  1542. + perror (de->d_name);
  1543. + }
  1544. + }
  1545. + free (path);
  1546. + }
  1547. + } else
  1548. + perror (ctx->statedir);
  1549. +
  1550. + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
  1551. + system (cmd);
  1552. + free (cmd);
  1553. +
  1554. + free (ctx->statedir);
  1555. + free (ctx);
  1556. +
  1557. + return err;
  1558. +}
  1559. +
  1560. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
  1561. +{
  1562. + pkg_vec_t *all;
  1563. + int i;
  1564. + pkg_t *pkg;
  1565. + ipkg_intercept_t ic;
  1566. + int r, err = 0;
  1567. +
  1568. + ipkg_message(conf, IPKG_INFO,
  1569. + "Configuring unpacked packages\n");
  1570. + fflush( stdout );
  1571. +
  1572. + all = pkg_vec_alloc();
  1573. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  1574. +
  1575. + ic = ipkg_prep_intercepts();
  1576. +
  1577. + for(i = 0; i < all->len; i++) {
  1578. + pkg = all->pkgs[i];
  1579. +
  1580. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1581. + continue;
  1582. +
  1583. + if (pkg->state_status == SS_UNPACKED) {
  1584. + ipkg_message(conf, IPKG_NOTICE,
  1585. + "Configuring %s\n", pkg->name);
  1586. + fflush( stdout );
  1587. + r = ipkg_configure(conf, pkg);
  1588. + if (r == 0) {
  1589. + pkg->state_status = SS_INSTALLED;
  1590. + pkg->parent->state_status = SS_INSTALLED;
  1591. + pkg->state_flag &= ~SF_PREFER;
  1592. + } else {
  1593. + if (!err)
  1594. + err = r;
  1595. + }
  1596. + }
  1597. + }
  1598. +
  1599. + r = ipkg_finalize_intercepts (ic);
  1600. + if (r && !err)
  1601. + err = r;
  1602. +
  1603. + pkg_vec_free(all);
  1604. + return err;
  1605. +}
  1606. +
  1607. +static void sigint_handler(int sig)
  1608. +{
  1609. + signal(sig, SIG_DFL);
  1610. + ipkg_message(NULL, IPKG_NOTICE,
  1611. + "ipkg: interrupted. writing out status database\n");
  1612. + write_status_files_if_changed(global_conf);
  1613. + exit(128 + sig);
  1614. +}
  1615. +
  1616. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1617. +{
  1618. + int i;
  1619. + char *arg;
  1620. + int err=0;
  1621. +
  1622. + global_conf = conf;
  1623. + signal(SIGINT, sigint_handler);
  1624. +
  1625. + /*
  1626. + * Now scan through package names and install
  1627. + */
  1628. + for (i=0; i < argc; i++) {
  1629. + arg = argv[i];
  1630. +
  1631. + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
  1632. + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
  1633. + if (err != EINVAL && err != 0)
  1634. + return err;
  1635. + }
  1636. + pkg_info_preinstall_check(conf);
  1637. +
  1638. + for (i=0; i < argc; i++) {
  1639. + arg = argv[i];
  1640. + if (conf->multiple_providers)
  1641. + err = ipkg_install_multi_by_name(conf, arg);
  1642. + else{
  1643. + err = ipkg_install_by_name(conf, arg);
  1644. + }
  1645. + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
  1646. + ipkg_message(conf, IPKG_ERROR,
  1647. + "Cannot find package %s.\n"
  1648. + "Check the spelling or perhaps run 'ipkg update'\n",
  1649. + arg);
  1650. + }
  1651. + }
  1652. +
  1653. + /* recheck to verify that all dependences are satisfied */
  1654. + if (0) ipkg_satisfy_all_dependences(conf);
  1655. +
  1656. + ipkg_configure_packages(conf, NULL);
  1657. +
  1658. + write_status_files_if_changed(conf);
  1659. +
  1660. + return err;
  1661. +}
  1662. +
  1663. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1664. +{
  1665. + int i;
  1666. + pkg_t *pkg;
  1667. + int err;
  1668. +
  1669. + global_conf = conf;
  1670. + signal(SIGINT, sigint_handler);
  1671. +
  1672. + if (argc) {
  1673. + for (i=0; i < argc; i++) {
  1674. + char *arg = argv[i];
  1675. +
  1676. + err = ipkg_prepare_url_for_install(conf, arg, &arg);
  1677. + if (err != EINVAL && err != 0)
  1678. + return err;
  1679. + }
  1680. + pkg_info_preinstall_check(conf);
  1681. +
  1682. + for (i=0; i < argc; i++) {
  1683. + char *arg = argv[i];
  1684. + if (conf->restrict_to_default_dest) {
  1685. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1686. + argv[i],
  1687. + conf->default_dest);
  1688. + if (pkg == NULL) {
  1689. + ipkg_message(conf, IPKG_NOTICE,
  1690. + "Package %s not installed in %s\n",
  1691. + argv[i], conf->default_dest->name);
  1692. + continue;
  1693. + }
  1694. + } else {
  1695. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  1696. + argv[i]);
  1697. + }
  1698. + if (pkg)
  1699. + ipkg_upgrade_pkg(conf, pkg);
  1700. + else {
  1701. + ipkg_install_by_name(conf, arg);
  1702. + }
  1703. + }
  1704. + } else {
  1705. + pkg_vec_t *installed = pkg_vec_alloc();
  1706. +
  1707. + pkg_info_preinstall_check(conf);
  1708. +
  1709. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  1710. + for (i = 0; i < installed->len; i++) {
  1711. + pkg = installed->pkgs[i];
  1712. + ipkg_upgrade_pkg(conf, pkg);
  1713. + }
  1714. + pkg_vec_free(installed);
  1715. + }
  1716. +
  1717. + /* recheck to verify that all dependences are satisfied */
  1718. + if (0) ipkg_satisfy_all_dependences(conf);
  1719. +
  1720. + ipkg_configure_packages(conf, NULL);
  1721. +
  1722. + write_status_files_if_changed(conf);
  1723. +
  1724. + return 0;
  1725. +}
  1726. +
  1727. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1728. +{
  1729. + int i, err;
  1730. + char *arg;
  1731. + pkg_t *pkg;
  1732. +
  1733. + pkg_info_preinstall_check(conf);
  1734. + for (i = 0; i < argc; i++) {
  1735. + arg = argv[i];
  1736. +
  1737. + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
  1738. + if (pkg == NULL) {
  1739. + ipkg_message(conf, IPKG_ERROR,
  1740. + "Cannot find package %s.\n"
  1741. + "Check the spelling or perhaps run 'ipkg update'\n",
  1742. + arg);
  1743. + continue;
  1744. + }
  1745. +
  1746. + err = ipkg_download_pkg(conf, pkg, ".");
  1747. +
  1748. + if (err) {
  1749. + ipkg_message(conf, IPKG_ERROR,
  1750. + "Failed to download %s\n", pkg->name);
  1751. + } else {
  1752. + ipkg_message(conf, IPKG_NOTICE,
  1753. + "Downloaded %s as %s\n",
  1754. + pkg->name, pkg->local_filename);
  1755. + }
  1756. + }
  1757. +
  1758. + return 0;
  1759. +}
  1760. +
  1761. +
  1762. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1763. +{
  1764. + int i ;
  1765. + pkg_vec_t *available;
  1766. + pkg_t *pkg;
  1767. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1768. + char *newline;
  1769. + char *pkg_name = NULL;
  1770. + char *version_str;
  1771. +
  1772. + if (argc > 0) {
  1773. + pkg_name = argv[0];
  1774. + }
  1775. + available = pkg_vec_alloc();
  1776. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1777. + for (i=0; i < available->len; i++) {
  1778. + pkg = available->pkgs[i];
  1779. + /* if we have package name or pattern and pkg does not match, then skip it */
  1780. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1781. + continue;
  1782. + if (pkg->description) {
  1783. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1784. + } else {
  1785. + desc_short[0] = '\0';
  1786. + }
  1787. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1788. + newline = strchr(desc_short, '\n');
  1789. + if (newline) {
  1790. + *newline = '\0';
  1791. + }
  1792. + if (ipkg_cb_list) {
  1793. + version_str = pkg_version_str_alloc(pkg);
  1794. + ipkg_cb_list(pkg->name,desc_short,
  1795. + version_str,
  1796. + pkg->state_status,
  1797. + p_userdata);
  1798. + free(version_str);
  1799. + }
  1800. + }
  1801. + pkg_vec_free(available);
  1802. +
  1803. + return 0;
  1804. +}
  1805. +
  1806. +
  1807. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1808. +{
  1809. + int i ;
  1810. + pkg_vec_t *available;
  1811. + pkg_t *pkg;
  1812. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1813. + char *newline;
  1814. + char *pkg_name = NULL;
  1815. + char *version_str;
  1816. +
  1817. + if (argc > 0) {
  1818. + pkg_name = argv[0];
  1819. + }
  1820. + available = pkg_vec_alloc();
  1821. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1822. + for (i=0; i < available->len; i++) {
  1823. + pkg = available->pkgs[i];
  1824. + /* if we have package name or pattern and pkg does not match, then skip it */
  1825. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1826. + continue;
  1827. + if (pkg->description) {
  1828. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1829. + } else {
  1830. + desc_short[0] = '\0';
  1831. + }
  1832. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1833. + newline = strchr(desc_short, '\n');
  1834. + if (newline) {
  1835. + *newline = '\0';
  1836. + }
  1837. + if (ipkg_cb_list) {
  1838. + version_str = pkg_version_str_alloc(pkg);
  1839. + ipkg_cb_list(pkg->name,desc_short,
  1840. + version_str,
  1841. + pkg->state_status,
  1842. + p_userdata);
  1843. + free(version_str);
  1844. + }
  1845. + }
  1846. +
  1847. + return 0;
  1848. +}
  1849. +
  1850. +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
  1851. +{
  1852. + int i;
  1853. + pkg_vec_t *available;
  1854. + pkg_t *pkg;
  1855. + char *pkg_name = NULL;
  1856. + char **pkg_fields = NULL;
  1857. + int n_fields = 0;
  1858. + char *buff ; // = (char *)malloc(1);
  1859. +
  1860. + if (argc > 0) {
  1861. + pkg_name = argv[0];
  1862. + }
  1863. + if (argc > 1) {
  1864. + pkg_fields = &argv[1];
  1865. + n_fields = argc - 1;
  1866. + }
  1867. +
  1868. + available = pkg_vec_alloc();
  1869. + if (installed_only)
  1870. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1871. + else
  1872. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1873. + for (i=0; i < available->len; i++) {
  1874. + pkg = available->pkgs[i];
  1875. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1876. + continue;
  1877. + }
  1878. + buff = pkg_formatted_info(pkg);
  1879. + if ( buff ) {
  1880. + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
  1881. + pkg->state_status,
  1882. + buff,
  1883. + p_userdata);
  1884. + free(buff);
  1885. + }
  1886. + if (conf->verbosity > 1) {
  1887. + conffile_list_elt_t *iter;
  1888. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  1889. + conffile_t *cf = iter->data;
  1890. + int modified = conffile_has_been_modified(conf, cf);
  1891. + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
  1892. + cf->name, cf->value, modified);
  1893. + }
  1894. + }
  1895. + }
  1896. + pkg_vec_free(available);
  1897. +
  1898. + return 0;
  1899. +}
  1900. +
  1901. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1902. +{
  1903. + return ipkg_info_status_cmd(conf, argc, argv, 0);
  1904. +}
  1905. +
  1906. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1907. +{
  1908. + return ipkg_info_status_cmd(conf, argc, argv, 1);
  1909. +}
  1910. +
  1911. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1912. +{
  1913. +
  1914. + int err;
  1915. + if (argc > 0) {
  1916. + char *pkg_name = NULL;
  1917. +
  1918. + pkg_name = argv[0];
  1919. +
  1920. + err = ipkg_configure_packages (conf, pkg_name);
  1921. +
  1922. + } else {
  1923. + err = ipkg_configure_packages (conf, NULL);
  1924. + }
  1925. +
  1926. + write_status_files_if_changed(conf);
  1927. +
  1928. + return err;
  1929. +}
  1930. +
  1931. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf)
  1932. +{
  1933. + int i, err;
  1934. + char *globpattern;
  1935. + glob_t globbuf;
  1936. +
  1937. + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
  1938. + err = glob(globpattern, 0, NULL, &globbuf);
  1939. + free(globpattern);
  1940. + if (err) {
  1941. + return 0;
  1942. + }
  1943. +
  1944. + ipkg_message(conf, IPKG_NOTICE,
  1945. + "The following packages in %s will now be installed.\n",
  1946. + conf->pending_dir);
  1947. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1948. + ipkg_message(conf, IPKG_NOTICE,
  1949. + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
  1950. + }
  1951. + ipkg_message(conf, IPKG_NOTICE, "\n");
  1952. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1953. + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
  1954. + if (err == 0) {
  1955. + err = unlink(globbuf.gl_pathv[i]);
  1956. + if (err) {
  1957. + ipkg_message(conf, IPKG_ERROR,
  1958. + "%s: ERROR: failed to unlink %s: %s\n",
  1959. + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
  1960. + return err;
  1961. + }
  1962. + }
  1963. + }
  1964. + globfree(&globbuf);
  1965. +
  1966. + return err;
  1967. +}
  1968. +
  1969. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1970. +{
  1971. + int i,a,done;
  1972. + pkg_t *pkg;
  1973. + pkg_t *pkg_to_remove;
  1974. + pkg_vec_t *available;
  1975. + char *pkg_name = NULL;
  1976. + global_conf = conf;
  1977. + signal(SIGINT, sigint_handler);
  1978. +
  1979. +// ENH: Add the "no pkg removed" just in case.
  1980. +
  1981. + done = 0;
  1982. +
  1983. + available = pkg_vec_alloc();
  1984. + pkg_info_preinstall_check(conf);
  1985. + if ( argc > 0 ) {
  1986. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1987. + for (i=0; i < argc; i++) {
  1988. + pkg_name = malloc(strlen(argv[i])+2);
  1989. + strcpy(pkg_name,argv[i]);
  1990. + for (a=0; a < available->len; a++) {
  1991. + pkg = available->pkgs[a];
  1992. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1993. + continue;
  1994. + }
  1995. + if (conf->restrict_to_default_dest) {
  1996. + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1997. + pkg->name,
  1998. + conf->default_dest);
  1999. + } else {
  2000. + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
  2001. + }
  2002. +
  2003. + if (pkg == NULL) {
  2004. + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
  2005. + continue;
  2006. + }
  2007. + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
  2008. + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
  2009. + continue;
  2010. + }
  2011. + ipkg_remove_pkg(conf, pkg_to_remove,0);
  2012. + done = 1;
  2013. + }
  2014. + free (pkg_name);
  2015. + }
  2016. + pkg_vec_free(available);
  2017. + } else {
  2018. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  2019. + int flagged_pkg_count = 0;
  2020. + int removed;
  2021. +
  2022. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
  2023. +
  2024. + for (i = 0; i < installed_pkgs->len; i++) {
  2025. + pkg = installed_pkgs->pkgs[i];
  2026. + if (pkg->state_flag & SF_USER) {
  2027. + flagged_pkg_count++;
  2028. + } else {
  2029. + if (!pkg_has_installed_dependents(pkg, NULL))
  2030. + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
  2031. + }
  2032. + }
  2033. + if (!flagged_pkg_count) {
  2034. + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
  2035. + "so refusing to uninstall unflagged non-leaf packages\n");
  2036. + return 0;
  2037. + }
  2038. +
  2039. + /* find packages not flagged SF_USER (i.e., installed to
  2040. + * satisfy a dependence) and not having any dependents, and
  2041. + * remove them */
  2042. + do {
  2043. + removed = 0;
  2044. + for (i = 0; i < installed_pkgs->len; i++) {
  2045. + pkg = installed_pkgs->pkgs[i];
  2046. + if (!(pkg->state_flag & SF_USER)
  2047. + && !pkg_has_installed_dependents(pkg, NULL)) {
  2048. + removed++;
  2049. + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
  2050. + ipkg_remove_pkg(conf, pkg,0);
  2051. + done = 1;
  2052. + }
  2053. + }
  2054. + } while (removed);
  2055. + pkg_vec_free(installed_pkgs);
  2056. + }
  2057. +
  2058. + if ( done == 0 )
  2059. + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
  2060. +
  2061. + write_status_files_if_changed(conf);
  2062. + return 0;
  2063. +}
  2064. +
  2065. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2066. +{
  2067. + int i;
  2068. + pkg_t *pkg;
  2069. +
  2070. + global_conf = conf;
  2071. + signal(SIGINT, sigint_handler);
  2072. +
  2073. + pkg_info_preinstall_check(conf);
  2074. +
  2075. + for (i=0; i < argc; i++) {
  2076. + if (conf->restrict_to_default_dest) {
  2077. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  2078. + argv[i],
  2079. + conf->default_dest);
  2080. + } else {
  2081. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  2082. + }
  2083. +
  2084. + if (pkg == NULL) {
  2085. + ipkg_message(conf, IPKG_ERROR,
  2086. + "Package %s is not installed.\n", argv[i]);
  2087. + continue;
  2088. + }
  2089. + ipkg_purge_pkg(conf, pkg);
  2090. + }
  2091. +
  2092. + write_status_files_if_changed(conf);
  2093. + return 0;
  2094. +}
  2095. +
  2096. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2097. +{
  2098. + int i;
  2099. + pkg_t *pkg;
  2100. + char *flags = argv[0];
  2101. +
  2102. + global_conf = conf;
  2103. + signal(SIGINT, sigint_handler);
  2104. +
  2105. + for (i=1; i < argc; i++) {
  2106. + if (conf->restrict_to_default_dest) {
  2107. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  2108. + argv[i],
  2109. + conf->default_dest);
  2110. + } else {
  2111. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  2112. + }
  2113. +
  2114. + if (pkg == NULL) {
  2115. + ipkg_message(conf, IPKG_ERROR,
  2116. + "Package %s is not installed.\n", argv[i]);
  2117. + continue;
  2118. + }
  2119. + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
  2120. + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
  2121. + pkg->state_flag = pkg_state_flag_from_str(flags);
  2122. + }
  2123. +/* pb_ asked this feature 03292004 */
  2124. +/* Actually I will use only this two, but this is an open for various status */
  2125. + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
  2126. + pkg->state_status = pkg_state_status_from_str(flags);
  2127. + }
  2128. + ipkg_state_changed++;
  2129. + ipkg_message(conf, IPKG_NOTICE,
  2130. + "Setting flags for package %s to %s\n",
  2131. + pkg->name, flags);
  2132. + }
  2133. +
  2134. + write_status_files_if_changed(conf);
  2135. + return 0;
  2136. +}
  2137. +
  2138. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2139. +{
  2140. + pkg_t *pkg;
  2141. + str_list_t *installed_files;
  2142. + str_list_elt_t *iter;
  2143. + char *pkg_version;
  2144. + size_t buff_len = 8192;
  2145. + size_t used_len;
  2146. + char *buff ;
  2147. +
  2148. + buff = (char *)malloc(buff_len);
  2149. + if ( buff == NULL ) {
  2150. + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
  2151. + return ENOMEM;
  2152. + }
  2153. +
  2154. + if (argc < 1) {
  2155. + return EINVAL;
  2156. + }
  2157. +
  2158. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  2159. + argv[0]);
  2160. + if (pkg == NULL) {
  2161. + ipkg_message(conf, IPKG_ERROR,
  2162. + "Package %s not installed.\n", argv[0]);
  2163. + return 0;
  2164. + }
  2165. +
  2166. + installed_files = pkg_get_installed_files(pkg);
  2167. + pkg_version = pkg_version_str_alloc(pkg);
  2168. +
  2169. + printf("Package %s (%s) is installed on %s and has the following files:\n",
  2170. + pkg->name, pkg_version, pkg->dest->name);
  2171. + for (iter = installed_files->head; iter; iter = iter->next) {
  2172. + puts(iter->data);
  2173. + }
  2174. +
  2175. + free(pkg_version);
  2176. + pkg_free_installed_files(pkg);
  2177. +
  2178. + return 0;
  2179. +}
  2180. +
  2181. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2182. +{
  2183. +
  2184. + if (argc > 0) {
  2185. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2186. + const char *rel_str = "depends on";
  2187. + int i;
  2188. +
  2189. + pkg_info_preinstall_check(conf);
  2190. +
  2191. + if (conf->query_all)
  2192. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2193. + else
  2194. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2195. + for (i = 0; i < argc; i++) {
  2196. + const char *target = argv[i];
  2197. + int j;
  2198. +
  2199. + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
  2200. +
  2201. + for (j = 0; j < available_pkgs->len; j++) {
  2202. + pkg_t *pkg = available_pkgs->pkgs[j];
  2203. + if (fnmatch(target, pkg->name, 0) == 0) {
  2204. + int k;
  2205. + int count = pkg->depends_count + pkg->pre_depends_count;
  2206. + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
  2207. + target, pkg->architecture, rel_str);
  2208. + for (k = 0; k < count; k++) {
  2209. + compound_depend_t *cdepend = &pkg->depends[k];
  2210. + int l;
  2211. + for (l = 0; l < cdepend->possibility_count; l++) {
  2212. + depend_t *possibility = cdepend->possibilities[l];
  2213. + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
  2214. + if (conf->verbosity > 0) {
  2215. + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
  2216. + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
  2217. + if (possibility->version) {
  2218. + const char *typestr = NULL;
  2219. + switch (possibility->constraint) {
  2220. + case NONE: typestr = "none"; break;
  2221. + case EARLIER: typestr = "<"; break;
  2222. + case EARLIER_EQUAL: typestr = "<="; break;
  2223. + case EQUAL: typestr = "="; break;
  2224. + case LATER_EQUAL: typestr = ">="; break;
  2225. + case LATER: typestr = ">"; break;
  2226. + }
  2227. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2228. + }
  2229. + // free(ver);
  2230. + }
  2231. + ipkg_message(conf, IPKG_ERROR, "\n");
  2232. + }
  2233. + }
  2234. + }
  2235. + }
  2236. + }
  2237. + pkg_vec_free(available_pkgs);
  2238. + }
  2239. + return 0;
  2240. +}
  2241. +
  2242. +enum what_field_type {
  2243. + WHATDEPENDS,
  2244. + WHATCONFLICTS,
  2245. + WHATPROVIDES,
  2246. + WHATREPLACES,
  2247. + WHATRECOMMENDS,
  2248. + WHATSUGGESTS
  2249. +};
  2250. +
  2251. +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
  2252. +{
  2253. +
  2254. + if (argc > 0) {
  2255. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2256. + const char *rel_str = NULL;
  2257. + int i;
  2258. + int changed;
  2259. +
  2260. + switch (what_field_type) {
  2261. + case WHATDEPENDS: rel_str = "depends on"; break;
  2262. + case WHATCONFLICTS: rel_str = "conflicts with"; break;
  2263. + case WHATSUGGESTS: rel_str = "suggests"; break;
  2264. + case WHATRECOMMENDS: rel_str = "recommends"; break;
  2265. + case WHATPROVIDES: rel_str = "provides"; break;
  2266. + case WHATREPLACES: rel_str = "replaces"; break;
  2267. + }
  2268. +
  2269. + if (conf->query_all)
  2270. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2271. + else
  2272. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2273. +
  2274. + /* mark the root set */
  2275. + pkg_vec_clear_marks(available_pkgs);
  2276. + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
  2277. + for (i = 0; i < argc; i++) {
  2278. + const char *dependee_pattern = argv[i];
  2279. + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
  2280. + }
  2281. + for (i = 0; i < available_pkgs->len; i++) {
  2282. + pkg_t *pkg = available_pkgs->pkgs[i];
  2283. + if (pkg->state_flag & SF_MARKED) {
  2284. + /* mark the parent (abstract) package */
  2285. + pkg_mark_provides(pkg);
  2286. + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
  2287. + }
  2288. + }
  2289. +
  2290. + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
  2291. + do {
  2292. + int j;
  2293. + changed = 0;
  2294. +
  2295. + for (j = 0; j < available_pkgs->len; j++) {
  2296. + pkg_t *pkg = available_pkgs->pkgs[j];
  2297. + int k;
  2298. + int count = ((what_field_type == WHATCONFLICTS)
  2299. + ? pkg->conflicts_count
  2300. + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
  2301. + /* skip this package if it is already marked */
  2302. + if (pkg->parent->state_flag & SF_MARKED) {
  2303. + continue;
  2304. + }
  2305. + for (k = 0; k < count; k++) {
  2306. + compound_depend_t *cdepend =
  2307. + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
  2308. + int l;
  2309. + for (l = 0; l < cdepend->possibility_count; l++) {
  2310. + depend_t *possibility = cdepend->possibilities[l];
  2311. + if (possibility->pkg->state_flag & SF_MARKED) {
  2312. + /* mark the depending package so we won't visit it again */
  2313. + pkg->state_flag |= SF_MARKED;
  2314. + pkg_mark_provides(pkg);
  2315. + changed++;
  2316. +
  2317. + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
  2318. + if (conf->verbosity > 0) {
  2319. + char *ver = pkg_version_str_alloc(pkg);
  2320. + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
  2321. + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
  2322. + if (possibility->version) {
  2323. + const char *typestr = NULL;
  2324. + switch (possibility->constraint) {
  2325. + case NONE: typestr = "none"; break;
  2326. + case EARLIER: typestr = "<"; break;
  2327. + case EARLIER_EQUAL: typestr = "<="; break;
  2328. + case EQUAL: typestr = "="; break;
  2329. + case LATER_EQUAL: typestr = ">="; break;
  2330. + case LATER: typestr = ">"; break;
  2331. + }
  2332. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2333. + }
  2334. + free(ver);
  2335. + if (!pkg_dependence_satisfiable(possibility))
  2336. + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
  2337. + }
  2338. + ipkg_message(conf, IPKG_NOTICE, "\n");
  2339. + goto next_package;
  2340. + }
  2341. + }
  2342. + }
  2343. + next_package:
  2344. + ;
  2345. + }
  2346. + } while (changed && recursive);
  2347. + pkg_vec_free(available_pkgs);
  2348. + }
  2349. +
  2350. + return 0;
  2351. +}
  2352. +
  2353. +int pkg_mark_provides(pkg_t *pkg)
  2354. +{
  2355. + int provides_count = pkg->provides_count;
  2356. + abstract_pkg_t **provides = pkg->provides;
  2357. + int i;
  2358. + pkg->parent->state_flag |= SF_MARKED;
  2359. + for (i = 0; i < provides_count; i++) {
  2360. + provides[i]->state_flag |= SF_MARKED;
  2361. + }
  2362. + return 0;
  2363. +}
  2364. +
  2365. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2366. +{
  2367. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
  2368. +}
  2369. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2370. +{
  2371. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
  2372. +}
  2373. +
  2374. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2375. +{
  2376. + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
  2377. +}
  2378. +
  2379. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2380. +{
  2381. + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
  2382. +}
  2383. +
  2384. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2385. +{
  2386. + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
  2387. +}
  2388. +
  2389. +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
  2390. +{
  2391. +
  2392. + if (argc > 0) {
  2393. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2394. + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
  2395. + int i;
  2396. +
  2397. + pkg_info_preinstall_check(conf);
  2398. +
  2399. + if (conf->query_all)
  2400. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2401. + else
  2402. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2403. + for (i = 0; i < argc; i++) {
  2404. + const char *target = argv[i];
  2405. + int j;
  2406. +
  2407. + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
  2408. + rel_str, target);
  2409. + for (j = 0; j < available_pkgs->len; j++) {
  2410. + pkg_t *pkg = available_pkgs->pkgs[j];
  2411. + int k;
  2412. + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
  2413. + for (k = 0; k < count; k++) {
  2414. + abstract_pkg_t *apkg =
  2415. + ((what_field_type == WHATPROVIDES)
  2416. + ? pkg->provides[k]
  2417. + : pkg->replaces[k]);
  2418. + if (fnmatch(target, apkg->name, 0) == 0) {
  2419. + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
  2420. + if (strcmp(target, apkg->name) != 0)
  2421. + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
  2422. + ipkg_message(conf, IPKG_ERROR, "\n");
  2423. + }
  2424. + }
  2425. + }
  2426. + }
  2427. + pkg_vec_free(available_pkgs);
  2428. + }
  2429. + return 0;
  2430. +}
  2431. +
  2432. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2433. +{
  2434. + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
  2435. +}
  2436. +
  2437. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2438. +{
  2439. + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
  2440. +}
  2441. +
  2442. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2443. +{
  2444. + int i;
  2445. +
  2446. + pkg_vec_t *installed;
  2447. + pkg_t *pkg;
  2448. + str_list_t *installed_files;
  2449. + str_list_elt_t *iter;
  2450. + char *installed_file;
  2451. +
  2452. + if (argc < 1) {
  2453. + return EINVAL;
  2454. + }
  2455. +
  2456. + installed = pkg_vec_alloc();
  2457. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  2458. +
  2459. + for (i=0; i < installed->len; i++) {
  2460. + pkg = installed->pkgs[i];
  2461. +
  2462. + installed_files = pkg_get_installed_files(pkg);
  2463. +
  2464. + for (iter = installed_files->head; iter; iter = iter->next) {
  2465. + installed_file = iter->data;
  2466. + if (fnmatch(argv[0], installed_file, 0)==0) {
  2467. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2468. + installed_file,
  2469. + pkg_version_str_alloc(pkg),
  2470. + pkg->state_status, p_userdata);
  2471. + }
  2472. + }
  2473. +
  2474. + pkg_free_installed_files(pkg);
  2475. + }
  2476. +
  2477. + /* XXX: CLEANUP: It's not obvious from the name of
  2478. + pkg_hash_fetch_all_installed that we need to call
  2479. + pkg_vec_free to avoid a memory leak. */
  2480. + pkg_vec_free(installed);
  2481. +
  2482. + return 0;
  2483. +}
  2484. +
  2485. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2486. +{
  2487. + if (argc == 3) {
  2488. + /* this is a bit gross */
  2489. + struct pkg p1, p2;
  2490. + parseVersion(&p1, argv[0]);
  2491. + parseVersion(&p2, argv[2]);
  2492. + return pkg_version_satisfied(&p1, &p2, argv[1]);
  2493. + } else {
  2494. + ipkg_message(conf, IPKG_ERROR,
  2495. + "ipkg compare_versions <v1> <op> <v2>\n"
  2496. + "<op> is one of <= >= << >> =\n");
  2497. + return -1;
  2498. + }
  2499. +}
  2500. +
  2501. +#ifndef HOST_CPU_STR
  2502. +#define HOST_CPU_STR__(X) #X
  2503. +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
  2504. +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
  2505. +#endif
  2506. +
  2507. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf)
  2508. +{
  2509. + nv_pair_list_elt_t *l;
  2510. +
  2511. + l = conf->arch_list.head;
  2512. + while (l) {
  2513. + nv_pair_t *nv = l->data;
  2514. + printf("arch %s %s\n", nv->name, nv->value);
  2515. + l = l->next;
  2516. + }
  2517. + return 0;
  2518. +}
  2519. +
  2520. +
  2521. diff -Nur busybox-1.18.1.orig/archival/libipkg/ipkg_cmd.h busybox-1.18.1/archival/libipkg/ipkg_cmd.h
  2522. --- busybox-1.18.1.orig/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
  2523. +++ busybox-1.18.1/archival/libipkg/ipkg_cmd.h 2010-12-25 22:38:07.000000000 +0100
  2524. @@ -0,0 +1,41 @@
  2525. +/* ipkg_cmd.h - the itsy package management system
  2526. +
  2527. + Carl D. Worth
  2528. +
  2529. + Copyright (C) 2001 University of Southern California
  2530. +
  2531. + This program is free software; you can redistribute it and/or
  2532. + modify it under the terms of the GNU General Public License as
  2533. + published by the Free Software Foundation; either version 2, or (at
  2534. + your option) any later version.
  2535. +
  2536. + This program is distributed in the hope that it will be useful, but
  2537. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2538. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2539. + General Public License for more details.
  2540. +*/
  2541. +
  2542. +#ifndef IPKG_CMD_H
  2543. +#define IPKG_CMD_H
  2544. +
  2545. +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
  2546. +
  2547. +struct ipkg_cmd
  2548. +{
  2549. + const char *name;
  2550. + int requires_args;
  2551. + ipkg_cmd_fun_t fun;
  2552. +};
  2553. +typedef struct ipkg_cmd ipkg_cmd_t;
  2554. +
  2555. +ipkg_cmd_t *ipkg_cmd_find(const char *name);
  2556. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
  2557. + const char **argv, void *userdata);
  2558. +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
  2559. +/* install any packges with state_want == SW_INSTALL */
  2560. +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
  2561. +/* ensure that all dependences are satisfied */
  2562. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
  2563. +int pkg_mark_provides(pkg_t *pkg);
  2564. +
  2565. +#endif
  2566. diff -Nur busybox-1.18.1.orig/archival/libipkg/ipkg_conf.c busybox-1.18.1/archival/libipkg/ipkg_conf.c
  2567. --- busybox-1.18.1.orig/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
  2568. +++ busybox-1.18.1/archival/libipkg/ipkg_conf.c 2010-12-25 22:38:07.000000000 +0100
  2569. @@ -0,0 +1,711 @@
  2570. +/* ipkg_conf.c - the itsy package management system
  2571. +
  2572. + Carl D. Worth
  2573. +
  2574. + Copyright (C) 2001 University of Southern California
  2575. +
  2576. + This program is free software; you can redistribute it and/or
  2577. + modify it under the terms of the GNU General Public License as
  2578. + published by the Free Software Foundation; either version 2, or (at
  2579. + your option) any later version.
  2580. +
  2581. + This program is distributed in the hope that it will be useful, but
  2582. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2583. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2584. + General Public License for more details.
  2585. +*/
  2586. +
  2587. +#include <glob.h>
  2588. +
  2589. +#include "ipkg.h"
  2590. +#include "ipkg_conf.h"
  2591. +
  2592. +#include "xregex.h"
  2593. +#include "sprintf_alloc.h"
  2594. +#include "ipkg_conf.h"
  2595. +#include "ipkg_message.h"
  2596. +#include "file_util.h"
  2597. +#include "str_util.h"
  2598. +#include "xsystem.h"
  2599. +
  2600. +
  2601. +ipkg_conf_t *global_conf;
  2602. +
  2603. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2604. + pkg_src_list_t *pkg_src_list,
  2605. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2606. + char **tmp_lists_dir);
  2607. +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
  2608. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  2609. + const char *name, const char *value);
  2610. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2611. + const char *default_dest_name);
  2612. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
  2613. + pkg_src_list_t *nv_pair_list);
  2614. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
  2615. + nv_pair_list_t *nv_pair_list, char * lists_dir);
  2616. +
  2617. +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
  2618. +{
  2619. + ipkg_option_t tmp[] = {
  2620. + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
  2621. + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
  2622. + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
  2623. + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
  2624. + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
  2625. + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
  2626. + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
  2627. + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
  2628. + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
  2629. + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
  2630. + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
  2631. + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
  2632. + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
  2633. + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
  2634. + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
  2635. + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
  2636. + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
  2637. + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
  2638. + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
  2639. + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
  2640. + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
  2641. + { NULL }
  2642. + };
  2643. +
  2644. + *options = (ipkg_option_t *)malloc(sizeof(tmp));
  2645. + if ( options == NULL ){
  2646. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  2647. + return -1;
  2648. + }
  2649. +
  2650. + memcpy(*options, tmp, sizeof(tmp));
  2651. + return 0;
  2652. +};
  2653. +
  2654. +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
  2655. +{
  2656. + if (arg_str) {
  2657. + if (*conf_str) {
  2658. + free(*conf_str);
  2659. + }
  2660. + *conf_str = strdup(arg_str);
  2661. + }
  2662. +}
  2663. +
  2664. +static void ipkg_conf_free_string(char **conf_str)
  2665. +{
  2666. + if (*conf_str) {
  2667. + free(*conf_str);
  2668. + *conf_str = NULL;
  2669. + }
  2670. +}
  2671. +
  2672. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
  2673. +{
  2674. + int err;
  2675. + char *tmp_dir_base;
  2676. + nv_pair_list_t tmp_dest_nv_pair_list;
  2677. + char * lists_dir =NULL;
  2678. + glob_t globbuf;
  2679. + const char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
  2680. + char *pending_dir =NULL;
  2681. +
  2682. + memset(conf, 0, sizeof(ipkg_conf_t));
  2683. +
  2684. + pkg_src_list_init(&conf->pkg_src_list);
  2685. +
  2686. + nv_pair_list_init(&tmp_dest_nv_pair_list);
  2687. + pkg_dest_list_init(&conf->pkg_dest_list);
  2688. +
  2689. + nv_pair_list_init(&conf->arch_list);
  2690. +
  2691. + conf->restrict_to_default_dest = 0;
  2692. + conf->default_dest = NULL;
  2693. +
  2694. +
  2695. + if (args->tmp_dir)
  2696. + tmp_dir_base = args->tmp_dir;
  2697. + else
  2698. + tmp_dir_base = getenv("TMPDIR");
  2699. + sprintf_alloc(&conf->tmp_dir, "%s/%s",
  2700. + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
  2701. + IPKG_CONF_TMP_DIR_SUFFIX);
  2702. + conf->tmp_dir = mkdtemp(conf->tmp_dir);
  2703. + if (conf->tmp_dir == NULL) {
  2704. + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
  2705. + __FUNCTION__, conf->tmp_dir, strerror(errno));
  2706. + return errno;
  2707. + }
  2708. +
  2709. + conf->force_depends = 0;
  2710. + conf->force_defaults = 0;
  2711. + conf->force_overwrite = 0;
  2712. + conf->force_downgrade = 0;
  2713. + conf->force_reinstall = 0;
  2714. + conf->force_space = 0;
  2715. + conf->force_removal_of_essential_packages = 0;
  2716. + conf->force_removal_of_dependent_packages = 0;
  2717. + conf->nodeps = 0;
  2718. + conf->verbose_wget = 0;
  2719. + conf->offline_root = NULL;
  2720. + conf->offline_root_pre_script_cmd = NULL;
  2721. + conf->offline_root_post_script_cmd = NULL;
  2722. + conf->multiple_providers = 0;
  2723. + conf->verbosity = 1;
  2724. + conf->noaction = 0;
  2725. +
  2726. + conf->http_proxy = NULL;
  2727. + conf->ftp_proxy = NULL;
  2728. + conf->no_proxy = NULL;
  2729. + conf->proxy_user = NULL;
  2730. + conf->proxy_passwd = NULL;
  2731. +
  2732. + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2733. + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2734. + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2735. + lists_dir=(char *)malloc(1);
  2736. + lists_dir[0]='\0';
  2737. + if (args->conf_file) {
  2738. + struct stat stat_buf;
  2739. + err = stat(args->conf_file, &stat_buf);
  2740. + if (err == 0)
  2741. + if (ipkg_conf_parse_file(conf, args->conf_file,
  2742. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2743. + /* Memory leakage from ipkg_conf_parse-file */
  2744. + return -1;
  2745. + }
  2746. +
  2747. + }
  2748. +
  2749. + /* if (!lists_dir ){*/
  2750. + if (strlen(lists_dir)<=1 ){
  2751. + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
  2752. + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
  2753. + }
  2754. +
  2755. + if (args->offline_root) {
  2756. + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
  2757. + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
  2758. + free(lists_dir);
  2759. + lists_dir = tmp;
  2760. + }
  2761. +
  2762. + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
  2763. + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
  2764. +
  2765. + conf->lists_dir = strdup(lists_dir);
  2766. + conf->pending_dir = strdup(pending_dir);
  2767. +
  2768. + if (args->offline_root)
  2769. + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
  2770. + memset(&globbuf, 0, sizeof(globbuf));
  2771. + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
  2772. + if (!err) {
  2773. + int i;
  2774. + for (i = 0; i < globbuf.gl_pathc; i++) {
  2775. + if (globbuf.gl_pathv[i])
  2776. + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
  2777. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2778. + /* Memory leakage from ipkg_conf_parse-file */
  2779. + return -1;
  2780. + }
  2781. + }
  2782. + }
  2783. + globfree(&globbuf);
  2784. +
  2785. + /* if no architectures were defined, then default all, noarch, and host architecture */
  2786. + if (nv_pair_list_empty(&conf->arch_list)) {
  2787. + nv_pair_list_append(&conf->arch_list, "all", "1");
  2788. + nv_pair_list_append(&conf->arch_list, "noarch", "1");
  2789. + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
  2790. + }
  2791. +
  2792. + /* Even if there is no conf file, we'll need at least one dest. */
  2793. + if (tmp_dest_nv_pair_list.head == NULL) {
  2794. + nv_pair_list_append(&tmp_dest_nv_pair_list,
  2795. + IPKG_CONF_DEFAULT_DEST_NAME,
  2796. + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
  2797. + }
  2798. +
  2799. + /* After parsing the file, set options from command-line, (so that
  2800. + command-line arguments take precedence) */
  2801. + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
  2802. + really needs to be cleaned up. There is so much duplication
  2803. + right now it is ridiculous. Maybe ipkg_conf_t should just save
  2804. + a pointer to args_t (which could then not be freed), rather
  2805. + than duplicating every field here? */
  2806. + if (args->force_depends) {
  2807. + conf->force_depends = 1;
  2808. + }
  2809. + if (args->force_defaults) {
  2810. + conf->force_defaults = 1;
  2811. + }
  2812. + if (args->force_overwrite) {
  2813. + conf->force_overwrite = 1;
  2814. + }
  2815. + if (args->force_downgrade) {
  2816. + conf->force_downgrade = 1;
  2817. + }
  2818. + if (args->force_reinstall) {
  2819. + conf->force_reinstall = 1;
  2820. + }
  2821. + if (args->force_removal_of_dependent_packages) {
  2822. + conf->force_removal_of_dependent_packages = 1;
  2823. + }
  2824. + if (args->force_removal_of_essential_packages) {
  2825. + conf->force_removal_of_essential_packages = 1;
  2826. + }
  2827. + if (args->nodeps) {
  2828. + conf->nodeps = 1;
  2829. + }
  2830. + if (args->noaction) {
  2831. + conf->noaction = 1;
  2832. + }
  2833. + if (args->query_all) {
  2834. + conf->query_all = 1;
  2835. + }
  2836. + if (args->verbose_wget) {
  2837. + conf->verbose_wget = 1;
  2838. + }
  2839. + if (args->multiple_providers) {
  2840. + conf->multiple_providers = 1;
  2841. + }
  2842. + if (args->verbosity != conf->verbosity) {
  2843. + conf->verbosity = args->verbosity;
  2844. + }
  2845. +
  2846. + ipkg_conf_override_string(&conf->offline_root,
  2847. + args->offline_root);
  2848. + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
  2849. + args->offline_root_pre_script_cmd);
  2850. + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
  2851. + args->offline_root_post_script_cmd);
  2852. +
  2853. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  2854. + read anything from there.
  2855. +*/
  2856. + if ( !(args->nocheckfordirorfile)){
  2857. + /* need to run load the source list before dest list -Jamey */
  2858. + if ( !(args->noreadfeedsfile))
  2859. + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
  2860. +
  2861. + /* Now that we have resolved conf->offline_root, we can commit to
  2862. + the directory names for the dests and load in all the package
  2863. + lists. */
  2864. + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
  2865. +
  2866. + if (args->dest) {
  2867. + err = ipkg_conf_set_default_dest(conf, args->dest);
  2868. + if (err) {
  2869. + return err;
  2870. + }
  2871. + }
  2872. + }
  2873. + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
  2874. + free(lists_dir);
  2875. + free(pending_dir);
  2876. +
  2877. + return 0;
  2878. +}
  2879. +
  2880. +void ipkg_conf_deinit(ipkg_conf_t *conf)
  2881. +{
  2882. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  2883. +#error
  2884. + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
  2885. + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  2886. + __FUNCTION__, conf->tmp_dir);
  2887. +#else
  2888. + int err;
  2889. +
  2890. + err = rmdir(conf->tmp_dir);
  2891. + if (err) {
  2892. + if (errno == ENOTEMPTY) {
  2893. + char *cmd;
  2894. + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
  2895. + err = xsystem(cmd);
  2896. + free(cmd);
  2897. + }
  2898. + if (err)
  2899. + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
  2900. + }
  2901. +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
  2902. +
  2903. + free(conf->tmp_dir); /*XXX*/
  2904. +
  2905. + pkg_src_list_deinit(&conf->pkg_src_list);
  2906. + pkg_dest_list_deinit(&conf->pkg_dest_list);
  2907. + nv_pair_list_deinit(&conf->arch_list);
  2908. + if (&conf->pkg_hash)
  2909. + pkg_hash_deinit(&conf->pkg_hash);
  2910. + if (&conf->file_hash)
  2911. + hash_table_deinit(&conf->file_hash);
  2912. + if (&conf->obs_file_hash)
  2913. + hash_table_deinit(&conf->obs_file_hash);
  2914. +
  2915. + ipkg_conf_free_string(&conf->offline_root);
  2916. + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
  2917. + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
  2918. +
  2919. + if (conf->verbosity > 1) {
  2920. + int i;
  2921. + hash_table_t *hashes[] = {
  2922. + &conf->pkg_hash,
  2923. + &conf->file_hash,
  2924. + &conf->obs_file_hash };
  2925. + for (i = 0; i < 3; i++) {
  2926. + hash_table_t *hash = hashes[i];
  2927. + int c = 0;
  2928. + int n_conflicts = 0;
  2929. + int j;
  2930. + for (j = 0; j < hash->n_entries; j++) {
  2931. + int len = 0;
  2932. + hash_entry_t *e = &hash->entries[j];
  2933. + if (e->next)
  2934. + n_conflicts++;
  2935. + while (e && e->key) {
  2936. + len++;
  2937. + e = e->next;
  2938. + }
  2939. + if (len > c)
  2940. + c = len;
  2941. + }
  2942. + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
  2943. + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
  2944. + hash_table_deinit(hash);
  2945. + }
  2946. + }
  2947. +}
  2948. +
  2949. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2950. + const char *default_dest_name)
  2951. +{
  2952. + pkg_dest_list_elt_t *iter;
  2953. + pkg_dest_t *dest;
  2954. +
  2955. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  2956. + dest = iter->data;
  2957. + if (strcmp(dest->name, default_dest_name) == 0) {
  2958. + conf->default_dest = dest;
  2959. + conf->restrict_to_default_dest = 1;
  2960. + return 0;
  2961. + }
  2962. + }
  2963. +
  2964. + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
  2965. +
  2966. + return 1;
  2967. +}
  2968. +
  2969. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
  2970. +{
  2971. + pkg_src_list_elt_t *iter;
  2972. + pkg_src_t *src;
  2973. + char *list_file;
  2974. +
  2975. + for (iter = pkg_src_list->head; iter; iter = iter->next) {
  2976. + src = iter->data;
  2977. + if (src == NULL) {
  2978. + continue;
  2979. + }
  2980. +
  2981. + sprintf_alloc(&list_file, "%s/%s",
  2982. + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
  2983. + src->name);
  2984. +
  2985. + if (file_exists(list_file)) {
  2986. + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
  2987. + }
  2988. + free(list_file);
  2989. + }
  2990. +
  2991. + return 0;
  2992. +}
  2993. +
  2994. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
  2995. +{
  2996. + nv_pair_list_elt_t *iter;
  2997. + nv_pair_t *nv_pair;
  2998. + pkg_dest_t *dest;
  2999. + char *root_dir;
  3000. +
  3001. + for (iter = nv_pair_list->head; iter; iter = iter->next) {
  3002. + nv_pair = iter->data;
  3003. +
  3004. + if (conf->offline_root) {
  3005. + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
  3006. + } else {
  3007. + root_dir = strdup(nv_pair->value);
  3008. + }
  3009. + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
  3010. + free(root_dir);
  3011. + if (dest == NULL) {
  3012. + continue;
  3013. + }
  3014. + if (conf->default_dest == NULL) {
  3015. + conf->default_dest = dest;
  3016. + }
  3017. + if (file_exists(dest->status_file_name)) {
  3018. + pkg_hash_add_from_file(conf, dest->status_file_name,
  3019. + NULL, dest, 1);
  3020. + }
  3021. + }
  3022. +
  3023. + return 0;
  3024. +}
  3025. +
  3026. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  3027. + pkg_src_list_t *pkg_src_list,
  3028. + nv_pair_list_t *tmp_dest_nv_pair_list,
  3029. + char **lists_dir)
  3030. +{
  3031. + ipkg_option_t * options;
  3032. + FILE *file = fopen(filename, "r");
  3033. + regex_t valid_line_re, comment_re;
  3034. +#define regmatch_size 12
  3035. + regmatch_t regmatch[regmatch_size];
  3036. +
  3037. + if (ipkg_init_options_array(conf, &options)<0)
  3038. + return ENOMEM;
  3039. +
  3040. + if (file == NULL) {
  3041. + fprintf(stderr, "%s: failed to open %s: %s\n",
  3042. + __FUNCTION__, filename, strerror(errno));
  3043. + free(options);
  3044. + return errno;
  3045. + }
  3046. + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
  3047. +
  3048. + xregcomp(&comment_re,
  3049. + "^[[:space:]]*(#.*|[[:space:]]*)$",
  3050. + REG_EXTENDED);
  3051. + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
  3052. +
  3053. + while(1) {
  3054. + int line_num = 0;
  3055. + char *line;
  3056. + char *type, *name, *value, *extra;
  3057. +
  3058. + line = file_read_line_alloc(file);
  3059. + line_num++;
  3060. + if (line == NULL) {
  3061. + break;
  3062. + }
  3063. +
  3064. + str_chomp(line);
  3065. +
  3066. + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
  3067. + goto NEXT_LINE;
  3068. + }
  3069. +
  3070. + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
  3071. + str_chomp(line);
  3072. + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
  3073. + filename, line_num, line);
  3074. + goto NEXT_LINE;
  3075. + }
  3076. +
  3077. + /* This has to be so ugly to deal with optional quotation marks */
  3078. + if (regmatch[2].rm_so > 0) {
  3079. + type = strndup(line + regmatch[2].rm_so,
  3080. + regmatch[2].rm_eo - regmatch[2].rm_so);
  3081. + } else {
  3082. + type = strndup(line + regmatch[3].rm_so,
  3083. + regmatch[3].rm_eo - regmatch[3].rm_so);
  3084. + }
  3085. + if (regmatch[5].rm_so > 0) {
  3086. + name = strndup(line + regmatch[5].rm_so,
  3087. + regmatch[5].rm_eo - regmatch[5].rm_so);
  3088. + } else {
  3089. + name = strndup(line + regmatch[6].rm_so,
  3090. + regmatch[6].rm_eo - regmatch[6].rm_so);
  3091. + }
  3092. + if (regmatch[8].rm_so > 0) {
  3093. + value = strndup(line + regmatch[8].rm_so,
  3094. + regmatch[8].rm_eo - regmatch[8].rm_so);
  3095. + } else {
  3096. + value = strndup(line + regmatch[9].rm_so,
  3097. + regmatch[9].rm_eo - regmatch[9].rm_so);
  3098. + }
  3099. + extra = NULL;
  3100. + if (regmatch[11].rm_so > 0) {
  3101. + extra = strndup (line + regmatch[11].rm_so,
  3102. + regmatch[11].rm_eo - regmatch[11].rm_so);
  3103. + }
  3104. +
  3105. + /* We use the tmp_dest_nv_pair_list below instead of
  3106. + conf->pkg_dest_list because we might encounter an
  3107. + offline_root option later and that would invalidate the
  3108. + directories we would have computed in
  3109. + pkg_dest_list_init. (We do a similar thing with
  3110. + tmp_src_nv_pair_list for sake of symmetry.) */
  3111. + if (strcmp(type, "option") == 0) {
  3112. + ipkg_conf_set_option(options, name, value);
  3113. + } else if (strcmp(type, "src") == 0) {
  3114. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3115. + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
  3116. + } else {
  3117. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3118. + name, value);
  3119. + }
  3120. + } else if (strcmp(type, "src/gz") == 0) {
  3121. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3122. + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
  3123. + } else {
  3124. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3125. + name, value);
  3126. + }
  3127. + } else if (strcmp(type, "dest") == 0) {
  3128. + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
  3129. + } else if (strcmp(type, "lists_dir") == 0) {
  3130. + *lists_dir = realloc(*lists_dir,strlen(value)+1);
  3131. + if (*lists_dir == NULL) {
  3132. + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
  3133. + free(options);
  3134. + return EINVAL;
  3135. + }
  3136. + sprintf (*lists_dir,"%s",value);
  3137. + } else if (strcmp(type, "arch") == 0) {
  3138. + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
  3139. + if (!value) {
  3140. + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
  3141. + value = strdup("10");
  3142. + }
  3143. + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
  3144. + } else {
  3145. + fprintf(stderr, "WARNING: Ignoring unknown configuration "
  3146. + "parameter: %s %s %s\n", type, name, value);
  3147. + free(options);
  3148. + return EINVAL;
  3149. + }
  3150. +
  3151. + free(type);
  3152. + free(name);
  3153. + free(value);
  3154. + if (extra)
  3155. + free (extra);
  3156. +
  3157. + NEXT_LINE:
  3158. + free(line);
  3159. + }
  3160. +
  3161. + free(options);
  3162. + regfree(&comment_re);
  3163. + regfree(&valid_line_re);
  3164. + fclose(file);
  3165. +
  3166. + return 0;
  3167. +}
  3168. +
  3169. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  3170. + const char *name, const char *value)
  3171. +{
  3172. + int i = 0;
  3173. + while (options[i].name) {
  3174. + if (strcmp(options[i].name, name) == 0) {
  3175. + switch (options[i].type) {
  3176. + case IPKG_OPT_TYPE_BOOL:
  3177. + *((int *)options[i].value) = 1;
  3178. + return 0;
  3179. + case IPKG_OPT_TYPE_INT:
  3180. + if (value) {
  3181. + *((int *)options[i].value) = atoi(value);
  3182. + return 0;
  3183. + } else {
  3184. + printf("%s: Option %s need an argument\n",
  3185. + __FUNCTION__, name);
  3186. + return EINVAL;
  3187. + }
  3188. + case IPKG_OPT_TYPE_STRING:
  3189. + if (value) {
  3190. + *((char **)options[i].value) = strdup(value);
  3191. + return 0;
  3192. + } else {
  3193. + printf("%s: Option %s need an argument\n",
  3194. + __FUNCTION__, name);
  3195. + return EINVAL;
  3196. + }
  3197. + }
  3198. + }
  3199. + i++;
  3200. + }
  3201. +
  3202. + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
  3203. + __FUNCTION__, name, value);
  3204. + return EINVAL;
  3205. +}
  3206. +
  3207. +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
  3208. +{
  3209. + pkg_dest_list_elt_t *iter;
  3210. + pkg_dest_t *dest;
  3211. + pkg_vec_t *all;
  3212. + pkg_t *pkg;
  3213. + register int i;
  3214. + int err;
  3215. +
  3216. + if (conf->noaction)
  3217. + return 0;
  3218. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3219. + dest = iter->data;
  3220. + dest->status_file = fopen(dest->status_file_tmp_name, "w");
  3221. + if (dest->status_file == NULL) {
  3222. + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
  3223. + __FUNCTION__, dest->status_file_name, strerror(errno));
  3224. + }
  3225. + }
  3226. +
  3227. + all = pkg_vec_alloc();
  3228. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  3229. +
  3230. + for(i = 0; i < all->len; i++) {
  3231. + pkg = all->pkgs[i];
  3232. + /* We don't need most uninstalled packages in the status file */
  3233. + if (pkg->state_status == SS_NOT_INSTALLED
  3234. + && (pkg->state_want == SW_UNKNOWN
  3235. + || pkg->state_want == SW_DEINSTALL
  3236. + || pkg->state_want == SW_PURGE)) {
  3237. + continue;
  3238. + }
  3239. + if (!pkg) {
  3240. + fprintf(stderr, "Null package\n");
  3241. + }
  3242. + if (pkg->dest == NULL) {
  3243. + fprintf(stderr, "%s: ERROR: Can't write status for "
  3244. + "package %s since it has a NULL dest\n",
  3245. + __FUNCTION__, pkg->name);
  3246. + continue;
  3247. + }
  3248. + if (pkg->dest->status_file) {
  3249. + pkg_print_status(pkg, pkg->dest->status_file);
  3250. + }
  3251. + }
  3252. +
  3253. + pkg_vec_free(all);
  3254. +
  3255. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3256. + dest = iter->data;
  3257. + if (dest->status_file) {
  3258. + err = ferror(dest->status_file);
  3259. + fclose(dest->status_file);
  3260. + dest->status_file = NULL;
  3261. + if (!err) {
  3262. + file_move(dest->status_file_tmp_name, dest->status_file_name);
  3263. + } else {
  3264. + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
  3265. + "retaining old %s\n", __FUNCTION__,
  3266. + dest->status_file_tmp_name, dest->status_file_name);
  3267. + }
  3268. + }
  3269. + }
  3270. +
  3271. + return 0;
  3272. +}
  3273. +
  3274. +
  3275. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
  3276. +{
  3277. + char *root_filename;
  3278. + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
  3279. + return root_filename;
  3280. +}
  3281. diff -Nur busybox-1.18.1.orig/archival/libipkg/ipkg_conf.h busybox-1.18.1/archival/libipkg/ipkg_conf.h
  3282. --- busybox-1.18.1.orig/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
  3283. +++ busybox-1.18.1/archival/libipkg/ipkg_conf.h 2010-12-25 22:38:07.000000000 +0100
  3284. @@ -0,0 +1,107 @@
  3285. +/* ipkg_conf.h - the itsy package management system
  3286. +
  3287. + Carl D. Worth
  3288. +
  3289. + Copyright (C) 2001 University of Southern California
  3290. +
  3291. + This program is free software; you can redistribute it and/or
  3292. + modify it under the terms of the GNU General Public License as
  3293. + published by the Free Software Foundation; either version 2, or (at
  3294. + your option) any later version.
  3295. +
  3296. + This program is distributed in the hope that it will be useful, but
  3297. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3298. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3299. + General Public License for more details.
  3300. +*/
  3301. +
  3302. +#ifndef IPKG_CONF_H
  3303. +#define IPKG_CONF_H
  3304. +
  3305. +typedef struct ipkg_conf ipkg_conf_t;
  3306. +
  3307. +#include "hash_table.h"
  3308. +#include "ipkg.h"
  3309. +#include "args.h"
  3310. +#include "pkg.h"
  3311. +#include "pkg_hash.h"
  3312. +#include "pkg_src_list.h"
  3313. +#include "pkg_dest_list.h"
  3314. +#include "nv_pair_list.h"
  3315. +
  3316. +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
  3317. +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
  3318. +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
  3319. +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
  3320. +
  3321. +/* In case the config file defines no dest */
  3322. +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
  3323. +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
  3324. +
  3325. +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
  3326. +
  3327. +struct ipkg_conf
  3328. +{
  3329. + pkg_src_list_t pkg_src_list;
  3330. + pkg_dest_list_t pkg_dest_list;
  3331. + nv_pair_list_t arch_list;
  3332. +
  3333. + int restrict_to_default_dest;
  3334. + pkg_dest_t *default_dest;
  3335. +
  3336. + char *tmp_dir;
  3337. + char *lists_dir;
  3338. + char *pending_dir;
  3339. +
  3340. + /* options */
  3341. + int force_depends;
  3342. + int force_defaults;
  3343. + int force_overwrite;
  3344. + int force_downgrade;
  3345. + int force_reinstall;
  3346. + int force_space;
  3347. + int force_removal_of_dependent_packages;
  3348. + int force_removal_of_essential_packages;
  3349. + int nodeps; /* do not follow dependences */
  3350. + int verbose_wget;
  3351. + int multiple_providers;
  3352. + char *offline_root;
  3353. + char *offline_root_pre_script_cmd;
  3354. + char *offline_root_post_script_cmd;
  3355. + int query_all;
  3356. + int verbosity;
  3357. + int noaction;
  3358. +
  3359. + /* proxy options */
  3360. + char *http_proxy;
  3361. + char *ftp_proxy;
  3362. + char *no_proxy;
  3363. + char *proxy_user;
  3364. + char *proxy_passwd;
  3365. +
  3366. + hash_table_t pkg_hash;
  3367. + hash_table_t file_hash;
  3368. + hash_table_t obs_file_hash;
  3369. +};
  3370. +
  3371. +enum ipkg_option_type {
  3372. + IPKG_OPT_TYPE_BOOL,
  3373. + IPKG_OPT_TYPE_INT,
  3374. + IPKG_OPT_TYPE_STRING
  3375. +};
  3376. +typedef enum ipkg_option_type ipkg_option_type_t;
  3377. +
  3378. +typedef struct ipkg_option ipkg_option_t;
  3379. +struct ipkg_option {
  3380. + const char *name;
  3381. + const ipkg_option_type_t type;
  3382. + const void *value;
  3383. +};
  3384. +
  3385. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
  3386. +void ipkg_conf_deinit(ipkg_conf_t *conf);
  3387. +
  3388. +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
  3389. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
  3390. +
  3391. +#endif
  3392. diff -Nur busybox-1.18.1.orig/archival/libipkg/ipkg_configure.c busybox-1.18.1/archival/libipkg/ipkg_configure.c
  3393. --- busybox-1.18.1.orig/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
  3394. +++ busybox-1.18.1/archival/libipkg/ipkg_configure.c 2010-12-25 22:38:07.000000000 +0100
  3395. @@ -0,0 +1,40 @@
  3396. +/* ipkg_configure.c - the itsy package management system
  3397. +
  3398. + Carl D. Worth
  3399. +
  3400. + Copyright (C) 2001 University of Southern California
  3401. +
  3402. + This program is free software; you can redistribute it and/or
  3403. + modify it under the terms of the GNU General Public License as
  3404. + published by the Free Software Foundation; either version 2, or (at
  3405. + your option) any later version.
  3406. +
  3407. + This program is distributed in the hope that it will be useful, but
  3408. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3409. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3410. + General Public License for more details.
  3411. +*/
  3412. +
  3413. +#include "ipkg.h"
  3414. +
  3415. +#include "ipkg_configure.h"
  3416. +
  3417. +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
  3418. +{
  3419. + int err;
  3420. +
  3421. + /* DPKG_INCOMPATIBILITY:
  3422. + dpkg actually does some conffile handling here, rather than at the
  3423. + end of ipkg_install(). Do we care? */
  3424. + /* DPKG_INCOMPATIBILITY:
  3425. + dpkg actually includes a version number to this script call */
  3426. + err = pkg_run_script(conf, pkg, "postinst", "configure");
  3427. + if (err) {
  3428. + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
  3429. + return err;
  3430. + }
  3431. +
  3432. + ipkg_state_changed++;
  3433. + return 0;
  3434. +}
  3435. +
  3436. diff -Nur busybox-1.18.1.orig/archival/libipkg/ipkg_configure.h busybox-1.18.1/archival/libipkg/ipkg_configure.h
  3437. --- busybox-1.18.1.orig/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
  3438. +++ busybox-1.18.1/archival/libipkg/ipkg_configure.h 2010-12-25 22:38:07.000000000 +0100
  3439. @@ -0,0 +1,25 @@
  3440. +/* ipkg_configure.h - the itsy package management system
  3441. +
  3442. + Carl D. Worth
  3443. +
  3444. + Copyright (C) 2001 University of Southern California
  3445. +
  3446. + This program is free software; you can redistribute it and/or
  3447. + modify it under the terms of the GNU General Public License as
  3448. + published by the Free Software Foundation; either version 2, or (at
  3449. + your option) any later version.
  3450. +
  3451. + This program is distributed in the hope that it will be useful, but
  3452. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3453. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3454. + General Public License for more details.
  3455. +*/
  3456. +
  3457. +#ifndef IPKG_CONFIGURE_H
  3458. +#define IPKG_CONFIGURE_H
  3459. +
  3460. +#include "ipkg_conf.h"
  3461. +
  3462. +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
  3463. +
  3464. +#endif
  3465. diff -Nur busybox-1.18.1.orig/archival/libipkg/ipkg_download.c busybox-1.18.1/archival/libipkg/ipkg_download.c
  3466. --- busybox-1.18.1.orig/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
  3467. +++ busybox-1.18.1/archival/libipkg/ipkg_download.c 2010-12-25 22:38:07.000000000 +0100
  3468. @@ -0,0 +1,195 @@
  3469. +/* ipkg_download.c - the itsy package management system
  3470. +
  3471. + Carl D. Worth
  3472. +
  3473. + Copyright (C) 2001 University of Southern California
  3474. +
  3475. + This program is free software; you can redistribute it and/or
  3476. + modify it under the terms of the GNU General Public License as
  3477. + published by the Free Software Foundation; either version 2, or (at
  3478. + your option) any later version.
  3479. +
  3480. + This program is distributed in the hope that it will be useful, but
  3481. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3482. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3483. + General Public License for more details.
  3484. +*/
  3485. +
  3486. +#include "ipkg.h"
  3487. +#include "ipkg_download.h"
  3488. +#include "ipkg_message.h"
  3489. +
  3490. +#include "sprintf_alloc.h"
  3491. +#include "xsystem.h"
  3492. +#include "file_util.h"
  3493. +#include "str_util.h"
  3494. +
  3495. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
  3496. +{
  3497. + int err = 0;
  3498. +
  3499. + char *src_basec = strdup(src);
  3500. + char *src_base = basename(src_basec);
  3501. + char *tmp_file_location;
  3502. + char *cmd;
  3503. +
  3504. + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
  3505. +
  3506. + fflush(stdout);
  3507. +
  3508. + if (str_starts_with(src, "file:")) {
  3509. + int ret;
  3510. + const char *file_src = src + 5;
  3511. + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
  3512. + ret = file_copy(src + 5, dest_file_name);
  3513. + ipkg_message(conf,IPKG_INFO,"Done.\n");
  3514. + return ret;
  3515. + }
  3516. +
  3517. + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
  3518. + err = unlink(tmp_file_location);
  3519. + if (err && errno != ENOENT) {
  3520. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
  3521. + __FUNCTION__, tmp_file_location, strerror(errno));
  3522. + free(tmp_file_location);
  3523. + return errno;
  3524. + }
  3525. +
  3526. + if (conf->http_proxy) {
  3527. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
  3528. + setenv("http_proxy", conf->http_proxy, 1);
  3529. + }
  3530. + if (conf->ftp_proxy) {
  3531. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
  3532. + setenv("ftp_proxy", conf->ftp_proxy, 1);
  3533. + }
  3534. + if (conf->no_proxy) {
  3535. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
  3536. + setenv("no_proxy", conf->no_proxy, 1);
  3537. + }
  3538. +
  3539. + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
  3540. + sprintf_alloc(&cmd, "wget %s %s%s %s%s %s -P %s %s",
  3541. + (conf->http_proxy || conf->ftp_proxy) ? "-Y on" : "",
  3542. + conf->proxy_user ? "--proxy-user=" : "",
  3543. + conf->proxy_user ? conf->proxy_user : "",
  3544. + conf->proxy_passwd ? "--proxy-passwd=" : "",
  3545. + conf->proxy_passwd ? conf->proxy_passwd : "",
  3546. + conf->verbose_wget ? "" : "-q",
  3547. + conf->tmp_dir,
  3548. + src);
  3549. + err = xsystem(cmd);
  3550. + if (err) {
  3551. + if (err != -1) {
  3552. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
  3553. + __FUNCTION__, err, cmd);
  3554. + }
  3555. + unlink(tmp_file_location);
  3556. + free(tmp_file_location);
  3557. + free(src_basec);
  3558. + free(cmd);
  3559. + return EINVAL;
  3560. + }
  3561. + free(cmd);
  3562. +
  3563. + err = file_move(tmp_file_location, dest_file_name);
  3564. +
  3565. + free(tmp_file_location);
  3566. + free(src_basec);
  3567. +
  3568. + if (err) {
  3569. + return err;
  3570. + }
  3571. +
  3572. + return 0;
  3573. +}
  3574. +
  3575. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
  3576. +{
  3577. + int err;
  3578. + char *url;
  3579. +
  3580. + if (pkg->src == NULL) {
  3581. + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
  3582. + pkg->name, pkg->parent->name);
  3583. + return -1;
  3584. + }
  3585. +
  3586. + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
  3587. +
  3588. + /* XXX: BUG: The pkg->filename might be something like
  3589. + "../../foo.ipk". While this is correct, and exactly what we
  3590. + want to use to construct url above, here we actually need to
  3591. + use just the filename part, without any directory. */
  3592. + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
  3593. +
  3594. + err = ipkg_download(conf, url, pkg->local_filename);
  3595. + free(url);
  3596. +
  3597. + return err;
  3598. +}
  3599. +
  3600. +/*
  3601. + * Downloads file from url, installs in package database, return package name.
  3602. + */
  3603. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
  3604. +{
  3605. + int err = 0;
  3606. + pkg_t *pkg;
  3607. + pkg = pkg_new();
  3608. + if (pkg == NULL)
  3609. + return ENOMEM;
  3610. +
  3611. + if (str_starts_with(url, "http://")
  3612. + || str_starts_with(url, "ftp://")) {
  3613. + char *tmp_file;
  3614. + char *file_basec = strdup(url);
  3615. + char *file_base = basename(file_basec);
  3616. +
  3617. + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
  3618. + err = ipkg_download(conf, url, tmp_file);
  3619. + if (err)
  3620. + return err;
  3621. +
  3622. + err = pkg_init_from_file(pkg, tmp_file);
  3623. + if (err)
  3624. + return err;
  3625. + pkg->local_filename = strdup(tmp_file);
  3626. +
  3627. + free(tmp_file);
  3628. + free(file_basec);
  3629. +
  3630. + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
  3631. + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
  3632. +
  3633. + err = pkg_init_from_file(pkg, url);
  3634. + if (err)
  3635. + return err;
  3636. + pkg->local_filename = strdup(url);
  3637. + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
  3638. + pkg->provided_by_hand = 1;
  3639. +
  3640. + } else {
  3641. + pkg_deinit(pkg);
  3642. + free(pkg);
  3643. + return 0;
  3644. + }
  3645. +
  3646. + if (!pkg->architecture) {
  3647. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3648. + return -EINVAL;
  3649. + }
  3650. +
  3651. + pkg->dest = conf->default_dest;
  3652. + pkg->state_want = SW_INSTALL;
  3653. + pkg->state_flag |= SF_PREFER;
  3654. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3655. + if ( pkg == NULL ){
  3656. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  3657. + return 0;
  3658. + }
  3659. + if (namep) {
  3660. + *namep = strdup(pkg->name);
  3661. + }
  3662. + return 0;
  3663. +}
  3664. diff -Nur busybox-1.18.1.orig/archival/libipkg/ipkg_download.h busybox-1.18.1/archival/libipkg/ipkg_download.h
  3665. --- busybox-1.18.1.orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
  3666. +++ busybox-1.18.1/archival/libipkg/ipkg_download.h 2010-12-25 22:38:07.000000000 +0100
  3667. @@ -0,0 +1,30 @@
  3668. +/* ipkg_download.h - the itsy package management system
  3669. +
  3670. + Carl D. Worth
  3671. +
  3672. + Copyright (C) 2001 University of Southern California
  3673. +
  3674. + This program is free software; you can redistribute it and/or
  3675. + modify it under the terms of the GNU General Public License as
  3676. + published by the Free Software Foundation; either version 2, or (at
  3677. + your option) any later version.
  3678. +
  3679. + This program is distributed in the hope that it will be useful, but
  3680. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3681. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3682. + General Public License for more details.
  3683. +*/
  3684. +
  3685. +#ifndef IPKG_DOWNLOAD_H
  3686. +#define IPKG_DOWNLOAD_H
  3687. +
  3688. +#include "ipkg_conf.h"
  3689. +
  3690. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
  3691. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
  3692. +/*
  3693. + * Downloads file from url, installs in package database, return package name.
  3694. + */
  3695. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
  3696. +
  3697. +#endif
  3698. diff -Nur busybox-1.18.1.orig/archival/libipkg/ipkg_includes.h busybox-1.18.1/archival/libipkg/ipkg_includes.h
  3699. --- busybox-1.18.1.orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
  3700. +++ busybox-1.18.1/archival/libipkg/ipkg_includes.h 2010-12-25 22:38:07.000000000 +0100
  3701. @@ -0,0 +1,82 @@
  3702. +#ifndef IPKG_INCLUDES_H
  3703. +#define IPKG_INCLUDES_H
  3704. +
  3705. +/* Define to 1 if you have the <memory.h> header file. */
  3706. +#define HAVE_MEMORY_H 1
  3707. +
  3708. +/* Define to 1 if you have the <regex.h> header file. */
  3709. +#define HAVE_REGEX_H 1
  3710. +
  3711. +/* Define to 1 if you have the <stdlib.h> header file. */
  3712. +#define HAVE_STDLIB_H 1
  3713. +
  3714. +/* Define to 1 if you have the <strings.h> header file. */
  3715. +#define HAVE_STRINGS_H 1
  3716. +
  3717. +/* Define to 1 if you have the <string.h> header file. */
  3718. +#define HAVE_STRING_H 1
  3719. +
  3720. +/* Define to 1 if you have the <sys/stat.h> header file. */
  3721. +#define HAVE_SYS_STAT_H 1
  3722. +
  3723. +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
  3724. +#define HAVE_SYS_WAIT_H 1
  3725. +
  3726. +/* Define to 1 if you have the <unistd.h> header file. */
  3727. +#define HAVE_UNISTD_H 1
  3728. +
  3729. +/* Define to 1 if you have the ANSI C header files. */
  3730. +#define STDC_HEADERS 1
  3731. +
  3732. +
  3733. +#include <stdio.h>
  3734. +
  3735. +#if STDC_HEADERS
  3736. +# include <stdlib.h>
  3737. +# include <stdarg.h>
  3738. +# include <stddef.h>
  3739. +# include <ctype.h>
  3740. +# include <errno.h>
  3741. +#else
  3742. +# if HAVE_STDLIB_H
  3743. +# include <stdlib.h>
  3744. +# endif
  3745. +#endif
  3746. +
  3747. +#if HAVE_REGEX_H
  3748. +# include <regex.h>
  3749. +#endif
  3750. +
  3751. +#if HAVE_STRING_H
  3752. +# if !STDC_HEADERS && HAVE_MEMORY_H
  3753. +# include <memory.h>
  3754. +# endif
  3755. +/* XXX: What's the right way to pick up GNU's strndup declaration? */
  3756. +# if __GNUC__
  3757. +# define __USE_GNU 1
  3758. +# endif
  3759. +# include <string.h>
  3760. +# undef __USE_GNU
  3761. +#endif
  3762. +
  3763. +#if HAVE_STRINGS_H
  3764. +# include <strings.h>
  3765. +#endif
  3766. +
  3767. +#if HAVE_SYS_STAT_H
  3768. +# include <sys/stat.h>
  3769. +#endif
  3770. +
  3771. +#if HAVE_SYS_WAIT_H
  3772. +# include <sys/wait.h>
  3773. +#endif
  3774. +
  3775. +#if HAVE_UNISTD_H
  3776. +# include <sys/types.h>
  3777. +# include <unistd.h>
  3778. +#endif
  3779. +
  3780. +#include <sys/mount.h>
  3781. +#include <mntent.h>
  3782. +
  3783. +#endif /* IPKG_INCLUDES_H */
  3784. diff -Nur busybox-1.18.1.orig/archival/libipkg/ipkg_install.c busybox-1.18.1/archival/libipkg/ipkg_install.c
  3785. --- busybox-1.18.1.orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
  3786. +++ busybox-1.18.1/archival/libipkg/ipkg_install.c 2010-12-25 22:38:07.000000000 +0100
  3787. @@ -0,0 +1,1982 @@
  3788. +/* ipkg_install.c - the itsy package management system
  3789. +
  3790. + Carl D. Worth
  3791. +
  3792. + Copyright (C) 2001 University of Southern California
  3793. +
  3794. + This program is free software; you can redistribute it and/or
  3795. + modify it under the terms of the GNU General Public License as
  3796. + published by the Free Software Foundation; either version 2, or (at
  3797. + your option) any later version.
  3798. +
  3799. + This program is distributed in the hope that it will be useful, but
  3800. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3801. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3802. + General Public License for more details.
  3803. +*/
  3804. +
  3805. +#include "ipkg.h"
  3806. +#include <errno.h>
  3807. +#include <dirent.h>
  3808. +#include <glob.h>
  3809. +#include <time.h>
  3810. +#include <signal.h>
  3811. +typedef void (*sighandler_t)(int);
  3812. +
  3813. +#include "pkg.h"
  3814. +#include "pkg_hash.h"
  3815. +#include "pkg_extract.h"
  3816. +
  3817. +#include "ipkg_install.h"
  3818. +#include "ipkg_configure.h"
  3819. +#include "ipkg_download.h"
  3820. +#include "ipkg_remove.h"
  3821. +
  3822. +#include "ipkg_utils.h"
  3823. +#include "ipkg_message.h"
  3824. +
  3825. +#include "sprintf_alloc.h"
  3826. +#include "file_util.h"
  3827. +#include "str_util.h"
  3828. +#include "xsystem.h"
  3829. +#include "user.h"
  3830. +
  3831. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  3832. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
  3833. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
  3834. +
  3835. +/*
  3836. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3837. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3838. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3839. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3840. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3841. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3842. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3843. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
  3844. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3845. +*/
  3846. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3847. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3848. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg);
  3849. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3850. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg);
  3851. +
  3852. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3853. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3854. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
  3855. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
  3856. +
  3857. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
  3858. +
  3859. +static int user_prefers_old_conffile(const char *file, const char *backup);
  3860. +
  3861. +static char *backup_filename_alloc(const char *file_name);
  3862. +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
  3863. +static int backup_exists_for(const char *file_name);
  3864. +static int backup_remove(const char *file_name);
  3865. +
  3866. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees);
  3867. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3868. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3869. +
  3870. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
  3871. +{
  3872. + int err, cmp;
  3873. + pkg_t *pkg, *old;
  3874. + char *old_version, *new_version;
  3875. +
  3876. + pkg = pkg_new();
  3877. + if (pkg == NULL) {
  3878. + return ENOMEM;
  3879. + }
  3880. +
  3881. + err = pkg_init_from_file(pkg, filename);
  3882. + if (err) {
  3883. + return err;
  3884. + }
  3885. +
  3886. + if (!pkg->architecture) {
  3887. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3888. + return -EINVAL;
  3889. + }
  3890. +
  3891. + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
  3892. + freeing the pkg that we pass in. It might be nice to clean this up
  3893. + if possible. */
  3894. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3895. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  3896. +
  3897. + pkg->local_filename = strdup(filename);
  3898. +
  3899. + if (old) {
  3900. + old_version = pkg_version_str_alloc(old);
  3901. + new_version = pkg_version_str_alloc(pkg);
  3902. +
  3903. + cmp = pkg_compare_versions(old, pkg);
  3904. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3905. + cmp = -1 ; /* then we force ipkg to downgrade */
  3906. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3907. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3908. + }
  3909. + if (cmp > 0) {
  3910. + ipkg_message(conf, IPKG_NOTICE,
  3911. + "Not downgrading package %s on %s from %s to %s.\n",
  3912. + old->name, old->dest->name, old_version, new_version);
  3913. + pkg->state_want = SW_DEINSTALL;
  3914. + pkg->state_flag |= SF_OBSOLETE;
  3915. + free(old_version);
  3916. + free(new_version);
  3917. + return 0;
  3918. + } else {
  3919. + free(old_version);
  3920. + free(new_version);
  3921. + }
  3922. + }
  3923. +
  3924. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3925. + return ipkg_install_pkg(conf, pkg,0);
  3926. +}
  3927. +
  3928. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3929. +{
  3930. + int cmp;
  3931. + pkg_t *old, *new;
  3932. + char *old_version, *new_version;
  3933. +
  3934. + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
  3935. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  3936. + if ( old )
  3937. + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
  3938. +
  3939. + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
  3940. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  3941. + if ( new )
  3942. + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
  3943. +
  3944. +/* Pigi Basically here is broken the version stuff.
  3945. + What's happening is that nothing provide the version to differents
  3946. + functions, so the returned struct is always the latest.
  3947. + That's why the install by name don't work.
  3948. +*/
  3949. + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
  3950. +
  3951. + if ( old )
  3952. + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
  3953. + if ( new )
  3954. + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
  3955. + ipkg_message(conf, IPKG_DEBUG2, " \n");
  3956. +
  3957. + if (new == NULL) {
  3958. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3959. + }
  3960. +
  3961. + new->state_flag |= SF_USER;
  3962. + if (old) {
  3963. + old_version = pkg_version_str_alloc(old);
  3964. + new_version = pkg_version_str_alloc(new);
  3965. +
  3966. + cmp = pkg_compare_versions(old, new);
  3967. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3968. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
  3969. + cmp = -1 ; /* then we force ipkg to downgrade */
  3970. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3971. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3972. + }
  3973. + ipkg_message(conf, IPKG_DEBUG,
  3974. + "Comparing visible versions of pkg %s:"
  3975. + "\n\t%s is installed "
  3976. + "\n\t%s is available "
  3977. + "\n\t%d was comparison result\n",
  3978. + pkg_name, old_version, new_version, cmp);
  3979. + if (cmp == 0 && !conf->force_reinstall) {
  3980. + ipkg_message(conf, IPKG_NOTICE,
  3981. + "Package %s (%s) installed in %s is up to date.\n",
  3982. + old->name, old_version, old->dest->name);
  3983. + free(old_version);
  3984. + free(new_version);
  3985. + return 0;
  3986. + } else if (cmp > 0) {
  3987. + ipkg_message(conf, IPKG_NOTICE,
  3988. + "Not downgrading package %s on %s from %s to %s.\n",
  3989. + old->name, old->dest->name, old_version, new_version);
  3990. + free(old_version);
  3991. + free(new_version);
  3992. + return 0;
  3993. + } else if (cmp < 0) {
  3994. + new->dest = old->dest;
  3995. + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
  3996. + }
  3997. + }
  3998. +
  3999. + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
  4000. + supposed to be an ipkg_error_t, but ipkg_install_pkg could
  4001. + return any kind of integer, (might be errno from a syscall,
  4002. + etc.). This is a real mess and will need to be cleaned up if
  4003. + anyone ever wants to make a nice libipkg. */
  4004. +
  4005. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4006. + return ipkg_install_pkg(conf, new,0);
  4007. +}
  4008. +
  4009. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
  4010. +{
  4011. + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
  4012. + int i;
  4013. + ipkg_error_t err;
  4014. + abstract_pkg_t *ppkg ;
  4015. +
  4016. + if (providers == NULL)
  4017. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4018. +
  4019. + for (i = 0; i < providers->len; i++) {
  4020. + ppkg = abstract_pkg_vec_get(providers, i);
  4021. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
  4022. + err = ipkg_install_by_name(conf, ppkg->name);
  4023. + if (err)
  4024. + return err;
  4025. +/* XXX Maybe ppkg should be freed ? */
  4026. + }
  4027. + return 0;
  4028. +}
  4029. +
  4030. +/*
  4031. + * Walk dependence graph starting with pkg, collect packages to be
  4032. + * installed into pkgs_needed, in dependence order.
  4033. + */
  4034. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
  4035. +{
  4036. + int i, err;
  4037. + pkg_vec_t *depends = pkg_vec_alloc();
  4038. + char **unresolved = NULL;
  4039. + int ndepends;
  4040. +
  4041. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4042. + pkg, depends,
  4043. + &unresolved);
  4044. +
  4045. + if (unresolved) {
  4046. + ipkg_message(conf, IPKG_ERROR,
  4047. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4048. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4049. + while (*unresolved) {
  4050. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4051. + unresolved++;
  4052. + }
  4053. + ipkg_message(conf, IPKG_ERROR, "\n");
  4054. + if (! conf->force_depends) {
  4055. + ipkg_message(conf, IPKG_INFO,
  4056. + "This could mean that your package list is out of date or that the packages\n"
  4057. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4058. + "of this problem try again with the '-force-depends' option.\n");
  4059. + pkg_vec_free(depends);
  4060. + return IPKG_PKG_DEPS_UNSATISFIED;
  4061. + }
  4062. + }
  4063. +
  4064. + if (ndepends <= 0) {
  4065. + pkg_vec_free(depends);
  4066. + return 0;
  4067. + }
  4068. +
  4069. + for (i = 0; i < depends->len; i++) {
  4070. + pkg_t *dep = depends->pkgs[i];
  4071. + /* The package was uninstalled when we started, but another
  4072. + dep earlier in this loop may have depended on it and pulled
  4073. + it in, so check first. */
  4074. + if ((dep->state_status != SS_INSTALLED)
  4075. + && (dep->state_status != SS_UNPACKED)
  4076. + && (dep->state_want != SW_INSTALL)) {
  4077. +
  4078. + /* Mark packages as to-be-installed */
  4079. + dep->state_want = SW_INSTALL;
  4080. +
  4081. + /* Dependencies should be installed the same place as pkg */
  4082. + if (dep->dest == NULL) {
  4083. + dep->dest = pkg->dest;
  4084. + }
  4085. +
  4086. + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
  4087. + if (err) {
  4088. + pkg_vec_free(depends);
  4089. + return err;
  4090. + }
  4091. + }
  4092. + }
  4093. + if (pkgs_needed)
  4094. + pkg_vec_insert(pkgs_needed, pkg);
  4095. +
  4096. + pkg_vec_free(depends);
  4097. +
  4098. + return 0;
  4099. +}
  4100. +
  4101. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
  4102. +{
  4103. + int cmp;
  4104. + pkg_t *old, *new;
  4105. + char *old_version, *new_version;
  4106. +
  4107. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  4108. +
  4109. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  4110. + if (new == NULL) {
  4111. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4112. + }
  4113. + if (old) {
  4114. + old_version = pkg_version_str_alloc(old);
  4115. + new_version = pkg_version_str_alloc(new);
  4116. +
  4117. + cmp = pkg_compare_versions(old, new);
  4118. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4119. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
  4120. + cmp = -1 ; /* then we force ipkg to downgrade */
  4121. + /* We need to use a value < 0 because in the 0 case we are asking to */
  4122. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4123. + }
  4124. + ipkg_message(conf, IPKG_DEBUG,
  4125. + "comparing visible versions of pkg %s:"
  4126. + "\n\t%s is installed "
  4127. + "\n\t%s is available "
  4128. + "\n\t%d was comparison result\n",
  4129. + pkg_name, old_version, new_version, cmp);
  4130. + if (cmp == 0 && !conf->force_reinstall) {
  4131. + ipkg_message(conf, IPKG_NOTICE,
  4132. + "Package %s (%s) installed in %s is up to date.\n",
  4133. + old->name, old_version, old->dest->name);
  4134. + free(old_version);
  4135. + free(new_version);
  4136. + return 0;
  4137. + } else if (cmp > 0) {
  4138. + ipkg_message(conf, IPKG_NOTICE,
  4139. + "Not downgrading package %s on %s from %s to %s.\n",
  4140. + old->name, old->dest->name, old_version, new_version);
  4141. + free(old_version);
  4142. + free(new_version);
  4143. + return 0;
  4144. + } else if (cmp < 0) {
  4145. + new->dest = old->dest;
  4146. + old->state_want = SW_DEINSTALL;
  4147. + old->state_flag |= SF_OBSOLETE;
  4148. + }
  4149. + }
  4150. + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
  4151. +}
  4152. +
  4153. +
  4154. +
  4155. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
  4156. +{
  4157. + int i, err;
  4158. + pkg_vec_t *depends = pkg_vec_alloc();
  4159. + pkg_t *dep;
  4160. + char **unresolved = NULL;
  4161. + int ndepends;
  4162. +
  4163. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4164. + pkg, depends,
  4165. + &unresolved);
  4166. +
  4167. + if (unresolved) {
  4168. + ipkg_message(conf, IPKG_ERROR,
  4169. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4170. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4171. + while (*unresolved) {
  4172. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4173. + unresolved++;
  4174. + }
  4175. + ipkg_message(conf, IPKG_ERROR, "\n");
  4176. + if (! conf->force_depends) {
  4177. + ipkg_message(conf, IPKG_INFO,
  4178. + "This could mean that your package list is out of date or that the packages\n"
  4179. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4180. + "of this problem try again with the '-force-depends' option.\n");
  4181. + pkg_vec_free(depends);
  4182. + return IPKG_PKG_DEPS_UNSATISFIED;
  4183. + }
  4184. + }
  4185. +
  4186. + if (ndepends <= 0) {
  4187. + return 0;
  4188. + }
  4189. +
  4190. + /* Mark packages as to-be-installed */
  4191. + for (i=0; i < depends->len; i++) {
  4192. + /* Dependencies should be installed the same place as pkg */
  4193. + if (depends->pkgs[i]->dest == NULL) {
  4194. + depends->pkgs[i]->dest = pkg->dest;
  4195. + }
  4196. + depends->pkgs[i]->state_want = SW_INSTALL;
  4197. + }
  4198. +
  4199. + for (i = 0; i < depends->len; i++) {
  4200. + dep = depends->pkgs[i];
  4201. + /* The package was uninstalled when we started, but another
  4202. + dep earlier in this loop may have depended on it and pulled
  4203. + it in, so check first. */
  4204. + if ((dep->state_status != SS_INSTALLED)
  4205. + && (dep->state_status != SS_UNPACKED)) {
  4206. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4207. + err = ipkg_install_pkg(conf, dep,0);
  4208. + if (err) {
  4209. + pkg_vec_free(depends);
  4210. + return err;
  4211. + }
  4212. + }
  4213. + }
  4214. +
  4215. + pkg_vec_free(depends);
  4216. +
  4217. + return 0;
  4218. +}
  4219. +
  4220. +
  4221. +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
  4222. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
  4223. +{
  4224. + if (conf->nodeps == 0) {
  4225. + int i;
  4226. + pkg_vec_t *installed = pkg_vec_alloc();
  4227. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  4228. + for (i = 0; i < installed->len; i++) {
  4229. + pkg_t *pkg = installed->pkgs[i];
  4230. + satisfy_dependencies_for(conf, pkg);
  4231. + }
  4232. + pkg_vec_free(installed);
  4233. + }
  4234. + return 0;
  4235. +}
  4236. +
  4237. +
  4238. +
  4239. +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
  4240. +{
  4241. + int i;
  4242. + pkg_vec_t *conflicts = NULL;
  4243. + int level;
  4244. + const char *prefix;
  4245. + if (conf->force_depends) {
  4246. + level = IPKG_NOTICE;
  4247. + prefix = "Warning";
  4248. + } else {
  4249. + level = IPKG_ERROR;
  4250. + prefix = "ERROR";
  4251. + }
  4252. +
  4253. + if (!conf->force_depends)
  4254. + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(pkg);
  4255. +
  4256. + if (conflicts) {
  4257. + ipkg_message(conf, level,
  4258. + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
  4259. + i = 0;
  4260. + while (i < conflicts->len)
  4261. + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
  4262. + ipkg_message(conf, level, "\n");
  4263. + pkg_vec_free(conflicts);
  4264. + return IPKG_PKG_DEPS_UNSATISFIED;
  4265. + }
  4266. + return 0;
  4267. +}
  4268. +
  4269. +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
  4270. +{
  4271. + str_list_t *new_list = pkg_get_installed_files(new_pkg);
  4272. + str_list_elt_t *iter;
  4273. +
  4274. + for (iter = new_list->head; iter; iter = iter->next) {
  4275. + char *new_file = iter->data;
  4276. + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
  4277. + if (!new_file)
  4278. + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
  4279. + if (!owner || (owner == old_pkg))
  4280. + file_hash_set_file_owner(conf, new_file, new_pkg);
  4281. + }
  4282. + if (old_pkg) {
  4283. + str_list_t *old_list = pkg_get_installed_files(old_pkg);
  4284. + for (iter = old_list->head; iter; iter = iter->next) {
  4285. + char *old_file = iter->data;
  4286. + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
  4287. + if (owner == old_pkg) {
  4288. + /* obsolete */
  4289. + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
  4290. + }
  4291. + }
  4292. + }
  4293. + return 0;
  4294. +}
  4295. +
  4296. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
  4297. +{
  4298. + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
  4299. +
  4300. + /* sma 6.20.02: yup; here's the first bit */
  4301. + /*
  4302. + * XXX: BUG easy for cworth
  4303. + * 1) please point the call below to the correct current root destination
  4304. + * 2) we need to resolve how to check the required space for a pending pkg,
  4305. + * my diddling with the .ipk file size below isn't going to cut it.
  4306. + * 3) return a proper error code instead of 1
  4307. + */
  4308. + int comp_size, blocks_available;
  4309. +
  4310. + if (!conf->force_space && pkg->installed_size != NULL) {
  4311. + blocks_available = get_available_blocks(conf->default_dest->root_dir);
  4312. +
  4313. + comp_size = strtoul(pkg->installed_size, NULL, 0);
  4314. + /* round up a blocks count without doing fancy-but-slow casting jazz */
  4315. + comp_size = (int)((comp_size + 1023) / 1024);
  4316. +
  4317. + if (comp_size >= blocks_available) {
  4318. + ipkg_message(conf, IPKG_ERROR,
  4319. + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
  4320. + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
  4321. + return ENOSPC;
  4322. + }
  4323. + }
  4324. + return 0;
  4325. +}
  4326. +
  4327. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
  4328. +{
  4329. + int err;
  4330. + char *conffiles_file_name;
  4331. + char *root_dir;
  4332. + FILE *conffiles_file;
  4333. +
  4334. + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
  4335. +
  4336. + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
  4337. + if (pkg->tmp_unpack_dir == NULL) {
  4338. + ipkg_message(conf, IPKG_ERROR,
  4339. + "%s: Failed to create temporary directory '%s': %s\n",
  4340. + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
  4341. + return errno;
  4342. + }
  4343. +
  4344. + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
  4345. + if (err) {
  4346. + return err;
  4347. + }
  4348. +
  4349. + /* XXX: CLEANUP: There might be a cleaner place to read in the
  4350. + conffiles. Seems like I should be able to get everything to go
  4351. + through pkg_init_from_file. If so, maybe it would make sense to
  4352. + move all of unpack_pkg_control_files to that function. */
  4353. +
  4354. + /* Don't need to re-read conffiles if we already have it */
  4355. + if (pkg->conffiles.head) {
  4356. + return 0;
  4357. + }
  4358. +
  4359. + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
  4360. + if (! file_exists(conffiles_file_name)) {
  4361. + free(conffiles_file_name);
  4362. + return 0;
  4363. + }
  4364. +
  4365. + conffiles_file = fopen(conffiles_file_name, "r");
  4366. + if (conffiles_file == NULL) {
  4367. + fprintf(stderr, "%s: failed to open %s: %s\n",
  4368. + __FUNCTION__, conffiles_file_name, strerror(errno));
  4369. + free(conffiles_file_name);
  4370. + return errno;
  4371. + }
  4372. + free(conffiles_file_name);
  4373. +
  4374. + while (1) {
  4375. + char *cf_name;
  4376. + char *cf_name_in_dest;
  4377. +
  4378. + cf_name = file_read_line_alloc(conffiles_file);
  4379. + if (cf_name == NULL) {
  4380. + break;
  4381. + }
  4382. + str_chomp(cf_name);
  4383. + if (cf_name[0] == '\0') {
  4384. + continue;
  4385. + }
  4386. +
  4387. + /* Prepend dest->root_dir to conffile name.
  4388. + Take pains to avoid multiple slashes. */
  4389. + root_dir = pkg->dest->root_dir;
  4390. + if (conf->offline_root)
  4391. + /* skip the offline_root prefix */
  4392. + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
  4393. + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
  4394. + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
  4395. +
  4396. + /* Can't get an md5sum now, (file isn't extracted yet).
  4397. + We'll wait until resolve_conffiles */
  4398. + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
  4399. +
  4400. + free(cf_name);
  4401. + free(cf_name_in_dest);
  4402. + }
  4403. +
  4404. + fclose(conffiles_file);
  4405. +
  4406. + return 0;
  4407. +}
  4408. +
  4409. +/* returns number of installed replacees */
  4410. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees)
  4411. +{
  4412. + abstract_pkg_t **replaces = pkg->replaces;
  4413. + int replaces_count = pkg->replaces_count;
  4414. + int i, j;
  4415. + for (i = 0; i < replaces_count; i++) {
  4416. + abstract_pkg_t *ab_pkg = replaces[i];
  4417. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  4418. + if (pkg_vec) {
  4419. + for (j = 0; j < pkg_vec->len; j++) {
  4420. + pkg_t *replacee = pkg_vec->pkgs[j];
  4421. + if (!pkg_conflicts(pkg, replacee))
  4422. + continue;
  4423. + if (replacee->state_status == SS_INSTALLED) {
  4424. + pkg_vec_insert(installed_replacees, replacee);
  4425. + }
  4426. + }
  4427. + }
  4428. + }
  4429. + return installed_replacees->len;
  4430. +}
  4431. +
  4432. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4433. +{
  4434. + int i;
  4435. + int replaces_count = replacees->len;
  4436. + for (i = 0; i < replaces_count; i++) {
  4437. + pkg_t *replacee = replacees->pkgs[i];
  4438. + int err;
  4439. + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
  4440. + err = ipkg_remove_pkg(conf, replacee,0);
  4441. + if (err)
  4442. + return err;
  4443. + }
  4444. + return 0;
  4445. +}
  4446. +
  4447. +/* to unwind the removal: make sure they are installed */
  4448. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4449. +{
  4450. + int i, err;
  4451. + int replaces_count = replacees->len;
  4452. + for (i = 0; i < replaces_count; i++) {
  4453. + pkg_t *replacee = replacees->pkgs[i];
  4454. + if (replacee->state_status != SS_INSTALLED) {
  4455. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4456. + err = ipkg_install_pkg(conf, replacee,0);
  4457. + if (err)
  4458. + return err;
  4459. + }
  4460. + }
  4461. + return 0;
  4462. +}
  4463. +
  4464. +int caught_sigint = 0;
  4465. +static void ipkg_install_pkg_sigint_handler(int sig)
  4466. +{
  4467. + caught_sigint = sig;
  4468. +}
  4469. +
  4470. +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
  4471. +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
  4472. +{
  4473. + if (old_pkg) {
  4474. + char message_out[15];
  4475. + char *old_version = pkg_version_str_alloc(old_pkg);
  4476. + char *new_version = pkg_version_str_alloc(pkg);
  4477. + int cmp = pkg_compare_versions(old_pkg, pkg);
  4478. + int rc = 0;
  4479. +
  4480. + memset(message_out,'\x0',15);
  4481. + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
  4482. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4483. + cmp = -1 ; /* then we force ipkg to downgrade */
  4484. + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
  4485. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4486. + }
  4487. +
  4488. + if (cmp > 0) {
  4489. + ipkg_message(conf, IPKG_NOTICE,
  4490. + "Not downgrading package %s on %s from %s to %s.\n",
  4491. + old_pkg->name, old_pkg->dest->name, old_version, new_version);
  4492. + rc = 1;
  4493. + } else if (cmp < 0) {
  4494. + ipkg_message(conf, IPKG_NOTICE,
  4495. + "%s%s on %s from %s to %s...\n",
  4496. + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
  4497. + pkg->dest = old_pkg->dest;
  4498. + rc = 0;
  4499. + } else /* cmp == 0 */ {
  4500. + if (conf->force_reinstall) {
  4501. + ipkg_message(conf, IPKG_NOTICE,
  4502. + "Reinstalling %s (%s) on %s...\n",
  4503. + pkg->name, new_version, old_pkg->dest->name);
  4504. + pkg->dest = old_pkg->dest;
  4505. + rc = 0;
  4506. + } else {
  4507. + ipkg_message(conf, IPKG_NOTICE,
  4508. + "Not installing %s (%s) on %s -- already installed.\n",
  4509. + pkg->name, new_version, old_pkg->dest->name);
  4510. + rc = 1;
  4511. + }
  4512. + }
  4513. + free(old_version);
  4514. + free(new_version);
  4515. + return rc;
  4516. + } else {
  4517. + char message_out[15], *version ;
  4518. + memset(message_out,'\x0',15);
  4519. + if ( message )
  4520. + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
  4521. + else
  4522. + strncpy( message_out,"Installing ",strlen("Installing ") );
  4523. + version = pkg_version_str_alloc(pkg);
  4524. +
  4525. + ipkg_message(conf, IPKG_NOTICE,
  4526. + "%s%s (%s) to %s...\n", message_out,
  4527. + pkg->name, version, pkg->dest->name);
  4528. + free(version);
  4529. + return 0;
  4530. + }
  4531. +}
  4532. +
  4533. +/* and now the meat... */
  4534. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
  4535. +{
  4536. + int err = 0;
  4537. + int message = 0;
  4538. + pkg_t *old_pkg = NULL;
  4539. + pkg_vec_t *replacees;
  4540. + abstract_pkg_t *ab_pkg = NULL;
  4541. + int old_state_flag;
  4542. + uint8_t *file_md5;
  4543. +
  4544. +
  4545. + if ( from_upgrade )
  4546. + message = 1; /* Coming from an upgrade, and should change the output message */
  4547. +
  4548. + if (!pkg) {
  4549. + ipkg_message(conf, IPKG_ERROR,
  4550. + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
  4551. + return -EINVAL;
  4552. + }
  4553. +
  4554. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
  4555. +
  4556. + if (!pkg_arch_supported(conf, pkg)) {
  4557. + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
  4558. + pkg->architecture, pkg->name);
  4559. + return -EINVAL;
  4560. + }
  4561. + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
  4562. + err = satisfy_dependencies_for(conf, pkg);
  4563. + if (err) { return err; }
  4564. +
  4565. + ipkg_message(conf, IPKG_NOTICE,
  4566. + "Package %s is already installed in %s.\n",
  4567. + pkg->name, pkg->dest->name);
  4568. + return 0;
  4569. + }
  4570. +
  4571. + if (pkg->dest == NULL) {
  4572. + pkg->dest = conf->default_dest;
  4573. + }
  4574. +
  4575. + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  4576. +
  4577. + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
  4578. + if (err) { return err; }
  4579. +
  4580. + pkg->state_want = SW_INSTALL;
  4581. + if (old_pkg){
  4582. + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
  4583. + }
  4584. +
  4585. +
  4586. + /* Abhaya: conflicts check */
  4587. + err = check_conflicts_for(conf, pkg);
  4588. + if (err) { return err; }
  4589. +
  4590. + /* this setup is to remove the upgrade scenario in the end when
  4591. + installing pkg A, A deps B & B deps on A. So both B and A are
  4592. + installed. Then A's installation is started resulting in an
  4593. + uncecessary upgrade */
  4594. + if (pkg->state_status == SS_INSTALLED
  4595. + && conf->force_reinstall == 0) return 0;
  4596. +
  4597. + err = verify_pkg_installable(conf, pkg);
  4598. + if (err) { return err; }
  4599. +
  4600. + if (pkg->local_filename == NULL) {
  4601. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  4602. + if (err) {
  4603. + ipkg_message(conf, IPKG_ERROR,
  4604. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  4605. + pkg->name);
  4606. + return err;
  4607. + }
  4608. + }
  4609. +
  4610. +/* Check for md5 values */
  4611. + if (pkg->md5sum)
  4612. + {
  4613. + file_md5 = file_md5sum_alloc(pkg->local_filename);
  4614. + if (strcmp((char *)file_md5, pkg->md5sum))
  4615. + {
  4616. + ipkg_message(conf, IPKG_ERROR,
  4617. + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
  4618. + pkg->name);
  4619. + free(file_md5);
  4620. + return err;
  4621. + }
  4622. + free(file_md5);
  4623. + }
  4624. +
  4625. + if (pkg->tmp_unpack_dir == NULL) {
  4626. + unpack_pkg_control_files(conf, pkg);
  4627. + }
  4628. +
  4629. + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
  4630. +/* Pigi: check if it will pass from here when replacing. It seems to fail */
  4631. +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
  4632. + err = update_file_ownership(conf, pkg, old_pkg);
  4633. + if (err) { return err; }
  4634. +
  4635. + if (conf->nodeps == 0) {
  4636. + err = satisfy_dependencies_for(conf, pkg);
  4637. + if (err) { return err; }
  4638. + }
  4639. +
  4640. + replacees = pkg_vec_alloc();
  4641. + pkg_get_installed_replacees(pkg, replacees);
  4642. +
  4643. + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
  4644. + {
  4645. + sigset_t newset, oldset;
  4646. + sighandler_t old_handler = NULL;
  4647. + int use_signal = 0;
  4648. + caught_sigint = 0;
  4649. + if (use_signal) {
  4650. + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
  4651. + } else {
  4652. + sigemptyset(&newset);
  4653. + sigaddset(&newset, SIGINT);
  4654. + sigprocmask(SIG_BLOCK, &newset, &oldset);
  4655. + }
  4656. +
  4657. + ipkg_state_changed++;
  4658. + pkg->state_flag |= SF_FILELIST_CHANGED;
  4659. +
  4660. + /* XXX: BUG: we really should treat replacement more like an upgrade
  4661. + * Instead, we're going to remove the replacees
  4662. + */
  4663. + err = pkg_remove_installed_replacees(conf, replacees);
  4664. + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
  4665. +
  4666. + /*
  4667. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  4668. + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
  4669. +
  4670. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  4671. + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
  4672. + */
  4673. +
  4674. + err = preinst_configure(conf, pkg, old_pkg);
  4675. + /*
  4676. + if (err) goto UNWIND_PREINST_CONFIGURE;
  4677. + */
  4678. +
  4679. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  4680. + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
  4681. +
  4682. + err = check_data_file_clashes(conf, pkg, old_pkg);
  4683. + /*
  4684. + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
  4685. +
  4686. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  4687. + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
  4688. + */
  4689. +
  4690. + if (conf->noaction) return 0;
  4691. +
  4692. + /* point of no return: no unwinding after this */
  4693. + if (old_pkg && !conf->force_reinstall) {
  4694. + old_pkg->state_want = SW_DEINSTALL;
  4695. +
  4696. + if (old_pkg->state_flag & SF_NOPRUNE) {
  4697. + ipkg_message(conf, IPKG_INFO,
  4698. + " not removing obsolesced files because package marked noprune\n");
  4699. + } else {
  4700. + ipkg_message(conf, IPKG_INFO,
  4701. + " removing obsolesced files\n");
  4702. + remove_obsolesced_files(conf, pkg, old_pkg);
  4703. + }
  4704. + /* removing files from old package, to avoid ghost files */
  4705. + remove_data_files_and_list(conf, old_pkg);
  4706. +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
  4707. + remove_maintainer_scripts_except_postrm(conf, old_pkg);
  4708. + remove_postrm(conf, old_pkg);
  4709. +/* Pigi */
  4710. +
  4711. + }
  4712. +
  4713. +
  4714. + ipkg_message(conf, IPKG_INFO,
  4715. + " installing maintainer scripts\n");
  4716. + install_maintainer_scripts(conf, pkg, old_pkg);
  4717. +
  4718. + /* the following just returns 0
  4719. + remove_disappeared(conf, pkg);
  4720. + */
  4721. +
  4722. + ipkg_message(conf, IPKG_INFO,
  4723. + " installing data files\n");
  4724. + install_data_files(conf, pkg);
  4725. +
  4726. +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
  4727. + err = check_data_file_clashes_change(conf, pkg);
  4728. +
  4729. + ipkg_message(conf, IPKG_INFO,
  4730. + " resolving conf files\n");
  4731. + resolve_conffiles(conf, pkg);
  4732. +
  4733. + pkg->state_status = SS_UNPACKED;
  4734. + old_state_flag = pkg->state_flag;
  4735. + pkg->state_flag &= ~SF_PREFER;
  4736. + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
  4737. +
  4738. + if (old_pkg && !conf->force_reinstall) {
  4739. + old_pkg->state_status = SS_NOT_INSTALLED;
  4740. + }
  4741. +
  4742. + time(&pkg->installed_time);
  4743. +
  4744. + ipkg_message(conf, IPKG_INFO,
  4745. + " cleanup temp files\n");
  4746. + cleanup_temporary_files(conf, pkg);
  4747. +
  4748. + ab_pkg = pkg->parent;
  4749. + if (ab_pkg)
  4750. + ab_pkg->state_status = pkg->state_status;
  4751. +
  4752. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  4753. +
  4754. + if (use_signal)
  4755. + signal(SIGINT, old_handler);
  4756. + else
  4757. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4758. +
  4759. + return 0;
  4760. +
  4761. +
  4762. + /*
  4763. + UNWIND_POSTRM_UPGRADE_OLD_PKG:
  4764. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4765. + UNWIND_CHECK_DATA_FILE_CLASHES:
  4766. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  4767. + */
  4768. + UNWIND_BACKUP_MODIFIED_CONFFILES:
  4769. + backup_modified_conffiles_unwind(pkg, old_pkg);
  4770. + /*
  4771. + UNWIND_PREINST_CONFIGURE:
  4772. + preinst_configure_unwind(conf, pkg, old_pkg);
  4773. + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
  4774. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  4775. + UNWIND_PRERM_UPGRADE_OLD_PKG:
  4776. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4777. + */
  4778. + UNWIND_REMOVE_INSTALLED_REPLACEES:
  4779. + pkg_remove_installed_replacees_unwind(conf, replacees);
  4780. +
  4781. + ipkg_message(conf, IPKG_INFO,
  4782. + " cleanup temp files\n");
  4783. + cleanup_temporary_files(conf, pkg);
  4784. +
  4785. + ipkg_message(conf, IPKG_INFO,
  4786. + "Failed.\n");
  4787. + if (use_signal)
  4788. + signal(SIGINT, old_handler);
  4789. + else
  4790. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4791. +
  4792. + return err;
  4793. + }
  4794. +}
  4795. +
  4796. +/*
  4797. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4798. +{
  4799. + DPKG_INCOMPATIBILITY:
  4800. + dpkg does some things here that we don't do yet. Do we care?
  4801. +
  4802. + 1. If a version of the package is already installed, call
  4803. + old-prerm upgrade new-version
  4804. + 2. If the script runs but exits with a non-zero exit status
  4805. + new-prerm failed-upgrade old-version
  4806. + Error unwind, for both the above cases:
  4807. + old-postinst abort-upgrade new-version
  4808. + return 0;
  4809. +}
  4810. +*/
  4811. +
  4812. +/*
  4813. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4814. +{
  4815. + DPKG_INCOMPATIBILITY:
  4816. + dpkg does some things here that we don't do yet. Do we care?
  4817. + (See prerm_upgrade_old_package for details)
  4818. +
  4819. + return 0;
  4820. +}
  4821. +*/
  4822. +
  4823. +/*
  4824. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4825. +{
  4826. + DPKG_INCOMPATIBILITY:
  4827. + dpkg does some things here that we don't do yet. Do we care?
  4828. + 2. If a 'conflicting' package is being removed at the same time:
  4829. + 1. If any packages depended on that conflicting package and
  4830. + --auto-deconfigure is specified, call, for each such package:
  4831. + deconfigured's-prerm deconfigure \
  4832. + in-favour package-being-installed version \
  4833. + removing conflicting-package version
  4834. + Error unwind:
  4835. + deconfigured's-postinst abort-deconfigure \
  4836. + in-favour package-being-installed-but-failed version \
  4837. + removing conflicting-package version
  4838. +
  4839. + The deconfigured packages are marked as requiring
  4840. + configuration, so that if --install is used they will be
  4841. + configured again if possible.
  4842. + 2. To prepare for removal of the conflicting package, call:
  4843. + conflictor's-prerm remove in-favour package new-version
  4844. + Error unwind:
  4845. + conflictor's-postinst abort-remove in-favour package new-version
  4846. + return 0;
  4847. +}
  4848. +*/
  4849. +
  4850. +/*
  4851. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4852. +{
  4853. + DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
  4854. + do yet. Do we care? (See prerm_deconfigure_conflictors for
  4855. + details)
  4856. + return 0;
  4857. +}
  4858. +*/
  4859. +
  4860. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4861. +{
  4862. + int err;
  4863. + char *preinst_args;
  4864. +
  4865. + if (old_pkg) {
  4866. + char *old_version = pkg_version_str_alloc(old_pkg);
  4867. + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
  4868. + free(old_version);
  4869. + } else if (pkg->state_status == SS_CONFIG_FILES) {
  4870. + char *pkg_version = pkg_version_str_alloc(pkg);
  4871. + sprintf_alloc(&preinst_args, "install %s", pkg_version);
  4872. + free(pkg_version);
  4873. + } else {
  4874. + preinst_args = strdup("install");
  4875. + }
  4876. +
  4877. + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
  4878. + if (err) {
  4879. + ipkg_message(conf, IPKG_ERROR,
  4880. + "Aborting installation of %s\n", pkg->name);
  4881. + return 1;
  4882. + }
  4883. +
  4884. + free(preinst_args);
  4885. +
  4886. + return 0;
  4887. +}
  4888. +
  4889. +/*
  4890. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4891. +{
  4892. + DPKG_INCOMPATIBILITY:
  4893. + dpkg does the following error unwind, should we?
  4894. + pkg->postrm abort-upgrade old-version
  4895. + OR pkg->postrm abort-install old-version
  4896. + OR pkg->postrm abort-install
  4897. + return 0;
  4898. +}
  4899. +*/
  4900. +
  4901. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4902. +{
  4903. + int err;
  4904. + conffile_list_elt_t *iter;
  4905. + conffile_t *cf;
  4906. +
  4907. + if (conf->noaction) return 0;
  4908. +
  4909. + /* Backup all modified conffiles */
  4910. + if (old_pkg) {
  4911. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4912. + char *cf_name;
  4913. +
  4914. + cf = iter->data;
  4915. + cf_name = root_filename_alloc(conf, cf->name);
  4916. +
  4917. + /* Don't worry if the conffile is just plain gone */
  4918. + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
  4919. + err = backup_make_backup(conf, cf_name);
  4920. + if (err) {
  4921. + return err;
  4922. + }
  4923. + }
  4924. + free(cf_name);
  4925. + }
  4926. + }
  4927. +
  4928. + /* Backup all conffiles that were not conffiles in old_pkg */
  4929. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4930. + char *cf_name;
  4931. + cf = iter->data;
  4932. + cf_name = root_filename_alloc(conf, cf->name);
  4933. + /* Ignore if this was a conffile in old_pkg as well */
  4934. + if (pkg_get_conffile(old_pkg, cf->name)) {
  4935. + continue;
  4936. + }
  4937. +
  4938. + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
  4939. + err = backup_make_backup(conf, cf_name);
  4940. + if (err) {
  4941. + return err;
  4942. + }
  4943. + }
  4944. + free(cf_name);
  4945. + }
  4946. +
  4947. + return 0;
  4948. +}
  4949. +
  4950. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg)
  4951. +{
  4952. + conffile_list_elt_t *iter;
  4953. +
  4954. + if (old_pkg) {
  4955. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4956. + backup_remove(iter->data->name);
  4957. + }
  4958. + }
  4959. +
  4960. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4961. + backup_remove(iter->data->name);
  4962. + }
  4963. +
  4964. + return 0;
  4965. +}
  4966. +
  4967. +
  4968. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4969. +{
  4970. + /* DPKG_INCOMPATIBILITY:
  4971. + ipkg takes a slightly different approach than dpkg at this
  4972. + point. dpkg installs each file in the new package while
  4973. + creating a backup for any file that is replaced, (so that it
  4974. + can unwind if necessary). To avoid complexity and redundant
  4975. + storage, ipkg doesn't do any installation until later, (at the
  4976. + point at which dpkg removes the backups.
  4977. +
  4978. + But, we do have to check for data file clashes, since after
  4979. + installing a package with a file clash, removing either of the
  4980. + packages involved in the clash has the potential to break the
  4981. + other package.
  4982. + */
  4983. + str_list_t *files_list;
  4984. + str_list_elt_t *iter;
  4985. +
  4986. + int clashes = 0;
  4987. +
  4988. + files_list = pkg_get_installed_files(pkg);
  4989. + for (iter = files_list->head; iter; iter = iter->next) {
  4990. + char *root_filename;
  4991. + char *filename = iter->data;
  4992. + root_filename = root_filename_alloc(conf, filename);
  4993. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  4994. + pkg_t *owner;
  4995. + pkg_t *obs;
  4996. + /* Pre-existing conffiles are OK */
  4997. + /* @@@@ should have way to check that it is a conffile -Jamey */
  4998. + if (backup_exists_for(root_filename)) {
  4999. + continue;
  5000. + }
  5001. +
  5002. + /* Pre-existing files are OK if force-overwrite was asserted. */
  5003. + if (conf->force_overwrite) {
  5004. + /* but we need to change who owns this file */
  5005. + file_hash_set_file_owner(conf, filename, pkg);
  5006. + continue;
  5007. + }
  5008. +
  5009. + owner = file_hash_get_file_owner(conf, filename);
  5010. +
  5011. + /* Pre-existing files are OK if owned by the pkg being upgraded. */
  5012. + if (owner && old_pkg) {
  5013. + if (strcmp(owner->name, old_pkg->name) == 0) {
  5014. + continue;
  5015. + }
  5016. + }
  5017. +
  5018. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5019. + if (owner) {
  5020. + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
  5021. + if (pkg_replaces(pkg, owner)) {
  5022. + continue;
  5023. + }
  5024. +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
  5025. + then it's ok to overwrite. */
  5026. + if (strcmp(owner->name,pkg->name)==0){
  5027. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5028. + continue;
  5029. + }
  5030. + }
  5031. +
  5032. + /* Pre-existing files are OK if they are obsolete */
  5033. + obs = hash_table_get(&conf->obs_file_hash, filename);
  5034. + if (obs) {
  5035. + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
  5036. + continue;
  5037. + }
  5038. +
  5039. + /* We have found a clash. */
  5040. + ipkg_message(conf, IPKG_ERROR,
  5041. + "Package %s wants to install file %s\n"
  5042. + "\tBut that file is already provided by package ",
  5043. + pkg->name, filename);
  5044. + if (owner) {
  5045. + ipkg_message(conf, IPKG_ERROR,
  5046. + "%s\n", owner->name);
  5047. + } else {
  5048. + ipkg_message(conf, IPKG_ERROR,
  5049. + "<no package>\nPlease move this file out of the way and try again.\n");
  5050. + }
  5051. + clashes++;
  5052. + }
  5053. + free(root_filename);
  5054. + }
  5055. + pkg_free_installed_files(pkg);
  5056. +
  5057. + return clashes;
  5058. +}
  5059. +
  5060. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg)
  5061. +{
  5062. + /* Basically that's the worst hack I could do to be able to change ownership of
  5063. + file list, but, being that we have no way to unwind the mods, due to structure
  5064. + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
  5065. + What we do here is change the ownership of file in hash if a replace ( or similar events
  5066. + happens )
  5067. + Only the action that are needed to change name should be considered.
  5068. + @@@ To change after 1.0 release.
  5069. + */
  5070. + str_list_t *files_list;
  5071. + str_list_elt_t *iter;
  5072. +
  5073. + int clashes = 0;
  5074. +
  5075. + files_list = pkg_get_installed_files(pkg);
  5076. + for (iter = files_list->head; iter; iter = iter->next) {
  5077. + char *root_filename;
  5078. + char *filename = iter->data;
  5079. + root_filename = root_filename_alloc(conf, filename);
  5080. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5081. + pkg_t *owner;
  5082. +
  5083. + if (conf->force_overwrite) {
  5084. + /* but we need to change who owns this file */
  5085. + file_hash_set_file_owner(conf, filename, pkg);
  5086. + continue;
  5087. + }
  5088. +
  5089. + owner = file_hash_get_file_owner(conf, filename);
  5090. +
  5091. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5092. + if (owner) {
  5093. + if (pkg_replaces(pkg, owner)) {
  5094. +/* It's now time to change the owner of that file.
  5095. + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
  5096. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5097. + file_hash_set_file_owner(conf, filename, pkg);
  5098. + continue;
  5099. + }
  5100. + }
  5101. +
  5102. + }
  5103. + free(root_filename);
  5104. + }
  5105. + pkg_free_installed_files(pkg);
  5106. +
  5107. + return clashes;
  5108. +}
  5109. +
  5110. +/*
  5111. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5112. +{
  5113. + Nothing to do since check_data_file_clashes doesn't change state
  5114. + return 0;
  5115. +}
  5116. +*/
  5117. +
  5118. +/*
  5119. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5120. +{
  5121. + DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
  5122. + 1. If the package is being upgraded, call
  5123. + old-postrm upgrade new-version
  5124. + 2. If this fails, attempt:
  5125. + new-postrm failed-upgrade old-version
  5126. + Error unwind, for both cases:
  5127. + old-preinst abort-upgrade new-version
  5128. + return 0;
  5129. +}
  5130. +*/
  5131. +
  5132. +/*
  5133. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5134. +{
  5135. + DPKG_INCOMPATIBILITY:
  5136. + dpkg does some things here that we don't do yet. Do we care?
  5137. + (See postrm_upgrade_old_pkg for details)
  5138. + return 0;
  5139. +}
  5140. +*/
  5141. +
  5142. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5143. +{
  5144. + int err;
  5145. + str_list_t *old_files;
  5146. + str_list_elt_t *of;
  5147. + str_list_t *new_files;
  5148. + str_list_elt_t *nf;
  5149. +
  5150. + if (old_pkg == NULL) {
  5151. + return 0;
  5152. + }
  5153. +
  5154. + old_files = pkg_get_installed_files(old_pkg);
  5155. + new_files = pkg_get_installed_files(pkg);
  5156. +
  5157. + for (of = old_files->head; of; of = of->next) {
  5158. + pkg_t *owner;
  5159. + char *old, *new;
  5160. + old = of->data;
  5161. + for (nf = new_files->head; nf; nf = nf->next) {
  5162. + new = nf->data;
  5163. + if (strcmp(old, new) == 0) {
  5164. + goto NOT_OBSOLETE;
  5165. + }
  5166. + }
  5167. + if (file_is_dir(old)) {
  5168. + continue;
  5169. + }
  5170. + owner = file_hash_get_file_owner(conf, old);
  5171. + if (owner != old_pkg) {
  5172. + /* in case obsolete file no longer belongs to old_pkg */
  5173. + continue;
  5174. + }
  5175. +
  5176. + /* old file is obsolete */
  5177. + ipkg_message(conf, IPKG_INFO,
  5178. + " removing obsolete file %s\n", old);
  5179. + if (!conf->noaction) {
  5180. + err = unlink(old);
  5181. + if (err) {
  5182. + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
  5183. + strerror(errno));
  5184. + }
  5185. + }
  5186. +
  5187. + NOT_OBSOLETE:
  5188. + ;
  5189. + }
  5190. +
  5191. + pkg_free_installed_files(old_pkg);
  5192. + pkg_free_installed_files(pkg);
  5193. +
  5194. + return 0;
  5195. +}
  5196. +
  5197. +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5198. +{
  5199. + int i;
  5200. + int err = 0;
  5201. + char *globpattern;
  5202. + glob_t globbuf;
  5203. + if (0) {
  5204. + if (!pkg->dest) {
  5205. + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
  5206. + return -1;
  5207. + }
  5208. + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
  5209. + err = glob(globpattern, 0, NULL, &globbuf);
  5210. + free(globpattern);
  5211. + if (err) {
  5212. + return err;
  5213. + }
  5214. + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
  5215. + for (i = 0; i < globbuf.gl_pathc; i++) {
  5216. + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
  5217. + globbuf.gl_pathv[i], old_pkg->name);
  5218. + if (!conf->noaction)
  5219. + unlink(globbuf.gl_pathv[i]);
  5220. + }
  5221. + globfree(&globbuf);
  5222. + }
  5223. + return err;
  5224. +}
  5225. +
  5226. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5227. +{
  5228. + int ret;
  5229. + char *prefix;
  5230. +
  5231. + if (old_pkg)
  5232. + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
  5233. + sprintf_alloc(&prefix, "%s.", pkg->name);
  5234. + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
  5235. + pkg->dest->info_dir,
  5236. + prefix);
  5237. + free(prefix);
  5238. + return ret;
  5239. +}
  5240. +
  5241. +/*
  5242. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
  5243. +{
  5244. + DPKG_INCOMPATIBILITY:
  5245. + This is a fairly sophisticated dpkg operation. Shall we
  5246. + skip it?
  5247. +
  5248. + Any packages all of whose files have been overwritten during the
  5249. + installation, and which aren't required for dependencies, are
  5250. + considered to have been removed. For each such package
  5251. + 1. disappearer's-postrm disappear overwriter overwriter-version
  5252. + 2. The package's maintainer scripts are removed
  5253. + 3. It is noted in the status database as being in a sane state,
  5254. + namely not installed (any conffiles it may have are ignored,
  5255. + rather than being removed by dpkg). Note that disappearing
  5256. + packages do not have their prerm called, because dpkg doesn't
  5257. + know in advance that the package is going to vanish.
  5258. +
  5259. +
  5260. + return 0;
  5261. +}
  5262. +*/
  5263. +
  5264. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
  5265. +{
  5266. + int err;
  5267. +
  5268. + /* ipkg takes a slightly different approach to data file backups
  5269. + than dpkg. Rather than removing backups at this point, we
  5270. + actually do the data file installation now. See comments in
  5271. + check_data_file_clashes() for more details. */
  5272. +
  5273. + ipkg_message(conf, IPKG_INFO,
  5274. + " extracting data files to %s\n", pkg->dest->root_dir);
  5275. + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
  5276. + if (err) {
  5277. + return err;
  5278. + }
  5279. +
  5280. + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
  5281. + so we can't save ourself from removing important packages
  5282. + At this point we (should) have extracted the .control file, so it
  5283. + would be a good idea to reload the data in it, and set the Essential
  5284. + state in *pkg. From now on the Essential is back in status file and
  5285. + we can protect again.
  5286. + We should operate this way:
  5287. + fopen the file ( pkg->dest->root_dir/pkg->name.control )
  5288. + check for "Essential" in it
  5289. + set the value in pkg->essential.
  5290. + This new routine could be useful also for every other flag
  5291. + Pigi: 16/03/2004 */
  5292. + set_flags_from_control(conf, pkg) ;
  5293. +
  5294. + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
  5295. + err = pkg_write_filelist(conf, pkg);
  5296. + if (err)
  5297. + return err;
  5298. +
  5299. + /* XXX: FEATURE: ipkg should identify any files which existed
  5300. + before installation and which were overwritten, (see
  5301. + check_data_file_clashes()). What it must do is remove any such
  5302. + files from the filelist of the old package which provided the
  5303. + file. Otherwise, if the old package were removed at some point
  5304. + it would break the new package. Removing the new package will
  5305. + also break the old one, but this cannot be helped since the old
  5306. + package's file has already been deleted. This is the importance
  5307. + of check_data_file_clashes(), and only allowing ipkg to install
  5308. + a clashing package with a user force. */
  5309. +
  5310. + return 0;
  5311. +}
  5312. +
  5313. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
  5314. +{
  5315. + conffile_list_elt_t *iter;
  5316. + conffile_t *cf;
  5317. + char *cf_backup;
  5318. + uint8_t *md5sum;
  5319. +
  5320. +
  5321. + if (conf->noaction) return 0;
  5322. +
  5323. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  5324. + char *root_filename;
  5325. + cf = iter->data;
  5326. + root_filename = root_filename_alloc(conf, cf->name);
  5327. +
  5328. + /* Might need to initialize the md5sum for each conffile */
  5329. + if (cf->value == NULL) {
  5330. + cf->value = (char *)file_md5sum_alloc(root_filename);
  5331. + }
  5332. +
  5333. + if (!file_exists(root_filename)) {
  5334. + free(root_filename);
  5335. + continue;
  5336. + }
  5337. +
  5338. + cf_backup = backup_filename_alloc(root_filename);
  5339. +
  5340. +
  5341. + if (file_exists(cf_backup)) {
  5342. + /* Let's compute md5 to test if files are changed */
  5343. + md5sum = file_md5sum_alloc(cf_backup);
  5344. + if (strcmp( cf->value, (char *)md5sum) != 0 ) {
  5345. + if (conf->force_defaults
  5346. + || user_prefers_old_conffile(cf->name, cf_backup) ) {
  5347. + rename(cf_backup, root_filename);
  5348. + }
  5349. + }
  5350. + unlink(cf_backup);
  5351. + free(md5sum);
  5352. + }
  5353. +
  5354. + free(cf_backup);
  5355. + free(root_filename);
  5356. + }
  5357. +
  5358. + return 0;
  5359. +}
  5360. +
  5361. +static int user_prefers_old_conffile(const char *file_name, const char *backup)
  5362. +{
  5363. + char *response;
  5364. + const char *short_file_name;
  5365. +
  5366. + short_file_name = strrchr(file_name, '/');
  5367. + if (short_file_name) {
  5368. + short_file_name++;
  5369. + } else {
  5370. + short_file_name = file_name;
  5371. + }
  5372. +
  5373. + while (1) {
  5374. + response = get_user_response(" Configuration file '%s'\n"
  5375. + " ==> File on system created by you or by a script.\n"
  5376. + " ==> File also in package provided by package maintainer.\n"
  5377. + " What would you like to do about it ? Your options are:\n"
  5378. + " Y or I : install the package maintainer's version\n"
  5379. + " N or O : keep your currently-installed version\n"
  5380. +#ifdef CONFIG_DIFF
  5381. + " D : show the differences between the versions\n"
  5382. +#endif
  5383. + " The default action is to keep your current version.\n"
  5384. + " *** %s (Y/I/N/O"
  5385. +#ifdef CONFIG_DIFF
  5386. + "/D"
  5387. +#endif
  5388. + ") [default=N] ? ", file_name, short_file_name);
  5389. + if (strcmp(response, "y") == 0
  5390. + || strcmp(response, "i") == 0
  5391. + || strcmp(response, "yes") == 0) {
  5392. + free(response);
  5393. + return 0;
  5394. + }
  5395. +
  5396. +#ifdef CONFIG_DIFF
  5397. + if (strcmp(response, "d") == 0) {
  5398. + char *cmd;
  5399. +
  5400. + free(response);
  5401. + /* XXX: BUG rewrite to use exec or busybox's internal diff */
  5402. + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
  5403. + xsystem(cmd);
  5404. + free(cmd);
  5405. + printf(" [Press ENTER to continue]\n");
  5406. + response = file_read_line_alloc(stdin);
  5407. + free(response);
  5408. + continue;
  5409. + }
  5410. +#endif
  5411. +
  5412. + free(response);
  5413. + return 1;
  5414. + }
  5415. +}
  5416. +
  5417. +/* XXX: CLEANUP: I'd like to move all of the code for
  5418. + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
  5419. + it would make sense to cleanup pkg->tmp_unpack_dir directly from
  5420. + pkg_deinit for example). */
  5421. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
  5422. +{
  5423. + DIR *tmp_dir;
  5424. + struct dirent *dirent;
  5425. + char *tmp_file;
  5426. +
  5427. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  5428. +#error
  5429. + ipkg_message(conf, IPKG_DEBUG,
  5430. + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  5431. + __FUNCTION__, pkg->tmp_unpack_dir);
  5432. + return 0;
  5433. +#endif
  5434. +
  5435. + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
  5436. + tmp_dir = opendir(pkg->tmp_unpack_dir);
  5437. + if (tmp_dir) {
  5438. + while (1) {
  5439. + dirent = readdir(tmp_dir);
  5440. + if (dirent == NULL) {
  5441. + break;
  5442. + }
  5443. + sprintf_alloc(&tmp_file, "%s/%s",
  5444. + pkg->tmp_unpack_dir, dirent->d_name);
  5445. + if (! file_is_dir(tmp_file)) {
  5446. + unlink(tmp_file);
  5447. + }
  5448. + free(tmp_file);
  5449. + }
  5450. + closedir(tmp_dir);
  5451. + rmdir(pkg->tmp_unpack_dir);
  5452. + free(pkg->tmp_unpack_dir);
  5453. + pkg->tmp_unpack_dir = NULL;
  5454. + }
  5455. + }
  5456. +
  5457. + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
  5458. + pkg->name, pkg->local_filename, conf->tmp_dir);
  5459. + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
  5460. + unlink(pkg->local_filename);
  5461. + free(pkg->local_filename);
  5462. + pkg->local_filename = NULL;
  5463. + }
  5464. +
  5465. + return 0;
  5466. +}
  5467. +
  5468. +static char *backup_filename_alloc(const char *file_name)
  5469. +{
  5470. + char *backup;
  5471. +
  5472. + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
  5473. +
  5474. + return backup;
  5475. +}
  5476. +
  5477. +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
  5478. +{
  5479. + int err;
  5480. + char *backup;
  5481. +
  5482. + backup = backup_filename_alloc(file_name);
  5483. + err = file_copy(file_name, backup);
  5484. + if (err) {
  5485. + ipkg_message(conf, IPKG_ERROR,
  5486. + "%s: Failed to copy %s to %s\n",
  5487. + __FUNCTION__, file_name, backup);
  5488. + }
  5489. +
  5490. + free(backup);
  5491. +
  5492. + return err;
  5493. +}
  5494. +
  5495. +static int backup_exists_for(const char *file_name)
  5496. +{
  5497. + int ret;
  5498. + char *backup;
  5499. +
  5500. + backup = backup_filename_alloc(file_name);
  5501. +
  5502. + ret = file_exists(backup);
  5503. +
  5504. + free(backup);
  5505. +
  5506. + return ret;
  5507. +}
  5508. +
  5509. +static int backup_remove(const char *file_name)
  5510. +{
  5511. + char *backup;
  5512. +
  5513. + backup = backup_filename_alloc(file_name);
  5514. + unlink(backup);
  5515. + free(backup);
  5516. +
  5517. + return 0;
  5518. +}
  5519. +
  5520. +
  5521. +
  5522. +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
  5523. +
  5524. +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
  5525. +{
  5526. + /* first, remove the packages that need removing */
  5527. + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
  5528. + pkg_t *pkg = pkgs_to_remove->pkgs[i];
  5529. + err = ipkg_remove_pkg(conf, pkg,0);
  5530. + if (err) return err;
  5531. + }
  5532. + return 0;
  5533. +}
  5534. +
  5535. +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)
  5536. +{
  5537. + int i;
  5538. + /* now one more pass checking on the ones that need to be installed */
  5539. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5540. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5541. + if (pkg->dest == NULL)
  5542. + pkg->dest = conf->default_dest;
  5543. +
  5544. + pkg->state_want = SW_INSTALL;
  5545. +
  5546. + /* Abhaya: conflicts check */
  5547. + err = check_conflicts_for(conf, pkg);
  5548. + if (err) { return err; }
  5549. + }
  5550. + return 0;
  5551. +}
  5552. +
  5553. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5554. +{
  5555. + int i;
  5556. + /* now one more pass checking on the ones that need to be installed */
  5557. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5558. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5559. +
  5560. + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
  5561. + pkg_vec_t *replacees = pkg_vec_alloc();
  5562. + pkg_get_installed_replacees(pkg, replacees);
  5563. +
  5564. + /* XXX: BUG: we really should treat replacement more like an upgrade
  5565. + * Instead, we're going to remove the replacees
  5566. + */
  5567. + err = pkg_remove_installed_replacees(conf, replacees);
  5568. + if (err) return err;
  5569. + pkg->state_flag |= SF_REMOVED_REPLACEES;
  5570. + }
  5571. + return 0;
  5572. +}
  5573. +
  5574. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5575. +{
  5576. + int i;
  5577. + /* now one more pass checking on the ones that need to be installed */
  5578. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5579. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5580. + if (pkg->local_filename == NULL) {
  5581. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  5582. + if (err) {
  5583. + ipkg_message(conf, IPKG_ERROR,
  5584. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  5585. + pkg->name);
  5586. + return err;
  5587. + }
  5588. + }
  5589. + if (pkg->tmp_unpack_dir == NULL) {
  5590. + err = unpack_pkg_control_files(conf, pkg);
  5591. + if (err) return err;
  5592. + }
  5593. + }
  5594. + return 0;
  5595. +}
  5596. +
  5597. +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5598. +{
  5599. + int i;
  5600. + /* now one more pass checking on the ones that need to be installed */
  5601. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5602. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5603. + pkg_t *old_pkg = pkg->old_pkg;
  5604. +
  5605. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  5606. + if (err) return err;
  5607. +
  5608. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  5609. + if (err) return err;
  5610. +
  5611. + err = preinst_configure(conf, pkg, old_pkg);
  5612. + if (err) return err;
  5613. +
  5614. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  5615. + if (err) return err;
  5616. +
  5617. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  5618. + if (err) return err;
  5619. + }
  5620. + return 0;
  5621. +}
  5622. +
  5623. +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5624. +{
  5625. + int i;
  5626. + /* now one more pass checking on the ones that need to be installed */
  5627. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5628. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5629. + pkg_t *old_pkg = pkg->old_pkg;
  5630. +
  5631. + if (old_pkg) {
  5632. + old_pkg->state_want = SW_DEINSTALL;
  5633. +
  5634. + if (old_pkg->state_flag & SF_NOPRUNE) {
  5635. + ipkg_message(conf, IPKG_INFO,
  5636. + " not removing obsolesced files because package marked noprune\n");
  5637. + } else {
  5638. + ipkg_message(conf, IPKG_INFO,
  5639. + " removing obsolesced files\n");
  5640. + remove_obsolesced_files(conf, pkg, old_pkg);
  5641. + }
  5642. + }
  5643. +
  5644. + ipkg_message(conf, IPKG_INFO,
  5645. + " installing maintainer scripts\n");
  5646. + install_maintainer_scripts(conf, pkg, old_pkg);
  5647. +
  5648. + /* the following just returns 0 */
  5649. + remove_disappeared(conf, pkg);
  5650. +
  5651. + ipkg_message(conf, IPKG_INFO,
  5652. + " installing data files\n");
  5653. + install_data_files(conf, pkg);
  5654. +
  5655. + ipkg_message(conf, IPKG_INFO,
  5656. + " resolving conf files\n");
  5657. + resolve_conffiles(conf, pkg);
  5658. +
  5659. + pkg->state_status = SS_UNPACKED;
  5660. +
  5661. + if (old_pkg) {
  5662. + old_pkg->state_status = SS_NOT_INSTALLED;
  5663. + }
  5664. +
  5665. + time(&pkg->installed_time);
  5666. +
  5667. + ipkg_message(conf, IPKG_INFO,
  5668. + " cleanup temp files\n");
  5669. + cleanup_temporary_files(conf, pkg);
  5670. +
  5671. + if (pkg->parent)
  5672. + pkg->parent->state_status = pkg->state_status;
  5673. + }
  5674. + return 0;
  5675. +}
  5676. +
  5677. +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5678. +{
  5679. + int i;
  5680. + /* now one more pass checking on the ones that need to be installed */
  5681. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5682. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5683. + pkg_t *old_pkg = pkg->old_pkg;
  5684. +
  5685. + if (old_pkg) {
  5686. + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
  5687. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5688. + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
  5689. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  5690. + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
  5691. + backup_modified_conffiles_unwind(pkg, old_pkg);
  5692. + */
  5693. + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
  5694. + preinst_configure_unwind(conf, pkg, old_pkg);
  5695. + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
  5696. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  5697. + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
  5698. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5699. + */
  5700. +
  5701. + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
  5702. + remove_installed_replacees_unwind(conf, pkg, old_pkg);
  5703. +
  5704. + }
  5705. + }
  5706. + return 0;
  5707. +}
  5708. +
  5709. +/*
  5710. + * Perform all the actions.
  5711. + *
  5712. + * pkgs_to_remove are packages marked for removal.
  5713. + * pkgs_superseded are the old packages being replaced by upgrades.
  5714. + *
  5715. + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
  5716. + */
  5717. +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)
  5718. +{
  5719. + int err;
  5720. + int i;
  5721. +
  5722. + err = ipkg_remove_packages(conf, pkgs_to_remove);
  5723. + if (err) return err;
  5724. +
  5725. + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
  5726. + if (err) return err;
  5727. +
  5728. + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
  5729. + if (err) goto UNWIND;
  5730. +
  5731. + /* @@@@ look at ipkg_install_pkg for handling replacements */
  5732. + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
  5733. + if (err) goto UNWIND;
  5734. +
  5735. + /*
  5736. + * Now that we have the packages unpacked, we can look for data
  5737. + * file clashes. First, we mark the files from the superseded
  5738. + * packages as obsolete. Then we scan the files in
  5739. + * pkgs_to_install, and only complain about clashes with
  5740. + * non-obsolete files.
  5741. + */
  5742. +
  5743. + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
  5744. + if (err) goto UNWIND;
  5745. +
  5746. + /* this was before checking data file clashes */
  5747. + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
  5748. + if (err) goto UNWIND;
  5749. +
  5750. + /* point of no return: no unwinding after this */
  5751. + err = ipkg_process_actions_install(conf, pkgs_to_install);
  5752. + if (err) return err;
  5753. +
  5754. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  5755. + return 0;
  5756. +
  5757. + UNWIND:
  5758. + ipkg_process_actions_unwind(conf, pkgs_to_install);
  5759. +
  5760. + ipkg_message(conf, IPKG_INFO,
  5761. + " cleanup temp files\n");
  5762. + cleanup_temporary_files(conf, pkg);
  5763. +
  5764. + ipkg_message(conf, IPKG_INFO,
  5765. + "Failed.\n");
  5766. + return err;
  5767. +}
  5768. +
  5769. +#endif
  5770. diff -Nur busybox-1.18.1.orig/archival/libipkg/ipkg_install.h busybox-1.18.1/archival/libipkg/ipkg_install.h
  5771. --- busybox-1.18.1.orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
  5772. +++ busybox-1.18.1/archival/libipkg/ipkg_install.h 2010-12-25 22:38:07.000000000 +0100
  5773. @@ -0,0 +1,35 @@
  5774. +/* ipkg_install.h - the itsy package management system
  5775. +
  5776. + Carl D. Worth
  5777. +
  5778. + Copyright (C) 2001 University of Southern California
  5779. +
  5780. + This program is free software; you can redistribute it and/or
  5781. + modify it under the terms of the GNU General Public License as
  5782. + published by the Free Software Foundation; either version 2, or (at
  5783. + your option) any later version.
  5784. +
  5785. + This program is distributed in the hope that it will be useful, but
  5786. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5787. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5788. + General Public License for more details.
  5789. +*/
  5790. +
  5791. +#ifndef IPKG_INSTALL_H
  5792. +#define IPKG_INSTALL_H
  5793. +
  5794. +#include "pkg.h"
  5795. +#include "ipkg_conf.h"
  5796. +
  5797. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5798. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5799. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
  5800. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
  5801. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  5802. +
  5803. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
  5804. +
  5805. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
  5806. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
  5807. +
  5808. +#endif
  5809. diff -Nur busybox-1.18.1.orig/archival/libipkg/ipkg_message.c busybox-1.18.1/archival/libipkg/ipkg_message.c
  5810. --- busybox-1.18.1.orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
  5811. +++ busybox-1.18.1/archival/libipkg/ipkg_message.c 2010-12-25 22:38:07.000000000 +0100
  5812. @@ -0,0 +1,35 @@
  5813. +/* ipkg_message.c - the itsy package management system
  5814. +
  5815. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5816. +
  5817. + This program is free software; you can redistribute it and/or
  5818. + modify it under the terms of the GNU General Public License as
  5819. + published by the Free Software Foundation; either version 2, or (at
  5820. + your option) any later version.
  5821. +
  5822. + This program is distributed in the hope that it will be useful, but
  5823. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5824. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5825. + General Public License for more details.
  5826. +*/
  5827. +
  5828. +
  5829. +#include "ipkg.h"
  5830. +#include "ipkg_conf.h"
  5831. +#include "ipkg_message.h"
  5832. +#include "libipkg.h"
  5833. +
  5834. +void
  5835. +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
  5836. +{
  5837. + va_list ap;
  5838. + char ts[256];
  5839. +
  5840. + if (ipkg_cb_message)
  5841. + {
  5842. + va_start (ap, fmt);
  5843. + vsnprintf (ts,256,fmt, ap);
  5844. + va_end (ap);
  5845. + ipkg_cb_message(conf,level,ts);
  5846. + }
  5847. +}
  5848. diff -Nur busybox-1.18.1.orig/archival/libipkg/ipkg_message.h busybox-1.18.1/archival/libipkg/ipkg_message.h
  5849. --- busybox-1.18.1.orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
  5850. +++ busybox-1.18.1/archival/libipkg/ipkg_message.h 2010-12-25 22:38:07.000000000 +0100
  5851. @@ -0,0 +1,32 @@
  5852. +/* ipkg_message.h - the itsy package management system
  5853. +
  5854. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5855. +
  5856. + This program is free software; you can redistribute it and/or
  5857. + modify it under the terms of the GNU General Public License as
  5858. + published by the Free Software Foundation; either version 2, or (at
  5859. + your option) any later version.
  5860. +
  5861. + This program is distributed in the hope that it will be useful, but
  5862. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5863. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5864. + General Public License for more details.
  5865. +*/
  5866. +
  5867. +#ifndef _IPKG_MESSAGE_H_
  5868. +#define _IPKG_MESSAGE_H_
  5869. +
  5870. +#include "ipkg.h"
  5871. +#include "ipkg_conf.h"
  5872. +
  5873. +typedef enum {
  5874. + IPKG_ERROR, /* error conditions */
  5875. + IPKG_NOTICE, /* normal but significant condition */
  5876. + IPKG_INFO, /* informational message */
  5877. + IPKG_DEBUG, /* debug level message */
  5878. + IPKG_DEBUG2, /* more debug level message */
  5879. +} message_level_t;
  5880. +
  5881. +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
  5882. +
  5883. +#endif /* _IPKG_MESSAGE_H_ */
  5884. diff -Nur busybox-1.18.1.orig/archival/libipkg/ipkg_remove.c busybox-1.18.1/archival/libipkg/ipkg_remove.c
  5885. --- busybox-1.18.1.orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
  5886. +++ busybox-1.18.1/archival/libipkg/ipkg_remove.c 2010-12-25 22:38:07.000000000 +0100
  5887. @@ -0,0 +1,385 @@
  5888. +/* ipkg_remove.c - the itsy package management system
  5889. +
  5890. + Carl D. Worth
  5891. +
  5892. + Copyright (C) 2001 University of Southern California
  5893. +
  5894. + This program is free software; you can redistribute it and/or
  5895. + modify it under the terms of the GNU General Public License as
  5896. + published by the Free Software Foundation; either version 2, or (at
  5897. + your option) any later version.
  5898. +
  5899. + This program is distributed in the hope that it will be useful, but
  5900. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5901. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5902. + General Public License for more details.
  5903. +*/
  5904. +
  5905. +#include "ipkg.h"
  5906. +#include "ipkg_message.h"
  5907. +
  5908. +#include <glob.h>
  5909. +
  5910. +#include "ipkg_remove.h"
  5911. +
  5912. +#include "file_util.h"
  5913. +#include "sprintf_alloc.h"
  5914. +#include "str_util.h"
  5915. +
  5916. +#include "ipkg_cmd.h"
  5917. +
  5918. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents);
  5919. +
  5920. +/*
  5921. + * Returns number of the number of packages depending on the packages provided by this package.
  5922. + * Every package implicitly provides itself.
  5923. + */
  5924. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents)
  5925. +{
  5926. + int nprovides = pkg->provides_count;
  5927. + abstract_pkg_t **provides = pkg->provides;
  5928. + int n_installed_dependents = 0;
  5929. + int i;
  5930. + for (i = 0; i <= nprovides; i++) {
  5931. + abstract_pkg_t *providee = provides[i];
  5932. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5933. + abstract_pkg_t *dep_ab_pkg;
  5934. + if (dependers == NULL)
  5935. + continue;
  5936. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5937. + if (dep_ab_pkg->state_status == SS_INSTALLED){
  5938. + n_installed_dependents++;
  5939. + }
  5940. + }
  5941. +
  5942. + }
  5943. + /* if caller requested the set of installed dependents */
  5944. + if (pdependents) {
  5945. + int p = 0;
  5946. + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
  5947. +
  5948. + if ( dependents == NULL ){
  5949. + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
  5950. + return -1;
  5951. + }
  5952. +
  5953. + *pdependents = dependents;
  5954. + for (i = 0; i <= nprovides; i++) {
  5955. + abstract_pkg_t *providee = provides[i];
  5956. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5957. + abstract_pkg_t *dep_ab_pkg;
  5958. + if (dependers == NULL)
  5959. + continue;
  5960. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5961. + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
  5962. + dependents[p++] = dep_ab_pkg;
  5963. + dep_ab_pkg->state_flag |= SF_MARKED;
  5964. + }
  5965. + }
  5966. + }
  5967. + dependents[p] = NULL;
  5968. + /* now clear the marks */
  5969. + for (i = 0; i < p; i++) {
  5970. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5971. + dep_ab_pkg->state_flag &= ~SF_MARKED;
  5972. + }
  5973. + }
  5974. + return n_installed_dependents;
  5975. +}
  5976. +
  5977. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5978. +{
  5979. + int i;
  5980. + int a;
  5981. + int count;
  5982. + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
  5983. + abstract_pkg_t * ab_pkg;
  5984. +
  5985. + if((ab_pkg = pkg->parent) == NULL){
  5986. + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
  5987. + __FUNCTION__, pkg->name);
  5988. + return 0;
  5989. + }
  5990. +
  5991. + if (dependents == NULL)
  5992. + return 0;
  5993. +
  5994. + // here i am using the dependencies_checked
  5995. + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
  5996. + return 0; // has already been encountered in the process
  5997. + // of marking packages for removal - Karthik
  5998. + ab_pkg->dependencies_checked = 2;
  5999. +
  6000. + i = 0;
  6001. + count = 1;
  6002. + while (dependents [i] != NULL) {
  6003. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  6004. +
  6005. + if (dep_ab_pkg->dependencies_checked == 2){
  6006. + i++;
  6007. + continue;
  6008. + }
  6009. + if (dep_ab_pkg->state_status == SS_INSTALLED) {
  6010. + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
  6011. + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
  6012. + if (dep_pkg->state_status == SS_INSTALLED) {
  6013. + pkg_vec_insert(dependent_pkgs, dep_pkg);
  6014. + count++;
  6015. + }
  6016. + }
  6017. + }
  6018. + i++;
  6019. + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
  6020. + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
  6021. + }
  6022. +
  6023. + if (count == 1)
  6024. + return 0;
  6025. +
  6026. +
  6027. + for (i = 0; i < dependent_pkgs->len; i++) {
  6028. + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
  6029. + if (err)
  6030. + return err;
  6031. + }
  6032. + return 0;
  6033. +}
  6034. +
  6035. +static int user_prefers_removing_dependents(ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  6036. +{
  6037. + abstract_pkg_t *dep_ab_pkg;
  6038. + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
  6039. + while ((dep_ab_pkg = *dependents++) != NULL) {
  6040. + if (dep_ab_pkg->state_status == SS_INSTALLED)
  6041. + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
  6042. + }
  6043. + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
  6044. + ipkg_message(conf, IPKG_ERROR, "");
  6045. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
  6046. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
  6047. + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
  6048. + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
  6049. + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
  6050. + return 0;
  6051. +}
  6052. +
  6053. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
  6054. +{
  6055. +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
  6056. + thus I wan't check for essential, as I'm upgrading.
  6057. + I hope it won't break anything :)
  6058. +*/
  6059. + int err;
  6060. + abstract_pkg_t *parent_pkg = NULL;
  6061. +
  6062. + if (pkg->essential && !message) {
  6063. + if (conf->force_removal_of_essential_packages) {
  6064. + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
  6065. + "\tIf your system breaks, you get to keep both pieces\n",
  6066. + pkg->name);
  6067. + } else {
  6068. + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
  6069. + "\tRemoving an essential package may lead to an unusable system, but if\n"
  6070. + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
  6071. + "\tits will with the option: -force-removal-of-essential-packages\n",
  6072. + pkg->name);
  6073. + return IPKG_PKG_IS_ESSENTIAL;
  6074. + }
  6075. + }
  6076. +
  6077. + if ((parent_pkg = pkg->parent) == NULL)
  6078. + return 0;
  6079. +
  6080. + /* only attempt to remove dependent installed packages if
  6081. + * force_depends is not specified or the package is being
  6082. + * replaced.
  6083. + */
  6084. + if (!conf->force_depends
  6085. + && !(pkg->state_flag & SF_REPLACE)) {
  6086. + abstract_pkg_t **dependents;
  6087. + int has_installed_dependents =
  6088. + pkg_has_installed_dependents(pkg, &dependents);
  6089. +
  6090. + if (has_installed_dependents) {
  6091. + /*
  6092. + * if this package is depended up by others, then either we should
  6093. + * not remove it or we should remove it and all of its dependents
  6094. + */
  6095. +
  6096. + if (!conf->force_removal_of_dependent_packages
  6097. + && !user_prefers_removing_dependents(conf, pkg, dependents)) {
  6098. + return IPKG_PKG_HAS_DEPENDENTS;
  6099. + }
  6100. +
  6101. + /* remove packages depending on this package - Karthik */
  6102. + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
  6103. + free(dependents);
  6104. + if (err) return err;
  6105. + }
  6106. + }
  6107. +
  6108. + if ( message==0 ){
  6109. + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
  6110. + fflush(stdout);
  6111. + }
  6112. + pkg->state_flag |= SF_FILELIST_CHANGED;
  6113. +
  6114. + pkg->state_want = SW_DEINSTALL;
  6115. + ipkg_state_changed++;
  6116. +
  6117. + pkg_run_script(conf, pkg, "prerm", "remove");
  6118. +
  6119. + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
  6120. + maintains an empty filelist rather than deleting it. That seems
  6121. + like a big pain, and I don't see that that should make a big
  6122. + difference, but for anyone who wants tighter compatibility,
  6123. + feel free to fix this. */
  6124. + remove_data_files_and_list(conf, pkg);
  6125. +
  6126. + pkg_run_script(conf, pkg, "postrm", "remove");
  6127. +
  6128. + remove_maintainer_scripts_except_postrm(conf, pkg);
  6129. +
  6130. + /* Aman Gupta - Since ipkg is made for handheld devices with limited
  6131. + * space, it doesn't make sense to leave extra configurations, files,
  6132. + * and maintainer scripts left around. So, we make remove like purge,
  6133. + * and take out all the crap :) */
  6134. +
  6135. + remove_postrm(conf, pkg);
  6136. + pkg->state_status = SS_NOT_INSTALLED;
  6137. +
  6138. + if (parent_pkg)
  6139. + parent_pkg->state_status = SS_NOT_INSTALLED;
  6140. +
  6141. + return 0;
  6142. +}
  6143. +
  6144. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
  6145. +{
  6146. + ipkg_remove_pkg(conf, pkg,0);
  6147. + return 0;
  6148. +}
  6149. +
  6150. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
  6151. +{
  6152. + str_list_t installed_dirs;
  6153. + str_list_t *installed_files;
  6154. + str_list_elt_t *iter;
  6155. + char *file_name;
  6156. + conffile_t *conffile;
  6157. + int removed_a_dir;
  6158. + pkg_t *owner;
  6159. +
  6160. + str_list_init(&installed_dirs);
  6161. + installed_files = pkg_get_installed_files(pkg);
  6162. +
  6163. + for (iter = installed_files->head; iter; iter = iter->next) {
  6164. + file_name = iter->data;
  6165. +
  6166. + if (file_is_dir(file_name)) {
  6167. + str_list_append(&installed_dirs, strdup(file_name));
  6168. + continue;
  6169. + }
  6170. +
  6171. + conffile = pkg_get_conffile(pkg, file_name);
  6172. + if (conffile) {
  6173. + /* XXX: QUESTION: Is this right? I figure we only need to
  6174. + save the conffile if it has been modified. Is that what
  6175. + dpkg does? Or does dpkg preserve all conffiles? If so,
  6176. + this seems like a better thing to do to conserve
  6177. + space. */
  6178. + if (conffile_has_been_modified(conf, conffile)) {
  6179. + printf(" not deleting modified conffile %s\n", file_name);
  6180. + fflush(stdout);
  6181. + continue;
  6182. + }
  6183. + }
  6184. +
  6185. + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
  6186. + if (!conf->noaction)
  6187. + unlink(file_name);
  6188. + }
  6189. +
  6190. + if (!conf->noaction) {
  6191. + do {
  6192. + removed_a_dir = 0;
  6193. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6194. + file_name = iter->data;
  6195. +
  6196. + if (rmdir(file_name) == 0) {
  6197. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
  6198. + removed_a_dir = 1;
  6199. + str_list_remove(&installed_dirs, &iter);
  6200. + }
  6201. + }
  6202. + } while (removed_a_dir);
  6203. + }
  6204. +
  6205. + pkg_free_installed_files(pkg);
  6206. + /* We have to remove the file list now, so that
  6207. + find_pkg_owning_file does not always just report this package */
  6208. + pkg_remove_installed_files_list(conf, pkg);
  6209. +
  6210. + /* Don't print warning for dirs that are provided by other packages */
  6211. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6212. + file_name = iter->data;
  6213. +
  6214. + owner = file_hash_get_file_owner(conf, file_name);
  6215. + if (owner) {
  6216. + free(iter->data);
  6217. + iter->data = NULL;
  6218. + str_list_remove(&installed_dirs, &iter);
  6219. + }
  6220. + }
  6221. +
  6222. + /* cleanup */
  6223. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6224. + free(iter->data);
  6225. + iter->data = NULL;
  6226. + }
  6227. + str_list_deinit(&installed_dirs);
  6228. +
  6229. + return 0;
  6230. +}
  6231. +
  6232. +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6233. +{
  6234. + int i, err;
  6235. + char *globpattern;
  6236. + glob_t globbuf;
  6237. +
  6238. + if (conf->noaction) return 0;
  6239. +
  6240. + sprintf_alloc(&globpattern, "%s/%s.*",
  6241. + pkg->dest->info_dir, pkg->name);
  6242. + err = glob(globpattern, 0, NULL, &globbuf);
  6243. + free(globpattern);
  6244. + if (err) {
  6245. + return 0;
  6246. + }
  6247. +
  6248. + for (i = 0; i < globbuf.gl_pathc; i++) {
  6249. + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
  6250. + continue;
  6251. + }
  6252. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
  6253. + unlink(globbuf.gl_pathv[i]);
  6254. + }
  6255. + globfree(&globbuf);
  6256. +
  6257. + return 0;
  6258. +}
  6259. +
  6260. +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6261. +{
  6262. + char *postrm_file_name;
  6263. +
  6264. + if (conf->noaction) return 0;
  6265. +
  6266. + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
  6267. + pkg->dest->info_dir, pkg->name);
  6268. + unlink(postrm_file_name);
  6269. + free(postrm_file_name);
  6270. +
  6271. + return 0;
  6272. +}
  6273. diff -Nur busybox-1.18.1.orig/archival/libipkg/ipkg_remove.h busybox-1.18.1/archival/libipkg/ipkg_remove.h
  6274. --- busybox-1.18.1.orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
  6275. +++ busybox-1.18.1/archival/libipkg/ipkg_remove.h 2010-12-25 22:38:07.000000000 +0100
  6276. @@ -0,0 +1,33 @@
  6277. +/* ipkg_remove.h - the itsy package management system
  6278. +
  6279. + Carl D. Worth
  6280. +
  6281. + Copyright (C) 2001 University of Southern California
  6282. +
  6283. + This program is free software; you can redistribute it and/or
  6284. + modify it under the terms of the GNU General Public License as
  6285. + published by the Free Software Foundation; either version 2, or (at
  6286. + your option) any later version.
  6287. +
  6288. + This program is distributed in the hope that it will be useful, but
  6289. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6290. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6291. + General Public License for more details.
  6292. +*/
  6293. +
  6294. +#ifndef IPKG_REMOVE_H
  6295. +#define IPKG_REMOVE_H
  6296. +
  6297. +#include "pkg.h"
  6298. +#include "ipkg_conf.h"
  6299. +
  6300. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
  6301. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
  6302. +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
  6303. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents);
  6304. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
  6305. +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6306. +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6307. +
  6308. +
  6309. +#endif
  6310. diff -Nur busybox-1.18.1.orig/archival/libipkg/ipkg_upgrade.c busybox-1.18.1/archival/libipkg/ipkg_upgrade.c
  6311. --- busybox-1.18.1.orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
  6312. +++ busybox-1.18.1/archival/libipkg/ipkg_upgrade.c 2010-12-25 22:38:07.000000000 +0100
  6313. @@ -0,0 +1,79 @@
  6314. +/* ipkg_upgrade.c - the itsy package management system
  6315. +
  6316. + Carl D. Worth
  6317. + Copyright (C) 2001 University of Southern California
  6318. +
  6319. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6320. +
  6321. + This program is free software; you can redistribute it and/or
  6322. + modify it under the terms of the GNU General Public License as
  6323. + published by the Free Software Foundation; either version 2, or (at
  6324. + your option) any later version.
  6325. +
  6326. + This program is distributed in the hope that it will be useful, but
  6327. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6328. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6329. + General Public License for more details.
  6330. +*/
  6331. +
  6332. +#include "ipkg.h"
  6333. +#include "ipkg_install.h"
  6334. +#include "ipkg_message.h"
  6335. +
  6336. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6337. +
  6338. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
  6339. +{
  6340. + pkg_t *new;
  6341. + int cmp;
  6342. + char *old_version, *new_version;
  6343. +
  6344. + if (old->state_flag & SF_HOLD) {
  6345. + ipkg_message(conf, IPKG_NOTICE,
  6346. + "Not upgrading package %s which is marked "
  6347. + "hold (flags=%#x)\n", old->name, old->state_flag);
  6348. + return 0;
  6349. + }
  6350. +
  6351. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
  6352. + if (new == NULL) {
  6353. + old_version = pkg_version_str_alloc(old);
  6354. + ipkg_message(conf, IPKG_NOTICE,
  6355. + "Assuming locally installed package %s (%s) "
  6356. + "is up to date.\n", old->name, old_version);
  6357. + free(old_version);
  6358. + return 0;
  6359. + }
  6360. +
  6361. + old_version = pkg_version_str_alloc(old);
  6362. + new_version = pkg_version_str_alloc(new);
  6363. +
  6364. + cmp = pkg_compare_versions(old, new);
  6365. + ipkg_message(conf, IPKG_DEBUG,
  6366. + "comparing visible versions of pkg %s:"
  6367. + "\n\t%s is installed "
  6368. + "\n\t%s is available "
  6369. + "\n\t%d was comparison result\n",
  6370. + old->name, old_version, new_version, cmp);
  6371. + if (cmp == 0) {
  6372. + ipkg_message(conf, IPKG_INFO,
  6373. + "Package %s (%s) installed in %s is up to date.\n",
  6374. + old->name, old_version, old->dest->name);
  6375. + free(old_version);
  6376. + free(new_version);
  6377. + return 0;
  6378. + } else if (cmp > 0) {
  6379. + ipkg_message(conf, IPKG_NOTICE,
  6380. + "Not downgrading package %s on %s from %s to %s.\n",
  6381. + old->name, old->dest->name, old_version, new_version);
  6382. + free(old_version);
  6383. + free(new_version);
  6384. + return 0;
  6385. + } else if (cmp < 0) {
  6386. + new->dest = old->dest;
  6387. + old->state_want = SW_DEINSTALL;
  6388. + }
  6389. +
  6390. + new->state_flag |= SF_USER;
  6391. + return ipkg_install_pkg(conf, new,1);
  6392. +}
  6393. diff -Nur busybox-1.18.1.orig/archival/libipkg/ipkg_upgrade.h busybox-1.18.1/archival/libipkg/ipkg_upgrade.h
  6394. --- busybox-1.18.1.orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
  6395. +++ busybox-1.18.1/archival/libipkg/ipkg_upgrade.h 2010-12-25 22:38:07.000000000 +0100
  6396. @@ -0,0 +1,18 @@
  6397. +/* ipkg_upgrade.c - the itsy package management system
  6398. +
  6399. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6400. +
  6401. + This program is free software; you can redistribute it and/or
  6402. + modify it under the terms of the GNU General Public License as
  6403. + published by the Free Software Foundation; either version 2, or (at
  6404. + your option) any later version.
  6405. +
  6406. + This program is distributed in the hope that it will be useful, but
  6407. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6408. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6409. + General Public License for more details.
  6410. +*/
  6411. +
  6412. +#include "ipkg.h"
  6413. +
  6414. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6415. diff -Nur busybox-1.18.1.orig/archival/libipkg/ipkg_utils.c busybox-1.18.1/archival/libipkg/ipkg_utils.c
  6416. --- busybox-1.18.1.orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
  6417. +++ busybox-1.18.1/archival/libipkg/ipkg_utils.c 2010-12-25 22:38:07.000000000 +0100
  6418. @@ -0,0 +1,185 @@
  6419. +/* ipkg_utils.c - the itsy package management system
  6420. +
  6421. + Steven M. Ayer
  6422. +
  6423. + Copyright (C) 2002 Compaq Computer Corporation
  6424. +
  6425. + This program is free software; you can redistribute it and/or
  6426. + modify it under the terms of the GNU General Public License as
  6427. + published by the Free Software Foundation; either version 2, or (at
  6428. + your option) any later version.
  6429. +
  6430. + This program is distributed in the hope that it will be useful, but
  6431. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6432. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6433. + General Public License for more details.
  6434. +*/
  6435. +
  6436. +#include "ipkg.h"
  6437. +#include <errno.h>
  6438. +#include <ctype.h>
  6439. +#include <sys/vfs.h>
  6440. +
  6441. +#include "ipkg_utils.h"
  6442. +#include "pkg.h"
  6443. +#include "pkg_hash.h"
  6444. +
  6445. +void push_error_list(struct errlist ** errors, char * msg);
  6446. +void reverse_error_list(struct errlist **errors);
  6447. +void free_error_list(struct errlist **errors);
  6448. +
  6449. +struct errlist* error_list;
  6450. +
  6451. +int get_available_blocks(char * filesystem)
  6452. +{
  6453. + struct statfs sfs;
  6454. +
  6455. + if(statfs(filesystem, &sfs)){
  6456. + fprintf(stderr, "bad statfs\n");
  6457. + return 0;
  6458. + }
  6459. + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
  6460. + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
  6461. +}
  6462. +
  6463. +char **read_raw_pkgs_from_file(const char *file_name)
  6464. +{
  6465. + FILE *fp;
  6466. + char **ret;
  6467. +
  6468. + if(!(fp = fopen(file_name, "r"))){
  6469. + fprintf(stderr, "can't get %s open for read\n", file_name);
  6470. + return NULL;
  6471. + }
  6472. +
  6473. + ret = read_raw_pkgs_from_stream(fp);
  6474. +
  6475. + fclose(fp);
  6476. +
  6477. + return ret;
  6478. +}
  6479. +
  6480. +char **read_raw_pkgs_from_stream(FILE *fp)
  6481. +{
  6482. + char **raw = NULL, *buf, *scout;
  6483. + int count = 0;
  6484. + size_t size = 512;
  6485. +
  6486. + buf = malloc (size);
  6487. +
  6488. + while (fgets(buf, size, fp)) {
  6489. + while (strlen (buf) == (size - 1)
  6490. + && buf[size-2] != '\n') {
  6491. + size_t o = size - 1;
  6492. + size *= 2;
  6493. + buf = realloc (buf, size);
  6494. + if (fgets (buf + o, size - o, fp) == NULL)
  6495. + break;
  6496. + }
  6497. +
  6498. + if(!(count % 50))
  6499. + raw = realloc(raw, (count + 50) * sizeof(char *));
  6500. +
  6501. + if((scout = strchr(buf, '\n')))
  6502. + *scout = '\0';
  6503. +
  6504. + raw[count++] = strdup(buf);
  6505. + }
  6506. +
  6507. + raw = realloc(raw, (count + 1) * sizeof(char *));
  6508. + raw[count] = NULL;
  6509. +
  6510. + free (buf);
  6511. +
  6512. + return raw;
  6513. +}
  6514. +
  6515. +/* something to remove whitespace, a hash pooper */
  6516. +char *trim_alloc(char *line)
  6517. +{
  6518. + char *new;
  6519. + char *dest, *src, *end;
  6520. +
  6521. + new = malloc(strlen(line) + 1);
  6522. + if ( new == NULL ){
  6523. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  6524. + return NULL;
  6525. + }
  6526. + dest = new, src = line, end = line + (strlen(line) - 1);
  6527. +
  6528. + /* remove it from the front */
  6529. + while(src &&
  6530. + isspace(*src) &&
  6531. + *src)
  6532. + src++;
  6533. + /* and now from the back */
  6534. + while((end > src) &&
  6535. + isspace(*end))
  6536. + end--;
  6537. + end++;
  6538. + *end = '\0';
  6539. + strcpy(new, src);
  6540. + /* this does from the first space
  6541. + * blasting away any versions stuff in depends
  6542. + while(src &&
  6543. + !isspace(*src) &&
  6544. + *src)
  6545. + *dest++ = *src++;
  6546. + *dest = '\0';
  6547. + */
  6548. +
  6549. + return new;
  6550. +}
  6551. +
  6552. +int line_is_blank(const char *line)
  6553. +{
  6554. + const char *s;
  6555. +
  6556. + for (s = line; *s; s++) {
  6557. + if (!isspace(*s))
  6558. + return 0;
  6559. + }
  6560. + return 1;
  6561. +}
  6562. +
  6563. +void push_error_list(struct errlist ** errors, char * msg){
  6564. + struct errlist *err_lst_tmp;
  6565. +
  6566. +
  6567. + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
  6568. + err_lst_tmp->errmsg=strdup(msg) ;
  6569. + err_lst_tmp->next = *errors;
  6570. + *errors = err_lst_tmp;
  6571. +}
  6572. +
  6573. +
  6574. +void reverse_error_list(struct errlist **errors){
  6575. + struct errlist *result=NULL;
  6576. + struct errlist *current= *errors;
  6577. + struct errlist *next;
  6578. +
  6579. + while ( current != NULL ) {
  6580. + next = current->next;
  6581. + current->next=result;
  6582. + result=current;
  6583. + current=next;
  6584. + }
  6585. + *errors=result;
  6586. +
  6587. +}
  6588. +
  6589. +
  6590. +void free_error_list(struct errlist **errors){
  6591. + struct errlist *current = *errors;
  6592. +
  6593. + while (current != NULL) {
  6594. + free(current->errmsg);
  6595. + current = (*errors)->next;
  6596. + free(*errors);
  6597. + *errors = current;
  6598. + }
  6599. +
  6600. +
  6601. +}
  6602. +
  6603. +
  6604. diff -Nur busybox-1.18.1.orig/archival/libipkg/ipkg_utils.h busybox-1.18.1/archival/libipkg/ipkg_utils.h
  6605. --- busybox-1.18.1.orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
  6606. +++ busybox-1.18.1/archival/libipkg/ipkg_utils.h 2010-12-25 22:38:07.000000000 +0100
  6607. @@ -0,0 +1,29 @@
  6608. +/* ipkg_utils.h - the itsy package management system
  6609. +
  6610. + Steven M. Ayer
  6611. +
  6612. + Copyright (C) 2002 Compaq Computer Corporation
  6613. +
  6614. + This program is free software; you can redistribute it and/or
  6615. + modify it under the terms of the GNU General Public License as
  6616. + published by the Free Software Foundation; either version 2, or (at
  6617. + your option) any later version.
  6618. +
  6619. + This program is distributed in the hope that it will be useful, but
  6620. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6621. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6622. + General Public License for more details.
  6623. +*/
  6624. +
  6625. +#ifndef IPKG_UTILS_H
  6626. +#define IPKG_UTILS_H
  6627. +
  6628. +#include "pkg.h"
  6629. +
  6630. +int get_available_blocks(char * filesystem);
  6631. +char **read_raw_pkgs_from_file(const char *file_name);
  6632. +char **read_raw_pkgs_from_stream(FILE *fp);
  6633. +char *trim_alloc(char * line);
  6634. +int line_is_blank(const char *line);
  6635. +
  6636. +#endif
  6637. diff -Nur busybox-1.18.1.orig/archival/libipkg/libipkg.c busybox-1.18.1/archival/libipkg/libipkg.c
  6638. --- busybox-1.18.1.orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
  6639. +++ busybox-1.18.1/archival/libipkg/libipkg.c 2010-12-25 22:38:07.000000000 +0100
  6640. @@ -0,0 +1,583 @@
  6641. +/* ipkglib.c - the itsy package management system
  6642. +
  6643. + Florina Boor
  6644. +
  6645. + Copyright (C) 2003 kernel concepts
  6646. +
  6647. + This program is free software; you can redistribute it and/or
  6648. + modify it under the terms of the GNU General Public License as
  6649. + published by the Free Software Foundation; either version 2, or (at
  6650. + your option) any later version.
  6651. +
  6652. + This program is distributed in the hope that it will be useful, but
  6653. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6654. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6655. + General Public License for more details.
  6656. +*/
  6657. +
  6658. +#include "ipkg.h"
  6659. +#include "ipkg_includes.h"
  6660. +#include "libipkg.h"
  6661. +
  6662. +#include "args.h"
  6663. +#include "ipkg_conf.h"
  6664. +#include "ipkg_cmd.h"
  6665. +#include "file_util.h"
  6666. +
  6667. +int ipkg_file_what(args_t *args, const char *file, const char* command);
  6668. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  6669. + char *msg);
  6670. +int default_ipkg_list_callback(char *name, char *desc, char *version);
  6671. +int default_ipkg_files_callback(char *desc);
  6672. +int default_ipkg_status_callback(char *desc);
  6673. +char* default_ipkg_response_callback(char *question);
  6674. +
  6675. +
  6676. +ipkg_message_callback ipkg_cb_message = NULL;
  6677. +ipkg_response_callback ipkg_cb_response = NULL;
  6678. +ipkg_status_callback ipkg_cb_status = NULL;
  6679. +ipkg_list_callback ipkg_cb_list = NULL;
  6680. +
  6681. +
  6682. +int
  6683. +ipkg_init (ipkg_message_callback mcall,
  6684. + ipkg_response_callback rcall,
  6685. + args_t * args)
  6686. +{
  6687. + ipkg_cb_message = mcall;
  6688. + ipkg_cb_response = rcall;
  6689. +
  6690. + args_init (args);
  6691. +
  6692. + return 0;
  6693. +}
  6694. +
  6695. +
  6696. +int
  6697. +ipkg_deinit (args_t * args)
  6698. +{
  6699. + args_deinit (args);
  6700. + ipkg_cb_message = NULL;
  6701. + ipkg_cb_response = NULL;
  6702. +
  6703. + /* place other cleanup stuff here */
  6704. +
  6705. + return 0;
  6706. +}
  6707. +
  6708. +
  6709. +int
  6710. +ipkg_packages_list(args_t *args,
  6711. + const char *packages,
  6712. + ipkg_list_callback cblist,
  6713. + void *userdata)
  6714. +{
  6715. + ipkg_cmd_t *cmd;
  6716. + ipkg_conf_t ipkg_conf;
  6717. + int err;
  6718. +
  6719. + err = ipkg_conf_init (&ipkg_conf, args);
  6720. + if (err)
  6721. + {
  6722. + return err;
  6723. + }
  6724. +
  6725. + ipkg_cb_list = cblist;
  6726. + /* we need to do this because of static declarations,
  6727. + * maybe a good idea to change */
  6728. + cmd = ipkg_cmd_find ("list");
  6729. + if (packages)
  6730. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6731. + else
  6732. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6733. + ipkg_cb_list = NULL;
  6734. + ipkg_conf_deinit (&ipkg_conf);
  6735. + return (err);
  6736. +}
  6737. +
  6738. +
  6739. +int
  6740. +ipkg_packages_status(args_t *args,
  6741. + const char *packages,
  6742. + ipkg_status_callback cbstatus,
  6743. + void *userdata)
  6744. +{
  6745. + ipkg_cmd_t *cmd;
  6746. + ipkg_conf_t ipkg_conf;
  6747. + int err;
  6748. +
  6749. + err = ipkg_conf_init (&ipkg_conf, args);
  6750. + if (err)
  6751. + {
  6752. + return err;
  6753. + }
  6754. +
  6755. + ipkg_cb_status = cbstatus;
  6756. +
  6757. + /* we need to do this because of static declarations,
  6758. + * maybe a good idea to change */
  6759. + cmd = ipkg_cmd_find ("status");
  6760. + if (packages)
  6761. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6762. + else
  6763. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6764. +
  6765. + ipkg_cb_status = NULL;
  6766. + ipkg_conf_deinit (&ipkg_conf);
  6767. + return (err);
  6768. +}
  6769. +
  6770. +
  6771. +int
  6772. +ipkg_packages_info(args_t *args,
  6773. + const char *packages,
  6774. + ipkg_status_callback cbstatus,
  6775. + void *userdata)
  6776. +{
  6777. + ipkg_cmd_t *cmd;
  6778. + ipkg_conf_t ipkg_conf;
  6779. + int err;
  6780. +
  6781. + err = ipkg_conf_init (&ipkg_conf, args);
  6782. + if (err)
  6783. + {
  6784. + return err;
  6785. + }
  6786. +
  6787. + ipkg_cb_status = cbstatus;
  6788. +
  6789. + /* we need to do this because of static declarations,
  6790. + * maybe a good idea to change */
  6791. + cmd = ipkg_cmd_find ("info");
  6792. + if (packages)
  6793. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6794. + else
  6795. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6796. +
  6797. + ipkg_cb_status = NULL;
  6798. + ipkg_conf_deinit (&ipkg_conf);
  6799. + return (err);
  6800. +}
  6801. +
  6802. +
  6803. +int
  6804. +ipkg_packages_install (args_t * args, const char *name)
  6805. +{
  6806. + ipkg_cmd_t *cmd;
  6807. + ipkg_conf_t ipkg_conf;
  6808. + int err;
  6809. +
  6810. + /* this error should be handled in application */
  6811. + if (!name || !strlen (name))
  6812. + return (-1);
  6813. +
  6814. + err = ipkg_conf_init (&ipkg_conf, args);
  6815. + if (err)
  6816. + {
  6817. + return err;
  6818. + }
  6819. +
  6820. + /* we need to do this because of static declarations,
  6821. + * maybe a good idea to change */
  6822. + cmd = ipkg_cmd_find ("install");
  6823. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6824. +
  6825. + ipkg_conf_deinit(&ipkg_conf);
  6826. + return (err);
  6827. +}
  6828. +
  6829. +
  6830. +int
  6831. +ipkg_packages_remove(args_t *args, const char *name, int purge)
  6832. +{
  6833. + ipkg_cmd_t *cmd;
  6834. + ipkg_conf_t ipkg_conf;
  6835. + int err;
  6836. +
  6837. + /* this error should be handled in application */
  6838. + if (!name || !strlen (name))
  6839. + return (-1);
  6840. +
  6841. + err = ipkg_conf_init (&ipkg_conf, args);
  6842. + if (err)
  6843. + {
  6844. + return err;
  6845. + }
  6846. +
  6847. + /* we need to do this because of static declarations,
  6848. + * maybe a good idea to change */
  6849. + if (purge)
  6850. + cmd = ipkg_cmd_find ("purge");
  6851. + else
  6852. + cmd = ipkg_cmd_find ("remove");
  6853. +
  6854. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6855. +
  6856. + ipkg_conf_deinit(&ipkg_conf);
  6857. + return (err);
  6858. +}
  6859. +
  6860. +
  6861. +int
  6862. +ipkg_lists_update(args_t *args)
  6863. +{
  6864. + ipkg_cmd_t *cmd;
  6865. + ipkg_conf_t ipkg_conf;
  6866. + int err;
  6867. +
  6868. + err = ipkg_conf_init (&ipkg_conf, args);
  6869. + if (err)
  6870. + {
  6871. + return err;
  6872. + }
  6873. +
  6874. + /* we need to do this because of static declarations,
  6875. + * maybe a good idea to change */
  6876. + cmd = ipkg_cmd_find ("update");
  6877. +
  6878. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6879. +
  6880. + ipkg_conf_deinit(&ipkg_conf);
  6881. + return (err);
  6882. +}
  6883. +
  6884. +
  6885. +int
  6886. +ipkg_packages_upgrade(args_t *args)
  6887. +{
  6888. + ipkg_cmd_t *cmd;
  6889. + ipkg_conf_t ipkg_conf;
  6890. + int err;
  6891. +
  6892. + err = ipkg_conf_init (&ipkg_conf, args);
  6893. + if (err)
  6894. + {
  6895. + return err;
  6896. + }
  6897. +
  6898. + /* we need to do this because of static declarations,
  6899. + * maybe a good idea to change */
  6900. + cmd = ipkg_cmd_find ("upgrade");
  6901. +
  6902. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6903. +
  6904. + ipkg_conf_deinit(&ipkg_conf);
  6905. + return (err);
  6906. +}
  6907. +
  6908. +
  6909. +int
  6910. +ipkg_packages_download (args_t * args, const char *name)
  6911. +{
  6912. + ipkg_cmd_t *cmd;
  6913. + ipkg_conf_t ipkg_conf;
  6914. + int err;
  6915. +
  6916. + /* this error should be handled in application */
  6917. + if (!name || !strlen (name))
  6918. + return (-1);
  6919. +
  6920. + err = ipkg_conf_init (&ipkg_conf, args);
  6921. + if (err)
  6922. + {
  6923. + return err;
  6924. + }
  6925. +
  6926. + /* we need to do this because of static declarations,
  6927. + * maybe a good idea to change */
  6928. + cmd = ipkg_cmd_find ("download");
  6929. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6930. +
  6931. + ipkg_conf_deinit(&ipkg_conf);
  6932. + return (err);
  6933. +}
  6934. +
  6935. +
  6936. +int
  6937. +ipkg_package_files(args_t *args,
  6938. + const char *name,
  6939. + ipkg_list_callback cblist,
  6940. + void *userdata)
  6941. +{
  6942. + ipkg_cmd_t *cmd;
  6943. + ipkg_conf_t ipkg_conf;
  6944. + int err;
  6945. +
  6946. + /* this error should be handled in application */
  6947. + if (!name || !strlen (name))
  6948. + return (-1);
  6949. +
  6950. + err = ipkg_conf_init (&ipkg_conf, args);
  6951. + if (err)
  6952. + {
  6953. + return err;
  6954. + }
  6955. +
  6956. + ipkg_cb_list = cblist;
  6957. +
  6958. + /* we need to do this because of static declarations,
  6959. + * maybe a good idea to change */
  6960. + cmd = ipkg_cmd_find ("files");
  6961. +
  6962. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
  6963. +
  6964. + ipkg_cb_list = NULL;
  6965. + ipkg_conf_deinit(&ipkg_conf);
  6966. + return (err);
  6967. +}
  6968. +
  6969. +
  6970. +int
  6971. +ipkg_file_search(args_t *args,
  6972. + const char *file,
  6973. + ipkg_list_callback cblist,
  6974. + void *userdata)
  6975. +{
  6976. + ipkg_cmd_t *cmd;
  6977. + ipkg_conf_t ipkg_conf;
  6978. + int err;
  6979. +
  6980. + /* this error should be handled in application */
  6981. + if (!file || !strlen (file))
  6982. + return (-1);
  6983. +
  6984. + err = ipkg_conf_init (&ipkg_conf, args);
  6985. + if (err)
  6986. + {
  6987. + return err;
  6988. + }
  6989. +
  6990. + ipkg_cb_list = cblist;
  6991. +
  6992. + /* we need to do this because of static declarations,
  6993. + * maybe a good idea to change */
  6994. + cmd = ipkg_cmd_find ("search");
  6995. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
  6996. +
  6997. + ipkg_cb_list = NULL;
  6998. + ipkg_conf_deinit(&ipkg_conf);
  6999. + return(err);
  7000. +}
  7001. +
  7002. +
  7003. +int
  7004. +ipkg_file_what(args_t *args, const char *file, const char* command)
  7005. +{
  7006. + ipkg_cmd_t *cmd;
  7007. + ipkg_conf_t ipkg_conf;
  7008. + int err;
  7009. +
  7010. + /* this error should be handled in application */
  7011. + if (!file || !strlen (file))
  7012. + return (-1);
  7013. +
  7014. + err = ipkg_conf_init (&ipkg_conf, args);
  7015. + if (err)
  7016. + {
  7017. + return err;
  7018. + }
  7019. +
  7020. + /* we need to do this because of static declarations,
  7021. + * maybe a good idea to change */
  7022. + cmd = ipkg_cmd_find (command);
  7023. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
  7024. +
  7025. + ipkg_conf_deinit(&ipkg_conf);
  7026. + return(err);
  7027. +}
  7028. +
  7029. +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
  7030. +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
  7031. +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
  7032. +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
  7033. +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
  7034. +
  7035. +
  7036. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  7037. + char *msg)
  7038. +{
  7039. + if (conf && (conf->verbosity < level)) {
  7040. + return 0;
  7041. + } else {
  7042. + if ( level == IPKG_ERROR )
  7043. + push_error_list(&error_list, msg);
  7044. + else
  7045. + printf(msg);
  7046. + }
  7047. + return 0;
  7048. +}
  7049. +
  7050. +int default_ipkg_list_callback(char *name, char *desc, char *version)
  7051. +{
  7052. + if (desc)
  7053. + printf("%s - %s - %s\n", name, version, desc);
  7054. + else
  7055. + printf("%s - %s\n", name, version);
  7056. + return 0;
  7057. +}
  7058. +
  7059. +int default_ipkg_files_callback(char *desc)
  7060. +{
  7061. + if (desc)
  7062. + printf("%s\n", desc);
  7063. + return 0;
  7064. +}
  7065. +
  7066. +int default_ipkg_status_callback(char *desc)
  7067. +{
  7068. + printf("%s\n", desc);
  7069. + return 0;
  7070. +}
  7071. +
  7072. +char* default_ipkg_response_callback(char *question)
  7073. +{
  7074. + char *response = NULL;
  7075. + printf(question);
  7076. + fflush(stdout);
  7077. + do {
  7078. + response = (char *)file_read_line_alloc(stdin);
  7079. + } while (response == NULL);
  7080. + return response;
  7081. +}
  7082. +
  7083. +/* This is used for backward compatibility */
  7084. +int
  7085. +ipkg_op (int argc, char *argv[])
  7086. +{
  7087. + int err, optind_;
  7088. + args_t args;
  7089. + char *cmd_name;
  7090. + ipkg_cmd_t *cmd;
  7091. + ipkg_conf_t ipkg_conf;
  7092. + const char *message = "ipkg must have one sub-command argument";
  7093. + FILE *f;
  7094. + struct mntent *mnt;
  7095. + int remountroot;
  7096. +
  7097. + args_init (&args);
  7098. +
  7099. + optind_ = args_parse (&args, argc, argv);
  7100. + if (optind_ == argc || optind_ < 0)
  7101. + {
  7102. + args_usage(message);
  7103. + }
  7104. +
  7105. + cmd_name = argv[optind_++];
  7106. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  7107. + read anything from there.
  7108. +*/
  7109. + if ( !strcmp(cmd_name,"print-architecture") ||
  7110. + !strcmp(cmd_name,"print_architecture") ||
  7111. + !strcmp(cmd_name,"print-installation-architecture") ||
  7112. + !strcmp(cmd_name,"print_installation_architecture") )
  7113. + args.nocheckfordirorfile = 1;
  7114. +
  7115. +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
  7116. + read anything from there.
  7117. +*/
  7118. + if ( !strcmp(cmd_name,"flag") ||
  7119. + !strcmp(cmd_name,"configure") ||
  7120. + !strcmp(cmd_name,"remove") ||
  7121. + !strcmp(cmd_name,"files") ||
  7122. + !strcmp(cmd_name,"search") ||
  7123. + !strcmp(cmd_name,"compare_versions") ||
  7124. + !strcmp(cmd_name,"compare-versions") ||
  7125. + !strcmp(cmd_name,"list_installed") ||
  7126. + !strcmp(cmd_name,"list-installed") ||
  7127. + !strcmp(cmd_name,"status") )
  7128. + args.noreadfeedsfile = 1;
  7129. +
  7130. +
  7131. +
  7132. +
  7133. + err = ipkg_conf_init (&ipkg_conf, &args);
  7134. + if (err)
  7135. + {
  7136. + return err;
  7137. + }
  7138. +
  7139. + args_deinit (&args);
  7140. +
  7141. + ipkg_cb_message = default_ipkg_message_callback;
  7142. + ipkg_cb_response = default_ipkg_response_callback;
  7143. + ipkg_cb_status = (ipkg_status_callback)default_ipkg_status_callback;
  7144. + if ( strcmp(cmd_name, "files")==0)
  7145. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_files_callback;
  7146. + else
  7147. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_list_callback;
  7148. +
  7149. + cmd = ipkg_cmd_find (cmd_name);
  7150. + if (cmd == NULL)
  7151. + {
  7152. + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
  7153. + cmd_name);
  7154. + args_usage (NULL);
  7155. + }
  7156. +
  7157. + if (cmd->requires_args && optind_ == argc)
  7158. + {
  7159. + fprintf (stderr,
  7160. + "%s: the ``%s'' command requires at least one argument\n",
  7161. + __FUNCTION__, cmd_name);
  7162. + args_usage (NULL);
  7163. + }
  7164. +
  7165. + remountroot = 0;
  7166. + /* check if /dev/root is mounted read-only */
  7167. + if ((f = setmntent("/proc/mounts", "r")) == NULL)
  7168. + fprintf (stderr, "Checking /proc/mounts failed\n");
  7169. +
  7170. + while ((mnt = getmntent(f)) != NULL) {
  7171. + if (strcmp(mnt->mnt_fsname, "/dev/root") == 0 &&
  7172. + hasmntopt(mnt, MNTOPT_RO) != NULL) {
  7173. + remountroot = 1;
  7174. + }
  7175. + }
  7176. +
  7177. + endmntent(f);
  7178. +
  7179. + if (remountroot) {
  7180. + if ( !strcmp(cmd_name,"install") ||
  7181. + !strcmp(cmd_name,"update") ||
  7182. + !strcmp(cmd_name,"upgrade") ||
  7183. + !strcmp(cmd_name,"flag") ||
  7184. + !strcmp(cmd_name,"configure") ||
  7185. + !strcmp(cmd_name,"remove") ) {
  7186. + /* mount rootfs read-write */
  7187. + if (mount("","/",0,MS_REMOUNT,0)<0)
  7188. + fprintf (stderr, "Mounting rootfs read-write failed\n");
  7189. + }
  7190. + }
  7191. +
  7192. + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind_, (const char **) (argv + optind_), NULL);
  7193. +
  7194. + ipkg_conf_deinit (&ipkg_conf);
  7195. +
  7196. + if (remountroot) {
  7197. + if ( !strcmp(cmd_name,"install") ||
  7198. + !strcmp(cmd_name,"update") ||
  7199. + !strcmp(cmd_name,"upgrade") ||
  7200. + !strcmp(cmd_name,"flag") ||
  7201. + !strcmp(cmd_name,"configure") ||
  7202. + !strcmp(cmd_name,"remove") ) {
  7203. + sync();
  7204. + /* mount rootfs read-only */
  7205. + if (mount("","/",0,MS_REMOUNT|MS_RDONLY,0)<0)
  7206. + fprintf (stderr, "Mounting rootfs read-only failed\n");
  7207. + }
  7208. + }
  7209. +
  7210. + /* check if cfgfs exists */
  7211. + if (access("/sbin/cfgfs", X_OK) == 0) {
  7212. + if ( !strcmp(cmd_name,"install") ||
  7213. + !strcmp(cmd_name,"update") ||
  7214. + !strcmp(cmd_name,"upgrade")) {
  7215. + if (system("cfgfs status -q") != 0) {
  7216. + fprintf (stdout, "Updates in /etc, please review changes\n");
  7217. + fprintf (stdout, "You can check via cfgfs status\n");
  7218. + }
  7219. + }
  7220. + }
  7221. +
  7222. + return err;
  7223. +}
  7224. diff -Nur busybox-1.18.1.orig/archival/libipkg/libipkg.h busybox-1.18.1/archival/libipkg/libipkg.h
  7225. --- busybox-1.18.1.orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
  7226. +++ busybox-1.18.1/archival/libipkg/libipkg.h 2010-12-25 22:38:07.000000000 +0100
  7227. @@ -0,0 +1,78 @@
  7228. +/* ipkglib.h - the itsy package management system
  7229. +
  7230. + Florian Boor <florian.boor@kernelconcepts.de>
  7231. +
  7232. + This program is free software; you can redistribute it and/or
  7233. + modify it under the terms of the GNU General Public License as
  7234. + published by the Free Software Foundation; either version 2, or (at
  7235. + your option) any later version.
  7236. +
  7237. + This program is distributed in the hope that it will be useful, but
  7238. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7239. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7240. + General Public License for more details.
  7241. +*/
  7242. +
  7243. +#ifndef IPKGLIB_H
  7244. +#define IPKGLIB_H
  7245. +
  7246. +#include "ipkg_conf.h"
  7247. +#include "ipkg_message.h"
  7248. +
  7249. +#include "args.h"
  7250. +#include "pkg.h"
  7251. +
  7252. +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
  7253. + char *msg);
  7254. +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
  7255. + pkg_state_status_t status, void *userdata);
  7256. +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
  7257. + void *userdata);
  7258. +typedef char* (*ipkg_response_callback)(char *question);
  7259. +
  7260. +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
  7261. +extern int ipkg_init (ipkg_message_callback mcall,
  7262. + ipkg_response_callback rcall,
  7263. + args_t * args);
  7264. +
  7265. +extern int ipkg_deinit (args_t *args);
  7266. +extern int ipkg_packages_list(args_t *args,
  7267. + const char *packages,
  7268. + ipkg_list_callback cblist,
  7269. + void *userdata);
  7270. +extern int ipkg_packages_status(args_t *args,
  7271. + const char *packages,
  7272. + ipkg_status_callback cbstatus,
  7273. + void *userdata);
  7274. +extern int ipkg_packages_info(args_t *args,
  7275. + const char *packages,
  7276. + ipkg_status_callback cbstatus,
  7277. + void *userdata);
  7278. +extern int ipkg_packages_install(args_t *args, const char *name);
  7279. +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
  7280. +extern int ipkg_lists_update(args_t *args);
  7281. +extern int ipkg_packages_upgrade(args_t *args);
  7282. +extern int ipkg_packages_download(args_t *args, const char *name);
  7283. +extern int ipkg_package_files(args_t *args,
  7284. + const char *name,
  7285. + ipkg_list_callback cblist,
  7286. + void *userdata);
  7287. +extern int ipkg_file_search(args_t *args,
  7288. + const char *file,
  7289. + ipkg_list_callback cblist,
  7290. + void *userdata);
  7291. +extern int ipkg_package_whatdepends(args_t *args, const char *file);
  7292. +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
  7293. +extern int ipkg_package_whatprovides(args_t *args, const char *file);
  7294. +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
  7295. +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
  7296. +
  7297. +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
  7298. +extern ipkg_response_callback ipkg_cb_response;
  7299. +extern ipkg_status_callback ipkg_cb_status;
  7300. +extern ipkg_list_callback ipkg_cb_list;
  7301. +extern void push_error_list(struct errlist **errors,char * msg);
  7302. +extern void reverse_error_list(struct errlist **errors);
  7303. +extern void free_error_list(struct errlist **errors);
  7304. +
  7305. +#endif
  7306. diff -Nur busybox-1.18.1.orig/archival/libipkg/nv_pair.c busybox-1.18.1/archival/libipkg/nv_pair.c
  7307. --- busybox-1.18.1.orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
  7308. +++ busybox-1.18.1/archival/libipkg/nv_pair.c 2010-12-25 22:38:07.000000000 +0100
  7309. @@ -0,0 +1,40 @@
  7310. +/* nv_pair.c - the itsy package management system
  7311. +
  7312. + Carl D. Worth
  7313. +
  7314. + Copyright (C) 2001 University of Southern California
  7315. +
  7316. + This program is free software; you can redistribute it and/or
  7317. + modify it under the terms of the GNU General Public License as
  7318. + published by the Free Software Foundation; either version 2, or (at
  7319. + your option) any later version.
  7320. +
  7321. + This program is distributed in the hope that it will be useful, but
  7322. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7323. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7324. + General Public License for more details.
  7325. +*/
  7326. +
  7327. +#include "ipkg.h"
  7328. +
  7329. +#include "nv_pair.h"
  7330. +#include "str_util.h"
  7331. +
  7332. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
  7333. +{
  7334. + nv_pair->name = str_dup_safe(name);
  7335. + nv_pair->value = str_dup_safe(value);
  7336. +
  7337. + return 0;
  7338. +}
  7339. +
  7340. +void nv_pair_deinit(nv_pair_t *nv_pair)
  7341. +{
  7342. + free(nv_pair->name);
  7343. + nv_pair->name = NULL;
  7344. +
  7345. + free(nv_pair->value);
  7346. + nv_pair->value = NULL;
  7347. +}
  7348. +
  7349. +
  7350. diff -Nur busybox-1.18.1.orig/archival/libipkg/nv_pair.h busybox-1.18.1/archival/libipkg/nv_pair.h
  7351. --- busybox-1.18.1.orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
  7352. +++ busybox-1.18.1/archival/libipkg/nv_pair.h 2010-12-25 22:38:07.000000000 +0100
  7353. @@ -0,0 +1,32 @@
  7354. +/* nv_pair.h - the itsy package management system
  7355. +
  7356. + Carl D. Worth
  7357. +
  7358. + Copyright (C) 2001 University of Southern California
  7359. +
  7360. + This program is free software; you can redistribute it and/or
  7361. + modify it under the terms of the GNU General Public License as
  7362. + published by the Free Software Foundation; either version 2, or (at
  7363. + your option) any later version.
  7364. +
  7365. + This program is distributed in the hope that it will be useful, but
  7366. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7367. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7368. + General Public License for more details.
  7369. +*/
  7370. +
  7371. +#ifndef NV_PAIR_H
  7372. +#define NV_PAIR_H
  7373. +
  7374. +typedef struct nv_pair nv_pair_t;
  7375. +struct nv_pair
  7376. +{
  7377. + char *name;
  7378. + char *value;
  7379. +};
  7380. +
  7381. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
  7382. +void nv_pair_deinit(nv_pair_t *nv_pair);
  7383. +
  7384. +#endif
  7385. +
  7386. diff -Nur busybox-1.18.1.orig/archival/libipkg/nv_pair_list.c busybox-1.18.1/archival/libipkg/nv_pair_list.c
  7387. --- busybox-1.18.1.orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
  7388. +++ busybox-1.18.1/archival/libipkg/nv_pair_list.c 2010-12-25 22:38:07.000000000 +0100
  7389. @@ -0,0 +1,98 @@
  7390. +/* nv_pair_list.c - the itsy package management system
  7391. +
  7392. + Carl D. Worth
  7393. +
  7394. + Copyright (C) 2001 University of Southern California
  7395. +
  7396. + This program is free software; you can redistribute it and/or
  7397. + modify it under the terms of the GNU General Public License as
  7398. + published by the Free Software Foundation; either version 2, or (at
  7399. + your option) any later version.
  7400. +
  7401. + This program is distributed in the hope that it will be useful, but
  7402. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7403. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7404. + General Public License for more details.
  7405. +*/
  7406. +
  7407. +#include "ipkg.h"
  7408. +
  7409. +#include "nv_pair.h"
  7410. +#include "void_list.h"
  7411. +#include "nv_pair_list.h"
  7412. +
  7413. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
  7414. +{
  7415. + return void_list_elt_init((void_list_elt_t *) elt, data);
  7416. +}
  7417. +
  7418. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
  7419. +{
  7420. + void_list_elt_deinit((void_list_elt_t *) elt);
  7421. +}
  7422. +
  7423. +int nv_pair_list_init(nv_pair_list_t *list)
  7424. +{
  7425. + return void_list_init((void_list_t *) list);
  7426. +}
  7427. +
  7428. +void nv_pair_list_deinit(nv_pair_list_t *list)
  7429. +{
  7430. + nv_pair_list_elt_t *iter;
  7431. + nv_pair_t *nv_pair;
  7432. +
  7433. + for (iter = list->head; iter; iter = iter->next) {
  7434. + nv_pair = iter->data;
  7435. + nv_pair_deinit(nv_pair);
  7436. +
  7437. + /* malloced in nv_pair_list_append */
  7438. + free(nv_pair);
  7439. + iter->data = NULL;
  7440. + }
  7441. + void_list_deinit((void_list_t *) list);
  7442. +}
  7443. +
  7444. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
  7445. +{
  7446. + int err;
  7447. +
  7448. + /* freed in nv_pair_list_deinit */
  7449. + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
  7450. +
  7451. + if (nv_pair == NULL) {
  7452. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7453. + return NULL;
  7454. + }
  7455. + nv_pair_init(nv_pair, name, value);
  7456. +
  7457. + err = void_list_append((void_list_t *) list, nv_pair);
  7458. + if (err) {
  7459. + return NULL;
  7460. + }
  7461. +
  7462. + return nv_pair;
  7463. +}
  7464. +
  7465. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
  7466. +{
  7467. + return void_list_push((void_list_t *) list, data);
  7468. +}
  7469. +
  7470. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
  7471. +{
  7472. + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
  7473. +}
  7474. +
  7475. +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
  7476. +{
  7477. + nv_pair_list_elt_t *iter;
  7478. + nv_pair_t *nv_pair;
  7479. +
  7480. + for (iter = list->head; iter; iter = iter->next) {
  7481. + nv_pair = iter->data;
  7482. + if (strcmp(nv_pair->name, name) == 0) {
  7483. + return nv_pair->value;
  7484. + }
  7485. + }
  7486. + return NULL;
  7487. +}
  7488. diff -Nur busybox-1.18.1.orig/archival/libipkg/nv_pair_list.h busybox-1.18.1/archival/libipkg/nv_pair_list.h
  7489. --- busybox-1.18.1.orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
  7490. +++ busybox-1.18.1/archival/libipkg/nv_pair_list.h 2010-12-25 22:38:07.000000000 +0100
  7491. @@ -0,0 +1,60 @@
  7492. +/* nv_pair_list.h - the itsy package management system
  7493. +
  7494. + Carl D. Worth
  7495. +
  7496. + Copyright (C) 2001 University of Southern California
  7497. +
  7498. + This program is free software; you can redistribute it and/or
  7499. + modify it under the terms of the GNU General Public License as
  7500. + published by the Free Software Foundation; either version 2, or (at
  7501. + your option) any later version.
  7502. +
  7503. + This program is distributed in the hope that it will be useful, but
  7504. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7505. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7506. + General Public License for more details.
  7507. +*/
  7508. +
  7509. +#ifndef NV_PAIR_LIST_H
  7510. +#define NV_PAIR_LIST_H
  7511. +
  7512. +#include "nv_pair.h"
  7513. +#include "void_list.h"
  7514. +
  7515. +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
  7516. +struct nv_pair_list_elt
  7517. +{
  7518. + nv_pair_list_elt_t *next;
  7519. + nv_pair_t *data;
  7520. +};
  7521. +
  7522. +typedef struct nv_pair_list nv_pair_list_t;
  7523. +struct nv_pair_list
  7524. +{
  7525. + nv_pair_list_elt_t pre_head;
  7526. + nv_pair_list_elt_t *head;
  7527. + nv_pair_list_elt_t *tail;
  7528. +};
  7529. +
  7530. +static inline int nv_pair_list_empty(nv_pair_list_t *list)
  7531. +{
  7532. + if (list->head == NULL)
  7533. + return 1;
  7534. + else
  7535. + return 0;
  7536. +}
  7537. +
  7538. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
  7539. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
  7540. +
  7541. +int nv_pair_list_init(nv_pair_list_t *list);
  7542. +void nv_pair_list_deinit(nv_pair_list_t *list);
  7543. +
  7544. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
  7545. + const char *name, const char *value);
  7546. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
  7547. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
  7548. +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
  7549. +
  7550. +#endif
  7551. +
  7552. diff -Nur busybox-1.18.1.orig/archival/libipkg/pkg.c busybox-1.18.1/archival/libipkg/pkg.c
  7553. --- busybox-1.18.1.orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
  7554. +++ busybox-1.18.1/archival/libipkg/pkg.c 2010-12-25 22:38:07.000000000 +0100
  7555. @@ -0,0 +1,1757 @@
  7556. +/* pkg.c - the itsy package management system
  7557. +
  7558. + Carl D. Worth
  7559. +
  7560. + Copyright (C) 2001 University of Southern California
  7561. +
  7562. + This program is free software; you can redistribute it and/or
  7563. + modify it under the terms of the GNU General Public License as
  7564. + published by the Free Software Foundation; either version 2, or (at
  7565. + your option) any later version.
  7566. +
  7567. + This program is distributed in the hope that it will be useful, but
  7568. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7569. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7570. + General Public License for more details.
  7571. +*/
  7572. +
  7573. +#include "ipkg.h"
  7574. +#include <ctype.h>
  7575. +#include <string.h>
  7576. +#include <errno.h>
  7577. +
  7578. +#include "pkg.h"
  7579. +
  7580. +#include "pkg_parse.h"
  7581. +#include "pkg_extract.h"
  7582. +#include "ipkg_message.h"
  7583. +#include "ipkg_utils.h"
  7584. +
  7585. +#include "sprintf_alloc.h"
  7586. +#include "file_util.h"
  7587. +#include "str_util.h"
  7588. +#include "xsystem.h"
  7589. +#include "ipkg_conf.h"
  7590. +
  7591. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname);
  7592. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_);
  7593. +
  7594. +typedef struct enum_map enum_map_t;
  7595. +struct enum_map
  7596. +{
  7597. + int value;
  7598. + const char *str;
  7599. +};
  7600. +
  7601. +static const enum_map_t pkg_state_want_map[] = {
  7602. + { SW_UNKNOWN, "unknown"},
  7603. + { SW_INSTALL, "install"},
  7604. + { SW_DEINSTALL, "deinstall"},
  7605. + { SW_PURGE, "purge"}
  7606. +};
  7607. +
  7608. +static const enum_map_t pkg_state_flag_map[] = {
  7609. + { SF_OK, "ok"},
  7610. + { SF_REINSTREQ, "reinstreq"},
  7611. + { SF_HOLD, "hold"},
  7612. + { SF_REPLACE, "replace"},
  7613. + { SF_NOPRUNE, "noprune"},
  7614. + { SF_PREFER, "prefer"},
  7615. + { SF_OBSOLETE, "obsolete"},
  7616. + { SF_USER, "user"},
  7617. +};
  7618. +
  7619. +static const enum_map_t pkg_state_status_map[] = {
  7620. + { SS_NOT_INSTALLED, "not-installed" },
  7621. + { SS_UNPACKED, "unpacked" },
  7622. + { SS_HALF_CONFIGURED, "half-configured" },
  7623. + { SS_INSTALLED, "installed" },
  7624. + { SS_HALF_INSTALLED, "half-installed" },
  7625. + { SS_CONFIG_FILES, "config-files" },
  7626. + { SS_POST_INST_FAILED, "post-inst-failed" },
  7627. + { SS_REMOVAL_FAILED, "removal-failed" }
  7628. +};
  7629. +
  7630. +static int verrevcmp(const char *val, const char *ref);
  7631. +
  7632. +
  7633. +pkg_t *pkg_new(void)
  7634. +{
  7635. + pkg_t *pkg;
  7636. +
  7637. + pkg = malloc(sizeof(pkg_t));
  7638. + if (pkg == NULL) {
  7639. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7640. + return NULL;
  7641. + }
  7642. +
  7643. + pkg_init(pkg);
  7644. +
  7645. + return pkg;
  7646. +}
  7647. +
  7648. +int pkg_init(pkg_t *pkg)
  7649. +{
  7650. + memset(pkg, 0, sizeof(pkg_t));
  7651. + pkg->name = NULL;
  7652. + pkg->epoch = 0;
  7653. + pkg->version = NULL;
  7654. + pkg->revision = NULL;
  7655. + pkg->familiar_revision = NULL;
  7656. + pkg->dest = NULL;
  7657. + pkg->src = NULL;
  7658. + pkg->architecture = NULL;
  7659. + pkg->maintainer = NULL;
  7660. + pkg->section = NULL;
  7661. + pkg->description = NULL;
  7662. + pkg->state_want = SW_UNKNOWN;
  7663. + pkg->state_flag = SF_OK;
  7664. + pkg->state_status = SS_NOT_INSTALLED;
  7665. + pkg->depends_str = NULL;
  7666. + pkg->provides_str = NULL;
  7667. + pkg->depends_count = 0;
  7668. + pkg->depends = NULL;
  7669. + pkg->suggests_str = NULL;
  7670. + pkg->recommends_str = NULL;
  7671. + pkg->suggests_count = 0;
  7672. + pkg->recommends_count = 0;
  7673. +
  7674. + /* Abhaya: added init for conflicts fields */
  7675. + pkg->conflicts = NULL;
  7676. + pkg->conflicts_count = 0;
  7677. +
  7678. + /* added for replaces. Jamey 7/23/2002 */
  7679. + pkg->replaces = NULL;
  7680. + pkg->replaces_count = 0;
  7681. +
  7682. + pkg->pre_depends_count = 0;
  7683. + pkg->pre_depends_str = NULL;
  7684. + pkg->provides_count = 0;
  7685. + pkg->provides = NULL;
  7686. + pkg->filename = NULL;
  7687. + pkg->local_filename = NULL;
  7688. + pkg->tmp_unpack_dir = NULL;
  7689. + pkg->md5sum = NULL;
  7690. + pkg->size = NULL;
  7691. + pkg->installed_size = NULL;
  7692. + pkg->priority = NULL;
  7693. + pkg->source = NULL;
  7694. + conffile_list_init(&pkg->conffiles);
  7695. + pkg->installed_files = NULL;
  7696. + pkg->installed_files_ref_cnt = 0;
  7697. + pkg->essential = 0;
  7698. + pkg->provided_by_hand = 0;
  7699. +
  7700. + return 0;
  7701. +}
  7702. +
  7703. +void pkg_deinit(pkg_t *pkg)
  7704. +{
  7705. + free(pkg->name);
  7706. + pkg->name = NULL;
  7707. + pkg->epoch = 0;
  7708. + free(pkg->version);
  7709. + pkg->version = NULL;
  7710. + /* revision and familiar_revision share storage with version, so
  7711. + don't free */
  7712. + pkg->revision = NULL;
  7713. + pkg->familiar_revision = NULL;
  7714. + /* owned by ipkg_conf_t */
  7715. + pkg->dest = NULL;
  7716. + /* owned by ipkg_conf_t */
  7717. + pkg->src = NULL;
  7718. + free(pkg->architecture);
  7719. + pkg->architecture = NULL;
  7720. + free(pkg->maintainer);
  7721. + pkg->maintainer = NULL;
  7722. + free(pkg->section);
  7723. + pkg->section = NULL;
  7724. + free(pkg->description);
  7725. + pkg->description = NULL;
  7726. + pkg->state_want = SW_UNKNOWN;
  7727. + pkg->state_flag = SF_OK;
  7728. + pkg->state_status = SS_NOT_INSTALLED;
  7729. + free(pkg->depends_str);
  7730. + pkg->depends_str = NULL;
  7731. + free(pkg->provides_str);
  7732. + pkg->provides_str = NULL;
  7733. + pkg->depends_count = 0;
  7734. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
  7735. + pkg->pre_depends_count = 0;
  7736. + free(pkg->pre_depends_str);
  7737. + pkg->pre_depends_str = NULL;
  7738. + pkg->provides_count = 0;
  7739. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
  7740. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
  7741. + free(pkg->filename);
  7742. + pkg->filename = NULL;
  7743. + free(pkg->local_filename);
  7744. + pkg->local_filename = NULL;
  7745. + /* CLEANUP: It'd be nice to pullin the cleanup function from
  7746. + ipkg_install.c here. See comment in
  7747. + ipkg_install.c:cleanup_temporary_files */
  7748. + free(pkg->tmp_unpack_dir);
  7749. + pkg->tmp_unpack_dir = NULL;
  7750. + free(pkg->md5sum);
  7751. + pkg->md5sum = NULL;
  7752. + free(pkg->size);
  7753. + pkg->size = NULL;
  7754. + free(pkg->installed_size);
  7755. + pkg->installed_size = NULL;
  7756. + free(pkg->priority);
  7757. + pkg->priority = NULL;
  7758. + free(pkg->source);
  7759. + pkg->source = NULL;
  7760. + conffile_list_deinit(&pkg->conffiles);
  7761. + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
  7762. + since if they are calling deinit, they should know. Maybe do an
  7763. + assertion here instead? */
  7764. + pkg->installed_files_ref_cnt = 1;
  7765. + pkg_free_installed_files(pkg);
  7766. + pkg->essential = 0;
  7767. +}
  7768. +
  7769. +int pkg_init_from_file(pkg_t *pkg, const char *filename)
  7770. +{
  7771. + int err;
  7772. + char **raw;
  7773. + FILE *control_file;
  7774. +
  7775. + err = pkg_init(pkg);
  7776. + if (err) { return err; }
  7777. +
  7778. + pkg->local_filename = strdup(filename);
  7779. +
  7780. + control_file = tmpfile();
  7781. + err = pkg_extract_control_file_to_stream(pkg, control_file);
  7782. + if (err) { return err; }
  7783. +
  7784. + rewind(control_file);
  7785. + raw = read_raw_pkgs_from_stream(control_file);
  7786. + pkg_parse_raw(pkg, &raw, NULL, NULL);
  7787. +
  7788. + fclose(control_file);
  7789. +
  7790. + return 0;
  7791. +}
  7792. +
  7793. +/* Merge any new information in newpkg into oldpkg */
  7794. +/* XXX: CLEANUP: This function shouldn't actually modify anything in
  7795. + newpkg, but should leave it usable. This rework is so that
  7796. + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
  7797. +/*
  7798. + * uh, i thought that i had originally written this so that it took
  7799. + * two pkgs and returned a new one? we can do that again... -sma
  7800. + */
  7801. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
  7802. +{
  7803. + if (oldpkg == newpkg) {
  7804. + return 0;
  7805. + }
  7806. +
  7807. + if (!oldpkg->src)
  7808. + oldpkg->src = newpkg->src;
  7809. + if (!oldpkg->dest)
  7810. + oldpkg->dest = newpkg->dest;
  7811. + if (!oldpkg->architecture)
  7812. + oldpkg->architecture = str_dup_safe(newpkg->architecture);
  7813. + if (!oldpkg->arch_priority)
  7814. + oldpkg->arch_priority = newpkg->arch_priority;
  7815. + if (!oldpkg->section)
  7816. + oldpkg->section = str_dup_safe(newpkg->section);
  7817. + if(!oldpkg->maintainer)
  7818. + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
  7819. + if(!oldpkg->description)
  7820. + oldpkg->description = str_dup_safe(newpkg->description);
  7821. + if (set_status) {
  7822. + /* merge the state_flags from the new package */
  7823. + oldpkg->state_want = newpkg->state_want;
  7824. + oldpkg->state_status = newpkg->state_status;
  7825. + oldpkg->state_flag = newpkg->state_flag;
  7826. + } else {
  7827. + if (oldpkg->state_want == SW_UNKNOWN)
  7828. + oldpkg->state_want = newpkg->state_want;
  7829. + if (oldpkg->state_status == SS_NOT_INSTALLED)
  7830. + oldpkg->state_status = newpkg->state_status;
  7831. + oldpkg->state_flag |= newpkg->state_flag;
  7832. + }
  7833. +
  7834. + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
  7835. + oldpkg->depends_str = newpkg->depends_str;
  7836. + newpkg->depends_str = NULL;
  7837. + oldpkg->depends_count = newpkg->depends_count;
  7838. + newpkg->depends_count = 0;
  7839. +
  7840. + oldpkg->depends = newpkg->depends;
  7841. + newpkg->depends = NULL;
  7842. +
  7843. + oldpkg->pre_depends_str = newpkg->pre_depends_str;
  7844. + newpkg->pre_depends_str = NULL;
  7845. + oldpkg->pre_depends_count = newpkg->pre_depends_count;
  7846. + newpkg->pre_depends_count = 0;
  7847. +
  7848. + oldpkg->recommends_str = newpkg->recommends_str;
  7849. + newpkg->recommends_str = NULL;
  7850. + oldpkg->recommends_count = newpkg->recommends_count;
  7851. + newpkg->recommends_count = 0;
  7852. +
  7853. + oldpkg->suggests_str = newpkg->suggests_str;
  7854. + newpkg->suggests_str = NULL;
  7855. + oldpkg->suggests_count = newpkg->suggests_count;
  7856. + newpkg->suggests_count = 0;
  7857. + }
  7858. +
  7859. + if (!oldpkg->provides_str) {
  7860. + oldpkg->provides_str = newpkg->provides_str;
  7861. + newpkg->provides_str = NULL;
  7862. + oldpkg->provides_count = newpkg->provides_count;
  7863. + newpkg->provides_count = 0;
  7864. +
  7865. + oldpkg->provides = newpkg->provides;
  7866. + newpkg->provides = NULL;
  7867. + }
  7868. +
  7869. + if (!oldpkg->conflicts_str) {
  7870. + oldpkg->conflicts_str = newpkg->conflicts_str;
  7871. + newpkg->conflicts_str = NULL;
  7872. + oldpkg->conflicts_count = newpkg->conflicts_count;
  7873. + newpkg->conflicts_count = 0;
  7874. +
  7875. + oldpkg->conflicts = newpkg->conflicts;
  7876. + newpkg->conflicts = NULL;
  7877. + }
  7878. +
  7879. + if (!oldpkg->replaces_str) {
  7880. + oldpkg->replaces_str = newpkg->replaces_str;
  7881. + newpkg->replaces_str = NULL;
  7882. + oldpkg->replaces_count = newpkg->replaces_count;
  7883. + newpkg->replaces_count = 0;
  7884. +
  7885. + oldpkg->replaces = newpkg->replaces;
  7886. + newpkg->replaces = NULL;
  7887. + }
  7888. +
  7889. + if (!oldpkg->filename)
  7890. + oldpkg->filename = str_dup_safe(newpkg->filename);
  7891. + if (0)
  7892. + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
  7893. + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
  7894. + if (!oldpkg->local_filename)
  7895. + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
  7896. + if (!oldpkg->tmp_unpack_dir)
  7897. + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
  7898. + if (!oldpkg->md5sum)
  7899. + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
  7900. + if (!oldpkg->size)
  7901. + oldpkg->size = str_dup_safe(newpkg->size);
  7902. + if (!oldpkg->installed_size)
  7903. + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
  7904. + if (!oldpkg->priority)
  7905. + oldpkg->priority = str_dup_safe(newpkg->priority);
  7906. + if (!oldpkg->source)
  7907. + oldpkg->source = str_dup_safe(newpkg->source);
  7908. + if (oldpkg->conffiles.head == NULL){
  7909. + oldpkg->conffiles = newpkg->conffiles;
  7910. + conffile_list_init(&newpkg->conffiles);
  7911. + }
  7912. + if (!oldpkg->installed_files){
  7913. + oldpkg->installed_files = newpkg->installed_files;
  7914. + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
  7915. + newpkg->installed_files = NULL;
  7916. + }
  7917. + if (!oldpkg->essential)
  7918. + oldpkg->essential = newpkg->essential;
  7919. +
  7920. + return 0;
  7921. +}
  7922. +
  7923. +abstract_pkg_t *abstract_pkg_new(void)
  7924. +{
  7925. + abstract_pkg_t * ab_pkg;
  7926. +
  7927. + ab_pkg = malloc(sizeof(abstract_pkg_t));
  7928. +
  7929. + if (ab_pkg == NULL) {
  7930. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7931. + return NULL;
  7932. + }
  7933. +
  7934. + if ( abstract_pkg_init(ab_pkg) < 0 )
  7935. + return NULL;
  7936. +
  7937. + return ab_pkg;
  7938. +}
  7939. +
  7940. +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
  7941. +{
  7942. + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
  7943. +
  7944. + ab_pkg->provided_by = abstract_pkg_vec_alloc();
  7945. + if (ab_pkg->provided_by==NULL){
  7946. + return -1;
  7947. + }
  7948. + ab_pkg->dependencies_checked = 0;
  7949. + ab_pkg->state_status = SS_NOT_INSTALLED;
  7950. +
  7951. + return 0;
  7952. +}
  7953. +
  7954. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
  7955. + char * temp_str;
  7956. + char **raw =NULL;
  7957. + char **raw_start=NULL;
  7958. +
  7959. + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
  7960. + if (temp_str == NULL ){
  7961. + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
  7962. + return;
  7963. + }
  7964. + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
  7965. +
  7966. + raw = raw_start = read_raw_pkgs_from_file(temp_str);
  7967. + if (raw == NULL ){
  7968. + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
  7969. + return;
  7970. + }
  7971. +
  7972. + while(*raw){
  7973. + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
  7974. + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
  7975. + }
  7976. + }
  7977. + raw = raw_start;
  7978. + while (*raw) {
  7979. + if (raw!=NULL)
  7980. + free(*raw++);
  7981. + }
  7982. +
  7983. + free(raw_start);
  7984. + free(temp_str);
  7985. +
  7986. + return ;
  7987. +
  7988. +}
  7989. +
  7990. +char * pkg_formatted_info(pkg_t *pkg )
  7991. +{
  7992. + char *line;
  7993. + char * buff;
  7994. +
  7995. + buff = malloc(8192);
  7996. + if (buff == NULL) {
  7997. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7998. + return NULL;
  7999. + }
  8000. +
  8001. + buff[0] = '\0';
  8002. +
  8003. + line = pkg_formatted_field(pkg, "Package");
  8004. + strncat(buff ,line, strlen(line));
  8005. + free(line);
  8006. +
  8007. + line = pkg_formatted_field(pkg, "Version");
  8008. + strncat(buff ,line, strlen(line));
  8009. + free(line);
  8010. +
  8011. + line = pkg_formatted_field(pkg, "Depends");
  8012. + strncat(buff ,line, strlen(line));
  8013. + free(line);
  8014. +
  8015. + line = pkg_formatted_field(pkg, "Recommends");
  8016. + strncat(buff ,line, strlen(line));
  8017. + free(line);
  8018. +
  8019. + line = pkg_formatted_field(pkg, "Suggests");
  8020. + strncat(buff ,line, strlen(line));
  8021. + free(line);
  8022. +
  8023. + line = pkg_formatted_field(pkg, "Provides");
  8024. + strncat(buff ,line, strlen(line));
  8025. + free(line);
  8026. +
  8027. + line = pkg_formatted_field(pkg, "Replaces");
  8028. + strncat(buff ,line, strlen(line));
  8029. + free(line);
  8030. +
  8031. + line = pkg_formatted_field(pkg, "Conflicts");
  8032. + strncat(buff ,line, strlen(line));
  8033. + free(line);
  8034. +
  8035. + line = pkg_formatted_field(pkg, "Status");
  8036. + strncat(buff ,line, strlen(line));
  8037. + free(line);
  8038. +
  8039. + line = pkg_formatted_field(pkg, "Section");
  8040. + strncat(buff ,line, strlen(line));
  8041. + free(line);
  8042. +
  8043. + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
  8044. + strncat(buff ,line, strlen(line));
  8045. + free(line);
  8046. +
  8047. + line = pkg_formatted_field(pkg, "Architecture");
  8048. + strncat(buff ,line, strlen(line));
  8049. + free(line);
  8050. +
  8051. + line = pkg_formatted_field(pkg, "Maintainer");
  8052. + strncat(buff ,line, strlen(line));
  8053. + free(line);
  8054. +
  8055. + line = pkg_formatted_field(pkg, "MD5sum");
  8056. + strncat(buff ,line, strlen(line));
  8057. + free(line);
  8058. +
  8059. + line = pkg_formatted_field(pkg, "Size");
  8060. + strncat(buff ,line, strlen(line));
  8061. + free(line);
  8062. +
  8063. + line = pkg_formatted_field(pkg, "Filename");
  8064. + strncat(buff ,line, strlen(line));
  8065. + free(line);
  8066. +
  8067. + line = pkg_formatted_field(pkg, "Conffiles");
  8068. + strncat(buff ,line, strlen(line));
  8069. + free(line);
  8070. +
  8071. + line = pkg_formatted_field(pkg, "Source");
  8072. + strncat(buff ,line, strlen(line));
  8073. + free(line);
  8074. +
  8075. + line = pkg_formatted_field(pkg, "Description");
  8076. + strncat(buff ,line, strlen(line));
  8077. + free(line);
  8078. +
  8079. + line = pkg_formatted_field(pkg, "Installed-Time");
  8080. + strncat(buff ,line, strlen(line));
  8081. + free(line);
  8082. +
  8083. + return buff;
  8084. +}
  8085. +
  8086. +char * pkg_formatted_field(pkg_t *pkg, const char *field )
  8087. +{
  8088. + static size_t LINE_LEN = 128;
  8089. + char * temp = (char *)malloc(1);
  8090. + int len = 0;
  8091. + int flag_provide_false = 0;
  8092. +
  8093. +/*
  8094. + Pigi: After some discussion with Florian we decided to modify the full procedure in
  8095. + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
  8096. +*/
  8097. +
  8098. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8099. + goto UNKNOWN_FMT_FIELD;
  8100. + }
  8101. +
  8102. + temp[0]='\0';
  8103. +
  8104. + switch (field[0])
  8105. + {
  8106. + case 'a':
  8107. + case 'A':
  8108. + if (strcasecmp(field, "Architecture") == 0) {
  8109. + /* Architecture */
  8110. + if (pkg->architecture) {
  8111. + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
  8112. + if ( temp == NULL ){
  8113. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8114. + return NULL;
  8115. + }
  8116. + temp[0]='\0';
  8117. + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
  8118. + }
  8119. + } else {
  8120. + goto UNKNOWN_FMT_FIELD;
  8121. + }
  8122. + break;
  8123. + case 'c':
  8124. + case 'C':
  8125. + if (strcasecmp(field, "Conffiles") == 0) {
  8126. + /* Conffiles */
  8127. + conffile_list_elt_t *iter;
  8128. + char confstr_[LINE_LEN];
  8129. +
  8130. + if (pkg->conffiles.head == NULL) {
  8131. + return temp;
  8132. + }
  8133. +
  8134. + len = 14 ;
  8135. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8136. + if (iter->data->name && iter->data->value) {
  8137. + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
  8138. + }
  8139. + }
  8140. + temp = (char *)realloc(temp,len);
  8141. + if ( temp == NULL ){
  8142. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8143. + return NULL;
  8144. + }
  8145. + temp[0]='\0';
  8146. + strncpy(temp, "Conffiles:\n", 12);
  8147. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8148. + if (iter->data->name && iter->data->value) {
  8149. + snprintf(confstr_, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
  8150. + strncat(temp, confstr_, strlen(confstr_));
  8151. + }
  8152. + }
  8153. + } else if (strcasecmp(field, "Conflicts") == 0) {
  8154. + int i;
  8155. +
  8156. + if (pkg->conflicts_count) {
  8157. + char conflictstr[LINE_LEN];
  8158. + len = 14 ;
  8159. + for(i = 0; i < pkg->conflicts_count; i++) {
  8160. + len = len + (strlen(pkg->conflicts_str[i])+5);
  8161. + }
  8162. + temp = (char *)realloc(temp,len);
  8163. + if ( temp == NULL ){
  8164. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8165. + return NULL;
  8166. + }
  8167. + temp[0]='\0';
  8168. + strncpy(temp, "Conflicts:", 11);
  8169. + for(i = 0; i < pkg->conflicts_count; i++) {
  8170. + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
  8171. + strncat(temp, conflictstr, strlen(conflictstr));
  8172. + }
  8173. + strncat(temp, "\n", strlen("\n"));
  8174. + }
  8175. + } else {
  8176. + goto UNKNOWN_FMT_FIELD;
  8177. + }
  8178. + break;
  8179. + case 'd':
  8180. + case 'D':
  8181. + if (strcasecmp(field, "Depends") == 0) {
  8182. + /* Depends */
  8183. + int i;
  8184. +
  8185. + if (pkg->depends_count) {
  8186. + char depstr[LINE_LEN];
  8187. + len = 14 ;
  8188. + for(i = 0; i < pkg->depends_count; i++) {
  8189. + len = len + (strlen(pkg->depends_str[i])+4);
  8190. + }
  8191. + temp = (char *)realloc(temp,len);
  8192. + if ( temp == NULL ){
  8193. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8194. + return NULL;
  8195. + }
  8196. + temp[0]='\0';
  8197. + strncpy(temp, "Depends:", 10);
  8198. + for(i = 0; i < pkg->depends_count; i++) {
  8199. + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
  8200. + strncat(temp, depstr, strlen(depstr));
  8201. + }
  8202. + strncat(temp, "\n", strlen("\n"));
  8203. + }
  8204. + } else if (strcasecmp(field, "Description") == 0) {
  8205. + /* Description */
  8206. + if (pkg->description) {
  8207. + temp = (char *)realloc(temp,strlen(pkg->description)+16);
  8208. + if ( temp == NULL ){
  8209. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8210. + return NULL;
  8211. + }
  8212. + temp[0]='\0';
  8213. + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
  8214. + }
  8215. + } else {
  8216. + goto UNKNOWN_FMT_FIELD;
  8217. + }
  8218. + break;
  8219. + case 'e':
  8220. + case 'E': {
  8221. + /* Essential */
  8222. + if (pkg->essential) {
  8223. + temp = (char *)realloc(temp,16);
  8224. + if ( temp == NULL ){
  8225. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8226. + return NULL;
  8227. + }
  8228. + temp[0]='\0';
  8229. + snprintf(temp, (16), "Essential: yes\n");
  8230. + }
  8231. + }
  8232. + break;
  8233. + case 'f':
  8234. + case 'F': {
  8235. + /* Filename */
  8236. + if (pkg->filename) {
  8237. + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
  8238. + if ( temp == NULL ){
  8239. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8240. + return NULL;
  8241. + }
  8242. + temp[0]='\0';
  8243. + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
  8244. + }
  8245. + }
  8246. + break;
  8247. + case 'i':
  8248. + case 'I': {
  8249. + if (strcasecmp(field, "Installed-Size") == 0) {
  8250. + /* Installed-Size */
  8251. + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
  8252. + if ( temp == NULL ){
  8253. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8254. + return NULL;
  8255. + }
  8256. + temp[0]='\0';
  8257. + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
  8258. + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
  8259. + temp = (char *)realloc(temp,29);
  8260. + if ( temp == NULL ){
  8261. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8262. + return NULL;
  8263. + }
  8264. + temp[0]='\0';
  8265. + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
  8266. + }
  8267. + }
  8268. + break;
  8269. + case 'm':
  8270. + case 'M': {
  8271. + /* Maintainer | MD5sum */
  8272. + if (strcasecmp(field, "Maintainer") == 0) {
  8273. + /* Maintainer */
  8274. + if (pkg->maintainer) {
  8275. + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
  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->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
  8282. + }
  8283. + } else if (strcasecmp(field, "MD5sum") == 0) {
  8284. + /* MD5sum */
  8285. + if (pkg->md5sum) {
  8286. + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
  8287. + if ( temp == NULL ){
  8288. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8289. + return NULL;
  8290. + }
  8291. + temp[0]='\0';
  8292. + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
  8293. + }
  8294. + } else {
  8295. + goto UNKNOWN_FMT_FIELD;
  8296. + }
  8297. + }
  8298. + break;
  8299. + case 'p':
  8300. + case 'P': {
  8301. + if (strcasecmp(field, "Package") == 0) {
  8302. + /* Package */
  8303. + temp = (char *)realloc(temp,strlen(pkg->name)+11);
  8304. + if ( temp == NULL ){
  8305. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8306. + return NULL;
  8307. + }
  8308. + temp[0]='\0';
  8309. + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
  8310. + } else if (strcasecmp(field, "Priority") == 0) {
  8311. + /* Priority */
  8312. + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
  8313. + if ( temp == NULL ){
  8314. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8315. + return NULL;
  8316. + }
  8317. + temp[0]='\0';
  8318. + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
  8319. + } else if (strcasecmp(field, "Provides") == 0) {
  8320. + /* Provides */
  8321. + int i;
  8322. +
  8323. + if (pkg->provides_count) {
  8324. + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
  8325. + for ( i=0; i < pkg->provides_count; i++ ){
  8326. + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
  8327. + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
  8328. + flag_provide_false = 1;
  8329. + }
  8330. + }
  8331. + if ( !flag_provide_false || /* Pigi there is not my trick flag */
  8332. + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
  8333. + char provstr[LINE_LEN];
  8334. + len = 15;
  8335. + for(i = 0; i < pkg->provides_count; i++) {
  8336. + len = len + (strlen(pkg->provides_str[i])+5);
  8337. + }
  8338. + temp = (char *)realloc(temp,len);
  8339. + if ( temp == NULL ){
  8340. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8341. + return NULL;
  8342. + }
  8343. + temp[0]='\0';
  8344. + strncpy(temp, "Provides:", 12);
  8345. + for(i = 0; i < pkg->provides_count; i++) {
  8346. + if (strlen(pkg->provides_str[i])>0){;
  8347. + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
  8348. + strncat(temp, provstr, strlen(provstr));
  8349. + }
  8350. + }
  8351. + strncat(temp, "\n", strlen("\n"));
  8352. + }
  8353. + }
  8354. + } else {
  8355. + goto UNKNOWN_FMT_FIELD;
  8356. + }
  8357. + }
  8358. + break;
  8359. + case 'r':
  8360. + case 'R': {
  8361. + int i;
  8362. + /* Replaces | Recommends*/
  8363. + if (strcasecmp (field, "Replaces") == 0) {
  8364. + if (pkg->replaces_count) {
  8365. + char replstr[LINE_LEN];
  8366. + len = 14;
  8367. + for (i = 0; i < pkg->replaces_count; i++) {
  8368. + len = len + (strlen(pkg->replaces_str[i])+5);
  8369. + }
  8370. + temp = (char *)realloc(temp,len);
  8371. + if ( temp == NULL ){
  8372. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8373. + return NULL;
  8374. + }
  8375. + temp[0]='\0';
  8376. + strncpy(temp, "Replaces:", 12);
  8377. + for (i = 0; i < pkg->replaces_count; i++) {
  8378. + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
  8379. + strncat(temp, replstr, strlen(replstr));
  8380. + }
  8381. + strncat(temp, "\n", strlen("\n"));
  8382. + }
  8383. + } else if (strcasecmp (field, "Recommends") == 0) {
  8384. + if (pkg->recommends_count) {
  8385. + char recstr[LINE_LEN];
  8386. + len = 15;
  8387. + for(i = 0; i < pkg->recommends_count; i++) {
  8388. + len = len + (strlen( pkg->recommends_str[i])+5);
  8389. + }
  8390. + temp = (char *)realloc(temp,len);
  8391. + if ( temp == NULL ){
  8392. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8393. + return NULL;
  8394. + }
  8395. + temp[0]='\0';
  8396. + strncpy(temp, "Recommends:", 13);
  8397. + for(i = 0; i < pkg->recommends_count; i++) {
  8398. + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
  8399. + strncat(temp, recstr, strlen(recstr));
  8400. + }
  8401. + strncat(temp, "\n", strlen("\n"));
  8402. + }
  8403. + } else {
  8404. + goto UNKNOWN_FMT_FIELD;
  8405. + }
  8406. + }
  8407. + break;
  8408. + case 's':
  8409. + case 'S': {
  8410. + /* Section | Size | Source | Status | Suggests */
  8411. + if (strcasecmp(field, "Section") == 0) {
  8412. + /* Section */
  8413. + if (pkg->section) {
  8414. + temp = (char *)realloc(temp,strlen(pkg->section)+11);
  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->section)+11), "Section: %s\n", pkg->section);
  8421. + }
  8422. + } else if (strcasecmp(field, "Size") == 0) {
  8423. + /* Size */
  8424. + if (pkg->size) {
  8425. + temp = (char *)realloc(temp,strlen(pkg->size)+8);
  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->size)+8), "Size: %s\n", pkg->size);
  8432. + }
  8433. + } else if (strcasecmp(field, "Source") == 0) {
  8434. + /* Source */
  8435. + if (pkg->source) {
  8436. + temp = (char *)realloc(temp,strlen(pkg->source)+10);
  8437. + if ( temp == NULL ){
  8438. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8439. + return NULL;
  8440. + }
  8441. + temp[0]='\0';
  8442. + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
  8443. + }
  8444. + } else if (strcasecmp(field, "Status") == 0) {
  8445. + /* Status */
  8446. + /* Benjamin Pineau note: we should avoid direct usage of
  8447. + * strlen(arg) without keeping "arg" for later free()
  8448. + */
  8449. + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
  8450. + char *pstat=pkg_state_status_to_str(pkg->state_status);
  8451. + char *pwant=pkg_state_want_to_str(pkg->state_want);
  8452. +
  8453. + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
  8454. + temp = (char *)realloc(temp,sum_of_sizes);
  8455. + if ( temp == NULL ){
  8456. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8457. + return NULL;
  8458. + }
  8459. + temp[0]='\0';
  8460. + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
  8461. + free(pflag);
  8462. + free(pwant);
  8463. + if(pstat) /* pfstat can be NULL if ENOMEM */
  8464. + free(pstat);
  8465. + } else if (strcasecmp(field, "Suggests") == 0) {
  8466. + if (pkg->suggests_count) {
  8467. + int i;
  8468. + char sugstr[LINE_LEN];
  8469. + len = 13;
  8470. + for(i = 0; i < pkg->suggests_count; i++) {
  8471. + len = len + (strlen(pkg->suggests_str[i])+5);
  8472. + }
  8473. + temp = (char *)realloc(temp,len);
  8474. + if ( temp == NULL ){
  8475. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8476. + return NULL;
  8477. + }
  8478. + temp[0]='\0';
  8479. + strncpy(temp, "Suggests:", 10);
  8480. + for(i = 0; i < pkg->suggests_count; i++) {
  8481. + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
  8482. + strncat(temp, sugstr, strlen(sugstr));
  8483. + }
  8484. + strncat(temp, "\n", strlen("\n"));
  8485. + }
  8486. + } else {
  8487. + goto UNKNOWN_FMT_FIELD;
  8488. + }
  8489. + }
  8490. + break;
  8491. + case 'v':
  8492. + case 'V': {
  8493. + /* Version */
  8494. + char *version = pkg_version_str_alloc(pkg);
  8495. + temp = (char *)realloc(temp,strlen(version)+14);
  8496. + if ( temp == NULL ){
  8497. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8498. + return NULL;
  8499. + }
  8500. + temp[0]='\0';
  8501. + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
  8502. + free(version);
  8503. + }
  8504. + break;
  8505. + default:
  8506. + goto UNKNOWN_FMT_FIELD;
  8507. + }
  8508. +
  8509. + if ( strlen(temp)<2 ) {
  8510. + temp[0]='\0';
  8511. + }
  8512. + return temp;
  8513. +
  8514. + UNKNOWN_FMT_FIELD:
  8515. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
  8516. + if ( strlen(temp)<2 ) {
  8517. + temp[0]='\0';
  8518. + }
  8519. +
  8520. + return temp;
  8521. +}
  8522. +
  8523. +void pkg_print_info(pkg_t *pkg, FILE *file)
  8524. +{
  8525. + char * buff;
  8526. + if (pkg == NULL) {
  8527. + return;
  8528. + }
  8529. +
  8530. + buff = pkg_formatted_info(pkg);
  8531. + if ( buff == NULL )
  8532. + return;
  8533. + if (strlen(buff)>2){
  8534. + fwrite(buff, 1, strlen(buff), file);
  8535. + }
  8536. + free(buff);
  8537. +}
  8538. +
  8539. +void pkg_print_status(pkg_t * pkg, FILE * file)
  8540. +{
  8541. + if (pkg == NULL) {
  8542. + return;
  8543. + }
  8544. +
  8545. + /* XXX: QUESTION: Do we actually want more fields here? The
  8546. + original idea was to save space by installing only what was
  8547. + needed for actual computation, (package, version, status,
  8548. + essential, conffiles). The assumption is that all other fields
  8549. + can be found in th available file.
  8550. +
  8551. + But, someone proposed the idea to make it possible to
  8552. + reconstruct a .ipk from an installed package, (ie. for beaming
  8553. + from one handheld to another). So, maybe we actually want a few
  8554. + more fields here, (depends, suggests, etc.), so that that would
  8555. + be guaranteed to work even in the absence of more information
  8556. + from the available file.
  8557. +
  8558. + 28-MAR-03: kergoth and I discussed this yesterday. We think
  8559. + the essential info needs to be here for all installed packages
  8560. + because they may not appear in the Packages files on various
  8561. + feeds. Furthermore, one should be able to install from URL or
  8562. + local storage without requiring a Packages file from any feed.
  8563. + -Jamey
  8564. + */
  8565. + pkg_print_field(pkg, file, "Package");
  8566. + pkg_print_field(pkg, file, "Version");
  8567. + pkg_print_field(pkg, file, "Depends");
  8568. + pkg_print_field(pkg, file, "Recommends");
  8569. + pkg_print_field(pkg, file, "Suggests");
  8570. + pkg_print_field(pkg, file, "Provides");
  8571. + pkg_print_field(pkg, file, "Replaces");
  8572. + pkg_print_field(pkg, file, "Conflicts");
  8573. + pkg_print_field(pkg, file, "Status");
  8574. + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
  8575. + pkg_print_field(pkg, file, "Architecture");
  8576. + pkg_print_field(pkg, file, "Conffiles");
  8577. + pkg_print_field(pkg, file, "Installed-Time");
  8578. + fputs("\n", file);
  8579. +}
  8580. +
  8581. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
  8582. +{
  8583. + char *buff;
  8584. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8585. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
  8586. + __FUNCTION__, field);
  8587. + }
  8588. + buff = pkg_formatted_field(pkg, field);
  8589. + if (strlen(buff)>2) {
  8590. + fprintf(file, "%s", buff);
  8591. + fflush(file);
  8592. + }
  8593. + free(buff);
  8594. + return;
  8595. +}
  8596. +
  8597. +/*
  8598. + * libdpkg - Debian packaging suite library routines
  8599. + * vercmp.c - comparison of version numbers
  8600. + *
  8601. + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  8602. + */
  8603. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
  8604. +{
  8605. + int r;
  8606. +
  8607. + if (pkg->epoch > ref_pkg->epoch) {
  8608. + return 1;
  8609. + }
  8610. +
  8611. + if (pkg->epoch < ref_pkg->epoch) {
  8612. + return -1;
  8613. + }
  8614. +
  8615. + r = verrevcmp(pkg->version, ref_pkg->version);
  8616. + if (r) {
  8617. + return r;
  8618. + }
  8619. +
  8620. +#ifdef USE_DEBVERSION
  8621. + r = verrevcmp(pkg->revision, ref_pkg->revision);
  8622. + if (r) {
  8623. + return r;
  8624. + }
  8625. +
  8626. + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
  8627. +#endif
  8628. +
  8629. + return r;
  8630. +}
  8631. +
  8632. +int verrevcmp(const char *val, const char *ref)
  8633. +{
  8634. + int vc, rc;
  8635. + long vl, rl;
  8636. + const char *vp, *rp;
  8637. + const char *vsep, *rsep;
  8638. +
  8639. + if (!val) val= "";
  8640. + if (!ref) ref= "";
  8641. + for (;;) {
  8642. + vp= val; while (*vp && !isdigit(*vp)) vp++;
  8643. + rp= ref; while (*rp && !isdigit(*rp)) rp++;
  8644. + for (;;) {
  8645. + vc= (val == vp) ? 0 : *val++;
  8646. + rc= (ref == rp) ? 0 : *ref++;
  8647. + if (!rc && !vc) break;
  8648. + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
  8649. + if (rc && !isalpha(rc)) rc += 256;
  8650. + if (vc != rc) return vc - rc;
  8651. + }
  8652. + val= vp;
  8653. + ref= rp;
  8654. + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
  8655. + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
  8656. + if (vl != rl) return vl - rl;
  8657. +
  8658. + vc = *val;
  8659. + rc = *ref;
  8660. + vsep = strchr(".-", vc);
  8661. + rsep = strchr(".-", rc);
  8662. + if (vsep && !rsep) return -1;
  8663. + if (!vsep && rsep) return +1;
  8664. +
  8665. + if (!*val && !*ref) return 0;
  8666. + if (!*val) return -1;
  8667. + if (!*ref) return +1;
  8668. + }
  8669. +}
  8670. +
  8671. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
  8672. +{
  8673. + int r;
  8674. +
  8675. + r = pkg_compare_versions(it, ref);
  8676. +
  8677. + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
  8678. + return r <= 0;
  8679. + }
  8680. +
  8681. + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
  8682. + return r >= 0;
  8683. + }
  8684. +
  8685. + if (strcmp(op, "<<") == 0) {
  8686. + return r < 0;
  8687. + }
  8688. +
  8689. + if (strcmp(op, ">>") == 0) {
  8690. + return r > 0;
  8691. + }
  8692. +
  8693. + if (strcmp(op, "=") == 0) {
  8694. + return r == 0;
  8695. + }
  8696. +
  8697. + fprintf(stderr, "unknown operator: %s", op);
  8698. + return 0;
  8699. +}
  8700. +
  8701. +int pkg_name_version_and_architecture_compare(pkg_t *p1, pkg_t *p2)
  8702. +{
  8703. + const pkg_t *a = *(const pkg_t **)p1;
  8704. + const pkg_t *b = *(const pkg_t **)p2;
  8705. + int namecmp;
  8706. + int vercmp;
  8707. + if (!a->name || !b->name) {
  8708. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8709. + a, a->name, b, b->name);
  8710. + return 0;
  8711. + }
  8712. +
  8713. + namecmp = strcmp(a->name, b->name);
  8714. + if (namecmp)
  8715. + return namecmp;
  8716. + vercmp = pkg_compare_versions(a, b);
  8717. + if (vercmp)
  8718. + return vercmp;
  8719. + if (!a->arch_priority || !b->arch_priority) {
  8720. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
  8721. + a, a->arch_priority, b, b->arch_priority);
  8722. + return 0;
  8723. + }
  8724. + if (a->arch_priority > b->arch_priority)
  8725. + return 1;
  8726. + if (a->arch_priority < b->arch_priority)
  8727. + return -1;
  8728. + return 0;
  8729. +}
  8730. +
  8731. +int abstract_pkg_name_compare(abstract_pkg_t *p1, abstract_pkg_t *p2)
  8732. +{
  8733. + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
  8734. + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
  8735. + if (!a->name || !b->name) {
  8736. + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8737. + a, a->name, b, b->name);
  8738. + return 0;
  8739. + }
  8740. + return strcmp(a->name, b->name);
  8741. +}
  8742. +
  8743. +
  8744. +char *pkg_version_str_alloc(pkg_t *pkg)
  8745. +{
  8746. + char *complete_version;
  8747. + char *epoch_str;
  8748. +#ifdef USE_DEBVERSION
  8749. + char *revision_str;
  8750. + char *familiar_revision_str;
  8751. +#endif
  8752. +
  8753. + if (pkg->epoch) {
  8754. + sprintf_alloc(&epoch_str, "%lu:", (unsigned long)pkg->epoch);
  8755. + } else {
  8756. + epoch_str = strdup("");
  8757. + }
  8758. +
  8759. +#ifdef USE_DEBVERSION
  8760. + if (pkg->revision && strlen(pkg->revision)) {
  8761. + sprintf_alloc(&revision_str, "-%s", pkg->revision);
  8762. + } else {
  8763. + revision_str = strdup("");
  8764. + }
  8765. +
  8766. + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
  8767. + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
  8768. + } else {
  8769. + familiar_revision_str = strdup("");
  8770. + }
  8771. +#endif
  8772. +
  8773. +#ifdef USE_DEBVERSION
  8774. + sprintf_alloc(&complete_version, "%s%s%s%s",
  8775. + epoch_str, pkg->version, revision_str, familiar_revision_str);
  8776. +#else
  8777. + sprintf_alloc(&complete_version, "%s%s",
  8778. + epoch_str, pkg->version);
  8779. +#endif
  8780. +
  8781. + free(epoch_str);
  8782. +#ifdef USE_DEBVERSION
  8783. + free(revision_str);
  8784. + free(familiar_revision_str);
  8785. +#endif
  8786. +
  8787. + return complete_version;
  8788. +}
  8789. +
  8790. +str_list_t *pkg_get_installed_files(pkg_t *pkg)
  8791. +{
  8792. + int err;
  8793. + char *list_file_name = NULL;
  8794. + FILE *list_file = NULL;
  8795. + char *line;
  8796. + char *installed_file_name;
  8797. + int rootdirlen;
  8798. +
  8799. + pkg->installed_files_ref_cnt++;
  8800. +
  8801. + if (pkg->installed_files) {
  8802. + return pkg->installed_files;
  8803. + }
  8804. +
  8805. + pkg->installed_files = str_list_alloc();
  8806. + if (pkg->installed_files == NULL) {
  8807. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8808. + return NULL;
  8809. + }
  8810. +
  8811. + /* For uninstalled packages, get the file list firectly from the package.
  8812. + For installed packages, look at the package.list file in the database.
  8813. + */
  8814. + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
  8815. + if (pkg->local_filename == NULL) {
  8816. + return pkg->installed_files;
  8817. + }
  8818. + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
  8819. + file. In other words, change deb_extract so that it can
  8820. + simply return the file list as a char *[] rather than
  8821. + insisting on writing in to a FILE * as it does now. */
  8822. + list_file = tmpfile();
  8823. + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
  8824. + if (err) {
  8825. + fclose(list_file);
  8826. + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
  8827. + __FUNCTION__, pkg->local_filename, strerror(err));
  8828. + return pkg->installed_files;
  8829. + }
  8830. + rewind(list_file);
  8831. + } else {
  8832. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8833. + pkg->dest->info_dir, pkg->name);
  8834. + if (! file_exists(list_file_name)) {
  8835. + free(list_file_name);
  8836. + return pkg->installed_files;
  8837. + }
  8838. +
  8839. + list_file = fopen(list_file_name, "r");
  8840. + if (list_file == NULL) {
  8841. + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
  8842. + list_file_name, strerror(errno));
  8843. + free(list_file_name);
  8844. + return pkg->installed_files;
  8845. + }
  8846. + free(list_file_name);
  8847. + }
  8848. +
  8849. + rootdirlen = strlen( pkg->dest->root_dir );
  8850. + while (1) {
  8851. + char *file_name;
  8852. +
  8853. + line = file_read_line_alloc(list_file);
  8854. + if (line == NULL) {
  8855. + break;
  8856. + }
  8857. + str_chomp(line);
  8858. + file_name = line;
  8859. +
  8860. + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
  8861. + if( strncmp( pkg->dest->root_dir,
  8862. + file_name,
  8863. + rootdirlen ) ) {
  8864. + if (*file_name == '.') {
  8865. + file_name++;
  8866. + }
  8867. + if (*file_name == '/') {
  8868. + file_name++;
  8869. + }
  8870. +
  8871. + /* Freed in pkg_free_installed_files */
  8872. + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
  8873. + } else {
  8874. + // already contains root_dir as header -> ABSOLUTE
  8875. + sprintf_alloc(&installed_file_name, "%s", file_name);
  8876. + }
  8877. + str_list_append(pkg->installed_files, installed_file_name);
  8878. + free(line);
  8879. + }
  8880. +
  8881. + fclose(list_file);
  8882. +
  8883. + return pkg->installed_files;
  8884. +}
  8885. +
  8886. +/* XXX: CLEANUP: This function and it's counterpart,
  8887. + (pkg_get_installed_files), do not match our init/deinit naming
  8888. + convention. Nor the alloc/free convention. But, then again, neither
  8889. + of these conventions currrently fit the way these two functions
  8890. + work. */
  8891. +int pkg_free_installed_files(pkg_t *pkg)
  8892. +{
  8893. + str_list_elt_t *iter;
  8894. +
  8895. + pkg->installed_files_ref_cnt--;
  8896. + if (pkg->installed_files_ref_cnt > 0) {
  8897. + return 0;
  8898. + }
  8899. +
  8900. + if (pkg->installed_files) {
  8901. +
  8902. + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
  8903. + /* malloced in pkg_get_installed_files */
  8904. + free (iter->data);
  8905. + iter->data = NULL;
  8906. + }
  8907. +
  8908. + str_list_deinit(pkg->installed_files);
  8909. + }
  8910. +
  8911. + pkg->installed_files = NULL;
  8912. +
  8913. + return 0;
  8914. +}
  8915. +
  8916. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
  8917. +{
  8918. + int err;
  8919. + char *list_file_name;
  8920. +
  8921. + //I don't think pkg_free_installed_files should be called here. Jamey
  8922. + //pkg_free_installed_files(pkg);
  8923. +
  8924. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8925. + pkg->dest->info_dir, pkg->name);
  8926. + if (!conf->noaction) {
  8927. + err = unlink(list_file_name);
  8928. + free(list_file_name);
  8929. +
  8930. + if (err) {
  8931. + return errno;
  8932. + }
  8933. + }
  8934. + return 0;
  8935. +}
  8936. +
  8937. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
  8938. +{
  8939. + conffile_list_elt_t *iter;
  8940. + conffile_t *conffile;
  8941. +
  8942. + if (pkg == NULL) {
  8943. + return NULL;
  8944. + }
  8945. +
  8946. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8947. + conffile = iter->data;
  8948. +
  8949. + if (strcmp(conffile->name, file_name) == 0) {
  8950. + return conffile;
  8951. + }
  8952. + }
  8953. +
  8954. + return NULL;
  8955. +}
  8956. +
  8957. +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
  8958. + const char *script, const char *args)
  8959. +{
  8960. + int err;
  8961. + char *path;
  8962. + char *cmd;
  8963. +
  8964. + /* XXX: FEATURE: When conf->offline_root is set, we should run the
  8965. + maintainer script within a chroot environment. */
  8966. +
  8967. + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
  8968. + have scripts in pkg->tmp_unpack_dir. */
  8969. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  8970. + if (pkg->dest == NULL) {
  8971. + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
  8972. + __FUNCTION__, pkg->name);
  8973. + return EINVAL;
  8974. + }
  8975. + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
  8976. + } else {
  8977. + if (pkg->tmp_unpack_dir == NULL) {
  8978. + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
  8979. + __FUNCTION__, pkg->name);
  8980. + return EINVAL;
  8981. + }
  8982. + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
  8983. + }
  8984. +
  8985. + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
  8986. + if (conf->noaction) return 0;
  8987. +
  8988. + /* XXX: CLEANUP: There must be a better way to handle maintainer
  8989. + scripts when running with offline_root mode and/or a dest other
  8990. + than '/'. I've been playing around with some clever chroot
  8991. + tricks and I might come up with something workable. */
  8992. + if (conf->offline_root) {
  8993. + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
  8994. + }
  8995. +
  8996. + setenv("PKG_ROOT",
  8997. + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
  8998. +
  8999. + if (! file_exists(path)) {
  9000. + free(path);
  9001. + return 0;
  9002. + }
  9003. +
  9004. + if (conf->offline_root) {
  9005. + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
  9006. + free(path);
  9007. + return 0;
  9008. + }
  9009. +
  9010. + sprintf_alloc(&cmd, "%s %s", path, args);
  9011. + free(path);
  9012. +
  9013. + err = xsystem(cmd);
  9014. + free(cmd);
  9015. +
  9016. + if (err) {
  9017. + fprintf(stderr, "%s script returned status %d\n", script, err);
  9018. + return err;
  9019. + }
  9020. +
  9021. + return 0;
  9022. +}
  9023. +
  9024. +char *pkg_state_want_to_str(pkg_state_want_t sw)
  9025. +{
  9026. + int i;
  9027. +
  9028. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9029. + if (pkg_state_want_map[i].value == sw) {
  9030. + return strdup(pkg_state_want_map[i].str);
  9031. + }
  9032. + }
  9033. +
  9034. + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
  9035. + __FUNCTION__, sw);
  9036. + return strdup("<STATE_WANT_UNKNOWN>");
  9037. +}
  9038. +
  9039. +pkg_state_want_t pkg_state_want_from_str(char *str)
  9040. +{
  9041. + int i;
  9042. +
  9043. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9044. + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
  9045. + return pkg_state_want_map[i].value;
  9046. + }
  9047. + }
  9048. +
  9049. + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
  9050. + __FUNCTION__, str);
  9051. + return SW_UNKNOWN;
  9052. +}
  9053. +
  9054. +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
  9055. +{
  9056. + int i;
  9057. + int len = 3; /* ok\000 is minimum */
  9058. + char *str = NULL;
  9059. +
  9060. + /* clear the temporary flags before converting to string */
  9061. + sf &= SF_NONVOLATILE_FLAGS;
  9062. +
  9063. + if (sf == 0) {
  9064. + return strdup("ok");
  9065. + } else {
  9066. +
  9067. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9068. + if (sf & pkg_state_flag_map[i].value) {
  9069. + len += strlen(pkg_state_flag_map[i].str) + 1;
  9070. + }
  9071. + }
  9072. + str = malloc(len);
  9073. + if ( str == NULL ) {
  9074. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9075. + return NULL;
  9076. + }
  9077. + str[0] = 0;
  9078. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9079. + if (sf & pkg_state_flag_map[i].value) {
  9080. + strcat(str, pkg_state_flag_map[i].str);
  9081. + strcat(str, ",");
  9082. + }
  9083. + }
  9084. + len = strlen(str);
  9085. + str[len-1] = 0; /* squash last comma */
  9086. + return str;
  9087. + }
  9088. +}
  9089. +
  9090. +pkg_state_flag_t pkg_state_flag_from_str(char *str)
  9091. +{
  9092. + int i;
  9093. + int sf = SF_OK;
  9094. +
  9095. + if (strcmp(str, "ok") == 0) {
  9096. + return SF_OK;
  9097. + }
  9098. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9099. + const char *sfname = pkg_state_flag_map[i].str;
  9100. + int sfname_len = strlen(sfname);
  9101. + if (strncmp(str, sfname, sfname_len) == 0) {
  9102. + sf |= pkg_state_flag_map[i].value;
  9103. + str += sfname_len;
  9104. + if (str[0] == ',') {
  9105. + str++;
  9106. + } else {
  9107. + break;
  9108. + }
  9109. + }
  9110. + }
  9111. +
  9112. + return sf;
  9113. +}
  9114. +
  9115. +char *pkg_state_status_to_str(pkg_state_status_t ss)
  9116. +{
  9117. + int i;
  9118. +
  9119. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9120. + if (pkg_state_status_map[i].value == ss) {
  9121. + return strdup(pkg_state_status_map[i].str);
  9122. + }
  9123. + }
  9124. +
  9125. + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
  9126. + __FUNCTION__, ss);
  9127. + return strdup("<STATE_STATUS_UNKNOWN>");
  9128. +}
  9129. +
  9130. +pkg_state_status_t pkg_state_status_from_str(char *str)
  9131. +{
  9132. + int i;
  9133. +
  9134. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9135. + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
  9136. + return pkg_state_status_map[i].value;
  9137. + }
  9138. + }
  9139. +
  9140. + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
  9141. + __FUNCTION__, str);
  9142. + return SS_NOT_INSTALLED;
  9143. +}
  9144. +
  9145. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
  9146. +{
  9147. + nv_pair_list_elt_t *l;
  9148. +
  9149. + if (!pkg->architecture)
  9150. + return 1;
  9151. +
  9152. + l = conf->arch_list.head;
  9153. +
  9154. + while (l) {
  9155. + nv_pair_t *nv = l->data;
  9156. + if (strcmp(nv->name, pkg->architecture) == 0) {
  9157. + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
  9158. + return 1;
  9159. + }
  9160. + l = l->next;
  9161. + }
  9162. +
  9163. + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
  9164. + return 0;
  9165. +}
  9166. +
  9167. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
  9168. +{
  9169. + nv_pair_list_elt_t *l;
  9170. +
  9171. + l = conf->arch_list.head;
  9172. +
  9173. + while (l) {
  9174. + nv_pair_t *nv = l->data;
  9175. + if (strcmp(nv->name, archname) == 0) {
  9176. + int priority = strtol(nv->value, NULL, 0);
  9177. + return priority;
  9178. + }
  9179. + l = l->next;
  9180. + }
  9181. + return 0;
  9182. +}
  9183. +
  9184. +int pkg_info_preinstall_check(ipkg_conf_t *conf)
  9185. +{
  9186. + int i;
  9187. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9188. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  9189. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9190. +
  9191. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
  9192. + pkg_hash_fetch_available(pkg_hash, available_pkgs);
  9193. + /* update arch_priority for each package */
  9194. + for (i = 0; i < available_pkgs->len; i++) {
  9195. + pkg_t *pkg = available_pkgs->pkgs[i];
  9196. + int arch_priority = 1;
  9197. + if (!pkg)
  9198. + continue;
  9199. + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
  9200. + if (pkg->architecture)
  9201. + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
  9202. + else
  9203. + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
  9204. + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
  9205. + pkg->arch_priority = arch_priority;
  9206. + }
  9207. +
  9208. + for (i = 0; i < available_pkgs->len; i++) {
  9209. + pkg_t *pkg = available_pkgs->pkgs[i];
  9210. + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
  9211. + /* clear flags and want for any uninstallable package */
  9212. + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
  9213. + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
  9214. + pkg->state_want = SW_UNKNOWN;
  9215. + pkg->state_flag = 0;
  9216. + }
  9217. + }
  9218. + pkg_vec_free(available_pkgs);
  9219. +
  9220. + /* update the file owner data structure */
  9221. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
  9222. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9223. + for (i = 0; i < installed_pkgs->len; i++) {
  9224. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9225. + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
  9226. + str_list_elt_t *iter;
  9227. + if (installed_files == NULL) {
  9228. + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
  9229. + break;
  9230. + }
  9231. + for (iter = installed_files->head; iter; iter = iter->next) {
  9232. + char *installed_file = iter->data;
  9233. + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
  9234. + file_hash_set_file_owner(conf, installed_file, pkg);
  9235. + }
  9236. + }
  9237. + pkg_vec_free(installed_pkgs);
  9238. +
  9239. + return 0;
  9240. +}
  9241. +
  9242. +struct pkg_write_filelist_data {
  9243. + ipkg_conf_t *conf;
  9244. + pkg_t *pkg;
  9245. + FILE *stream;
  9246. +};
  9247. +
  9248. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
  9249. +{
  9250. + struct pkg_write_filelist_data *data = data_;
  9251. + pkg_t *entry = entry_;
  9252. + if (entry == data->pkg) {
  9253. + fprintf(data->stream, "%s\n", key);
  9254. + }
  9255. +}
  9256. +
  9257. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
  9258. +{
  9259. + struct pkg_write_filelist_data data;
  9260. + char *list_file_name = NULL;
  9261. + int err = 0;
  9262. +
  9263. + if (!pkg) {
  9264. + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
  9265. + return -EINVAL;
  9266. + }
  9267. + ipkg_message(conf, IPKG_INFO,
  9268. + " creating %s.list file\n", pkg->name);
  9269. + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
  9270. + if (!list_file_name) {
  9271. + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
  9272. + return -ENOMEM;
  9273. + }
  9274. + ipkg_message(conf, IPKG_INFO,
  9275. + " creating %s file for pkg %s\n", list_file_name, pkg->name);
  9276. + data.stream = fopen(list_file_name, "w");
  9277. + if (!data.stream) {
  9278. + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
  9279. + list_file_name, strerror(errno));
  9280. + return errno;
  9281. + }
  9282. + data.pkg = pkg;
  9283. + data.conf = conf;
  9284. + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
  9285. + fclose(data.stream);
  9286. + free(list_file_name);
  9287. +
  9288. + return err;
  9289. +}
  9290. +
  9291. +int pkg_write_changed_filelists(ipkg_conf_t *conf)
  9292. +{
  9293. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9294. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9295. + int i;
  9296. + int err;
  9297. + if (conf->noaction)
  9298. + return 0;
  9299. +
  9300. + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
  9301. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9302. + for (i = 0; i < installed_pkgs->len; i++) {
  9303. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9304. + if (pkg->state_flag & SF_FILELIST_CHANGED) {
  9305. + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
  9306. + err = pkg_write_filelist(conf, pkg);
  9307. + if (err)
  9308. + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
  9309. + }
  9310. + }
  9311. + return 0;
  9312. +}
  9313. diff -Nur busybox-1.18.1.orig/archival/libipkg/pkg.h busybox-1.18.1/archival/libipkg/pkg.h
  9314. --- busybox-1.18.1.orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
  9315. +++ busybox-1.18.1/archival/libipkg/pkg.h 2010-12-25 22:38:07.000000000 +0100
  9316. @@ -0,0 +1,229 @@
  9317. +/* pkg.h - the itsy package management system
  9318. +
  9319. + Carl D. Worth
  9320. +
  9321. + Copyright (C) 2001 University of Southern California
  9322. +
  9323. + This program is free software; you can redistribute it and/or
  9324. + modify it under the terms of the GNU General Public License as
  9325. + published by the Free Software Foundation; either version 2, or (at
  9326. + your option) any later version.
  9327. +
  9328. + This program is distributed in the hope that it will be useful, but
  9329. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9330. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9331. + General Public License for more details.
  9332. +*/
  9333. +
  9334. +#ifndef PKG_H
  9335. +#define PKG_H
  9336. +
  9337. +#include <sys/types.h>
  9338. +#include <sys/stat.h>
  9339. +#include <unistd.h>
  9340. +
  9341. +#include "pkg_vec.h"
  9342. +#include "str_list.h"
  9343. +#include "pkg_src.h"
  9344. +#include "pkg_dest.h"
  9345. +#include "ipkg_conf.h"
  9346. +#include "conffile_list.h"
  9347. +
  9348. +struct ipkg_conf;
  9349. +
  9350. +/* I think "Size" is currently the shortest field name */
  9351. +#define PKG_MINIMUM_FIELD_NAME_LEN 4
  9352. +
  9353. +enum pkg_state_want
  9354. +{
  9355. + SW_UNKNOWN = 1,
  9356. + SW_INSTALL,
  9357. + SW_DEINSTALL,
  9358. + SW_PURGE,
  9359. + SW_LAST_STATE_WANT
  9360. +};
  9361. +typedef enum pkg_state_want pkg_state_want_t;
  9362. +
  9363. +enum pkg_state_flag
  9364. +{
  9365. + SF_OK = 0,
  9366. + SF_REINSTREQ = 1,
  9367. + SF_HOLD = 2, /* do not upgrade version */
  9368. + SF_REPLACE = 4, /* replace this package */
  9369. + SF_NOPRUNE = 8, /* do not remove obsolete files */
  9370. + SF_PREFER = 16, /* prefer this version */
  9371. + SF_OBSOLETE = 32, /* old package in upgrade pair */
  9372. + SF_MARKED = 64, /* temporary mark */
  9373. + SF_FILELIST_CHANGED = 128, /* needs filelist written */
  9374. + SF_USER = 256,
  9375. + SF_LAST_STATE_FLAG
  9376. +};
  9377. +typedef enum pkg_state_flag pkg_state_flag_t;
  9378. +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
  9379. +
  9380. +enum pkg_state_status
  9381. +{
  9382. + SS_NOT_INSTALLED = 1,
  9383. + SS_UNPACKED,
  9384. + SS_HALF_CONFIGURED,
  9385. + SS_INSTALLED,
  9386. + SS_HALF_INSTALLED,
  9387. + SS_CONFIG_FILES,
  9388. + SS_POST_INST_FAILED,
  9389. + SS_REMOVAL_FAILED,
  9390. + SS_LAST_STATE_STATUS
  9391. +};
  9392. +typedef enum pkg_state_status pkg_state_status_t;
  9393. +
  9394. +struct abstract_pkg{
  9395. + char * name;
  9396. + int dependencies_checked;
  9397. + pkg_vec_t * pkgs;
  9398. + pkg_state_status_t state_status;
  9399. + pkg_state_flag_t state_flag;
  9400. + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
  9401. + abstract_pkg_vec_t * provided_by;
  9402. + abstract_pkg_vec_t * replaced_by;
  9403. +};
  9404. +
  9405. +#include "pkg_depends.h"
  9406. +
  9407. +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
  9408. +
  9409. + The 3 version fields should go into a single version struct. (This
  9410. + is especially important since, currently, pkg->version can easily
  9411. + be mistaken for pkg_verson_str_alloc(pkg) although they are very
  9412. + distinct. This has been the source of multiple bugs.
  9413. +
  9414. + The 3 state fields could possibly also go into their own struct.
  9415. +
  9416. + All fields which deal with lists of packages, (Depends,
  9417. + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
  9418. + be handled by a single struct in pkg_t
  9419. +
  9420. + All string fields for which there is a small set of possible
  9421. + values, (section, maintainer, architecture, maybe version?), that
  9422. + are reused among different packages -- for all such packages we
  9423. + should move from "char *"s to some atom datatype to share data
  9424. + storage and use less memory. We might even do reference counting,
  9425. + but probably not since most often we only create new pkg_t structs,
  9426. + we don't often free them. */
  9427. +struct pkg
  9428. +{
  9429. + char *name;
  9430. + unsigned long epoch;
  9431. + char *version;
  9432. + char *revision;
  9433. + char *familiar_revision;
  9434. + pkg_src_t *src;
  9435. + pkg_dest_t *dest;
  9436. + char *architecture;
  9437. + char *section;
  9438. + char *maintainer;
  9439. + char *description;
  9440. + pkg_state_want_t state_want;
  9441. + pkg_state_flag_t state_flag;
  9442. + pkg_state_status_t state_status;
  9443. + char **depends_str;
  9444. + int depends_count;
  9445. + char **pre_depends_str;
  9446. + int pre_depends_count;
  9447. + char **recommends_str;
  9448. + int recommends_count;
  9449. + char **suggests_str;
  9450. + int suggests_count;
  9451. + compound_depend_t * depends;
  9452. +
  9453. + /* Abhaya: new conflicts */
  9454. + char **conflicts_str;
  9455. + compound_depend_t * conflicts;
  9456. + int conflicts_count;
  9457. +
  9458. + char **replaces_str;
  9459. + int replaces_count;
  9460. + abstract_pkg_t ** replaces;
  9461. +
  9462. + char **provides_str;
  9463. + int provides_count;
  9464. + abstract_pkg_t ** provides;
  9465. +
  9466. + abstract_pkg_t *parent;
  9467. +
  9468. + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
  9469. +
  9470. + char *filename;
  9471. + char *local_filename;
  9472. + char *url;
  9473. + char *tmp_unpack_dir;
  9474. + char *md5sum;
  9475. + char *size;
  9476. + char *installed_size;
  9477. + char *priority;
  9478. + char *source;
  9479. + conffile_list_t conffiles;
  9480. + time_t installed_time;
  9481. + /* As pointer for lazy evaluation */
  9482. + str_list_t *installed_files;
  9483. + /* XXX: CLEANUP: I'd like to perhaps come up with a better
  9484. + mechanism to avoid the problem here, (which is that the
  9485. + installed_files list was being freed from an inner loop while
  9486. + still being used within an outer loop. */
  9487. + int installed_files_ref_cnt;
  9488. + int essential;
  9489. + int arch_priority;
  9490. +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
  9491. + int provided_by_hand;
  9492. +};
  9493. +
  9494. +pkg_t *pkg_new(void);
  9495. +int pkg_init(pkg_t *pkg);
  9496. +void pkg_deinit(pkg_t *pkg);
  9497. +int pkg_init_from_file(pkg_t *pkg, const char *filename);
  9498. +abstract_pkg_t *abstract_pkg_new(void);
  9499. +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
  9500. +
  9501. +/*
  9502. + * merges fields from newpkg into oldpkg.
  9503. + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
  9504. + */
  9505. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
  9506. +
  9507. +char *pkg_version_str_alloc(pkg_t *pkg);
  9508. +
  9509. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
  9510. +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
  9511. +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
  9512. +
  9513. +char * pkg_formatted_info(pkg_t *pkg );
  9514. +char * pkg_formatted_field(pkg_t *pkg, const char *field );
  9515. +
  9516. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
  9517. +
  9518. +void pkg_print_info(pkg_t *pkg, FILE *file);
  9519. +void pkg_print_status(pkg_t * pkg, FILE * file);
  9520. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
  9521. +str_list_t *pkg_get_installed_files(pkg_t *pkg);
  9522. +int pkg_free_installed_files(pkg_t *pkg);
  9523. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
  9524. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
  9525. +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
  9526. + const char *script, const char *args);
  9527. +
  9528. +/* enum mappings */
  9529. +char *pkg_state_want_to_str(pkg_state_want_t sw);
  9530. +pkg_state_want_t pkg_state_want_from_str(char *str);
  9531. +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
  9532. +pkg_state_flag_t pkg_state_flag_from_str(char *str);
  9533. +char *pkg_state_status_to_str(pkg_state_status_t ss);
  9534. +pkg_state_status_t pkg_state_status_from_str(char *str);
  9535. +
  9536. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
  9537. +
  9538. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
  9539. +int pkg_info_preinstall_check(ipkg_conf_t *conf);
  9540. +int pkg_free_installed_files(pkg_t *pkg);
  9541. +
  9542. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
  9543. +int pkg_write_changed_filelists(ipkg_conf_t *conf);
  9544. +
  9545. +#endif
  9546. diff -Nur busybox-1.18.1.orig/archival/libipkg/pkg_depends.c busybox-1.18.1/archival/libipkg/pkg_depends.c
  9547. --- busybox-1.18.1.orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
  9548. +++ busybox-1.18.1/archival/libipkg/pkg_depends.c 2010-12-25 22:38:07.000000000 +0100
  9549. @@ -0,0 +1,1032 @@
  9550. +/* pkg_depends.c - the itsy package management system
  9551. +
  9552. + Steven M. Ayer
  9553. +
  9554. + Copyright (C) 2002 Compaq Computer Corporation
  9555. +
  9556. + This program is free software; you can redistribute it and/or
  9557. + modify it under the terms of the GNU General Public License as
  9558. + published by the Free Software Foundation; either version 2, or (at
  9559. + your option) any later version.
  9560. +
  9561. + This program is distributed in the hope that it will be useful, but
  9562. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9563. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9564. + General Public License for more details.
  9565. +*/
  9566. +
  9567. +#include "ipkg.h"
  9568. +#include <errno.h>
  9569. +#include <ctype.h>
  9570. +
  9571. +#include "pkg.h"
  9572. +#include "ipkg_utils.h"
  9573. +#include "pkg_hash.h"
  9574. +#include "ipkg_message.h"
  9575. +#include "pkg_parse.h"
  9576. +#include "hash_table.h"
  9577. +
  9578. +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
  9579. +static depend_t * depend_init(void);
  9580. +static void depend_deinit(depend_t *d);
  9581. +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
  9582. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
  9583. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
  9584. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg);
  9585. +
  9586. +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
  9587. +{
  9588. + depend_t *depend = (depend_t *)cdata;
  9589. + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
  9590. + return 1;
  9591. + else
  9592. + return 0;
  9593. +}
  9594. +
  9595. +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
  9596. +{
  9597. + depend_t *depend = (depend_t *)cdata;
  9598. +#if 0
  9599. + pkg_t * temp = pkg_new();
  9600. + int comparison;
  9601. + parseVersion(temp, depend->version);
  9602. + comparison = pkg_compare_versions(pkg, temp);
  9603. + free(temp);
  9604. +
  9605. + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
  9606. + __FUNCTION__, pkg->name, pkg->version,
  9607. + depend, depend->constraint, depend->version,
  9608. + comparison, version_constraints_satisfied(depend, pkg));
  9609. +#endif
  9610. + if (version_constraints_satisfied(depend, pkg))
  9611. + return 1;
  9612. + else
  9613. + return 0;
  9614. +}
  9615. +
  9616. +/* returns ndependences or negative error value */
  9617. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
  9618. + pkg_vec_t *unsatisfied, char *** unresolved)
  9619. +{
  9620. + pkg_t * satisfier_entry_pkg;
  9621. + register int i, j, k, l;
  9622. + int count, found;
  9623. + char ** the_lost;
  9624. + abstract_pkg_t * ab_pkg;
  9625. +
  9626. + /*
  9627. + * this is a setup to check for redundant/cyclic dependency checks,
  9628. + * which are marked at the abstract_pkg level
  9629. + */
  9630. + if (!(ab_pkg = pkg->parent)) {
  9631. + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
  9632. + *unresolved = NULL;
  9633. + return 0;
  9634. + }
  9635. + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
  9636. + *unresolved = NULL;
  9637. + return 0;
  9638. + } else {
  9639. + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
  9640. + }
  9641. + /**/
  9642. +
  9643. + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
  9644. + if (!count){
  9645. + *unresolved = NULL;
  9646. + return 0;
  9647. + }
  9648. +
  9649. + the_lost = NULL;
  9650. +
  9651. + /* foreach dependency */
  9652. + for (i = 0; i < count; i++) {
  9653. + compound_depend_t * compound_depend = &pkg->depends[i];
  9654. + depend_t ** possible_satisfiers = compound_depend->possibilities;;
  9655. + found = 0;
  9656. + satisfier_entry_pkg = NULL;
  9657. +
  9658. + if (compound_depend->type == GREEDY_DEPEND) {
  9659. + /* foreach possible satisfier */
  9660. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9661. + /* foreach provided_by, which includes the abstract_pkg itself */
  9662. + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
  9663. + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
  9664. + int nposs = ab_provider_vec->len;
  9665. + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
  9666. + for (l = 0; l < nposs; l++) {
  9667. + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
  9668. + /* if no depends on this one, try the first package that Provides this one */
  9669. + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
  9670. + continue;
  9671. + }
  9672. +
  9673. + /* cruise this possiblity's pkg_vec looking for an installed version */
  9674. + for (k = 0; k < test_vec->len; k++) {
  9675. + pkg_t *pkg_scout = test_vec->pkgs[k];
  9676. + /* not installed, and not already known about? */
  9677. + if ((pkg_scout->state_want != SW_INSTALL)
  9678. + && !pkg_scout->parent->dependencies_checked
  9679. + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
  9680. + char ** newstuff = NULL;
  9681. + int rc;
  9682. + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
  9683. + /* check for not-already-installed dependencies */
  9684. + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
  9685. + pkg_scout,
  9686. + tmp_vec,
  9687. + &newstuff);
  9688. + if (newstuff == NULL) {
  9689. + int ok = 1;
  9690. + for (i = 0; i < rc; i++) {
  9691. + pkg_t *p = tmp_vec->pkgs[i];
  9692. + if (p->state_want == SW_INSTALL)
  9693. + continue;
  9694. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
  9695. + ok = 0;
  9696. + break;
  9697. + }
  9698. + pkg_vec_free (tmp_vec);
  9699. + if (ok) {
  9700. + /* mark this one for installation */
  9701. + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
  9702. + pkg_vec_insert(unsatisfied, pkg_scout);
  9703. + }
  9704. + } else {
  9705. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
  9706. + free (newstuff);
  9707. + }
  9708. + }
  9709. + }
  9710. + }
  9711. + }
  9712. +
  9713. + continue;
  9714. + }
  9715. +
  9716. + /* foreach possible satisfier, look for installed package */
  9717. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9718. + /* foreach provided_by, which includes the abstract_pkg itself */
  9719. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9720. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9721. + pkg_t *satisfying_pkg =
  9722. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9723. + pkg_installed_and_constraint_satisfied,
  9724. + dependence_to_satisfy, 1);
  9725. + /* Being that I can't test constraing in pkg_hash, I will test it here */
  9726. + if (satisfying_pkg != NULL) {
  9727. + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9728. + satisfying_pkg = NULL;
  9729. + }
  9730. + }
  9731. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
  9732. + if (satisfying_pkg != NULL) {
  9733. + found = 1;
  9734. + break;
  9735. + }
  9736. +
  9737. + }
  9738. + /* if nothing installed matches, then look for uninstalled satisfier */
  9739. + if (!found) {
  9740. + /* foreach possible satisfier, look for installed package */
  9741. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9742. + /* foreach provided_by, which includes the abstract_pkg itself */
  9743. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9744. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9745. + pkg_t *satisfying_pkg =
  9746. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9747. + pkg_constraint_satisfied,
  9748. + dependence_to_satisfy, 1);
  9749. + /* Being that I can't test constraing in pkg_hash, I will test it here too */
  9750. + if (satisfying_pkg != NULL) {
  9751. + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9752. + satisfying_pkg = NULL;
  9753. + }
  9754. + }
  9755. +
  9756. + /* user request overrides package recommendation */
  9757. + if (satisfying_pkg != NULL
  9758. + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
  9759. + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
  9760. + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
  9761. + pkg->name, satisfying_pkg->name);
  9762. + continue;
  9763. + }
  9764. +
  9765. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
  9766. + if (satisfying_pkg != NULL) {
  9767. + satisfier_entry_pkg = satisfying_pkg;
  9768. + break;
  9769. + }
  9770. + }
  9771. + }
  9772. +
  9773. + /* we didn't find one, add something to the unsatisfied vector */
  9774. + if (!found) {
  9775. + if (!satisfier_entry_pkg) {
  9776. + /* failure to meet recommendations is not an error */
  9777. + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
  9778. + the_lost = add_unresolved_dep(pkg, the_lost, i);
  9779. + else
  9780. + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
  9781. + pkg->name, compound_depend->possibilities[0]->pkg->name);
  9782. + }
  9783. + else {
  9784. + if (compound_depend->type == SUGGEST) {
  9785. + /* just mention it politely */
  9786. + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
  9787. + pkg->name, satisfier_entry_pkg->name);
  9788. + } else {
  9789. + char ** newstuff = NULL;
  9790. +
  9791. + if (satisfier_entry_pkg != pkg &&
  9792. + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
  9793. + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
  9794. + pkg_hash_fetch_unsatisfied_dependencies(conf,
  9795. + satisfier_entry_pkg,
  9796. + unsatisfied,
  9797. + &newstuff);
  9798. + the_lost = merge_unresolved(the_lost, newstuff);
  9799. + }
  9800. + }
  9801. + }
  9802. + }
  9803. + }
  9804. + *unresolved = the_lost;
  9805. +
  9806. + return unsatisfied->len;
  9807. +}
  9808. +
  9809. +/*checking for conflicts !in replaces
  9810. + If a packages conflicts with another but is also replacing it, I should not consider it a
  9811. + really conflicts
  9812. + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
  9813. +*/
  9814. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
  9815. +{
  9816. + int i ;
  9817. + int replaces_count = pkg->replaces_count;
  9818. + abstract_pkg_t **replaces;
  9819. +
  9820. + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
  9821. + return 0;
  9822. +
  9823. + replaces = pkg->replaces;
  9824. +
  9825. + for (i = 0; i < replaces_count; i++) {
  9826. + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
  9827. + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
  9828. + return 1;
  9829. + }
  9830. + }
  9831. + return 0;
  9832. +
  9833. +}
  9834. +
  9835. +
  9836. +/* Abhaya: added support for conflicts */
  9837. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg)
  9838. +{
  9839. + pkg_vec_t * installed_conflicts, * test_vec;
  9840. + compound_depend_t * conflicts;
  9841. + depend_t ** possible_satisfiers;
  9842. + depend_t * possible_satisfier;
  9843. + register int i, j, k;
  9844. + int count;
  9845. + abstract_pkg_t * ab_pkg;
  9846. + pkg_t **pkg_scouts;
  9847. + pkg_t *pkg_scout;
  9848. +
  9849. + /*
  9850. + * this is a setup to check for redundant/cyclic dependency checks,
  9851. + * which are marked at the abstract_pkg level
  9852. + */
  9853. + if(!(ab_pkg = pkg->parent)){
  9854. + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
  9855. + return (pkg_vec_t *)NULL;
  9856. + }
  9857. +
  9858. + conflicts = pkg->conflicts;
  9859. + if(!conflicts){
  9860. + return (pkg_vec_t *)NULL;
  9861. + }
  9862. + installed_conflicts = pkg_vec_alloc();
  9863. +
  9864. + count = pkg->conflicts_count;
  9865. +
  9866. +
  9867. +
  9868. + /* foreach conflict */
  9869. + for(i = 0; i < pkg->conflicts_count; i++){
  9870. +
  9871. + possible_satisfiers = conflicts->possibilities;
  9872. +
  9873. + /* foreach possible satisfier */
  9874. + for(j = 0; j < conflicts->possibility_count; j++){
  9875. + possible_satisfier = possible_satisfiers[j];
  9876. + if (!possible_satisfier)
  9877. + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
  9878. + if (!possible_satisfier->pkg)
  9879. + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
  9880. + test_vec = possible_satisfier->pkg->pkgs;
  9881. + if (test_vec) {
  9882. + /* pkg_vec found, it is an actual package conflict
  9883. + * cruise this possiblity's pkg_vec looking for an installed version */
  9884. + pkg_scouts = test_vec->pkgs;
  9885. + for(k = 0; k < test_vec->len; k++){
  9886. + pkg_scout = pkg_scouts[k];
  9887. + if (!pkg_scout) {
  9888. + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
  9889. + continue;
  9890. + }
  9891. + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
  9892. + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
  9893. + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
  9894. + pkg_vec_insert(installed_conflicts, pkg_scout);
  9895. + }
  9896. + }
  9897. + }
  9898. + }
  9899. + }
  9900. + conflicts++;
  9901. + }
  9902. +
  9903. + if (installed_conflicts->len)
  9904. + return installed_conflicts;
  9905. + pkg_vec_free(installed_conflicts);
  9906. + return (pkg_vec_t *)NULL;
  9907. +}
  9908. +
  9909. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
  9910. +{
  9911. + pkg_t * temp;
  9912. + int comparison;
  9913. +
  9914. + if(depends->constraint == NONE)
  9915. + return 1;
  9916. +
  9917. + temp = pkg_new();
  9918. +
  9919. + parseVersion(temp, depends->version);
  9920. +
  9921. + comparison = pkg_compare_versions(pkg, temp);
  9922. +
  9923. + free(temp);
  9924. +
  9925. + if((depends->constraint == EARLIER) &&
  9926. + (comparison < 0))
  9927. + return 1;
  9928. + else if((depends->constraint == LATER) &&
  9929. + (comparison > 0))
  9930. + return 1;
  9931. + else if(comparison == 0)
  9932. + return 1;
  9933. + else if((depends->constraint == LATER_EQUAL) &&
  9934. + (comparison >= 0))
  9935. + return 1;
  9936. + else if((depends->constraint == EARLIER_EQUAL) &&
  9937. + (comparison <= 0))
  9938. + return 1;
  9939. +
  9940. + return 0;
  9941. +}
  9942. +
  9943. +int pkg_dependence_satisfiable(depend_t *depend)
  9944. +{
  9945. + abstract_pkg_t *apkg = depend->pkg;
  9946. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9947. + int n_providers = provider_apkgs->len;
  9948. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9949. + pkg_vec_t *pkg_vec;
  9950. + int n_pkgs ;
  9951. + int i;
  9952. + int j;
  9953. +
  9954. + for (i = 0; i < n_providers; i++) {
  9955. + abstract_pkg_t *papkg = apkgs[i];
  9956. + pkg_vec = papkg->pkgs;
  9957. + if (pkg_vec) {
  9958. + n_pkgs = pkg_vec->len;
  9959. + for (j = 0; j < n_pkgs; j++) {
  9960. + pkg_t *pkg = pkg_vec->pkgs[j];
  9961. + if (version_constraints_satisfied(depend, pkg)) {
  9962. + return 1;
  9963. + }
  9964. + }
  9965. + }
  9966. + }
  9967. + return 0;
  9968. +}
  9969. +
  9970. +int pkg_dependence_satisfied(depend_t *depend)
  9971. +{
  9972. + abstract_pkg_t *apkg = depend->pkg;
  9973. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9974. + int n_providers = provider_apkgs->len;
  9975. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9976. + int i;
  9977. + int n_pkgs;
  9978. + int j;
  9979. +
  9980. + for (i = 0; i < n_providers; i++) {
  9981. + abstract_pkg_t *papkg = apkgs[i];
  9982. + pkg_vec_t *pkg_vec = papkg->pkgs;
  9983. + if (pkg_vec) {
  9984. + n_pkgs = pkg_vec->len;
  9985. + for (j = 0; j < n_pkgs; j++) {
  9986. + pkg_t *pkg = pkg_vec->pkgs[j];
  9987. + if (version_constraints_satisfied(depend, pkg)) {
  9988. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
  9989. + return 1;
  9990. + }
  9991. + }
  9992. + }
  9993. + }
  9994. + return 0;
  9995. +}
  9996. +
  9997. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
  9998. +{
  9999. + register int i;
  10000. + pkg_t ** pkgs = vec->pkgs;
  10001. +
  10002. + for(i = 0; i < vec->len; i++)
  10003. + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
  10004. + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
  10005. + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
  10006. + return 1;
  10007. + return 0;
  10008. +}
  10009. +
  10010. +
  10011. +#ifdef DeadCode
  10012. +/**
  10013. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10014. + * the same abstract package and 0 otherwise.
  10015. + */
  10016. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
  10017. +{
  10018. + abstract_pkg_t **provides = pkg->provides;
  10019. + int provides_count = pkg->provides_count;
  10020. + abstract_pkg_t **replacee_provides = replacee->provides;
  10021. + int replacee_provides_count = replacee->provides_count;
  10022. + int i, j;
  10023. + for (i = 0; i < provides_count; i++) {
  10024. + abstract_pkg_t *apkg = provides[i];
  10025. + for (j = 0; j < replacee_provides_count; j++) {
  10026. + abstract_pkg_t *replacee_apkg = replacee_provides[i];
  10027. + if (apkg == replacee_apkg)
  10028. + return 1;
  10029. + }
  10030. + }
  10031. + return 0;
  10032. +}
  10033. +#endif
  10034. +
  10035. +/**
  10036. + * pkg_provides_abstract returns 1 if pkg->provides contains providee
  10037. + * and 0 otherwise.
  10038. + */
  10039. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
  10040. +{
  10041. + abstract_pkg_t **provides = pkg->provides;
  10042. + int provides_count = pkg->provides_count;
  10043. + int i;
  10044. + for (i = 0; i < provides_count; i++) {
  10045. + if (provides[i] == providee)
  10046. + return 1;
  10047. + }
  10048. + return 0;
  10049. +}
  10050. +
  10051. +/**
  10052. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10053. + * otherwise.
  10054. + */
  10055. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
  10056. +{
  10057. + abstract_pkg_t **replaces = pkg->replaces;
  10058. + int replaces_count = pkg->replaces_count;
  10059. + /* abstract_pkg_t **replacee_provides = pkg->provides;
  10060. + int replacee_provides_count = pkg->provides_count; */
  10061. + int i, j;
  10062. + for (i = 0; i < replaces_count; i++) {
  10063. + abstract_pkg_t *abstract_replacee = replaces[i];
  10064. + for (j = 0; j < replaces_count; j++) {
  10065. + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
  10066. + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
  10067. + if (replacee->provides[j] == abstract_replacee)
  10068. + return 1;
  10069. + }
  10070. + }
  10071. + return 0;
  10072. +}
  10073. +
  10074. +
  10075. +/**
  10076. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
  10077. + * otherwise.
  10078. + */
  10079. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
  10080. +{
  10081. + compound_depend_t *conflicts = pkg->conflicts;
  10082. + int conflicts_count = pkg->conflicts_count;
  10083. + int i, j;
  10084. + for (i = 0; i < conflicts_count; i++) {
  10085. + int possibility_count = conflicts[i].possibility_count;
  10086. + struct depend **possibilities = conflicts[i].possibilities;
  10087. + for (j = 0; j < possibility_count; j++) {
  10088. + if (possibilities[j]->pkg == conflictee) {
  10089. + return 1;
  10090. + }
  10091. + }
  10092. + }
  10093. + return 0;
  10094. +}
  10095. +
  10096. +/**
  10097. + * pkg_conflicts returns 1 if pkg->conflicts contains one of
  10098. + * conflictee's provides and 0 otherwise.
  10099. + */
  10100. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
  10101. +{
  10102. + compound_depend_t *conflicts = pkg->conflicts;
  10103. + int conflicts_count = pkg->conflicts_count;
  10104. + abstract_pkg_t **conflictee_provides = conflictee->provides;
  10105. + int conflictee_provides_count = conflictee->provides_count;
  10106. + int i, j, k;
  10107. + int possibility_count;
  10108. + struct depend **possibilities;
  10109. + abstract_pkg_t *possibility ;
  10110. +
  10111. + for (i = 0; i < conflicts_count; i++) {
  10112. + possibility_count = conflicts[i].possibility_count;
  10113. + possibilities = conflicts[i].possibilities;
  10114. + for (j = 0; j < possibility_count; j++) {
  10115. + possibility = possibilities[j]->pkg;
  10116. + for (k = 0; k < conflictee_provides_count; k++) {
  10117. + if (possibility == conflictee_provides[k]) {
  10118. + return 1;
  10119. + }
  10120. + }
  10121. + }
  10122. + }
  10123. + return 0;
  10124. +}
  10125. +
  10126. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
  10127. +{
  10128. + int oldlen = 0, newlen = 0;
  10129. + char ** result;
  10130. + register int i, j;
  10131. +
  10132. + if(!newstuff)
  10133. + return oldstuff;
  10134. +
  10135. + while(oldstuff && oldstuff[oldlen]) oldlen++;
  10136. + while(newstuff && newstuff[newlen]) newlen++;
  10137. +
  10138. + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
  10139. + if (result == NULL) {
  10140. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10141. + return NULL;
  10142. + }
  10143. +
  10144. + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
  10145. + *(result + i) = *(newstuff + j);
  10146. +
  10147. + *(result + i) = NULL;
  10148. +
  10149. + return result;
  10150. +}
  10151. +
  10152. +/*
  10153. + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
  10154. + * this is null terminated, no count is carried around
  10155. + */
  10156. +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
  10157. +{
  10158. + int count;
  10159. + char ** resized;
  10160. + char *depend_str = pkg_depend_str(pkg, ref_ndx);
  10161. +
  10162. + count = 0;
  10163. + while(the_lost && the_lost[count]) count++;
  10164. +
  10165. + count++; /* need one to hold the null */
  10166. + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
  10167. + if (resized == NULL) {
  10168. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10169. + return NULL;
  10170. + }
  10171. + resized[count - 1] = strdup(depend_str);
  10172. + resized[count] = NULL;
  10173. +
  10174. + return resized;
  10175. +}
  10176. +
  10177. +void printDepends(pkg_t * pkg)
  10178. +{
  10179. + register int i, j;
  10180. + compound_depend_t * depend;
  10181. + int count;
  10182. +
  10183. + count = pkg->pre_depends_count + pkg->depends_count;
  10184. +
  10185. + depend = pkg->depends;
  10186. + if(!depend){
  10187. + fprintf(stderr, "Depends pointer is NULL\n");
  10188. + return;
  10189. + }
  10190. + for(i = 0; i < count; i++){
  10191. + fprintf(stderr, "%s has %d possibilities:\n",
  10192. + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
  10193. + depend->possibility_count);
  10194. + for(j = 0; j < depend->possibility_count; j++)
  10195. + fprintf(stderr, "\t%s version %s (%d)\n",
  10196. + depend->possibilities[j]->pkg->name,
  10197. + depend->possibilities[j]->version,
  10198. + depend->possibilities[j]->constraint);
  10199. + depend++;
  10200. + }
  10201. +}
  10202. +
  10203. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10204. +{
  10205. + register int i, j;
  10206. +
  10207. + /* every pkg provides itself */
  10208. + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
  10209. +
  10210. + if (!pkg->provides_count)
  10211. + return 0;
  10212. +
  10213. + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
  10214. + if (pkg->provides == NULL) {
  10215. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10216. + return -1 ;
  10217. + }
  10218. + pkg->provides[0] = ab_pkg;
  10219. +
  10220. + // if (strcmp(ab_pkg->name, pkg->name))
  10221. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10222. +
  10223. + for(i = 0; i < pkg->provides_count; i++){
  10224. + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
  10225. +
  10226. + pkg->provides[i+1] = provided_abpkg;
  10227. +
  10228. + j = 0;
  10229. + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
  10230. + }
  10231. + return 0;
  10232. +}
  10233. +
  10234. +/* Abhaya: added conflicts support */
  10235. +int buildConflicts(hash_table_t * hash, pkg_t * pkg)
  10236. +{
  10237. + register int i;
  10238. + compound_depend_t * conflicts;
  10239. +
  10240. + if (!pkg->conflicts_count)
  10241. + return 0;
  10242. +
  10243. + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
  10244. + pkg->conflicts_count);
  10245. + if (conflicts == NULL) {
  10246. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10247. + return -1;
  10248. + }
  10249. + for (i = 0; i < pkg->conflicts_count; i++) {
  10250. + conflicts->type = CONFLICTS;
  10251. + parseDepends(conflicts, hash,
  10252. + pkg->conflicts_str[i]);
  10253. +#if 0
  10254. + for (j = 0; j < conflicts->possibility_count; j++) {
  10255. + depend_t *possibility = conflicts->possibilities[j];
  10256. + abstract_pkg_t *conflicting_apkg = possibility->pkg;
  10257. + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
  10258. + }
  10259. +#endif
  10260. + conflicts++;
  10261. + }
  10262. + return 0;
  10263. +}
  10264. +
  10265. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10266. +{
  10267. + register int i, j;
  10268. +
  10269. + if (!pkg->replaces_count)
  10270. + return 0;
  10271. +
  10272. + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
  10273. + if (pkg->replaces == NULL) {
  10274. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10275. + return -1;
  10276. + }
  10277. +
  10278. + // if (strcmp(ab_pkg->name, pkg->name))
  10279. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10280. +
  10281. + for(i = 0; i < pkg->replaces_count; i++){
  10282. + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
  10283. +
  10284. + pkg->replaces[i] = old_abpkg;
  10285. +
  10286. + j = 0;
  10287. + if (!old_abpkg->replaced_by)
  10288. + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
  10289. + if ( old_abpkg->replaced_by == NULL ){
  10290. + return -1;
  10291. + }
  10292. + /* if a package pkg both replaces and conflicts old_abpkg,
  10293. + * then add it to the replaced_by vector so that old_abpkg
  10294. + * will be upgraded to ab_pkg automatically */
  10295. + if (pkg_conflicts_abstract(pkg, old_abpkg))
  10296. + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
  10297. + }
  10298. + return 0;
  10299. +}
  10300. +
  10301. +int buildDepends(hash_table_t * hash, pkg_t * pkg)
  10302. +{
  10303. + int count;
  10304. + register int i;
  10305. + compound_depend_t * depends;
  10306. +
  10307. + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
  10308. + return 0;
  10309. +
  10310. + if (0 && pkg->pre_depends_count)
  10311. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10312. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10313. + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
  10314. + if (depends == NULL) {
  10315. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10316. + return -1;
  10317. + }
  10318. +
  10319. +
  10320. + for(i = 0; i < pkg->pre_depends_count; i++){
  10321. + parseDepends(depends, hash, pkg->pre_depends_str[i]);
  10322. + if (0 && pkg->pre_depends_count)
  10323. + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
  10324. + pkg->pre_depends_str[i], depends, depends->possibility_count);
  10325. + depends->type = PREDEPEND;
  10326. + depends++;
  10327. + }
  10328. +
  10329. + for(i = 0; i < pkg->recommends_count; i++){
  10330. + parseDepends(depends, hash, pkg->recommends_str[i]);
  10331. + if (0 && pkg->recommends_count)
  10332. + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
  10333. + pkg->recommends_str[i], depends, depends->possibility_count);
  10334. + depends->type = RECOMMEND;
  10335. + depends++;
  10336. + }
  10337. +
  10338. + for(i = 0; i < pkg->suggests_count; i++){
  10339. + parseDepends(depends, hash, pkg->suggests_str[i]);
  10340. + if (0 && pkg->suggests_count)
  10341. + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
  10342. + pkg->suggests_str[i], depends, depends->possibility_count);
  10343. + depends->type = SUGGEST;
  10344. + depends++;
  10345. + }
  10346. +
  10347. + for(i = 0; i < pkg->depends_count; i++){
  10348. + parseDepends(depends, hash, pkg->depends_str[i]);
  10349. + if (0 && pkg->depends_count)
  10350. + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
  10351. + pkg->depends_str[i], depends, depends->possibility_count);
  10352. + depends++;
  10353. + }
  10354. + return 0;
  10355. +}
  10356. +
  10357. +/*
  10358. + * pkg_depend_string: returns the depends string specified by index_.
  10359. + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
  10360. + * [0,npredepends) -> returns pre_depends_str[index_]
  10361. + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index_]
  10362. + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index_]
  10363. + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index_]
  10364. + */
  10365. +char *pkg_depend_str(pkg_t *pkg, int index_)
  10366. +{
  10367. + if (index_ < pkg->pre_depends_count) {
  10368. + return pkg->pre_depends_str[index_];
  10369. + }
  10370. + index_ -= pkg->pre_depends_count;
  10371. +
  10372. + if (index_ < pkg->recommends_count) {
  10373. + return pkg->recommends_str[index_];
  10374. + }
  10375. + index_ -= pkg->recommends_count;
  10376. +
  10377. + if (index_ < pkg->suggests_count) {
  10378. + return pkg->suggests_str[index_];
  10379. + }
  10380. + index_ -= pkg->suggests_count;
  10381. +
  10382. + if (index_ < pkg->depends_count) {
  10383. + return pkg->depends_str[index_];
  10384. + }
  10385. + fprintf(stderr, "pkg_depend_str: index_ %d out of range for pkg=%s\n", index_, pkg->name);
  10386. + return NULL;
  10387. +}
  10388. +
  10389. +void freeDepends(pkg_t *pkg)
  10390. +{
  10391. + int i;
  10392. +
  10393. + if (pkg == NULL || pkg->depends == NULL) {
  10394. + return;
  10395. + }
  10396. +
  10397. + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
  10398. + for (i=0; i < pkg->depends->possibility_count; i++) {
  10399. + depend_deinit(pkg->depends->possibilities[i]);
  10400. + }
  10401. + free(pkg->depends->possibilities);
  10402. + free(pkg->depends);
  10403. + pkg->depends = NULL;
  10404. +}
  10405. +
  10406. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
  10407. +{
  10408. + compound_depend_t * depends;
  10409. + int count, othercount;
  10410. + register int i, j;
  10411. + abstract_pkg_t * ab_depend;
  10412. + abstract_pkg_t ** temp;
  10413. +
  10414. + count = pkg->pre_depends_count + pkg->depends_count;
  10415. + depends = pkg->depends;
  10416. +
  10417. + if (0 && pkg->pre_depends_count)
  10418. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10419. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10420. + for (i = 0; i < count; i++) {
  10421. + if (0 && pkg->pre_depends_count)
  10422. + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
  10423. + for (j = 0; j < depends->possibility_count; j++){
  10424. + ab_depend = depends->possibilities[j]->pkg;
  10425. + if(!ab_depend->depended_upon_by)
  10426. + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
  10427. +
  10428. + temp = ab_depend->depended_upon_by;
  10429. + othercount = 1;
  10430. + while(*temp){
  10431. + temp++;
  10432. + othercount++;
  10433. + }
  10434. + *temp = ab_pkg;
  10435. +
  10436. + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
  10437. + (othercount + 1) * sizeof(abstract_pkg_t *));
  10438. + /* the array may have moved */
  10439. + temp = ab_depend->depended_upon_by + othercount;
  10440. + *temp = NULL;
  10441. + }
  10442. + depends++;
  10443. + }
  10444. +}
  10445. +
  10446. +static depend_t * depend_init(void)
  10447. +{
  10448. + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
  10449. + if ( d==NULL ){
  10450. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10451. + return NULL;
  10452. + }
  10453. + d->constraint = NONE;
  10454. + d->version = NULL;
  10455. + d->pkg = NULL;
  10456. +
  10457. + return d;
  10458. +}
  10459. +
  10460. +static void depend_deinit(depend_t *d)
  10461. +{
  10462. + free(d);
  10463. +}
  10464. +
  10465. +static int parseDepends(compound_depend_t *compound_depend,
  10466. + hash_table_t * hash, char * depend_str)
  10467. +{
  10468. + char * pkg_name, buffer[2048];
  10469. + int num_of_ors = 0;
  10470. + register int i;
  10471. + register char * src, * dest;
  10472. + depend_t ** possibilities;
  10473. +
  10474. + /* first count the number of ored possibilities for satisfying dependency */
  10475. + src = depend_str;
  10476. + while(*src)
  10477. + if(*src++ == '|')
  10478. + num_of_ors++;
  10479. +
  10480. + compound_depend->type = DEPEND;
  10481. +
  10482. + compound_depend->possibility_count = num_of_ors + 1;
  10483. + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
  10484. + if (!possibilities)
  10485. + return -ENOMEM;
  10486. + compound_depend->possibilities = possibilities;
  10487. +
  10488. + src = depend_str;
  10489. + for(i = 0; i < num_of_ors + 1; i++){
  10490. + possibilities[i] = depend_init();
  10491. + if (!possibilities[i])
  10492. + return -ENOMEM;
  10493. + /* gobble up just the name first */
  10494. + dest = buffer;
  10495. + while(*src &&
  10496. + !isspace(*src) &&
  10497. + (*src != '(') &&
  10498. + (*src != '*') &&
  10499. + (*src != '|'))
  10500. + *dest++ = *src++;
  10501. + *dest = '\0';
  10502. + pkg_name = trim_alloc(buffer);
  10503. + if (pkg_name == NULL )
  10504. + return -ENOMEM;
  10505. +
  10506. + /* now look at possible version info */
  10507. +
  10508. + /* skip to next chars */
  10509. + if(isspace(*src))
  10510. + while(*src && isspace(*src)) src++;
  10511. +
  10512. + /* extract constraint and version */
  10513. + if(*src == '('){
  10514. + src++;
  10515. + if(!strncmp(src, "<<", 2)){
  10516. + possibilities[i]->constraint = EARLIER;
  10517. + src += 2;
  10518. + }
  10519. + else if(!strncmp(src, "<=", 2)){
  10520. + possibilities[i]->constraint = EARLIER_EQUAL;
  10521. + src += 2;
  10522. + }
  10523. + else if(!strncmp(src, ">=", 2)){
  10524. + possibilities[i]->constraint = LATER_EQUAL;
  10525. + src += 2;
  10526. + }
  10527. + else if(!strncmp(src, ">>", 2)){
  10528. + possibilities[i]->constraint = LATER;
  10529. + src += 2;
  10530. + }
  10531. + else if(!strncmp(src, "=", 1)){
  10532. + possibilities[i]->constraint = EQUAL;
  10533. + src++;
  10534. + }
  10535. + /* should these be here to support deprecated designations; dpkg does */
  10536. + else if(!strncmp(src, "<", 1)){
  10537. + possibilities[i]->constraint = EARLIER_EQUAL;
  10538. + src++;
  10539. + }
  10540. + else if(!strncmp(src, ">", 1)){
  10541. + possibilities[i]->constraint = LATER_EQUAL;
  10542. + src++;
  10543. + }
  10544. +
  10545. + /* now we have any constraint, pass space to version string */
  10546. + while(isspace(*src)) src++;
  10547. +
  10548. + /* this would be the version string */
  10549. + dest = buffer;
  10550. + while(*src && *src != ')')
  10551. + *dest++ = *src++;
  10552. + *dest = '\0';
  10553. +
  10554. + possibilities[i]->version = trim_alloc(buffer);
  10555. + /* fprintf(stderr, "let's print the depends version string:");
  10556. + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
  10557. + if (possibilities[i]->version == NULL )
  10558. + return -ENOMEM;
  10559. +
  10560. +
  10561. + }
  10562. + /* hook up the dependency to its abstract pkg */
  10563. + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
  10564. +
  10565. + free(pkg_name);
  10566. +
  10567. + /* now get past the ) and any possible | chars */
  10568. + while(*src &&
  10569. + (isspace(*src) ||
  10570. + (*src == ')') ||
  10571. + (*src == '|')))
  10572. + src++;
  10573. + if (*src == '*')
  10574. + {
  10575. + compound_depend->type = GREEDY_DEPEND;
  10576. + src++;
  10577. + }
  10578. + }
  10579. +
  10580. + return 0;
  10581. +}
  10582. diff -Nur busybox-1.18.1.orig/archival/libipkg/pkg_depends.h busybox-1.18.1/archival/libipkg/pkg_depends.h
  10583. --- busybox-1.18.1.orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
  10584. +++ busybox-1.18.1/archival/libipkg/pkg_depends.h 2010-12-25 22:38:07.000000000 +0100
  10585. @@ -0,0 +1,105 @@
  10586. +/* pkg_depends.h - the itsy package management system
  10587. +
  10588. + Steven M. Ayer
  10589. +
  10590. + Copyright (C) 2002 Compaq Computer Corporation
  10591. +
  10592. + This program is free software; you can redistribute it and/or
  10593. + modify it under the terms of the GNU General Public License as
  10594. + published by the Free Software Foundation; either version 2, or (at
  10595. + your option) any later version.
  10596. +
  10597. + This program is distributed in the hope that it will be useful, but
  10598. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10599. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10600. + General Public License for more details.
  10601. +*/
  10602. +
  10603. +#ifndef PKG_DEPENDS_H
  10604. +#define PKG_DEPENDS_H
  10605. +
  10606. +#include "pkg.h"
  10607. +#include "pkg_hash.h"
  10608. +
  10609. +enum depend_type {
  10610. + PREDEPEND,
  10611. + DEPEND,
  10612. + CONFLICTS,
  10613. + GREEDY_DEPEND,
  10614. + RECOMMEND,
  10615. + SUGGEST
  10616. +};
  10617. +typedef enum depend_type depend_type_t;
  10618. +
  10619. +enum version_constraint {
  10620. + NONE,
  10621. + EARLIER,
  10622. + EARLIER_EQUAL,
  10623. + EQUAL,
  10624. + LATER_EQUAL,
  10625. + LATER
  10626. +};
  10627. +typedef enum version_constraint version_constraint_t;
  10628. +
  10629. +struct depend{
  10630. + version_constraint_t constraint;
  10631. + char * version;
  10632. + abstract_pkg_t * pkg;
  10633. +};
  10634. +typedef struct depend depend_t;
  10635. +
  10636. +struct compound_depend{
  10637. + depend_type_t type;
  10638. + int possibility_count;
  10639. + struct depend ** possibilities;
  10640. +};
  10641. +typedef struct compound_depend compound_depend_t;
  10642. +
  10643. +#include "hash_table.h"
  10644. +
  10645. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10646. +int buildConflicts(hash_table_t * hash, pkg_t * pkg);
  10647. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10648. +int buildDepends(hash_table_t * hash, pkg_t * pkg);
  10649. +
  10650. +/**
  10651. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10652. + * the same abstract package and 0 otherwise.
  10653. + */
  10654. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
  10655. +
  10656. +/**
  10657. + * pkg_provides returns 1 if pkg->provides contains providee and 0
  10658. + * otherwise.
  10659. + */
  10660. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
  10661. +
  10662. +/**
  10663. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10664. + * otherwise.
  10665. + */
  10666. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
  10667. +
  10668. +/**
  10669. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
  10670. + * otherwise.
  10671. + */
  10672. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
  10673. +
  10674. +/**
  10675. + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
  10676. + * otherwise.
  10677. + */
  10678. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
  10679. +
  10680. +char *pkg_depend_str(pkg_t *pkg, int index_);
  10681. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
  10682. +void freeDepends(pkg_t *pkg);
  10683. +void printDepends(pkg_t * pkg);
  10684. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
  10685. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
  10686. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
  10687. +int pkg_dependence_satisfiable(depend_t *depend);
  10688. +int pkg_dependence_satisfied(depend_t *depend);
  10689. +
  10690. +#endif
  10691. diff -Nur busybox-1.18.1.orig/archival/libipkg/pkg_dest.c busybox-1.18.1/archival/libipkg/pkg_dest.c
  10692. --- busybox-1.18.1.orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
  10693. +++ busybox-1.18.1/archival/libipkg/pkg_dest.c 2010-12-25 22:38:07.000000000 +0100
  10694. @@ -0,0 +1,92 @@
  10695. +/* pkg_dest.c - the itsy package management system
  10696. +
  10697. + Carl D. Worth
  10698. +
  10699. + Copyright (C) 2001 University of Southern California
  10700. +
  10701. + This program is free software; you can redistribute it and/or
  10702. + modify it under the terms of the GNU General Public License as
  10703. + published by the Free Software Foundation; either version 2, or (at
  10704. + your option) any later version.
  10705. +
  10706. + This program is distributed in the hope that it will be useful, but
  10707. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10708. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10709. + General Public License for more details.
  10710. +*/
  10711. +
  10712. +#include "ipkg.h"
  10713. +
  10714. +#include "pkg_dest.h"
  10715. +#include "file_util.h"
  10716. +#include "str_util.h"
  10717. +#include "sprintf_alloc.h"
  10718. +
  10719. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
  10720. +{
  10721. + dest->name = strdup(name);
  10722. +
  10723. + /* Guarantee that dest->root_dir ends with a '/' */
  10724. + if (str_ends_with(root_dir, "/")) {
  10725. + dest->root_dir = strdup(root_dir);
  10726. + } else {
  10727. + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
  10728. + }
  10729. + file_mkdir_hier(dest->root_dir, 0755);
  10730. +
  10731. + sprintf_alloc(&dest->ipkg_dir, "%s%s",
  10732. + dest->root_dir, IPKG_STATE_DIR_PREFIX);
  10733. + file_mkdir_hier(dest->ipkg_dir, 0755);
  10734. +
  10735. + if (str_starts_with (lists_dir, "/"))
  10736. + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
  10737. + else
  10738. + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
  10739. +
  10740. + file_mkdir_hier(dest->lists_dir, 0755);
  10741. +
  10742. + sprintf_alloc(&dest->info_dir, "%s/%s",
  10743. + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
  10744. + file_mkdir_hier(dest->info_dir, 0755);
  10745. +
  10746. + sprintf_alloc(&dest->status_file_name, "%s/%s",
  10747. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10748. +
  10749. + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
  10750. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10751. +
  10752. + dest->status_file = NULL;
  10753. +
  10754. + return 0;
  10755. +}
  10756. +
  10757. +void pkg_dest_deinit(pkg_dest_t *dest)
  10758. +{
  10759. + free(dest->name);
  10760. + dest->name = NULL;
  10761. +
  10762. + free(dest->root_dir);
  10763. + dest->root_dir = NULL;
  10764. +
  10765. + free(dest->ipkg_dir);
  10766. + dest->ipkg_dir = NULL;
  10767. +
  10768. + free(dest->lists_dir);
  10769. + dest->lists_dir = NULL;
  10770. +
  10771. + free(dest->info_dir);
  10772. + dest->info_dir = NULL;
  10773. +
  10774. + free(dest->status_file_name);
  10775. + dest->status_file_name = NULL;
  10776. +
  10777. + free(dest->status_file_tmp_name);
  10778. + dest->status_file_tmp_name = NULL;
  10779. +
  10780. + if (dest->status_file) {
  10781. + fclose(dest->status_file);
  10782. + }
  10783. + dest->status_file = NULL;
  10784. +
  10785. + dest->root_dir = NULL;
  10786. +}
  10787. diff -Nur busybox-1.18.1.orig/archival/libipkg/pkg_dest.h busybox-1.18.1/archival/libipkg/pkg_dest.h
  10788. --- busybox-1.18.1.orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
  10789. +++ busybox-1.18.1/archival/libipkg/pkg_dest.h 2010-12-25 22:38:07.000000000 +0100
  10790. @@ -0,0 +1,38 @@
  10791. +/* pkg_dest.h - the itsy package management system
  10792. +
  10793. + Carl D. Worth
  10794. +
  10795. + Copyright (C) 2001 University of Southern California
  10796. +
  10797. + This program is free software; you can redistribute it and/or
  10798. + modify it under the terms of the GNU General Public License as
  10799. + published by the Free Software Foundation; either version 2, or (at
  10800. + your option) any later version.
  10801. +
  10802. + This program is distributed in the hope that it will be useful, but
  10803. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10804. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10805. + General Public License for more details.
  10806. +*/
  10807. +
  10808. +#ifndef PKG_DEST_H
  10809. +#define PKG_DEST_H
  10810. +
  10811. +typedef struct pkg_dest pkg_dest_t;
  10812. +struct pkg_dest
  10813. +{
  10814. + char *name;
  10815. + char *root_dir;
  10816. + char *ipkg_dir;
  10817. + char *lists_dir;
  10818. + char *info_dir;
  10819. + char *status_file_name;
  10820. + char *status_file_tmp_name;
  10821. + FILE *status_file;
  10822. +};
  10823. +
  10824. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
  10825. +void pkg_dest_deinit(pkg_dest_t *dest);
  10826. +
  10827. +#endif
  10828. +
  10829. diff -Nur busybox-1.18.1.orig/archival/libipkg/pkg_dest_list.c busybox-1.18.1/archival/libipkg/pkg_dest_list.c
  10830. --- busybox-1.18.1.orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
  10831. +++ busybox-1.18.1/archival/libipkg/pkg_dest_list.c 2010-12-25 22:38:07.000000000 +0100
  10832. @@ -0,0 +1,85 @@
  10833. +/* pkg_dest_list.c - the itsy package management system
  10834. +
  10835. + Carl D. Worth
  10836. +
  10837. + Copyright (C) 2001 University of Southern California
  10838. +
  10839. + This program is free software; you can redistribute it and/or
  10840. + modify it under the terms of the GNU General Public License as
  10841. + published by the Free Software Foundation; either version 2, or (at
  10842. + your option) any later version.
  10843. +
  10844. + This program is distributed in the hope that it will be useful, but
  10845. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10846. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10847. + General Public License for more details.
  10848. +*/
  10849. +
  10850. +#include "ipkg.h"
  10851. +
  10852. +#include "pkg_dest.h"
  10853. +#include "void_list.h"
  10854. +#include "pkg_dest_list.h"
  10855. +
  10856. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
  10857. +{
  10858. + return void_list_elt_init((void_list_elt_t *) elt, data);
  10859. +}
  10860. +
  10861. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
  10862. +{
  10863. + void_list_elt_deinit((void_list_elt_t *) elt);
  10864. +}
  10865. +
  10866. +int pkg_dest_list_init(pkg_dest_list_t *list)
  10867. +{
  10868. + return void_list_init((void_list_t *) list);
  10869. +}
  10870. +
  10871. +void pkg_dest_list_deinit(pkg_dest_list_t *list)
  10872. +{
  10873. + pkg_dest_list_elt_t *iter;
  10874. + pkg_dest_t *pkg_dest;
  10875. +
  10876. + for (iter = list->head; iter; iter = iter->next) {
  10877. + pkg_dest = iter->data;
  10878. + pkg_dest_deinit(pkg_dest);
  10879. +
  10880. + /* malloced in pkg_dest_list_append */
  10881. + free(pkg_dest);
  10882. + iter->data = NULL;
  10883. + }
  10884. + void_list_deinit((void_list_t *) list);
  10885. +}
  10886. +
  10887. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10888. + const char *root_dir,const char *lists_dir)
  10889. +{
  10890. + int err;
  10891. + pkg_dest_t *pkg_dest;
  10892. +
  10893. + /* freed in plg_dest_list_deinit */
  10894. + pkg_dest = malloc(sizeof(pkg_dest_t));
  10895. + if (pkg_dest == NULL) {
  10896. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10897. + return NULL;
  10898. + }
  10899. +
  10900. + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
  10901. + err = void_list_append((void_list_t *) list, pkg_dest);
  10902. + if (err) {
  10903. + return NULL;
  10904. + }
  10905. +
  10906. + return pkg_dest;
  10907. +}
  10908. +
  10909. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
  10910. +{
  10911. + return void_list_push((void_list_t *) list, data);
  10912. +}
  10913. +
  10914. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
  10915. +{
  10916. + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
  10917. +}
  10918. diff -Nur busybox-1.18.1.orig/archival/libipkg/pkg_dest_list.h busybox-1.18.1/archival/libipkg/pkg_dest_list.h
  10919. --- busybox-1.18.1.orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
  10920. +++ busybox-1.18.1/archival/libipkg/pkg_dest_list.h 2010-12-25 22:38:07.000000000 +0100
  10921. @@ -0,0 +1,50 @@
  10922. +/* pkg_dest_list.h - the itsy package management system
  10923. +
  10924. + Carl D. Worth
  10925. +
  10926. + Copyright (C) 2001 University of Southern California
  10927. +
  10928. + This program is free software; you can redistribute it and/or
  10929. + modify it under the terms of the GNU General Public License as
  10930. + published by the Free Software Foundation; either version 2, or (at
  10931. + your option) any later version.
  10932. +
  10933. + This program is distributed in the hope that it will be useful, but
  10934. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10935. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10936. + General Public License for more details.
  10937. +*/
  10938. +
  10939. +#ifndef PKG_DEST_LIST_H
  10940. +#define PKG_DEST_LIST_H
  10941. +
  10942. +#include "pkg_dest.h"
  10943. +
  10944. +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
  10945. +struct pkg_dest_list_elt
  10946. +{
  10947. + pkg_dest_list_elt_t *next;
  10948. + pkg_dest_t *data;
  10949. +};
  10950. +
  10951. +typedef struct pkg_dest_list pkg_dest_list_t;
  10952. +struct pkg_dest_list
  10953. +{
  10954. + pkg_dest_list_elt_t pre_head;
  10955. + pkg_dest_list_elt_t *head;
  10956. + pkg_dest_list_elt_t *tail;
  10957. +};
  10958. +
  10959. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
  10960. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
  10961. +
  10962. +int pkg_dest_list_init(pkg_dest_list_t *list);
  10963. +void pkg_dest_list_deinit(pkg_dest_list_t *list);
  10964. +
  10965. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10966. + const char *root_dir,const char* lists_dir);
  10967. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
  10968. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
  10969. +
  10970. +#endif
  10971. +
  10972. diff -Nur busybox-1.18.1.orig/archival/libipkg/pkg_extract.c busybox-1.18.1/archival/libipkg/pkg_extract.c
  10973. --- busybox-1.18.1.orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
  10974. +++ busybox-1.18.1/archival/libipkg/pkg_extract.c 2010-12-25 22:48:39.000000000 +0100
  10975. @@ -0,0 +1,255 @@
  10976. +/* pkg_extract.c - the itsy package management system
  10977. +
  10978. + Carl D. Worth
  10979. +
  10980. + Copyright (C) 2001 University of Southern California
  10981. +
  10982. + This program is free software; you can redistribute it and/or
  10983. + modify it under the terms of the GNU General Public License as
  10984. + published by the Free Software Foundation; either version 2, or (at
  10985. + your option) any later version.
  10986. +
  10987. + This program is distributed in the hope that it will be useful, but
  10988. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10989. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10990. + General Public License for more details.
  10991. +*/
  10992. +
  10993. +#include "ipkg.h"
  10994. +#include <errno.h>
  10995. +#include <fcntl.h>
  10996. +#include <stdio.h>
  10997. +
  10998. +#include "pkg_extract.h"
  10999. +
  11000. +#include "libbb.h"
  11001. +#include "file_util.h"
  11002. +#include "sprintf_alloc.h"
  11003. +#include "archive.h"
  11004. +
  11005. +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
  11006. +#define IPKG_DATA_ARCHIVE "data.tar.gz"
  11007. +#define IPKG_CONTROL_FILE "control"
  11008. +
  11009. +static void FAST_FUNC ipkg_data_extract_all_prefix(archive_handle_t *archive_handle)
  11010. +{
  11011. + char *name_ptr = archive_handle->file_header->name;
  11012. +
  11013. + /* Skip all leading "/" */
  11014. + while (*name_ptr == '/')
  11015. + name_ptr++;
  11016. + /* Skip all leading "./" and "../" */
  11017. + while (name_ptr[0] == '.') {
  11018. + if (name_ptr[1] == '.' && name_ptr[2] == '/')
  11019. + name_ptr++;
  11020. + if (name_ptr[1] != '/')
  11021. + break;
  11022. + name_ptr += 2;
  11023. + }
  11024. +
  11025. + if (name_ptr[0] != '\0') {
  11026. + archive_handle->file_header->name = xasprintf("%s%s", archive_handle->dpkg__buffer, name_ptr);
  11027. + data_extract_all(archive_handle);
  11028. + }
  11029. +}
  11030. +
  11031. +static void FAST_FUNC ipkg_data_extract_to_buffer(archive_handle_t *archive_handle)
  11032. +{
  11033. + unsigned size = archive_handle->file_header->size;
  11034. +
  11035. + archive_handle->dpkg__buffer = xzalloc(size + 1);
  11036. + xread(archive_handle->src_fd, archive_handle->dpkg__buffer, size);
  11037. +}
  11038. +
  11039. +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
  11040. +{
  11041. + archive_handle_t *archive;
  11042. + char *path;
  11043. +
  11044. + sprintf_alloc(&path, "%s/", dir);
  11045. + archive = init_handle();
  11046. + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
  11047. + archive->filter = filter_accept_list;
  11048. + llist_add_to(&(archive->accept), (char *)filename);
  11049. + archive->dpkg__buffer = path;
  11050. + archive->action_data = ipkg_data_extract_all_prefix;
  11051. + archive->ah_flags |= ARCHIVE_UNLINK_OLD;
  11052. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11053. + close(archive->src_fd);
  11054. + free(archive->accept);
  11055. + free(archive);
  11056. + free(path);
  11057. +}
  11058. +
  11059. +static void FAST_FUNC data_extract_file_name_to_buffer(archive_handle_t *archive)
  11060. +{
  11061. + unsigned int size = strlen(archive->file_header->name) + 2;
  11062. +
  11063. + if (archive->dpkg__buffer == NULL) {
  11064. + archive->dpkg__buffer = xmalloc(size);
  11065. + strcpy(archive->dpkg__buffer, archive->file_header->name);
  11066. + } else {
  11067. + size += strlen(archive->dpkg__buffer);
  11068. + archive->dpkg__buffer = xrealloc(archive->dpkg__buffer, size);
  11069. + strcat(archive->dpkg__buffer, archive->file_header->name);
  11070. + }
  11071. + strcat(archive->dpkg__buffer, "\n");
  11072. + data_skip(archive);
  11073. +}
  11074. +
  11075. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
  11076. +{
  11077. + archive_handle_t *archive;
  11078. + char *name;
  11079. + const char *filename = IPKG_CONTROL_FILE;
  11080. +
  11081. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  11082. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  11083. + archive = init_handle();
  11084. + archive->src_fd = xopen(name, O_RDONLY);
  11085. + archive->filter = filter_accept_list;
  11086. + llist_add_to(&(archive->accept), (char *)filename);
  11087. + archive->action_data = ipkg_data_extract_to_buffer;
  11088. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11089. + close(archive->src_fd);
  11090. + fputs(archive->dpkg__buffer, stream);
  11091. + free(archive->dpkg__buffer);
  11092. + free(archive->accept);
  11093. + free(archive);
  11094. + free(name);
  11095. +
  11096. + return 0;
  11097. +}
  11098. +
  11099. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
  11100. +{
  11101. + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
  11102. +}
  11103. +
  11104. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
  11105. +{
  11106. + archive_handle_t *archive;
  11107. + char *name;
  11108. + char *path;
  11109. +
  11110. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  11111. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  11112. + sprintf_alloc(&path, "%s/%s", dir, prefix);
  11113. + archive = init_handle();
  11114. + archive->src_fd = xopen(name, O_RDONLY);
  11115. + archive->filter = filter_accept_all;
  11116. + archive->dpkg__buffer = path;
  11117. + archive->action_data = ipkg_data_extract_all_prefix;
  11118. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  11119. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11120. + close(archive->src_fd);
  11121. + free(archive);
  11122. + free(path);
  11123. + free(name);
  11124. +
  11125. + return 0;
  11126. +}
  11127. +
  11128. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
  11129. +{
  11130. + archive_handle_t *archive;
  11131. + char *name;
  11132. + char *path;
  11133. +
  11134. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  11135. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  11136. + sprintf_alloc(&path, "%s/", dir);
  11137. + archive = init_handle();
  11138. + archive->src_fd = xopen(name, O_RDONLY);
  11139. + archive->filter = filter_accept_all;
  11140. + archive->dpkg__buffer = path;
  11141. + archive->action_data = ipkg_data_extract_all_prefix;
  11142. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  11143. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11144. + close(archive->src_fd);
  11145. + free(archive);
  11146. + free(path);
  11147. + free(name);
  11148. +
  11149. + return 0;
  11150. +}
  11151. +
  11152. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
  11153. +{
  11154. + int err=0;
  11155. + char *line, *data_file;
  11156. + FILE *file;
  11157. + FILE *tmp;
  11158. +
  11159. + file = fopen(file_name, "w");
  11160. + if (file == NULL) {
  11161. + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
  11162. + __FUNCTION__, file_name);
  11163. + return EINVAL;
  11164. + }
  11165. +
  11166. + tmp = tmpfile();
  11167. + if (pkg->installed_files) {
  11168. + str_list_elt_t *elt;
  11169. + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
  11170. + fprintf(file, "%s\n", elt->data);
  11171. + }
  11172. + } else {
  11173. + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
  11174. + if (err) {
  11175. + fclose(file);
  11176. + fclose(tmp);
  11177. + return err;
  11178. + }
  11179. +
  11180. + /* Fixup data file names by removing the initial '.' */
  11181. + rewind(tmp);
  11182. + while (1) {
  11183. + line = file_read_line_alloc(tmp);
  11184. + if (line == NULL) {
  11185. + break;
  11186. + }
  11187. +
  11188. + data_file = line;
  11189. + if (*data_file == '.') {
  11190. + data_file++;
  11191. + }
  11192. +
  11193. + if (*data_file != '/') {
  11194. + fputs("/", file);
  11195. + }
  11196. +
  11197. + /* I have no idea why, but this is what dpkg does */
  11198. + if (strcmp(data_file, "/\n") == 0) {
  11199. + fputs("/.\n", file);
  11200. + } else {
  11201. + fputs(data_file, file);
  11202. + }
  11203. + }
  11204. + }
  11205. + fclose(tmp);
  11206. + fclose(file);
  11207. +
  11208. + return err;
  11209. +}
  11210. +
  11211. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
  11212. +{
  11213. + archive_handle_t *archive;
  11214. + char *name;
  11215. +
  11216. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  11217. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  11218. + archive = init_handle();
  11219. + archive->src_fd = xopen(name, O_RDONLY);
  11220. + archive->filter = filter_accept_all;
  11221. + archive->action_data = data_extract_file_name_to_buffer;
  11222. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11223. + close(archive->src_fd);
  11224. + fputs(archive->dpkg__buffer, file);
  11225. + free(archive->dpkg__buffer);
  11226. + free(archive);
  11227. + free(name);
  11228. +
  11229. + return 0;
  11230. +}
  11231. diff -Nur busybox-1.18.1.orig/archival/libipkg/pkg_extract.h busybox-1.18.1/archival/libipkg/pkg_extract.h
  11232. --- busybox-1.18.1.orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
  11233. +++ busybox-1.18.1/archival/libipkg/pkg_extract.h 2010-12-25 22:38:07.000000000 +0100
  11234. @@ -0,0 +1,32 @@
  11235. +/* pkg_extract.c - the itsy package management system
  11236. +
  11237. + Carl D. Worth
  11238. +
  11239. + Copyright (C) 2001 University of Southern California
  11240. +
  11241. + This program is free software; you can redistribute it and/or
  11242. + modify it under the terms of the GNU General Public License as
  11243. + published by the Free Software Foundation; either version 2, or (at
  11244. + your option) any later version.
  11245. +
  11246. + This program is distributed in the hope that it will be useful, but
  11247. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11248. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11249. + General Public License for more details.
  11250. +*/
  11251. +
  11252. +#ifndef PKG_EXTRACT_H
  11253. +#define PKG_EXTRACT_H
  11254. +
  11255. +#include "pkg.h"
  11256. +
  11257. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
  11258. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
  11259. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
  11260. + const char *dir,
  11261. + const char *prefix);
  11262. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
  11263. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
  11264. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
  11265. +
  11266. +#endif
  11267. diff -Nur busybox-1.18.1.orig/archival/libipkg/pkg_hash.c busybox-1.18.1/archival/libipkg/pkg_hash.c
  11268. --- busybox-1.18.1.orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
  11269. +++ busybox-1.18.1/archival/libipkg/pkg_hash.c 2010-12-25 22:38:07.000000000 +0100
  11270. @@ -0,0 +1,623 @@
  11271. +/* ipkg_hash.c - the itsy package management system
  11272. +
  11273. + Steven M. Ayer
  11274. +
  11275. + Copyright (C) 2002 Compaq Computer Corporation
  11276. +
  11277. + This program is free software; you can redistribute it and/or
  11278. + modify it under the terms of the GNU General Public License as
  11279. + published by the Free Software Foundation; either version 2, or (at
  11280. + your option) any later version.
  11281. +
  11282. + This program is distributed in the hope that it will be useful, but
  11283. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11284. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11285. + General Public License for more details.
  11286. +*/
  11287. +
  11288. +#include "ipkg.h"
  11289. +#include <errno.h>
  11290. +#include <ctype.h>
  11291. +#include <stdlib.h>
  11292. +#include <string.h>
  11293. +
  11294. +#include "hash_table.h"
  11295. +#include "pkg.h"
  11296. +#include "ipkg_message.h"
  11297. +#include "pkg_vec.h"
  11298. +#include "pkg_hash.h"
  11299. +#include "pkg_parse.h"
  11300. +#include "ipkg_utils.h"
  11301. +
  11302. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11303. +
  11304. +/*
  11305. + * this will talk to both feeds-lists files and installed status files
  11306. + * example api:
  11307. + *
  11308. + * hash_table_t hash;
  11309. + * pkg_hash_init(name, &hash, 1000);
  11310. + * pkg_hash_add_from_file(<feed filename>);
  11311. + *
  11312. + * the query function is just there as a shell to prove to me that this
  11313. + * sort of works, but isn't far from doing something useful
  11314. + *
  11315. + * -sma, 12/21/01
  11316. + * modified: CDW 3 Jan. 2002
  11317. + */
  11318. +
  11319. +
  11320. +
  11321. +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
  11322. +{
  11323. + return hash_table_init(name, hash, len);
  11324. +}
  11325. +
  11326. +void pkg_hash_deinit(hash_table_t *hash)
  11327. +{
  11328. + hash_table_deinit(hash);
  11329. +}
  11330. +
  11331. +
  11332. +/* Find the default arch for a given package status file if none is given. */
  11333. +static char *pkg_get_default_arch(ipkg_conf_t *conf)
  11334. +{
  11335. + nv_pair_list_elt_t *l;
  11336. + const char *def_arch = HOST_CPU_STR; /* Default arch */
  11337. + int def_prio = 0; /* Other archs override this */
  11338. +
  11339. + l = conf->arch_list.head;
  11340. +
  11341. + while (l) {
  11342. + nv_pair_t *nv = l->data;
  11343. + int priority = strtol(nv->value, NULL, 0);
  11344. +
  11345. + /* Check if this arch has higher priority, and is valid */
  11346. + if ((priority > def_prio) &&
  11347. + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
  11348. + /* Our new default */
  11349. + def_prio = priority;
  11350. + def_arch = nv->name;
  11351. + }
  11352. + l = l->next;
  11353. + }
  11354. +
  11355. + return strdup(def_arch);
  11356. +}
  11357. +
  11358. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11359. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
  11360. +{
  11361. + hash_table_t *hash = &conf->pkg_hash;
  11362. + char **raw;
  11363. + char **raw_start;
  11364. + pkg_t *pkg;
  11365. +
  11366. + raw = raw_start = read_raw_pkgs_from_file(file_name);
  11367. + if (!raw)
  11368. + return -ENOMEM;
  11369. +
  11370. + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
  11371. + pkg = pkg_new();
  11372. + if (!pkg)
  11373. + return -ENOMEM;
  11374. +
  11375. + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
  11376. + if (!pkg->architecture) {
  11377. + char *version_str = pkg_version_str_alloc(pkg);
  11378. + pkg->architecture = pkg_get_default_arch(conf);
  11379. + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
  11380. + pkg->name, version_str, pkg->architecture);
  11381. + free(version_str);
  11382. + }
  11383. + hash_insert_pkg(hash, pkg, is_status_file,conf);
  11384. + } else {
  11385. + free(pkg);
  11386. + }
  11387. + }
  11388. +
  11389. + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
  11390. + memory after read_raw_pkgs_from_file */
  11391. + raw = raw_start;
  11392. + while (*raw) {
  11393. + free(*raw++);
  11394. + }
  11395. + free(raw_start);
  11396. + return 0;
  11397. +}
  11398. +
  11399. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
  11400. +{
  11401. + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
  11402. +}
  11403. +
  11404. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
  11405. +{
  11406. + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
  11407. + if (apkg)
  11408. + return NULL;
  11409. + return apkg->provided_by;
  11410. +}
  11411. +
  11412. +
  11413. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11414. + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
  11415. +{
  11416. + int i;
  11417. + int nprovides = 0;
  11418. + int nmatching = 0;
  11419. + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
  11420. + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
  11421. + abstract_pkg_vec_t *provided_apkg_vec;
  11422. + abstract_pkg_t **provided_apkgs;
  11423. + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
  11424. + pkg_t *latest_installed_parent = NULL;
  11425. + pkg_t *latest_matching = NULL;
  11426. + pkg_t *held_pkg = NULL;
  11427. + pkg_t *good_pkg_by_name = NULL;
  11428. +
  11429. + if (matching_apkgs == NULL || providers == NULL ||
  11430. + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
  11431. + return NULL;
  11432. +
  11433. + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
  11434. +
  11435. + provided_apkg_vec = apkg->provided_by;
  11436. + nprovides = provided_apkg_vec->len;
  11437. + provided_apkgs = provided_apkg_vec->pkgs;
  11438. + if (nprovides > 1)
  11439. + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
  11440. +
  11441. + /* accumulate all the providers */
  11442. + for (i = 0; i < nprovides; i++) {
  11443. + abstract_pkg_t *provider_apkg = provided_apkgs[i];
  11444. + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
  11445. + abstract_pkg_vec_insert(providers, provider_apkg);
  11446. + }
  11447. + nprovides = providers->len;
  11448. +
  11449. + for (i = 0; i < nprovides; i++) {
  11450. + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
  11451. + abstract_pkg_t *replacement_apkg = NULL;
  11452. + pkg_vec_t *vec;
  11453. +
  11454. + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
  11455. + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
  11456. + if (provider_apkg->replaced_by->len > 1) {
  11457. + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
  11458. + provider_apkg->name, replacement_apkg->name);
  11459. + }
  11460. + }
  11461. +
  11462. + if (replacement_apkg)
  11463. + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
  11464. + replacement_apkg->name, provider_apkg->name);
  11465. +
  11466. + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
  11467. + if (abstract_pkg_vec_contains(providers, replacement_apkg))
  11468. + continue;
  11469. + else
  11470. + provider_apkg = replacement_apkg;
  11471. + }
  11472. +
  11473. + if (!(vec = provider_apkg->pkgs)) {
  11474. + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
  11475. + continue;
  11476. + }
  11477. +
  11478. +
  11479. + /* now check for supported architecture */
  11480. + {
  11481. + int max_count = 0;
  11482. + int j;
  11483. +
  11484. + /* count packages matching max arch priority and keep track of last one */
  11485. + for (j = 0; j < vec->len; j++) {
  11486. + pkg_t *maybe = vec->pkgs[j];
  11487. + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
  11488. + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
  11489. + if (maybe->arch_priority > 0) {
  11490. + max_count++;
  11491. + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
  11492. + pkg_vec_insert(matching_pkgs, maybe);
  11493. + }
  11494. + }
  11495. + }
  11496. + }
  11497. +
  11498. + if (matching_pkgs->len > 1)
  11499. + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
  11500. + if (matching_apkgs->len > 1)
  11501. + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
  11502. +
  11503. +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
  11504. + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
  11505. +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
  11506. + Until now I always got the latest, but that breaks the downgrade option.
  11507. + If I stop at the first one, I would probably miss the new ones
  11508. + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
  11509. + or from a Packages feed.
  11510. + 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*/
  11511. +/*Pigi*/
  11512. +
  11513. + for (i = 0; i < matching_pkgs->len; i++) {
  11514. + pkg_t *matching = matching_pkgs->pkgs[i];
  11515. + if (constraint_fcn(matching, cdata)) { /* We found it */
  11516. + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
  11517. + good_pkg_by_name = matching;
  11518. + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
  11519. + break;
  11520. + }
  11521. + }
  11522. +
  11523. +
  11524. + for (i = 0; i < matching_pkgs->len; i++) {
  11525. + pkg_t *matching = matching_pkgs->pkgs[i];
  11526. + latest_matching = matching;
  11527. + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
  11528. + latest_installed_parent = matching;
  11529. + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
  11530. + if (held_pkg)
  11531. + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
  11532. + held_pkg->name, matching->name);
  11533. + held_pkg = matching;
  11534. + }
  11535. + }
  11536. +
  11537. + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
  11538. + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
  11539. + apkg->name, matching_apkgs->len);
  11540. + for (i = 0; i < matching_apkgs->len; i++) {
  11541. + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
  11542. + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
  11543. + }
  11544. + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
  11545. + }
  11546. +
  11547. + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
  11548. + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
  11549. + __FUNCTION__, apkg->name, matching_pkgs->len);
  11550. + for (i = 0; i < matching_pkgs->len; i++) {
  11551. + pkg_t *matching = matching_pkgs->pkgs[i];
  11552. + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
  11553. + matching->name, matching->version, matching->architecture);
  11554. + }
  11555. + }
  11556. +
  11557. + nmatching = matching_apkgs->len;
  11558. +
  11559. + pkg_vec_free(matching_pkgs);
  11560. + abstract_pkg_vec_free(matching_apkgs);
  11561. + abstract_pkg_vec_free(providers);
  11562. +
  11563. + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
  11564. + return good_pkg_by_name;
  11565. + }
  11566. + if (held_pkg) {
  11567. + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
  11568. + return held_pkg;
  11569. + }
  11570. + if (latest_installed_parent) {
  11571. + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
  11572. + return latest_installed_parent;
  11573. + }
  11574. + if (nmatching > 1) {
  11575. + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
  11576. + return NULL;
  11577. + }
  11578. + if (latest_matching) {
  11579. + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
  11580. + latest_matching->name, latest_matching->version, latest_matching->architecture);
  11581. + return latest_matching;
  11582. + }
  11583. + return NULL;
  11584. +}
  11585. +
  11586. +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
  11587. +{
  11588. + const char *name = (const char *)cdata;
  11589. + if (strcmp(pkg->name, name) == 0)
  11590. + return 1;
  11591. + else
  11592. + return 0;
  11593. +}
  11594. +
  11595. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
  11596. +{
  11597. + hash_table_t *hash = &conf->pkg_hash;
  11598. + abstract_pkg_t *apkg = NULL;
  11599. +
  11600. + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
  11601. + return NULL;
  11602. +
  11603. + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
  11604. +}
  11605. +
  11606. +
  11607. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11608. + const char *pkg_name,
  11609. + const char * version)
  11610. +{
  11611. + pkg_vec_t * vec;
  11612. + register int i;
  11613. + char *version_str = NULL;
  11614. +
  11615. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
  11616. + return NULL;
  11617. +
  11618. + for(i = 0; i < vec->len; i++) {
  11619. + version_str = pkg_version_str_alloc(vec->pkgs[i]);
  11620. + if(!strcmp(version_str, version)) {
  11621. + free(version_str);
  11622. + break;
  11623. + }
  11624. + free(version_str);
  11625. + }
  11626. +
  11627. + if(i == vec->len)
  11628. + return NULL;
  11629. +
  11630. + return vec->pkgs[i];
  11631. +}
  11632. +
  11633. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11634. + const char *pkg_name,
  11635. + pkg_dest_t *dest)
  11636. +{
  11637. + pkg_vec_t * vec;
  11638. + register int i;
  11639. +
  11640. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
  11641. + return NULL;
  11642. + }
  11643. +
  11644. + for(i = 0; i < vec->len; i++)
  11645. + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
  11646. + return vec->pkgs[i];
  11647. + }
  11648. + return NULL;
  11649. +}
  11650. +
  11651. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11652. + const char *pkg_name)
  11653. +{
  11654. + pkg_vec_t * vec;
  11655. + register int i;
  11656. +
  11657. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
  11658. + return NULL;
  11659. + }
  11660. +
  11661. + for(i = 0; i < vec->len; i++)
  11662. + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
  11663. + return vec->pkgs[i];
  11664. + }
  11665. +
  11666. + return NULL;
  11667. +}
  11668. +
  11669. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
  11670. +{
  11671. + abstract_pkg_t * ab_pkg;
  11672. +
  11673. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
  11674. + return NULL;
  11675. + }
  11676. +
  11677. + if (ab_pkg->pkgs) {
  11678. + return ab_pkg->pkgs;
  11679. + } else if (ab_pkg->provided_by) {
  11680. + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
  11681. + if (abpkg != NULL){
  11682. + return abpkg->pkgs;
  11683. + } else {
  11684. + return ab_pkg->pkgs;
  11685. + }
  11686. + } else {
  11687. + return NULL;
  11688. + }
  11689. +}
  11690. +
  11691. +static int pkg_compare_names(const void *p1, const void *p2)
  11692. +{
  11693. + const pkg_t *pkg1 = *(const pkg_t **)p1;
  11694. + const pkg_t *pkg2 = *(const pkg_t **)p2;
  11695. + if (pkg1->name == NULL)
  11696. + return 1;
  11697. + if (pkg2->name == NULL)
  11698. + return -1;
  11699. + return(strcmp(pkg1->name, pkg2->name));
  11700. +}
  11701. +
  11702. +
  11703. +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
  11704. +{
  11705. + int j;
  11706. + const char *name;
  11707. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11708. + pkg_vec_t *all = (pkg_vec_t *)data;
  11709. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11710. + name = pkg_name;
  11711. + if (pkg_vec) {
  11712. + for (j = 0; j < pkg_vec->len; j++) {
  11713. + pkg_t *pkg = pkg_vec->pkgs[j];
  11714. + pkg_vec_insert(all, pkg);
  11715. + }
  11716. + }
  11717. +}
  11718. +
  11719. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
  11720. +{
  11721. + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
  11722. + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
  11723. +}
  11724. +
  11725. +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
  11726. +{
  11727. + const char *name;
  11728. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11729. + pkg_vec_t *all = (pkg_vec_t *)data;
  11730. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11731. + int j;
  11732. + name = pkg_name;
  11733. + if (pkg_vec) {
  11734. + for (j = 0; j < pkg_vec->len; j++) {
  11735. + pkg_t *pkg = pkg_vec->pkgs[j];
  11736. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  11737. + pkg_vec_insert(all, pkg);
  11738. + }
  11739. + }
  11740. + }
  11741. +}
  11742. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
  11743. +{
  11744. + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
  11745. + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
  11746. +}
  11747. +
  11748. +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
  11749. +{
  11750. + int i;
  11751. + pkg_t *pkg;
  11752. + const char *name;
  11753. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11754. + ipkg_conf_t *conf = (ipkg_conf_t *)data;
  11755. + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
  11756. + name = pkg_name;
  11757. + fprintf(stdout, "%s\n", ab_pkg->name);
  11758. + i = 0;
  11759. + if (dependents != NULL)
  11760. + while (dependents [i] != NULL)
  11761. + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
  11762. + dependents = ab_pkg->provided_by->pkgs;
  11763. + i = 0;
  11764. + if (dependents != NULL)
  11765. + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
  11766. + printf ("\tprovided by - %s\n", dependents [i ++]->name);
  11767. + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
  11768. + if (pkg) {
  11769. + i = 0;
  11770. + while (i < pkg->depends_count)
  11771. + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
  11772. + }
  11773. +}
  11774. +void pkg_hash_dump(hash_table_t *hash, void *data)
  11775. +{
  11776. +
  11777. + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
  11778. + hash_table_foreach(hash, pkg_hash_dump_helper, data);
  11779. + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
  11780. +}
  11781. +
  11782. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11783. +{
  11784. + abstract_pkg_t * ab_pkg;
  11785. +
  11786. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
  11787. + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
  11788. +
  11789. + return ab_pkg;
  11790. +}
  11791. +
  11792. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  11793. +{
  11794. + abstract_pkg_t * ab_pkg;
  11795. + int arch_priority;
  11796. +
  11797. + if(!pkg)
  11798. + return pkg;
  11799. +
  11800. + arch_priority = pkg->arch_priority;
  11801. +
  11802. + if (buildDepends(hash, pkg)<0){
  11803. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11804. + return NULL;
  11805. + }
  11806. + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
  11807. +
  11808. + if (set_status) {
  11809. + if (pkg->state_status == SS_INSTALLED) {
  11810. + ab_pkg->state_status = SS_INSTALLED;
  11811. + } else if (pkg->state_status == SS_UNPACKED) {
  11812. + ab_pkg->state_status = SS_UNPACKED;
  11813. + }
  11814. + }
  11815. +
  11816. + if(!ab_pkg->pkgs)
  11817. + ab_pkg->pkgs = pkg_vec_alloc();
  11818. +
  11819. + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
  11820. + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
  11821. + pkg->parent = ab_pkg;
  11822. +
  11823. + if (buildProvides(hash, ab_pkg, pkg)<0){
  11824. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11825. + return NULL;
  11826. + }
  11827. + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
  11828. + if (buildConflicts(hash, pkg)<0){
  11829. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11830. + return NULL;
  11831. + }
  11832. + if (buildReplaces(hash, ab_pkg, pkg)<0) {
  11833. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11834. + return NULL;
  11835. + }
  11836. +
  11837. + buildDependedUponBy(pkg, ab_pkg);
  11838. + return pkg;
  11839. +}
  11840. +
  11841. +/*
  11842. + * this will assume that we've already determined that
  11843. + * the abstract pkg doesn't exist, 'cause we should know these things...
  11844. + */
  11845. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11846. +{
  11847. + abstract_pkg_t * ab_pkg;
  11848. +
  11849. + ab_pkg = abstract_pkg_new();
  11850. + if (ab_pkg == NULL) { return NULL; }
  11851. +
  11852. + ab_pkg->name = strdup(pkg_name);
  11853. + hash_table_insert(hash, pkg_name, ab_pkg);
  11854. +
  11855. + return ab_pkg;
  11856. +}
  11857. +
  11858. +
  11859. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
  11860. +{
  11861. + hash_table_t *file_hash = &conf->file_hash;
  11862. +
  11863. + return hash_table_get(file_hash, file_name);
  11864. +}
  11865. +
  11866. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
  11867. +{
  11868. + hash_table_t *file_hash = &conf->file_hash;
  11869. + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
  11870. + int file_name_len = strlen(file_name);
  11871. +
  11872. + if (file_name[file_name_len -1] == '/')
  11873. + return 0;
  11874. +
  11875. + if (conf->offline_root) {
  11876. + int len = strlen(conf->offline_root);
  11877. + if (strncmp(file_name, conf->offline_root, len) == 0) {
  11878. + file_name += len;
  11879. + }
  11880. + }
  11881. +
  11882. + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
  11883. + hash_table_insert(file_hash, file_name, owning_pkg);
  11884. + if (old_owning_pkg) {
  11885. + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
  11886. + /* mark this package to have its filelist written */
  11887. + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11888. + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11889. + }
  11890. + return 0;
  11891. +}
  11892. +
  11893. +
  11894. diff -Nur busybox-1.18.1.orig/archival/libipkg/pkg_hash.h busybox-1.18.1/archival/libipkg/pkg_hash.h
  11895. --- busybox-1.18.1.orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
  11896. +++ busybox-1.18.1/archival/libipkg/pkg_hash.h 2010-12-25 22:38:07.000000000 +0100
  11897. @@ -0,0 +1,61 @@
  11898. +/* pkg_hash.h - the itsy package management system
  11899. +
  11900. + Steven M. Ayer
  11901. +
  11902. + Copyright (C) 2002 Compaq Computer Corporation
  11903. +
  11904. + This program is free software; you can redistribute it and/or
  11905. + modify it under the terms of the GNU General Public License as
  11906. + published by the Free Software Foundation; either version 2, or (at
  11907. + your option) any later version.
  11908. +
  11909. + This program is distributed in the hope that it will be useful, but
  11910. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11911. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11912. + General Public License for more details.
  11913. +*/
  11914. +
  11915. +#ifndef PKG_HASH_H
  11916. +#define PKG_HASH_H
  11917. +
  11918. +#include "pkg.h"
  11919. +#include "pkg_vec.h"
  11920. +#include "hash_table.h"
  11921. +
  11922. +
  11923. +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
  11924. +void pkg_hash_deinit(hash_table_t *hash);
  11925. +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
  11926. +
  11927. +void pkg_hash_dump(hash_table_t *hash, void *data);
  11928. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
  11929. +
  11930. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11931. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
  11932. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
  11933. +
  11934. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11935. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
  11936. +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11937. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
  11938. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11939. + const char *pkg_name,
  11940. + const char * version);
  11941. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
  11942. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11943. + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
  11944. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
  11945. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11946. + const char *pkg_name);
  11947. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11948. + const char *pkg_name,
  11949. + pkg_dest_t *dest);
  11950. +
  11951. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
  11952. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
  11953. +
  11954. +/* XXX: shouldn't this go in pkg_vec.[ch]? */
  11955. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11956. +
  11957. +#endif
  11958. +
  11959. diff -Nur busybox-1.18.1.orig/archival/libipkg/pkg_parse.c busybox-1.18.1/archival/libipkg/pkg_parse.c
  11960. --- busybox-1.18.1.orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
  11961. +++ busybox-1.18.1/archival/libipkg/pkg_parse.c 2010-12-25 22:38:07.000000000 +0100
  11962. @@ -0,0 +1,368 @@
  11963. +/* pkg_parse.c - the itsy package management system
  11964. +
  11965. + Steven M. Ayer
  11966. +
  11967. + Copyright (C) 2002 Compaq Computer Corporation
  11968. +
  11969. + This program is free software; you can redistribute it and/or
  11970. + modify it under the terms of the GNU General Public License as
  11971. + published by the Free Software Foundation; either version 2, or (at
  11972. + your option) any later version.
  11973. +
  11974. + This program is distributed in the hope that it will be useful, but
  11975. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11976. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11977. + General Public License for more details.
  11978. +*/
  11979. +
  11980. +#include "ipkg.h"
  11981. +#include <errno.h>
  11982. +#include <ctype.h>
  11983. +
  11984. +#include "pkg.h"
  11985. +#include "ipkg_utils.h"
  11986. +#include "pkg_parse.h"
  11987. +
  11988. +int alterProvidesLine(char *raw, char *temp);
  11989. +
  11990. +int isGenericFieldType(char * type, char * line)
  11991. +{
  11992. + if(!strncmp(line, type, strlen(type)))
  11993. + return 1;
  11994. + return 0;
  11995. +}
  11996. +
  11997. +char * parseGenericFieldType(char * type, char * raw)
  11998. +{
  11999. + char * field_value = raw + (strlen(type) + 1);
  12000. + return trim_alloc(field_value);
  12001. +}
  12002. +
  12003. +void parseStatus(pkg_t *pkg, char * raw)
  12004. +{
  12005. + char sw_str[64], sf_str[64], ss_str[64];
  12006. +
  12007. + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
  12008. + pkg->state_want = pkg_state_want_from_str(sw_str);
  12009. + pkg->state_flag = pkg_state_flag_from_str(sf_str);
  12010. + pkg->state_status = pkg_state_status_from_str(ss_str);
  12011. +}
  12012. +
  12013. +char ** parseDependsString(char * raw, int * depends_count)
  12014. +{
  12015. + char ** depends = NULL;
  12016. + int line_count = 0;
  12017. + char buff[2048], * dest;
  12018. +
  12019. + while(raw && *raw && !isspace(*raw)) {
  12020. + raw++;
  12021. + }
  12022. +
  12023. + if(line_is_blank(raw)){
  12024. + *depends_count = line_count;
  12025. + return NULL;
  12026. + }
  12027. + while(raw && *raw){
  12028. + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
  12029. +
  12030. + while(isspace(*raw)) raw++;
  12031. +
  12032. + dest = buff;
  12033. + while((*raw != ',') && *raw)
  12034. + *dest++ = *raw++;
  12035. +
  12036. + *dest = '\0';
  12037. + depends[line_count] = trim_alloc(buff);
  12038. + if(depends[line_count] ==NULL)
  12039. + return NULL;
  12040. + line_count++;
  12041. + if(*raw == ',')
  12042. + raw++;
  12043. + }
  12044. + *depends_count = line_count;
  12045. + return depends;
  12046. +}
  12047. +
  12048. +void parseConffiles(pkg_t * pkg, char * raw)
  12049. +{
  12050. + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
  12051. +
  12052. + if(!strncmp(raw, "Conffiles:", 10))
  12053. + raw += strlen("Conffiles:");
  12054. +
  12055. + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
  12056. + conffile_list_append(&pkg->conffiles, file_name, md5sum);
  12057. + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
  12058. + while (*raw && isspace(*raw)) {
  12059. + raw++;
  12060. + }
  12061. + raw += strlen(file_name);
  12062. + while (*raw && isspace(*raw)) {
  12063. + raw++;
  12064. + }
  12065. + raw += strlen(md5sum);
  12066. + }
  12067. +}
  12068. +
  12069. +int parseVersion(pkg_t *pkg, char *raw)
  12070. +{
  12071. + char *colon, *eepochcolon;
  12072. +#ifdef USE_DEBVERSION
  12073. + char *hyphen;
  12074. +#endif
  12075. + unsigned long epoch;
  12076. +
  12077. + if (!*raw) {
  12078. + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
  12079. + return EINVAL;
  12080. + }
  12081. +
  12082. + if (strncmp(raw, "Version:", 8) == 0) {
  12083. + raw += 8;
  12084. + }
  12085. + while (*raw && isspace(*raw)) {
  12086. + raw++;
  12087. + }
  12088. +
  12089. + colon= strchr(raw,':');
  12090. + if (colon) {
  12091. + epoch= strtoul(raw,&eepochcolon,10);
  12092. + if (colon != eepochcolon) {
  12093. + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
  12094. + return EINVAL;
  12095. + }
  12096. + if (!*++colon) {
  12097. + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
  12098. + return EINVAL;
  12099. + }
  12100. + raw= colon;
  12101. + pkg->epoch= epoch;
  12102. + } else {
  12103. + pkg->epoch= 0;
  12104. + }
  12105. +
  12106. + pkg->revision = (char *)"";
  12107. + pkg->familiar_revision = (char *)"";
  12108. +
  12109. + pkg->version= malloc(strlen(raw)+1);
  12110. + if ( pkg->version == NULL ) {
  12111. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12112. + return ENOMEM;
  12113. + }
  12114. + strcpy(pkg->version, raw);
  12115. +
  12116. +#ifdef USE_DEBVERSION
  12117. + hyphen= strrchr(pkg->version,'-');
  12118. +
  12119. + if (hyphen) {
  12120. + *hyphen++= 0;
  12121. + if (strncmp("fam", hyphen, 3) == 0) {
  12122. + pkg->familiar_revision=hyphen+3;
  12123. + hyphen= strrchr(pkg->version,'-');
  12124. + if (hyphen) {
  12125. + *hyphen++= 0;
  12126. + pkg->revision = hyphen;
  12127. + }
  12128. + } else {
  12129. + pkg->revision = hyphen;
  12130. + }
  12131. + }
  12132. +#endif
  12133. +
  12134. +/*
  12135. + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
  12136. + pkg->epoch,
  12137. + pkg->version,
  12138. + pkg->revision,
  12139. + pkg->familiar_revision);
  12140. +*/
  12141. +
  12142. + return 0;
  12143. +}
  12144. +
  12145. +
  12146. +/* This code is needed to insert in first position the keyword for the aligning bug */
  12147. +
  12148. +int alterProvidesLine(char *raw, char *temp)
  12149. +{
  12150. +
  12151. +
  12152. + if (!*raw) {
  12153. + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
  12154. + return -EINVAL;
  12155. + }
  12156. +
  12157. + if ( temp == NULL ) {
  12158. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12159. + return -ENOMEM;
  12160. + }
  12161. +
  12162. + if (strncmp(raw, "Provides:", 9) == 0) {
  12163. + raw += 9;
  12164. + }
  12165. + while (*raw && isspace(*raw)) {
  12166. + raw++;
  12167. + }
  12168. +
  12169. + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
  12170. + while (*raw) {
  12171. + strncat( temp, raw++, 1);
  12172. + }
  12173. + return 0;
  12174. +
  12175. +}
  12176. +
  12177. +/* Some random thoughts from Carl:
  12178. +
  12179. + This function could be considerably simplified if we just kept
  12180. + an array of all the generic string-valued field names, and looped
  12181. + through those looking for a match. Also, these fields could perhaps
  12182. + be stored in the package as an array as well, (or, probably better,
  12183. + as an nv_pair_list_t).
  12184. +
  12185. + Fields which require special parsing or storage, (such as Depends:
  12186. + and Status:) could be handled as they are now.
  12187. +*/
  12188. +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
  12189. + to a dependency list. And, since we already have
  12190. + Depends/Pre-Depends and need to add Conflicts, Recommends, and
  12191. + Enhances, perhaps we could generalize all of these and save some
  12192. + code duplication.
  12193. +*/
  12194. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
  12195. +{
  12196. + int reading_conffiles, reading_description;
  12197. + int pkg_false_provides=1;
  12198. + char ** lines;
  12199. + char * provide=NULL;
  12200. +
  12201. + pkg->src = src;
  12202. + pkg->dest = dest;
  12203. +
  12204. + reading_conffiles = reading_description = 0;
  12205. +
  12206. + for (lines = *raw; *lines; lines++) {
  12207. + /* fprintf(stderr, "PARSING %s\n", *lines);*/
  12208. + if(isGenericFieldType((char *)"Package:", *lines))
  12209. + pkg->name = parseGenericFieldType((char *)"Package", *lines);
  12210. + else if(isGenericFieldType((char *)"Architecture:", *lines))
  12211. + pkg->architecture = parseGenericFieldType((char *)"Architecture", *lines);
  12212. + else if(isGenericFieldType((char *)"Filename:", *lines))
  12213. + pkg->filename = parseGenericFieldType((char *)"Filename", *lines);
  12214. + else if(isGenericFieldType((char *)"Section:", *lines))
  12215. + pkg->section = parseGenericFieldType((char *)"Section", *lines);
  12216. + else if(isGenericFieldType((char *)"MD5sum:", *lines))
  12217. + pkg->md5sum = parseGenericFieldType((char *)"MD5sum", *lines);
  12218. + /* The old ipkg wrote out status files with the wrong case for MD5sum,
  12219. + let's parse it either way */
  12220. + else if(isGenericFieldType((char *)"MD5Sum:", *lines))
  12221. + pkg->md5sum = parseGenericFieldType((char *)"MD5Sum", *lines);
  12222. + else if(isGenericFieldType((char *)"Size:", *lines))
  12223. + pkg->size = parseGenericFieldType((char *)"Size", *lines);
  12224. + else if(isGenericFieldType((char *)"Source:", *lines))
  12225. + pkg->source = parseGenericFieldType((char *)"Source", *lines);
  12226. + else if(isGenericFieldType((char *)"Installed-Size:", *lines))
  12227. + pkg->installed_size = parseGenericFieldType((char *)"Installed-Size", *lines);
  12228. + else if(isGenericFieldType((char *)"Installed-Time:", *lines)) {
  12229. + char *time_str = parseGenericFieldType((char *)"Installed-Time", *lines);
  12230. + pkg->installed_time = strtoul(time_str, NULL, 0);
  12231. + } else if(isGenericFieldType((char *)"Priority:", *lines))
  12232. + pkg->priority = parseGenericFieldType((char *)"Priority", *lines);
  12233. + else if(isGenericFieldType((char *)"Essential:", *lines)) {
  12234. + char *essential_value;
  12235. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12236. + if (strcmp(essential_value, "yes") == 0) {
  12237. + pkg->essential = 1;
  12238. + }
  12239. + free(essential_value);
  12240. + }
  12241. + else if(isGenericFieldType((char *)"Status", *lines))
  12242. + parseStatus(pkg, *lines);
  12243. + else if(isGenericFieldType((char *)"Version", *lines))
  12244. + parseVersion(pkg, *lines);
  12245. + else if(isGenericFieldType((char *)"Maintainer", *lines))
  12246. + pkg->maintainer = parseGenericFieldType((char *)"Maintainer", *lines);
  12247. + else if(isGenericFieldType((char *)"Conffiles", *lines)){
  12248. + parseConffiles(pkg, *lines);
  12249. + reading_conffiles = 1;
  12250. + }
  12251. + else if(isGenericFieldType((char *)"Description", *lines)) {
  12252. + pkg->description = parseGenericFieldType((char *)"Description", *lines);
  12253. + reading_conffiles = 0;
  12254. + reading_description = 1;
  12255. + }
  12256. +
  12257. + else if(isGenericFieldType((char *)"Provides", *lines)){
  12258. +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
  12259. + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
  12260. + if ( alterProvidesLine(*lines,provide) ){
  12261. + return EINVAL;
  12262. + }
  12263. + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
  12264. +/* Let's try to hack a bit here.
  12265. + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
  12266. + in alot of other places. We will remove it before writing down the status database */
  12267. + pkg_false_provides=0;
  12268. + free(provide);
  12269. + }
  12270. +
  12271. + else if(isGenericFieldType((char *)"Depends", *lines))
  12272. + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
  12273. + else if(isGenericFieldType((char *)"Pre-Depends", *lines))
  12274. + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
  12275. + else if(isGenericFieldType((char *)"Recommends", *lines))
  12276. + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
  12277. + else if(isGenericFieldType((char *)"Suggests", *lines))
  12278. + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
  12279. + /* Abhaya: support for conflicts */
  12280. + else if(isGenericFieldType((char *)"Conflicts", *lines))
  12281. + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
  12282. + else if(isGenericFieldType((char *)"Replaces", *lines))
  12283. + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
  12284. + else if(line_is_blank(*lines)) {
  12285. + lines++;
  12286. + break;
  12287. + }
  12288. + else if(**lines == ' '){
  12289. + if(reading_description) {
  12290. + /* we already know it's not blank, so the rest of description */
  12291. + pkg->description = realloc(pkg->description,
  12292. + strlen(pkg->description)
  12293. + + 1 + strlen(*lines) + 1);
  12294. + strcat(pkg->description, "\n");
  12295. + strcat(pkg->description, (*lines));
  12296. + }
  12297. + else if(reading_conffiles)
  12298. + parseConffiles(pkg, *lines);
  12299. + }
  12300. + }
  12301. + *raw = lines;
  12302. +/* If the ipk has not a Provides line, we insert our false line */
  12303. + if ( pkg_false_provides==1)
  12304. + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
  12305. +
  12306. + if (pkg->name) {
  12307. + return 0;
  12308. + } else {
  12309. + return EINVAL;
  12310. + }
  12311. +}
  12312. +
  12313. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
  12314. +{
  12315. + char ** lines;
  12316. +
  12317. + for (lines = *raw; *lines; lines++) {
  12318. + if(isGenericFieldType((char *)"Essential:", *lines)) {
  12319. + char *essential_value;
  12320. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12321. + if (strcmp(essential_value, "yes") == 0) {
  12322. + pkg->essential = 1;
  12323. + }
  12324. + free(essential_value);
  12325. + }
  12326. + }
  12327. + *raw = lines;
  12328. +
  12329. + return 0;
  12330. +}
  12331. diff -Nur busybox-1.18.1.orig/archival/libipkg/pkg_parse.h busybox-1.18.1/archival/libipkg/pkg_parse.h
  12332. --- busybox-1.18.1.orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
  12333. +++ busybox-1.18.1/archival/libipkg/pkg_parse.h 2010-12-25 22:38:07.000000000 +0100
  12334. @@ -0,0 +1,31 @@
  12335. +/* pkg_parse.h - the itsy package management system
  12336. +
  12337. + Steven M. Ayer
  12338. +
  12339. + Copyright (C) 2002 Compaq Computer Corporation
  12340. +
  12341. + This program is free software; you can redistribute it and/or
  12342. + modify it under the terms of the GNU General Public License as
  12343. + published by the Free Software Foundation; either version 2, or (at
  12344. + your option) any later version.
  12345. +
  12346. + This program is distributed in the hope that it will be useful, but
  12347. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12348. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12349. + General Public License for more details.
  12350. +*/
  12351. +
  12352. +#ifndef PKG_PARSE_H
  12353. +#define PKG_PARSE_H
  12354. +
  12355. +int isGenericFieldType(char * type, char * line);
  12356. +char * parseGenericFieldType(char * type, char * raw);
  12357. +void parseStatus(pkg_t *pkg, char * raw);
  12358. +int parseVersion(pkg_t *pkg, char *raw);
  12359. +char ** parseDependsString(char * raw, int * depends_count);
  12360. +int parseVersion(pkg_t *pkg, char *raw);
  12361. +void parseConffiles(pkg_t * pkg, char * raw);
  12362. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
  12363. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
  12364. +
  12365. +#endif
  12366. diff -Nur busybox-1.18.1.orig/archival/libipkg/pkg_src.c busybox-1.18.1/archival/libipkg/pkg_src.c
  12367. --- busybox-1.18.1.orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
  12368. +++ busybox-1.18.1/archival/libipkg/pkg_src.c 2010-12-25 22:38:07.000000000 +0100
  12369. @@ -0,0 +1,43 @@
  12370. +/* pkg_src.c - the itsy package management system
  12371. +
  12372. + Carl D. Worth
  12373. +
  12374. + Copyright (C) 2001 University of Southern California
  12375. +
  12376. + This program is free software; you can redistribute it and/or
  12377. + modify it under the terms of the GNU General Public License as
  12378. + published by the Free Software Foundation; either version 2, or (at
  12379. + your option) any later version.
  12380. +
  12381. + This program is distributed in the hope that it will be useful, but
  12382. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12383. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12384. + General Public License for more details.
  12385. +*/
  12386. +
  12387. +#include "ipkg.h"
  12388. +
  12389. +#include "pkg_src.h"
  12390. +#include "str_util.h"
  12391. +
  12392. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
  12393. +{
  12394. + src->gzip = gzip;
  12395. + src->name = str_dup_safe (name);
  12396. + src->value = str_dup_safe (base_url);
  12397. + if (extra_data)
  12398. + src->extra_data = str_dup_safe (extra_data);
  12399. + else
  12400. + src->extra_data = NULL;
  12401. + return 0;
  12402. +}
  12403. +
  12404. +void pkg_src_deinit(pkg_src_t *src)
  12405. +{
  12406. + free (src->name);
  12407. + free (src->value);
  12408. + if (src->extra_data)
  12409. + free (src->extra_data);
  12410. +}
  12411. +
  12412. +
  12413. diff -Nur busybox-1.18.1.orig/archival/libipkg/pkg_src.h busybox-1.18.1/archival/libipkg/pkg_src.h
  12414. --- busybox-1.18.1.orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
  12415. +++ busybox-1.18.1/archival/libipkg/pkg_src.h 2010-12-25 22:38:07.000000000 +0100
  12416. @@ -0,0 +1,34 @@
  12417. +/* pkg_src.h - the itsy package management system
  12418. +
  12419. + Carl D. Worth
  12420. +
  12421. + Copyright (C) 2001 University of Southern California
  12422. +
  12423. + This program is free software; you can redistribute it and/or
  12424. + modify it under the terms of the GNU General Public License as
  12425. + published by the Free Software Foundation; either version 2, or (at
  12426. + your option) any later version.
  12427. +
  12428. + This program is distributed in the hope that it will be useful, but
  12429. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12430. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12431. + General Public License for more details.
  12432. +*/
  12433. +
  12434. +#ifndef PKG_SRC_H
  12435. +#define PKG_SRC_H
  12436. +
  12437. +#include "nv_pair.h"
  12438. +
  12439. +typedef struct
  12440. +{
  12441. + char *name;
  12442. + char *value;
  12443. + char *extra_data;
  12444. + int gzip;
  12445. +} pkg_src_t;
  12446. +
  12447. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
  12448. +void pkg_src_deinit(pkg_src_t *src);
  12449. +
  12450. +#endif
  12451. diff -Nur busybox-1.18.1.orig/archival/libipkg/pkg_src_list.c busybox-1.18.1/archival/libipkg/pkg_src_list.c
  12452. --- busybox-1.18.1.orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
  12453. +++ busybox-1.18.1/archival/libipkg/pkg_src_list.c 2010-12-25 22:38:07.000000000 +0100
  12454. @@ -0,0 +1,75 @@
  12455. +/* pkg_src_list.c - the itsy package management system
  12456. +
  12457. + Carl D. Worth
  12458. +
  12459. + Copyright (C) 2001 University of Southern California
  12460. +
  12461. + This program is free software; you can redistribute it and/or
  12462. + modify it under the terms of the GNU General Public License as
  12463. + published by the Free Software Foundation; either version 2, or (at
  12464. + your option) any later version.
  12465. +
  12466. + This program is distributed in the hope that it will be useful, but
  12467. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12468. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12469. + General Public License for more details.
  12470. +*/
  12471. +
  12472. +#include "ipkg.h"
  12473. +
  12474. +#include "pkg_src_list.h"
  12475. +#include "void_list.h"
  12476. +
  12477. +int pkg_src_list_init(pkg_src_list_t *list)
  12478. +{
  12479. + return void_list_init((void_list_t *) list);
  12480. +}
  12481. +
  12482. +void pkg_src_list_deinit(pkg_src_list_t *list)
  12483. +{
  12484. + pkg_src_list_elt_t *iter;
  12485. + pkg_src_t *pkg_src;
  12486. +
  12487. + for (iter = list->head; iter; iter = iter->next) {
  12488. + pkg_src = iter->data;
  12489. + pkg_src_deinit(pkg_src);
  12490. +
  12491. + /* malloced in pkg_src_list_append */
  12492. + free(pkg_src);
  12493. + iter->data = NULL;
  12494. + }
  12495. + void_list_deinit((void_list_t *) list);
  12496. +}
  12497. +
  12498. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
  12499. + const char *name, const char *base_url, const char *extra_data,
  12500. + int gzip)
  12501. +{
  12502. + int err;
  12503. +
  12504. + /* freed in pkg_src_list_deinit */
  12505. + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
  12506. +
  12507. + if (pkg_src == NULL) {
  12508. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12509. + return NULL;
  12510. + }
  12511. + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
  12512. +
  12513. + err = void_list_append((void_list_t *) list, pkg_src);
  12514. + if (err) {
  12515. + return NULL;
  12516. + }
  12517. +
  12518. + return pkg_src;
  12519. +}
  12520. +
  12521. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
  12522. +{
  12523. + return void_list_push((void_list_t *) list, data);
  12524. +}
  12525. +
  12526. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
  12527. +{
  12528. + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
  12529. +}
  12530. diff -Nur busybox-1.18.1.orig/archival/libipkg/pkg_src_list.h busybox-1.18.1/archival/libipkg/pkg_src_list.h
  12531. --- busybox-1.18.1.orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
  12532. +++ busybox-1.18.1/archival/libipkg/pkg_src_list.h 2010-12-25 22:38:07.000000000 +0100
  12533. @@ -0,0 +1,57 @@
  12534. +/* pkg_src_list.h - the itsy package management system
  12535. +
  12536. + Carl D. Worth
  12537. +
  12538. + Copyright (C) 2001 University of Southern California
  12539. +
  12540. + This program is free software; you can redistribute it and/or
  12541. + modify it under the terms of the GNU General Public License as
  12542. + published by the Free Software Foundation; either version 2, or (at
  12543. + your option) any later version.
  12544. +
  12545. + This program is distributed in the hope that it will be useful, but
  12546. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12547. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12548. + General Public License for more details.
  12549. +*/
  12550. +
  12551. +#ifndef PKG_SRC_LIST_H
  12552. +#define PKG_SRC_LIST_H
  12553. +
  12554. +#include "pkg_src.h"
  12555. +
  12556. +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
  12557. +struct pkg_src_list_elt
  12558. +{
  12559. + pkg_src_list_elt_t *next;
  12560. + pkg_src_t *data;
  12561. +};
  12562. +
  12563. +typedef struct pkg_src_list pkg_src_list_t;
  12564. +struct pkg_src_list
  12565. +{
  12566. + pkg_src_list_elt_t pre_head;
  12567. + pkg_src_list_elt_t *head;
  12568. + pkg_src_list_elt_t *tail;
  12569. +};
  12570. +
  12571. +static inline int pkg_src_list_empty(pkg_src_list_t *list)
  12572. +{
  12573. + if (list->head == NULL)
  12574. + return 1;
  12575. + else
  12576. + return 0;
  12577. +}
  12578. +
  12579. +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
  12580. +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
  12581. +
  12582. +int pkg_src_list_init(pkg_src_list_t *list);
  12583. +void pkg_src_list_deinit(pkg_src_list_t *list);
  12584. +
  12585. +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);
  12586. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
  12587. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
  12588. +
  12589. +#endif
  12590. +
  12591. diff -Nur busybox-1.18.1.orig/archival/libipkg/pkg_vec.c busybox-1.18.1/archival/libipkg/pkg_vec.c
  12592. --- busybox-1.18.1.orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
  12593. +++ busybox-1.18.1/archival/libipkg/pkg_vec.c 2010-12-25 22:38:07.000000000 +0100
  12594. @@ -0,0 +1,231 @@
  12595. +/* pkg_vec.c - the itsy package management system
  12596. +
  12597. + Steven M. Ayer
  12598. +
  12599. + Copyright (C) 2002 Compaq Computer Corporation
  12600. +
  12601. + This program is free software; you can redistribute it and/or
  12602. + modify it under the terms of the GNU General Public License as
  12603. + published by the Free Software Foundation; either version 2, or (at
  12604. + your option) any later version.
  12605. +
  12606. + This program is distributed in the hope that it will be useful, but
  12607. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12608. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12609. + General Public License for more details.
  12610. +*/
  12611. +
  12612. +#include <stdlib.h>
  12613. +#include <fnmatch.h>
  12614. +#include "libbb.h"
  12615. +#include "xregex.h"
  12616. +#include "ipkg.h"
  12617. +#include "pkg.h"
  12618. +
  12619. +pkg_vec_t * pkg_vec_alloc(void)
  12620. +{
  12621. + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
  12622. + if (!vec) {
  12623. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12624. + return NULL;
  12625. + }
  12626. + vec->pkgs = NULL;
  12627. + vec->len = 0;
  12628. +
  12629. + return vec;
  12630. +}
  12631. +
  12632. +void pkg_vec_free(pkg_vec_t *vec)
  12633. +{
  12634. + free(vec->pkgs);
  12635. + free(vec);
  12636. +}
  12637. +
  12638. +/*
  12639. + * assumption: all names in a vector are identical
  12640. + * assumption: all version strings are trimmed,
  12641. + * so identical versions have identical version strings,
  12642. + * implying identical packages; let's marry these
  12643. + */
  12644. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  12645. +{
  12646. + int i;
  12647. + int found = 0;
  12648. +
  12649. + /* look for a duplicate pkg by name, version, and architecture */
  12650. + for (i = 0; i < vec->len; i++){
  12651. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
  12652. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
  12653. + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
  12654. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12655. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12656. + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
  12657. + found = 1;
  12658. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
  12659. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12660. + break;
  12661. + }
  12662. + }
  12663. +
  12664. + /* we didn't find one, add it */
  12665. + if (!found){
  12666. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
  12667. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12668. +
  12669. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12670. + vec->pkgs[vec->len] = pkg;
  12671. + vec->len++;
  12672. + return pkg;
  12673. + }
  12674. + /* update the one that we have */
  12675. + else {
  12676. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
  12677. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12678. + if (set_status) {
  12679. + /* this is from the status file, so need to merge with existing database */
  12680. + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
  12681. + pkg_merge(vec->pkgs[i], pkg, set_status);
  12682. + /* XXX: CLEANUP: It's not so polite to free something here
  12683. + that was passed in from above. */
  12684. + pkg_deinit(pkg);
  12685. + free(pkg);
  12686. + } else {
  12687. + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
  12688. + /* just overwrite the old one */
  12689. + pkg_deinit(vec->pkgs[i]);
  12690. + free(vec->pkgs[i]);
  12691. + vec->pkgs[i] = pkg;
  12692. + }
  12693. + return vec->pkgs[i];
  12694. + }
  12695. +}
  12696. +
  12697. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
  12698. +{
  12699. + int i;
  12700. + int found = 0;
  12701. +
  12702. + /* look for a duplicate pkg by name, version, and architecture */
  12703. + for (i = 0; i < vec->len; i++)
  12704. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12705. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12706. + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
  12707. + found = 1;
  12708. + break;
  12709. + }
  12710. +
  12711. + /* we didn't find one, add it */
  12712. + if(!found){
  12713. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12714. + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
  12715. + vec->len++;
  12716. + }
  12717. +}
  12718. +
  12719. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
  12720. +{
  12721. + int i;
  12722. + for (i = 0; i < vec->len; i++)
  12723. + if (vec->pkgs[i] == apkg)
  12724. + return 1;
  12725. + return 0;
  12726. +}
  12727. +
  12728. +typedef int (*compare_fcn_t)(const void *, const void *);
  12729. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
  12730. +{
  12731. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12732. +}
  12733. +
  12734. +int pkg_vec_clear_marks(pkg_vec_t *vec)
  12735. +{
  12736. + int npkgs = vec->len;
  12737. + int i;
  12738. + for (i = 0; i < npkgs; i++) {
  12739. + pkg_t *pkg = vec->pkgs[i];
  12740. + pkg->state_flag &= ~SF_MARKED;
  12741. + }
  12742. + return 0;
  12743. +}
  12744. +
  12745. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
  12746. +{
  12747. + int matching_count = 0;
  12748. + pkg_t **pkgs = vec->pkgs;
  12749. + int npkgs = vec->len;
  12750. + int i;
  12751. + for (i = 0; i < npkgs; i++) {
  12752. + pkg_t *pkg = pkgs[i];
  12753. + if (fnmatch(pattern, pkg->name, 0)==0) {
  12754. + pkg->state_flag |= SF_MARKED;
  12755. + matching_count++;
  12756. + }
  12757. + }
  12758. + return matching_count;
  12759. +}
  12760. +
  12761. +
  12762. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
  12763. +{
  12764. + abstract_pkg_vec_t * vec ;
  12765. + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
  12766. + if (!vec) {
  12767. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12768. + return NULL;
  12769. + }
  12770. + vec->pkgs = NULL;
  12771. + vec->len = 0;
  12772. +
  12773. + return vec;
  12774. +}
  12775. +
  12776. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
  12777. +{
  12778. + free(vec->pkgs);
  12779. + free(vec);
  12780. +}
  12781. +
  12782. +/*
  12783. + * assumption: all names in a vector are unique
  12784. + */
  12785. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
  12786. +{
  12787. + int i;
  12788. +
  12789. + /* look for a duplicate pkg by name */
  12790. + for(i = 0; i < vec->len; i++)
  12791. + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12792. + break;
  12793. +
  12794. + /* we didn't find one, add it */
  12795. + if(i == vec->len){
  12796. + vec->pkgs =
  12797. + (abstract_pkg_t **)
  12798. + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
  12799. + vec->pkgs[vec->len] = pkg;
  12800. + vec->len++;
  12801. + }
  12802. +}
  12803. +
  12804. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
  12805. +{
  12806. + if (vec->len > i)
  12807. + return vec->pkgs[i];
  12808. + else
  12809. + return NULL;
  12810. +}
  12811. +
  12812. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
  12813. +{
  12814. + int i;
  12815. + for (i = 0; i < vec->len; i++)
  12816. + if (vec->pkgs[i] == apkg)
  12817. + return 1;
  12818. + return 0;
  12819. +}
  12820. +
  12821. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
  12822. +{
  12823. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12824. +}
  12825. +
  12826. diff -Nur busybox-1.18.1.orig/archival/libipkg/pkg_vec.h busybox-1.18.1/archival/libipkg/pkg_vec.h
  12827. --- busybox-1.18.1.orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
  12828. +++ busybox-1.18.1/archival/libipkg/pkg_vec.h 2010-12-25 22:38:07.000000000 +0100
  12829. @@ -0,0 +1,62 @@
  12830. +/* pkg_vec.h - the itsy package management system
  12831. +
  12832. + Steven M. Ayer
  12833. +
  12834. + Copyright (C) 2002 Compaq Computer Corporation
  12835. +
  12836. + This program is free software; you can redistribute it and/or
  12837. + modify it under the terms of the GNU General Public License as
  12838. + published by the Free Software Foundation; either version 2, or (at
  12839. + your option) any later version.
  12840. +
  12841. + This program is distributed in the hope that it will be useful, but
  12842. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12843. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12844. + General Public License for more details.
  12845. +*/
  12846. +
  12847. +#ifndef PKG_VEC_H
  12848. +#define PKG_VEC_H
  12849. +
  12850. +typedef struct pkg pkg_t;
  12851. +typedef struct abstract_pkg abstract_pkg_t;
  12852. +
  12853. +struct pkg_vec
  12854. +{
  12855. + pkg_t **pkgs;
  12856. + int len;
  12857. +};
  12858. +typedef struct pkg_vec pkg_vec_t;
  12859. +
  12860. +struct abstract_pkg_vec
  12861. +{
  12862. + abstract_pkg_t **pkgs;
  12863. + int len;
  12864. +};
  12865. +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
  12866. +
  12867. +
  12868. +pkg_vec_t * pkg_vec_alloc(void);
  12869. +void pkg_vec_free(pkg_vec_t *vec);
  12870. +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
  12871. +
  12872. +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
  12873. +/* pkg_vec_insert_merge: might munge pkg.
  12874. +* returns the pkg that is in the pkg graph */
  12875. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
  12876. +/* this one never munges pkg */
  12877. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
  12878. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
  12879. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
  12880. +
  12881. +int pkg_vec_clear_marks(pkg_vec_t *vec);
  12882. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
  12883. +
  12884. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
  12885. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
  12886. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
  12887. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
  12888. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
  12889. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
  12890. +#endif
  12891. +
  12892. diff -Nur busybox-1.18.1.orig/archival/libipkg/sprintf_alloc.h busybox-1.18.1/archival/libipkg/sprintf_alloc.h
  12893. --- busybox-1.18.1.orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
  12894. +++ busybox-1.18.1/archival/libipkg/sprintf_alloc.h 2010-12-25 22:38:07.000000000 +0100
  12895. @@ -0,0 +1,25 @@
  12896. +/* sprintf_alloca.c -- like sprintf with memory allocation
  12897. +
  12898. + Carl D. Worth
  12899. +
  12900. + Copyright (C) 2001 University of Southern California
  12901. +
  12902. + This program is free software; you can redistribute it and/or modify
  12903. + it under the terms of the GNU General Public License as published by
  12904. + the Free Software Foundation; either version 2, or (at your option)
  12905. + any later version.
  12906. +
  12907. + This program is distributed in the hope that it will be useful,
  12908. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  12909. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12910. + GNU General Public License for more details.
  12911. +*/
  12912. +
  12913. +#ifndef SPRINTF_ALLOC_H
  12914. +#define SPRINTF_ALLOC_H
  12915. +
  12916. +#include "libbb.h"
  12917. +
  12918. +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
  12919. +
  12920. +#endif
  12921. diff -Nur busybox-1.18.1.orig/archival/libipkg/str_list.c busybox-1.18.1/archival/libipkg/str_list.c
  12922. --- busybox-1.18.1.orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
  12923. +++ busybox-1.18.1/archival/libipkg/str_list.c 2010-12-25 22:38:07.000000000 +0100
  12924. @@ -0,0 +1,76 @@
  12925. +/* str_list.c - the itsy package management system
  12926. +
  12927. + Carl D. Worth
  12928. +
  12929. + Copyright (C) 2001 University of Southern California
  12930. +
  12931. + This program is free software; you can redistribute it and/or
  12932. + modify it under the terms of the GNU General Public License as
  12933. + published by the Free Software Foundation; either version 2, or (at
  12934. + your option) any later version.
  12935. +
  12936. + This program is distributed in the hope that it will be useful, but
  12937. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12938. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12939. + General Public License for more details.
  12940. +*/
  12941. +
  12942. +#include "ipkg.h"
  12943. +
  12944. +#include "str_list.h"
  12945. +
  12946. +int str_list_elt_init(str_list_elt_t *elt, char *data)
  12947. +{
  12948. + return void_list_elt_init((void_list_elt_t *) elt, data);
  12949. +}
  12950. +
  12951. +void str_list_elt_deinit(str_list_elt_t *elt)
  12952. +{
  12953. + void_list_elt_deinit((void_list_elt_t *) elt);
  12954. +}
  12955. +
  12956. +str_list_t *str_list_alloc(void)
  12957. +{
  12958. + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
  12959. + if (list)
  12960. + str_list_init(list);
  12961. + return list;
  12962. +}
  12963. +
  12964. +int str_list_init(str_list_t *list)
  12965. +{
  12966. + return void_list_init((void_list_t *) list);
  12967. +}
  12968. +
  12969. +void str_list_deinit(str_list_t *list)
  12970. +{
  12971. + void_list_deinit((void_list_t *) list);
  12972. +}
  12973. +
  12974. +int str_list_append(str_list_t *list, char *data)
  12975. +{
  12976. + return void_list_append((void_list_t *) list, data);
  12977. +}
  12978. +
  12979. +int str_list_push(str_list_t *list, char *data)
  12980. +{
  12981. + return void_list_push((void_list_t *) list, data);
  12982. +}
  12983. +
  12984. +str_list_elt_t *str_list_pop(str_list_t *list)
  12985. +{
  12986. + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
  12987. +}
  12988. +
  12989. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
  12990. +{
  12991. + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
  12992. + (void_list_elt_t **) iter);
  12993. +}
  12994. +
  12995. +char *str_list_remove_elt(str_list_t *list, const char *target_str)
  12996. +{
  12997. + return (char *)void_list_remove_elt((void_list_t *) list,
  12998. + (void *)target_str,
  12999. + (void_list_cmp_t)strcmp);
  13000. +}
  13001. diff -Nur busybox-1.18.1.orig/archival/libipkg/str_list.h busybox-1.18.1/archival/libipkg/str_list.h
  13002. --- busybox-1.18.1.orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
  13003. +++ busybox-1.18.1/archival/libipkg/str_list.h 2010-12-25 22:38:07.000000000 +0100
  13004. @@ -0,0 +1,51 @@
  13005. +/* str_list.h - the itsy package management system
  13006. +
  13007. + Carl D. Worth
  13008. +
  13009. + Copyright (C) 2001 University of Southern California
  13010. +
  13011. + This program is free software; you can redistribute it and/or
  13012. + modify it under the terms of the GNU General Public License as
  13013. + published by the Free Software Foundation; either version 2, or (at
  13014. + your option) any later version.
  13015. +
  13016. + This program is distributed in the hope that it will be useful, but
  13017. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13018. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13019. + General Public License for more details.
  13020. +*/
  13021. +
  13022. +#ifndef STR_LIST_H
  13023. +#define STR_LIST_H
  13024. +
  13025. +#include "void_list.h"
  13026. +
  13027. +typedef struct str_list_elt str_list_elt_t;
  13028. +struct str_list_elt
  13029. +{
  13030. + str_list_elt_t *next;
  13031. + char *data;
  13032. +};
  13033. +
  13034. +typedef struct xstr_list str_list_t;
  13035. +struct xstr_list
  13036. +{
  13037. + str_list_elt_t pre_head;
  13038. + str_list_elt_t *head;
  13039. + str_list_elt_t *tail;
  13040. +};
  13041. +
  13042. +int str_list_elt_init(str_list_elt_t *elt, char *data);
  13043. +void str_list_elt_deinit(str_list_elt_t *elt);
  13044. +
  13045. +str_list_t *str_list_alloc(void);
  13046. +int str_list_init(str_list_t *list);
  13047. +void str_list_deinit(str_list_t *list);
  13048. +
  13049. +int str_list_append(str_list_t *list, char *data);
  13050. +int str_list_push(str_list_t *list, char *data);
  13051. +str_list_elt_t *str_list_pop(str_list_t *list);
  13052. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
  13053. +char *str_list_remove_elt(str_list_t *list, const char *target_str);
  13054. +
  13055. +#endif
  13056. diff -Nur busybox-1.18.1.orig/archival/libipkg/str_util.c busybox-1.18.1/archival/libipkg/str_util.c
  13057. --- busybox-1.18.1.orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
  13058. +++ busybox-1.18.1/archival/libipkg/str_util.c 2010-12-25 22:38:07.000000000 +0100
  13059. @@ -0,0 +1,69 @@
  13060. +/* str_utils.c - the itsy package management system
  13061. +
  13062. + Carl D. Worth
  13063. +
  13064. + Copyright (C) 2001 University of Southern California
  13065. +
  13066. + This program is free software; you can redistribute it and/or
  13067. + modify it under the terms of the GNU General Public License as
  13068. + published by the Free Software Foundation; either version 2, or (at
  13069. + your option) any later version.
  13070. +
  13071. + This program is distributed in the hope that it will be useful, but
  13072. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13073. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13074. + General Public License for more details.
  13075. +*/
  13076. +
  13077. +#include "ipkg.h"
  13078. +
  13079. +int str_starts_with(const char *str, const char *prefix);
  13080. +int str_ends_with(const char *str, const char *suffix);
  13081. +int str_chomp(char *str);
  13082. +int str_toupper(char *str);
  13083. +char *str_dup_safe(const char *str);
  13084. +
  13085. +int str_starts_with(const char *str, const char *prefix)
  13086. +{
  13087. + return (strncmp(str, prefix, strlen(prefix)) == 0);
  13088. +}
  13089. +
  13090. +int str_ends_with(const char *str, const char *suffix)
  13091. +{
  13092. + int suffix_len;
  13093. + int str_len;
  13094. +
  13095. + str_len = strlen(str);
  13096. + suffix_len = strlen(suffix);
  13097. +
  13098. + if (str_len < suffix_len) {
  13099. + return 0;
  13100. + }
  13101. +
  13102. + return (strcmp(str + str_len - suffix_len, suffix) == 0);
  13103. +}
  13104. +
  13105. +int str_chomp(char *str)
  13106. +{
  13107. + if (str[strlen(str) - 1] == '\n') {
  13108. + str[strlen(str) - 1] = '\0';
  13109. + return 1;
  13110. + }
  13111. + return 0;
  13112. +}
  13113. +
  13114. +int str_toupper(char *str)
  13115. +{
  13116. + while (*str) {
  13117. + *str = toupper(*str);
  13118. + str++;
  13119. + }
  13120. +
  13121. + return 0;
  13122. +}
  13123. +
  13124. +char *str_dup_safe(const char *str)
  13125. +{
  13126. + return str ? strdup(str) : NULL;
  13127. +}
  13128. +
  13129. diff -Nur busybox-1.18.1.orig/archival/libipkg/str_util.h busybox-1.18.1/archival/libipkg/str_util.h
  13130. --- busybox-1.18.1.orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
  13131. +++ busybox-1.18.1/archival/libipkg/str_util.h 2010-12-25 22:38:07.000000000 +0100
  13132. @@ -0,0 +1,27 @@
  13133. +/* str_utils.h - the itsy package management system
  13134. +
  13135. + Carl D. Worth
  13136. +
  13137. + Copyright (C) 2001 University of Southern California
  13138. +
  13139. + This program is free software; you can redistribute it and/or
  13140. + modify it under the terms of the GNU General Public License as
  13141. + published by the Free Software Foundation; either version 2, or (at
  13142. + your option) any later version.
  13143. +
  13144. + This program is distributed in the hope that it will be useful, but
  13145. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13146. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13147. + General Public License for more details.
  13148. +*/
  13149. +
  13150. +#ifndef STR_UTILS_H
  13151. +#define STR_UTILS_H
  13152. +
  13153. +int str_starts_with(const char *str, const char *prefix);
  13154. +int str_ends_with(const char *str, const char *suffix);
  13155. +int str_chomp(char *str);
  13156. +int str_toupper(char *str);
  13157. +char *str_dup_safe(const char *str);
  13158. +
  13159. +#endif
  13160. diff -Nur busybox-1.18.1.orig/archival/libipkg/user.c busybox-1.18.1/archival/libipkg/user.c
  13161. --- busybox-1.18.1.orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
  13162. +++ busybox-1.18.1/archival/libipkg/user.c 2010-12-25 22:38:07.000000000 +0100
  13163. @@ -0,0 +1,49 @@
  13164. +/* user.c - the itsy package management system
  13165. +
  13166. + Jamey Hicks
  13167. +
  13168. + Copyright (C) 2002 Hewlett Packard Company
  13169. + Copyright (C) 2001 University of Southern California
  13170. +
  13171. + This program is free software; you can redistribute it and/or
  13172. + modify it under the terms of the GNU General Public License as
  13173. + published by the Free Software Foundation; either version 2, or (at
  13174. + your option) any later version.
  13175. +
  13176. + This program is distributed in the hope that it will be useful, but
  13177. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13178. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13179. + General Public License for more details.
  13180. +*/
  13181. +
  13182. +#include <stdio.h>
  13183. +#include <stdarg.h>
  13184. +#include "libbb.h"
  13185. +#include "file_util.h"
  13186. +#include "str_util.h"
  13187. +#include "libipkg.h"
  13188. +
  13189. +char *get_user_response(const char *format, ...);
  13190. +static char *question = NULL;
  13191. +static int question_len = 255;
  13192. +
  13193. +char *get_user_response(const char *format, ...)
  13194. +{
  13195. + int len = question_len;
  13196. + va_list ap;
  13197. + char *response;
  13198. + va_start(ap, format);
  13199. +
  13200. + do {
  13201. + if (question == NULL || len > question_len) {
  13202. + question = realloc(question, len + 1);
  13203. + question_len = len;
  13204. + }
  13205. + len = vsnprintf(question,question_len,format,ap);
  13206. + } while (len > question_len);
  13207. + response = strdup(ipkg_cb_response(question));
  13208. + str_chomp(response);
  13209. + str_tolower(response);
  13210. +
  13211. + return response;
  13212. +}
  13213. diff -Nur busybox-1.18.1.orig/archival/libipkg/user.h busybox-1.18.1/archival/libipkg/user.h
  13214. --- busybox-1.18.1.orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
  13215. +++ busybox-1.18.1/archival/libipkg/user.h 2010-12-25 22:38:07.000000000 +0100
  13216. @@ -0,0 +1,23 @@
  13217. +/* user.c - the itsy package management system
  13218. +
  13219. + Jamey Hicks
  13220. +
  13221. + Copyright (C) 2002 Hewlett Packard Company
  13222. + Copyright (C) 2001 University of Southern California
  13223. +
  13224. + This program is free software; you can redistribute it and/or
  13225. + modify it under the terms of the GNU General Public License as
  13226. + published by the Free Software Foundation; either version 2, or (at
  13227. + your option) any later version.
  13228. +
  13229. + This program is distributed in the hope that it will be useful, but
  13230. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13231. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13232. + General Public License for more details.
  13233. +*/
  13234. +
  13235. +#include <stdio.h>
  13236. +#include <stdarg.h>
  13237. +
  13238. +char *get_user_response(const char *format, ...);
  13239. +
  13240. diff -Nur busybox-1.18.1.orig/archival/libipkg/void_list.c busybox-1.18.1/archival/libipkg/void_list.c
  13241. --- busybox-1.18.1.orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
  13242. +++ busybox-1.18.1/archival/libipkg/void_list.c 2010-12-25 22:38:07.000000000 +0100
  13243. @@ -0,0 +1,194 @@
  13244. +/* void_list.c - the itsy package management system
  13245. +
  13246. + Carl D. Worth
  13247. +
  13248. + Copyright (C) 2001 University of Southern California
  13249. +
  13250. + This program is free software; you can redistribute it and/or
  13251. + modify it under the terms of the GNU General Public License as
  13252. + published by the Free Software Foundation; either version 2, or (at
  13253. + your option) any later version.
  13254. +
  13255. + This program is distributed in the hope that it will be useful, but
  13256. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13257. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13258. + General Public License for more details.
  13259. +*/
  13260. +
  13261. +#include "ipkg.h"
  13262. +#include <errno.h>
  13263. +
  13264. +#include "void_list.h"
  13265. +
  13266. +int void_list_elt_init(void_list_elt_t *elt, void *data)
  13267. +{
  13268. + elt->next = NULL;
  13269. + elt->data = data;
  13270. +
  13271. + return 0;
  13272. +}
  13273. +
  13274. +void void_list_elt_deinit(void_list_elt_t *elt)
  13275. +{
  13276. + void_list_elt_init(elt, NULL);
  13277. +}
  13278. +
  13279. +int void_list_init(void_list_t *list)
  13280. +{
  13281. + void_list_elt_init(&list->pre_head, NULL);
  13282. + list->head = NULL;
  13283. + list->pre_head.next = list->head;
  13284. + list->tail = NULL;
  13285. +
  13286. + return 0;
  13287. +}
  13288. +
  13289. +void void_list_deinit(void_list_t *list)
  13290. +{
  13291. + void_list_elt_t *elt;
  13292. +
  13293. + while (list->head) {
  13294. + elt = void_list_pop(list);
  13295. + void_list_elt_deinit(elt);
  13296. + /* malloced in void_list_append */
  13297. + free(elt);
  13298. + }
  13299. +}
  13300. +
  13301. +int void_list_append(void_list_t *list, void *data)
  13302. +{
  13303. + void_list_elt_t *elt;
  13304. +
  13305. + /* freed in void_list_deinit */
  13306. + elt = malloc(sizeof(void_list_elt_t));
  13307. + if (elt == NULL) {
  13308. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13309. + return ENOMEM;
  13310. + }
  13311. +
  13312. + void_list_elt_init(elt, data);
  13313. +
  13314. + if (list->tail) {
  13315. + list->tail->next = elt;
  13316. + list->tail = elt;
  13317. + } else {
  13318. + list->head = elt;
  13319. + list->pre_head.next = list->head;
  13320. + list->tail = elt;
  13321. + }
  13322. +
  13323. + return 0;
  13324. +}
  13325. +
  13326. +int void_list_push(void_list_t *list, void *data)
  13327. +{
  13328. + void_list_elt_t *elt;
  13329. +
  13330. + elt = malloc(sizeof(void_list_elt_t));
  13331. + if (elt == NULL) {
  13332. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13333. + return ENOMEM;
  13334. + }
  13335. +
  13336. + void_list_elt_init(elt, data);
  13337. +
  13338. + elt->next = list->head;
  13339. + list->head->next = elt;
  13340. + if (list->tail == NULL) {
  13341. + list->tail = list->head;
  13342. + }
  13343. +
  13344. + return 0;
  13345. +}
  13346. +
  13347. +void_list_elt_t *void_list_pop(void_list_t *list)
  13348. +{
  13349. + void_list_elt_t *elt;
  13350. +
  13351. + elt = list->head;
  13352. +
  13353. + if (list->head) {
  13354. + list->head = list->head->next;
  13355. + list->pre_head.next = list->head;
  13356. + if (list->head == NULL) {
  13357. + list->tail = NULL;
  13358. + }
  13359. + }
  13360. +
  13361. + return elt;
  13362. +}
  13363. +
  13364. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
  13365. +{
  13366. + void_list_elt_t *prior;
  13367. + void_list_elt_t *old_elt;
  13368. + void *old_data;
  13369. +
  13370. + old_elt = *iter;
  13371. + old_data = old_elt->data;
  13372. +
  13373. + if (old_elt == list->head) {
  13374. + prior = &list->pre_head;
  13375. + void_list_pop(list);
  13376. + } else {
  13377. + for (prior = list->head; prior; prior = prior->next) {
  13378. + if (prior->next == old_elt) {
  13379. + break;
  13380. + }
  13381. + }
  13382. + if (prior == NULL || prior->next != old_elt) {
  13383. + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
  13384. + return NULL;
  13385. + }
  13386. + prior->next = old_elt->next;
  13387. +
  13388. + if (old_elt == list->tail) {
  13389. + list->tail = prior;
  13390. + }
  13391. + }
  13392. +
  13393. + void_list_elt_deinit(old_elt);
  13394. + *iter = prior;
  13395. +
  13396. + return old_data;
  13397. +}
  13398. +
  13399. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13400. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
  13401. +{
  13402. + void_list_elt_t *prior;
  13403. + void_list_elt_t *old_elt = NULL;
  13404. + void *old_data = NULL;
  13405. +
  13406. + /* first element */
  13407. + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
  13408. + old_elt = list->head;
  13409. + old_data = list->head->data;
  13410. + void_list_pop(list);
  13411. + } else {
  13412. + int found = 0;
  13413. + for (prior = list->head; prior && prior->next; prior = prior->next) {
  13414. + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
  13415. + old_elt = prior->next;
  13416. + old_data = old_elt->data;
  13417. + found = 1;
  13418. + break;
  13419. + }
  13420. + }
  13421. + if (!found) {
  13422. + return NULL;
  13423. + }
  13424. + prior->next = old_elt->next;
  13425. +
  13426. + if (old_elt == list->tail) {
  13427. + list->tail = prior;
  13428. + }
  13429. + }
  13430. + if (old_elt)
  13431. + void_list_elt_deinit(old_elt);
  13432. +
  13433. + if (old_data)
  13434. + return old_data;
  13435. + else
  13436. + return NULL;
  13437. +}
  13438. diff -Nur busybox-1.18.1.orig/archival/libipkg/void_list.h busybox-1.18.1/archival/libipkg/void_list.h
  13439. --- busybox-1.18.1.orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
  13440. +++ busybox-1.18.1/archival/libipkg/void_list.h 2010-12-25 22:38:07.000000000 +0100
  13441. @@ -0,0 +1,59 @@
  13442. +/* void_list.h - the itsy package management system
  13443. +
  13444. + Carl D. Worth
  13445. +
  13446. + Copyright (C) 2001 University of Southern California
  13447. +
  13448. + This program is free software; you can redistribute it and/or
  13449. + modify it under the terms of the GNU General Public License as
  13450. + published by the Free Software Foundation; either version 2, or (at
  13451. + your option) any later version.
  13452. +
  13453. + This program is distributed in the hope that it will be useful, but
  13454. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13455. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13456. + General Public License for more details.
  13457. +*/
  13458. +
  13459. +#ifndef VOID_LIST_H
  13460. +#define VOID_LIST_H
  13461. +
  13462. +typedef struct void_list_elt void_list_elt_t;
  13463. +struct void_list_elt
  13464. +{
  13465. + void_list_elt_t *next;
  13466. + void *data;
  13467. +};
  13468. +
  13469. +typedef struct void_list void_list_t;
  13470. +struct void_list
  13471. +{
  13472. + void_list_elt_t pre_head;
  13473. + void_list_elt_t *head;
  13474. + void_list_elt_t *tail;
  13475. +};
  13476. +
  13477. +static inline int void_list_empty(void_list_t *list)
  13478. +{
  13479. + if (list->head == NULL)
  13480. + return 1;
  13481. + else
  13482. + return 0;
  13483. +}
  13484. +
  13485. +int void_list_elt_init(void_list_elt_t *elt, void *data);
  13486. +void void_list_elt_deinit(void_list_elt_t *elt);
  13487. +
  13488. +int void_list_init(void_list_t *list);
  13489. +void void_list_deinit(void_list_t *list);
  13490. +
  13491. +int void_list_append(void_list_t *list, void *data);
  13492. +int void_list_push(void_list_t *list, void *data);
  13493. +void_list_elt_t *void_list_pop(void_list_t *list);
  13494. +
  13495. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
  13496. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13497. +typedef int (*void_list_cmp_t)(const void *, const void *);
  13498. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
  13499. +
  13500. +#endif
  13501. diff -Nur busybox-1.18.1.orig/archival/libipkg/xsystem.c busybox-1.18.1/archival/libipkg/xsystem.c
  13502. --- busybox-1.18.1.orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
  13503. +++ busybox-1.18.1/archival/libipkg/xsystem.c 2010-12-25 22:38:07.000000000 +0100
  13504. @@ -0,0 +1,64 @@
  13505. +/* xsystem.c - system(3) with error messages
  13506. +
  13507. + Carl D. Worth
  13508. +
  13509. + Copyright (C) 2001 University of Southern California
  13510. +
  13511. + This program is free software; you can redistribute it and/or
  13512. + modify it under the terms of the GNU General Public License as
  13513. + published by the Free Software Foundation; either version 2, or (at
  13514. + your option) any later version.
  13515. +
  13516. + This program is distributed in the hope that it will be useful, but
  13517. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13518. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13519. + General Public License for more details.
  13520. +*/
  13521. +
  13522. +#include "ipkg.h"
  13523. +#include <sys/wait.h>
  13524. +
  13525. +#include "xsystem.h"
  13526. +
  13527. +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
  13528. + really need the /bin/sh invocation which takes resources and
  13529. + introduces security problems. I should switch all of this to a sort
  13530. + of execl() or execv() interface/implementation.
  13531. +*/
  13532. +
  13533. +/* Like system(3), but with error messages printed if the fork fails
  13534. + or if the child process dies due to an uncaught signal. Also, the
  13535. + return value is a bit simpler:
  13536. +
  13537. + -1 if there was any problem
  13538. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13539. + as defined in <sys/wait.h>.
  13540. +*/
  13541. +int xsystem(const char *cmd)
  13542. +{
  13543. + int err;
  13544. +
  13545. + err = system(cmd);
  13546. +
  13547. + if (err == -1) {
  13548. + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
  13549. + __FUNCTION__, cmd);
  13550. + return -1;
  13551. + }
  13552. +
  13553. + if (WIFSIGNALED(err)) {
  13554. + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
  13555. + __FUNCTION__, WTERMSIG(err), cmd);
  13556. + return -1;
  13557. + }
  13558. +
  13559. + if (WIFEXITED(err)) {
  13560. + /* Normal child exit */
  13561. + return WEXITSTATUS(err);
  13562. + }
  13563. +
  13564. + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
  13565. + __FUNCTION__, err);
  13566. + return -1;
  13567. +}
  13568. +
  13569. diff -Nur busybox-1.18.1.orig/archival/libipkg/xsystem.h busybox-1.18.1/archival/libipkg/xsystem.h
  13570. --- busybox-1.18.1.orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
  13571. +++ busybox-1.18.1/archival/libipkg/xsystem.h 2010-12-25 22:38:07.000000000 +0100
  13572. @@ -0,0 +1,34 @@
  13573. +/* xsystem.h - system(3) with error messages
  13574. +
  13575. + Carl D. Worth
  13576. +
  13577. + Copyright (C) 2001 University of Southern California
  13578. +
  13579. + This program is free software; you can redistribute it and/or
  13580. + modify it under the terms of the GNU General Public License as
  13581. + published by the Free Software Foundation; either version 2, or (at
  13582. + your option) any later version.
  13583. +
  13584. + This program is distributed in the hope that it will be useful, but
  13585. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13586. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13587. + General Public License for more details.
  13588. +*/
  13589. +
  13590. +#ifndef XSYSTEM_H
  13591. +#define XSYSTEM_H
  13592. +
  13593. +#include <stdlib.h>
  13594. +
  13595. +/* Like system(3), but with error messages printed if the fork fails
  13596. + or if the child process dies due to an uncaught signal. Also, the
  13597. + return value is a bit simpler:
  13598. +
  13599. + -1 if there was any problem
  13600. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13601. + as defined in <sys/wait.h>.
  13602. +*/
  13603. +int xsystem(const char *cmd);
  13604. +
  13605. +#endif
  13606. +
  13607. diff -Nur busybox-1.18.1.orig/include/applets.src.h busybox-1.18.1/include/applets.src.h
  13608. --- busybox-1.18.1.orig/include/applets.src.h 2010-12-21 05:31:04.000000000 +0100
  13609. +++ busybox-1.18.1/include/applets.src.h 2010-12-25 22:38:09.000000000 +0100
  13610. @@ -195,6 +195,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.18.1.orig/include/archive.h busybox-1.18.1/include/archive.h
  13619. --- busybox-1.18.1.orig/include/archive.h 2010-12-20 01:41:27.000000000 +0100
  13620. +++ busybox-1.18.1/include/archive.h 2010-12-25 22:51:31.000000000 +0100
  13621. @@ -95,7 +95,7 @@
  13622. struct hardlinks_t *cpio__hardlinks_to_create;
  13623. struct hardlinks_t *cpio__created_hardlinks;
  13624. #endif
  13625. -#if ENABLE_DPKG || ENABLE_DPKG_DEB
  13626. +#if ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13627. /* Temporary storage */
  13628. char *dpkg__buffer;
  13629. /* How to process any sub archive, e.g. get_header_tar_gz */
  13630. diff -Nur busybox-1.18.1.orig/include/usage.src.h busybox-1.18.1/include/usage.src.h
  13631. --- busybox-1.18.1.orig/include/usage.src.h 2010-12-21 05:29:45.000000000 +0100
  13632. +++ busybox-1.18.1/include/usage.src.h 2010-12-25 22:45:09.000000000 +0100
  13633. @@ -1919,6 +1919,82 @@
  13634. "\n -l Limits" \
  13635. "\n -u Summary" \
  13636. +#define ipkg_trivial_usage \
  13637. + "[options]... sub-command [arguments]..."
  13638. +#define ipkg_full_usage \
  13639. + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
  13640. + "\n" \
  13641. + "Sub-commands:\n" \
  13642. + "\nPackage Manipulation:\n" \
  13643. + "\tupdate Update list of available packages\n" \
  13644. + "\tupgrade Upgrade all installed packages to latest version\n" \
  13645. + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
  13646. + "\tinstall <file.ipk> Install package <file.ipk>\n" \
  13647. + "\tconfigure [<pkg>] Configure unpacked packages\n" \
  13648. + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
  13649. + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
  13650. + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
  13651. + "\n" \
  13652. + "Informational Commands:\n" \
  13653. + "\tlist List available packages and descriptions\n" \
  13654. + "\tlist_installed List all and only the installed packages and description \n" \
  13655. + "\tfiles <pkg> List all files belonging to <pkg>\n" \
  13656. + "\tsearch <file|regexp> Search for a package providing <file>\n" \
  13657. + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
  13658. + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
  13659. + "\tdownload <pkg> Download <pkg> to current directory.\n" \
  13660. + "\tcompare_versions <v1> <op> <v2>\n" \
  13661. + "\t compare versions using <= < > >= = << >>\n" \
  13662. + "\tprint_architecture prints the architecture.\n" \
  13663. + "\tprint_installation_architecture\n" \
  13664. + "\twhatdepends [-A] [pkgname|pat]+\n" \
  13665. + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
  13666. + "\twhatprovides [-A] [pkgname|pat]+\n" \
  13667. + "\twhatconflicts [-A] [pkgname|pat]+\n" \
  13668. + "\twhatreplaces [-A] [pkgname|pat]+\n" \
  13669. + "\t prints the installation architecture.\n" \
  13670. + "\n" \
  13671. + "\nOptions:\n" \
  13672. + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
  13673. + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
  13674. + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
  13675. + "\t 0 errors only\n" \
  13676. + "\t 1 normal messages (default)\n" \
  13677. + "\t 2 informative messages\n" \
  13678. + "\t 3 debug output\n" \
  13679. + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
  13680. + "\t-conf <conf_file> Default configuration file location\n" \
  13681. + " is /etc/ipkg.conf\n" \
  13682. + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
  13683. + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
  13684. + " <dest_name> should be a defined dest name from\n" \
  13685. + " the configuration file, (but can also be a\n" \
  13686. + " directory name in a pinch).\n" \
  13687. + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
  13688. + "\t-offline <offline_root> offline installation of packages.\n" \
  13689. + "\t-verbose_wget more wget messages\n" \
  13690. + "\n" \
  13691. + "Force Options (use when ipkg is too smart for its own good):\n" \
  13692. + "\t-force-depends Make dependency checks warnings instead of errors\n" \
  13693. + "\t Install/remove package in spite of failed dependences\n" \
  13694. + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
  13695. + " (no prompts). Note that this will not prevent\n" \
  13696. + " package installation scripts from prompting.\n" \
  13697. + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
  13698. + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
  13699. + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
  13700. + "\t-force_space Install even if there does not seem to be enough space.\n" \
  13701. + "\t-noaction No action -- test only\n" \
  13702. + "\t-nodeps Do not follow dependences\n" \
  13703. + "\t-force-removal-of-dependent-packages\n" \
  13704. + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
  13705. + "\t-test No action -- test only\n" \
  13706. + "\t-t Specify tmp-dir.\n" \
  13707. + "\t--tmp-dir Specify tmp-dir.\n" \
  13708. + "\n" \
  13709. + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
  13710. + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
  13711. +
  13712. #define iplink_trivial_usage \
  13713. "{ set DEVICE { up | down | arp { on | off } | show [DEVICE] }"
  13714. #define iplink_full_usage "\n\n" \