001-ipkg.patch 423 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699
  1. diff -Nur busybox-1.15.2.orig/archival/Config.in busybox-1.15.2/archival/Config.in
  2. --- busybox-1.15.2.orig/archival/Config.in 2009-10-08 02:59:09.000000000 +0200
  3. +++ busybox-1.15.2/archival/Config.in 2010-03-14 20:53:41.000000000 +0100
  4. @@ -180,6 +180,14 @@
  5. are actually slower than gzip at equivalent compression ratios
  6. and take up 3.2K of code.
  7. +config IPKG
  8. + bool "ipkg"
  9. + default n
  10. + select MD5SUM
  11. + select WGET
  12. + help
  13. + ipkg is the itsy package management system.
  14. +
  15. config RPM2CPIO
  16. bool "rpm2cpio"
  17. default n
  18. diff -Nur busybox-1.15.2.orig/archival/dpkg.c busybox-1.15.2/archival/dpkg.c
  19. --- busybox-1.15.2.orig/archival/dpkg.c 2009-10-08 02:59:09.000000000 +0200
  20. +++ busybox-1.15.2/archival/dpkg.c 2010-03-14 20:53:41.000000000 +0100
  21. @@ -1481,16 +1481,7 @@
  22. return ar_handle->sub_archive->buffer;
  23. }
  24. -static void FAST_FUNC data_extract_all_prefix(archive_handle_t *archive_handle)
  25. -{
  26. - char *name_ptr = archive_handle->file_header->name;
  27. -
  28. - name_ptr += strspn(name_ptr, "./");
  29. - if (name_ptr[0] != '\0') {
  30. - archive_handle->file_header->name = xasprintf("%s%s", archive_handle->buffer, name_ptr);
  31. - data_extract_all(archive_handle);
  32. - }
  33. -}
  34. +/* remove data_extract_all_prefix */
  35. static void unpack_package(deb_file_t *deb_file)
  36. {
  37. diff -Nur busybox-1.15.2.orig/archival/ipkg.c busybox-1.15.2/archival/ipkg.c
  38. --- busybox-1.15.2.orig/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
  39. +++ busybox-1.15.2/archival/ipkg.c 2010-03-14 20:53:41.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.15.2.orig/archival/Kbuild busybox-1.15.2/archival/Kbuild
  70. --- busybox-1.15.2.orig/archival/Kbuild 2009-09-26 15:14:56.000000000 +0200
  71. +++ busybox-1.15.2/archival/Kbuild 2010-03-14 20:53:41.000000000 +0100
  72. @@ -16,6 +16,7 @@
  73. lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
  74. lib-$(CONFIG_GUNZIP) += bbunzip.o
  75. lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
  76. +lib-$(CONFIG_IPKG) += ipkg.o
  77. lib-$(CONFIG_LZOP) += lzop.o lzo1x_1.o lzo1x_1o.o lzo1x_d.o bbunzip.o
  78. lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o
  79. lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
  80. diff -Nur busybox-1.15.2.orig/archival/libipkg/args.c busybox-1.15.2/archival/libipkg/args.c
  81. --- busybox-1.15.2.orig/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
  82. +++ busybox-1.15.2/archival/libipkg/args.c 2010-03-14 20:53:41.000000000 +0100
  83. @@ -0,0 +1,242 @@
  84. +/* args.c - parse command-line args
  85. +
  86. + Carl D. Worth
  87. +
  88. + Copyright 2001 University of Southern California
  89. +
  90. + This program is free software; you can redistribute it and/or modify
  91. + it under the terms of the GNU General Public License as published by
  92. + the Free Software Foundation; either version 2, or (at your option)
  93. + any later version.
  94. +
  95. + This program is distributed in the hope that it will be useful,
  96. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  97. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  98. + GNU General Public License for more details.
  99. + */
  100. +
  101. +#include <getopt.h>
  102. +#include <stdlib.h>
  103. +#include <string.h>
  104. +#include <unistd.h>
  105. +
  106. +#include "ipkg.h"
  107. +#include "ipkg_message.h"
  108. +
  109. +#include "args.h"
  110. +#include "sprintf_alloc.h"
  111. +
  112. +#include "libbb.h"
  113. +
  114. +
  115. +static void print_version(void);
  116. +
  117. +enum long_args_opt
  118. +{
  119. + ARGS_OPT_FORCE_DEFAULTS = 129,
  120. + ARGS_OPT_FORCE_DEPENDS,
  121. + ARGS_OPT_FORCE_OVERWRITE,
  122. + ARGS_OPT_FORCE_DOWNGRADE,
  123. + ARGS_OPT_FORCE_REINSTALL,
  124. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
  125. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
  126. + ARGS_OPT_FORCE_SPACE,
  127. + ARGS_OPT_NOACTION,
  128. + ARGS_OPT_NODEPS,
  129. + ARGS_OPT_VERBOSE_WGET,
  130. + ARGS_OPT_VERBOSITY,
  131. + ARGS_OPT_MULTIPLE_PROVIDERS
  132. +};
  133. +
  134. +int args_init(args_t *args)
  135. +{
  136. + const char *conf_file_dir;
  137. +
  138. + memset(args, 0, sizeof(args_t));
  139. +
  140. + args->dest = ARGS_DEFAULT_DEST;
  141. +
  142. + conf_file_dir = getenv("IPKG_CONF_DIR");
  143. + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
  144. + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
  145. + }
  146. + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
  147. + ARGS_DEFAULT_CONF_FILE_NAME);
  148. +
  149. + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
  150. + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
  151. + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
  152. + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
  153. + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
  154. + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
  155. + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
  156. + args->noaction = ARGS_DEFAULT_NOACTION;
  157. + args->nodeps = ARGS_DEFAULT_NODEPS;
  158. + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
  159. + args->verbosity = ARGS_DEFAULT_VERBOSITY;
  160. + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
  161. + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
  162. + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
  163. + args->multiple_providers = 0;
  164. + args->nocheckfordirorfile = 0;
  165. + args->noreadfeedsfile = 0;
  166. +
  167. + return 1;
  168. +}
  169. +
  170. +void args_deinit(args_t *args)
  171. +{
  172. + free(args->conf_file);
  173. + args->conf_file = NULL;
  174. +}
  175. +
  176. +int args_parse(args_t *args, int argc, char *argv[])
  177. +{
  178. + int c;
  179. + int option_index = 0;
  180. + int parse_err = 0;
  181. + static struct option long_options[] = {
  182. + {"query-all", 0, 0, 'A'},
  183. + {"conf-file", 1, 0, 'f'},
  184. + {"conf", 1, 0, 'f'},
  185. + {"dest", 1, 0, 'd'},
  186. + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  187. + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  188. + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  189. + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  190. + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  191. + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  192. + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  193. + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  194. + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  195. + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  196. + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
  197. + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
  198. + {"recursive", 0, 0,
  199. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  200. + {"force-removal-of-dependent-packages", 0, 0,
  201. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  202. + {"force_removal_of_dependent_packages", 0, 0,
  203. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  204. + {"force-removal-of-essential-packages", 0, 0,
  205. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  206. + {"force_removal_of_essential_packages", 0, 0,
  207. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  208. + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  209. + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  210. + {"noaction", 0, 0, ARGS_OPT_NOACTION},
  211. + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
  212. + {"offline", 1, 0, 'o'},
  213. + {"offline-root", 1, 0, 'o'},
  214. + {"test", 0, 0, ARGS_OPT_NOACTION},
  215. + {"tmp-dir", 1, 0, 't'},
  216. + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  217. + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  218. + {"verbosity", 2, 0, 'V'},
  219. + {"version", 0, 0, 'v'},
  220. + {0, 0, 0, 0}
  221. + };
  222. +
  223. + while (1) {
  224. + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
  225. + if (c == -1)
  226. + break;
  227. +
  228. + switch (c) {
  229. + case 'A':
  230. + args->query_all = 1;
  231. + break;
  232. + case 'd':
  233. + args->dest = optarg;
  234. + break;
  235. + case 'f':
  236. + free(args->conf_file);
  237. + args->conf_file = strdup(optarg);
  238. + break;
  239. + case 'o':
  240. + args->offline_root = optarg;
  241. + break;
  242. + case 'n':
  243. + args->noaction = 1;
  244. + break;
  245. + case 't':
  246. + args->tmp_dir = strdup(optarg);
  247. + break;
  248. + case 'v':
  249. + print_version();
  250. + exit(0);
  251. + case 'V':
  252. + case ARGS_OPT_VERBOSITY:
  253. + if (optarg)
  254. + args->verbosity = atoi(optarg);
  255. + else
  256. + args->verbosity += 1;
  257. + break;
  258. + case ARGS_OPT_FORCE_DEFAULTS:
  259. + args->force_defaults = 1;
  260. + break;
  261. + case ARGS_OPT_FORCE_DEPENDS:
  262. + args->force_depends = 1;
  263. + break;
  264. + case ARGS_OPT_FORCE_OVERWRITE:
  265. + args->force_overwrite = 1;
  266. + break;
  267. + case ARGS_OPT_FORCE_DOWNGRADE:
  268. + args->force_downgrade = 1;
  269. + break;
  270. + case ARGS_OPT_FORCE_REINSTALL:
  271. + args->force_reinstall = 1;
  272. + break;
  273. + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
  274. + args->force_removal_of_essential_packages = 1;
  275. + break;
  276. + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
  277. + args->force_removal_of_dependent_packages = 1;
  278. + break;
  279. + case ARGS_OPT_FORCE_SPACE:
  280. + args->force_space = 1;
  281. + break;
  282. + case ARGS_OPT_VERBOSE_WGET:
  283. + args->verbose_wget = 1;
  284. + break;
  285. + case ARGS_OPT_MULTIPLE_PROVIDERS:
  286. + args->multiple_providers = 1;
  287. + break;
  288. + case ARGS_OPT_NODEPS:
  289. + args->nodeps = 1;
  290. + break;
  291. + case ARGS_OPT_NOACTION:
  292. + args->noaction = 1;
  293. + break;
  294. + case ':':
  295. + parse_err++;
  296. + break;
  297. + case '?':
  298. + parse_err++;
  299. + break;
  300. + default:
  301. + bb_error_msg("Confusion: getopt_long returned %d\n", c);
  302. + }
  303. + }
  304. +
  305. + if (parse_err) {
  306. + return -parse_err;
  307. + } else {
  308. + return optind;
  309. + }
  310. +}
  311. +
  312. +void args_usage(const char *complaint)
  313. +{
  314. + if (complaint) {
  315. + bb_error_msg("%s\n", complaint);
  316. + }
  317. + print_version();
  318. + bb_show_usage();
  319. + exit(1);
  320. +}
  321. +
  322. +static void print_version(void)
  323. +{
  324. + bb_error_msg("version %s\n", IPKG_VERSION);
  325. +}
  326. diff -Nur busybox-1.15.2.orig/archival/libipkg/args.h busybox-1.15.2/archival/libipkg/args.h
  327. --- busybox-1.15.2.orig/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
  328. +++ busybox-1.15.2/archival/libipkg/args.h 2010-03-14 20:53:41.000000000 +0100
  329. @@ -0,0 +1,72 @@
  330. +/* args.h - parse command-line args
  331. +
  332. + Carl D. Worth
  333. +
  334. + Copyright 2001 University of Southern California
  335. +
  336. + This program is free software; you can redistribute it and/or modify
  337. + it under the terms of the GNU General Public License as published by
  338. + the Free Software Foundation; either version 2, or (at your option)
  339. + any later version.
  340. +
  341. + This program is distributed in the hope that it will be useful,
  342. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  343. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  344. + GNU General Public License for more details.
  345. +*/
  346. +
  347. +#ifndef ARGS_H
  348. +#define ARGS_H
  349. +
  350. +struct args
  351. +{
  352. + char *conf_file;
  353. + char *dest;
  354. + char *tmp_dir;
  355. + int force_defaults;
  356. + int force_depends;
  357. + int force_overwrite;
  358. + int force_downgrade;
  359. + int force_reinstall;
  360. + int force_removal_of_essential_packages;
  361. + int force_removal_of_dependent_packages;
  362. + int force_space;
  363. + int noaction;
  364. + int nodeps;
  365. + int multiple_providers;
  366. + int query_all;
  367. + int verbose_wget;
  368. + int verbosity;
  369. + int nocheckfordirorfile;
  370. + int noreadfeedsfile;
  371. + char *offline_root;
  372. + char *offline_root_pre_script_cmd;
  373. + char *offline_root_post_script_cmd;
  374. +};
  375. +typedef struct args args_t;
  376. +
  377. +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
  378. +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
  379. +#define ARGS_DEFAULT_DEST NULL
  380. +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
  381. +#define ARGS_DEFAULT_FORCE_DEPENDS 0
  382. +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
  383. +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
  384. +#define ARGS_DEFAULT_FORCE_REINSTALL 0
  385. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
  386. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
  387. +#define ARGS_DEFAULT_FORCE_SPACE 0
  388. +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
  389. +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
  390. +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
  391. +#define ARGS_DEFAULT_NOACTION 0
  392. +#define ARGS_DEFAULT_NODEPS 0
  393. +#define ARGS_DEFAULT_VERBOSE_WGET 0
  394. +#define ARGS_DEFAULT_VERBOSITY 1
  395. +
  396. +int args_init(args_t *args);
  397. +void args_deinit(args_t *args);
  398. +int args_parse(args_t *args, int argc, char *argv[]);
  399. +void args_usage(const char *complaint);
  400. +
  401. +#endif
  402. diff -Nur busybox-1.15.2.orig/archival/libipkg/conffile.c busybox-1.15.2/archival/libipkg/conffile.c
  403. --- busybox-1.15.2.orig/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
  404. +++ busybox-1.15.2/archival/libipkg/conffile.c 2010-03-14 20:53:41.000000000 +0100
  405. @@ -0,0 +1,65 @@
  406. +/* conffile.c - the itsy package management system
  407. +
  408. + Carl D. Worth
  409. +
  410. + Copyright (C) 2001 University of Southern California
  411. +
  412. + This program is free software; you can redistribute it and/or
  413. + modify it under the terms of the GNU General Public License as
  414. + published by the Free Software Foundation; either version 2, or (at
  415. + your option) any later version.
  416. +
  417. + This program is distributed in the hope that it will be useful, but
  418. + WITHOUT ANY WARRANTY; without even the implied warranty of
  419. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  420. + General Public License for more details.
  421. +*/
  422. +
  423. +#include <string.h>
  424. +#include <stdlib.h>
  425. +
  426. +#include "libbb.h"
  427. +#include "ipkg.h"
  428. +#include "ipkg_message.h"
  429. +
  430. +#include "conffile.h"
  431. +#include "file_util.h"
  432. +#include "sprintf_alloc.h"
  433. +
  434. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum)
  435. +{
  436. + return nv_pair_init(conffile, file_name, (char *)md5sum);
  437. +}
  438. +
  439. +void conffile_deinit(conffile_t *conffile)
  440. +{
  441. + nv_pair_deinit(conffile);
  442. +}
  443. +
  444. +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
  445. +{
  446. + uint8_t *md5sum;
  447. + char *filename = conffile->name;
  448. + char *root_filename;
  449. + int ret;
  450. +
  451. + if (conffile->value == NULL) {
  452. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
  453. + return 1;
  454. + }
  455. +
  456. + root_filename = root_filename_alloc(conf, filename);
  457. +
  458. + md5sum = file_md5sum_alloc(root_filename);
  459. +
  460. + ret = strcmp((char *)md5sum, conffile->value);
  461. + if (ret) {
  462. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
  463. + conffile->name, md5sum, conffile->value);
  464. + }
  465. +
  466. + free(root_filename);
  467. + free(md5sum);
  468. +
  469. + return ret;
  470. +}
  471. diff -Nur busybox-1.15.2.orig/archival/libipkg/conffile.h busybox-1.15.2/archival/libipkg/conffile.h
  472. --- busybox-1.15.2.orig/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
  473. +++ busybox-1.15.2/archival/libipkg/conffile.h 2010-03-14 20:53:41.000000000 +0100
  474. @@ -0,0 +1,30 @@
  475. +/* conffile.h - the itsy package management system
  476. +
  477. + Carl D. Worth
  478. +
  479. + Copyright (C) 2001 University of Southern California
  480. +
  481. + This program is free software; you can redistribute it and/or
  482. + modify it under the terms of the GNU General Public License as
  483. + published by the Free Software Foundation; either version 2, or (at
  484. + your option) any later version.
  485. +
  486. + This program is distributed in the hope that it will be useful, but
  487. + WITHOUT ANY WARRANTY; without even the implied warranty of
  488. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  489. + General Public License for more details.
  490. +*/
  491. +
  492. +#ifndef CONFFILE_H
  493. +#define CONFFILE_H
  494. +
  495. +#include "nv_pair.h"
  496. +
  497. +typedef struct nv_pair conffile_t;
  498. +
  499. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum);
  500. +void conffile_deinit(conffile_t *conffile);
  501. +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
  502. +
  503. +#endif
  504. +
  505. diff -Nur busybox-1.15.2.orig/archival/libipkg/conffile_list.c busybox-1.15.2/archival/libipkg/conffile_list.c
  506. --- busybox-1.15.2.orig/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
  507. +++ busybox-1.15.2/archival/libipkg/conffile_list.c 2010-03-14 20:53:41.000000000 +0100
  508. @@ -0,0 +1,47 @@
  509. +/* conffile_list.c - the itsy package management system
  510. +
  511. + Carl D. Worth
  512. +
  513. + Copyright (C) 2001 University of Southern California
  514. +
  515. + This program is free software; you can redistribute it and/or
  516. + modify it under the terms of the GNU General Public License as
  517. + published by the Free Software Foundation; either version 2, or (at
  518. + your option) any later version.
  519. +
  520. + This program is distributed in the hope that it will be useful, but
  521. + WITHOUT ANY WARRANTY; without even the implied warranty of
  522. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  523. + General Public License for more details.
  524. +*/
  525. +
  526. +#include "ipkg.h"
  527. +
  528. +#include "conffile_list.h"
  529. +
  530. +int conffile_list_init(conffile_list_t *list)
  531. +{
  532. + return nv_pair_list_init(list);
  533. +}
  534. +
  535. +void conffile_list_deinit(conffile_list_t *list)
  536. +{
  537. + nv_pair_list_deinit(list);
  538. +}
  539. +
  540. +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
  541. + const char *md5sum)
  542. +{
  543. + return nv_pair_list_append(list, file_name, md5sum);
  544. +}
  545. +
  546. +int conffile_list_push(conffile_list_t *list, conffile_t *data)
  547. +{
  548. + return nv_pair_list_push(list, data);
  549. +}
  550. +
  551. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
  552. +{
  553. + return nv_pair_list_pop(list);
  554. +}
  555. +
  556. diff -Nur busybox-1.15.2.orig/archival/libipkg/conffile_list.h busybox-1.15.2/archival/libipkg/conffile_list.h
  557. --- busybox-1.15.2.orig/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
  558. +++ busybox-1.15.2/archival/libipkg/conffile_list.h 2010-03-14 20:53:41.000000000 +0100
  559. @@ -0,0 +1,36 @@
  560. +/* conffile_list.h - the itsy package management system
  561. +
  562. + Carl D. Worth
  563. +
  564. + Copyright (C) 2001 University of Southern California
  565. +
  566. + This program is free software; you can redistribute it and/or
  567. + modify it under the terms of the GNU General Public License as
  568. + published by the Free Software Foundation; either version 2, or (at
  569. + your option) any later version.
  570. +
  571. + This program is distributed in the hope that it will be useful, but
  572. + WITHOUT ANY WARRANTY; without even the implied warranty of
  573. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  574. + General Public License for more details.
  575. +*/
  576. +
  577. +#ifndef CONFFILE_LIST_H
  578. +#define CONFFILE_LIST_H
  579. +
  580. +#include "conffile.h"
  581. +#include "nv_pair_list.h"
  582. +
  583. +typedef struct nv_pair_list_elt conffile_list_elt_t;
  584. +typedef struct nv_pair_list conffile_list_t;
  585. +
  586. +int conffile_list_init(conffile_list_t *list);
  587. +void conffile_list_deinit(conffile_list_t *list);
  588. +
  589. +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
  590. + const char *root_dir);
  591. +int conffile_list_push(conffile_list_t *list, conffile_t *data);
  592. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
  593. +
  594. +#endif
  595. +
  596. diff -Nur busybox-1.15.2.orig/archival/libipkg/file_util.c busybox-1.15.2/archival/libipkg/file_util.c
  597. --- busybox-1.15.2.orig/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
  598. +++ busybox-1.15.2/archival/libipkg/file_util.c 2010-03-14 20:53:41.000000000 +0100
  599. @@ -0,0 +1,186 @@
  600. +/* file_util.c - convenience routines for common stat operations
  601. +
  602. + Carl D. Worth
  603. +
  604. + Copyright (C) 2001 University of Southern California
  605. +
  606. + This program is free software; you can redistribute it and/or
  607. + modify it under the terms of the GNU General Public License as
  608. + published by the Free Software Foundation; either version 2, or (at
  609. + your option) any later version.
  610. +
  611. + This program is distributed in the hope that it will be useful, but
  612. + WITHOUT ANY WARRANTY; without even the implied warranty of
  613. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  614. + General Public License for more details.
  615. +*/
  616. +
  617. +#include "ipkg.h"
  618. +#include <sys/types.h>
  619. +#include <sys/stat.h>
  620. +
  621. +#include "sprintf_alloc.h"
  622. +#include "file_util.h"
  623. +#include "libbb.h"
  624. +#undef strlen
  625. +
  626. +int file_exists(const char *file_name)
  627. +{
  628. + int err;
  629. + struct stat stat_buf;
  630. +
  631. + err = stat(file_name, &stat_buf);
  632. + if (err == 0) {
  633. + return 1;
  634. + } else {
  635. + return 0;
  636. + }
  637. +}
  638. +
  639. +int file_is_dir(const char *file_name)
  640. +{
  641. + int err;
  642. + struct stat stat_buf;
  643. +
  644. + err = stat(file_name, &stat_buf);
  645. + if (err) {
  646. + return 0;
  647. + }
  648. +
  649. + return S_ISDIR(stat_buf.st_mode);
  650. +}
  651. +
  652. +/* read a single line from a file, stopping at a newline or EOF.
  653. + If a newline is read, it will appear in the resulting string.
  654. + Return value is a malloc'ed char * which should be freed at
  655. + some point by the caller.
  656. +
  657. + Return value is NULL if the file is at EOF when called.
  658. +*/
  659. +#define FILE_READ_LINE_BUF_SIZE 1024
  660. +char *file_read_line_alloc(FILE *file)
  661. +{
  662. + char buf[FILE_READ_LINE_BUF_SIZE];
  663. + int buf_len;
  664. + char *line = NULL;
  665. + int line_size = 0;
  666. +
  667. + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
  668. + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
  669. + buf_len = strlen(buf);
  670. + if (line) {
  671. + line_size += buf_len;
  672. + line = realloc(line, line_size);
  673. + if (line == NULL) {
  674. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  675. + break;
  676. + }
  677. + strcat(line, buf);
  678. + } else {
  679. + line_size = buf_len + 1;
  680. + line = strdup(buf);
  681. + }
  682. + if (buf[buf_len - 1] == '\n') {
  683. + break;
  684. + }
  685. + }
  686. +
  687. + return line;
  688. +}
  689. +
  690. +int file_move(const char *src, const char *dest)
  691. +{
  692. + int err;
  693. +
  694. + err = rename(src, dest);
  695. +
  696. + if (err && errno == EXDEV) {
  697. + err = file_copy(src, dest);
  698. + unlink(src);
  699. + } else if (err) {
  700. + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
  701. + __FUNCTION__, src, dest, strerror(errno));
  702. + }
  703. +
  704. + return err;
  705. +}
  706. +
  707. +/* I put these here to keep libbb dependencies from creeping all over
  708. + the ipkg code */
  709. +int file_copy(const char *src, const char *dest)
  710. +{
  711. + int err;
  712. +
  713. + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
  714. + if (err) {
  715. + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
  716. + __FUNCTION__, src, dest);
  717. + }
  718. +
  719. + return err;
  720. +}
  721. +
  722. +int file_mkdir_hier(char *path, long mode)
  723. +{
  724. + return bb_make_directory(path, mode, FILEUTILS_RECUR);
  725. +}
  726. +
  727. +static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
  728. + unsigned hash_length)
  729. +{
  730. + /* xzalloc zero-terminates */
  731. + char *hex_value = xzalloc((hash_length * 2) + 1);
  732. + bin2hex(hex_value, (char*)hash_value, hash_length);
  733. + return (unsigned char *)hex_value;
  734. +}
  735. +
  736. +static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
  737. +{
  738. + int src_fd, hash_len, count;
  739. + union _ctx_ {
  740. + sha1_ctx_t sha1;
  741. + md5_ctx_t md5;
  742. + } context;
  743. + uint8_t *hash_value = NULL;
  744. + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
  745. + void FAST_FUNC (*update)(const void*, size_t, void*);
  746. + void FAST_FUNC (*final)(void*, void*);
  747. +
  748. + src_fd = open_or_warn_stdin(filename);
  749. + if (src_fd < 0) {
  750. + return NULL;
  751. + }
  752. +
  753. + /* figure specific hash algorithims */
  754. + if (ENABLE_MD5SUM && hash_algo == HASH_MD5) {
  755. + md5_begin(&context.md5);
  756. + update = (void*)md5_hash;
  757. + final = (void*)md5_end;
  758. + hash_len = 16;
  759. + } else {
  760. + bb_error_msg_and_die("algorithm not supported");
  761. + }
  762. +
  763. + while (0 < (count = safe_read(src_fd, in_buf, 4096))) {
  764. + update(in_buf, count, &context);
  765. + }
  766. +
  767. + if (count == 0) {
  768. + final(in_buf, &context);
  769. + hash_value = hash_bin_to_hex(in_buf, hash_len);
  770. + }
  771. +
  772. + RELEASE_CONFIG_BUFFER(in_buf);
  773. +
  774. + if (src_fd != STDIN_FILENO) {
  775. + close(src_fd);
  776. + }
  777. +
  778. + return hash_value;
  779. +}
  780. +
  781. +uint8_t *file_md5sum_alloc(const char *file_name)
  782. +{
  783. + return hash_file(file_name, HASH_MD5);
  784. +}
  785. +
  786. diff -Nur busybox-1.15.2.orig/archival/libipkg/file_util.h busybox-1.15.2/archival/libipkg/file_util.h
  787. --- busybox-1.15.2.orig/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
  788. +++ busybox-1.15.2/archival/libipkg/file_util.h 2010-03-14 20:53:41.000000000 +0100
  789. @@ -0,0 +1,29 @@
  790. +/* file_util.h - convenience routines for common file operations
  791. +
  792. + Carl D. Worth
  793. +
  794. + Copyright (C) 2001 University of Southern California
  795. +
  796. + This program is free software; you can redistribute it and/or
  797. + modify it under the terms of the GNU General Public License as
  798. + published by the Free Software Foundation; either version 2, or (at
  799. + your option) any later version.
  800. +
  801. + This program is distributed in the hope that it will be useful, but
  802. + WITHOUT ANY WARRANTY; without even the implied warranty of
  803. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  804. + General Public License for more details.
  805. +*/
  806. +
  807. +#ifndef FILE_UTIL_H
  808. +#define FILE_UTIL_H
  809. +
  810. +int file_exists(const char *file_name);
  811. +int file_is_dir(const char *file_name);
  812. +char *file_read_line_alloc(FILE *file);
  813. +int file_move(const char *src, const char *dest);
  814. +int file_copy(const char *src, const char *dest);
  815. +int file_mkdir_hier(char *path, long mode);
  816. +uint8_t *file_md5sum_alloc(const char *file_name);
  817. +
  818. +#endif
  819. diff -Nur busybox-1.15.2.orig/archival/libipkg/hash_table.c busybox-1.15.2/archival/libipkg/hash_table.c
  820. --- busybox-1.15.2.orig/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
  821. +++ busybox-1.15.2/archival/libipkg/hash_table.c 2010-03-14 20:53:41.000000000 +0100
  822. @@ -0,0 +1,155 @@
  823. +/* hash.c - hash tables for ipkg
  824. +
  825. + Steven M. Ayer, Jamey Hicks
  826. +
  827. + Copyright (C) 2002 Compaq Computer Corporation
  828. +
  829. + This program is free software; you can redistribute it and/or
  830. + modify it under the terms of the GNU General Public License as
  831. + published by the Free Software Foundation; either version 2, or (at
  832. + your option) any later version.
  833. +
  834. + This program is distributed in the hope that it will be useful, but
  835. + WITHOUT ANY WARRANTY; without even the implied warranty of
  836. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  837. + General Public License for more details.
  838. +*/
  839. +
  840. +#include <errno.h>
  841. +#include <stdio.h>
  842. +#include <stdlib.h>
  843. +#include <string.h>
  844. +#include "hash_table.h"
  845. +#include "ipkg_message.h"
  846. +
  847. +
  848. +static int hash_index(hash_table_t *hash, const char *pkg_name);
  849. +static int rotating(const char *key, int len, int prime);
  850. +
  851. +static int hash_index(hash_table_t *hash, const char *pkg_name)
  852. +{
  853. + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
  854. +}
  855. +
  856. +static int rotating(const char *key, int len, int prime)
  857. +{
  858. + unsigned int hash, i;
  859. + for (hash=len, i=0; i<len; ++i)
  860. + hash = (hash<<4)^(hash>>28)^key[i];
  861. + return (hash % prime);
  862. +}
  863. +
  864. +
  865. +/*
  866. + * this is an open table keyed by strings
  867. + */
  868. +int hash_table_init(const char *name, hash_table_t *hash, int len)
  869. +{
  870. + static int primes_table[] = {
  871. + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
  872. + 19471, 23143, 33961, 46499, 49727, 99529, 0
  873. + };
  874. + int *picker;
  875. +
  876. + if (hash->entries != NULL) {
  877. + /* we have been here already */
  878. + return 0;
  879. + }
  880. +
  881. + hash->name = name;
  882. + hash->entries = NULL;
  883. + hash->n_entries = 0;
  884. + hash->hash_entry_key = NULL;
  885. +
  886. + picker = primes_table;
  887. + while(*picker && (*picker++ < len));
  888. + if(!*picker)
  889. + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
  890. + --picker;
  891. +
  892. + hash->n_entries = *picker;
  893. + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
  894. + if (hash->entries == NULL) {
  895. + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
  896. + return ENOMEM;
  897. + }
  898. + return 0;
  899. +}
  900. +
  901. +void hash_table_deinit(hash_table_t *hash)
  902. +{
  903. + free(hash->entries);
  904. + hash->entries = NULL;
  905. + hash->n_entries = 0;
  906. +}
  907. +
  908. +void *hash_table_get(hash_table_t *hash, const char *key)
  909. +{
  910. + int ndx= hash_index(hash, key);
  911. + hash_entry_t *hash_entry = hash->entries + ndx;
  912. + while (hash_entry)
  913. + {
  914. + if (hash_entry->key)
  915. + {
  916. + if (strcmp(key, hash_entry->key) == 0) {
  917. + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
  918. + return hash_entry->data;
  919. + }
  920. + }
  921. + hash_entry = hash_entry->next;
  922. + }
  923. + return NULL;
  924. +}
  925. +
  926. +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
  927. +{
  928. + int ndx= hash_index(hash, key);
  929. + hash_entry_t *hash_entry = hash->entries + ndx;
  930. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
  931. + if (hash_entry->key) {
  932. + if (strcmp(hash_entry->key, key) == 0) {
  933. + /* alread in table, update the value */
  934. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
  935. + hash_entry->data = value;
  936. + return 0;
  937. + } else {
  938. + /*
  939. + * if this is a collision, we have to go to the end of the ll,
  940. + * then add a new entry
  941. + * before we can hook up the value
  942. + */
  943. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
  944. + while (hash_entry->next)
  945. + hash_entry = hash_entry->next;
  946. + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
  947. + if (!hash_entry->next) {
  948. + return -ENOMEM;
  949. + }
  950. + hash_entry = hash_entry->next;
  951. + hash_entry->next = NULL;
  952. + }
  953. + }
  954. + hash->n_elements++;
  955. + hash_entry->key = strdup(key);
  956. + hash_entry->data = value;
  957. +
  958. + return 0;
  959. +}
  960. +
  961. +
  962. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
  963. +{
  964. + int i;
  965. + if (!hash || !f)
  966. + return;
  967. +
  968. + for (i = 0; i < hash->n_entries; i++) {
  969. + hash_entry_t *hash_entry = (hash->entries + i);
  970. + do {
  971. + if(hash_entry->key) {
  972. + f(hash_entry->key, hash_entry->data, data);
  973. + }
  974. + } while((hash_entry = hash_entry->next));
  975. + }
  976. +}
  977. +
  978. diff -Nur busybox-1.15.2.orig/archival/libipkg/hash_table.h busybox-1.15.2/archival/libipkg/hash_table.h
  979. --- busybox-1.15.2.orig/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
  980. +++ busybox-1.15.2/archival/libipkg/hash_table.h 2010-03-14 20:53:41.000000000 +0100
  981. @@ -0,0 +1,44 @@
  982. +/* hash.h - hash tables for ipkg
  983. +
  984. + Steven M. Ayer, Jamey Hicks
  985. +
  986. + Copyright (C) 2002 Compaq Computer Corporation
  987. +
  988. + This program is free software; you can redistribute it and/or
  989. + modify it under the terms of the GNU General Public License as
  990. + published by the Free Software Foundation; either version 2, or (at
  991. + your option) any later version.
  992. +
  993. + This program is distributed in the hope that it will be useful, but
  994. + WITHOUT ANY WARRANTY; without even the implied warranty of
  995. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  996. + General Public License for more details.
  997. +*/
  998. +
  999. +#ifndef _HASH_TABLE_H_
  1000. +#define _HASH_TABLE_H_
  1001. +
  1002. +typedef struct hash_entry hash_entry_t;
  1003. +typedef struct hash_table hash_table_t;
  1004. +
  1005. +struct hash_entry {
  1006. + const char * key;
  1007. + void * data;
  1008. + struct hash_entry * next;
  1009. +};
  1010. +
  1011. +struct hash_table {
  1012. + const char *name;
  1013. + hash_entry_t * entries;
  1014. + int n_entries; /* number of buckets */
  1015. + int n_elements;
  1016. + const char * (*hash_entry_key)(void * data);
  1017. +};
  1018. +
  1019. +int hash_table_init(const char *name, hash_table_t *hash, int len);
  1020. +void hash_table_deinit(hash_table_t *hash);
  1021. +void *hash_table_get(hash_table_t *hash, const char *key);
  1022. +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
  1023. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
  1024. +
  1025. +#endif /* _HASH_TABLE_H_ */
  1026. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_cmd.c busybox-1.15.2/archival/libipkg/ipkg_cmd.c
  1027. --- busybox-1.15.2.orig/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
  1028. +++ busybox-1.15.2/archival/libipkg/ipkg_cmd.c 2010-03-14 20:57:14.000000000 +0100
  1029. @@ -0,0 +1,1386 @@
  1030. +/* ipkg_cmd.c - the itsy package management system
  1031. +
  1032. + Carl D. Worth
  1033. +
  1034. + Copyright (C) 2001 University of Southern California
  1035. +
  1036. + This program is free software; you can redistribute it and/or
  1037. + modify it under the terms of the GNU General Public License as
  1038. + published by the Free Software Foundation; either version 2, or (at
  1039. + your option) any later version.
  1040. +
  1041. + This program is distributed in the hope that it will be useful, but
  1042. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1043. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1044. + General Public License for more details.
  1045. +*/
  1046. +
  1047. +#include <string.h>
  1048. +
  1049. +#include "ipkg.h"
  1050. +#include <libgen.h>
  1051. +#include <glob.h>
  1052. +#include <errno.h>
  1053. +#include <stdlib.h>
  1054. +#include <unistd.h>
  1055. +#include <signal.h>
  1056. +#include <stdio.h>
  1057. +#include <dirent.h>
  1058. +
  1059. +#include "ipkg_conf.h"
  1060. +#include "ipkg_cmd.h"
  1061. +#include "ipkg_message.h"
  1062. +#include "pkg.h"
  1063. +#include "pkg_dest.h"
  1064. +#include "pkg_parse.h"
  1065. +#include "sprintf_alloc.h"
  1066. +#include "pkg.h"
  1067. +#include "file_util.h"
  1068. +#include "str_util.h"
  1069. +#include "unarchive.h"
  1070. +
  1071. +#include <fnmatch.h>
  1072. +
  1073. +
  1074. +#include "ipkg_download.h"
  1075. +#include "ipkg_install.h"
  1076. +#include "ipkg_upgrade.h"
  1077. +#include "ipkg_remove.h"
  1078. +#include "ipkg_configure.h"
  1079. +#include "ipkg_message.h"
  1080. +
  1081. +#include "libipkg.h"
  1082. +static void *p_userdata = NULL;
  1083. +
  1084. +static int ipkg_update_cmd(ipkg_conf_t *conf);
  1085. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1086. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1087. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1088. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1089. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf);
  1090. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1091. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1092. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1093. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1094. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1095. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1096. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1097. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1098. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1099. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1100. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1101. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1102. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1103. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1104. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1105. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1106. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1107. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf);
  1108. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1109. +
  1110. +/* XXX: CLEANUP: The usage strings should be incorporated into this
  1111. + array for easier maintenance */
  1112. +static ipkg_cmd_t cmds[] = {
  1113. + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
  1114. + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
  1115. + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
  1116. + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
  1117. + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
  1118. + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
  1119. + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
  1120. + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
  1121. + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
  1122. + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
  1123. + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
  1124. + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
  1125. + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
  1126. + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
  1127. + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
  1128. + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1129. + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1130. + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1131. + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1132. + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1133. + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1134. + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
  1135. + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
  1136. + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
  1137. + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
  1138. + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
  1139. + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
  1140. + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
  1141. + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
  1142. +};
  1143. +
  1144. +int ipkg_state_changed;
  1145. +static void write_status_files_if_changed(ipkg_conf_t *conf)
  1146. +{
  1147. + if (ipkg_state_changed && !conf->noaction) {
  1148. + ipkg_message(conf, IPKG_INFO,
  1149. + " writing status file\n");
  1150. + ipkg_conf_write_status_files(conf);
  1151. + pkg_write_changed_filelists(conf);
  1152. + } else {
  1153. + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
  1154. + }
  1155. +}
  1156. +
  1157. +
  1158. +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
  1159. +
  1160. +ipkg_cmd_t *ipkg_cmd_find(const char *name)
  1161. +{
  1162. + int i;
  1163. + ipkg_cmd_t *cmd;
  1164. +
  1165. + for (i=0; i < num_cmds; i++) {
  1166. + cmd = &cmds[i];
  1167. + if (strcmp(name, cmd->name) == 0) {
  1168. + return cmd;
  1169. + }
  1170. + }
  1171. +
  1172. + return NULL;
  1173. +}
  1174. +
  1175. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
  1176. +{
  1177. + int result;
  1178. + p_userdata = userdata;
  1179. +
  1180. +
  1181. + result = (cmd->fun)(conf, argc, argv);
  1182. + if ( result == 0 ) {
  1183. + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
  1184. + } else {
  1185. + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
  1186. +
  1187. + }
  1188. + if ( error_list ) {
  1189. + reverse_error_list(&error_list);
  1190. +
  1191. + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
  1192. + /* Here we print the errors collected and free the list */
  1193. + while (error_list != NULL) {
  1194. + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
  1195. + error_list = error_list->next;
  1196. +
  1197. + }
  1198. + free_error_list(&error_list);
  1199. +
  1200. + }
  1201. +
  1202. + p_userdata = NULL;
  1203. + return result;
  1204. +}
  1205. +
  1206. +static int ipkg_update_cmd(ipkg_conf_t *conf)
  1207. +{
  1208. + int err;
  1209. + int failures;
  1210. + char *lists_dir;
  1211. + pkg_src_list_elt_t *iter;
  1212. + pkg_src_t *src;
  1213. +
  1214. +
  1215. + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
  1216. +
  1217. + if (! file_is_dir(lists_dir)) {
  1218. + if (file_exists(lists_dir)) {
  1219. + ipkg_message(conf, IPKG_ERROR,
  1220. + "%s: ERROR: %s exists, but is not a directory\n",
  1221. + __FUNCTION__, lists_dir);
  1222. + free(lists_dir);
  1223. + return EINVAL;
  1224. + }
  1225. + err = file_mkdir_hier(lists_dir, 0755);
  1226. + if (err) {
  1227. + ipkg_message(conf, IPKG_ERROR,
  1228. + "%s: ERROR: failed to make directory %s: %s\n",
  1229. + __FUNCTION__, lists_dir, strerror(errno));
  1230. + free(lists_dir);
  1231. + return EINVAL;
  1232. + }
  1233. + }
  1234. +
  1235. + failures = 0;
  1236. + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
  1237. + char *url, *list_file_name;
  1238. +
  1239. + src = iter->data;
  1240. +
  1241. + if (src->extra_data) /* debian style? */
  1242. + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
  1243. + src->gzip ? "Packages.gz" : "Packages");
  1244. + else
  1245. + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
  1246. +
  1247. + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
  1248. + if (src->gzip) {
  1249. + char *tmp;
  1250. + char *tmp_file_name;
  1251. + FILE *in, *out;
  1252. +
  1253. + tmp = strdup ("/tmp/ipkg.XXXXXX");
  1254. +
  1255. + if (mkdtemp (tmp) == NULL) {
  1256. + perror ("mkdtemp");
  1257. + failures++;
  1258. + continue;
  1259. + }
  1260. +
  1261. + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
  1262. + err = ipkg_download(conf, url, tmp_file_name);
  1263. + if (err == 0) {
  1264. + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
  1265. + in = fopen (tmp_file_name, "r");
  1266. + out = fopen (list_file_name, "w");
  1267. + if (in && out) {
  1268. + inflate_unzip_result res;
  1269. + inflate_unzip (&res, 0x8000, fileno(in), fileno(out));
  1270. + } else
  1271. + err = 1;
  1272. + if (in)
  1273. + fclose (in);
  1274. + if (out)
  1275. + fclose (out);
  1276. + unlink (tmp_file_name);
  1277. + rmdir (tmp);
  1278. + free (tmp);
  1279. + }
  1280. + } else
  1281. + err = ipkg_download(conf, url, list_file_name);
  1282. + if (err) {
  1283. + failures++;
  1284. + } else {
  1285. + ipkg_message(conf, IPKG_NOTICE,
  1286. + "Updated list of available packages in %s\n",
  1287. + list_file_name);
  1288. + }
  1289. + free(url);
  1290. + free(list_file_name);
  1291. + }
  1292. + free(lists_dir);
  1293. +
  1294. +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
  1295. +#warning here
  1296. + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
  1297. + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
  1298. + * -Jamey 3/1/03
  1299. + */
  1300. + {
  1301. + int i;
  1302. + int changed = 0;
  1303. + pkg_vec_t *available = pkg_vec_alloc();
  1304. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1305. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
  1306. + for (i = 0; i < available->len; i++) {
  1307. + pkg_t *pkg = available->pkgs[i];
  1308. + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
  1309. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
  1310. + pkg->state_want = SW_UNKNOWN;
  1311. + changed = 1;
  1312. + }
  1313. + }
  1314. + pkg_vec_free(available);
  1315. + if (changed) {
  1316. + write_status_files_if_changed(conf);
  1317. + }
  1318. + }
  1319. +#endif
  1320. +
  1321. + return failures;
  1322. +}
  1323. +
  1324. +
  1325. +/* scan the args passed and cache the local filenames of the packages */
  1326. +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
  1327. +{
  1328. + int i;
  1329. + int err;
  1330. +
  1331. + /*
  1332. + * First scan through package names/urls
  1333. + * For any urls, download the packages and install in database.
  1334. + * For any files, install package info in database.
  1335. + */
  1336. + for (i = 0; i < argc; i ++) {
  1337. + char *filename = argv [i];
  1338. + //char *tmp = basename (tmp);
  1339. + //int tmplen = strlen (tmp);
  1340. +
  1341. + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
  1342. + // continue;
  1343. + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
  1344. + // continue;
  1345. +
  1346. + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
  1347. +
  1348. + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
  1349. + if (err)
  1350. + return err;
  1351. + }
  1352. + return 0;
  1353. +}
  1354. +
  1355. +struct ipkg_intercept
  1356. +{
  1357. + char *oldpath;
  1358. + char *statedir;
  1359. +};
  1360. +
  1361. +typedef struct ipkg_intercept *ipkg_intercept_t;
  1362. +ipkg_intercept_t ipkg_prep_intercepts(void);
  1363. +
  1364. +ipkg_intercept_t ipkg_prep_intercepts(void)
  1365. +{
  1366. + ipkg_intercept_t ctx;
  1367. + char *newpath;
  1368. + int gen;
  1369. +
  1370. + ctx = malloc (sizeof (*ctx));
  1371. + ctx->oldpath = strdup (getenv ("PATH"));
  1372. +
  1373. + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
  1374. + setenv ("PATH", newpath, 1);
  1375. + free (newpath);
  1376. +
  1377. + gen = 0;
  1378. + retry:
  1379. + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
  1380. + if (mkdir (ctx->statedir, 0770) < 0) {
  1381. + if (errno == EEXIST) {
  1382. + free (ctx->statedir);
  1383. + gen++;
  1384. + goto retry;
  1385. + }
  1386. + perror (ctx->statedir);
  1387. + return NULL;
  1388. + }
  1389. + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
  1390. + return ctx;
  1391. +}
  1392. +
  1393. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx);
  1394. +
  1395. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
  1396. +{
  1397. + char *cmd;
  1398. + DIR *dir;
  1399. + int err = 0;
  1400. +
  1401. + setenv ("PATH", ctx->oldpath, 1);
  1402. + free (ctx->oldpath);
  1403. +
  1404. + dir = opendir (ctx->statedir);
  1405. + if (dir) {
  1406. + struct dirent *de;
  1407. + while (de = readdir (dir), de != NULL) {
  1408. + char *path;
  1409. +
  1410. + if (de->d_name[0] == '.')
  1411. + continue;
  1412. +
  1413. + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
  1414. + if (access (path, X_OK) == 0) {
  1415. + if (system (path)) {
  1416. + err = errno;
  1417. + perror (de->d_name);
  1418. + }
  1419. + }
  1420. + free (path);
  1421. + }
  1422. + } else
  1423. + perror (ctx->statedir);
  1424. +
  1425. + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
  1426. + system (cmd);
  1427. + free (cmd);
  1428. +
  1429. + free (ctx->statedir);
  1430. + free (ctx);
  1431. +
  1432. + return err;
  1433. +}
  1434. +
  1435. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
  1436. +{
  1437. + pkg_vec_t *all;
  1438. + int i;
  1439. + pkg_t *pkg;
  1440. + ipkg_intercept_t ic;
  1441. + int r, err = 0;
  1442. +
  1443. + ipkg_message(conf, IPKG_INFO,
  1444. + "Configuring unpacked packages\n");
  1445. + fflush( stdout );
  1446. +
  1447. + all = pkg_vec_alloc();
  1448. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  1449. +
  1450. + ic = ipkg_prep_intercepts();
  1451. +
  1452. + for(i = 0; i < all->len; i++) {
  1453. + pkg = all->pkgs[i];
  1454. +
  1455. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1456. + continue;
  1457. +
  1458. + if (pkg->state_status == SS_UNPACKED) {
  1459. + ipkg_message(conf, IPKG_NOTICE,
  1460. + "Configuring %s\n", pkg->name);
  1461. + fflush( stdout );
  1462. + r = ipkg_configure(conf, pkg);
  1463. + if (r == 0) {
  1464. + pkg->state_status = SS_INSTALLED;
  1465. + pkg->parent->state_status = SS_INSTALLED;
  1466. + pkg->state_flag &= ~SF_PREFER;
  1467. + } else {
  1468. + if (!err)
  1469. + err = r;
  1470. + }
  1471. + }
  1472. + }
  1473. +
  1474. + r = ipkg_finalize_intercepts (ic);
  1475. + if (r && !err)
  1476. + err = r;
  1477. +
  1478. + pkg_vec_free(all);
  1479. + return err;
  1480. +}
  1481. +
  1482. +static void sigint_handler(int sig)
  1483. +{
  1484. + signal(sig, SIG_DFL);
  1485. + ipkg_message(NULL, IPKG_NOTICE,
  1486. + "ipkg: interrupted. writing out status database\n");
  1487. + write_status_files_if_changed(global_conf);
  1488. + exit(128 + sig);
  1489. +}
  1490. +
  1491. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1492. +{
  1493. + int i;
  1494. + char *arg;
  1495. + int err=0;
  1496. +
  1497. + global_conf = conf;
  1498. + signal(SIGINT, sigint_handler);
  1499. +
  1500. + /*
  1501. + * Now scan through package names and install
  1502. + */
  1503. + for (i=0; i < argc; i++) {
  1504. + arg = argv[i];
  1505. +
  1506. + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
  1507. + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
  1508. + if (err != EINVAL && err != 0)
  1509. + return err;
  1510. + }
  1511. + pkg_info_preinstall_check(conf);
  1512. +
  1513. + for (i=0; i < argc; i++) {
  1514. + arg = argv[i];
  1515. + if (conf->multiple_providers)
  1516. + err = ipkg_install_multi_by_name(conf, arg);
  1517. + else{
  1518. + err = ipkg_install_by_name(conf, arg);
  1519. + }
  1520. + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
  1521. + ipkg_message(conf, IPKG_ERROR,
  1522. + "Cannot find package %s.\n"
  1523. + "Check the spelling or perhaps run 'ipkg update'\n",
  1524. + arg);
  1525. + }
  1526. + }
  1527. +
  1528. + /* recheck to verify that all dependences are satisfied */
  1529. + if (0) ipkg_satisfy_all_dependences(conf);
  1530. +
  1531. + ipkg_configure_packages(conf, NULL);
  1532. +
  1533. + write_status_files_if_changed(conf);
  1534. +
  1535. + return err;
  1536. +}
  1537. +
  1538. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1539. +{
  1540. + int i;
  1541. + pkg_t *pkg;
  1542. + int err;
  1543. +
  1544. + global_conf = conf;
  1545. + signal(SIGINT, sigint_handler);
  1546. +
  1547. + if (argc) {
  1548. + for (i=0; i < argc; i++) {
  1549. + char *arg = argv[i];
  1550. +
  1551. + err = ipkg_prepare_url_for_install(conf, arg, &arg);
  1552. + if (err != EINVAL && err != 0)
  1553. + return err;
  1554. + }
  1555. + pkg_info_preinstall_check(conf);
  1556. +
  1557. + for (i=0; i < argc; i++) {
  1558. + char *arg = argv[i];
  1559. + if (conf->restrict_to_default_dest) {
  1560. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1561. + argv[i],
  1562. + conf->default_dest);
  1563. + if (pkg == NULL) {
  1564. + ipkg_message(conf, IPKG_NOTICE,
  1565. + "Package %s not installed in %s\n",
  1566. + argv[i], conf->default_dest->name);
  1567. + continue;
  1568. + }
  1569. + } else {
  1570. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  1571. + argv[i]);
  1572. + }
  1573. + if (pkg)
  1574. + ipkg_upgrade_pkg(conf, pkg);
  1575. + else {
  1576. + ipkg_install_by_name(conf, arg);
  1577. + }
  1578. + }
  1579. + } else {
  1580. + pkg_vec_t *installed = pkg_vec_alloc();
  1581. +
  1582. + pkg_info_preinstall_check(conf);
  1583. +
  1584. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  1585. + for (i = 0; i < installed->len; i++) {
  1586. + pkg = installed->pkgs[i];
  1587. + ipkg_upgrade_pkg(conf, pkg);
  1588. + }
  1589. + pkg_vec_free(installed);
  1590. + }
  1591. +
  1592. + /* recheck to verify that all dependences are satisfied */
  1593. + if (0) ipkg_satisfy_all_dependences(conf);
  1594. +
  1595. + ipkg_configure_packages(conf, NULL);
  1596. +
  1597. + write_status_files_if_changed(conf);
  1598. +
  1599. + return 0;
  1600. +}
  1601. +
  1602. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1603. +{
  1604. + int i, err;
  1605. + char *arg;
  1606. + pkg_t *pkg;
  1607. +
  1608. + pkg_info_preinstall_check(conf);
  1609. + for (i = 0; i < argc; i++) {
  1610. + arg = argv[i];
  1611. +
  1612. + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
  1613. + if (pkg == NULL) {
  1614. + ipkg_message(conf, IPKG_ERROR,
  1615. + "Cannot find package %s.\n"
  1616. + "Check the spelling or perhaps run 'ipkg update'\n",
  1617. + arg);
  1618. + continue;
  1619. + }
  1620. +
  1621. + err = ipkg_download_pkg(conf, pkg, ".");
  1622. +
  1623. + if (err) {
  1624. + ipkg_message(conf, IPKG_ERROR,
  1625. + "Failed to download %s\n", pkg->name);
  1626. + } else {
  1627. + ipkg_message(conf, IPKG_NOTICE,
  1628. + "Downloaded %s as %s\n",
  1629. + pkg->name, pkg->local_filename);
  1630. + }
  1631. + }
  1632. +
  1633. + return 0;
  1634. +}
  1635. +
  1636. +
  1637. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1638. +{
  1639. + int i ;
  1640. + pkg_vec_t *available;
  1641. + pkg_t *pkg;
  1642. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1643. + char *newline;
  1644. + char *pkg_name = NULL;
  1645. + char *version_str;
  1646. +
  1647. + if (argc > 0) {
  1648. + pkg_name = argv[0];
  1649. + }
  1650. + available = pkg_vec_alloc();
  1651. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1652. + for (i=0; i < available->len; i++) {
  1653. + pkg = available->pkgs[i];
  1654. + /* if we have package name or pattern and pkg does not match, then skip it */
  1655. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1656. + continue;
  1657. + if (pkg->description) {
  1658. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1659. + } else {
  1660. + desc_short[0] = '\0';
  1661. + }
  1662. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1663. + newline = strchr(desc_short, '\n');
  1664. + if (newline) {
  1665. + *newline = '\0';
  1666. + }
  1667. + if (ipkg_cb_list) {
  1668. + version_str = pkg_version_str_alloc(pkg);
  1669. + ipkg_cb_list(pkg->name,desc_short,
  1670. + version_str,
  1671. + pkg->state_status,
  1672. + p_userdata);
  1673. + free(version_str);
  1674. + }
  1675. + }
  1676. + pkg_vec_free(available);
  1677. +
  1678. + return 0;
  1679. +}
  1680. +
  1681. +
  1682. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1683. +{
  1684. + int i ;
  1685. + pkg_vec_t *available;
  1686. + pkg_t *pkg;
  1687. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1688. + char *newline;
  1689. + char *pkg_name = NULL;
  1690. + char *version_str;
  1691. +
  1692. + if (argc > 0) {
  1693. + pkg_name = argv[0];
  1694. + }
  1695. + available = pkg_vec_alloc();
  1696. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1697. + for (i=0; i < available->len; i++) {
  1698. + pkg = available->pkgs[i];
  1699. + /* if we have package name or pattern and pkg does not match, then skip it */
  1700. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1701. + continue;
  1702. + if (pkg->description) {
  1703. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1704. + } else {
  1705. + desc_short[0] = '\0';
  1706. + }
  1707. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1708. + newline = strchr(desc_short, '\n');
  1709. + if (newline) {
  1710. + *newline = '\0';
  1711. + }
  1712. + if (ipkg_cb_list) {
  1713. + version_str = pkg_version_str_alloc(pkg);
  1714. + ipkg_cb_list(pkg->name,desc_short,
  1715. + version_str,
  1716. + pkg->state_status,
  1717. + p_userdata);
  1718. + free(version_str);
  1719. + }
  1720. + }
  1721. +
  1722. + return 0;
  1723. +}
  1724. +
  1725. +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
  1726. +{
  1727. + int i;
  1728. + pkg_vec_t *available;
  1729. + pkg_t *pkg;
  1730. + char *pkg_name = NULL;
  1731. + char **pkg_fields = NULL;
  1732. + int n_fields = 0;
  1733. + char *buff ; // = (char *)malloc(1);
  1734. +
  1735. + if (argc > 0) {
  1736. + pkg_name = argv[0];
  1737. + }
  1738. + if (argc > 1) {
  1739. + pkg_fields = &argv[1];
  1740. + n_fields = argc - 1;
  1741. + }
  1742. +
  1743. + available = pkg_vec_alloc();
  1744. + if (installed_only)
  1745. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1746. + else
  1747. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1748. + for (i=0; i < available->len; i++) {
  1749. + pkg = available->pkgs[i];
  1750. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1751. + continue;
  1752. + }
  1753. + buff = pkg_formatted_info(pkg);
  1754. + if ( buff ) {
  1755. + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
  1756. + pkg->state_status,
  1757. + buff,
  1758. + p_userdata);
  1759. + free(buff);
  1760. + }
  1761. + if (conf->verbosity > 1) {
  1762. + conffile_list_elt_t *iter;
  1763. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  1764. + conffile_t *cf = iter->data;
  1765. + int modified = conffile_has_been_modified(conf, cf);
  1766. + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
  1767. + cf->name, cf->value, modified);
  1768. + }
  1769. + }
  1770. + }
  1771. + pkg_vec_free(available);
  1772. +
  1773. + return 0;
  1774. +}
  1775. +
  1776. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1777. +{
  1778. + return ipkg_info_status_cmd(conf, argc, argv, 0);
  1779. +}
  1780. +
  1781. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1782. +{
  1783. + return ipkg_info_status_cmd(conf, argc, argv, 1);
  1784. +}
  1785. +
  1786. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1787. +{
  1788. +
  1789. + int err;
  1790. + if (argc > 0) {
  1791. + char *pkg_name = NULL;
  1792. +
  1793. + pkg_name = argv[0];
  1794. +
  1795. + err = ipkg_configure_packages (conf, pkg_name);
  1796. +
  1797. + } else {
  1798. + err = ipkg_configure_packages (conf, NULL);
  1799. + }
  1800. +
  1801. + write_status_files_if_changed(conf);
  1802. +
  1803. + return err;
  1804. +}
  1805. +
  1806. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf)
  1807. +{
  1808. + int i, err;
  1809. + char *globpattern;
  1810. + glob_t globbuf;
  1811. +
  1812. + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
  1813. + err = glob(globpattern, 0, NULL, &globbuf);
  1814. + free(globpattern);
  1815. + if (err) {
  1816. + return 0;
  1817. + }
  1818. +
  1819. + ipkg_message(conf, IPKG_NOTICE,
  1820. + "The following packages in %s will now be installed.\n",
  1821. + conf->pending_dir);
  1822. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1823. + ipkg_message(conf, IPKG_NOTICE,
  1824. + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
  1825. + }
  1826. + ipkg_message(conf, IPKG_NOTICE, "\n");
  1827. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1828. + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
  1829. + if (err == 0) {
  1830. + err = unlink(globbuf.gl_pathv[i]);
  1831. + if (err) {
  1832. + ipkg_message(conf, IPKG_ERROR,
  1833. + "%s: ERROR: failed to unlink %s: %s\n",
  1834. + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
  1835. + return err;
  1836. + }
  1837. + }
  1838. + }
  1839. + globfree(&globbuf);
  1840. +
  1841. + return err;
  1842. +}
  1843. +
  1844. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1845. +{
  1846. + int i,a,done;
  1847. + pkg_t *pkg;
  1848. + pkg_t *pkg_to_remove;
  1849. + pkg_vec_t *available;
  1850. + char *pkg_name = NULL;
  1851. + global_conf = conf;
  1852. + signal(SIGINT, sigint_handler);
  1853. +
  1854. +// ENH: Add the "no pkg removed" just in case.
  1855. +
  1856. + done = 0;
  1857. +
  1858. + available = pkg_vec_alloc();
  1859. + pkg_info_preinstall_check(conf);
  1860. + if ( argc > 0 ) {
  1861. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1862. + for (i=0; i < argc; i++) {
  1863. + pkg_name = malloc(strlen(argv[i])+2);
  1864. + strcpy(pkg_name,argv[i]);
  1865. + for (a=0; a < available->len; a++) {
  1866. + pkg = available->pkgs[a];
  1867. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1868. + continue;
  1869. + }
  1870. + if (conf->restrict_to_default_dest) {
  1871. + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1872. + pkg->name,
  1873. + conf->default_dest);
  1874. + } else {
  1875. + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
  1876. + }
  1877. +
  1878. + if (pkg == NULL) {
  1879. + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
  1880. + continue;
  1881. + }
  1882. + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
  1883. + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
  1884. + continue;
  1885. + }
  1886. + ipkg_remove_pkg(conf, pkg_to_remove,0);
  1887. + done = 1;
  1888. + }
  1889. + free (pkg_name);
  1890. + }
  1891. + pkg_vec_free(available);
  1892. + } else {
  1893. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  1894. + int flagged_pkg_count = 0;
  1895. + int removed;
  1896. +
  1897. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
  1898. +
  1899. + for (i = 0; i < installed_pkgs->len; i++) {
  1900. + pkg = installed_pkgs->pkgs[i];
  1901. + if (pkg->state_flag & SF_USER) {
  1902. + flagged_pkg_count++;
  1903. + } else {
  1904. + if (!pkg_has_installed_dependents(pkg, NULL))
  1905. + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
  1906. + }
  1907. + }
  1908. + if (!flagged_pkg_count) {
  1909. + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
  1910. + "so refusing to uninstall unflagged non-leaf packages\n");
  1911. + return 0;
  1912. + }
  1913. +
  1914. + /* find packages not flagged SF_USER (i.e., installed to
  1915. + * satisfy a dependence) and not having any dependents, and
  1916. + * remove them */
  1917. + do {
  1918. + removed = 0;
  1919. + for (i = 0; i < installed_pkgs->len; i++) {
  1920. + pkg = installed_pkgs->pkgs[i];
  1921. + if (!(pkg->state_flag & SF_USER)
  1922. + && !pkg_has_installed_dependents(pkg, NULL)) {
  1923. + removed++;
  1924. + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
  1925. + ipkg_remove_pkg(conf, pkg,0);
  1926. + done = 1;
  1927. + }
  1928. + }
  1929. + } while (removed);
  1930. + pkg_vec_free(installed_pkgs);
  1931. + }
  1932. +
  1933. + if ( done == 0 )
  1934. + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
  1935. +
  1936. + write_status_files_if_changed(conf);
  1937. + return 0;
  1938. +}
  1939. +
  1940. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1941. +{
  1942. + int i;
  1943. + pkg_t *pkg;
  1944. +
  1945. + global_conf = conf;
  1946. + signal(SIGINT, sigint_handler);
  1947. +
  1948. + pkg_info_preinstall_check(conf);
  1949. +
  1950. + for (i=0; i < argc; i++) {
  1951. + if (conf->restrict_to_default_dest) {
  1952. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1953. + argv[i],
  1954. + conf->default_dest);
  1955. + } else {
  1956. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1957. + }
  1958. +
  1959. + if (pkg == NULL) {
  1960. + ipkg_message(conf, IPKG_ERROR,
  1961. + "Package %s is not installed.\n", argv[i]);
  1962. + continue;
  1963. + }
  1964. + ipkg_purge_pkg(conf, pkg);
  1965. + }
  1966. +
  1967. + write_status_files_if_changed(conf);
  1968. + return 0;
  1969. +}
  1970. +
  1971. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1972. +{
  1973. + int i;
  1974. + pkg_t *pkg;
  1975. + char *flags = argv[0];
  1976. +
  1977. + global_conf = conf;
  1978. + signal(SIGINT, sigint_handler);
  1979. +
  1980. + for (i=1; i < argc; i++) {
  1981. + if (conf->restrict_to_default_dest) {
  1982. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1983. + argv[i],
  1984. + conf->default_dest);
  1985. + } else {
  1986. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1987. + }
  1988. +
  1989. + if (pkg == NULL) {
  1990. + ipkg_message(conf, IPKG_ERROR,
  1991. + "Package %s is not installed.\n", argv[i]);
  1992. + continue;
  1993. + }
  1994. + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
  1995. + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
  1996. + pkg->state_flag = pkg_state_flag_from_str(flags);
  1997. + }
  1998. +/* pb_ asked this feature 03292004 */
  1999. +/* Actually I will use only this two, but this is an open for various status */
  2000. + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
  2001. + pkg->state_status = pkg_state_status_from_str(flags);
  2002. + }
  2003. + ipkg_state_changed++;
  2004. + ipkg_message(conf, IPKG_NOTICE,
  2005. + "Setting flags for package %s to %s\n",
  2006. + pkg->name, flags);
  2007. + }
  2008. +
  2009. + write_status_files_if_changed(conf);
  2010. + return 0;
  2011. +}
  2012. +
  2013. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2014. +{
  2015. + pkg_t *pkg;
  2016. + str_list_t *installed_files;
  2017. + str_list_elt_t *iter;
  2018. + char *pkg_version;
  2019. + size_t buff_len = 8192;
  2020. + size_t used_len;
  2021. + char *buff ;
  2022. +
  2023. + buff = (char *)malloc(buff_len);
  2024. + if ( buff == NULL ) {
  2025. + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
  2026. + return ENOMEM;
  2027. + }
  2028. +
  2029. + if (argc < 1) {
  2030. + return EINVAL;
  2031. + }
  2032. +
  2033. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  2034. + argv[0]);
  2035. + if (pkg == NULL) {
  2036. + ipkg_message(conf, IPKG_ERROR,
  2037. + "Package %s not installed.\n", argv[0]);
  2038. + return 0;
  2039. + }
  2040. +
  2041. + installed_files = pkg_get_installed_files(pkg);
  2042. + pkg_version = pkg_version_str_alloc(pkg);
  2043. +
  2044. + if (buff) {
  2045. + try_again:
  2046. + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
  2047. + pkg->name, pkg_version, pkg->dest->name) + 1;
  2048. + if (used_len > buff_len) {
  2049. + buff_len *= 2;
  2050. + buff = realloc (buff, buff_len);
  2051. + goto try_again;
  2052. + }
  2053. + for (iter = installed_files->head; iter; iter = iter->next) {
  2054. + used_len += strlen (iter->data) + 1;
  2055. + while (buff_len <= used_len) {
  2056. + buff_len *= 2;
  2057. + buff = realloc (buff, buff_len);
  2058. + }
  2059. + strncat(buff, iter->data, buff_len);
  2060. + strncat(buff, "\n", buff_len);
  2061. + }
  2062. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2063. + buff,
  2064. + pkg_version_str_alloc(pkg),
  2065. + pkg->state_status,
  2066. + p_userdata);
  2067. + free(buff);
  2068. + }
  2069. +
  2070. + free(pkg_version);
  2071. + pkg_free_installed_files(pkg);
  2072. +
  2073. + return 0;
  2074. +}
  2075. +
  2076. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2077. +{
  2078. +
  2079. + if (argc > 0) {
  2080. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2081. + const char *rel_str = "depends on";
  2082. + int i;
  2083. +
  2084. + pkg_info_preinstall_check(conf);
  2085. +
  2086. + if (conf->query_all)
  2087. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2088. + else
  2089. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2090. + for (i = 0; i < argc; i++) {
  2091. + const char *target = argv[i];
  2092. + int j;
  2093. +
  2094. + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
  2095. +
  2096. + for (j = 0; j < available_pkgs->len; j++) {
  2097. + pkg_t *pkg = available_pkgs->pkgs[j];
  2098. + if (fnmatch(target, pkg->name, 0) == 0) {
  2099. + int k;
  2100. + int count = pkg->depends_count + pkg->pre_depends_count;
  2101. + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
  2102. + target, pkg->architecture, rel_str);
  2103. + for (k = 0; k < count; k++) {
  2104. + compound_depend_t *cdepend = &pkg->depends[k];
  2105. + int l;
  2106. + for (l = 0; l < cdepend->possibility_count; l++) {
  2107. + depend_t *possibility = cdepend->possibilities[l];
  2108. + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
  2109. + if (conf->verbosity > 0) {
  2110. + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
  2111. + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
  2112. + if (possibility->version) {
  2113. + const char *typestr = NULL;
  2114. + switch (possibility->constraint) {
  2115. + case NONE: typestr = "none"; break;
  2116. + case EARLIER: typestr = "<"; break;
  2117. + case EARLIER_EQUAL: typestr = "<="; break;
  2118. + case EQUAL: typestr = "="; break;
  2119. + case LATER_EQUAL: typestr = ">="; break;
  2120. + case LATER: typestr = ">"; break;
  2121. + }
  2122. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2123. + }
  2124. + // free(ver);
  2125. + }
  2126. + ipkg_message(conf, IPKG_ERROR, "\n");
  2127. + }
  2128. + }
  2129. + }
  2130. + }
  2131. + }
  2132. + pkg_vec_free(available_pkgs);
  2133. + }
  2134. + return 0;
  2135. +}
  2136. +
  2137. +enum what_field_type {
  2138. + WHATDEPENDS,
  2139. + WHATCONFLICTS,
  2140. + WHATPROVIDES,
  2141. + WHATREPLACES,
  2142. + WHATRECOMMENDS,
  2143. + WHATSUGGESTS
  2144. +};
  2145. +
  2146. +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
  2147. +{
  2148. +
  2149. + if (argc > 0) {
  2150. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2151. + const char *rel_str = NULL;
  2152. + int i;
  2153. + int changed;
  2154. +
  2155. + switch (what_field_type) {
  2156. + case WHATDEPENDS: rel_str = "depends on"; break;
  2157. + case WHATCONFLICTS: rel_str = "conflicts with"; break;
  2158. + case WHATSUGGESTS: rel_str = "suggests"; break;
  2159. + case WHATRECOMMENDS: rel_str = "recommends"; break;
  2160. + case WHATPROVIDES: rel_str = "provides"; break;
  2161. + case WHATREPLACES: rel_str = "replaces"; break;
  2162. + }
  2163. +
  2164. + if (conf->query_all)
  2165. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2166. + else
  2167. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2168. +
  2169. + /* mark the root set */
  2170. + pkg_vec_clear_marks(available_pkgs);
  2171. + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
  2172. + for (i = 0; i < argc; i++) {
  2173. + const char *dependee_pattern = argv[i];
  2174. + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
  2175. + }
  2176. + for (i = 0; i < available_pkgs->len; i++) {
  2177. + pkg_t *pkg = available_pkgs->pkgs[i];
  2178. + if (pkg->state_flag & SF_MARKED) {
  2179. + /* mark the parent (abstract) package */
  2180. + pkg_mark_provides(pkg);
  2181. + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
  2182. + }
  2183. + }
  2184. +
  2185. + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
  2186. + do {
  2187. + int j;
  2188. + changed = 0;
  2189. +
  2190. + for (j = 0; j < available_pkgs->len; j++) {
  2191. + pkg_t *pkg = available_pkgs->pkgs[j];
  2192. + int k;
  2193. + int count = ((what_field_type == WHATCONFLICTS)
  2194. + ? pkg->conflicts_count
  2195. + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
  2196. + /* skip this package if it is already marked */
  2197. + if (pkg->parent->state_flag & SF_MARKED) {
  2198. + continue;
  2199. + }
  2200. + for (k = 0; k < count; k++) {
  2201. + compound_depend_t *cdepend =
  2202. + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
  2203. + int l;
  2204. + for (l = 0; l < cdepend->possibility_count; l++) {
  2205. + depend_t *possibility = cdepend->possibilities[l];
  2206. + if (possibility->pkg->state_flag & SF_MARKED) {
  2207. + /* mark the depending package so we won't visit it again */
  2208. + pkg->state_flag |= SF_MARKED;
  2209. + pkg_mark_provides(pkg);
  2210. + changed++;
  2211. +
  2212. + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
  2213. + if (conf->verbosity > 0) {
  2214. + char *ver = pkg_version_str_alloc(pkg);
  2215. + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
  2216. + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
  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. + if (!pkg_dependence_satisfiable(possibility))
  2231. + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
  2232. + }
  2233. + ipkg_message(conf, IPKG_NOTICE, "\n");
  2234. + goto next_package;
  2235. + }
  2236. + }
  2237. + }
  2238. + next_package:
  2239. + ;
  2240. + }
  2241. + } while (changed && recursive);
  2242. + pkg_vec_free(available_pkgs);
  2243. + }
  2244. +
  2245. + return 0;
  2246. +}
  2247. +
  2248. +int pkg_mark_provides(pkg_t *pkg)
  2249. +{
  2250. + int provides_count = pkg->provides_count;
  2251. + abstract_pkg_t **provides = pkg->provides;
  2252. + int i;
  2253. + pkg->parent->state_flag |= SF_MARKED;
  2254. + for (i = 0; i < provides_count; i++) {
  2255. + provides[i]->state_flag |= SF_MARKED;
  2256. + }
  2257. + return 0;
  2258. +}
  2259. +
  2260. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2261. +{
  2262. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
  2263. +}
  2264. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2265. +{
  2266. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
  2267. +}
  2268. +
  2269. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2270. +{
  2271. + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
  2272. +}
  2273. +
  2274. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2275. +{
  2276. + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
  2277. +}
  2278. +
  2279. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2280. +{
  2281. + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
  2282. +}
  2283. +
  2284. +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
  2285. +{
  2286. +
  2287. + if (argc > 0) {
  2288. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2289. + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
  2290. + int i;
  2291. +
  2292. + pkg_info_preinstall_check(conf);
  2293. +
  2294. + if (conf->query_all)
  2295. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2296. + else
  2297. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2298. + for (i = 0; i < argc; i++) {
  2299. + const char *target = argv[i];
  2300. + int j;
  2301. +
  2302. + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
  2303. + rel_str, target);
  2304. + for (j = 0; j < available_pkgs->len; j++) {
  2305. + pkg_t *pkg = available_pkgs->pkgs[j];
  2306. + int k;
  2307. + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
  2308. + for (k = 0; k < count; k++) {
  2309. + abstract_pkg_t *apkg =
  2310. + ((what_field_type == WHATPROVIDES)
  2311. + ? pkg->provides[k]
  2312. + : pkg->replaces[k]);
  2313. + if (fnmatch(target, apkg->name, 0) == 0) {
  2314. + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
  2315. + if (strcmp(target, apkg->name) != 0)
  2316. + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
  2317. + ipkg_message(conf, IPKG_ERROR, "\n");
  2318. + }
  2319. + }
  2320. + }
  2321. + }
  2322. + pkg_vec_free(available_pkgs);
  2323. + }
  2324. + return 0;
  2325. +}
  2326. +
  2327. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2328. +{
  2329. + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
  2330. +}
  2331. +
  2332. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2333. +{
  2334. + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
  2335. +}
  2336. +
  2337. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2338. +{
  2339. + int i;
  2340. +
  2341. + pkg_vec_t *installed;
  2342. + pkg_t *pkg;
  2343. + str_list_t *installed_files;
  2344. + str_list_elt_t *iter;
  2345. + char *installed_file;
  2346. +
  2347. + if (argc < 1) {
  2348. + return EINVAL;
  2349. + }
  2350. +
  2351. + installed = pkg_vec_alloc();
  2352. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  2353. +
  2354. + for (i=0; i < installed->len; i++) {
  2355. + pkg = installed->pkgs[i];
  2356. +
  2357. + installed_files = pkg_get_installed_files(pkg);
  2358. +
  2359. + for (iter = installed_files->head; iter; iter = iter->next) {
  2360. + installed_file = iter->data;
  2361. + if (fnmatch(argv[0], installed_file, 0)==0) {
  2362. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2363. + installed_file,
  2364. + pkg_version_str_alloc(pkg),
  2365. + pkg->state_status, p_userdata);
  2366. + }
  2367. + }
  2368. +
  2369. + pkg_free_installed_files(pkg);
  2370. + }
  2371. +
  2372. + /* XXX: CLEANUP: It's not obvious from the name of
  2373. + pkg_hash_fetch_all_installed that we need to call
  2374. + pkg_vec_free to avoid a memory leak. */
  2375. + pkg_vec_free(installed);
  2376. +
  2377. + return 0;
  2378. +}
  2379. +
  2380. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2381. +{
  2382. + if (argc == 3) {
  2383. + /* this is a bit gross */
  2384. + struct pkg p1, p2;
  2385. + parseVersion(&p1, argv[0]);
  2386. + parseVersion(&p2, argv[2]);
  2387. + return pkg_version_satisfied(&p1, &p2, argv[1]);
  2388. + } else {
  2389. + ipkg_message(conf, IPKG_ERROR,
  2390. + "ipkg compare_versions <v1> <op> <v2>\n"
  2391. + "<op> is one of <= >= << >> =\n");
  2392. + return -1;
  2393. + }
  2394. +}
  2395. +
  2396. +#ifndef HOST_CPU_STR
  2397. +#define HOST_CPU_STR__(X) #X
  2398. +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
  2399. +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
  2400. +#endif
  2401. +
  2402. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf)
  2403. +{
  2404. + nv_pair_list_elt_t *l;
  2405. +
  2406. + l = conf->arch_list.head;
  2407. + while (l) {
  2408. + nv_pair_t *nv = l->data;
  2409. + printf("arch %s %s\n", nv->name, nv->value);
  2410. + l = l->next;
  2411. + }
  2412. + return 0;
  2413. +}
  2414. +
  2415. +
  2416. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_cmd.h busybox-1.15.2/archival/libipkg/ipkg_cmd.h
  2417. --- busybox-1.15.2.orig/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
  2418. +++ busybox-1.15.2/archival/libipkg/ipkg_cmd.h 2010-03-14 21:06:29.000000000 +0100
  2419. @@ -0,0 +1,41 @@
  2420. +/* ipkg_cmd.h - the itsy package management system
  2421. +
  2422. + Carl D. Worth
  2423. +
  2424. + Copyright (C) 2001 University of Southern California
  2425. +
  2426. + This program is free software; you can redistribute it and/or
  2427. + modify it under the terms of the GNU General Public License as
  2428. + published by the Free Software Foundation; either version 2, or (at
  2429. + your option) any later version.
  2430. +
  2431. + This program is distributed in the hope that it will be useful, but
  2432. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2433. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2434. + General Public License for more details.
  2435. +*/
  2436. +
  2437. +#ifndef IPKG_CMD_H
  2438. +#define IPKG_CMD_H
  2439. +
  2440. +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
  2441. +
  2442. +struct ipkg_cmd
  2443. +{
  2444. + const char *name;
  2445. + int requires_args;
  2446. + ipkg_cmd_fun_t fun;
  2447. +};
  2448. +typedef struct ipkg_cmd ipkg_cmd_t;
  2449. +
  2450. +ipkg_cmd_t *ipkg_cmd_find(const char *name);
  2451. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
  2452. + const char **argv, void *userdata);
  2453. +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
  2454. +/* install any packges with state_want == SW_INSTALL */
  2455. +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
  2456. +/* ensure that all dependences are satisfied */
  2457. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
  2458. +int pkg_mark_provides(pkg_t *pkg);
  2459. +
  2460. +#endif
  2461. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_conf.c busybox-1.15.2/archival/libipkg/ipkg_conf.c
  2462. --- busybox-1.15.2.orig/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
  2463. +++ busybox-1.15.2/archival/libipkg/ipkg_conf.c 2010-03-14 20:53:41.000000000 +0100
  2464. @@ -0,0 +1,711 @@
  2465. +/* ipkg_conf.c - the itsy package management system
  2466. +
  2467. + Carl D. Worth
  2468. +
  2469. + Copyright (C) 2001 University of Southern California
  2470. +
  2471. + This program is free software; you can redistribute it and/or
  2472. + modify it under the terms of the GNU General Public License as
  2473. + published by the Free Software Foundation; either version 2, or (at
  2474. + your option) any later version.
  2475. +
  2476. + This program is distributed in the hope that it will be useful, but
  2477. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2478. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2479. + General Public License for more details.
  2480. +*/
  2481. +
  2482. +#include <glob.h>
  2483. +
  2484. +#include "ipkg.h"
  2485. +#include "ipkg_conf.h"
  2486. +
  2487. +#include "xregex.h"
  2488. +#include "sprintf_alloc.h"
  2489. +#include "ipkg_conf.h"
  2490. +#include "ipkg_message.h"
  2491. +#include "file_util.h"
  2492. +#include "str_util.h"
  2493. +#include "xsystem.h"
  2494. +
  2495. +
  2496. +ipkg_conf_t *global_conf;
  2497. +
  2498. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2499. + pkg_src_list_t *pkg_src_list,
  2500. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2501. + char **tmp_lists_dir);
  2502. +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
  2503. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  2504. + const char *name, const char *value);
  2505. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2506. + const char *default_dest_name);
  2507. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
  2508. + pkg_src_list_t *nv_pair_list);
  2509. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
  2510. + nv_pair_list_t *nv_pair_list, char * lists_dir);
  2511. +
  2512. +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
  2513. +{
  2514. + ipkg_option_t tmp[] = {
  2515. + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
  2516. + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
  2517. + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
  2518. + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
  2519. + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
  2520. + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
  2521. + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
  2522. + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
  2523. + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
  2524. + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
  2525. + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
  2526. + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
  2527. + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
  2528. + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
  2529. + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
  2530. + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
  2531. + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
  2532. + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
  2533. + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
  2534. + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
  2535. + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
  2536. + { NULL }
  2537. + };
  2538. +
  2539. + *options = (ipkg_option_t *)malloc(sizeof(tmp));
  2540. + if ( options == NULL ){
  2541. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  2542. + return -1;
  2543. + }
  2544. +
  2545. + memcpy(*options, tmp, sizeof(tmp));
  2546. + return 0;
  2547. +};
  2548. +
  2549. +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
  2550. +{
  2551. + if (arg_str) {
  2552. + if (*conf_str) {
  2553. + free(*conf_str);
  2554. + }
  2555. + *conf_str = strdup(arg_str);
  2556. + }
  2557. +}
  2558. +
  2559. +static void ipkg_conf_free_string(char **conf_str)
  2560. +{
  2561. + if (*conf_str) {
  2562. + free(*conf_str);
  2563. + *conf_str = NULL;
  2564. + }
  2565. +}
  2566. +
  2567. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
  2568. +{
  2569. + int err;
  2570. + char *tmp_dir_base;
  2571. + nv_pair_list_t tmp_dest_nv_pair_list;
  2572. + char * lists_dir =NULL;
  2573. + glob_t globbuf;
  2574. + const char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
  2575. + char *pending_dir =NULL;
  2576. +
  2577. + memset(conf, 0, sizeof(ipkg_conf_t));
  2578. +
  2579. + pkg_src_list_init(&conf->pkg_src_list);
  2580. +
  2581. + nv_pair_list_init(&tmp_dest_nv_pair_list);
  2582. + pkg_dest_list_init(&conf->pkg_dest_list);
  2583. +
  2584. + nv_pair_list_init(&conf->arch_list);
  2585. +
  2586. + conf->restrict_to_default_dest = 0;
  2587. + conf->default_dest = NULL;
  2588. +
  2589. +
  2590. + if (args->tmp_dir)
  2591. + tmp_dir_base = args->tmp_dir;
  2592. + else
  2593. + tmp_dir_base = getenv("TMPDIR");
  2594. + sprintf_alloc(&conf->tmp_dir, "%s/%s",
  2595. + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
  2596. + IPKG_CONF_TMP_DIR_SUFFIX);
  2597. + conf->tmp_dir = mkdtemp(conf->tmp_dir);
  2598. + if (conf->tmp_dir == NULL) {
  2599. + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
  2600. + __FUNCTION__, conf->tmp_dir, strerror(errno));
  2601. + return errno;
  2602. + }
  2603. +
  2604. + conf->force_depends = 0;
  2605. + conf->force_defaults = 0;
  2606. + conf->force_overwrite = 0;
  2607. + conf->force_downgrade = 0;
  2608. + conf->force_reinstall = 0;
  2609. + conf->force_space = 0;
  2610. + conf->force_removal_of_essential_packages = 0;
  2611. + conf->force_removal_of_dependent_packages = 0;
  2612. + conf->nodeps = 0;
  2613. + conf->verbose_wget = 0;
  2614. + conf->offline_root = NULL;
  2615. + conf->offline_root_pre_script_cmd = NULL;
  2616. + conf->offline_root_post_script_cmd = NULL;
  2617. + conf->multiple_providers = 0;
  2618. + conf->verbosity = 1;
  2619. + conf->noaction = 0;
  2620. +
  2621. + conf->http_proxy = NULL;
  2622. + conf->ftp_proxy = NULL;
  2623. + conf->no_proxy = NULL;
  2624. + conf->proxy_user = NULL;
  2625. + conf->proxy_passwd = NULL;
  2626. +
  2627. + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2628. + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2629. + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2630. + lists_dir=(char *)malloc(1);
  2631. + lists_dir[0]='\0';
  2632. + if (args->conf_file) {
  2633. + struct stat stat_buf;
  2634. + err = stat(args->conf_file, &stat_buf);
  2635. + if (err == 0)
  2636. + if (ipkg_conf_parse_file(conf, args->conf_file,
  2637. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2638. + /* Memory leakage from ipkg_conf_parse-file */
  2639. + return -1;
  2640. + }
  2641. +
  2642. + }
  2643. +
  2644. + /* if (!lists_dir ){*/
  2645. + if (strlen(lists_dir)<=1 ){
  2646. + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
  2647. + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
  2648. + }
  2649. +
  2650. + if (args->offline_root) {
  2651. + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
  2652. + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
  2653. + free(lists_dir);
  2654. + lists_dir = tmp;
  2655. + }
  2656. +
  2657. + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
  2658. + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
  2659. +
  2660. + conf->lists_dir = strdup(lists_dir);
  2661. + conf->pending_dir = strdup(pending_dir);
  2662. +
  2663. + if (args->offline_root)
  2664. + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
  2665. + memset(&globbuf, 0, sizeof(globbuf));
  2666. + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
  2667. + if (!err) {
  2668. + int i;
  2669. + for (i = 0; i < globbuf.gl_pathc; i++) {
  2670. + if (globbuf.gl_pathv[i])
  2671. + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
  2672. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2673. + /* Memory leakage from ipkg_conf_parse-file */
  2674. + return -1;
  2675. + }
  2676. + }
  2677. + }
  2678. + globfree(&globbuf);
  2679. +
  2680. + /* if no architectures were defined, then default all, noarch, and host architecture */
  2681. + if (nv_pair_list_empty(&conf->arch_list)) {
  2682. + nv_pair_list_append(&conf->arch_list, "all", "1");
  2683. + nv_pair_list_append(&conf->arch_list, "noarch", "1");
  2684. + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
  2685. + }
  2686. +
  2687. + /* Even if there is no conf file, we'll need at least one dest. */
  2688. + if (tmp_dest_nv_pair_list.head == NULL) {
  2689. + nv_pair_list_append(&tmp_dest_nv_pair_list,
  2690. + IPKG_CONF_DEFAULT_DEST_NAME,
  2691. + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
  2692. + }
  2693. +
  2694. + /* After parsing the file, set options from command-line, (so that
  2695. + command-line arguments take precedence) */
  2696. + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
  2697. + really needs to be cleaned up. There is so much duplication
  2698. + right now it is ridiculous. Maybe ipkg_conf_t should just save
  2699. + a pointer to args_t (which could then not be freed), rather
  2700. + than duplicating every field here? */
  2701. + if (args->force_depends) {
  2702. + conf->force_depends = 1;
  2703. + }
  2704. + if (args->force_defaults) {
  2705. + conf->force_defaults = 1;
  2706. + }
  2707. + if (args->force_overwrite) {
  2708. + conf->force_overwrite = 1;
  2709. + }
  2710. + if (args->force_downgrade) {
  2711. + conf->force_downgrade = 1;
  2712. + }
  2713. + if (args->force_reinstall) {
  2714. + conf->force_reinstall = 1;
  2715. + }
  2716. + if (args->force_removal_of_dependent_packages) {
  2717. + conf->force_removal_of_dependent_packages = 1;
  2718. + }
  2719. + if (args->force_removal_of_essential_packages) {
  2720. + conf->force_removal_of_essential_packages = 1;
  2721. + }
  2722. + if (args->nodeps) {
  2723. + conf->nodeps = 1;
  2724. + }
  2725. + if (args->noaction) {
  2726. + conf->noaction = 1;
  2727. + }
  2728. + if (args->query_all) {
  2729. + conf->query_all = 1;
  2730. + }
  2731. + if (args->verbose_wget) {
  2732. + conf->verbose_wget = 1;
  2733. + }
  2734. + if (args->multiple_providers) {
  2735. + conf->multiple_providers = 1;
  2736. + }
  2737. + if (args->verbosity != conf->verbosity) {
  2738. + conf->verbosity = args->verbosity;
  2739. + }
  2740. +
  2741. + ipkg_conf_override_string(&conf->offline_root,
  2742. + args->offline_root);
  2743. + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
  2744. + args->offline_root_pre_script_cmd);
  2745. + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
  2746. + args->offline_root_post_script_cmd);
  2747. +
  2748. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  2749. + read anything from there.
  2750. +*/
  2751. + if ( !(args->nocheckfordirorfile)){
  2752. + /* need to run load the source list before dest list -Jamey */
  2753. + if ( !(args->noreadfeedsfile))
  2754. + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
  2755. +
  2756. + /* Now that we have resolved conf->offline_root, we can commit to
  2757. + the directory names for the dests and load in all the package
  2758. + lists. */
  2759. + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
  2760. +
  2761. + if (args->dest) {
  2762. + err = ipkg_conf_set_default_dest(conf, args->dest);
  2763. + if (err) {
  2764. + return err;
  2765. + }
  2766. + }
  2767. + }
  2768. + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
  2769. + free(lists_dir);
  2770. + free(pending_dir);
  2771. +
  2772. + return 0;
  2773. +}
  2774. +
  2775. +void ipkg_conf_deinit(ipkg_conf_t *conf)
  2776. +{
  2777. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  2778. +#error
  2779. + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
  2780. + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  2781. + __FUNCTION__, conf->tmp_dir);
  2782. +#else
  2783. + int err;
  2784. +
  2785. + err = rmdir(conf->tmp_dir);
  2786. + if (err) {
  2787. + if (errno == ENOTEMPTY) {
  2788. + char *cmd;
  2789. + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
  2790. + err = xsystem(cmd);
  2791. + free(cmd);
  2792. + }
  2793. + if (err)
  2794. + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
  2795. + }
  2796. +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
  2797. +
  2798. + free(conf->tmp_dir); /*XXX*/
  2799. +
  2800. + pkg_src_list_deinit(&conf->pkg_src_list);
  2801. + pkg_dest_list_deinit(&conf->pkg_dest_list);
  2802. + nv_pair_list_deinit(&conf->arch_list);
  2803. + if (&conf->pkg_hash)
  2804. + pkg_hash_deinit(&conf->pkg_hash);
  2805. + if (&conf->file_hash)
  2806. + hash_table_deinit(&conf->file_hash);
  2807. + if (&conf->obs_file_hash)
  2808. + hash_table_deinit(&conf->obs_file_hash);
  2809. +
  2810. + ipkg_conf_free_string(&conf->offline_root);
  2811. + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
  2812. + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
  2813. +
  2814. + if (conf->verbosity > 1) {
  2815. + int i;
  2816. + hash_table_t *hashes[] = {
  2817. + &conf->pkg_hash,
  2818. + &conf->file_hash,
  2819. + &conf->obs_file_hash };
  2820. + for (i = 0; i < 3; i++) {
  2821. + hash_table_t *hash = hashes[i];
  2822. + int c = 0;
  2823. + int n_conflicts = 0;
  2824. + int j;
  2825. + for (j = 0; j < hash->n_entries; j++) {
  2826. + int len = 0;
  2827. + hash_entry_t *e = &hash->entries[j];
  2828. + if (e->next)
  2829. + n_conflicts++;
  2830. + while (e && e->key) {
  2831. + len++;
  2832. + e = e->next;
  2833. + }
  2834. + if (len > c)
  2835. + c = len;
  2836. + }
  2837. + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
  2838. + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
  2839. + hash_table_deinit(hash);
  2840. + }
  2841. + }
  2842. +}
  2843. +
  2844. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2845. + const char *default_dest_name)
  2846. +{
  2847. + pkg_dest_list_elt_t *iter;
  2848. + pkg_dest_t *dest;
  2849. +
  2850. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  2851. + dest = iter->data;
  2852. + if (strcmp(dest->name, default_dest_name) == 0) {
  2853. + conf->default_dest = dest;
  2854. + conf->restrict_to_default_dest = 1;
  2855. + return 0;
  2856. + }
  2857. + }
  2858. +
  2859. + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
  2860. +
  2861. + return 1;
  2862. +}
  2863. +
  2864. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
  2865. +{
  2866. + pkg_src_list_elt_t *iter;
  2867. + pkg_src_t *src;
  2868. + char *list_file;
  2869. +
  2870. + for (iter = pkg_src_list->head; iter; iter = iter->next) {
  2871. + src = iter->data;
  2872. + if (src == NULL) {
  2873. + continue;
  2874. + }
  2875. +
  2876. + sprintf_alloc(&list_file, "%s/%s",
  2877. + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
  2878. + src->name);
  2879. +
  2880. + if (file_exists(list_file)) {
  2881. + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
  2882. + }
  2883. + free(list_file);
  2884. + }
  2885. +
  2886. + return 0;
  2887. +}
  2888. +
  2889. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
  2890. +{
  2891. + nv_pair_list_elt_t *iter;
  2892. + nv_pair_t *nv_pair;
  2893. + pkg_dest_t *dest;
  2894. + char *root_dir;
  2895. +
  2896. + for (iter = nv_pair_list->head; iter; iter = iter->next) {
  2897. + nv_pair = iter->data;
  2898. +
  2899. + if (conf->offline_root) {
  2900. + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
  2901. + } else {
  2902. + root_dir = strdup(nv_pair->value);
  2903. + }
  2904. + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
  2905. + free(root_dir);
  2906. + if (dest == NULL) {
  2907. + continue;
  2908. + }
  2909. + if (conf->default_dest == NULL) {
  2910. + conf->default_dest = dest;
  2911. + }
  2912. + if (file_exists(dest->status_file_name)) {
  2913. + pkg_hash_add_from_file(conf, dest->status_file_name,
  2914. + NULL, dest, 1);
  2915. + }
  2916. + }
  2917. +
  2918. + return 0;
  2919. +}
  2920. +
  2921. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2922. + pkg_src_list_t *pkg_src_list,
  2923. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2924. + char **lists_dir)
  2925. +{
  2926. + ipkg_option_t * options;
  2927. + FILE *file = fopen(filename, "r");
  2928. + regex_t valid_line_re, comment_re;
  2929. +#define regmatch_size 12
  2930. + regmatch_t regmatch[regmatch_size];
  2931. +
  2932. + if (ipkg_init_options_array(conf, &options)<0)
  2933. + return ENOMEM;
  2934. +
  2935. + if (file == NULL) {
  2936. + fprintf(stderr, "%s: failed to open %s: %s\n",
  2937. + __FUNCTION__, filename, strerror(errno));
  2938. + free(options);
  2939. + return errno;
  2940. + }
  2941. + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
  2942. +
  2943. + xregcomp(&comment_re,
  2944. + "^[[:space:]]*(#.*|[[:space:]]*)$",
  2945. + REG_EXTENDED);
  2946. + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
  2947. +
  2948. + while(1) {
  2949. + int line_num = 0;
  2950. + char *line;
  2951. + char *type, *name, *value, *extra;
  2952. +
  2953. + line = file_read_line_alloc(file);
  2954. + line_num++;
  2955. + if (line == NULL) {
  2956. + break;
  2957. + }
  2958. +
  2959. + str_chomp(line);
  2960. +
  2961. + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
  2962. + goto NEXT_LINE;
  2963. + }
  2964. +
  2965. + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
  2966. + str_chomp(line);
  2967. + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
  2968. + filename, line_num, line);
  2969. + goto NEXT_LINE;
  2970. + }
  2971. +
  2972. + /* This has to be so ugly to deal with optional quotation marks */
  2973. + if (regmatch[2].rm_so > 0) {
  2974. + type = strndup(line + regmatch[2].rm_so,
  2975. + regmatch[2].rm_eo - regmatch[2].rm_so);
  2976. + } else {
  2977. + type = strndup(line + regmatch[3].rm_so,
  2978. + regmatch[3].rm_eo - regmatch[3].rm_so);
  2979. + }
  2980. + if (regmatch[5].rm_so > 0) {
  2981. + name = strndup(line + regmatch[5].rm_so,
  2982. + regmatch[5].rm_eo - regmatch[5].rm_so);
  2983. + } else {
  2984. + name = strndup(line + regmatch[6].rm_so,
  2985. + regmatch[6].rm_eo - regmatch[6].rm_so);
  2986. + }
  2987. + if (regmatch[8].rm_so > 0) {
  2988. + value = strndup(line + regmatch[8].rm_so,
  2989. + regmatch[8].rm_eo - regmatch[8].rm_so);
  2990. + } else {
  2991. + value = strndup(line + regmatch[9].rm_so,
  2992. + regmatch[9].rm_eo - regmatch[9].rm_so);
  2993. + }
  2994. + extra = NULL;
  2995. + if (regmatch[11].rm_so > 0) {
  2996. + extra = strndup (line + regmatch[11].rm_so,
  2997. + regmatch[11].rm_eo - regmatch[11].rm_so);
  2998. + }
  2999. +
  3000. + /* We use the tmp_dest_nv_pair_list below instead of
  3001. + conf->pkg_dest_list because we might encounter an
  3002. + offline_root option later and that would invalidate the
  3003. + directories we would have computed in
  3004. + pkg_dest_list_init. (We do a similar thing with
  3005. + tmp_src_nv_pair_list for sake of symmetry.) */
  3006. + if (strcmp(type, "option") == 0) {
  3007. + ipkg_conf_set_option(options, name, value);
  3008. + } else if (strcmp(type, "src") == 0) {
  3009. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3010. + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
  3011. + } else {
  3012. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3013. + name, value);
  3014. + }
  3015. + } else if (strcmp(type, "src/gz") == 0) {
  3016. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3017. + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
  3018. + } else {
  3019. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3020. + name, value);
  3021. + }
  3022. + } else if (strcmp(type, "dest") == 0) {
  3023. + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
  3024. + } else if (strcmp(type, "lists_dir") == 0) {
  3025. + *lists_dir = realloc(*lists_dir,strlen(value)+1);
  3026. + if (*lists_dir == NULL) {
  3027. + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
  3028. + free(options);
  3029. + return EINVAL;
  3030. + }
  3031. + sprintf (*lists_dir,"%s",value);
  3032. + } else if (strcmp(type, "arch") == 0) {
  3033. + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
  3034. + if (!value) {
  3035. + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
  3036. + value = strdup("10");
  3037. + }
  3038. + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
  3039. + } else {
  3040. + fprintf(stderr, "WARNING: Ignoring unknown configuration "
  3041. + "parameter: %s %s %s\n", type, name, value);
  3042. + free(options);
  3043. + return EINVAL;
  3044. + }
  3045. +
  3046. + free(type);
  3047. + free(name);
  3048. + free(value);
  3049. + if (extra)
  3050. + free (extra);
  3051. +
  3052. + NEXT_LINE:
  3053. + free(line);
  3054. + }
  3055. +
  3056. + free(options);
  3057. + regfree(&comment_re);
  3058. + regfree(&valid_line_re);
  3059. + fclose(file);
  3060. +
  3061. + return 0;
  3062. +}
  3063. +
  3064. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  3065. + const char *name, const char *value)
  3066. +{
  3067. + int i = 0;
  3068. + while (options[i].name) {
  3069. + if (strcmp(options[i].name, name) == 0) {
  3070. + switch (options[i].type) {
  3071. + case IPKG_OPT_TYPE_BOOL:
  3072. + *((int *)options[i].value) = 1;
  3073. + return 0;
  3074. + case IPKG_OPT_TYPE_INT:
  3075. + if (value) {
  3076. + *((int *)options[i].value) = atoi(value);
  3077. + return 0;
  3078. + } else {
  3079. + printf("%s: Option %s need an argument\n",
  3080. + __FUNCTION__, name);
  3081. + return EINVAL;
  3082. + }
  3083. + case IPKG_OPT_TYPE_STRING:
  3084. + if (value) {
  3085. + *((char **)options[i].value) = strdup(value);
  3086. + return 0;
  3087. + } else {
  3088. + printf("%s: Option %s need an argument\n",
  3089. + __FUNCTION__, name);
  3090. + return EINVAL;
  3091. + }
  3092. + }
  3093. + }
  3094. + i++;
  3095. + }
  3096. +
  3097. + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
  3098. + __FUNCTION__, name, value);
  3099. + return EINVAL;
  3100. +}
  3101. +
  3102. +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
  3103. +{
  3104. + pkg_dest_list_elt_t *iter;
  3105. + pkg_dest_t *dest;
  3106. + pkg_vec_t *all;
  3107. + pkg_t *pkg;
  3108. + register int i;
  3109. + int err;
  3110. +
  3111. + if (conf->noaction)
  3112. + return 0;
  3113. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3114. + dest = iter->data;
  3115. + dest->status_file = fopen(dest->status_file_tmp_name, "w");
  3116. + if (dest->status_file == NULL) {
  3117. + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
  3118. + __FUNCTION__, dest->status_file_name, strerror(errno));
  3119. + }
  3120. + }
  3121. +
  3122. + all = pkg_vec_alloc();
  3123. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  3124. +
  3125. + for(i = 0; i < all->len; i++) {
  3126. + pkg = all->pkgs[i];
  3127. + /* We don't need most uninstalled packages in the status file */
  3128. + if (pkg->state_status == SS_NOT_INSTALLED
  3129. + && (pkg->state_want == SW_UNKNOWN
  3130. + || pkg->state_want == SW_DEINSTALL
  3131. + || pkg->state_want == SW_PURGE)) {
  3132. + continue;
  3133. + }
  3134. + if (!pkg) {
  3135. + fprintf(stderr, "Null package\n");
  3136. + }
  3137. + if (pkg->dest == NULL) {
  3138. + fprintf(stderr, "%s: ERROR: Can't write status for "
  3139. + "package %s since it has a NULL dest\n",
  3140. + __FUNCTION__, pkg->name);
  3141. + continue;
  3142. + }
  3143. + if (pkg->dest->status_file) {
  3144. + pkg_print_status(pkg, pkg->dest->status_file);
  3145. + }
  3146. + }
  3147. +
  3148. + pkg_vec_free(all);
  3149. +
  3150. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3151. + dest = iter->data;
  3152. + if (dest->status_file) {
  3153. + err = ferror(dest->status_file);
  3154. + fclose(dest->status_file);
  3155. + dest->status_file = NULL;
  3156. + if (!err) {
  3157. + file_move(dest->status_file_tmp_name, dest->status_file_name);
  3158. + } else {
  3159. + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
  3160. + "retaining old %s\n", __FUNCTION__,
  3161. + dest->status_file_tmp_name, dest->status_file_name);
  3162. + }
  3163. + }
  3164. + }
  3165. +
  3166. + return 0;
  3167. +}
  3168. +
  3169. +
  3170. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
  3171. +{
  3172. + char *root_filename;
  3173. + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
  3174. + return root_filename;
  3175. +}
  3176. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_conf.h busybox-1.15.2/archival/libipkg/ipkg_conf.h
  3177. --- busybox-1.15.2.orig/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
  3178. +++ busybox-1.15.2/archival/libipkg/ipkg_conf.h 2010-03-14 20:53:41.000000000 +0100
  3179. @@ -0,0 +1,107 @@
  3180. +/* ipkg_conf.h - the itsy package management system
  3181. +
  3182. + Carl D. Worth
  3183. +
  3184. + Copyright (C) 2001 University of Southern California
  3185. +
  3186. + This program is free software; you can redistribute it and/or
  3187. + modify it under the terms of the GNU General Public License as
  3188. + published by the Free Software Foundation; either version 2, or (at
  3189. + your option) any later version.
  3190. +
  3191. + This program is distributed in the hope that it will be useful, but
  3192. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3193. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3194. + General Public License for more details.
  3195. +*/
  3196. +
  3197. +#ifndef IPKG_CONF_H
  3198. +#define IPKG_CONF_H
  3199. +
  3200. +typedef struct ipkg_conf ipkg_conf_t;
  3201. +
  3202. +#include "hash_table.h"
  3203. +#include "ipkg.h"
  3204. +#include "args.h"
  3205. +#include "pkg.h"
  3206. +#include "pkg_hash.h"
  3207. +#include "pkg_src_list.h"
  3208. +#include "pkg_dest_list.h"
  3209. +#include "nv_pair_list.h"
  3210. +
  3211. +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
  3212. +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
  3213. +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
  3214. +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
  3215. +
  3216. +/* In case the config file defines no dest */
  3217. +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
  3218. +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
  3219. +
  3220. +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
  3221. +
  3222. +struct ipkg_conf
  3223. +{
  3224. + pkg_src_list_t pkg_src_list;
  3225. + pkg_dest_list_t pkg_dest_list;
  3226. + nv_pair_list_t arch_list;
  3227. +
  3228. + int restrict_to_default_dest;
  3229. + pkg_dest_t *default_dest;
  3230. +
  3231. + char *tmp_dir;
  3232. + char *lists_dir;
  3233. + char *pending_dir;
  3234. +
  3235. + /* options */
  3236. + int force_depends;
  3237. + int force_defaults;
  3238. + int force_overwrite;
  3239. + int force_downgrade;
  3240. + int force_reinstall;
  3241. + int force_space;
  3242. + int force_removal_of_dependent_packages;
  3243. + int force_removal_of_essential_packages;
  3244. + int nodeps; /* do not follow dependences */
  3245. + int verbose_wget;
  3246. + int multiple_providers;
  3247. + char *offline_root;
  3248. + char *offline_root_pre_script_cmd;
  3249. + char *offline_root_post_script_cmd;
  3250. + int query_all;
  3251. + int verbosity;
  3252. + int noaction;
  3253. +
  3254. + /* proxy options */
  3255. + char *http_proxy;
  3256. + char *ftp_proxy;
  3257. + char *no_proxy;
  3258. + char *proxy_user;
  3259. + char *proxy_passwd;
  3260. +
  3261. + hash_table_t pkg_hash;
  3262. + hash_table_t file_hash;
  3263. + hash_table_t obs_file_hash;
  3264. +};
  3265. +
  3266. +enum ipkg_option_type {
  3267. + IPKG_OPT_TYPE_BOOL,
  3268. + IPKG_OPT_TYPE_INT,
  3269. + IPKG_OPT_TYPE_STRING
  3270. +};
  3271. +typedef enum ipkg_option_type ipkg_option_type_t;
  3272. +
  3273. +typedef struct ipkg_option ipkg_option_t;
  3274. +struct ipkg_option {
  3275. + const char *name;
  3276. + const ipkg_option_type_t type;
  3277. + const void *value;
  3278. +};
  3279. +
  3280. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
  3281. +void ipkg_conf_deinit(ipkg_conf_t *conf);
  3282. +
  3283. +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
  3284. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
  3285. +
  3286. +#endif
  3287. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_configure.c busybox-1.15.2/archival/libipkg/ipkg_configure.c
  3288. --- busybox-1.15.2.orig/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
  3289. +++ busybox-1.15.2/archival/libipkg/ipkg_configure.c 2010-03-14 20:53:41.000000000 +0100
  3290. @@ -0,0 +1,40 @@
  3291. +/* ipkg_configure.c - the itsy package management system
  3292. +
  3293. + Carl D. Worth
  3294. +
  3295. + Copyright (C) 2001 University of Southern California
  3296. +
  3297. + This program is free software; you can redistribute it and/or
  3298. + modify it under the terms of the GNU General Public License as
  3299. + published by the Free Software Foundation; either version 2, or (at
  3300. + your option) any later version.
  3301. +
  3302. + This program is distributed in the hope that it will be useful, but
  3303. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3304. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3305. + General Public License for more details.
  3306. +*/
  3307. +
  3308. +#include "ipkg.h"
  3309. +
  3310. +#include "ipkg_configure.h"
  3311. +
  3312. +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
  3313. +{
  3314. + int err;
  3315. +
  3316. + /* DPKG_INCOMPATIBILITY:
  3317. + dpkg actually does some conffile handling here, rather than at the
  3318. + end of ipkg_install(). Do we care? */
  3319. + /* DPKG_INCOMPATIBILITY:
  3320. + dpkg actually includes a version number to this script call */
  3321. + err = pkg_run_script(conf, pkg, "postinst", "configure");
  3322. + if (err) {
  3323. + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
  3324. + return err;
  3325. + }
  3326. +
  3327. + ipkg_state_changed++;
  3328. + return 0;
  3329. +}
  3330. +
  3331. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_configure.h busybox-1.15.2/archival/libipkg/ipkg_configure.h
  3332. --- busybox-1.15.2.orig/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
  3333. +++ busybox-1.15.2/archival/libipkg/ipkg_configure.h 2010-03-14 20:53:41.000000000 +0100
  3334. @@ -0,0 +1,25 @@
  3335. +/* ipkg_configure.h - the itsy package management system
  3336. +
  3337. + Carl D. Worth
  3338. +
  3339. + Copyright (C) 2001 University of Southern California
  3340. +
  3341. + This program is free software; you can redistribute it and/or
  3342. + modify it under the terms of the GNU General Public License as
  3343. + published by the Free Software Foundation; either version 2, or (at
  3344. + your option) any later version.
  3345. +
  3346. + This program is distributed in the hope that it will be useful, but
  3347. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3348. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3349. + General Public License for more details.
  3350. +*/
  3351. +
  3352. +#ifndef IPKG_CONFIGURE_H
  3353. +#define IPKG_CONFIGURE_H
  3354. +
  3355. +#include "ipkg_conf.h"
  3356. +
  3357. +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
  3358. +
  3359. +#endif
  3360. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_download.c busybox-1.15.2/archival/libipkg/ipkg_download.c
  3361. --- busybox-1.15.2.orig/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
  3362. +++ busybox-1.15.2/archival/libipkg/ipkg_download.c 2010-03-14 20:53:41.000000000 +0100
  3363. @@ -0,0 +1,195 @@
  3364. +/* ipkg_download.c - the itsy package management system
  3365. +
  3366. + Carl D. Worth
  3367. +
  3368. + Copyright (C) 2001 University of Southern California
  3369. +
  3370. + This program is free software; you can redistribute it and/or
  3371. + modify it under the terms of the GNU General Public License as
  3372. + published by the Free Software Foundation; either version 2, or (at
  3373. + your option) any later version.
  3374. +
  3375. + This program is distributed in the hope that it will be useful, but
  3376. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3377. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3378. + General Public License for more details.
  3379. +*/
  3380. +
  3381. +#include "ipkg.h"
  3382. +#include "ipkg_download.h"
  3383. +#include "ipkg_message.h"
  3384. +
  3385. +#include "sprintf_alloc.h"
  3386. +#include "xsystem.h"
  3387. +#include "file_util.h"
  3388. +#include "str_util.h"
  3389. +
  3390. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
  3391. +{
  3392. + int err = 0;
  3393. +
  3394. + char *src_basec = strdup(src);
  3395. + char *src_base = basename(src_basec);
  3396. + char *tmp_file_location;
  3397. + char *cmd;
  3398. +
  3399. + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
  3400. +
  3401. + fflush(stdout);
  3402. +
  3403. + if (str_starts_with(src, "file:")) {
  3404. + int ret;
  3405. + const char *file_src = src + 5;
  3406. + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
  3407. + ret = file_copy(src + 5, dest_file_name);
  3408. + ipkg_message(conf,IPKG_INFO,"Done.\n");
  3409. + return ret;
  3410. + }
  3411. +
  3412. + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
  3413. + err = unlink(tmp_file_location);
  3414. + if (err && errno != ENOENT) {
  3415. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
  3416. + __FUNCTION__, tmp_file_location, strerror(errno));
  3417. + free(tmp_file_location);
  3418. + return errno;
  3419. + }
  3420. +
  3421. + if (conf->http_proxy) {
  3422. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
  3423. + setenv("http_proxy", conf->http_proxy, 1);
  3424. + }
  3425. + if (conf->ftp_proxy) {
  3426. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
  3427. + setenv("ftp_proxy", conf->ftp_proxy, 1);
  3428. + }
  3429. + if (conf->no_proxy) {
  3430. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
  3431. + setenv("no_proxy", conf->no_proxy, 1);
  3432. + }
  3433. +
  3434. + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
  3435. + sprintf_alloc(&cmd, "wget %s %s%s %s%s %s -P %s %s",
  3436. + (conf->http_proxy || conf->ftp_proxy) ? "-Y on" : "",
  3437. + conf->proxy_user ? "--proxy-user=" : "",
  3438. + conf->proxy_user ? conf->proxy_user : "",
  3439. + conf->proxy_passwd ? "--proxy-passwd=" : "",
  3440. + conf->proxy_passwd ? conf->proxy_passwd : "",
  3441. + conf->verbose_wget ? "" : "-q",
  3442. + conf->tmp_dir,
  3443. + src);
  3444. + err = xsystem(cmd);
  3445. + if (err) {
  3446. + if (err != -1) {
  3447. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
  3448. + __FUNCTION__, err, cmd);
  3449. + }
  3450. + unlink(tmp_file_location);
  3451. + free(tmp_file_location);
  3452. + free(src_basec);
  3453. + free(cmd);
  3454. + return EINVAL;
  3455. + }
  3456. + free(cmd);
  3457. +
  3458. + err = file_move(tmp_file_location, dest_file_name);
  3459. +
  3460. + free(tmp_file_location);
  3461. + free(src_basec);
  3462. +
  3463. + if (err) {
  3464. + return err;
  3465. + }
  3466. +
  3467. + return 0;
  3468. +}
  3469. +
  3470. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
  3471. +{
  3472. + int err;
  3473. + char *url;
  3474. +
  3475. + if (pkg->src == NULL) {
  3476. + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
  3477. + pkg->name, pkg->parent->name);
  3478. + return -1;
  3479. + }
  3480. +
  3481. + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
  3482. +
  3483. + /* XXX: BUG: The pkg->filename might be something like
  3484. + "../../foo.ipk". While this is correct, and exactly what we
  3485. + want to use to construct url above, here we actually need to
  3486. + use just the filename part, without any directory. */
  3487. + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
  3488. +
  3489. + err = ipkg_download(conf, url, pkg->local_filename);
  3490. + free(url);
  3491. +
  3492. + return err;
  3493. +}
  3494. +
  3495. +/*
  3496. + * Downloads file from url, installs in package database, return package name.
  3497. + */
  3498. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
  3499. +{
  3500. + int err = 0;
  3501. + pkg_t *pkg;
  3502. + pkg = pkg_new();
  3503. + if (pkg == NULL)
  3504. + return ENOMEM;
  3505. +
  3506. + if (str_starts_with(url, "http://")
  3507. + || str_starts_with(url, "ftp://")) {
  3508. + char *tmp_file;
  3509. + char *file_basec = strdup(url);
  3510. + char *file_base = basename(file_basec);
  3511. +
  3512. + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
  3513. + err = ipkg_download(conf, url, tmp_file);
  3514. + if (err)
  3515. + return err;
  3516. +
  3517. + err = pkg_init_from_file(pkg, tmp_file);
  3518. + if (err)
  3519. + return err;
  3520. + pkg->local_filename = strdup(tmp_file);
  3521. +
  3522. + free(tmp_file);
  3523. + free(file_basec);
  3524. +
  3525. + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
  3526. + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
  3527. +
  3528. + err = pkg_init_from_file(pkg, url);
  3529. + if (err)
  3530. + return err;
  3531. + pkg->local_filename = strdup(url);
  3532. + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
  3533. + pkg->provided_by_hand = 1;
  3534. +
  3535. + } else {
  3536. + pkg_deinit(pkg);
  3537. + free(pkg);
  3538. + return 0;
  3539. + }
  3540. +
  3541. + if (!pkg->architecture) {
  3542. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3543. + return -EINVAL;
  3544. + }
  3545. +
  3546. + pkg->dest = conf->default_dest;
  3547. + pkg->state_want = SW_INSTALL;
  3548. + pkg->state_flag |= SF_PREFER;
  3549. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3550. + if ( pkg == NULL ){
  3551. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  3552. + return 0;
  3553. + }
  3554. + if (namep) {
  3555. + *namep = strdup(pkg->name);
  3556. + }
  3557. + return 0;
  3558. +}
  3559. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_download.h busybox-1.15.2/archival/libipkg/ipkg_download.h
  3560. --- busybox-1.15.2.orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
  3561. +++ busybox-1.15.2/archival/libipkg/ipkg_download.h 2010-03-14 20:53:41.000000000 +0100
  3562. @@ -0,0 +1,30 @@
  3563. +/* ipkg_download.h - the itsy package management system
  3564. +
  3565. + Carl D. Worth
  3566. +
  3567. + Copyright (C) 2001 University of Southern California
  3568. +
  3569. + This program is free software; you can redistribute it and/or
  3570. + modify it under the terms of the GNU General Public License as
  3571. + published by the Free Software Foundation; either version 2, or (at
  3572. + your option) any later version.
  3573. +
  3574. + This program is distributed in the hope that it will be useful, but
  3575. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3576. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3577. + General Public License for more details.
  3578. +*/
  3579. +
  3580. +#ifndef IPKG_DOWNLOAD_H
  3581. +#define IPKG_DOWNLOAD_H
  3582. +
  3583. +#include "ipkg_conf.h"
  3584. +
  3585. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
  3586. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
  3587. +/*
  3588. + * Downloads file from url, installs in package database, return package name.
  3589. + */
  3590. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
  3591. +
  3592. +#endif
  3593. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg.h busybox-1.15.2/archival/libipkg/ipkg.h
  3594. --- busybox-1.15.2.orig/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
  3595. +++ busybox-1.15.2/archival/libipkg/ipkg.h 2010-03-14 20:53:41.000000000 +0100
  3596. @@ -0,0 +1,68 @@
  3597. +/* ipkg.h - the itsy package management system
  3598. +
  3599. + Carl D. Worth
  3600. +
  3601. + Copyright (C) 2001 University of Southern California
  3602. +
  3603. + This program is free software; you can redistribute it and/or
  3604. + modify it under the terms of the GNU General Public License as
  3605. + published by the Free Software Foundation; either version 2, or (at
  3606. + your option) any later version.
  3607. +
  3608. + This program is distributed in the hope that it will be useful, but
  3609. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3610. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3611. + General Public License for more details.
  3612. +*/
  3613. +
  3614. +#ifndef IPKG_H
  3615. +#define IPKG_H
  3616. +
  3617. +#include "libbb.h"
  3618. +
  3619. +#include "ipkg_includes.h"
  3620. +#include "ipkg_conf.h"
  3621. +#include "ipkg_message.h"
  3622. +
  3623. +#define IPKG_PKG_EXTENSION ".ipk"
  3624. +#define DPKG_PKG_EXTENSION ".deb"
  3625. +
  3626. +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
  3627. +#define IPKG_PKG_VERSION_SEP_CHAR '_'
  3628. +
  3629. +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
  3630. +#define IPKG_LISTS_DIR_SUFFIX "lists"
  3631. +#define IPKG_INFO_DIR_SUFFIX "info"
  3632. +#define IPKG_STATUS_FILE_SUFFIX "status"
  3633. +
  3634. +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
  3635. +
  3636. +#define IPKG_LIST_DESCRIPTION_LENGTH 128
  3637. +
  3638. +#define IPKG_VERSION "1.00"
  3639. +
  3640. +
  3641. +enum ipkg_error {
  3642. + IPKG_SUCCESS = 0,
  3643. + IPKG_PKG_DEPS_UNSATISFIED,
  3644. + IPKG_PKG_IS_ESSENTIAL,
  3645. + IPKG_PKG_HAS_DEPENDENTS,
  3646. + IPKG_PKG_HAS_NO_CANDIDATE
  3647. +};
  3648. +typedef enum ipkg_error ipkg_error_t;
  3649. +
  3650. +extern int ipkg_state_changed;
  3651. +
  3652. +
  3653. +struct errlist {
  3654. + char * errmsg;
  3655. + struct errlist * next;
  3656. +} ;
  3657. +
  3658. +extern struct errlist* error_list;
  3659. +
  3660. +extern ipkg_conf_t *global_conf;
  3661. +
  3662. +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
  3663. +
  3664. +#endif
  3665. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_includes.h busybox-1.15.2/archival/libipkg/ipkg_includes.h
  3666. --- busybox-1.15.2.orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
  3667. +++ busybox-1.15.2/archival/libipkg/ipkg_includes.h 2010-03-14 20:53:41.000000000 +0100
  3668. @@ -0,0 +1,79 @@
  3669. +#ifndef IPKG_INCLUDES_H
  3670. +#define IPKG_INCLUDES_H
  3671. +
  3672. +/* Define to 1 if you have the <memory.h> header file. */
  3673. +#define HAVE_MEMORY_H 1
  3674. +
  3675. +/* Define to 1 if you have the <regex.h> header file. */
  3676. +#define HAVE_REGEX_H 1
  3677. +
  3678. +/* Define to 1 if you have the <stdlib.h> header file. */
  3679. +#define HAVE_STDLIB_H 1
  3680. +
  3681. +/* Define to 1 if you have the <strings.h> header file. */
  3682. +#define HAVE_STRINGS_H 1
  3683. +
  3684. +/* Define to 1 if you have the <string.h> header file. */
  3685. +#define HAVE_STRING_H 1
  3686. +
  3687. +/* Define to 1 if you have the <sys/stat.h> header file. */
  3688. +#define HAVE_SYS_STAT_H 1
  3689. +
  3690. +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
  3691. +#define HAVE_SYS_WAIT_H 1
  3692. +
  3693. +/* Define to 1 if you have the <unistd.h> header file. */
  3694. +#define HAVE_UNISTD_H 1
  3695. +
  3696. +/* Define to 1 if you have the ANSI C header files. */
  3697. +#define STDC_HEADERS 1
  3698. +
  3699. +
  3700. +#include <stdio.h>
  3701. +
  3702. +#if STDC_HEADERS
  3703. +# include <stdlib.h>
  3704. +# include <stdarg.h>
  3705. +# include <stddef.h>
  3706. +# include <ctype.h>
  3707. +# include <errno.h>
  3708. +#else
  3709. +# if HAVE_STDLIB_H
  3710. +# include <stdlib.h>
  3711. +# endif
  3712. +#endif
  3713. +
  3714. +#if HAVE_REGEX_H
  3715. +# include <regex.h>
  3716. +#endif
  3717. +
  3718. +#if HAVE_STRING_H
  3719. +# if !STDC_HEADERS && HAVE_MEMORY_H
  3720. +# include <memory.h>
  3721. +# endif
  3722. +/* XXX: What's the right way to pick up GNU's strndup declaration? */
  3723. +# if __GNUC__
  3724. +# define __USE_GNU 1
  3725. +# endif
  3726. +# include <string.h>
  3727. +# undef __USE_GNU
  3728. +#endif
  3729. +
  3730. +#if HAVE_STRINGS_H
  3731. +# include <strings.h>
  3732. +#endif
  3733. +
  3734. +#if HAVE_SYS_STAT_H
  3735. +# include <sys/stat.h>
  3736. +#endif
  3737. +
  3738. +#if HAVE_SYS_WAIT_H
  3739. +# include <sys/wait.h>
  3740. +#endif
  3741. +
  3742. +#if HAVE_UNISTD_H
  3743. +# include <sys/types.h>
  3744. +# include <unistd.h>
  3745. +#endif
  3746. +
  3747. +#endif /* IPKG_INCLUDES_H */
  3748. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_install.c busybox-1.15.2/archival/libipkg/ipkg_install.c
  3749. --- busybox-1.15.2.orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
  3750. +++ busybox-1.15.2/archival/libipkg/ipkg_install.c 2010-03-14 20:53:41.000000000 +0100
  3751. @@ -0,0 +1,1982 @@
  3752. +/* ipkg_install.c - the itsy package management system
  3753. +
  3754. + Carl D. Worth
  3755. +
  3756. + Copyright (C) 2001 University of Southern California
  3757. +
  3758. + This program is free software; you can redistribute it and/or
  3759. + modify it under the terms of the GNU General Public License as
  3760. + published by the Free Software Foundation; either version 2, or (at
  3761. + your option) any later version.
  3762. +
  3763. + This program is distributed in the hope that it will be useful, but
  3764. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3765. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3766. + General Public License for more details.
  3767. +*/
  3768. +
  3769. +#include "ipkg.h"
  3770. +#include <errno.h>
  3771. +#include <dirent.h>
  3772. +#include <glob.h>
  3773. +#include <time.h>
  3774. +#include <signal.h>
  3775. +typedef void (*sighandler_t)(int);
  3776. +
  3777. +#include "pkg.h"
  3778. +#include "pkg_hash.h"
  3779. +#include "pkg_extract.h"
  3780. +
  3781. +#include "ipkg_install.h"
  3782. +#include "ipkg_configure.h"
  3783. +#include "ipkg_download.h"
  3784. +#include "ipkg_remove.h"
  3785. +
  3786. +#include "ipkg_utils.h"
  3787. +#include "ipkg_message.h"
  3788. +
  3789. +#include "sprintf_alloc.h"
  3790. +#include "file_util.h"
  3791. +#include "str_util.h"
  3792. +#include "xsystem.h"
  3793. +#include "user.h"
  3794. +
  3795. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  3796. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
  3797. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
  3798. +
  3799. +/*
  3800. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3801. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3802. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3803. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3804. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3805. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3806. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3807. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
  3808. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3809. +*/
  3810. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3811. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3812. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg);
  3813. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3814. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg);
  3815. +
  3816. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3817. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3818. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
  3819. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
  3820. +
  3821. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
  3822. +
  3823. +static int user_prefers_old_conffile(const char *file, const char *backup);
  3824. +
  3825. +static char *backup_filename_alloc(const char *file_name);
  3826. +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
  3827. +static int backup_exists_for(const char *file_name);
  3828. +static int backup_remove(const char *file_name);
  3829. +
  3830. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees);
  3831. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3832. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3833. +
  3834. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
  3835. +{
  3836. + int err, cmp;
  3837. + pkg_t *pkg, *old;
  3838. + char *old_version, *new_version;
  3839. +
  3840. + pkg = pkg_new();
  3841. + if (pkg == NULL) {
  3842. + return ENOMEM;
  3843. + }
  3844. +
  3845. + err = pkg_init_from_file(pkg, filename);
  3846. + if (err) {
  3847. + return err;
  3848. + }
  3849. +
  3850. + if (!pkg->architecture) {
  3851. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3852. + return -EINVAL;
  3853. + }
  3854. +
  3855. + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
  3856. + freeing the pkg that we pass in. It might be nice to clean this up
  3857. + if possible. */
  3858. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3859. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  3860. +
  3861. + pkg->local_filename = strdup(filename);
  3862. +
  3863. + if (old) {
  3864. + old_version = pkg_version_str_alloc(old);
  3865. + new_version = pkg_version_str_alloc(pkg);
  3866. +
  3867. + cmp = pkg_compare_versions(old, pkg);
  3868. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3869. + cmp = -1 ; /* then we force ipkg to downgrade */
  3870. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3871. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3872. + }
  3873. + if (cmp > 0) {
  3874. + ipkg_message(conf, IPKG_NOTICE,
  3875. + "Not downgrading package %s on %s from %s to %s.\n",
  3876. + old->name, old->dest->name, old_version, new_version);
  3877. + pkg->state_want = SW_DEINSTALL;
  3878. + pkg->state_flag |= SF_OBSOLETE;
  3879. + free(old_version);
  3880. + free(new_version);
  3881. + return 0;
  3882. + } else {
  3883. + free(old_version);
  3884. + free(new_version);
  3885. + }
  3886. + }
  3887. +
  3888. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3889. + return ipkg_install_pkg(conf, pkg,0);
  3890. +}
  3891. +
  3892. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3893. +{
  3894. + int cmp;
  3895. + pkg_t *old, *new;
  3896. + char *old_version, *new_version;
  3897. +
  3898. + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
  3899. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  3900. + if ( old )
  3901. + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
  3902. +
  3903. + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
  3904. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  3905. + if ( new )
  3906. + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
  3907. +
  3908. +/* Pigi Basically here is broken the version stuff.
  3909. + What's happening is that nothing provide the version to differents
  3910. + functions, so the returned struct is always the latest.
  3911. + That's why the install by name don't work.
  3912. +*/
  3913. + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
  3914. +
  3915. + if ( old )
  3916. + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
  3917. + if ( new )
  3918. + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
  3919. + ipkg_message(conf, IPKG_DEBUG2, " \n");
  3920. +
  3921. + if (new == NULL) {
  3922. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3923. + }
  3924. +
  3925. + new->state_flag |= SF_USER;
  3926. + if (old) {
  3927. + old_version = pkg_version_str_alloc(old);
  3928. + new_version = pkg_version_str_alloc(new);
  3929. +
  3930. + cmp = pkg_compare_versions(old, new);
  3931. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3932. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
  3933. + cmp = -1 ; /* then we force ipkg to downgrade */
  3934. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3935. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3936. + }
  3937. + ipkg_message(conf, IPKG_DEBUG,
  3938. + "Comparing visible versions of pkg %s:"
  3939. + "\n\t%s is installed "
  3940. + "\n\t%s is available "
  3941. + "\n\t%d was comparison result\n",
  3942. + pkg_name, old_version, new_version, cmp);
  3943. + if (cmp == 0 && !conf->force_reinstall) {
  3944. + ipkg_message(conf, IPKG_NOTICE,
  3945. + "Package %s (%s) installed in %s is up to date.\n",
  3946. + old->name, old_version, old->dest->name);
  3947. + free(old_version);
  3948. + free(new_version);
  3949. + return 0;
  3950. + } else if (cmp > 0) {
  3951. + ipkg_message(conf, IPKG_NOTICE,
  3952. + "Not downgrading package %s on %s from %s to %s.\n",
  3953. + old->name, old->dest->name, old_version, new_version);
  3954. + free(old_version);
  3955. + free(new_version);
  3956. + return 0;
  3957. + } else if (cmp < 0) {
  3958. + new->dest = old->dest;
  3959. + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
  3960. + }
  3961. + }
  3962. +
  3963. + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
  3964. + supposed to be an ipkg_error_t, but ipkg_install_pkg could
  3965. + return any kind of integer, (might be errno from a syscall,
  3966. + etc.). This is a real mess and will need to be cleaned up if
  3967. + anyone ever wants to make a nice libipkg. */
  3968. +
  3969. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3970. + return ipkg_install_pkg(conf, new,0);
  3971. +}
  3972. +
  3973. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3974. +{
  3975. + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
  3976. + int i;
  3977. + ipkg_error_t err;
  3978. + abstract_pkg_t *ppkg ;
  3979. +
  3980. + if (providers == NULL)
  3981. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3982. +
  3983. + for (i = 0; i < providers->len; i++) {
  3984. + ppkg = abstract_pkg_vec_get(providers, i);
  3985. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
  3986. + err = ipkg_install_by_name(conf, ppkg->name);
  3987. + if (err)
  3988. + return err;
  3989. +/* XXX Maybe ppkg should be freed ? */
  3990. + }
  3991. + return 0;
  3992. +}
  3993. +
  3994. +/*
  3995. + * Walk dependence graph starting with pkg, collect packages to be
  3996. + * installed into pkgs_needed, in dependence order.
  3997. + */
  3998. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
  3999. +{
  4000. + int i, err;
  4001. + pkg_vec_t *depends = pkg_vec_alloc();
  4002. + char **unresolved = NULL;
  4003. + int ndepends;
  4004. +
  4005. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4006. + pkg, depends,
  4007. + &unresolved);
  4008. +
  4009. + if (unresolved) {
  4010. + ipkg_message(conf, IPKG_ERROR,
  4011. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4012. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4013. + while (*unresolved) {
  4014. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4015. + unresolved++;
  4016. + }
  4017. + ipkg_message(conf, IPKG_ERROR, "\n");
  4018. + if (! conf->force_depends) {
  4019. + ipkg_message(conf, IPKG_INFO,
  4020. + "This could mean that your package list is out of date or that the packages\n"
  4021. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4022. + "of this problem try again with the '-force-depends' option.\n");
  4023. + pkg_vec_free(depends);
  4024. + return IPKG_PKG_DEPS_UNSATISFIED;
  4025. + }
  4026. + }
  4027. +
  4028. + if (ndepends <= 0) {
  4029. + pkg_vec_free(depends);
  4030. + return 0;
  4031. + }
  4032. +
  4033. + for (i = 0; i < depends->len; i++) {
  4034. + pkg_t *dep = depends->pkgs[i];
  4035. + /* The package was uninstalled when we started, but another
  4036. + dep earlier in this loop may have depended on it and pulled
  4037. + it in, so check first. */
  4038. + if ((dep->state_status != SS_INSTALLED)
  4039. + && (dep->state_status != SS_UNPACKED)
  4040. + && (dep->state_want != SW_INSTALL)) {
  4041. +
  4042. + /* Mark packages as to-be-installed */
  4043. + dep->state_want = SW_INSTALL;
  4044. +
  4045. + /* Dependencies should be installed the same place as pkg */
  4046. + if (dep->dest == NULL) {
  4047. + dep->dest = pkg->dest;
  4048. + }
  4049. +
  4050. + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
  4051. + if (err) {
  4052. + pkg_vec_free(depends);
  4053. + return err;
  4054. + }
  4055. + }
  4056. + }
  4057. + if (pkgs_needed)
  4058. + pkg_vec_insert(pkgs_needed, pkg);
  4059. +
  4060. + pkg_vec_free(depends);
  4061. +
  4062. + return 0;
  4063. +}
  4064. +
  4065. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
  4066. +{
  4067. + int cmp;
  4068. + pkg_t *old, *new;
  4069. + char *old_version, *new_version;
  4070. +
  4071. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  4072. +
  4073. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  4074. + if (new == NULL) {
  4075. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4076. + }
  4077. + if (old) {
  4078. + old_version = pkg_version_str_alloc(old);
  4079. + new_version = pkg_version_str_alloc(new);
  4080. +
  4081. + cmp = pkg_compare_versions(old, new);
  4082. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4083. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
  4084. + cmp = -1 ; /* then we force ipkg to downgrade */
  4085. + /* We need to use a value < 0 because in the 0 case we are asking to */
  4086. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4087. + }
  4088. + ipkg_message(conf, IPKG_DEBUG,
  4089. + "comparing visible versions of pkg %s:"
  4090. + "\n\t%s is installed "
  4091. + "\n\t%s is available "
  4092. + "\n\t%d was comparison result\n",
  4093. + pkg_name, old_version, new_version, cmp);
  4094. + if (cmp == 0 && !conf->force_reinstall) {
  4095. + ipkg_message(conf, IPKG_NOTICE,
  4096. + "Package %s (%s) installed in %s is up to date.\n",
  4097. + old->name, old_version, old->dest->name);
  4098. + free(old_version);
  4099. + free(new_version);
  4100. + return 0;
  4101. + } else if (cmp > 0) {
  4102. + ipkg_message(conf, IPKG_NOTICE,
  4103. + "Not downgrading package %s on %s from %s to %s.\n",
  4104. + old->name, old->dest->name, old_version, new_version);
  4105. + free(old_version);
  4106. + free(new_version);
  4107. + return 0;
  4108. + } else if (cmp < 0) {
  4109. + new->dest = old->dest;
  4110. + old->state_want = SW_DEINSTALL;
  4111. + old->state_flag |= SF_OBSOLETE;
  4112. + }
  4113. + }
  4114. + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
  4115. +}
  4116. +
  4117. +
  4118. +
  4119. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
  4120. +{
  4121. + int i, err;
  4122. + pkg_vec_t *depends = pkg_vec_alloc();
  4123. + pkg_t *dep;
  4124. + char **unresolved = NULL;
  4125. + int ndepends;
  4126. +
  4127. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4128. + pkg, depends,
  4129. + &unresolved);
  4130. +
  4131. + if (unresolved) {
  4132. + ipkg_message(conf, IPKG_ERROR,
  4133. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4134. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4135. + while (*unresolved) {
  4136. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4137. + unresolved++;
  4138. + }
  4139. + ipkg_message(conf, IPKG_ERROR, "\n");
  4140. + if (! conf->force_depends) {
  4141. + ipkg_message(conf, IPKG_INFO,
  4142. + "This could mean that your package list is out of date or that the packages\n"
  4143. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4144. + "of this problem try again with the '-force-depends' option.\n");
  4145. + pkg_vec_free(depends);
  4146. + return IPKG_PKG_DEPS_UNSATISFIED;
  4147. + }
  4148. + }
  4149. +
  4150. + if (ndepends <= 0) {
  4151. + return 0;
  4152. + }
  4153. +
  4154. + /* Mark packages as to-be-installed */
  4155. + for (i=0; i < depends->len; i++) {
  4156. + /* Dependencies should be installed the same place as pkg */
  4157. + if (depends->pkgs[i]->dest == NULL) {
  4158. + depends->pkgs[i]->dest = pkg->dest;
  4159. + }
  4160. + depends->pkgs[i]->state_want = SW_INSTALL;
  4161. + }
  4162. +
  4163. + for (i = 0; i < depends->len; i++) {
  4164. + dep = depends->pkgs[i];
  4165. + /* The package was uninstalled when we started, but another
  4166. + dep earlier in this loop may have depended on it and pulled
  4167. + it in, so check first. */
  4168. + if ((dep->state_status != SS_INSTALLED)
  4169. + && (dep->state_status != SS_UNPACKED)) {
  4170. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4171. + err = ipkg_install_pkg(conf, dep,0);
  4172. + if (err) {
  4173. + pkg_vec_free(depends);
  4174. + return err;
  4175. + }
  4176. + }
  4177. + }
  4178. +
  4179. + pkg_vec_free(depends);
  4180. +
  4181. + return 0;
  4182. +}
  4183. +
  4184. +
  4185. +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
  4186. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
  4187. +{
  4188. + if (conf->nodeps == 0) {
  4189. + int i;
  4190. + pkg_vec_t *installed = pkg_vec_alloc();
  4191. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  4192. + for (i = 0; i < installed->len; i++) {
  4193. + pkg_t *pkg = installed->pkgs[i];
  4194. + satisfy_dependencies_for(conf, pkg);
  4195. + }
  4196. + pkg_vec_free(installed);
  4197. + }
  4198. + return 0;
  4199. +}
  4200. +
  4201. +
  4202. +
  4203. +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
  4204. +{
  4205. + int i;
  4206. + pkg_vec_t *conflicts = NULL;
  4207. + int level;
  4208. + const char *prefix;
  4209. + if (conf->force_depends) {
  4210. + level = IPKG_NOTICE;
  4211. + prefix = "Warning";
  4212. + } else {
  4213. + level = IPKG_ERROR;
  4214. + prefix = "ERROR";
  4215. + }
  4216. +
  4217. + if (!conf->force_depends)
  4218. + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(pkg);
  4219. +
  4220. + if (conflicts) {
  4221. + ipkg_message(conf, level,
  4222. + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
  4223. + i = 0;
  4224. + while (i < conflicts->len)
  4225. + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
  4226. + ipkg_message(conf, level, "\n");
  4227. + pkg_vec_free(conflicts);
  4228. + return IPKG_PKG_DEPS_UNSATISFIED;
  4229. + }
  4230. + return 0;
  4231. +}
  4232. +
  4233. +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
  4234. +{
  4235. + str_list_t *new_list = pkg_get_installed_files(new_pkg);
  4236. + str_list_elt_t *iter;
  4237. +
  4238. + for (iter = new_list->head; iter; iter = iter->next) {
  4239. + char *new_file = iter->data;
  4240. + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
  4241. + if (!new_file)
  4242. + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
  4243. + if (!owner || (owner == old_pkg))
  4244. + file_hash_set_file_owner(conf, new_file, new_pkg);
  4245. + }
  4246. + if (old_pkg) {
  4247. + str_list_t *old_list = pkg_get_installed_files(old_pkg);
  4248. + for (iter = old_list->head; iter; iter = iter->next) {
  4249. + char *old_file = iter->data;
  4250. + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
  4251. + if (owner == old_pkg) {
  4252. + /* obsolete */
  4253. + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
  4254. + }
  4255. + }
  4256. + }
  4257. + return 0;
  4258. +}
  4259. +
  4260. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
  4261. +{
  4262. + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
  4263. +
  4264. + /* sma 6.20.02: yup; here's the first bit */
  4265. + /*
  4266. + * XXX: BUG easy for cworth
  4267. + * 1) please point the call below to the correct current root destination
  4268. + * 2) we need to resolve how to check the required space for a pending pkg,
  4269. + * my diddling with the .ipk file size below isn't going to cut it.
  4270. + * 3) return a proper error code instead of 1
  4271. + */
  4272. + int comp_size, blocks_available;
  4273. +
  4274. + if (!conf->force_space && pkg->installed_size != NULL) {
  4275. + blocks_available = get_available_blocks(conf->default_dest->root_dir);
  4276. +
  4277. + comp_size = strtoul(pkg->installed_size, NULL, 0);
  4278. + /* round up a blocks count without doing fancy-but-slow casting jazz */
  4279. + comp_size = (int)((comp_size + 1023) / 1024);
  4280. +
  4281. + if (comp_size >= blocks_available) {
  4282. + ipkg_message(conf, IPKG_ERROR,
  4283. + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
  4284. + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
  4285. + return ENOSPC;
  4286. + }
  4287. + }
  4288. + return 0;
  4289. +}
  4290. +
  4291. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
  4292. +{
  4293. + int err;
  4294. + char *conffiles_file_name;
  4295. + char *root_dir;
  4296. + FILE *conffiles_file;
  4297. +
  4298. + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
  4299. +
  4300. + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
  4301. + if (pkg->tmp_unpack_dir == NULL) {
  4302. + ipkg_message(conf, IPKG_ERROR,
  4303. + "%s: Failed to create temporary directory '%s': %s\n",
  4304. + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
  4305. + return errno;
  4306. + }
  4307. +
  4308. + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
  4309. + if (err) {
  4310. + return err;
  4311. + }
  4312. +
  4313. + /* XXX: CLEANUP: There might be a cleaner place to read in the
  4314. + conffiles. Seems like I should be able to get everything to go
  4315. + through pkg_init_from_file. If so, maybe it would make sense to
  4316. + move all of unpack_pkg_control_files to that function. */
  4317. +
  4318. + /* Don't need to re-read conffiles if we already have it */
  4319. + if (pkg->conffiles.head) {
  4320. + return 0;
  4321. + }
  4322. +
  4323. + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
  4324. + if (! file_exists(conffiles_file_name)) {
  4325. + free(conffiles_file_name);
  4326. + return 0;
  4327. + }
  4328. +
  4329. + conffiles_file = fopen(conffiles_file_name, "r");
  4330. + if (conffiles_file == NULL) {
  4331. + fprintf(stderr, "%s: failed to open %s: %s\n",
  4332. + __FUNCTION__, conffiles_file_name, strerror(errno));
  4333. + free(conffiles_file_name);
  4334. + return errno;
  4335. + }
  4336. + free(conffiles_file_name);
  4337. +
  4338. + while (1) {
  4339. + char *cf_name;
  4340. + char *cf_name_in_dest;
  4341. +
  4342. + cf_name = file_read_line_alloc(conffiles_file);
  4343. + if (cf_name == NULL) {
  4344. + break;
  4345. + }
  4346. + str_chomp(cf_name);
  4347. + if (cf_name[0] == '\0') {
  4348. + continue;
  4349. + }
  4350. +
  4351. + /* Prepend dest->root_dir to conffile name.
  4352. + Take pains to avoid multiple slashes. */
  4353. + root_dir = pkg->dest->root_dir;
  4354. + if (conf->offline_root)
  4355. + /* skip the offline_root prefix */
  4356. + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
  4357. + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
  4358. + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
  4359. +
  4360. + /* Can't get an md5sum now, (file isn't extracted yet).
  4361. + We'll wait until resolve_conffiles */
  4362. + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
  4363. +
  4364. + free(cf_name);
  4365. + free(cf_name_in_dest);
  4366. + }
  4367. +
  4368. + fclose(conffiles_file);
  4369. +
  4370. + return 0;
  4371. +}
  4372. +
  4373. +/* returns number of installed replacees */
  4374. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees)
  4375. +{
  4376. + abstract_pkg_t **replaces = pkg->replaces;
  4377. + int replaces_count = pkg->replaces_count;
  4378. + int i, j;
  4379. + for (i = 0; i < replaces_count; i++) {
  4380. + abstract_pkg_t *ab_pkg = replaces[i];
  4381. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  4382. + if (pkg_vec) {
  4383. + for (j = 0; j < pkg_vec->len; j++) {
  4384. + pkg_t *replacee = pkg_vec->pkgs[j];
  4385. + if (!pkg_conflicts(pkg, replacee))
  4386. + continue;
  4387. + if (replacee->state_status == SS_INSTALLED) {
  4388. + pkg_vec_insert(installed_replacees, replacee);
  4389. + }
  4390. + }
  4391. + }
  4392. + }
  4393. + return installed_replacees->len;
  4394. +}
  4395. +
  4396. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4397. +{
  4398. + int i;
  4399. + int replaces_count = replacees->len;
  4400. + for (i = 0; i < replaces_count; i++) {
  4401. + pkg_t *replacee = replacees->pkgs[i];
  4402. + int err;
  4403. + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
  4404. + err = ipkg_remove_pkg(conf, replacee,0);
  4405. + if (err)
  4406. + return err;
  4407. + }
  4408. + return 0;
  4409. +}
  4410. +
  4411. +/* to unwind the removal: make sure they are installed */
  4412. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4413. +{
  4414. + int i, err;
  4415. + int replaces_count = replacees->len;
  4416. + for (i = 0; i < replaces_count; i++) {
  4417. + pkg_t *replacee = replacees->pkgs[i];
  4418. + if (replacee->state_status != SS_INSTALLED) {
  4419. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4420. + err = ipkg_install_pkg(conf, replacee,0);
  4421. + if (err)
  4422. + return err;
  4423. + }
  4424. + }
  4425. + return 0;
  4426. +}
  4427. +
  4428. +int caught_sigint = 0;
  4429. +static void ipkg_install_pkg_sigint_handler(int sig)
  4430. +{
  4431. + caught_sigint = sig;
  4432. +}
  4433. +
  4434. +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
  4435. +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
  4436. +{
  4437. + if (old_pkg) {
  4438. + char message_out[15];
  4439. + char *old_version = pkg_version_str_alloc(old_pkg);
  4440. + char *new_version = pkg_version_str_alloc(pkg);
  4441. + int cmp = pkg_compare_versions(old_pkg, pkg);
  4442. + int rc = 0;
  4443. +
  4444. + memset(message_out,'\x0',15);
  4445. + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
  4446. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4447. + cmp = -1 ; /* then we force ipkg to downgrade */
  4448. + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
  4449. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4450. + }
  4451. +
  4452. + if (cmp > 0) {
  4453. + ipkg_message(conf, IPKG_NOTICE,
  4454. + "Not downgrading package %s on %s from %s to %s.\n",
  4455. + old_pkg->name, old_pkg->dest->name, old_version, new_version);
  4456. + rc = 1;
  4457. + } else if (cmp < 0) {
  4458. + ipkg_message(conf, IPKG_NOTICE,
  4459. + "%s%s on %s from %s to %s...\n",
  4460. + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
  4461. + pkg->dest = old_pkg->dest;
  4462. + rc = 0;
  4463. + } else /* cmp == 0 */ {
  4464. + if (conf->force_reinstall) {
  4465. + ipkg_message(conf, IPKG_NOTICE,
  4466. + "Reinstalling %s (%s) on %s...\n",
  4467. + pkg->name, new_version, old_pkg->dest->name);
  4468. + pkg->dest = old_pkg->dest;
  4469. + rc = 0;
  4470. + } else {
  4471. + ipkg_message(conf, IPKG_NOTICE,
  4472. + "Not installing %s (%s) on %s -- already installed.\n",
  4473. + pkg->name, new_version, old_pkg->dest->name);
  4474. + rc = 1;
  4475. + }
  4476. + }
  4477. + free(old_version);
  4478. + free(new_version);
  4479. + return rc;
  4480. + } else {
  4481. + char message_out[15], *version ;
  4482. + memset(message_out,'\x0',15);
  4483. + if ( message )
  4484. + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
  4485. + else
  4486. + strncpy( message_out,"Installing ",strlen("Installing ") );
  4487. + version = pkg_version_str_alloc(pkg);
  4488. +
  4489. + ipkg_message(conf, IPKG_NOTICE,
  4490. + "%s%s (%s) to %s...\n", message_out,
  4491. + pkg->name, version, pkg->dest->name);
  4492. + free(version);
  4493. + return 0;
  4494. + }
  4495. +}
  4496. +
  4497. +/* and now the meat... */
  4498. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
  4499. +{
  4500. + int err = 0;
  4501. + int message = 0;
  4502. + pkg_t *old_pkg = NULL;
  4503. + pkg_vec_t *replacees;
  4504. + abstract_pkg_t *ab_pkg = NULL;
  4505. + int old_state_flag;
  4506. + uint8_t *file_md5;
  4507. +
  4508. +
  4509. + if ( from_upgrade )
  4510. + message = 1; /* Coming from an upgrade, and should change the output message */
  4511. +
  4512. + if (!pkg) {
  4513. + ipkg_message(conf, IPKG_ERROR,
  4514. + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
  4515. + return -EINVAL;
  4516. + }
  4517. +
  4518. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
  4519. +
  4520. + if (!pkg_arch_supported(conf, pkg)) {
  4521. + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
  4522. + pkg->architecture, pkg->name);
  4523. + return -EINVAL;
  4524. + }
  4525. + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
  4526. + err = satisfy_dependencies_for(conf, pkg);
  4527. + if (err) { return err; }
  4528. +
  4529. + ipkg_message(conf, IPKG_NOTICE,
  4530. + "Package %s is already installed in %s.\n",
  4531. + pkg->name, pkg->dest->name);
  4532. + return 0;
  4533. + }
  4534. +
  4535. + if (pkg->dest == NULL) {
  4536. + pkg->dest = conf->default_dest;
  4537. + }
  4538. +
  4539. + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  4540. +
  4541. + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
  4542. + if (err) { return err; }
  4543. +
  4544. + pkg->state_want = SW_INSTALL;
  4545. + if (old_pkg){
  4546. + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
  4547. + }
  4548. +
  4549. +
  4550. + /* Abhaya: conflicts check */
  4551. + err = check_conflicts_for(conf, pkg);
  4552. + if (err) { return err; }
  4553. +
  4554. + /* this setup is to remove the upgrade scenario in the end when
  4555. + installing pkg A, A deps B & B deps on A. So both B and A are
  4556. + installed. Then A's installation is started resulting in an
  4557. + uncecessary upgrade */
  4558. + if (pkg->state_status == SS_INSTALLED
  4559. + && conf->force_reinstall == 0) return 0;
  4560. +
  4561. + err = verify_pkg_installable(conf, pkg);
  4562. + if (err) { return err; }
  4563. +
  4564. + if (pkg->local_filename == NULL) {
  4565. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  4566. + if (err) {
  4567. + ipkg_message(conf, IPKG_ERROR,
  4568. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  4569. + pkg->name);
  4570. + return err;
  4571. + }
  4572. + }
  4573. +
  4574. +/* Check for md5 values */
  4575. + if (pkg->md5sum)
  4576. + {
  4577. + file_md5 = file_md5sum_alloc(pkg->local_filename);
  4578. + if (strcmp((char *)file_md5, pkg->md5sum))
  4579. + {
  4580. + ipkg_message(conf, IPKG_ERROR,
  4581. + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
  4582. + pkg->name);
  4583. + free(file_md5);
  4584. + return err;
  4585. + }
  4586. + free(file_md5);
  4587. + }
  4588. +
  4589. + if (pkg->tmp_unpack_dir == NULL) {
  4590. + unpack_pkg_control_files(conf, pkg);
  4591. + }
  4592. +
  4593. + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
  4594. +/* Pigi: check if it will pass from here when replacing. It seems to fail */
  4595. +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
  4596. + err = update_file_ownership(conf, pkg, old_pkg);
  4597. + if (err) { return err; }
  4598. +
  4599. + if (conf->nodeps == 0) {
  4600. + err = satisfy_dependencies_for(conf, pkg);
  4601. + if (err) { return err; }
  4602. + }
  4603. +
  4604. + replacees = pkg_vec_alloc();
  4605. + pkg_get_installed_replacees(pkg, replacees);
  4606. +
  4607. + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
  4608. + {
  4609. + sigset_t newset, oldset;
  4610. + sighandler_t old_handler = NULL;
  4611. + int use_signal = 0;
  4612. + caught_sigint = 0;
  4613. + if (use_signal) {
  4614. + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
  4615. + } else {
  4616. + sigemptyset(&newset);
  4617. + sigaddset(&newset, SIGINT);
  4618. + sigprocmask(SIG_BLOCK, &newset, &oldset);
  4619. + }
  4620. +
  4621. + ipkg_state_changed++;
  4622. + pkg->state_flag |= SF_FILELIST_CHANGED;
  4623. +
  4624. + /* XXX: BUG: we really should treat replacement more like an upgrade
  4625. + * Instead, we're going to remove the replacees
  4626. + */
  4627. + err = pkg_remove_installed_replacees(conf, replacees);
  4628. + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
  4629. +
  4630. + /*
  4631. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  4632. + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
  4633. +
  4634. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  4635. + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
  4636. + */
  4637. +
  4638. + err = preinst_configure(conf, pkg, old_pkg);
  4639. + /*
  4640. + if (err) goto UNWIND_PREINST_CONFIGURE;
  4641. + */
  4642. +
  4643. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  4644. + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
  4645. +
  4646. + err = check_data_file_clashes(conf, pkg, old_pkg);
  4647. + /*
  4648. + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
  4649. +
  4650. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  4651. + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
  4652. + */
  4653. +
  4654. + if (conf->noaction) return 0;
  4655. +
  4656. + /* point of no return: no unwinding after this */
  4657. + if (old_pkg && !conf->force_reinstall) {
  4658. + old_pkg->state_want = SW_DEINSTALL;
  4659. +
  4660. + if (old_pkg->state_flag & SF_NOPRUNE) {
  4661. + ipkg_message(conf, IPKG_INFO,
  4662. + " not removing obsolesced files because package marked noprune\n");
  4663. + } else {
  4664. + ipkg_message(conf, IPKG_INFO,
  4665. + " removing obsolesced files\n");
  4666. + remove_obsolesced_files(conf, pkg, old_pkg);
  4667. + }
  4668. + /* removing files from old package, to avoid ghost files */
  4669. + remove_data_files_and_list(conf, old_pkg);
  4670. +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
  4671. + remove_maintainer_scripts_except_postrm(conf, old_pkg);
  4672. + remove_postrm(conf, old_pkg);
  4673. +/* Pigi */
  4674. +
  4675. + }
  4676. +
  4677. +
  4678. + ipkg_message(conf, IPKG_INFO,
  4679. + " installing maintainer scripts\n");
  4680. + install_maintainer_scripts(conf, pkg, old_pkg);
  4681. +
  4682. + /* the following just returns 0
  4683. + remove_disappeared(conf, pkg);
  4684. + */
  4685. +
  4686. + ipkg_message(conf, IPKG_INFO,
  4687. + " installing data files\n");
  4688. + install_data_files(conf, pkg);
  4689. +
  4690. +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
  4691. + err = check_data_file_clashes_change(conf, pkg);
  4692. +
  4693. + ipkg_message(conf, IPKG_INFO,
  4694. + " resolving conf files\n");
  4695. + resolve_conffiles(conf, pkg);
  4696. +
  4697. + pkg->state_status = SS_UNPACKED;
  4698. + old_state_flag = pkg->state_flag;
  4699. + pkg->state_flag &= ~SF_PREFER;
  4700. + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
  4701. +
  4702. + if (old_pkg && !conf->force_reinstall) {
  4703. + old_pkg->state_status = SS_NOT_INSTALLED;
  4704. + }
  4705. +
  4706. + time(&pkg->installed_time);
  4707. +
  4708. + ipkg_message(conf, IPKG_INFO,
  4709. + " cleanup temp files\n");
  4710. + cleanup_temporary_files(conf, pkg);
  4711. +
  4712. + ab_pkg = pkg->parent;
  4713. + if (ab_pkg)
  4714. + ab_pkg->state_status = pkg->state_status;
  4715. +
  4716. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  4717. +
  4718. + if (use_signal)
  4719. + signal(SIGINT, old_handler);
  4720. + else
  4721. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4722. +
  4723. + return 0;
  4724. +
  4725. +
  4726. + /*
  4727. + UNWIND_POSTRM_UPGRADE_OLD_PKG:
  4728. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4729. + UNWIND_CHECK_DATA_FILE_CLASHES:
  4730. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  4731. + */
  4732. + UNWIND_BACKUP_MODIFIED_CONFFILES:
  4733. + backup_modified_conffiles_unwind(pkg, old_pkg);
  4734. + /*
  4735. + UNWIND_PREINST_CONFIGURE:
  4736. + preinst_configure_unwind(conf, pkg, old_pkg);
  4737. + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
  4738. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  4739. + UNWIND_PRERM_UPGRADE_OLD_PKG:
  4740. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4741. + */
  4742. + UNWIND_REMOVE_INSTALLED_REPLACEES:
  4743. + pkg_remove_installed_replacees_unwind(conf, replacees);
  4744. +
  4745. + ipkg_message(conf, IPKG_INFO,
  4746. + " cleanup temp files\n");
  4747. + cleanup_temporary_files(conf, pkg);
  4748. +
  4749. + ipkg_message(conf, IPKG_INFO,
  4750. + "Failed.\n");
  4751. + if (use_signal)
  4752. + signal(SIGINT, old_handler);
  4753. + else
  4754. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4755. +
  4756. + return err;
  4757. + }
  4758. +}
  4759. +
  4760. +/*
  4761. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4762. +{
  4763. + DPKG_INCOMPATIBILITY:
  4764. + dpkg does some things here that we don't do yet. Do we care?
  4765. +
  4766. + 1. If a version of the package is already installed, call
  4767. + old-prerm upgrade new-version
  4768. + 2. If the script runs but exits with a non-zero exit status
  4769. + new-prerm failed-upgrade old-version
  4770. + Error unwind, for both the above cases:
  4771. + old-postinst abort-upgrade new-version
  4772. + return 0;
  4773. +}
  4774. +*/
  4775. +
  4776. +/*
  4777. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4778. +{
  4779. + DPKG_INCOMPATIBILITY:
  4780. + dpkg does some things here that we don't do yet. Do we care?
  4781. + (See prerm_upgrade_old_package for details)
  4782. +
  4783. + return 0;
  4784. +}
  4785. +*/
  4786. +
  4787. +/*
  4788. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4789. +{
  4790. + DPKG_INCOMPATIBILITY:
  4791. + dpkg does some things here that we don't do yet. Do we care?
  4792. + 2. If a 'conflicting' package is being removed at the same time:
  4793. + 1. If any packages depended on that conflicting package and
  4794. + --auto-deconfigure is specified, call, for each such package:
  4795. + deconfigured's-prerm deconfigure \
  4796. + in-favour package-being-installed version \
  4797. + removing conflicting-package version
  4798. + Error unwind:
  4799. + deconfigured's-postinst abort-deconfigure \
  4800. + in-favour package-being-installed-but-failed version \
  4801. + removing conflicting-package version
  4802. +
  4803. + The deconfigured packages are marked as requiring
  4804. + configuration, so that if --install is used they will be
  4805. + configured again if possible.
  4806. + 2. To prepare for removal of the conflicting package, call:
  4807. + conflictor's-prerm remove in-favour package new-version
  4808. + Error unwind:
  4809. + conflictor's-postinst abort-remove in-favour package new-version
  4810. + return 0;
  4811. +}
  4812. +*/
  4813. +
  4814. +/*
  4815. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4816. +{
  4817. + DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
  4818. + do yet. Do we care? (See prerm_deconfigure_conflictors for
  4819. + details)
  4820. + return 0;
  4821. +}
  4822. +*/
  4823. +
  4824. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4825. +{
  4826. + int err;
  4827. + char *preinst_args;
  4828. +
  4829. + if (old_pkg) {
  4830. + char *old_version = pkg_version_str_alloc(old_pkg);
  4831. + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
  4832. + free(old_version);
  4833. + } else if (pkg->state_status == SS_CONFIG_FILES) {
  4834. + char *pkg_version = pkg_version_str_alloc(pkg);
  4835. + sprintf_alloc(&preinst_args, "install %s", pkg_version);
  4836. + free(pkg_version);
  4837. + } else {
  4838. + preinst_args = strdup("install");
  4839. + }
  4840. +
  4841. + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
  4842. + if (err) {
  4843. + ipkg_message(conf, IPKG_ERROR,
  4844. + "Aborting installation of %s\n", pkg->name);
  4845. + return 1;
  4846. + }
  4847. +
  4848. + free(preinst_args);
  4849. +
  4850. + return 0;
  4851. +}
  4852. +
  4853. +/*
  4854. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4855. +{
  4856. + DPKG_INCOMPATIBILITY:
  4857. + dpkg does the following error unwind, should we?
  4858. + pkg->postrm abort-upgrade old-version
  4859. + OR pkg->postrm abort-install old-version
  4860. + OR pkg->postrm abort-install
  4861. + return 0;
  4862. +}
  4863. +*/
  4864. +
  4865. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4866. +{
  4867. + int err;
  4868. + conffile_list_elt_t *iter;
  4869. + conffile_t *cf;
  4870. +
  4871. + if (conf->noaction) return 0;
  4872. +
  4873. + /* Backup all modified conffiles */
  4874. + if (old_pkg) {
  4875. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4876. + char *cf_name;
  4877. +
  4878. + cf = iter->data;
  4879. + cf_name = root_filename_alloc(conf, cf->name);
  4880. +
  4881. + /* Don't worry if the conffile is just plain gone */
  4882. + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
  4883. + err = backup_make_backup(conf, cf_name);
  4884. + if (err) {
  4885. + return err;
  4886. + }
  4887. + }
  4888. + free(cf_name);
  4889. + }
  4890. + }
  4891. +
  4892. + /* Backup all conffiles that were not conffiles in old_pkg */
  4893. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4894. + char *cf_name;
  4895. + cf = iter->data;
  4896. + cf_name = root_filename_alloc(conf, cf->name);
  4897. + /* Ignore if this was a conffile in old_pkg as well */
  4898. + if (pkg_get_conffile(old_pkg, cf->name)) {
  4899. + continue;
  4900. + }
  4901. +
  4902. + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
  4903. + err = backup_make_backup(conf, cf_name);
  4904. + if (err) {
  4905. + return err;
  4906. + }
  4907. + }
  4908. + free(cf_name);
  4909. + }
  4910. +
  4911. + return 0;
  4912. +}
  4913. +
  4914. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg)
  4915. +{
  4916. + conffile_list_elt_t *iter;
  4917. +
  4918. + if (old_pkg) {
  4919. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4920. + backup_remove(iter->data->name);
  4921. + }
  4922. + }
  4923. +
  4924. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4925. + backup_remove(iter->data->name);
  4926. + }
  4927. +
  4928. + return 0;
  4929. +}
  4930. +
  4931. +
  4932. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4933. +{
  4934. + /* DPKG_INCOMPATIBILITY:
  4935. + ipkg takes a slightly different approach than dpkg at this
  4936. + point. dpkg installs each file in the new package while
  4937. + creating a backup for any file that is replaced, (so that it
  4938. + can unwind if necessary). To avoid complexity and redundant
  4939. + storage, ipkg doesn't do any installation until later, (at the
  4940. + point at which dpkg removes the backups.
  4941. +
  4942. + But, we do have to check for data file clashes, since after
  4943. + installing a package with a file clash, removing either of the
  4944. + packages involved in the clash has the potential to break the
  4945. + other package.
  4946. + */
  4947. + str_list_t *files_list;
  4948. + str_list_elt_t *iter;
  4949. +
  4950. + int clashes = 0;
  4951. +
  4952. + files_list = pkg_get_installed_files(pkg);
  4953. + for (iter = files_list->head; iter; iter = iter->next) {
  4954. + char *root_filename;
  4955. + char *filename = iter->data;
  4956. + root_filename = root_filename_alloc(conf, filename);
  4957. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  4958. + pkg_t *owner;
  4959. + pkg_t *obs;
  4960. + /* Pre-existing conffiles are OK */
  4961. + /* @@@@ should have way to check that it is a conffile -Jamey */
  4962. + if (backup_exists_for(root_filename)) {
  4963. + continue;
  4964. + }
  4965. +
  4966. + /* Pre-existing files are OK if force-overwrite was asserted. */
  4967. + if (conf->force_overwrite) {
  4968. + /* but we need to change who owns this file */
  4969. + file_hash_set_file_owner(conf, filename, pkg);
  4970. + continue;
  4971. + }
  4972. +
  4973. + owner = file_hash_get_file_owner(conf, filename);
  4974. +
  4975. + /* Pre-existing files are OK if owned by the pkg being upgraded. */
  4976. + if (owner && old_pkg) {
  4977. + if (strcmp(owner->name, old_pkg->name) == 0) {
  4978. + continue;
  4979. + }
  4980. + }
  4981. +
  4982. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  4983. + if (owner) {
  4984. + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
  4985. + if (pkg_replaces(pkg, owner)) {
  4986. + continue;
  4987. + }
  4988. +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
  4989. + then it's ok to overwrite. */
  4990. + if (strcmp(owner->name,pkg->name)==0){
  4991. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  4992. + continue;
  4993. + }
  4994. + }
  4995. +
  4996. + /* Pre-existing files are OK if they are obsolete */
  4997. + obs = hash_table_get(&conf->obs_file_hash, filename);
  4998. + if (obs) {
  4999. + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
  5000. + continue;
  5001. + }
  5002. +
  5003. + /* We have found a clash. */
  5004. + ipkg_message(conf, IPKG_ERROR,
  5005. + "Package %s wants to install file %s\n"
  5006. + "\tBut that file is already provided by package ",
  5007. + pkg->name, filename);
  5008. + if (owner) {
  5009. + ipkg_message(conf, IPKG_ERROR,
  5010. + "%s\n", owner->name);
  5011. + } else {
  5012. + ipkg_message(conf, IPKG_ERROR,
  5013. + "<no package>\nPlease move this file out of the way and try again.\n");
  5014. + }
  5015. + clashes++;
  5016. + }
  5017. + free(root_filename);
  5018. + }
  5019. + pkg_free_installed_files(pkg);
  5020. +
  5021. + return clashes;
  5022. +}
  5023. +
  5024. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg)
  5025. +{
  5026. + /* Basically that's the worst hack I could do to be able to change ownership of
  5027. + file list, but, being that we have no way to unwind the mods, due to structure
  5028. + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
  5029. + What we do here is change the ownership of file in hash if a replace ( or similar events
  5030. + happens )
  5031. + Only the action that are needed to change name should be considered.
  5032. + @@@ To change after 1.0 release.
  5033. + */
  5034. + str_list_t *files_list;
  5035. + str_list_elt_t *iter;
  5036. +
  5037. + int clashes = 0;
  5038. +
  5039. + files_list = pkg_get_installed_files(pkg);
  5040. + for (iter = files_list->head; iter; iter = iter->next) {
  5041. + char *root_filename;
  5042. + char *filename = iter->data;
  5043. + root_filename = root_filename_alloc(conf, filename);
  5044. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5045. + pkg_t *owner;
  5046. +
  5047. + if (conf->force_overwrite) {
  5048. + /* but we need to change who owns this file */
  5049. + file_hash_set_file_owner(conf, filename, pkg);
  5050. + continue;
  5051. + }
  5052. +
  5053. + owner = file_hash_get_file_owner(conf, filename);
  5054. +
  5055. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5056. + if (owner) {
  5057. + if (pkg_replaces(pkg, owner)) {
  5058. +/* It's now time to change the owner of that file.
  5059. + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
  5060. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5061. + file_hash_set_file_owner(conf, filename, pkg);
  5062. + continue;
  5063. + }
  5064. + }
  5065. +
  5066. + }
  5067. + free(root_filename);
  5068. + }
  5069. + pkg_free_installed_files(pkg);
  5070. +
  5071. + return clashes;
  5072. +}
  5073. +
  5074. +/*
  5075. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5076. +{
  5077. + Nothing to do since check_data_file_clashes doesn't change state
  5078. + return 0;
  5079. +}
  5080. +*/
  5081. +
  5082. +/*
  5083. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5084. +{
  5085. + DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
  5086. + 1. If the package is being upgraded, call
  5087. + old-postrm upgrade new-version
  5088. + 2. If this fails, attempt:
  5089. + new-postrm failed-upgrade old-version
  5090. + Error unwind, for both cases:
  5091. + old-preinst abort-upgrade new-version
  5092. + return 0;
  5093. +}
  5094. +*/
  5095. +
  5096. +/*
  5097. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5098. +{
  5099. + DPKG_INCOMPATIBILITY:
  5100. + dpkg does some things here that we don't do yet. Do we care?
  5101. + (See postrm_upgrade_old_pkg for details)
  5102. + return 0;
  5103. +}
  5104. +*/
  5105. +
  5106. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5107. +{
  5108. + int err;
  5109. + str_list_t *old_files;
  5110. + str_list_elt_t *of;
  5111. + str_list_t *new_files;
  5112. + str_list_elt_t *nf;
  5113. +
  5114. + if (old_pkg == NULL) {
  5115. + return 0;
  5116. + }
  5117. +
  5118. + old_files = pkg_get_installed_files(old_pkg);
  5119. + new_files = pkg_get_installed_files(pkg);
  5120. +
  5121. + for (of = old_files->head; of; of = of->next) {
  5122. + pkg_t *owner;
  5123. + char *old, *new;
  5124. + old = of->data;
  5125. + for (nf = new_files->head; nf; nf = nf->next) {
  5126. + new = nf->data;
  5127. + if (strcmp(old, new) == 0) {
  5128. + goto NOT_OBSOLETE;
  5129. + }
  5130. + }
  5131. + if (file_is_dir(old)) {
  5132. + continue;
  5133. + }
  5134. + owner = file_hash_get_file_owner(conf, old);
  5135. + if (owner != old_pkg) {
  5136. + /* in case obsolete file no longer belongs to old_pkg */
  5137. + continue;
  5138. + }
  5139. +
  5140. + /* old file is obsolete */
  5141. + ipkg_message(conf, IPKG_INFO,
  5142. + " removing obsolete file %s\n", old);
  5143. + if (!conf->noaction) {
  5144. + err = unlink(old);
  5145. + if (err) {
  5146. + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
  5147. + strerror(errno));
  5148. + }
  5149. + }
  5150. +
  5151. + NOT_OBSOLETE:
  5152. + ;
  5153. + }
  5154. +
  5155. + pkg_free_installed_files(old_pkg);
  5156. + pkg_free_installed_files(pkg);
  5157. +
  5158. + return 0;
  5159. +}
  5160. +
  5161. +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5162. +{
  5163. + int i;
  5164. + int err = 0;
  5165. + char *globpattern;
  5166. + glob_t globbuf;
  5167. + if (0) {
  5168. + if (!pkg->dest) {
  5169. + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
  5170. + return -1;
  5171. + }
  5172. + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
  5173. + err = glob(globpattern, 0, NULL, &globbuf);
  5174. + free(globpattern);
  5175. + if (err) {
  5176. + return err;
  5177. + }
  5178. + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
  5179. + for (i = 0; i < globbuf.gl_pathc; i++) {
  5180. + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
  5181. + globbuf.gl_pathv[i], old_pkg->name);
  5182. + if (!conf->noaction)
  5183. + unlink(globbuf.gl_pathv[i]);
  5184. + }
  5185. + globfree(&globbuf);
  5186. + }
  5187. + return err;
  5188. +}
  5189. +
  5190. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5191. +{
  5192. + int ret;
  5193. + char *prefix;
  5194. +
  5195. + if (old_pkg)
  5196. + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
  5197. + sprintf_alloc(&prefix, "%s.", pkg->name);
  5198. + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
  5199. + pkg->dest->info_dir,
  5200. + prefix);
  5201. + free(prefix);
  5202. + return ret;
  5203. +}
  5204. +
  5205. +/*
  5206. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
  5207. +{
  5208. + DPKG_INCOMPATIBILITY:
  5209. + This is a fairly sophisticated dpkg operation. Shall we
  5210. + skip it?
  5211. +
  5212. + Any packages all of whose files have been overwritten during the
  5213. + installation, and which aren't required for dependencies, are
  5214. + considered to have been removed. For each such package
  5215. + 1. disappearer's-postrm disappear overwriter overwriter-version
  5216. + 2. The package's maintainer scripts are removed
  5217. + 3. It is noted in the status database as being in a sane state,
  5218. + namely not installed (any conffiles it may have are ignored,
  5219. + rather than being removed by dpkg). Note that disappearing
  5220. + packages do not have their prerm called, because dpkg doesn't
  5221. + know in advance that the package is going to vanish.
  5222. +
  5223. +
  5224. + return 0;
  5225. +}
  5226. +*/
  5227. +
  5228. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
  5229. +{
  5230. + int err;
  5231. +
  5232. + /* ipkg takes a slightly different approach to data file backups
  5233. + than dpkg. Rather than removing backups at this point, we
  5234. + actually do the data file installation now. See comments in
  5235. + check_data_file_clashes() for more details. */
  5236. +
  5237. + ipkg_message(conf, IPKG_INFO,
  5238. + " extracting data files to %s\n", pkg->dest->root_dir);
  5239. + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
  5240. + if (err) {
  5241. + return err;
  5242. + }
  5243. +
  5244. + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
  5245. + so we can't save ourself from removing important packages
  5246. + At this point we (should) have extracted the .control file, so it
  5247. + would be a good idea to reload the data in it, and set the Essential
  5248. + state in *pkg. From now on the Essential is back in status file and
  5249. + we can protect again.
  5250. + We should operate this way:
  5251. + fopen the file ( pkg->dest->root_dir/pkg->name.control )
  5252. + check for "Essential" in it
  5253. + set the value in pkg->essential.
  5254. + This new routine could be useful also for every other flag
  5255. + Pigi: 16/03/2004 */
  5256. + set_flags_from_control(conf, pkg) ;
  5257. +
  5258. + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
  5259. + err = pkg_write_filelist(conf, pkg);
  5260. + if (err)
  5261. + return err;
  5262. +
  5263. + /* XXX: FEATURE: ipkg should identify any files which existed
  5264. + before installation and which were overwritten, (see
  5265. + check_data_file_clashes()). What it must do is remove any such
  5266. + files from the filelist of the old package which provided the
  5267. + file. Otherwise, if the old package were removed at some point
  5268. + it would break the new package. Removing the new package will
  5269. + also break the old one, but this cannot be helped since the old
  5270. + package's file has already been deleted. This is the importance
  5271. + of check_data_file_clashes(), and only allowing ipkg to install
  5272. + a clashing package with a user force. */
  5273. +
  5274. + return 0;
  5275. +}
  5276. +
  5277. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
  5278. +{
  5279. + conffile_list_elt_t *iter;
  5280. + conffile_t *cf;
  5281. + char *cf_backup;
  5282. + uint8_t *md5sum;
  5283. +
  5284. +
  5285. + if (conf->noaction) return 0;
  5286. +
  5287. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  5288. + char *root_filename;
  5289. + cf = iter->data;
  5290. + root_filename = root_filename_alloc(conf, cf->name);
  5291. +
  5292. + /* Might need to initialize the md5sum for each conffile */
  5293. + if (cf->value == NULL) {
  5294. + cf->value = (char *)file_md5sum_alloc(root_filename);
  5295. + }
  5296. +
  5297. + if (!file_exists(root_filename)) {
  5298. + free(root_filename);
  5299. + continue;
  5300. + }
  5301. +
  5302. + cf_backup = backup_filename_alloc(root_filename);
  5303. +
  5304. +
  5305. + if (file_exists(cf_backup)) {
  5306. + /* Let's compute md5 to test if files are changed */
  5307. + md5sum = file_md5sum_alloc(cf_backup);
  5308. + if (strcmp( cf->value, (char *)md5sum) != 0 ) {
  5309. + if (conf->force_defaults
  5310. + || user_prefers_old_conffile(cf->name, cf_backup) ) {
  5311. + rename(cf_backup, root_filename);
  5312. + }
  5313. + }
  5314. + unlink(cf_backup);
  5315. + free(md5sum);
  5316. + }
  5317. +
  5318. + free(cf_backup);
  5319. + free(root_filename);
  5320. + }
  5321. +
  5322. + return 0;
  5323. +}
  5324. +
  5325. +static int user_prefers_old_conffile(const char *file_name, const char *backup)
  5326. +{
  5327. + char *response;
  5328. + const char *short_file_name;
  5329. +
  5330. + short_file_name = strrchr(file_name, '/');
  5331. + if (short_file_name) {
  5332. + short_file_name++;
  5333. + } else {
  5334. + short_file_name = file_name;
  5335. + }
  5336. +
  5337. + while (1) {
  5338. + response = get_user_response(" Configuration file '%s'\n"
  5339. + " ==> File on system created by you or by a script.\n"
  5340. + " ==> File also in package provided by package maintainer.\n"
  5341. + " What would you like to do about it ? Your options are:\n"
  5342. + " Y or I : install the package maintainer's version\n"
  5343. + " N or O : keep your currently-installed version\n"
  5344. +#ifdef CONFIG_DIFF
  5345. + " D : show the differences between the versions\n"
  5346. +#endif
  5347. + " The default action is to keep your current version.\n"
  5348. + " *** %s (Y/I/N/O"
  5349. +#ifdef CONFIG_DIFF
  5350. + "/D"
  5351. +#endif
  5352. + ") [default=N] ? ", file_name, short_file_name);
  5353. + if (strcmp(response, "y") == 0
  5354. + || strcmp(response, "i") == 0
  5355. + || strcmp(response, "yes") == 0) {
  5356. + free(response);
  5357. + return 0;
  5358. + }
  5359. +
  5360. +#ifdef CONFIG_DIFF
  5361. + if (strcmp(response, "d") == 0) {
  5362. + char *cmd;
  5363. +
  5364. + free(response);
  5365. + /* XXX: BUG rewrite to use exec or busybox's internal diff */
  5366. + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
  5367. + xsystem(cmd);
  5368. + free(cmd);
  5369. + printf(" [Press ENTER to continue]\n");
  5370. + response = file_read_line_alloc(stdin);
  5371. + free(response);
  5372. + continue;
  5373. + }
  5374. +#endif
  5375. +
  5376. + free(response);
  5377. + return 1;
  5378. + }
  5379. +}
  5380. +
  5381. +/* XXX: CLEANUP: I'd like to move all of the code for
  5382. + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
  5383. + it would make sense to cleanup pkg->tmp_unpack_dir directly from
  5384. + pkg_deinit for example). */
  5385. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
  5386. +{
  5387. + DIR *tmp_dir;
  5388. + struct dirent *dirent;
  5389. + char *tmp_file;
  5390. +
  5391. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  5392. +#error
  5393. + ipkg_message(conf, IPKG_DEBUG,
  5394. + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  5395. + __FUNCTION__, pkg->tmp_unpack_dir);
  5396. + return 0;
  5397. +#endif
  5398. +
  5399. + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
  5400. + tmp_dir = opendir(pkg->tmp_unpack_dir);
  5401. + if (tmp_dir) {
  5402. + while (1) {
  5403. + dirent = readdir(tmp_dir);
  5404. + if (dirent == NULL) {
  5405. + break;
  5406. + }
  5407. + sprintf_alloc(&tmp_file, "%s/%s",
  5408. + pkg->tmp_unpack_dir, dirent->d_name);
  5409. + if (! file_is_dir(tmp_file)) {
  5410. + unlink(tmp_file);
  5411. + }
  5412. + free(tmp_file);
  5413. + }
  5414. + closedir(tmp_dir);
  5415. + rmdir(pkg->tmp_unpack_dir);
  5416. + free(pkg->tmp_unpack_dir);
  5417. + pkg->tmp_unpack_dir = NULL;
  5418. + }
  5419. + }
  5420. +
  5421. + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
  5422. + pkg->name, pkg->local_filename, conf->tmp_dir);
  5423. + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
  5424. + unlink(pkg->local_filename);
  5425. + free(pkg->local_filename);
  5426. + pkg->local_filename = NULL;
  5427. + }
  5428. +
  5429. + return 0;
  5430. +}
  5431. +
  5432. +static char *backup_filename_alloc(const char *file_name)
  5433. +{
  5434. + char *backup;
  5435. +
  5436. + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
  5437. +
  5438. + return backup;
  5439. +}
  5440. +
  5441. +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
  5442. +{
  5443. + int err;
  5444. + char *backup;
  5445. +
  5446. + backup = backup_filename_alloc(file_name);
  5447. + err = file_copy(file_name, backup);
  5448. + if (err) {
  5449. + ipkg_message(conf, IPKG_ERROR,
  5450. + "%s: Failed to copy %s to %s\n",
  5451. + __FUNCTION__, file_name, backup);
  5452. + }
  5453. +
  5454. + free(backup);
  5455. +
  5456. + return err;
  5457. +}
  5458. +
  5459. +static int backup_exists_for(const char *file_name)
  5460. +{
  5461. + int ret;
  5462. + char *backup;
  5463. +
  5464. + backup = backup_filename_alloc(file_name);
  5465. +
  5466. + ret = file_exists(backup);
  5467. +
  5468. + free(backup);
  5469. +
  5470. + return ret;
  5471. +}
  5472. +
  5473. +static int backup_remove(const char *file_name)
  5474. +{
  5475. + char *backup;
  5476. +
  5477. + backup = backup_filename_alloc(file_name);
  5478. + unlink(backup);
  5479. + free(backup);
  5480. +
  5481. + return 0;
  5482. +}
  5483. +
  5484. +
  5485. +
  5486. +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
  5487. +
  5488. +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
  5489. +{
  5490. + /* first, remove the packages that need removing */
  5491. + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
  5492. + pkg_t *pkg = pkgs_to_remove->pkgs[i];
  5493. + err = ipkg_remove_pkg(conf, pkg,0);
  5494. + if (err) return err;
  5495. + }
  5496. + return 0;
  5497. +}
  5498. +
  5499. +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)
  5500. +{
  5501. + int i;
  5502. + /* now one more pass checking on the ones that need to be installed */
  5503. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5504. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5505. + if (pkg->dest == NULL)
  5506. + pkg->dest = conf->default_dest;
  5507. +
  5508. + pkg->state_want = SW_INSTALL;
  5509. +
  5510. + /* Abhaya: conflicts check */
  5511. + err = check_conflicts_for(conf, pkg);
  5512. + if (err) { return err; }
  5513. + }
  5514. + return 0;
  5515. +}
  5516. +
  5517. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5518. +{
  5519. + int i;
  5520. + /* now one more pass checking on the ones that need to be installed */
  5521. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5522. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5523. +
  5524. + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
  5525. + pkg_vec_t *replacees = pkg_vec_alloc();
  5526. + pkg_get_installed_replacees(pkg, replacees);
  5527. +
  5528. + /* XXX: BUG: we really should treat replacement more like an upgrade
  5529. + * Instead, we're going to remove the replacees
  5530. + */
  5531. + err = pkg_remove_installed_replacees(conf, replacees);
  5532. + if (err) return err;
  5533. + pkg->state_flag |= SF_REMOVED_REPLACEES;
  5534. + }
  5535. + return 0;
  5536. +}
  5537. +
  5538. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5539. +{
  5540. + int i;
  5541. + /* now one more pass checking on the ones that need to be installed */
  5542. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5543. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5544. + if (pkg->local_filename == NULL) {
  5545. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  5546. + if (err) {
  5547. + ipkg_message(conf, IPKG_ERROR,
  5548. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  5549. + pkg->name);
  5550. + return err;
  5551. + }
  5552. + }
  5553. + if (pkg->tmp_unpack_dir == NULL) {
  5554. + err = unpack_pkg_control_files(conf, pkg);
  5555. + if (err) return err;
  5556. + }
  5557. + }
  5558. + return 0;
  5559. +}
  5560. +
  5561. +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5562. +{
  5563. + int i;
  5564. + /* now one more pass checking on the ones that need to be installed */
  5565. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5566. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5567. + pkg_t *old_pkg = pkg->old_pkg;
  5568. +
  5569. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  5570. + if (err) return err;
  5571. +
  5572. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  5573. + if (err) return err;
  5574. +
  5575. + err = preinst_configure(conf, pkg, old_pkg);
  5576. + if (err) return err;
  5577. +
  5578. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  5579. + if (err) return err;
  5580. +
  5581. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  5582. + if (err) return err;
  5583. + }
  5584. + return 0;
  5585. +}
  5586. +
  5587. +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5588. +{
  5589. + int i;
  5590. + /* now one more pass checking on the ones that need to be installed */
  5591. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5592. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5593. + pkg_t *old_pkg = pkg->old_pkg;
  5594. +
  5595. + if (old_pkg) {
  5596. + old_pkg->state_want = SW_DEINSTALL;
  5597. +
  5598. + if (old_pkg->state_flag & SF_NOPRUNE) {
  5599. + ipkg_message(conf, IPKG_INFO,
  5600. + " not removing obsolesced files because package marked noprune\n");
  5601. + } else {
  5602. + ipkg_message(conf, IPKG_INFO,
  5603. + " removing obsolesced files\n");
  5604. + remove_obsolesced_files(conf, pkg, old_pkg);
  5605. + }
  5606. + }
  5607. +
  5608. + ipkg_message(conf, IPKG_INFO,
  5609. + " installing maintainer scripts\n");
  5610. + install_maintainer_scripts(conf, pkg, old_pkg);
  5611. +
  5612. + /* the following just returns 0 */
  5613. + remove_disappeared(conf, pkg);
  5614. +
  5615. + ipkg_message(conf, IPKG_INFO,
  5616. + " installing data files\n");
  5617. + install_data_files(conf, pkg);
  5618. +
  5619. + ipkg_message(conf, IPKG_INFO,
  5620. + " resolving conf files\n");
  5621. + resolve_conffiles(conf, pkg);
  5622. +
  5623. + pkg->state_status = SS_UNPACKED;
  5624. +
  5625. + if (old_pkg) {
  5626. + old_pkg->state_status = SS_NOT_INSTALLED;
  5627. + }
  5628. +
  5629. + time(&pkg->installed_time);
  5630. +
  5631. + ipkg_message(conf, IPKG_INFO,
  5632. + " cleanup temp files\n");
  5633. + cleanup_temporary_files(conf, pkg);
  5634. +
  5635. + if (pkg->parent)
  5636. + pkg->parent->state_status = pkg->state_status;
  5637. + }
  5638. + return 0;
  5639. +}
  5640. +
  5641. +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5642. +{
  5643. + int i;
  5644. + /* now one more pass checking on the ones that need to be installed */
  5645. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5646. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5647. + pkg_t *old_pkg = pkg->old_pkg;
  5648. +
  5649. + if (old_pkg) {
  5650. + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
  5651. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5652. + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
  5653. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  5654. + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
  5655. + backup_modified_conffiles_unwind(pkg, old_pkg);
  5656. + */
  5657. + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
  5658. + preinst_configure_unwind(conf, pkg, old_pkg);
  5659. + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
  5660. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  5661. + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
  5662. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5663. + */
  5664. +
  5665. + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
  5666. + remove_installed_replacees_unwind(conf, pkg, old_pkg);
  5667. +
  5668. + }
  5669. + }
  5670. + return 0;
  5671. +}
  5672. +
  5673. +/*
  5674. + * Perform all the actions.
  5675. + *
  5676. + * pkgs_to_remove are packages marked for removal.
  5677. + * pkgs_superseded are the old packages being replaced by upgrades.
  5678. + *
  5679. + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
  5680. + */
  5681. +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)
  5682. +{
  5683. + int err;
  5684. + int i;
  5685. +
  5686. + err = ipkg_remove_packages(conf, pkgs_to_remove);
  5687. + if (err) return err;
  5688. +
  5689. + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
  5690. + if (err) return err;
  5691. +
  5692. + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
  5693. + if (err) goto UNWIND;
  5694. +
  5695. + /* @@@@ look at ipkg_install_pkg for handling replacements */
  5696. + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
  5697. + if (err) goto UNWIND;
  5698. +
  5699. + /*
  5700. + * Now that we have the packages unpacked, we can look for data
  5701. + * file clashes. First, we mark the files from the superseded
  5702. + * packages as obsolete. Then we scan the files in
  5703. + * pkgs_to_install, and only complain about clashes with
  5704. + * non-obsolete files.
  5705. + */
  5706. +
  5707. + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
  5708. + if (err) goto UNWIND;
  5709. +
  5710. + /* this was before checking data file clashes */
  5711. + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
  5712. + if (err) goto UNWIND;
  5713. +
  5714. + /* point of no return: no unwinding after this */
  5715. + err = ipkg_process_actions_install(conf, pkgs_to_install);
  5716. + if (err) return err;
  5717. +
  5718. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  5719. + return 0;
  5720. +
  5721. + UNWIND:
  5722. + ipkg_process_actions_unwind(conf, pkgs_to_install);
  5723. +
  5724. + ipkg_message(conf, IPKG_INFO,
  5725. + " cleanup temp files\n");
  5726. + cleanup_temporary_files(conf, pkg);
  5727. +
  5728. + ipkg_message(conf, IPKG_INFO,
  5729. + "Failed.\n");
  5730. + return err;
  5731. +}
  5732. +
  5733. +#endif
  5734. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_install.h busybox-1.15.2/archival/libipkg/ipkg_install.h
  5735. --- busybox-1.15.2.orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
  5736. +++ busybox-1.15.2/archival/libipkg/ipkg_install.h 2010-03-14 20:53:41.000000000 +0100
  5737. @@ -0,0 +1,35 @@
  5738. +/* ipkg_install.h - the itsy package management system
  5739. +
  5740. + Carl D. Worth
  5741. +
  5742. + Copyright (C) 2001 University of Southern California
  5743. +
  5744. + This program is free software; you can redistribute it and/or
  5745. + modify it under the terms of the GNU General Public License as
  5746. + published by the Free Software Foundation; either version 2, or (at
  5747. + your option) any later version.
  5748. +
  5749. + This program is distributed in the hope that it will be useful, but
  5750. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5751. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5752. + General Public License for more details.
  5753. +*/
  5754. +
  5755. +#ifndef IPKG_INSTALL_H
  5756. +#define IPKG_INSTALL_H
  5757. +
  5758. +#include "pkg.h"
  5759. +#include "ipkg_conf.h"
  5760. +
  5761. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5762. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5763. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
  5764. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
  5765. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  5766. +
  5767. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
  5768. +
  5769. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
  5770. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
  5771. +
  5772. +#endif
  5773. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_message.c busybox-1.15.2/archival/libipkg/ipkg_message.c
  5774. --- busybox-1.15.2.orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
  5775. +++ busybox-1.15.2/archival/libipkg/ipkg_message.c 2010-03-14 20:57:51.000000000 +0100
  5776. @@ -0,0 +1,35 @@
  5777. +/* ipkg_message.c - the itsy package management system
  5778. +
  5779. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5780. +
  5781. + This program is free software; you can redistribute it and/or
  5782. + modify it under the terms of the GNU General Public License as
  5783. + published by the Free Software Foundation; either version 2, or (at
  5784. + your option) any later version.
  5785. +
  5786. + This program is distributed in the hope that it will be useful, but
  5787. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5788. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5789. + General Public License for more details.
  5790. +*/
  5791. +
  5792. +
  5793. +#include "ipkg.h"
  5794. +#include "ipkg_conf.h"
  5795. +#include "ipkg_message.h"
  5796. +#include "libipkg.h"
  5797. +
  5798. +void
  5799. +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
  5800. +{
  5801. + va_list ap;
  5802. + char ts[256];
  5803. +
  5804. + if (ipkg_cb_message)
  5805. + {
  5806. + va_start (ap, fmt);
  5807. + vsnprintf (ts,256,fmt, ap);
  5808. + va_end (ap);
  5809. + ipkg_cb_message(conf,level,ts);
  5810. + }
  5811. +}
  5812. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_message.h busybox-1.15.2/archival/libipkg/ipkg_message.h
  5813. --- busybox-1.15.2.orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
  5814. +++ busybox-1.15.2/archival/libipkg/ipkg_message.h 2010-03-14 20:53:41.000000000 +0100
  5815. @@ -0,0 +1,32 @@
  5816. +/* ipkg_message.h - the itsy package management system
  5817. +
  5818. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5819. +
  5820. + This program is free software; you can redistribute it and/or
  5821. + modify it under the terms of the GNU General Public License as
  5822. + published by the Free Software Foundation; either version 2, or (at
  5823. + your option) any later version.
  5824. +
  5825. + This program is distributed in the hope that it will be useful, but
  5826. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5827. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5828. + General Public License for more details.
  5829. +*/
  5830. +
  5831. +#ifndef _IPKG_MESSAGE_H_
  5832. +#define _IPKG_MESSAGE_H_
  5833. +
  5834. +#include "ipkg.h"
  5835. +#include "ipkg_conf.h"
  5836. +
  5837. +typedef enum {
  5838. + IPKG_ERROR, /* error conditions */
  5839. + IPKG_NOTICE, /* normal but significant condition */
  5840. + IPKG_INFO, /* informational message */
  5841. + IPKG_DEBUG, /* debug level message */
  5842. + IPKG_DEBUG2, /* more debug level message */
  5843. +} message_level_t;
  5844. +
  5845. +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
  5846. +
  5847. +#endif /* _IPKG_MESSAGE_H_ */
  5848. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_remove.c busybox-1.15.2/archival/libipkg/ipkg_remove.c
  5849. --- busybox-1.15.2.orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
  5850. +++ busybox-1.15.2/archival/libipkg/ipkg_remove.c 2010-03-14 20:53:41.000000000 +0100
  5851. @@ -0,0 +1,385 @@
  5852. +/* ipkg_remove.c - the itsy package management system
  5853. +
  5854. + Carl D. Worth
  5855. +
  5856. + Copyright (C) 2001 University of Southern California
  5857. +
  5858. + This program is free software; you can redistribute it and/or
  5859. + modify it under the terms of the GNU General Public License as
  5860. + published by the Free Software Foundation; either version 2, or (at
  5861. + your option) any later version.
  5862. +
  5863. + This program is distributed in the hope that it will be useful, but
  5864. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5865. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5866. + General Public License for more details.
  5867. +*/
  5868. +
  5869. +#include "ipkg.h"
  5870. +#include "ipkg_message.h"
  5871. +
  5872. +#include <glob.h>
  5873. +
  5874. +#include "ipkg_remove.h"
  5875. +
  5876. +#include "file_util.h"
  5877. +#include "sprintf_alloc.h"
  5878. +#include "str_util.h"
  5879. +
  5880. +#include "ipkg_cmd.h"
  5881. +
  5882. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents);
  5883. +
  5884. +/*
  5885. + * Returns number of the number of packages depending on the packages provided by this package.
  5886. + * Every package implicitly provides itself.
  5887. + */
  5888. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents)
  5889. +{
  5890. + int nprovides = pkg->provides_count;
  5891. + abstract_pkg_t **provides = pkg->provides;
  5892. + int n_installed_dependents = 0;
  5893. + int i;
  5894. + for (i = 0; i <= nprovides; i++) {
  5895. + abstract_pkg_t *providee = provides[i];
  5896. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5897. + abstract_pkg_t *dep_ab_pkg;
  5898. + if (dependers == NULL)
  5899. + continue;
  5900. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5901. + if (dep_ab_pkg->state_status == SS_INSTALLED){
  5902. + n_installed_dependents++;
  5903. + }
  5904. + }
  5905. +
  5906. + }
  5907. + /* if caller requested the set of installed dependents */
  5908. + if (pdependents) {
  5909. + int p = 0;
  5910. + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
  5911. +
  5912. + if ( dependents == NULL ){
  5913. + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
  5914. + return -1;
  5915. + }
  5916. +
  5917. + *pdependents = dependents;
  5918. + for (i = 0; i <= nprovides; i++) {
  5919. + abstract_pkg_t *providee = provides[i];
  5920. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5921. + abstract_pkg_t *dep_ab_pkg;
  5922. + if (dependers == NULL)
  5923. + continue;
  5924. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5925. + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
  5926. + dependents[p++] = dep_ab_pkg;
  5927. + dep_ab_pkg->state_flag |= SF_MARKED;
  5928. + }
  5929. + }
  5930. + }
  5931. + dependents[p] = NULL;
  5932. + /* now clear the marks */
  5933. + for (i = 0; i < p; i++) {
  5934. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5935. + dep_ab_pkg->state_flag &= ~SF_MARKED;
  5936. + }
  5937. + }
  5938. + return n_installed_dependents;
  5939. +}
  5940. +
  5941. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5942. +{
  5943. + int i;
  5944. + int a;
  5945. + int count;
  5946. + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
  5947. + abstract_pkg_t * ab_pkg;
  5948. +
  5949. + if((ab_pkg = pkg->parent) == NULL){
  5950. + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
  5951. + __FUNCTION__, pkg->name);
  5952. + return 0;
  5953. + }
  5954. +
  5955. + if (dependents == NULL)
  5956. + return 0;
  5957. +
  5958. + // here i am using the dependencies_checked
  5959. + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
  5960. + return 0; // has already been encountered in the process
  5961. + // of marking packages for removal - Karthik
  5962. + ab_pkg->dependencies_checked = 2;
  5963. +
  5964. + i = 0;
  5965. + count = 1;
  5966. + while (dependents [i] != NULL) {
  5967. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5968. +
  5969. + if (dep_ab_pkg->dependencies_checked == 2){
  5970. + i++;
  5971. + continue;
  5972. + }
  5973. + if (dep_ab_pkg->state_status == SS_INSTALLED) {
  5974. + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
  5975. + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
  5976. + if (dep_pkg->state_status == SS_INSTALLED) {
  5977. + pkg_vec_insert(dependent_pkgs, dep_pkg);
  5978. + count++;
  5979. + }
  5980. + }
  5981. + }
  5982. + i++;
  5983. + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
  5984. + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
  5985. + }
  5986. +
  5987. + if (count == 1)
  5988. + return 0;
  5989. +
  5990. +
  5991. + for (i = 0; i < dependent_pkgs->len; i++) {
  5992. + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
  5993. + if (err)
  5994. + return err;
  5995. + }
  5996. + return 0;
  5997. +}
  5998. +
  5999. +static int user_prefers_removing_dependents(ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  6000. +{
  6001. + abstract_pkg_t *dep_ab_pkg;
  6002. + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
  6003. + while ((dep_ab_pkg = *dependents++) != NULL) {
  6004. + if (dep_ab_pkg->state_status == SS_INSTALLED)
  6005. + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
  6006. + }
  6007. + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
  6008. + ipkg_message(conf, IPKG_ERROR, "");
  6009. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
  6010. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
  6011. + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
  6012. + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
  6013. + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
  6014. + return 0;
  6015. +}
  6016. +
  6017. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
  6018. +{
  6019. +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
  6020. + thus I wan't check for essential, as I'm upgrading.
  6021. + I hope it won't break anything :)
  6022. +*/
  6023. + int err;
  6024. + abstract_pkg_t *parent_pkg = NULL;
  6025. +
  6026. + if (pkg->essential && !message) {
  6027. + if (conf->force_removal_of_essential_packages) {
  6028. + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
  6029. + "\tIf your system breaks, you get to keep both pieces\n",
  6030. + pkg->name);
  6031. + } else {
  6032. + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
  6033. + "\tRemoving an essential package may lead to an unusable system, but if\n"
  6034. + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
  6035. + "\tits will with the option: -force-removal-of-essential-packages\n",
  6036. + pkg->name);
  6037. + return IPKG_PKG_IS_ESSENTIAL;
  6038. + }
  6039. + }
  6040. +
  6041. + if ((parent_pkg = pkg->parent) == NULL)
  6042. + return 0;
  6043. +
  6044. + /* only attempt to remove dependent installed packages if
  6045. + * force_depends is not specified or the package is being
  6046. + * replaced.
  6047. + */
  6048. + if (!conf->force_depends
  6049. + && !(pkg->state_flag & SF_REPLACE)) {
  6050. + abstract_pkg_t **dependents;
  6051. + int has_installed_dependents =
  6052. + pkg_has_installed_dependents(pkg, &dependents);
  6053. +
  6054. + if (has_installed_dependents) {
  6055. + /*
  6056. + * if this package is depended up by others, then either we should
  6057. + * not remove it or we should remove it and all of its dependents
  6058. + */
  6059. +
  6060. + if (!conf->force_removal_of_dependent_packages
  6061. + && !user_prefers_removing_dependents(conf, pkg, dependents)) {
  6062. + return IPKG_PKG_HAS_DEPENDENTS;
  6063. + }
  6064. +
  6065. + /* remove packages depending on this package - Karthik */
  6066. + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
  6067. + free(dependents);
  6068. + if (err) return err;
  6069. + }
  6070. + }
  6071. +
  6072. + if ( message==0 ){
  6073. + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
  6074. + fflush(stdout);
  6075. + }
  6076. + pkg->state_flag |= SF_FILELIST_CHANGED;
  6077. +
  6078. + pkg->state_want = SW_DEINSTALL;
  6079. + ipkg_state_changed++;
  6080. +
  6081. + pkg_run_script(conf, pkg, "prerm", "remove");
  6082. +
  6083. + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
  6084. + maintains an empty filelist rather than deleting it. That seems
  6085. + like a big pain, and I don't see that that should make a big
  6086. + difference, but for anyone who wants tighter compatibility,
  6087. + feel free to fix this. */
  6088. + remove_data_files_and_list(conf, pkg);
  6089. +
  6090. + pkg_run_script(conf, pkg, "postrm", "remove");
  6091. +
  6092. + remove_maintainer_scripts_except_postrm(conf, pkg);
  6093. +
  6094. + /* Aman Gupta - Since ipkg is made for handheld devices with limited
  6095. + * space, it doesn't make sense to leave extra configurations, files,
  6096. + * and maintainer scripts left around. So, we make remove like purge,
  6097. + * and take out all the crap :) */
  6098. +
  6099. + remove_postrm(conf, pkg);
  6100. + pkg->state_status = SS_NOT_INSTALLED;
  6101. +
  6102. + if (parent_pkg)
  6103. + parent_pkg->state_status = SS_NOT_INSTALLED;
  6104. +
  6105. + return 0;
  6106. +}
  6107. +
  6108. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
  6109. +{
  6110. + ipkg_remove_pkg(conf, pkg,0);
  6111. + return 0;
  6112. +}
  6113. +
  6114. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
  6115. +{
  6116. + str_list_t installed_dirs;
  6117. + str_list_t *installed_files;
  6118. + str_list_elt_t *iter;
  6119. + char *file_name;
  6120. + conffile_t *conffile;
  6121. + int removed_a_dir;
  6122. + pkg_t *owner;
  6123. +
  6124. + str_list_init(&installed_dirs);
  6125. + installed_files = pkg_get_installed_files(pkg);
  6126. +
  6127. + for (iter = installed_files->head; iter; iter = iter->next) {
  6128. + file_name = iter->data;
  6129. +
  6130. + if (file_is_dir(file_name)) {
  6131. + str_list_append(&installed_dirs, strdup(file_name));
  6132. + continue;
  6133. + }
  6134. +
  6135. + conffile = pkg_get_conffile(pkg, file_name);
  6136. + if (conffile) {
  6137. + /* XXX: QUESTION: Is this right? I figure we only need to
  6138. + save the conffile if it has been modified. Is that what
  6139. + dpkg does? Or does dpkg preserve all conffiles? If so,
  6140. + this seems like a better thing to do to conserve
  6141. + space. */
  6142. + if (conffile_has_been_modified(conf, conffile)) {
  6143. + printf(" not deleting modified conffile %s\n", file_name);
  6144. + fflush(stdout);
  6145. + continue;
  6146. + }
  6147. + }
  6148. +
  6149. + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
  6150. + if (!conf->noaction)
  6151. + unlink(file_name);
  6152. + }
  6153. +
  6154. + if (!conf->noaction) {
  6155. + do {
  6156. + removed_a_dir = 0;
  6157. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6158. + file_name = iter->data;
  6159. +
  6160. + if (rmdir(file_name) == 0) {
  6161. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
  6162. + removed_a_dir = 1;
  6163. + str_list_remove(&installed_dirs, &iter);
  6164. + }
  6165. + }
  6166. + } while (removed_a_dir);
  6167. + }
  6168. +
  6169. + pkg_free_installed_files(pkg);
  6170. + /* We have to remove the file list now, so that
  6171. + find_pkg_owning_file does not always just report this package */
  6172. + pkg_remove_installed_files_list(conf, pkg);
  6173. +
  6174. + /* Don't print warning for dirs that are provided by other packages */
  6175. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6176. + file_name = iter->data;
  6177. +
  6178. + owner = file_hash_get_file_owner(conf, file_name);
  6179. + if (owner) {
  6180. + free(iter->data);
  6181. + iter->data = NULL;
  6182. + str_list_remove(&installed_dirs, &iter);
  6183. + }
  6184. + }
  6185. +
  6186. + /* cleanup */
  6187. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6188. + free(iter->data);
  6189. + iter->data = NULL;
  6190. + }
  6191. + str_list_deinit(&installed_dirs);
  6192. +
  6193. + return 0;
  6194. +}
  6195. +
  6196. +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6197. +{
  6198. + int i, err;
  6199. + char *globpattern;
  6200. + glob_t globbuf;
  6201. +
  6202. + if (conf->noaction) return 0;
  6203. +
  6204. + sprintf_alloc(&globpattern, "%s/%s.*",
  6205. + pkg->dest->info_dir, pkg->name);
  6206. + err = glob(globpattern, 0, NULL, &globbuf);
  6207. + free(globpattern);
  6208. + if (err) {
  6209. + return 0;
  6210. + }
  6211. +
  6212. + for (i = 0; i < globbuf.gl_pathc; i++) {
  6213. + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
  6214. + continue;
  6215. + }
  6216. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
  6217. + unlink(globbuf.gl_pathv[i]);
  6218. + }
  6219. + globfree(&globbuf);
  6220. +
  6221. + return 0;
  6222. +}
  6223. +
  6224. +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6225. +{
  6226. + char *postrm_file_name;
  6227. +
  6228. + if (conf->noaction) return 0;
  6229. +
  6230. + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
  6231. + pkg->dest->info_dir, pkg->name);
  6232. + unlink(postrm_file_name);
  6233. + free(postrm_file_name);
  6234. +
  6235. + return 0;
  6236. +}
  6237. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_remove.h busybox-1.15.2/archival/libipkg/ipkg_remove.h
  6238. --- busybox-1.15.2.orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
  6239. +++ busybox-1.15.2/archival/libipkg/ipkg_remove.h 2010-03-14 20:53:41.000000000 +0100
  6240. @@ -0,0 +1,33 @@
  6241. +/* ipkg_remove.h - the itsy package management system
  6242. +
  6243. + Carl D. Worth
  6244. +
  6245. + Copyright (C) 2001 University of Southern California
  6246. +
  6247. + This program is free software; you can redistribute it and/or
  6248. + modify it under the terms of the GNU General Public License as
  6249. + published by the Free Software Foundation; either version 2, or (at
  6250. + your option) any later version.
  6251. +
  6252. + This program is distributed in the hope that it will be useful, but
  6253. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6254. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6255. + General Public License for more details.
  6256. +*/
  6257. +
  6258. +#ifndef IPKG_REMOVE_H
  6259. +#define IPKG_REMOVE_H
  6260. +
  6261. +#include "pkg.h"
  6262. +#include "ipkg_conf.h"
  6263. +
  6264. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
  6265. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
  6266. +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
  6267. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents);
  6268. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
  6269. +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6270. +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6271. +
  6272. +
  6273. +#endif
  6274. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_upgrade.c busybox-1.15.2/archival/libipkg/ipkg_upgrade.c
  6275. --- busybox-1.15.2.orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
  6276. +++ busybox-1.15.2/archival/libipkg/ipkg_upgrade.c 2010-03-14 20:53:41.000000000 +0100
  6277. @@ -0,0 +1,79 @@
  6278. +/* ipkg_upgrade.c - the itsy package management system
  6279. +
  6280. + Carl D. Worth
  6281. + Copyright (C) 2001 University of Southern California
  6282. +
  6283. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6284. +
  6285. + This program is free software; you can redistribute it and/or
  6286. + modify it under the terms of the GNU General Public License as
  6287. + published by the Free Software Foundation; either version 2, or (at
  6288. + your option) any later version.
  6289. +
  6290. + This program is distributed in the hope that it will be useful, but
  6291. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6292. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6293. + General Public License for more details.
  6294. +*/
  6295. +
  6296. +#include "ipkg.h"
  6297. +#include "ipkg_install.h"
  6298. +#include "ipkg_message.h"
  6299. +
  6300. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6301. +
  6302. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
  6303. +{
  6304. + pkg_t *new;
  6305. + int cmp;
  6306. + char *old_version, *new_version;
  6307. +
  6308. + if (old->state_flag & SF_HOLD) {
  6309. + ipkg_message(conf, IPKG_NOTICE,
  6310. + "Not upgrading package %s which is marked "
  6311. + "hold (flags=%#x)\n", old->name, old->state_flag);
  6312. + return 0;
  6313. + }
  6314. +
  6315. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
  6316. + if (new == NULL) {
  6317. + old_version = pkg_version_str_alloc(old);
  6318. + ipkg_message(conf, IPKG_NOTICE,
  6319. + "Assuming locally installed package %s (%s) "
  6320. + "is up to date.\n", old->name, old_version);
  6321. + free(old_version);
  6322. + return 0;
  6323. + }
  6324. +
  6325. + old_version = pkg_version_str_alloc(old);
  6326. + new_version = pkg_version_str_alloc(new);
  6327. +
  6328. + cmp = pkg_compare_versions(old, new);
  6329. + ipkg_message(conf, IPKG_DEBUG,
  6330. + "comparing visible versions of pkg %s:"
  6331. + "\n\t%s is installed "
  6332. + "\n\t%s is available "
  6333. + "\n\t%d was comparison result\n",
  6334. + old->name, old_version, new_version, cmp);
  6335. + if (cmp == 0) {
  6336. + ipkg_message(conf, IPKG_INFO,
  6337. + "Package %s (%s) installed in %s is up to date.\n",
  6338. + old->name, old_version, old->dest->name);
  6339. + free(old_version);
  6340. + free(new_version);
  6341. + return 0;
  6342. + } else if (cmp > 0) {
  6343. + ipkg_message(conf, IPKG_NOTICE,
  6344. + "Not downgrading package %s on %s from %s to %s.\n",
  6345. + old->name, old->dest->name, old_version, new_version);
  6346. + free(old_version);
  6347. + free(new_version);
  6348. + return 0;
  6349. + } else if (cmp < 0) {
  6350. + new->dest = old->dest;
  6351. + old->state_want = SW_DEINSTALL;
  6352. + }
  6353. +
  6354. + new->state_flag |= SF_USER;
  6355. + return ipkg_install_pkg(conf, new,1);
  6356. +}
  6357. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_upgrade.h busybox-1.15.2/archival/libipkg/ipkg_upgrade.h
  6358. --- busybox-1.15.2.orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
  6359. +++ busybox-1.15.2/archival/libipkg/ipkg_upgrade.h 2010-03-14 20:53:41.000000000 +0100
  6360. @@ -0,0 +1,18 @@
  6361. +/* ipkg_upgrade.c - the itsy package management system
  6362. +
  6363. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6364. +
  6365. + This program is free software; you can redistribute it and/or
  6366. + modify it under the terms of the GNU General Public License as
  6367. + published by the Free Software Foundation; either version 2, or (at
  6368. + your option) any later version.
  6369. +
  6370. + This program is distributed in the hope that it will be useful, but
  6371. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6372. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6373. + General Public License for more details.
  6374. +*/
  6375. +
  6376. +#include "ipkg.h"
  6377. +
  6378. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6379. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_utils.c busybox-1.15.2/archival/libipkg/ipkg_utils.c
  6380. --- busybox-1.15.2.orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
  6381. +++ busybox-1.15.2/archival/libipkg/ipkg_utils.c 2010-03-14 20:53:41.000000000 +0100
  6382. @@ -0,0 +1,185 @@
  6383. +/* ipkg_utils.c - the itsy package management system
  6384. +
  6385. + Steven M. Ayer
  6386. +
  6387. + Copyright (C) 2002 Compaq Computer Corporation
  6388. +
  6389. + This program is free software; you can redistribute it and/or
  6390. + modify it under the terms of the GNU General Public License as
  6391. + published by the Free Software Foundation; either version 2, or (at
  6392. + your option) any later version.
  6393. +
  6394. + This program is distributed in the hope that it will be useful, but
  6395. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6396. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6397. + General Public License for more details.
  6398. +*/
  6399. +
  6400. +#include "ipkg.h"
  6401. +#include <errno.h>
  6402. +#include <ctype.h>
  6403. +#include <sys/vfs.h>
  6404. +
  6405. +#include "ipkg_utils.h"
  6406. +#include "pkg.h"
  6407. +#include "pkg_hash.h"
  6408. +
  6409. +void push_error_list(struct errlist ** errors, char * msg);
  6410. +void reverse_error_list(struct errlist **errors);
  6411. +void free_error_list(struct errlist **errors);
  6412. +
  6413. +struct errlist* error_list;
  6414. +
  6415. +int get_available_blocks(char * filesystem)
  6416. +{
  6417. + struct statfs sfs;
  6418. +
  6419. + if(statfs(filesystem, &sfs)){
  6420. + fprintf(stderr, "bad statfs\n");
  6421. + return 0;
  6422. + }
  6423. + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
  6424. + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
  6425. +}
  6426. +
  6427. +char **read_raw_pkgs_from_file(const char *file_name)
  6428. +{
  6429. + FILE *fp;
  6430. + char **ret;
  6431. +
  6432. + if(!(fp = fopen(file_name, "r"))){
  6433. + fprintf(stderr, "can't get %s open for read\n", file_name);
  6434. + return NULL;
  6435. + }
  6436. +
  6437. + ret = read_raw_pkgs_from_stream(fp);
  6438. +
  6439. + fclose(fp);
  6440. +
  6441. + return ret;
  6442. +}
  6443. +
  6444. +char **read_raw_pkgs_from_stream(FILE *fp)
  6445. +{
  6446. + char **raw = NULL, *buf, *scout;
  6447. + int count = 0;
  6448. + size_t size = 512;
  6449. +
  6450. + buf = malloc (size);
  6451. +
  6452. + while (fgets(buf, size, fp)) {
  6453. + while (strlen (buf) == (size - 1)
  6454. + && buf[size-2] != '\n') {
  6455. + size_t o = size - 1;
  6456. + size *= 2;
  6457. + buf = realloc (buf, size);
  6458. + if (fgets (buf + o, size - o, fp) == NULL)
  6459. + break;
  6460. + }
  6461. +
  6462. + if(!(count % 50))
  6463. + raw = realloc(raw, (count + 50) * sizeof(char *));
  6464. +
  6465. + if((scout = strchr(buf, '\n')))
  6466. + *scout = '\0';
  6467. +
  6468. + raw[count++] = strdup(buf);
  6469. + }
  6470. +
  6471. + raw = realloc(raw, (count + 1) * sizeof(char *));
  6472. + raw[count] = NULL;
  6473. +
  6474. + free (buf);
  6475. +
  6476. + return raw;
  6477. +}
  6478. +
  6479. +/* something to remove whitespace, a hash pooper */
  6480. +char *trim_alloc(char *line)
  6481. +{
  6482. + char *new;
  6483. + char *dest, *src, *end;
  6484. +
  6485. + new = malloc(strlen(line) + 1);
  6486. + if ( new == NULL ){
  6487. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  6488. + return NULL;
  6489. + }
  6490. + dest = new, src = line, end = line + (strlen(line) - 1);
  6491. +
  6492. + /* remove it from the front */
  6493. + while(src &&
  6494. + isspace(*src) &&
  6495. + *src)
  6496. + src++;
  6497. + /* and now from the back */
  6498. + while((end > src) &&
  6499. + isspace(*end))
  6500. + end--;
  6501. + end++;
  6502. + *end = '\0';
  6503. + strcpy(new, src);
  6504. + /* this does from the first space
  6505. + * blasting away any versions stuff in depends
  6506. + while(src &&
  6507. + !isspace(*src) &&
  6508. + *src)
  6509. + *dest++ = *src++;
  6510. + *dest = '\0';
  6511. + */
  6512. +
  6513. + return new;
  6514. +}
  6515. +
  6516. +int line_is_blank(const char *line)
  6517. +{
  6518. + const char *s;
  6519. +
  6520. + for (s = line; *s; s++) {
  6521. + if (!isspace(*s))
  6522. + return 0;
  6523. + }
  6524. + return 1;
  6525. +}
  6526. +
  6527. +void push_error_list(struct errlist ** errors, char * msg){
  6528. + struct errlist *err_lst_tmp;
  6529. +
  6530. +
  6531. + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
  6532. + err_lst_tmp->errmsg=strdup(msg) ;
  6533. + err_lst_tmp->next = *errors;
  6534. + *errors = err_lst_tmp;
  6535. +}
  6536. +
  6537. +
  6538. +void reverse_error_list(struct errlist **errors){
  6539. + struct errlist *result=NULL;
  6540. + struct errlist *current= *errors;
  6541. + struct errlist *next;
  6542. +
  6543. + while ( current != NULL ) {
  6544. + next = current->next;
  6545. + current->next=result;
  6546. + result=current;
  6547. + current=next;
  6548. + }
  6549. + *errors=result;
  6550. +
  6551. +}
  6552. +
  6553. +
  6554. +void free_error_list(struct errlist **errors){
  6555. + struct errlist *current = *errors;
  6556. +
  6557. + while (current != NULL) {
  6558. + free(current->errmsg);
  6559. + current = (*errors)->next;
  6560. + free(*errors);
  6561. + *errors = current;
  6562. + }
  6563. +
  6564. +
  6565. +}
  6566. +
  6567. +
  6568. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_utils.h busybox-1.15.2/archival/libipkg/ipkg_utils.h
  6569. --- busybox-1.15.2.orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
  6570. +++ busybox-1.15.2/archival/libipkg/ipkg_utils.h 2010-03-14 20:53:41.000000000 +0100
  6571. @@ -0,0 +1,29 @@
  6572. +/* ipkg_utils.h - the itsy package management system
  6573. +
  6574. + Steven M. Ayer
  6575. +
  6576. + Copyright (C) 2002 Compaq Computer Corporation
  6577. +
  6578. + This program is free software; you can redistribute it and/or
  6579. + modify it under the terms of the GNU General Public License as
  6580. + published by the Free Software Foundation; either version 2, or (at
  6581. + your option) any later version.
  6582. +
  6583. + This program is distributed in the hope that it will be useful, but
  6584. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6585. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6586. + General Public License for more details.
  6587. +*/
  6588. +
  6589. +#ifndef IPKG_UTILS_H
  6590. +#define IPKG_UTILS_H
  6591. +
  6592. +#include "pkg.h"
  6593. +
  6594. +int get_available_blocks(char * filesystem);
  6595. +char **read_raw_pkgs_from_file(const char *file_name);
  6596. +char **read_raw_pkgs_from_stream(FILE *fp);
  6597. +char *trim_alloc(char * line);
  6598. +int line_is_blank(const char *line);
  6599. +
  6600. +#endif
  6601. diff -Nur busybox-1.15.2.orig/archival/libipkg/Kbuild busybox-1.15.2/archival/libipkg/Kbuild
  6602. --- busybox-1.15.2.orig/archival/libipkg/Kbuild 1970-01-01 01:00:00.000000000 +0100
  6603. +++ busybox-1.15.2/archival/libipkg/Kbuild 2010-03-14 21:01:18.000000000 +0100
  6604. @@ -0,0 +1,60 @@
  6605. +# Makefile for busybox
  6606. +#
  6607. +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  6608. +# Copyright (C) 2006 OpenWrt.org
  6609. +#
  6610. +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  6611. +
  6612. +LIBIPKG_CORE_OBJS:= \
  6613. + args.o \
  6614. + libipkg.o \
  6615. + user.o \
  6616. +
  6617. +LIBIPKG_CMD_OBJS:= \
  6618. + ipkg_cmd.o \
  6619. + ipkg_configure.o \
  6620. + ipkg_download.o \
  6621. + ipkg_install.o \
  6622. + ipkg_remove.o \
  6623. + ipkg_upgrade.o \
  6624. +
  6625. +LIBIPKG_DB_OBJS:= \
  6626. + hash_table.o \
  6627. + ipkg_conf.o \
  6628. + ipkg_utils.o \
  6629. + pkg.o \
  6630. + pkg_depends.o \
  6631. + pkg_extract.o \
  6632. + pkg_hash.o \
  6633. + pkg_parse.o \
  6634. + pkg_vec.o \
  6635. +
  6636. +LIBIPKG_LIST_OBJS:= \
  6637. + conffile.o \
  6638. + conffile_list.o \
  6639. + nv_pair.o \
  6640. + nv_pair_list.o \
  6641. + pkg_dest.o \
  6642. + pkg_dest_list.o \
  6643. + pkg_src.o \
  6644. + pkg_src_list.o \
  6645. + str_list.o \
  6646. + void_list.o \
  6647. +
  6648. +LIBIPKG_UTIL_OBJS:= \
  6649. + file_util.o \
  6650. + ipkg_message.o \
  6651. + str_util.o \
  6652. + xsystem.o \
  6653. +
  6654. +lib-y :=
  6655. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
  6656. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
  6657. +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
  6658. +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
  6659. +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
  6660. +
  6661. +ifeq ($(strip $(IPKG_ARCH)),)
  6662. +IPKG_ARCH:=$(TARGET_ARCH)
  6663. +endif
  6664. +CFLAGS += -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
  6665. diff -Nur busybox-1.15.2.orig/archival/libipkg/libipkg.c busybox-1.15.2/archival/libipkg/libipkg.c
  6666. --- busybox-1.15.2.orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
  6667. +++ busybox-1.15.2/archival/libipkg/libipkg.c 2010-03-14 20:59:05.000000000 +0100
  6668. @@ -0,0 +1,525 @@
  6669. +/* ipkglib.c - the itsy package management system
  6670. +
  6671. + Florina Boor
  6672. +
  6673. + Copyright (C) 2003 kernel concepts
  6674. +
  6675. + This program is free software; you can redistribute it and/or
  6676. + modify it under the terms of the GNU General Public License as
  6677. + published by the Free Software Foundation; either version 2, or (at
  6678. + your option) any later version.
  6679. +
  6680. + This program is distributed in the hope that it will be useful, but
  6681. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6682. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6683. + General Public License for more details.
  6684. +*/
  6685. +
  6686. +#include "ipkg.h"
  6687. +#include "ipkg_includes.h"
  6688. +#include "libipkg.h"
  6689. +
  6690. +#include "args.h"
  6691. +#include "ipkg_conf.h"
  6692. +#include "ipkg_cmd.h"
  6693. +#include "file_util.h"
  6694. +
  6695. +int ipkg_file_what(args_t *args, const char *file, const char* command);
  6696. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  6697. + char *msg);
  6698. +int default_ipkg_list_callback(char *name, char *desc, char *version);
  6699. +int default_ipkg_files_callback(char *desc);
  6700. +int default_ipkg_status_callback(char *desc);
  6701. +char* default_ipkg_response_callback(char *question);
  6702. +
  6703. +
  6704. +ipkg_message_callback ipkg_cb_message = NULL;
  6705. +ipkg_response_callback ipkg_cb_response = NULL;
  6706. +ipkg_status_callback ipkg_cb_status = NULL;
  6707. +ipkg_list_callback ipkg_cb_list = NULL;
  6708. +
  6709. +
  6710. +int
  6711. +ipkg_init (ipkg_message_callback mcall,
  6712. + ipkg_response_callback rcall,
  6713. + args_t * args)
  6714. +{
  6715. + ipkg_cb_message = mcall;
  6716. + ipkg_cb_response = rcall;
  6717. +
  6718. + args_init (args);
  6719. +
  6720. + return 0;
  6721. +}
  6722. +
  6723. +
  6724. +int
  6725. +ipkg_deinit (args_t * args)
  6726. +{
  6727. + args_deinit (args);
  6728. + ipkg_cb_message = NULL;
  6729. + ipkg_cb_response = NULL;
  6730. +
  6731. + /* place other cleanup stuff here */
  6732. +
  6733. + return 0;
  6734. +}
  6735. +
  6736. +
  6737. +int
  6738. +ipkg_packages_list(args_t *args,
  6739. + const char *packages,
  6740. + ipkg_list_callback cblist,
  6741. + void *userdata)
  6742. +{
  6743. + ipkg_cmd_t *cmd;
  6744. + ipkg_conf_t ipkg_conf;
  6745. + int err;
  6746. +
  6747. + err = ipkg_conf_init (&ipkg_conf, args);
  6748. + if (err)
  6749. + {
  6750. + return err;
  6751. + }
  6752. +
  6753. + ipkg_cb_list = cblist;
  6754. + /* we need to do this because of static declarations,
  6755. + * maybe a good idea to change */
  6756. + cmd = ipkg_cmd_find ("list");
  6757. + if (packages)
  6758. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6759. + else
  6760. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6761. + ipkg_cb_list = NULL;
  6762. + ipkg_conf_deinit (&ipkg_conf);
  6763. + return (err);
  6764. +}
  6765. +
  6766. +
  6767. +int
  6768. +ipkg_packages_status(args_t *args,
  6769. + const char *packages,
  6770. + ipkg_status_callback cbstatus,
  6771. + void *userdata)
  6772. +{
  6773. + ipkg_cmd_t *cmd;
  6774. + ipkg_conf_t ipkg_conf;
  6775. + int err;
  6776. +
  6777. + err = ipkg_conf_init (&ipkg_conf, args);
  6778. + if (err)
  6779. + {
  6780. + return err;
  6781. + }
  6782. +
  6783. + ipkg_cb_status = cbstatus;
  6784. +
  6785. + /* we need to do this because of static declarations,
  6786. + * maybe a good idea to change */
  6787. + cmd = ipkg_cmd_find ("status");
  6788. + if (packages)
  6789. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6790. + else
  6791. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6792. +
  6793. + ipkg_cb_status = NULL;
  6794. + ipkg_conf_deinit (&ipkg_conf);
  6795. + return (err);
  6796. +}
  6797. +
  6798. +
  6799. +int
  6800. +ipkg_packages_info(args_t *args,
  6801. + const char *packages,
  6802. + ipkg_status_callback cbstatus,
  6803. + void *userdata)
  6804. +{
  6805. + ipkg_cmd_t *cmd;
  6806. + ipkg_conf_t ipkg_conf;
  6807. + int err;
  6808. +
  6809. + err = ipkg_conf_init (&ipkg_conf, args);
  6810. + if (err)
  6811. + {
  6812. + return err;
  6813. + }
  6814. +
  6815. + ipkg_cb_status = cbstatus;
  6816. +
  6817. + /* we need to do this because of static declarations,
  6818. + * maybe a good idea to change */
  6819. + cmd = ipkg_cmd_find ("info");
  6820. + if (packages)
  6821. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6822. + else
  6823. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6824. +
  6825. + ipkg_cb_status = NULL;
  6826. + ipkg_conf_deinit (&ipkg_conf);
  6827. + return (err);
  6828. +}
  6829. +
  6830. +
  6831. +int
  6832. +ipkg_packages_install (args_t * args, const char *name)
  6833. +{
  6834. + ipkg_cmd_t *cmd;
  6835. + ipkg_conf_t ipkg_conf;
  6836. + int err;
  6837. +
  6838. + /* this error should be handled in application */
  6839. + if (!name || !strlen (name))
  6840. + return (-1);
  6841. +
  6842. + err = ipkg_conf_init (&ipkg_conf, args);
  6843. + if (err)
  6844. + {
  6845. + return err;
  6846. + }
  6847. +
  6848. + /* we need to do this because of static declarations,
  6849. + * maybe a good idea to change */
  6850. + cmd = ipkg_cmd_find ("install");
  6851. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6852. +
  6853. + ipkg_conf_deinit(&ipkg_conf);
  6854. + return (err);
  6855. +}
  6856. +
  6857. +
  6858. +int
  6859. +ipkg_packages_remove(args_t *args, const char *name, int purge)
  6860. +{
  6861. + ipkg_cmd_t *cmd;
  6862. + ipkg_conf_t ipkg_conf;
  6863. + int err;
  6864. +
  6865. + /* this error should be handled in application */
  6866. + if (!name || !strlen (name))
  6867. + return (-1);
  6868. +
  6869. + err = ipkg_conf_init (&ipkg_conf, args);
  6870. + if (err)
  6871. + {
  6872. + return err;
  6873. + }
  6874. +
  6875. + /* we need to do this because of static declarations,
  6876. + * maybe a good idea to change */
  6877. + if (purge)
  6878. + cmd = ipkg_cmd_find ("purge");
  6879. + else
  6880. + cmd = ipkg_cmd_find ("remove");
  6881. +
  6882. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6883. +
  6884. + ipkg_conf_deinit(&ipkg_conf);
  6885. + return (err);
  6886. +}
  6887. +
  6888. +
  6889. +int
  6890. +ipkg_lists_update(args_t *args)
  6891. +{
  6892. + ipkg_cmd_t *cmd;
  6893. + ipkg_conf_t ipkg_conf;
  6894. + int err;
  6895. +
  6896. + err = ipkg_conf_init (&ipkg_conf, args);
  6897. + if (err)
  6898. + {
  6899. + return err;
  6900. + }
  6901. +
  6902. + /* we need to do this because of static declarations,
  6903. + * maybe a good idea to change */
  6904. + cmd = ipkg_cmd_find ("update");
  6905. +
  6906. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6907. +
  6908. + ipkg_conf_deinit(&ipkg_conf);
  6909. + return (err);
  6910. +}
  6911. +
  6912. +
  6913. +int
  6914. +ipkg_packages_upgrade(args_t *args)
  6915. +{
  6916. + ipkg_cmd_t *cmd;
  6917. + ipkg_conf_t ipkg_conf;
  6918. + int err;
  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 ("upgrade");
  6929. +
  6930. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6931. +
  6932. + ipkg_conf_deinit(&ipkg_conf);
  6933. + return (err);
  6934. +}
  6935. +
  6936. +
  6937. +int
  6938. +ipkg_packages_download (args_t * args, const char *name)
  6939. +{
  6940. + ipkg_cmd_t *cmd;
  6941. + ipkg_conf_t ipkg_conf;
  6942. + int err;
  6943. +
  6944. + /* this error should be handled in application */
  6945. + if (!name || !strlen (name))
  6946. + return (-1);
  6947. +
  6948. + err = ipkg_conf_init (&ipkg_conf, args);
  6949. + if (err)
  6950. + {
  6951. + return err;
  6952. + }
  6953. +
  6954. + /* we need to do this because of static declarations,
  6955. + * maybe a good idea to change */
  6956. + cmd = ipkg_cmd_find ("download");
  6957. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6958. +
  6959. + ipkg_conf_deinit(&ipkg_conf);
  6960. + return (err);
  6961. +}
  6962. +
  6963. +
  6964. +int
  6965. +ipkg_package_files(args_t *args,
  6966. + const char *name,
  6967. + ipkg_list_callback cblist,
  6968. + void *userdata)
  6969. +{
  6970. + ipkg_cmd_t *cmd;
  6971. + ipkg_conf_t ipkg_conf;
  6972. + int err;
  6973. +
  6974. + /* this error should be handled in application */
  6975. + if (!name || !strlen (name))
  6976. + return (-1);
  6977. +
  6978. + err = ipkg_conf_init (&ipkg_conf, args);
  6979. + if (err)
  6980. + {
  6981. + return err;
  6982. + }
  6983. +
  6984. + ipkg_cb_list = cblist;
  6985. +
  6986. + /* we need to do this because of static declarations,
  6987. + * maybe a good idea to change */
  6988. + cmd = ipkg_cmd_find ("files");
  6989. +
  6990. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
  6991. +
  6992. + ipkg_cb_list = NULL;
  6993. + ipkg_conf_deinit(&ipkg_conf);
  6994. + return (err);
  6995. +}
  6996. +
  6997. +
  6998. +int
  6999. +ipkg_file_search(args_t *args,
  7000. + const char *file,
  7001. + ipkg_list_callback cblist,
  7002. + void *userdata)
  7003. +{
  7004. + ipkg_cmd_t *cmd;
  7005. + ipkg_conf_t ipkg_conf;
  7006. + int err;
  7007. +
  7008. + /* this error should be handled in application */
  7009. + if (!file || !strlen (file))
  7010. + return (-1);
  7011. +
  7012. + err = ipkg_conf_init (&ipkg_conf, args);
  7013. + if (err)
  7014. + {
  7015. + return err;
  7016. + }
  7017. +
  7018. + ipkg_cb_list = cblist;
  7019. +
  7020. + /* we need to do this because of static declarations,
  7021. + * maybe a good idea to change */
  7022. + cmd = ipkg_cmd_find ("search");
  7023. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
  7024. +
  7025. + ipkg_cb_list = NULL;
  7026. + ipkg_conf_deinit(&ipkg_conf);
  7027. + return(err);
  7028. +}
  7029. +
  7030. +
  7031. +int
  7032. +ipkg_file_what(args_t *args, const char *file, const char* command)
  7033. +{
  7034. + ipkg_cmd_t *cmd;
  7035. + ipkg_conf_t ipkg_conf;
  7036. + int err;
  7037. +
  7038. + /* this error should be handled in application */
  7039. + if (!file || !strlen (file))
  7040. + return (-1);
  7041. +
  7042. + err = ipkg_conf_init (&ipkg_conf, args);
  7043. + if (err)
  7044. + {
  7045. + return err;
  7046. + }
  7047. +
  7048. + /* we need to do this because of static declarations,
  7049. + * maybe a good idea to change */
  7050. + cmd = ipkg_cmd_find (command);
  7051. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
  7052. +
  7053. + ipkg_conf_deinit(&ipkg_conf);
  7054. + return(err);
  7055. +}
  7056. +
  7057. +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
  7058. +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
  7059. +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
  7060. +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
  7061. +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
  7062. +
  7063. +
  7064. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  7065. + char *msg)
  7066. +{
  7067. + if (conf && (conf->verbosity < level)) {
  7068. + return 0;
  7069. + } else {
  7070. + if ( level == IPKG_ERROR )
  7071. + push_error_list(&error_list, msg);
  7072. + else
  7073. + printf(msg);
  7074. + }
  7075. + return 0;
  7076. +}
  7077. +
  7078. +int default_ipkg_list_callback(char *name, char *desc, char *version)
  7079. +{
  7080. + if (desc)
  7081. + printf("%s - %s - %s\n", name, version, desc);
  7082. + else
  7083. + printf("%s - %s\n", name, version);
  7084. + return 0;
  7085. +}
  7086. +
  7087. +int default_ipkg_files_callback(char *desc)
  7088. +{
  7089. + if (desc)
  7090. + printf("%s\n", desc);
  7091. + return 0;
  7092. +}
  7093. +
  7094. +int default_ipkg_status_callback(char *desc)
  7095. +{
  7096. + printf("%s\n", desc);
  7097. + return 0;
  7098. +}
  7099. +
  7100. +char* default_ipkg_response_callback(char *question)
  7101. +{
  7102. + char *response = NULL;
  7103. + printf(question);
  7104. + fflush(stdout);
  7105. + do {
  7106. + response = (char *)file_read_line_alloc(stdin);
  7107. + } while (response == NULL);
  7108. + return response;
  7109. +}
  7110. +
  7111. +/* This is used for backward compatibility */
  7112. +int
  7113. +ipkg_op (int argc, char *argv[])
  7114. +{
  7115. + int err, optind_;
  7116. + args_t args;
  7117. + char *cmd_name;
  7118. + ipkg_cmd_t *cmd;
  7119. + ipkg_conf_t ipkg_conf;
  7120. + const char *message = "ipkg must have one sub-command argument";
  7121. +
  7122. + args_init (&args);
  7123. +
  7124. + optind_ = args_parse (&args, argc, argv);
  7125. + if (optind_ == argc || optind_ < 0)
  7126. + {
  7127. + args_usage(message);
  7128. + }
  7129. +
  7130. + cmd_name = argv[optind_++];
  7131. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  7132. + read anything from there.
  7133. +*/
  7134. + if ( !strcmp(cmd_name,"print-architecture") ||
  7135. + !strcmp(cmd_name,"print_architecture") ||
  7136. + !strcmp(cmd_name,"print-installation-architecture") ||
  7137. + !strcmp(cmd_name,"print_installation_architecture") )
  7138. + args.nocheckfordirorfile = 1;
  7139. +
  7140. +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
  7141. + read anything from there.
  7142. +*/
  7143. + if ( !strcmp(cmd_name,"flag") ||
  7144. + !strcmp(cmd_name,"configure") ||
  7145. + !strcmp(cmd_name,"remove") ||
  7146. + !strcmp(cmd_name,"files") ||
  7147. + !strcmp(cmd_name,"search") ||
  7148. + !strcmp(cmd_name,"compare_versions") ||
  7149. + !strcmp(cmd_name,"compare-versions") ||
  7150. + !strcmp(cmd_name,"list_installed") ||
  7151. + !strcmp(cmd_name,"list-installed") ||
  7152. + !strcmp(cmd_name,"status") )
  7153. + args.noreadfeedsfile = 1;
  7154. +
  7155. +
  7156. + err = ipkg_conf_init (&ipkg_conf, &args);
  7157. + if (err)
  7158. + {
  7159. + return err;
  7160. + }
  7161. +
  7162. + args_deinit (&args);
  7163. +
  7164. + ipkg_cb_message = default_ipkg_message_callback;
  7165. + ipkg_cb_response = default_ipkg_response_callback;
  7166. + ipkg_cb_status = (ipkg_status_callback)default_ipkg_status_callback;
  7167. + if ( strcmp(cmd_name, "files")==0)
  7168. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_files_callback;
  7169. + else
  7170. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_list_callback;
  7171. +
  7172. + cmd = ipkg_cmd_find (cmd_name);
  7173. + if (cmd == NULL)
  7174. + {
  7175. + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
  7176. + cmd_name);
  7177. + args_usage (NULL);
  7178. + }
  7179. +
  7180. + if (cmd->requires_args && optind_ == argc)
  7181. + {
  7182. + fprintf (stderr,
  7183. + "%s: the ``%s'' command requires at least one argument\n",
  7184. + __FUNCTION__, cmd_name);
  7185. + args_usage (NULL);
  7186. + }
  7187. +
  7188. + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind_, (const char **) (argv + optind_), NULL);
  7189. +
  7190. + ipkg_conf_deinit (&ipkg_conf);
  7191. +
  7192. + return err;
  7193. +}
  7194. diff -Nur busybox-1.15.2.orig/archival/libipkg/libipkg.h busybox-1.15.2/archival/libipkg/libipkg.h
  7195. --- busybox-1.15.2.orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
  7196. +++ busybox-1.15.2/archival/libipkg/libipkg.h 2010-03-14 21:00:54.000000000 +0100
  7197. @@ -0,0 +1,78 @@
  7198. +/* ipkglib.h - the itsy package management system
  7199. +
  7200. + Florian Boor <florian.boor@kernelconcepts.de>
  7201. +
  7202. + This program is free software; you can redistribute it and/or
  7203. + modify it under the terms of the GNU General Public License as
  7204. + published by the Free Software Foundation; either version 2, or (at
  7205. + your option) any later version.
  7206. +
  7207. + This program is distributed in the hope that it will be useful, but
  7208. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7209. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7210. + General Public License for more details.
  7211. +*/
  7212. +
  7213. +#ifndef IPKGLIB_H
  7214. +#define IPKGLIB_H
  7215. +
  7216. +#include "ipkg_conf.h"
  7217. +#include "ipkg_message.h"
  7218. +
  7219. +#include "args.h"
  7220. +#include "pkg.h"
  7221. +
  7222. +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
  7223. + char *msg);
  7224. +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
  7225. + pkg_state_status_t status, void *userdata);
  7226. +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
  7227. + void *userdata);
  7228. +typedef char* (*ipkg_response_callback)(char *question);
  7229. +
  7230. +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
  7231. +extern int ipkg_init (ipkg_message_callback mcall,
  7232. + ipkg_response_callback rcall,
  7233. + args_t * args);
  7234. +
  7235. +extern int ipkg_deinit (args_t *args);
  7236. +extern int ipkg_packages_list(args_t *args,
  7237. + const char *packages,
  7238. + ipkg_list_callback cblist,
  7239. + void *userdata);
  7240. +extern int ipkg_packages_status(args_t *args,
  7241. + const char *packages,
  7242. + ipkg_status_callback cbstatus,
  7243. + void *userdata);
  7244. +extern int ipkg_packages_info(args_t *args,
  7245. + const char *packages,
  7246. + ipkg_status_callback cbstatus,
  7247. + void *userdata);
  7248. +extern int ipkg_packages_install(args_t *args, const char *name);
  7249. +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
  7250. +extern int ipkg_lists_update(args_t *args);
  7251. +extern int ipkg_packages_upgrade(args_t *args);
  7252. +extern int ipkg_packages_download(args_t *args, const char *name);
  7253. +extern int ipkg_package_files(args_t *args,
  7254. + const char *name,
  7255. + ipkg_list_callback cblist,
  7256. + void *userdata);
  7257. +extern int ipkg_file_search(args_t *args,
  7258. + const char *file,
  7259. + ipkg_list_callback cblist,
  7260. + void *userdata);
  7261. +extern int ipkg_package_whatdepends(args_t *args, const char *file);
  7262. +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
  7263. +extern int ipkg_package_whatprovides(args_t *args, const char *file);
  7264. +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
  7265. +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
  7266. +
  7267. +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
  7268. +extern ipkg_response_callback ipkg_cb_response;
  7269. +extern ipkg_status_callback ipkg_cb_status;
  7270. +extern ipkg_list_callback ipkg_cb_list;
  7271. +extern void push_error_list(struct errlist **errors,char * msg);
  7272. +extern void reverse_error_list(struct errlist **errors);
  7273. +extern void free_error_list(struct errlist **errors);
  7274. +
  7275. +#endif
  7276. diff -Nur busybox-1.15.2.orig/archival/libipkg/nv_pair.c busybox-1.15.2/archival/libipkg/nv_pair.c
  7277. --- busybox-1.15.2.orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
  7278. +++ busybox-1.15.2/archival/libipkg/nv_pair.c 2010-03-14 20:53:41.000000000 +0100
  7279. @@ -0,0 +1,40 @@
  7280. +/* nv_pair.c - the itsy package management system
  7281. +
  7282. + Carl D. Worth
  7283. +
  7284. + Copyright (C) 2001 University of Southern California
  7285. +
  7286. + This program is free software; you can redistribute it and/or
  7287. + modify it under the terms of the GNU General Public License as
  7288. + published by the Free Software Foundation; either version 2, or (at
  7289. + your option) any later version.
  7290. +
  7291. + This program is distributed in the hope that it will be useful, but
  7292. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7293. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7294. + General Public License for more details.
  7295. +*/
  7296. +
  7297. +#include "ipkg.h"
  7298. +
  7299. +#include "nv_pair.h"
  7300. +#include "str_util.h"
  7301. +
  7302. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
  7303. +{
  7304. + nv_pair->name = str_dup_safe(name);
  7305. + nv_pair->value = str_dup_safe(value);
  7306. +
  7307. + return 0;
  7308. +}
  7309. +
  7310. +void nv_pair_deinit(nv_pair_t *nv_pair)
  7311. +{
  7312. + free(nv_pair->name);
  7313. + nv_pair->name = NULL;
  7314. +
  7315. + free(nv_pair->value);
  7316. + nv_pair->value = NULL;
  7317. +}
  7318. +
  7319. +
  7320. diff -Nur busybox-1.15.2.orig/archival/libipkg/nv_pair.h busybox-1.15.2/archival/libipkg/nv_pair.h
  7321. --- busybox-1.15.2.orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
  7322. +++ busybox-1.15.2/archival/libipkg/nv_pair.h 2010-03-14 20:53:41.000000000 +0100
  7323. @@ -0,0 +1,32 @@
  7324. +/* nv_pair.h - the itsy package management system
  7325. +
  7326. + Carl D. Worth
  7327. +
  7328. + Copyright (C) 2001 University of Southern California
  7329. +
  7330. + This program is free software; you can redistribute it and/or
  7331. + modify it under the terms of the GNU General Public License as
  7332. + published by the Free Software Foundation; either version 2, or (at
  7333. + your option) any later version.
  7334. +
  7335. + This program is distributed in the hope that it will be useful, but
  7336. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7337. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7338. + General Public License for more details.
  7339. +*/
  7340. +
  7341. +#ifndef NV_PAIR_H
  7342. +#define NV_PAIR_H
  7343. +
  7344. +typedef struct nv_pair nv_pair_t;
  7345. +struct nv_pair
  7346. +{
  7347. + char *name;
  7348. + char *value;
  7349. +};
  7350. +
  7351. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
  7352. +void nv_pair_deinit(nv_pair_t *nv_pair);
  7353. +
  7354. +#endif
  7355. +
  7356. diff -Nur busybox-1.15.2.orig/archival/libipkg/nv_pair_list.c busybox-1.15.2/archival/libipkg/nv_pair_list.c
  7357. --- busybox-1.15.2.orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
  7358. +++ busybox-1.15.2/archival/libipkg/nv_pair_list.c 2010-03-14 20:53:41.000000000 +0100
  7359. @@ -0,0 +1,98 @@
  7360. +/* nv_pair_list.c - the itsy package management system
  7361. +
  7362. + Carl D. Worth
  7363. +
  7364. + Copyright (C) 2001 University of Southern California
  7365. +
  7366. + This program is free software; you can redistribute it and/or
  7367. + modify it under the terms of the GNU General Public License as
  7368. + published by the Free Software Foundation; either version 2, or (at
  7369. + your option) any later version.
  7370. +
  7371. + This program is distributed in the hope that it will be useful, but
  7372. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7373. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7374. + General Public License for more details.
  7375. +*/
  7376. +
  7377. +#include "ipkg.h"
  7378. +
  7379. +#include "nv_pair.h"
  7380. +#include "void_list.h"
  7381. +#include "nv_pair_list.h"
  7382. +
  7383. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
  7384. +{
  7385. + return void_list_elt_init((void_list_elt_t *) elt, data);
  7386. +}
  7387. +
  7388. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
  7389. +{
  7390. + void_list_elt_deinit((void_list_elt_t *) elt);
  7391. +}
  7392. +
  7393. +int nv_pair_list_init(nv_pair_list_t *list)
  7394. +{
  7395. + return void_list_init((void_list_t *) list);
  7396. +}
  7397. +
  7398. +void nv_pair_list_deinit(nv_pair_list_t *list)
  7399. +{
  7400. + nv_pair_list_elt_t *iter;
  7401. + nv_pair_t *nv_pair;
  7402. +
  7403. + for (iter = list->head; iter; iter = iter->next) {
  7404. + nv_pair = iter->data;
  7405. + nv_pair_deinit(nv_pair);
  7406. +
  7407. + /* malloced in nv_pair_list_append */
  7408. + free(nv_pair);
  7409. + iter->data = NULL;
  7410. + }
  7411. + void_list_deinit((void_list_t *) list);
  7412. +}
  7413. +
  7414. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
  7415. +{
  7416. + int err;
  7417. +
  7418. + /* freed in nv_pair_list_deinit */
  7419. + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
  7420. +
  7421. + if (nv_pair == NULL) {
  7422. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7423. + return NULL;
  7424. + }
  7425. + nv_pair_init(nv_pair, name, value);
  7426. +
  7427. + err = void_list_append((void_list_t *) list, nv_pair);
  7428. + if (err) {
  7429. + return NULL;
  7430. + }
  7431. +
  7432. + return nv_pair;
  7433. +}
  7434. +
  7435. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
  7436. +{
  7437. + return void_list_push((void_list_t *) list, data);
  7438. +}
  7439. +
  7440. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
  7441. +{
  7442. + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
  7443. +}
  7444. +
  7445. +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
  7446. +{
  7447. + nv_pair_list_elt_t *iter;
  7448. + nv_pair_t *nv_pair;
  7449. +
  7450. + for (iter = list->head; iter; iter = iter->next) {
  7451. + nv_pair = iter->data;
  7452. + if (strcmp(nv_pair->name, name) == 0) {
  7453. + return nv_pair->value;
  7454. + }
  7455. + }
  7456. + return NULL;
  7457. +}
  7458. diff -Nur busybox-1.15.2.orig/archival/libipkg/nv_pair_list.h busybox-1.15.2/archival/libipkg/nv_pair_list.h
  7459. --- busybox-1.15.2.orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
  7460. +++ busybox-1.15.2/archival/libipkg/nv_pair_list.h 2010-03-14 20:53:41.000000000 +0100
  7461. @@ -0,0 +1,60 @@
  7462. +/* nv_pair_list.h - the itsy package management system
  7463. +
  7464. + Carl D. Worth
  7465. +
  7466. + Copyright (C) 2001 University of Southern California
  7467. +
  7468. + This program is free software; you can redistribute it and/or
  7469. + modify it under the terms of the GNU General Public License as
  7470. + published by the Free Software Foundation; either version 2, or (at
  7471. + your option) any later version.
  7472. +
  7473. + This program is distributed in the hope that it will be useful, but
  7474. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7475. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7476. + General Public License for more details.
  7477. +*/
  7478. +
  7479. +#ifndef NV_PAIR_LIST_H
  7480. +#define NV_PAIR_LIST_H
  7481. +
  7482. +#include "nv_pair.h"
  7483. +#include "void_list.h"
  7484. +
  7485. +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
  7486. +struct nv_pair_list_elt
  7487. +{
  7488. + nv_pair_list_elt_t *next;
  7489. + nv_pair_t *data;
  7490. +};
  7491. +
  7492. +typedef struct nv_pair_list nv_pair_list_t;
  7493. +struct nv_pair_list
  7494. +{
  7495. + nv_pair_list_elt_t pre_head;
  7496. + nv_pair_list_elt_t *head;
  7497. + nv_pair_list_elt_t *tail;
  7498. +};
  7499. +
  7500. +static inline int nv_pair_list_empty(nv_pair_list_t *list)
  7501. +{
  7502. + if (list->head == NULL)
  7503. + return 1;
  7504. + else
  7505. + return 0;
  7506. +}
  7507. +
  7508. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
  7509. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
  7510. +
  7511. +int nv_pair_list_init(nv_pair_list_t *list);
  7512. +void nv_pair_list_deinit(nv_pair_list_t *list);
  7513. +
  7514. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
  7515. + const char *name, const char *value);
  7516. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
  7517. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
  7518. +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
  7519. +
  7520. +#endif
  7521. +
  7522. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg.c busybox-1.15.2/archival/libipkg/pkg.c
  7523. --- busybox-1.15.2.orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
  7524. +++ busybox-1.15.2/archival/libipkg/pkg.c 2010-03-14 20:53:41.000000000 +0100
  7525. @@ -0,0 +1,1757 @@
  7526. +/* pkg.c - the itsy package management system
  7527. +
  7528. + Carl D. Worth
  7529. +
  7530. + Copyright (C) 2001 University of Southern California
  7531. +
  7532. + This program is free software; you can redistribute it and/or
  7533. + modify it under the terms of the GNU General Public License as
  7534. + published by the Free Software Foundation; either version 2, or (at
  7535. + your option) any later version.
  7536. +
  7537. + This program is distributed in the hope that it will be useful, but
  7538. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7539. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7540. + General Public License for more details.
  7541. +*/
  7542. +
  7543. +#include "ipkg.h"
  7544. +#include <ctype.h>
  7545. +#include <string.h>
  7546. +#include <errno.h>
  7547. +
  7548. +#include "pkg.h"
  7549. +
  7550. +#include "pkg_parse.h"
  7551. +#include "pkg_extract.h"
  7552. +#include "ipkg_message.h"
  7553. +#include "ipkg_utils.h"
  7554. +
  7555. +#include "sprintf_alloc.h"
  7556. +#include "file_util.h"
  7557. +#include "str_util.h"
  7558. +#include "xsystem.h"
  7559. +#include "ipkg_conf.h"
  7560. +
  7561. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname);
  7562. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_);
  7563. +
  7564. +typedef struct enum_map enum_map_t;
  7565. +struct enum_map
  7566. +{
  7567. + int value;
  7568. + const char *str;
  7569. +};
  7570. +
  7571. +static const enum_map_t pkg_state_want_map[] = {
  7572. + { SW_UNKNOWN, "unknown"},
  7573. + { SW_INSTALL, "install"},
  7574. + { SW_DEINSTALL, "deinstall"},
  7575. + { SW_PURGE, "purge"}
  7576. +};
  7577. +
  7578. +static const enum_map_t pkg_state_flag_map[] = {
  7579. + { SF_OK, "ok"},
  7580. + { SF_REINSTREQ, "reinstreq"},
  7581. + { SF_HOLD, "hold"},
  7582. + { SF_REPLACE, "replace"},
  7583. + { SF_NOPRUNE, "noprune"},
  7584. + { SF_PREFER, "prefer"},
  7585. + { SF_OBSOLETE, "obsolete"},
  7586. + { SF_USER, "user"},
  7587. +};
  7588. +
  7589. +static const enum_map_t pkg_state_status_map[] = {
  7590. + { SS_NOT_INSTALLED, "not-installed" },
  7591. + { SS_UNPACKED, "unpacked" },
  7592. + { SS_HALF_CONFIGURED, "half-configured" },
  7593. + { SS_INSTALLED, "installed" },
  7594. + { SS_HALF_INSTALLED, "half-installed" },
  7595. + { SS_CONFIG_FILES, "config-files" },
  7596. + { SS_POST_INST_FAILED, "post-inst-failed" },
  7597. + { SS_REMOVAL_FAILED, "removal-failed" }
  7598. +};
  7599. +
  7600. +static int verrevcmp(const char *val, const char *ref);
  7601. +
  7602. +
  7603. +pkg_t *pkg_new(void)
  7604. +{
  7605. + pkg_t *pkg;
  7606. +
  7607. + pkg = malloc(sizeof(pkg_t));
  7608. + if (pkg == NULL) {
  7609. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7610. + return NULL;
  7611. + }
  7612. +
  7613. + pkg_init(pkg);
  7614. +
  7615. + return pkg;
  7616. +}
  7617. +
  7618. +int pkg_init(pkg_t *pkg)
  7619. +{
  7620. + memset(pkg, 0, sizeof(pkg_t));
  7621. + pkg->name = NULL;
  7622. + pkg->epoch = 0;
  7623. + pkg->version = NULL;
  7624. + pkg->revision = NULL;
  7625. + pkg->familiar_revision = NULL;
  7626. + pkg->dest = NULL;
  7627. + pkg->src = NULL;
  7628. + pkg->architecture = NULL;
  7629. + pkg->maintainer = NULL;
  7630. + pkg->section = NULL;
  7631. + pkg->description = NULL;
  7632. + pkg->state_want = SW_UNKNOWN;
  7633. + pkg->state_flag = SF_OK;
  7634. + pkg->state_status = SS_NOT_INSTALLED;
  7635. + pkg->depends_str = NULL;
  7636. + pkg->provides_str = NULL;
  7637. + pkg->depends_count = 0;
  7638. + pkg->depends = NULL;
  7639. + pkg->suggests_str = NULL;
  7640. + pkg->recommends_str = NULL;
  7641. + pkg->suggests_count = 0;
  7642. + pkg->recommends_count = 0;
  7643. +
  7644. + /* Abhaya: added init for conflicts fields */
  7645. + pkg->conflicts = NULL;
  7646. + pkg->conflicts_count = 0;
  7647. +
  7648. + /* added for replaces. Jamey 7/23/2002 */
  7649. + pkg->replaces = NULL;
  7650. + pkg->replaces_count = 0;
  7651. +
  7652. + pkg->pre_depends_count = 0;
  7653. + pkg->pre_depends_str = NULL;
  7654. + pkg->provides_count = 0;
  7655. + pkg->provides = NULL;
  7656. + pkg->filename = NULL;
  7657. + pkg->local_filename = NULL;
  7658. + pkg->tmp_unpack_dir = NULL;
  7659. + pkg->md5sum = NULL;
  7660. + pkg->size = NULL;
  7661. + pkg->installed_size = NULL;
  7662. + pkg->priority = NULL;
  7663. + pkg->source = NULL;
  7664. + conffile_list_init(&pkg->conffiles);
  7665. + pkg->installed_files = NULL;
  7666. + pkg->installed_files_ref_cnt = 0;
  7667. + pkg->essential = 0;
  7668. + pkg->provided_by_hand = 0;
  7669. +
  7670. + return 0;
  7671. +}
  7672. +
  7673. +void pkg_deinit(pkg_t *pkg)
  7674. +{
  7675. + free(pkg->name);
  7676. + pkg->name = NULL;
  7677. + pkg->epoch = 0;
  7678. + free(pkg->version);
  7679. + pkg->version = NULL;
  7680. + /* revision and familiar_revision share storage with version, so
  7681. + don't free */
  7682. + pkg->revision = NULL;
  7683. + pkg->familiar_revision = NULL;
  7684. + /* owned by ipkg_conf_t */
  7685. + pkg->dest = NULL;
  7686. + /* owned by ipkg_conf_t */
  7687. + pkg->src = NULL;
  7688. + free(pkg->architecture);
  7689. + pkg->architecture = NULL;
  7690. + free(pkg->maintainer);
  7691. + pkg->maintainer = NULL;
  7692. + free(pkg->section);
  7693. + pkg->section = NULL;
  7694. + free(pkg->description);
  7695. + pkg->description = NULL;
  7696. + pkg->state_want = SW_UNKNOWN;
  7697. + pkg->state_flag = SF_OK;
  7698. + pkg->state_status = SS_NOT_INSTALLED;
  7699. + free(pkg->depends_str);
  7700. + pkg->depends_str = NULL;
  7701. + free(pkg->provides_str);
  7702. + pkg->provides_str = NULL;
  7703. + pkg->depends_count = 0;
  7704. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
  7705. + pkg->pre_depends_count = 0;
  7706. + free(pkg->pre_depends_str);
  7707. + pkg->pre_depends_str = NULL;
  7708. + pkg->provides_count = 0;
  7709. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
  7710. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
  7711. + free(pkg->filename);
  7712. + pkg->filename = NULL;
  7713. + free(pkg->local_filename);
  7714. + pkg->local_filename = NULL;
  7715. + /* CLEANUP: It'd be nice to pullin the cleanup function from
  7716. + ipkg_install.c here. See comment in
  7717. + ipkg_install.c:cleanup_temporary_files */
  7718. + free(pkg->tmp_unpack_dir);
  7719. + pkg->tmp_unpack_dir = NULL;
  7720. + free(pkg->md5sum);
  7721. + pkg->md5sum = NULL;
  7722. + free(pkg->size);
  7723. + pkg->size = NULL;
  7724. + free(pkg->installed_size);
  7725. + pkg->installed_size = NULL;
  7726. + free(pkg->priority);
  7727. + pkg->priority = NULL;
  7728. + free(pkg->source);
  7729. + pkg->source = NULL;
  7730. + conffile_list_deinit(&pkg->conffiles);
  7731. + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
  7732. + since if they are calling deinit, they should know. Maybe do an
  7733. + assertion here instead? */
  7734. + pkg->installed_files_ref_cnt = 1;
  7735. + pkg_free_installed_files(pkg);
  7736. + pkg->essential = 0;
  7737. +}
  7738. +
  7739. +int pkg_init_from_file(pkg_t *pkg, const char *filename)
  7740. +{
  7741. + int err;
  7742. + char **raw;
  7743. + FILE *control_file;
  7744. +
  7745. + err = pkg_init(pkg);
  7746. + if (err) { return err; }
  7747. +
  7748. + pkg->local_filename = strdup(filename);
  7749. +
  7750. + control_file = tmpfile();
  7751. + err = pkg_extract_control_file_to_stream(pkg, control_file);
  7752. + if (err) { return err; }
  7753. +
  7754. + rewind(control_file);
  7755. + raw = read_raw_pkgs_from_stream(control_file);
  7756. + pkg_parse_raw(pkg, &raw, NULL, NULL);
  7757. +
  7758. + fclose(control_file);
  7759. +
  7760. + return 0;
  7761. +}
  7762. +
  7763. +/* Merge any new information in newpkg into oldpkg */
  7764. +/* XXX: CLEANUP: This function shouldn't actually modify anything in
  7765. + newpkg, but should leave it usable. This rework is so that
  7766. + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
  7767. +/*
  7768. + * uh, i thought that i had originally written this so that it took
  7769. + * two pkgs and returned a new one? we can do that again... -sma
  7770. + */
  7771. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
  7772. +{
  7773. + if (oldpkg == newpkg) {
  7774. + return 0;
  7775. + }
  7776. +
  7777. + if (!oldpkg->src)
  7778. + oldpkg->src = newpkg->src;
  7779. + if (!oldpkg->dest)
  7780. + oldpkg->dest = newpkg->dest;
  7781. + if (!oldpkg->architecture)
  7782. + oldpkg->architecture = str_dup_safe(newpkg->architecture);
  7783. + if (!oldpkg->arch_priority)
  7784. + oldpkg->arch_priority = newpkg->arch_priority;
  7785. + if (!oldpkg->section)
  7786. + oldpkg->section = str_dup_safe(newpkg->section);
  7787. + if(!oldpkg->maintainer)
  7788. + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
  7789. + if(!oldpkg->description)
  7790. + oldpkg->description = str_dup_safe(newpkg->description);
  7791. + if (set_status) {
  7792. + /* merge the state_flags from the new package */
  7793. + oldpkg->state_want = newpkg->state_want;
  7794. + oldpkg->state_status = newpkg->state_status;
  7795. + oldpkg->state_flag = newpkg->state_flag;
  7796. + } else {
  7797. + if (oldpkg->state_want == SW_UNKNOWN)
  7798. + oldpkg->state_want = newpkg->state_want;
  7799. + if (oldpkg->state_status == SS_NOT_INSTALLED)
  7800. + oldpkg->state_status = newpkg->state_status;
  7801. + oldpkg->state_flag |= newpkg->state_flag;
  7802. + }
  7803. +
  7804. + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
  7805. + oldpkg->depends_str = newpkg->depends_str;
  7806. + newpkg->depends_str = NULL;
  7807. + oldpkg->depends_count = newpkg->depends_count;
  7808. + newpkg->depends_count = 0;
  7809. +
  7810. + oldpkg->depends = newpkg->depends;
  7811. + newpkg->depends = NULL;
  7812. +
  7813. + oldpkg->pre_depends_str = newpkg->pre_depends_str;
  7814. + newpkg->pre_depends_str = NULL;
  7815. + oldpkg->pre_depends_count = newpkg->pre_depends_count;
  7816. + newpkg->pre_depends_count = 0;
  7817. +
  7818. + oldpkg->recommends_str = newpkg->recommends_str;
  7819. + newpkg->recommends_str = NULL;
  7820. + oldpkg->recommends_count = newpkg->recommends_count;
  7821. + newpkg->recommends_count = 0;
  7822. +
  7823. + oldpkg->suggests_str = newpkg->suggests_str;
  7824. + newpkg->suggests_str = NULL;
  7825. + oldpkg->suggests_count = newpkg->suggests_count;
  7826. + newpkg->suggests_count = 0;
  7827. + }
  7828. +
  7829. + if (!oldpkg->provides_str) {
  7830. + oldpkg->provides_str = newpkg->provides_str;
  7831. + newpkg->provides_str = NULL;
  7832. + oldpkg->provides_count = newpkg->provides_count;
  7833. + newpkg->provides_count = 0;
  7834. +
  7835. + oldpkg->provides = newpkg->provides;
  7836. + newpkg->provides = NULL;
  7837. + }
  7838. +
  7839. + if (!oldpkg->conflicts_str) {
  7840. + oldpkg->conflicts_str = newpkg->conflicts_str;
  7841. + newpkg->conflicts_str = NULL;
  7842. + oldpkg->conflicts_count = newpkg->conflicts_count;
  7843. + newpkg->conflicts_count = 0;
  7844. +
  7845. + oldpkg->conflicts = newpkg->conflicts;
  7846. + newpkg->conflicts = NULL;
  7847. + }
  7848. +
  7849. + if (!oldpkg->replaces_str) {
  7850. + oldpkg->replaces_str = newpkg->replaces_str;
  7851. + newpkg->replaces_str = NULL;
  7852. + oldpkg->replaces_count = newpkg->replaces_count;
  7853. + newpkg->replaces_count = 0;
  7854. +
  7855. + oldpkg->replaces = newpkg->replaces;
  7856. + newpkg->replaces = NULL;
  7857. + }
  7858. +
  7859. + if (!oldpkg->filename)
  7860. + oldpkg->filename = str_dup_safe(newpkg->filename);
  7861. + if (0)
  7862. + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
  7863. + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
  7864. + if (!oldpkg->local_filename)
  7865. + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
  7866. + if (!oldpkg->tmp_unpack_dir)
  7867. + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
  7868. + if (!oldpkg->md5sum)
  7869. + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
  7870. + if (!oldpkg->size)
  7871. + oldpkg->size = str_dup_safe(newpkg->size);
  7872. + if (!oldpkg->installed_size)
  7873. + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
  7874. + if (!oldpkg->priority)
  7875. + oldpkg->priority = str_dup_safe(newpkg->priority);
  7876. + if (!oldpkg->source)
  7877. + oldpkg->source = str_dup_safe(newpkg->source);
  7878. + if (oldpkg->conffiles.head == NULL){
  7879. + oldpkg->conffiles = newpkg->conffiles;
  7880. + conffile_list_init(&newpkg->conffiles);
  7881. + }
  7882. + if (!oldpkg->installed_files){
  7883. + oldpkg->installed_files = newpkg->installed_files;
  7884. + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
  7885. + newpkg->installed_files = NULL;
  7886. + }
  7887. + if (!oldpkg->essential)
  7888. + oldpkg->essential = newpkg->essential;
  7889. +
  7890. + return 0;
  7891. +}
  7892. +
  7893. +abstract_pkg_t *abstract_pkg_new(void)
  7894. +{
  7895. + abstract_pkg_t * ab_pkg;
  7896. +
  7897. + ab_pkg = malloc(sizeof(abstract_pkg_t));
  7898. +
  7899. + if (ab_pkg == NULL) {
  7900. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7901. + return NULL;
  7902. + }
  7903. +
  7904. + if ( abstract_pkg_init(ab_pkg) < 0 )
  7905. + return NULL;
  7906. +
  7907. + return ab_pkg;
  7908. +}
  7909. +
  7910. +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
  7911. +{
  7912. + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
  7913. +
  7914. + ab_pkg->provided_by = abstract_pkg_vec_alloc();
  7915. + if (ab_pkg->provided_by==NULL){
  7916. + return -1;
  7917. + }
  7918. + ab_pkg->dependencies_checked = 0;
  7919. + ab_pkg->state_status = SS_NOT_INSTALLED;
  7920. +
  7921. + return 0;
  7922. +}
  7923. +
  7924. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
  7925. + char * temp_str;
  7926. + char **raw =NULL;
  7927. + char **raw_start=NULL;
  7928. +
  7929. + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
  7930. + if (temp_str == NULL ){
  7931. + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
  7932. + return;
  7933. + }
  7934. + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
  7935. +
  7936. + raw = raw_start = read_raw_pkgs_from_file(temp_str);
  7937. + if (raw == NULL ){
  7938. + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
  7939. + return;
  7940. + }
  7941. +
  7942. + while(*raw){
  7943. + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
  7944. + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
  7945. + }
  7946. + }
  7947. + raw = raw_start;
  7948. + while (*raw) {
  7949. + if (raw!=NULL)
  7950. + free(*raw++);
  7951. + }
  7952. +
  7953. + free(raw_start);
  7954. + free(temp_str);
  7955. +
  7956. + return ;
  7957. +
  7958. +}
  7959. +
  7960. +char * pkg_formatted_info(pkg_t *pkg )
  7961. +{
  7962. + char *line;
  7963. + char * buff;
  7964. +
  7965. + buff = malloc(8192);
  7966. + if (buff == NULL) {
  7967. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7968. + return NULL;
  7969. + }
  7970. +
  7971. + buff[0] = '\0';
  7972. +
  7973. + line = pkg_formatted_field(pkg, "Package");
  7974. + strncat(buff ,line, strlen(line));
  7975. + free(line);
  7976. +
  7977. + line = pkg_formatted_field(pkg, "Version");
  7978. + strncat(buff ,line, strlen(line));
  7979. + free(line);
  7980. +
  7981. + line = pkg_formatted_field(pkg, "Depends");
  7982. + strncat(buff ,line, strlen(line));
  7983. + free(line);
  7984. +
  7985. + line = pkg_formatted_field(pkg, "Recommends");
  7986. + strncat(buff ,line, strlen(line));
  7987. + free(line);
  7988. +
  7989. + line = pkg_formatted_field(pkg, "Suggests");
  7990. + strncat(buff ,line, strlen(line));
  7991. + free(line);
  7992. +
  7993. + line = pkg_formatted_field(pkg, "Provides");
  7994. + strncat(buff ,line, strlen(line));
  7995. + free(line);
  7996. +
  7997. + line = pkg_formatted_field(pkg, "Replaces");
  7998. + strncat(buff ,line, strlen(line));
  7999. + free(line);
  8000. +
  8001. + line = pkg_formatted_field(pkg, "Conflicts");
  8002. + strncat(buff ,line, strlen(line));
  8003. + free(line);
  8004. +
  8005. + line = pkg_formatted_field(pkg, "Status");
  8006. + strncat(buff ,line, strlen(line));
  8007. + free(line);
  8008. +
  8009. + line = pkg_formatted_field(pkg, "Section");
  8010. + strncat(buff ,line, strlen(line));
  8011. + free(line);
  8012. +
  8013. + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
  8014. + strncat(buff ,line, strlen(line));
  8015. + free(line);
  8016. +
  8017. + line = pkg_formatted_field(pkg, "Architecture");
  8018. + strncat(buff ,line, strlen(line));
  8019. + free(line);
  8020. +
  8021. + line = pkg_formatted_field(pkg, "Maintainer");
  8022. + strncat(buff ,line, strlen(line));
  8023. + free(line);
  8024. +
  8025. + line = pkg_formatted_field(pkg, "MD5sum");
  8026. + strncat(buff ,line, strlen(line));
  8027. + free(line);
  8028. +
  8029. + line = pkg_formatted_field(pkg, "Size");
  8030. + strncat(buff ,line, strlen(line));
  8031. + free(line);
  8032. +
  8033. + line = pkg_formatted_field(pkg, "Filename");
  8034. + strncat(buff ,line, strlen(line));
  8035. + free(line);
  8036. +
  8037. + line = pkg_formatted_field(pkg, "Conffiles");
  8038. + strncat(buff ,line, strlen(line));
  8039. + free(line);
  8040. +
  8041. + line = pkg_formatted_field(pkg, "Source");
  8042. + strncat(buff ,line, strlen(line));
  8043. + free(line);
  8044. +
  8045. + line = pkg_formatted_field(pkg, "Description");
  8046. + strncat(buff ,line, strlen(line));
  8047. + free(line);
  8048. +
  8049. + line = pkg_formatted_field(pkg, "Installed-Time");
  8050. + strncat(buff ,line, strlen(line));
  8051. + free(line);
  8052. +
  8053. + return buff;
  8054. +}
  8055. +
  8056. +char * pkg_formatted_field(pkg_t *pkg, const char *field )
  8057. +{
  8058. + static size_t LINE_LEN = 128;
  8059. + char * temp = (char *)malloc(1);
  8060. + int len = 0;
  8061. + int flag_provide_false = 0;
  8062. +
  8063. +/*
  8064. + Pigi: After some discussion with Florian we decided to modify the full procedure in
  8065. + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
  8066. +*/
  8067. +
  8068. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8069. + goto UNKNOWN_FMT_FIELD;
  8070. + }
  8071. +
  8072. + temp[0]='\0';
  8073. +
  8074. + switch (field[0])
  8075. + {
  8076. + case 'a':
  8077. + case 'A':
  8078. + if (strcasecmp(field, "Architecture") == 0) {
  8079. + /* Architecture */
  8080. + if (pkg->architecture) {
  8081. + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
  8082. + if ( temp == NULL ){
  8083. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8084. + return NULL;
  8085. + }
  8086. + temp[0]='\0';
  8087. + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
  8088. + }
  8089. + } else {
  8090. + goto UNKNOWN_FMT_FIELD;
  8091. + }
  8092. + break;
  8093. + case 'c':
  8094. + case 'C':
  8095. + if (strcasecmp(field, "Conffiles") == 0) {
  8096. + /* Conffiles */
  8097. + conffile_list_elt_t *iter;
  8098. + char confstr_[LINE_LEN];
  8099. +
  8100. + if (pkg->conffiles.head == NULL) {
  8101. + return temp;
  8102. + }
  8103. +
  8104. + len = 14 ;
  8105. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8106. + if (iter->data->name && iter->data->value) {
  8107. + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
  8108. + }
  8109. + }
  8110. + temp = (char *)realloc(temp,len);
  8111. + if ( temp == NULL ){
  8112. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8113. + return NULL;
  8114. + }
  8115. + temp[0]='\0';
  8116. + strncpy(temp, "Conffiles:\n", 12);
  8117. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8118. + if (iter->data->name && iter->data->value) {
  8119. + snprintf(confstr_, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
  8120. + strncat(temp, confstr_, strlen(confstr_));
  8121. + }
  8122. + }
  8123. + } else if (strcasecmp(field, "Conflicts") == 0) {
  8124. + int i;
  8125. +
  8126. + if (pkg->conflicts_count) {
  8127. + char conflictstr[LINE_LEN];
  8128. + len = 14 ;
  8129. + for(i = 0; i < pkg->conflicts_count; i++) {
  8130. + len = len + (strlen(pkg->conflicts_str[i])+5);
  8131. + }
  8132. + temp = (char *)realloc(temp,len);
  8133. + if ( temp == NULL ){
  8134. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8135. + return NULL;
  8136. + }
  8137. + temp[0]='\0';
  8138. + strncpy(temp, "Conflicts:", 11);
  8139. + for(i = 0; i < pkg->conflicts_count; i++) {
  8140. + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
  8141. + strncat(temp, conflictstr, strlen(conflictstr));
  8142. + }
  8143. + strncat(temp, "\n", strlen("\n"));
  8144. + }
  8145. + } else {
  8146. + goto UNKNOWN_FMT_FIELD;
  8147. + }
  8148. + break;
  8149. + case 'd':
  8150. + case 'D':
  8151. + if (strcasecmp(field, "Depends") == 0) {
  8152. + /* Depends */
  8153. + int i;
  8154. +
  8155. + if (pkg->depends_count) {
  8156. + char depstr[LINE_LEN];
  8157. + len = 14 ;
  8158. + for(i = 0; i < pkg->depends_count; i++) {
  8159. + len = len + (strlen(pkg->depends_str[i])+4);
  8160. + }
  8161. + temp = (char *)realloc(temp,len);
  8162. + if ( temp == NULL ){
  8163. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8164. + return NULL;
  8165. + }
  8166. + temp[0]='\0';
  8167. + strncpy(temp, "Depends:", 10);
  8168. + for(i = 0; i < pkg->depends_count; i++) {
  8169. + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
  8170. + strncat(temp, depstr, strlen(depstr));
  8171. + }
  8172. + strncat(temp, "\n", strlen("\n"));
  8173. + }
  8174. + } else if (strcasecmp(field, "Description") == 0) {
  8175. + /* Description */
  8176. + if (pkg->description) {
  8177. + temp = (char *)realloc(temp,strlen(pkg->description)+16);
  8178. + if ( temp == NULL ){
  8179. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8180. + return NULL;
  8181. + }
  8182. + temp[0]='\0';
  8183. + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
  8184. + }
  8185. + } else {
  8186. + goto UNKNOWN_FMT_FIELD;
  8187. + }
  8188. + break;
  8189. + case 'e':
  8190. + case 'E': {
  8191. + /* Essential */
  8192. + if (pkg->essential) {
  8193. + temp = (char *)realloc(temp,16);
  8194. + if ( temp == NULL ){
  8195. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8196. + return NULL;
  8197. + }
  8198. + temp[0]='\0';
  8199. + snprintf(temp, (16), "Essential: yes\n");
  8200. + }
  8201. + }
  8202. + break;
  8203. + case 'f':
  8204. + case 'F': {
  8205. + /* Filename */
  8206. + if (pkg->filename) {
  8207. + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
  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->filename)+12), "Filename: %s\n", pkg->filename);
  8214. + }
  8215. + }
  8216. + break;
  8217. + case 'i':
  8218. + case 'I': {
  8219. + if (strcasecmp(field, "Installed-Size") == 0) {
  8220. + /* Installed-Size */
  8221. + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
  8222. + if ( temp == NULL ){
  8223. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8224. + return NULL;
  8225. + }
  8226. + temp[0]='\0';
  8227. + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
  8228. + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
  8229. + temp = (char *)realloc(temp,29);
  8230. + if ( temp == NULL ){
  8231. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8232. + return NULL;
  8233. + }
  8234. + temp[0]='\0';
  8235. + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
  8236. + }
  8237. + }
  8238. + break;
  8239. + case 'm':
  8240. + case 'M': {
  8241. + /* Maintainer | MD5sum */
  8242. + if (strcasecmp(field, "Maintainer") == 0) {
  8243. + /* Maintainer */
  8244. + if (pkg->maintainer) {
  8245. + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
  8246. + if ( temp == NULL ){
  8247. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8248. + return NULL;
  8249. + }
  8250. + temp[0]='\0';
  8251. + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
  8252. + }
  8253. + } else if (strcasecmp(field, "MD5sum") == 0) {
  8254. + /* MD5sum */
  8255. + if (pkg->md5sum) {
  8256. + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
  8257. + if ( temp == NULL ){
  8258. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8259. + return NULL;
  8260. + }
  8261. + temp[0]='\0';
  8262. + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
  8263. + }
  8264. + } else {
  8265. + goto UNKNOWN_FMT_FIELD;
  8266. + }
  8267. + }
  8268. + break;
  8269. + case 'p':
  8270. + case 'P': {
  8271. + if (strcasecmp(field, "Package") == 0) {
  8272. + /* Package */
  8273. + temp = (char *)realloc(temp,strlen(pkg->name)+11);
  8274. + if ( temp == NULL ){
  8275. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8276. + return NULL;
  8277. + }
  8278. + temp[0]='\0';
  8279. + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
  8280. + } else if (strcasecmp(field, "Priority") == 0) {
  8281. + /* Priority */
  8282. + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
  8283. + if ( temp == NULL ){
  8284. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8285. + return NULL;
  8286. + }
  8287. + temp[0]='\0';
  8288. + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
  8289. + } else if (strcasecmp(field, "Provides") == 0) {
  8290. + /* Provides */
  8291. + int i;
  8292. +
  8293. + if (pkg->provides_count) {
  8294. + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
  8295. + for ( i=0; i < pkg->provides_count; i++ ){
  8296. + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
  8297. + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
  8298. + flag_provide_false = 1;
  8299. + }
  8300. + }
  8301. + if ( !flag_provide_false || /* Pigi there is not my trick flag */
  8302. + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
  8303. + char provstr[LINE_LEN];
  8304. + len = 15;
  8305. + for(i = 0; i < pkg->provides_count; i++) {
  8306. + len = len + (strlen(pkg->provides_str[i])+5);
  8307. + }
  8308. + temp = (char *)realloc(temp,len);
  8309. + if ( temp == NULL ){
  8310. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8311. + return NULL;
  8312. + }
  8313. + temp[0]='\0';
  8314. + strncpy(temp, "Provides:", 12);
  8315. + for(i = 0; i < pkg->provides_count; i++) {
  8316. + if (strlen(pkg->provides_str[i])>0){;
  8317. + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
  8318. + strncat(temp, provstr, strlen(provstr));
  8319. + }
  8320. + }
  8321. + strncat(temp, "\n", strlen("\n"));
  8322. + }
  8323. + }
  8324. + } else {
  8325. + goto UNKNOWN_FMT_FIELD;
  8326. + }
  8327. + }
  8328. + break;
  8329. + case 'r':
  8330. + case 'R': {
  8331. + int i;
  8332. + /* Replaces | Recommends*/
  8333. + if (strcasecmp (field, "Replaces") == 0) {
  8334. + if (pkg->replaces_count) {
  8335. + char replstr[LINE_LEN];
  8336. + len = 14;
  8337. + for (i = 0; i < pkg->replaces_count; i++) {
  8338. + len = len + (strlen(pkg->replaces_str[i])+5);
  8339. + }
  8340. + temp = (char *)realloc(temp,len);
  8341. + if ( temp == NULL ){
  8342. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8343. + return NULL;
  8344. + }
  8345. + temp[0]='\0';
  8346. + strncpy(temp, "Replaces:", 12);
  8347. + for (i = 0; i < pkg->replaces_count; i++) {
  8348. + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
  8349. + strncat(temp, replstr, strlen(replstr));
  8350. + }
  8351. + strncat(temp, "\n", strlen("\n"));
  8352. + }
  8353. + } else if (strcasecmp (field, "Recommends") == 0) {
  8354. + if (pkg->recommends_count) {
  8355. + char recstr[LINE_LEN];
  8356. + len = 15;
  8357. + for(i = 0; i < pkg->recommends_count; i++) {
  8358. + len = len + (strlen( pkg->recommends_str[i])+5);
  8359. + }
  8360. + temp = (char *)realloc(temp,len);
  8361. + if ( temp == NULL ){
  8362. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8363. + return NULL;
  8364. + }
  8365. + temp[0]='\0';
  8366. + strncpy(temp, "Recommends:", 13);
  8367. + for(i = 0; i < pkg->recommends_count; i++) {
  8368. + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
  8369. + strncat(temp, recstr, strlen(recstr));
  8370. + }
  8371. + strncat(temp, "\n", strlen("\n"));
  8372. + }
  8373. + } else {
  8374. + goto UNKNOWN_FMT_FIELD;
  8375. + }
  8376. + }
  8377. + break;
  8378. + case 's':
  8379. + case 'S': {
  8380. + /* Section | Size | Source | Status | Suggests */
  8381. + if (strcasecmp(field, "Section") == 0) {
  8382. + /* Section */
  8383. + if (pkg->section) {
  8384. + temp = (char *)realloc(temp,strlen(pkg->section)+11);
  8385. + if ( temp == NULL ){
  8386. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8387. + return NULL;
  8388. + }
  8389. + temp[0]='\0';
  8390. + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
  8391. + }
  8392. + } else if (strcasecmp(field, "Size") == 0) {
  8393. + /* Size */
  8394. + if (pkg->size) {
  8395. + temp = (char *)realloc(temp,strlen(pkg->size)+8);
  8396. + if ( temp == NULL ){
  8397. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8398. + return NULL;
  8399. + }
  8400. + temp[0]='\0';
  8401. + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
  8402. + }
  8403. + } else if (strcasecmp(field, "Source") == 0) {
  8404. + /* Source */
  8405. + if (pkg->source) {
  8406. + temp = (char *)realloc(temp,strlen(pkg->source)+10);
  8407. + if ( temp == NULL ){
  8408. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8409. + return NULL;
  8410. + }
  8411. + temp[0]='\0';
  8412. + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
  8413. + }
  8414. + } else if (strcasecmp(field, "Status") == 0) {
  8415. + /* Status */
  8416. + /* Benjamin Pineau note: we should avoid direct usage of
  8417. + * strlen(arg) without keeping "arg" for later free()
  8418. + */
  8419. + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
  8420. + char *pstat=pkg_state_status_to_str(pkg->state_status);
  8421. + char *pwant=pkg_state_want_to_str(pkg->state_want);
  8422. +
  8423. + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
  8424. + temp = (char *)realloc(temp,sum_of_sizes);
  8425. + if ( temp == NULL ){
  8426. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8427. + return NULL;
  8428. + }
  8429. + temp[0]='\0';
  8430. + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
  8431. + free(pflag);
  8432. + free(pwant);
  8433. + if(pstat) /* pfstat can be NULL if ENOMEM */
  8434. + free(pstat);
  8435. + } else if (strcasecmp(field, "Suggests") == 0) {
  8436. + if (pkg->suggests_count) {
  8437. + int i;
  8438. + char sugstr[LINE_LEN];
  8439. + len = 13;
  8440. + for(i = 0; i < pkg->suggests_count; i++) {
  8441. + len = len + (strlen(pkg->suggests_str[i])+5);
  8442. + }
  8443. + temp = (char *)realloc(temp,len);
  8444. + if ( temp == NULL ){
  8445. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8446. + return NULL;
  8447. + }
  8448. + temp[0]='\0';
  8449. + strncpy(temp, "Suggests:", 10);
  8450. + for(i = 0; i < pkg->suggests_count; i++) {
  8451. + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
  8452. + strncat(temp, sugstr, strlen(sugstr));
  8453. + }
  8454. + strncat(temp, "\n", strlen("\n"));
  8455. + }
  8456. + } else {
  8457. + goto UNKNOWN_FMT_FIELD;
  8458. + }
  8459. + }
  8460. + break;
  8461. + case 'v':
  8462. + case 'V': {
  8463. + /* Version */
  8464. + char *version = pkg_version_str_alloc(pkg);
  8465. + temp = (char *)realloc(temp,strlen(version)+14);
  8466. + if ( temp == NULL ){
  8467. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8468. + return NULL;
  8469. + }
  8470. + temp[0]='\0';
  8471. + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
  8472. + free(version);
  8473. + }
  8474. + break;
  8475. + default:
  8476. + goto UNKNOWN_FMT_FIELD;
  8477. + }
  8478. +
  8479. + if ( strlen(temp)<2 ) {
  8480. + temp[0]='\0';
  8481. + }
  8482. + return temp;
  8483. +
  8484. + UNKNOWN_FMT_FIELD:
  8485. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
  8486. + if ( strlen(temp)<2 ) {
  8487. + temp[0]='\0';
  8488. + }
  8489. +
  8490. + return temp;
  8491. +}
  8492. +
  8493. +void pkg_print_info(pkg_t *pkg, FILE *file)
  8494. +{
  8495. + char * buff;
  8496. + if (pkg == NULL) {
  8497. + return;
  8498. + }
  8499. +
  8500. + buff = pkg_formatted_info(pkg);
  8501. + if ( buff == NULL )
  8502. + return;
  8503. + if (strlen(buff)>2){
  8504. + fwrite(buff, 1, strlen(buff), file);
  8505. + }
  8506. + free(buff);
  8507. +}
  8508. +
  8509. +void pkg_print_status(pkg_t * pkg, FILE * file)
  8510. +{
  8511. + if (pkg == NULL) {
  8512. + return;
  8513. + }
  8514. +
  8515. + /* XXX: QUESTION: Do we actually want more fields here? The
  8516. + original idea was to save space by installing only what was
  8517. + needed for actual computation, (package, version, status,
  8518. + essential, conffiles). The assumption is that all other fields
  8519. + can be found in th available file.
  8520. +
  8521. + But, someone proposed the idea to make it possible to
  8522. + reconstruct a .ipk from an installed package, (ie. for beaming
  8523. + from one handheld to another). So, maybe we actually want a few
  8524. + more fields here, (depends, suggests, etc.), so that that would
  8525. + be guaranteed to work even in the absence of more information
  8526. + from the available file.
  8527. +
  8528. + 28-MAR-03: kergoth and I discussed this yesterday. We think
  8529. + the essential info needs to be here for all installed packages
  8530. + because they may not appear in the Packages files on various
  8531. + feeds. Furthermore, one should be able to install from URL or
  8532. + local storage without requiring a Packages file from any feed.
  8533. + -Jamey
  8534. + */
  8535. + pkg_print_field(pkg, file, "Package");
  8536. + pkg_print_field(pkg, file, "Version");
  8537. + pkg_print_field(pkg, file, "Depends");
  8538. + pkg_print_field(pkg, file, "Recommends");
  8539. + pkg_print_field(pkg, file, "Suggests");
  8540. + pkg_print_field(pkg, file, "Provides");
  8541. + pkg_print_field(pkg, file, "Replaces");
  8542. + pkg_print_field(pkg, file, "Conflicts");
  8543. + pkg_print_field(pkg, file, "Status");
  8544. + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
  8545. + pkg_print_field(pkg, file, "Architecture");
  8546. + pkg_print_field(pkg, file, "Conffiles");
  8547. + pkg_print_field(pkg, file, "Installed-Time");
  8548. + fputs("\n", file);
  8549. +}
  8550. +
  8551. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
  8552. +{
  8553. + char *buff;
  8554. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8555. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
  8556. + __FUNCTION__, field);
  8557. + }
  8558. + buff = pkg_formatted_field(pkg, field);
  8559. + if (strlen(buff)>2) {
  8560. + fprintf(file, "%s", buff);
  8561. + fflush(file);
  8562. + }
  8563. + free(buff);
  8564. + return;
  8565. +}
  8566. +
  8567. +/*
  8568. + * libdpkg - Debian packaging suite library routines
  8569. + * vercmp.c - comparison of version numbers
  8570. + *
  8571. + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  8572. + */
  8573. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
  8574. +{
  8575. + int r;
  8576. +
  8577. + if (pkg->epoch > ref_pkg->epoch) {
  8578. + return 1;
  8579. + }
  8580. +
  8581. + if (pkg->epoch < ref_pkg->epoch) {
  8582. + return -1;
  8583. + }
  8584. +
  8585. + r = verrevcmp(pkg->version, ref_pkg->version);
  8586. + if (r) {
  8587. + return r;
  8588. + }
  8589. +
  8590. +#ifdef USE_DEBVERSION
  8591. + r = verrevcmp(pkg->revision, ref_pkg->revision);
  8592. + if (r) {
  8593. + return r;
  8594. + }
  8595. +
  8596. + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
  8597. +#endif
  8598. +
  8599. + return r;
  8600. +}
  8601. +
  8602. +int verrevcmp(const char *val, const char *ref)
  8603. +{
  8604. + int vc, rc;
  8605. + long vl, rl;
  8606. + const char *vp, *rp;
  8607. + const char *vsep, *rsep;
  8608. +
  8609. + if (!val) val= "";
  8610. + if (!ref) ref= "";
  8611. + for (;;) {
  8612. + vp= val; while (*vp && !isdigit(*vp)) vp++;
  8613. + rp= ref; while (*rp && !isdigit(*rp)) rp++;
  8614. + for (;;) {
  8615. + vc= (val == vp) ? 0 : *val++;
  8616. + rc= (ref == rp) ? 0 : *ref++;
  8617. + if (!rc && !vc) break;
  8618. + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
  8619. + if (rc && !isalpha(rc)) rc += 256;
  8620. + if (vc != rc) return vc - rc;
  8621. + }
  8622. + val= vp;
  8623. + ref= rp;
  8624. + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
  8625. + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
  8626. + if (vl != rl) return vl - rl;
  8627. +
  8628. + vc = *val;
  8629. + rc = *ref;
  8630. + vsep = strchr(".-", vc);
  8631. + rsep = strchr(".-", rc);
  8632. + if (vsep && !rsep) return -1;
  8633. + if (!vsep && rsep) return +1;
  8634. +
  8635. + if (!*val && !*ref) return 0;
  8636. + if (!*val) return -1;
  8637. + if (!*ref) return +1;
  8638. + }
  8639. +}
  8640. +
  8641. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
  8642. +{
  8643. + int r;
  8644. +
  8645. + r = pkg_compare_versions(it, ref);
  8646. +
  8647. + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
  8648. + return r <= 0;
  8649. + }
  8650. +
  8651. + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
  8652. + return r >= 0;
  8653. + }
  8654. +
  8655. + if (strcmp(op, "<<") == 0) {
  8656. + return r < 0;
  8657. + }
  8658. +
  8659. + if (strcmp(op, ">>") == 0) {
  8660. + return r > 0;
  8661. + }
  8662. +
  8663. + if (strcmp(op, "=") == 0) {
  8664. + return r == 0;
  8665. + }
  8666. +
  8667. + fprintf(stderr, "unknown operator: %s", op);
  8668. + return 0;
  8669. +}
  8670. +
  8671. +int pkg_name_version_and_architecture_compare(pkg_t *p1, pkg_t *p2)
  8672. +{
  8673. + const pkg_t *a = *(const pkg_t **)p1;
  8674. + const pkg_t *b = *(const pkg_t **)p2;
  8675. + int namecmp;
  8676. + int vercmp;
  8677. + if (!a->name || !b->name) {
  8678. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8679. + a, a->name, b, b->name);
  8680. + return 0;
  8681. + }
  8682. +
  8683. + namecmp = strcmp(a->name, b->name);
  8684. + if (namecmp)
  8685. + return namecmp;
  8686. + vercmp = pkg_compare_versions(a, b);
  8687. + if (vercmp)
  8688. + return vercmp;
  8689. + if (!a->arch_priority || !b->arch_priority) {
  8690. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
  8691. + a, a->arch_priority, b, b->arch_priority);
  8692. + return 0;
  8693. + }
  8694. + if (a->arch_priority > b->arch_priority)
  8695. + return 1;
  8696. + if (a->arch_priority < b->arch_priority)
  8697. + return -1;
  8698. + return 0;
  8699. +}
  8700. +
  8701. +int abstract_pkg_name_compare(abstract_pkg_t *p1, abstract_pkg_t *p2)
  8702. +{
  8703. + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
  8704. + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
  8705. + if (!a->name || !b->name) {
  8706. + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8707. + a, a->name, b, b->name);
  8708. + return 0;
  8709. + }
  8710. + return strcmp(a->name, b->name);
  8711. +}
  8712. +
  8713. +
  8714. +char *pkg_version_str_alloc(pkg_t *pkg)
  8715. +{
  8716. + char *complete_version;
  8717. + char *epoch_str;
  8718. +#ifdef USE_DEBVERSION
  8719. + char *revision_str;
  8720. + char *familiar_revision_str;
  8721. +#endif
  8722. +
  8723. + if (pkg->epoch) {
  8724. + sprintf_alloc(&epoch_str, "%lu:", (unsigned long)pkg->epoch);
  8725. + } else {
  8726. + epoch_str = strdup("");
  8727. + }
  8728. +
  8729. +#ifdef USE_DEBVERSION
  8730. + if (pkg->revision && strlen(pkg->revision)) {
  8731. + sprintf_alloc(&revision_str, "-%s", pkg->revision);
  8732. + } else {
  8733. + revision_str = strdup("");
  8734. + }
  8735. +
  8736. + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
  8737. + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
  8738. + } else {
  8739. + familiar_revision_str = strdup("");
  8740. + }
  8741. +#endif
  8742. +
  8743. +#ifdef USE_DEBVERSION
  8744. + sprintf_alloc(&complete_version, "%s%s%s%s",
  8745. + epoch_str, pkg->version, revision_str, familiar_revision_str);
  8746. +#else
  8747. + sprintf_alloc(&complete_version, "%s%s",
  8748. + epoch_str, pkg->version);
  8749. +#endif
  8750. +
  8751. + free(epoch_str);
  8752. +#ifdef USE_DEBVERSION
  8753. + free(revision_str);
  8754. + free(familiar_revision_str);
  8755. +#endif
  8756. +
  8757. + return complete_version;
  8758. +}
  8759. +
  8760. +str_list_t *pkg_get_installed_files(pkg_t *pkg)
  8761. +{
  8762. + int err;
  8763. + char *list_file_name = NULL;
  8764. + FILE *list_file = NULL;
  8765. + char *line;
  8766. + char *installed_file_name;
  8767. + int rootdirlen;
  8768. +
  8769. + pkg->installed_files_ref_cnt++;
  8770. +
  8771. + if (pkg->installed_files) {
  8772. + return pkg->installed_files;
  8773. + }
  8774. +
  8775. + pkg->installed_files = str_list_alloc();
  8776. + if (pkg->installed_files == NULL) {
  8777. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8778. + return NULL;
  8779. + }
  8780. +
  8781. + /* For uninstalled packages, get the file list firectly from the package.
  8782. + For installed packages, look at the package.list file in the database.
  8783. + */
  8784. + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
  8785. + if (pkg->local_filename == NULL) {
  8786. + return pkg->installed_files;
  8787. + }
  8788. + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
  8789. + file. In other words, change deb_extract so that it can
  8790. + simply return the file list as a char *[] rather than
  8791. + insisting on writing in to a FILE * as it does now. */
  8792. + list_file = tmpfile();
  8793. + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
  8794. + if (err) {
  8795. + fclose(list_file);
  8796. + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
  8797. + __FUNCTION__, pkg->local_filename, strerror(err));
  8798. + return pkg->installed_files;
  8799. + }
  8800. + rewind(list_file);
  8801. + } else {
  8802. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8803. + pkg->dest->info_dir, pkg->name);
  8804. + if (! file_exists(list_file_name)) {
  8805. + free(list_file_name);
  8806. + return pkg->installed_files;
  8807. + }
  8808. +
  8809. + list_file = fopen(list_file_name, "r");
  8810. + if (list_file == NULL) {
  8811. + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
  8812. + list_file_name, strerror(errno));
  8813. + free(list_file_name);
  8814. + return pkg->installed_files;
  8815. + }
  8816. + free(list_file_name);
  8817. + }
  8818. +
  8819. + rootdirlen = strlen( pkg->dest->root_dir );
  8820. + while (1) {
  8821. + char *file_name;
  8822. +
  8823. + line = file_read_line_alloc(list_file);
  8824. + if (line == NULL) {
  8825. + break;
  8826. + }
  8827. + str_chomp(line);
  8828. + file_name = line;
  8829. +
  8830. + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
  8831. + if( strncmp( pkg->dest->root_dir,
  8832. + file_name,
  8833. + rootdirlen ) ) {
  8834. + if (*file_name == '.') {
  8835. + file_name++;
  8836. + }
  8837. + if (*file_name == '/') {
  8838. + file_name++;
  8839. + }
  8840. +
  8841. + /* Freed in pkg_free_installed_files */
  8842. + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
  8843. + } else {
  8844. + // already contains root_dir as header -> ABSOLUTE
  8845. + sprintf_alloc(&installed_file_name, "%s", file_name);
  8846. + }
  8847. + str_list_append(pkg->installed_files, installed_file_name);
  8848. + free(line);
  8849. + }
  8850. +
  8851. + fclose(list_file);
  8852. +
  8853. + return pkg->installed_files;
  8854. +}
  8855. +
  8856. +/* XXX: CLEANUP: This function and it's counterpart,
  8857. + (pkg_get_installed_files), do not match our init/deinit naming
  8858. + convention. Nor the alloc/free convention. But, then again, neither
  8859. + of these conventions currrently fit the way these two functions
  8860. + work. */
  8861. +int pkg_free_installed_files(pkg_t *pkg)
  8862. +{
  8863. + str_list_elt_t *iter;
  8864. +
  8865. + pkg->installed_files_ref_cnt--;
  8866. + if (pkg->installed_files_ref_cnt > 0) {
  8867. + return 0;
  8868. + }
  8869. +
  8870. + if (pkg->installed_files) {
  8871. +
  8872. + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
  8873. + /* malloced in pkg_get_installed_files */
  8874. + free (iter->data);
  8875. + iter->data = NULL;
  8876. + }
  8877. +
  8878. + str_list_deinit(pkg->installed_files);
  8879. + }
  8880. +
  8881. + pkg->installed_files = NULL;
  8882. +
  8883. + return 0;
  8884. +}
  8885. +
  8886. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
  8887. +{
  8888. + int err;
  8889. + char *list_file_name;
  8890. +
  8891. + //I don't think pkg_free_installed_files should be called here. Jamey
  8892. + //pkg_free_installed_files(pkg);
  8893. +
  8894. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8895. + pkg->dest->info_dir, pkg->name);
  8896. + if (!conf->noaction) {
  8897. + err = unlink(list_file_name);
  8898. + free(list_file_name);
  8899. +
  8900. + if (err) {
  8901. + return errno;
  8902. + }
  8903. + }
  8904. + return 0;
  8905. +}
  8906. +
  8907. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
  8908. +{
  8909. + conffile_list_elt_t *iter;
  8910. + conffile_t *conffile;
  8911. +
  8912. + if (pkg == NULL) {
  8913. + return NULL;
  8914. + }
  8915. +
  8916. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8917. + conffile = iter->data;
  8918. +
  8919. + if (strcmp(conffile->name, file_name) == 0) {
  8920. + return conffile;
  8921. + }
  8922. + }
  8923. +
  8924. + return NULL;
  8925. +}
  8926. +
  8927. +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
  8928. + const char *script, const char *args)
  8929. +{
  8930. + int err;
  8931. + char *path;
  8932. + char *cmd;
  8933. +
  8934. + /* XXX: FEATURE: When conf->offline_root is set, we should run the
  8935. + maintainer script within a chroot environment. */
  8936. +
  8937. + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
  8938. + have scripts in pkg->tmp_unpack_dir. */
  8939. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  8940. + if (pkg->dest == NULL) {
  8941. + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
  8942. + __FUNCTION__, pkg->name);
  8943. + return EINVAL;
  8944. + }
  8945. + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
  8946. + } else {
  8947. + if (pkg->tmp_unpack_dir == NULL) {
  8948. + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
  8949. + __FUNCTION__, pkg->name);
  8950. + return EINVAL;
  8951. + }
  8952. + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
  8953. + }
  8954. +
  8955. + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
  8956. + if (conf->noaction) return 0;
  8957. +
  8958. + /* XXX: CLEANUP: There must be a better way to handle maintainer
  8959. + scripts when running with offline_root mode and/or a dest other
  8960. + than '/'. I've been playing around with some clever chroot
  8961. + tricks and I might come up with something workable. */
  8962. + if (conf->offline_root) {
  8963. + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
  8964. + }
  8965. +
  8966. + setenv("PKG_ROOT",
  8967. + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
  8968. +
  8969. + if (! file_exists(path)) {
  8970. + free(path);
  8971. + return 0;
  8972. + }
  8973. +
  8974. + if (conf->offline_root) {
  8975. + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
  8976. + free(path);
  8977. + return 0;
  8978. + }
  8979. +
  8980. + sprintf_alloc(&cmd, "%s %s", path, args);
  8981. + free(path);
  8982. +
  8983. + err = xsystem(cmd);
  8984. + free(cmd);
  8985. +
  8986. + if (err) {
  8987. + fprintf(stderr, "%s script returned status %d\n", script, err);
  8988. + return err;
  8989. + }
  8990. +
  8991. + return 0;
  8992. +}
  8993. +
  8994. +char *pkg_state_want_to_str(pkg_state_want_t sw)
  8995. +{
  8996. + int i;
  8997. +
  8998. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  8999. + if (pkg_state_want_map[i].value == sw) {
  9000. + return strdup(pkg_state_want_map[i].str);
  9001. + }
  9002. + }
  9003. +
  9004. + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
  9005. + __FUNCTION__, sw);
  9006. + return strdup("<STATE_WANT_UNKNOWN>");
  9007. +}
  9008. +
  9009. +pkg_state_want_t pkg_state_want_from_str(char *str)
  9010. +{
  9011. + int i;
  9012. +
  9013. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9014. + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
  9015. + return pkg_state_want_map[i].value;
  9016. + }
  9017. + }
  9018. +
  9019. + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
  9020. + __FUNCTION__, str);
  9021. + return SW_UNKNOWN;
  9022. +}
  9023. +
  9024. +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
  9025. +{
  9026. + int i;
  9027. + int len = 3; /* ok\000 is minimum */
  9028. + char *str = NULL;
  9029. +
  9030. + /* clear the temporary flags before converting to string */
  9031. + sf &= SF_NONVOLATILE_FLAGS;
  9032. +
  9033. + if (sf == 0) {
  9034. + return strdup("ok");
  9035. + } else {
  9036. +
  9037. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9038. + if (sf & pkg_state_flag_map[i].value) {
  9039. + len += strlen(pkg_state_flag_map[i].str) + 1;
  9040. + }
  9041. + }
  9042. + str = malloc(len);
  9043. + if ( str == NULL ) {
  9044. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9045. + return NULL;
  9046. + }
  9047. + str[0] = 0;
  9048. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9049. + if (sf & pkg_state_flag_map[i].value) {
  9050. + strcat(str, pkg_state_flag_map[i].str);
  9051. + strcat(str, ",");
  9052. + }
  9053. + }
  9054. + len = strlen(str);
  9055. + str[len-1] = 0; /* squash last comma */
  9056. + return str;
  9057. + }
  9058. +}
  9059. +
  9060. +pkg_state_flag_t pkg_state_flag_from_str(char *str)
  9061. +{
  9062. + int i;
  9063. + int sf = SF_OK;
  9064. +
  9065. + if (strcmp(str, "ok") == 0) {
  9066. + return SF_OK;
  9067. + }
  9068. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9069. + const char *sfname = pkg_state_flag_map[i].str;
  9070. + int sfname_len = strlen(sfname);
  9071. + if (strncmp(str, sfname, sfname_len) == 0) {
  9072. + sf |= pkg_state_flag_map[i].value;
  9073. + str += sfname_len;
  9074. + if (str[0] == ',') {
  9075. + str++;
  9076. + } else {
  9077. + break;
  9078. + }
  9079. + }
  9080. + }
  9081. +
  9082. + return sf;
  9083. +}
  9084. +
  9085. +char *pkg_state_status_to_str(pkg_state_status_t ss)
  9086. +{
  9087. + int i;
  9088. +
  9089. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9090. + if (pkg_state_status_map[i].value == ss) {
  9091. + return strdup(pkg_state_status_map[i].str);
  9092. + }
  9093. + }
  9094. +
  9095. + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
  9096. + __FUNCTION__, ss);
  9097. + return strdup("<STATE_STATUS_UNKNOWN>");
  9098. +}
  9099. +
  9100. +pkg_state_status_t pkg_state_status_from_str(char *str)
  9101. +{
  9102. + int i;
  9103. +
  9104. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9105. + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
  9106. + return pkg_state_status_map[i].value;
  9107. + }
  9108. + }
  9109. +
  9110. + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
  9111. + __FUNCTION__, str);
  9112. + return SS_NOT_INSTALLED;
  9113. +}
  9114. +
  9115. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
  9116. +{
  9117. + nv_pair_list_elt_t *l;
  9118. +
  9119. + if (!pkg->architecture)
  9120. + return 1;
  9121. +
  9122. + l = conf->arch_list.head;
  9123. +
  9124. + while (l) {
  9125. + nv_pair_t *nv = l->data;
  9126. + if (strcmp(nv->name, pkg->architecture) == 0) {
  9127. + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
  9128. + return 1;
  9129. + }
  9130. + l = l->next;
  9131. + }
  9132. +
  9133. + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
  9134. + return 0;
  9135. +}
  9136. +
  9137. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
  9138. +{
  9139. + nv_pair_list_elt_t *l;
  9140. +
  9141. + l = conf->arch_list.head;
  9142. +
  9143. + while (l) {
  9144. + nv_pair_t *nv = l->data;
  9145. + if (strcmp(nv->name, archname) == 0) {
  9146. + int priority = strtol(nv->value, NULL, 0);
  9147. + return priority;
  9148. + }
  9149. + l = l->next;
  9150. + }
  9151. + return 0;
  9152. +}
  9153. +
  9154. +int pkg_info_preinstall_check(ipkg_conf_t *conf)
  9155. +{
  9156. + int i;
  9157. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9158. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  9159. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9160. +
  9161. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
  9162. + pkg_hash_fetch_available(pkg_hash, available_pkgs);
  9163. + /* update arch_priority for each package */
  9164. + for (i = 0; i < available_pkgs->len; i++) {
  9165. + pkg_t *pkg = available_pkgs->pkgs[i];
  9166. + int arch_priority = 1;
  9167. + if (!pkg)
  9168. + continue;
  9169. + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
  9170. + if (pkg->architecture)
  9171. + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
  9172. + else
  9173. + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
  9174. + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
  9175. + pkg->arch_priority = arch_priority;
  9176. + }
  9177. +
  9178. + for (i = 0; i < available_pkgs->len; i++) {
  9179. + pkg_t *pkg = available_pkgs->pkgs[i];
  9180. + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
  9181. + /* clear flags and want for any uninstallable package */
  9182. + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
  9183. + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
  9184. + pkg->state_want = SW_UNKNOWN;
  9185. + pkg->state_flag = 0;
  9186. + }
  9187. + }
  9188. + pkg_vec_free(available_pkgs);
  9189. +
  9190. + /* update the file owner data structure */
  9191. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
  9192. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9193. + for (i = 0; i < installed_pkgs->len; i++) {
  9194. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9195. + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
  9196. + str_list_elt_t *iter;
  9197. + if (installed_files == NULL) {
  9198. + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
  9199. + break;
  9200. + }
  9201. + for (iter = installed_files->head; iter; iter = iter->next) {
  9202. + char *installed_file = iter->data;
  9203. + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
  9204. + file_hash_set_file_owner(conf, installed_file, pkg);
  9205. + }
  9206. + }
  9207. + pkg_vec_free(installed_pkgs);
  9208. +
  9209. + return 0;
  9210. +}
  9211. +
  9212. +struct pkg_write_filelist_data {
  9213. + ipkg_conf_t *conf;
  9214. + pkg_t *pkg;
  9215. + FILE *stream;
  9216. +};
  9217. +
  9218. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
  9219. +{
  9220. + struct pkg_write_filelist_data *data = data_;
  9221. + pkg_t *entry = entry_;
  9222. + if (entry == data->pkg) {
  9223. + fprintf(data->stream, "%s\n", key);
  9224. + }
  9225. +}
  9226. +
  9227. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
  9228. +{
  9229. + struct pkg_write_filelist_data data;
  9230. + char *list_file_name = NULL;
  9231. + int err = 0;
  9232. +
  9233. + if (!pkg) {
  9234. + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
  9235. + return -EINVAL;
  9236. + }
  9237. + ipkg_message(conf, IPKG_INFO,
  9238. + " creating %s.list file\n", pkg->name);
  9239. + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
  9240. + if (!list_file_name) {
  9241. + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
  9242. + return -ENOMEM;
  9243. + }
  9244. + ipkg_message(conf, IPKG_INFO,
  9245. + " creating %s file for pkg %s\n", list_file_name, pkg->name);
  9246. + data.stream = fopen(list_file_name, "w");
  9247. + if (!data.stream) {
  9248. + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
  9249. + list_file_name, strerror(errno));
  9250. + return errno;
  9251. + }
  9252. + data.pkg = pkg;
  9253. + data.conf = conf;
  9254. + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
  9255. + fclose(data.stream);
  9256. + free(list_file_name);
  9257. +
  9258. + return err;
  9259. +}
  9260. +
  9261. +int pkg_write_changed_filelists(ipkg_conf_t *conf)
  9262. +{
  9263. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9264. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9265. + int i;
  9266. + int err;
  9267. + if (conf->noaction)
  9268. + return 0;
  9269. +
  9270. + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
  9271. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9272. + for (i = 0; i < installed_pkgs->len; i++) {
  9273. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9274. + if (pkg->state_flag & SF_FILELIST_CHANGED) {
  9275. + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
  9276. + err = pkg_write_filelist(conf, pkg);
  9277. + if (err)
  9278. + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
  9279. + }
  9280. + }
  9281. + return 0;
  9282. +}
  9283. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_depends.c busybox-1.15.2/archival/libipkg/pkg_depends.c
  9284. --- busybox-1.15.2.orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
  9285. +++ busybox-1.15.2/archival/libipkg/pkg_depends.c 2010-03-14 20:53:41.000000000 +0100
  9286. @@ -0,0 +1,1032 @@
  9287. +/* pkg_depends.c - the itsy package management system
  9288. +
  9289. + Steven M. Ayer
  9290. +
  9291. + Copyright (C) 2002 Compaq Computer Corporation
  9292. +
  9293. + This program is free software; you can redistribute it and/or
  9294. + modify it under the terms of the GNU General Public License as
  9295. + published by the Free Software Foundation; either version 2, or (at
  9296. + your option) any later version.
  9297. +
  9298. + This program is distributed in the hope that it will be useful, but
  9299. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9300. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9301. + General Public License for more details.
  9302. +*/
  9303. +
  9304. +#include "ipkg.h"
  9305. +#include <errno.h>
  9306. +#include <ctype.h>
  9307. +
  9308. +#include "pkg.h"
  9309. +#include "ipkg_utils.h"
  9310. +#include "pkg_hash.h"
  9311. +#include "ipkg_message.h"
  9312. +#include "pkg_parse.h"
  9313. +#include "hash_table.h"
  9314. +
  9315. +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
  9316. +static depend_t * depend_init(void);
  9317. +static void depend_deinit(depend_t *d);
  9318. +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
  9319. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
  9320. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
  9321. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg);
  9322. +
  9323. +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
  9324. +{
  9325. + depend_t *depend = (depend_t *)cdata;
  9326. + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
  9327. + return 1;
  9328. + else
  9329. + return 0;
  9330. +}
  9331. +
  9332. +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
  9333. +{
  9334. + depend_t *depend = (depend_t *)cdata;
  9335. +#if 0
  9336. + pkg_t * temp = pkg_new();
  9337. + int comparison;
  9338. + parseVersion(temp, depend->version);
  9339. + comparison = pkg_compare_versions(pkg, temp);
  9340. + free(temp);
  9341. +
  9342. + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
  9343. + __FUNCTION__, pkg->name, pkg->version,
  9344. + depend, depend->constraint, depend->version,
  9345. + comparison, version_constraints_satisfied(depend, pkg));
  9346. +#endif
  9347. + if (version_constraints_satisfied(depend, pkg))
  9348. + return 1;
  9349. + else
  9350. + return 0;
  9351. +}
  9352. +
  9353. +/* returns ndependences or negative error value */
  9354. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
  9355. + pkg_vec_t *unsatisfied, char *** unresolved)
  9356. +{
  9357. + pkg_t * satisfier_entry_pkg;
  9358. + register int i, j, k, l;
  9359. + int count, found;
  9360. + char ** the_lost;
  9361. + abstract_pkg_t * ab_pkg;
  9362. +
  9363. + /*
  9364. + * this is a setup to check for redundant/cyclic dependency checks,
  9365. + * which are marked at the abstract_pkg level
  9366. + */
  9367. + if (!(ab_pkg = pkg->parent)) {
  9368. + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
  9369. + *unresolved = NULL;
  9370. + return 0;
  9371. + }
  9372. + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
  9373. + *unresolved = NULL;
  9374. + return 0;
  9375. + } else {
  9376. + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
  9377. + }
  9378. + /**/
  9379. +
  9380. + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
  9381. + if (!count){
  9382. + *unresolved = NULL;
  9383. + return 0;
  9384. + }
  9385. +
  9386. + the_lost = NULL;
  9387. +
  9388. + /* foreach dependency */
  9389. + for (i = 0; i < count; i++) {
  9390. + compound_depend_t * compound_depend = &pkg->depends[i];
  9391. + depend_t ** possible_satisfiers = compound_depend->possibilities;;
  9392. + found = 0;
  9393. + satisfier_entry_pkg = NULL;
  9394. +
  9395. + if (compound_depend->type == GREEDY_DEPEND) {
  9396. + /* foreach possible satisfier */
  9397. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9398. + /* foreach provided_by, which includes the abstract_pkg itself */
  9399. + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
  9400. + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
  9401. + int nposs = ab_provider_vec->len;
  9402. + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
  9403. + for (l = 0; l < nposs; l++) {
  9404. + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
  9405. + /* if no depends on this one, try the first package that Provides this one */
  9406. + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
  9407. + continue;
  9408. + }
  9409. +
  9410. + /* cruise this possiblity's pkg_vec looking for an installed version */
  9411. + for (k = 0; k < test_vec->len; k++) {
  9412. + pkg_t *pkg_scout = test_vec->pkgs[k];
  9413. + /* not installed, and not already known about? */
  9414. + if ((pkg_scout->state_want != SW_INSTALL)
  9415. + && !pkg_scout->parent->dependencies_checked
  9416. + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
  9417. + char ** newstuff = NULL;
  9418. + int rc;
  9419. + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
  9420. + /* check for not-already-installed dependencies */
  9421. + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
  9422. + pkg_scout,
  9423. + tmp_vec,
  9424. + &newstuff);
  9425. + if (newstuff == NULL) {
  9426. + int ok = 1;
  9427. + for (i = 0; i < rc; i++) {
  9428. + pkg_t *p = tmp_vec->pkgs[i];
  9429. + if (p->state_want == SW_INSTALL)
  9430. + continue;
  9431. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
  9432. + ok = 0;
  9433. + break;
  9434. + }
  9435. + pkg_vec_free (tmp_vec);
  9436. + if (ok) {
  9437. + /* mark this one for installation */
  9438. + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
  9439. + pkg_vec_insert(unsatisfied, pkg_scout);
  9440. + }
  9441. + } else {
  9442. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
  9443. + free (newstuff);
  9444. + }
  9445. + }
  9446. + }
  9447. + }
  9448. + }
  9449. +
  9450. + continue;
  9451. + }
  9452. +
  9453. + /* foreach possible satisfier, look for installed package */
  9454. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9455. + /* foreach provided_by, which includes the abstract_pkg itself */
  9456. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9457. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9458. + pkg_t *satisfying_pkg =
  9459. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9460. + pkg_installed_and_constraint_satisfied,
  9461. + dependence_to_satisfy, 1);
  9462. + /* Being that I can't test constraing in pkg_hash, I will test it here */
  9463. + if (satisfying_pkg != NULL) {
  9464. + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9465. + satisfying_pkg = NULL;
  9466. + }
  9467. + }
  9468. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
  9469. + if (satisfying_pkg != NULL) {
  9470. + found = 1;
  9471. + break;
  9472. + }
  9473. +
  9474. + }
  9475. + /* if nothing installed matches, then look for uninstalled satisfier */
  9476. + if (!found) {
  9477. + /* foreach possible satisfier, look for installed package */
  9478. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9479. + /* foreach provided_by, which includes the abstract_pkg itself */
  9480. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9481. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9482. + pkg_t *satisfying_pkg =
  9483. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9484. + pkg_constraint_satisfied,
  9485. + dependence_to_satisfy, 1);
  9486. + /* Being that I can't test constraing in pkg_hash, I will test it here too */
  9487. + if (satisfying_pkg != NULL) {
  9488. + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9489. + satisfying_pkg = NULL;
  9490. + }
  9491. + }
  9492. +
  9493. + /* user request overrides package recommendation */
  9494. + if (satisfying_pkg != NULL
  9495. + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
  9496. + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
  9497. + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
  9498. + pkg->name, satisfying_pkg->name);
  9499. + continue;
  9500. + }
  9501. +
  9502. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
  9503. + if (satisfying_pkg != NULL) {
  9504. + satisfier_entry_pkg = satisfying_pkg;
  9505. + break;
  9506. + }
  9507. + }
  9508. + }
  9509. +
  9510. + /* we didn't find one, add something to the unsatisfied vector */
  9511. + if (!found) {
  9512. + if (!satisfier_entry_pkg) {
  9513. + /* failure to meet recommendations is not an error */
  9514. + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
  9515. + the_lost = add_unresolved_dep(pkg, the_lost, i);
  9516. + else
  9517. + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
  9518. + pkg->name, compound_depend->possibilities[0]->pkg->name);
  9519. + }
  9520. + else {
  9521. + if (compound_depend->type == SUGGEST) {
  9522. + /* just mention it politely */
  9523. + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
  9524. + pkg->name, satisfier_entry_pkg->name);
  9525. + } else {
  9526. + char ** newstuff = NULL;
  9527. +
  9528. + if (satisfier_entry_pkg != pkg &&
  9529. + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
  9530. + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
  9531. + pkg_hash_fetch_unsatisfied_dependencies(conf,
  9532. + satisfier_entry_pkg,
  9533. + unsatisfied,
  9534. + &newstuff);
  9535. + the_lost = merge_unresolved(the_lost, newstuff);
  9536. + }
  9537. + }
  9538. + }
  9539. + }
  9540. + }
  9541. + *unresolved = the_lost;
  9542. +
  9543. + return unsatisfied->len;
  9544. +}
  9545. +
  9546. +/*checking for conflicts !in replaces
  9547. + If a packages conflicts with another but is also replacing it, I should not consider it a
  9548. + really conflicts
  9549. + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
  9550. +*/
  9551. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
  9552. +{
  9553. + int i ;
  9554. + int replaces_count = pkg->replaces_count;
  9555. + abstract_pkg_t **replaces;
  9556. +
  9557. + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
  9558. + return 0;
  9559. +
  9560. + replaces = pkg->replaces;
  9561. +
  9562. + for (i = 0; i < replaces_count; i++) {
  9563. + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
  9564. + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
  9565. + return 1;
  9566. + }
  9567. + }
  9568. + return 0;
  9569. +
  9570. +}
  9571. +
  9572. +
  9573. +/* Abhaya: added support for conflicts */
  9574. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg)
  9575. +{
  9576. + pkg_vec_t * installed_conflicts, * test_vec;
  9577. + compound_depend_t * conflicts;
  9578. + depend_t ** possible_satisfiers;
  9579. + depend_t * possible_satisfier;
  9580. + register int i, j, k;
  9581. + int count;
  9582. + abstract_pkg_t * ab_pkg;
  9583. + pkg_t **pkg_scouts;
  9584. + pkg_t *pkg_scout;
  9585. +
  9586. + /*
  9587. + * this is a setup to check for redundant/cyclic dependency checks,
  9588. + * which are marked at the abstract_pkg level
  9589. + */
  9590. + if(!(ab_pkg = pkg->parent)){
  9591. + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
  9592. + return (pkg_vec_t *)NULL;
  9593. + }
  9594. +
  9595. + conflicts = pkg->conflicts;
  9596. + if(!conflicts){
  9597. + return (pkg_vec_t *)NULL;
  9598. + }
  9599. + installed_conflicts = pkg_vec_alloc();
  9600. +
  9601. + count = pkg->conflicts_count;
  9602. +
  9603. +
  9604. +
  9605. + /* foreach conflict */
  9606. + for(i = 0; i < pkg->conflicts_count; i++){
  9607. +
  9608. + possible_satisfiers = conflicts->possibilities;
  9609. +
  9610. + /* foreach possible satisfier */
  9611. + for(j = 0; j < conflicts->possibility_count; j++){
  9612. + possible_satisfier = possible_satisfiers[j];
  9613. + if (!possible_satisfier)
  9614. + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
  9615. + if (!possible_satisfier->pkg)
  9616. + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
  9617. + test_vec = possible_satisfier->pkg->pkgs;
  9618. + if (test_vec) {
  9619. + /* pkg_vec found, it is an actual package conflict
  9620. + * cruise this possiblity's pkg_vec looking for an installed version */
  9621. + pkg_scouts = test_vec->pkgs;
  9622. + for(k = 0; k < test_vec->len; k++){
  9623. + pkg_scout = pkg_scouts[k];
  9624. + if (!pkg_scout) {
  9625. + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
  9626. + continue;
  9627. + }
  9628. + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
  9629. + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
  9630. + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
  9631. + pkg_vec_insert(installed_conflicts, pkg_scout);
  9632. + }
  9633. + }
  9634. + }
  9635. + }
  9636. + }
  9637. + conflicts++;
  9638. + }
  9639. +
  9640. + if (installed_conflicts->len)
  9641. + return installed_conflicts;
  9642. + pkg_vec_free(installed_conflicts);
  9643. + return (pkg_vec_t *)NULL;
  9644. +}
  9645. +
  9646. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
  9647. +{
  9648. + pkg_t * temp;
  9649. + int comparison;
  9650. +
  9651. + if(depends->constraint == NONE)
  9652. + return 1;
  9653. +
  9654. + temp = pkg_new();
  9655. +
  9656. + parseVersion(temp, depends->version);
  9657. +
  9658. + comparison = pkg_compare_versions(pkg, temp);
  9659. +
  9660. + free(temp);
  9661. +
  9662. + if((depends->constraint == EARLIER) &&
  9663. + (comparison < 0))
  9664. + return 1;
  9665. + else if((depends->constraint == LATER) &&
  9666. + (comparison > 0))
  9667. + return 1;
  9668. + else if(comparison == 0)
  9669. + return 1;
  9670. + else if((depends->constraint == LATER_EQUAL) &&
  9671. + (comparison >= 0))
  9672. + return 1;
  9673. + else if((depends->constraint == EARLIER_EQUAL) &&
  9674. + (comparison <= 0))
  9675. + return 1;
  9676. +
  9677. + return 0;
  9678. +}
  9679. +
  9680. +int pkg_dependence_satisfiable(depend_t *depend)
  9681. +{
  9682. + abstract_pkg_t *apkg = depend->pkg;
  9683. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9684. + int n_providers = provider_apkgs->len;
  9685. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9686. + pkg_vec_t *pkg_vec;
  9687. + int n_pkgs ;
  9688. + int i;
  9689. + int j;
  9690. +
  9691. + for (i = 0; i < n_providers; i++) {
  9692. + abstract_pkg_t *papkg = apkgs[i];
  9693. + pkg_vec = papkg->pkgs;
  9694. + if (pkg_vec) {
  9695. + n_pkgs = pkg_vec->len;
  9696. + for (j = 0; j < n_pkgs; j++) {
  9697. + pkg_t *pkg = pkg_vec->pkgs[j];
  9698. + if (version_constraints_satisfied(depend, pkg)) {
  9699. + return 1;
  9700. + }
  9701. + }
  9702. + }
  9703. + }
  9704. + return 0;
  9705. +}
  9706. +
  9707. +int pkg_dependence_satisfied(depend_t *depend)
  9708. +{
  9709. + abstract_pkg_t *apkg = depend->pkg;
  9710. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9711. + int n_providers = provider_apkgs->len;
  9712. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9713. + int i;
  9714. + int n_pkgs;
  9715. + int j;
  9716. +
  9717. + for (i = 0; i < n_providers; i++) {
  9718. + abstract_pkg_t *papkg = apkgs[i];
  9719. + pkg_vec_t *pkg_vec = papkg->pkgs;
  9720. + if (pkg_vec) {
  9721. + n_pkgs = pkg_vec->len;
  9722. + for (j = 0; j < n_pkgs; j++) {
  9723. + pkg_t *pkg = pkg_vec->pkgs[j];
  9724. + if (version_constraints_satisfied(depend, pkg)) {
  9725. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
  9726. + return 1;
  9727. + }
  9728. + }
  9729. + }
  9730. + }
  9731. + return 0;
  9732. +}
  9733. +
  9734. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
  9735. +{
  9736. + register int i;
  9737. + pkg_t ** pkgs = vec->pkgs;
  9738. +
  9739. + for(i = 0; i < vec->len; i++)
  9740. + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
  9741. + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
  9742. + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
  9743. + return 1;
  9744. + return 0;
  9745. +}
  9746. +
  9747. +
  9748. +#ifdef DeadCode
  9749. +/**
  9750. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  9751. + * the same abstract package and 0 otherwise.
  9752. + */
  9753. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
  9754. +{
  9755. + abstract_pkg_t **provides = pkg->provides;
  9756. + int provides_count = pkg->provides_count;
  9757. + abstract_pkg_t **replacee_provides = replacee->provides;
  9758. + int replacee_provides_count = replacee->provides_count;
  9759. + int i, j;
  9760. + for (i = 0; i < provides_count; i++) {
  9761. + abstract_pkg_t *apkg = provides[i];
  9762. + for (j = 0; j < replacee_provides_count; j++) {
  9763. + abstract_pkg_t *replacee_apkg = replacee_provides[i];
  9764. + if (apkg == replacee_apkg)
  9765. + return 1;
  9766. + }
  9767. + }
  9768. + return 0;
  9769. +}
  9770. +#endif
  9771. +
  9772. +/**
  9773. + * pkg_provides_abstract returns 1 if pkg->provides contains providee
  9774. + * and 0 otherwise.
  9775. + */
  9776. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
  9777. +{
  9778. + abstract_pkg_t **provides = pkg->provides;
  9779. + int provides_count = pkg->provides_count;
  9780. + int i;
  9781. + for (i = 0; i < provides_count; i++) {
  9782. + if (provides[i] == providee)
  9783. + return 1;
  9784. + }
  9785. + return 0;
  9786. +}
  9787. +
  9788. +/**
  9789. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  9790. + * otherwise.
  9791. + */
  9792. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
  9793. +{
  9794. + abstract_pkg_t **replaces = pkg->replaces;
  9795. + int replaces_count = pkg->replaces_count;
  9796. + /* abstract_pkg_t **replacee_provides = pkg->provides;
  9797. + int replacee_provides_count = pkg->provides_count; */
  9798. + int i, j;
  9799. + for (i = 0; i < replaces_count; i++) {
  9800. + abstract_pkg_t *abstract_replacee = replaces[i];
  9801. + for (j = 0; j < replaces_count; j++) {
  9802. + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
  9803. + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
  9804. + if (replacee->provides[j] == abstract_replacee)
  9805. + return 1;
  9806. + }
  9807. + }
  9808. + return 0;
  9809. +}
  9810. +
  9811. +
  9812. +/**
  9813. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
  9814. + * otherwise.
  9815. + */
  9816. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
  9817. +{
  9818. + compound_depend_t *conflicts = pkg->conflicts;
  9819. + int conflicts_count = pkg->conflicts_count;
  9820. + int i, j;
  9821. + for (i = 0; i < conflicts_count; i++) {
  9822. + int possibility_count = conflicts[i].possibility_count;
  9823. + struct depend **possibilities = conflicts[i].possibilities;
  9824. + for (j = 0; j < possibility_count; j++) {
  9825. + if (possibilities[j]->pkg == conflictee) {
  9826. + return 1;
  9827. + }
  9828. + }
  9829. + }
  9830. + return 0;
  9831. +}
  9832. +
  9833. +/**
  9834. + * pkg_conflicts returns 1 if pkg->conflicts contains one of
  9835. + * conflictee's provides and 0 otherwise.
  9836. + */
  9837. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
  9838. +{
  9839. + compound_depend_t *conflicts = pkg->conflicts;
  9840. + int conflicts_count = pkg->conflicts_count;
  9841. + abstract_pkg_t **conflictee_provides = conflictee->provides;
  9842. + int conflictee_provides_count = conflictee->provides_count;
  9843. + int i, j, k;
  9844. + int possibility_count;
  9845. + struct depend **possibilities;
  9846. + abstract_pkg_t *possibility ;
  9847. +
  9848. + for (i = 0; i < conflicts_count; i++) {
  9849. + possibility_count = conflicts[i].possibility_count;
  9850. + possibilities = conflicts[i].possibilities;
  9851. + for (j = 0; j < possibility_count; j++) {
  9852. + possibility = possibilities[j]->pkg;
  9853. + for (k = 0; k < conflictee_provides_count; k++) {
  9854. + if (possibility == conflictee_provides[k]) {
  9855. + return 1;
  9856. + }
  9857. + }
  9858. + }
  9859. + }
  9860. + return 0;
  9861. +}
  9862. +
  9863. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
  9864. +{
  9865. + int oldlen = 0, newlen = 0;
  9866. + char ** result;
  9867. + register int i, j;
  9868. +
  9869. + if(!newstuff)
  9870. + return oldstuff;
  9871. +
  9872. + while(oldstuff && oldstuff[oldlen]) oldlen++;
  9873. + while(newstuff && newstuff[newlen]) newlen++;
  9874. +
  9875. + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
  9876. + if (result == NULL) {
  9877. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9878. + return NULL;
  9879. + }
  9880. +
  9881. + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
  9882. + *(result + i) = *(newstuff + j);
  9883. +
  9884. + *(result + i) = NULL;
  9885. +
  9886. + return result;
  9887. +}
  9888. +
  9889. +/*
  9890. + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
  9891. + * this is null terminated, no count is carried around
  9892. + */
  9893. +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
  9894. +{
  9895. + int count;
  9896. + char ** resized;
  9897. + char *depend_str = pkg_depend_str(pkg, ref_ndx);
  9898. +
  9899. + count = 0;
  9900. + while(the_lost && the_lost[count]) count++;
  9901. +
  9902. + count++; /* need one to hold the null */
  9903. + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
  9904. + if (resized == NULL) {
  9905. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9906. + return NULL;
  9907. + }
  9908. + resized[count - 1] = strdup(depend_str);
  9909. + resized[count] = NULL;
  9910. +
  9911. + return resized;
  9912. +}
  9913. +
  9914. +void printDepends(pkg_t * pkg)
  9915. +{
  9916. + register int i, j;
  9917. + compound_depend_t * depend;
  9918. + int count;
  9919. +
  9920. + count = pkg->pre_depends_count + pkg->depends_count;
  9921. +
  9922. + depend = pkg->depends;
  9923. + if(!depend){
  9924. + fprintf(stderr, "Depends pointer is NULL\n");
  9925. + return;
  9926. + }
  9927. + for(i = 0; i < count; i++){
  9928. + fprintf(stderr, "%s has %d possibilities:\n",
  9929. + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
  9930. + depend->possibility_count);
  9931. + for(j = 0; j < depend->possibility_count; j++)
  9932. + fprintf(stderr, "\t%s version %s (%d)\n",
  9933. + depend->possibilities[j]->pkg->name,
  9934. + depend->possibilities[j]->version,
  9935. + depend->possibilities[j]->constraint);
  9936. + depend++;
  9937. + }
  9938. +}
  9939. +
  9940. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  9941. +{
  9942. + register int i, j;
  9943. +
  9944. + /* every pkg provides itself */
  9945. + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
  9946. +
  9947. + if (!pkg->provides_count)
  9948. + return 0;
  9949. +
  9950. + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
  9951. + if (pkg->provides == NULL) {
  9952. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9953. + return -1 ;
  9954. + }
  9955. + pkg->provides[0] = ab_pkg;
  9956. +
  9957. + // if (strcmp(ab_pkg->name, pkg->name))
  9958. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  9959. +
  9960. + for(i = 0; i < pkg->provides_count; i++){
  9961. + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
  9962. +
  9963. + pkg->provides[i+1] = provided_abpkg;
  9964. +
  9965. + j = 0;
  9966. + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
  9967. + }
  9968. + return 0;
  9969. +}
  9970. +
  9971. +/* Abhaya: added conflicts support */
  9972. +int buildConflicts(hash_table_t * hash, pkg_t * pkg)
  9973. +{
  9974. + register int i;
  9975. + compound_depend_t * conflicts;
  9976. +
  9977. + if (!pkg->conflicts_count)
  9978. + return 0;
  9979. +
  9980. + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
  9981. + pkg->conflicts_count);
  9982. + if (conflicts == NULL) {
  9983. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9984. + return -1;
  9985. + }
  9986. + for (i = 0; i < pkg->conflicts_count; i++) {
  9987. + conflicts->type = CONFLICTS;
  9988. + parseDepends(conflicts, hash,
  9989. + pkg->conflicts_str[i]);
  9990. +#if 0
  9991. + for (j = 0; j < conflicts->possibility_count; j++) {
  9992. + depend_t *possibility = conflicts->possibilities[j];
  9993. + abstract_pkg_t *conflicting_apkg = possibility->pkg;
  9994. + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
  9995. + }
  9996. +#endif
  9997. + conflicts++;
  9998. + }
  9999. + return 0;
  10000. +}
  10001. +
  10002. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10003. +{
  10004. + register int i, j;
  10005. +
  10006. + if (!pkg->replaces_count)
  10007. + return 0;
  10008. +
  10009. + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
  10010. + if (pkg->replaces == NULL) {
  10011. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10012. + return -1;
  10013. + }
  10014. +
  10015. + // if (strcmp(ab_pkg->name, pkg->name))
  10016. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10017. +
  10018. + for(i = 0; i < pkg->replaces_count; i++){
  10019. + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
  10020. +
  10021. + pkg->replaces[i] = old_abpkg;
  10022. +
  10023. + j = 0;
  10024. + if (!old_abpkg->replaced_by)
  10025. + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
  10026. + if ( old_abpkg->replaced_by == NULL ){
  10027. + return -1;
  10028. + }
  10029. + /* if a package pkg both replaces and conflicts old_abpkg,
  10030. + * then add it to the replaced_by vector so that old_abpkg
  10031. + * will be upgraded to ab_pkg automatically */
  10032. + if (pkg_conflicts_abstract(pkg, old_abpkg))
  10033. + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
  10034. + }
  10035. + return 0;
  10036. +}
  10037. +
  10038. +int buildDepends(hash_table_t * hash, pkg_t * pkg)
  10039. +{
  10040. + int count;
  10041. + register int i;
  10042. + compound_depend_t * depends;
  10043. +
  10044. + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
  10045. + return 0;
  10046. +
  10047. + if (0 && pkg->pre_depends_count)
  10048. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10049. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10050. + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
  10051. + if (depends == NULL) {
  10052. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10053. + return -1;
  10054. + }
  10055. +
  10056. +
  10057. + for(i = 0; i < pkg->pre_depends_count; i++){
  10058. + parseDepends(depends, hash, pkg->pre_depends_str[i]);
  10059. + if (0 && pkg->pre_depends_count)
  10060. + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
  10061. + pkg->pre_depends_str[i], depends, depends->possibility_count);
  10062. + depends->type = PREDEPEND;
  10063. + depends++;
  10064. + }
  10065. +
  10066. + for(i = 0; i < pkg->recommends_count; i++){
  10067. + parseDepends(depends, hash, pkg->recommends_str[i]);
  10068. + if (0 && pkg->recommends_count)
  10069. + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
  10070. + pkg->recommends_str[i], depends, depends->possibility_count);
  10071. + depends->type = RECOMMEND;
  10072. + depends++;
  10073. + }
  10074. +
  10075. + for(i = 0; i < pkg->suggests_count; i++){
  10076. + parseDepends(depends, hash, pkg->suggests_str[i]);
  10077. + if (0 && pkg->suggests_count)
  10078. + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
  10079. + pkg->suggests_str[i], depends, depends->possibility_count);
  10080. + depends->type = SUGGEST;
  10081. + depends++;
  10082. + }
  10083. +
  10084. + for(i = 0; i < pkg->depends_count; i++){
  10085. + parseDepends(depends, hash, pkg->depends_str[i]);
  10086. + if (0 && pkg->depends_count)
  10087. + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
  10088. + pkg->depends_str[i], depends, depends->possibility_count);
  10089. + depends++;
  10090. + }
  10091. + return 0;
  10092. +}
  10093. +
  10094. +/*
  10095. + * pkg_depend_string: returns the depends string specified by index_.
  10096. + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
  10097. + * [0,npredepends) -> returns pre_depends_str[index_]
  10098. + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index_]
  10099. + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index_]
  10100. + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index_]
  10101. + */
  10102. +char *pkg_depend_str(pkg_t *pkg, int index_)
  10103. +{
  10104. + if (index_ < pkg->pre_depends_count) {
  10105. + return pkg->pre_depends_str[index_];
  10106. + }
  10107. + index_ -= pkg->pre_depends_count;
  10108. +
  10109. + if (index_ < pkg->recommends_count) {
  10110. + return pkg->recommends_str[index_];
  10111. + }
  10112. + index_ -= pkg->recommends_count;
  10113. +
  10114. + if (index_ < pkg->suggests_count) {
  10115. + return pkg->suggests_str[index_];
  10116. + }
  10117. + index_ -= pkg->suggests_count;
  10118. +
  10119. + if (index_ < pkg->depends_count) {
  10120. + return pkg->depends_str[index_];
  10121. + }
  10122. + fprintf(stderr, "pkg_depend_str: index_ %d out of range for pkg=%s\n", index_, pkg->name);
  10123. + return NULL;
  10124. +}
  10125. +
  10126. +void freeDepends(pkg_t *pkg)
  10127. +{
  10128. + int i;
  10129. +
  10130. + if (pkg == NULL || pkg->depends == NULL) {
  10131. + return;
  10132. + }
  10133. +
  10134. + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
  10135. + for (i=0; i < pkg->depends->possibility_count; i++) {
  10136. + depend_deinit(pkg->depends->possibilities[i]);
  10137. + }
  10138. + free(pkg->depends->possibilities);
  10139. + free(pkg->depends);
  10140. + pkg->depends = NULL;
  10141. +}
  10142. +
  10143. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
  10144. +{
  10145. + compound_depend_t * depends;
  10146. + int count, othercount;
  10147. + register int i, j;
  10148. + abstract_pkg_t * ab_depend;
  10149. + abstract_pkg_t ** temp;
  10150. +
  10151. + count = pkg->pre_depends_count + pkg->depends_count;
  10152. + depends = pkg->depends;
  10153. +
  10154. + if (0 && pkg->pre_depends_count)
  10155. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10156. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10157. + for (i = 0; i < count; i++) {
  10158. + if (0 && pkg->pre_depends_count)
  10159. + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
  10160. + for (j = 0; j < depends->possibility_count; j++){
  10161. + ab_depend = depends->possibilities[j]->pkg;
  10162. + if(!ab_depend->depended_upon_by)
  10163. + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
  10164. +
  10165. + temp = ab_depend->depended_upon_by;
  10166. + othercount = 1;
  10167. + while(*temp){
  10168. + temp++;
  10169. + othercount++;
  10170. + }
  10171. + *temp = ab_pkg;
  10172. +
  10173. + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
  10174. + (othercount + 1) * sizeof(abstract_pkg_t *));
  10175. + /* the array may have moved */
  10176. + temp = ab_depend->depended_upon_by + othercount;
  10177. + *temp = NULL;
  10178. + }
  10179. + depends++;
  10180. + }
  10181. +}
  10182. +
  10183. +static depend_t * depend_init(void)
  10184. +{
  10185. + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
  10186. + if ( d==NULL ){
  10187. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10188. + return NULL;
  10189. + }
  10190. + d->constraint = NONE;
  10191. + d->version = NULL;
  10192. + d->pkg = NULL;
  10193. +
  10194. + return d;
  10195. +}
  10196. +
  10197. +static void depend_deinit(depend_t *d)
  10198. +{
  10199. + free(d);
  10200. +}
  10201. +
  10202. +static int parseDepends(compound_depend_t *compound_depend,
  10203. + hash_table_t * hash, char * depend_str)
  10204. +{
  10205. + char * pkg_name, buffer[2048];
  10206. + int num_of_ors = 0;
  10207. + register int i;
  10208. + register char * src, * dest;
  10209. + depend_t ** possibilities;
  10210. +
  10211. + /* first count the number of ored possibilities for satisfying dependency */
  10212. + src = depend_str;
  10213. + while(*src)
  10214. + if(*src++ == '|')
  10215. + num_of_ors++;
  10216. +
  10217. + compound_depend->type = DEPEND;
  10218. +
  10219. + compound_depend->possibility_count = num_of_ors + 1;
  10220. + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
  10221. + if (!possibilities)
  10222. + return -ENOMEM;
  10223. + compound_depend->possibilities = possibilities;
  10224. +
  10225. + src = depend_str;
  10226. + for(i = 0; i < num_of_ors + 1; i++){
  10227. + possibilities[i] = depend_init();
  10228. + if (!possibilities[i])
  10229. + return -ENOMEM;
  10230. + /* gobble up just the name first */
  10231. + dest = buffer;
  10232. + while(*src &&
  10233. + !isspace(*src) &&
  10234. + (*src != '(') &&
  10235. + (*src != '*') &&
  10236. + (*src != '|'))
  10237. + *dest++ = *src++;
  10238. + *dest = '\0';
  10239. + pkg_name = trim_alloc(buffer);
  10240. + if (pkg_name == NULL )
  10241. + return -ENOMEM;
  10242. +
  10243. + /* now look at possible version info */
  10244. +
  10245. + /* skip to next chars */
  10246. + if(isspace(*src))
  10247. + while(*src && isspace(*src)) src++;
  10248. +
  10249. + /* extract constraint and version */
  10250. + if(*src == '('){
  10251. + src++;
  10252. + if(!strncmp(src, "<<", 2)){
  10253. + possibilities[i]->constraint = EARLIER;
  10254. + src += 2;
  10255. + }
  10256. + else if(!strncmp(src, "<=", 2)){
  10257. + possibilities[i]->constraint = EARLIER_EQUAL;
  10258. + src += 2;
  10259. + }
  10260. + else if(!strncmp(src, ">=", 2)){
  10261. + possibilities[i]->constraint = LATER_EQUAL;
  10262. + src += 2;
  10263. + }
  10264. + else if(!strncmp(src, ">>", 2)){
  10265. + possibilities[i]->constraint = LATER;
  10266. + src += 2;
  10267. + }
  10268. + else if(!strncmp(src, "=", 1)){
  10269. + possibilities[i]->constraint = EQUAL;
  10270. + src++;
  10271. + }
  10272. + /* should these be here to support deprecated designations; dpkg does */
  10273. + else if(!strncmp(src, "<", 1)){
  10274. + possibilities[i]->constraint = EARLIER_EQUAL;
  10275. + src++;
  10276. + }
  10277. + else if(!strncmp(src, ">", 1)){
  10278. + possibilities[i]->constraint = LATER_EQUAL;
  10279. + src++;
  10280. + }
  10281. +
  10282. + /* now we have any constraint, pass space to version string */
  10283. + while(isspace(*src)) src++;
  10284. +
  10285. + /* this would be the version string */
  10286. + dest = buffer;
  10287. + while(*src && *src != ')')
  10288. + *dest++ = *src++;
  10289. + *dest = '\0';
  10290. +
  10291. + possibilities[i]->version = trim_alloc(buffer);
  10292. + /* fprintf(stderr, "let's print the depends version string:");
  10293. + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
  10294. + if (possibilities[i]->version == NULL )
  10295. + return -ENOMEM;
  10296. +
  10297. +
  10298. + }
  10299. + /* hook up the dependency to its abstract pkg */
  10300. + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
  10301. +
  10302. + free(pkg_name);
  10303. +
  10304. + /* now get past the ) and any possible | chars */
  10305. + while(*src &&
  10306. + (isspace(*src) ||
  10307. + (*src == ')') ||
  10308. + (*src == '|')))
  10309. + src++;
  10310. + if (*src == '*')
  10311. + {
  10312. + compound_depend->type = GREEDY_DEPEND;
  10313. + src++;
  10314. + }
  10315. + }
  10316. +
  10317. + return 0;
  10318. +}
  10319. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_depends.h busybox-1.15.2/archival/libipkg/pkg_depends.h
  10320. --- busybox-1.15.2.orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
  10321. +++ busybox-1.15.2/archival/libipkg/pkg_depends.h 2010-03-14 20:53:41.000000000 +0100
  10322. @@ -0,0 +1,105 @@
  10323. +/* pkg_depends.h - the itsy package management system
  10324. +
  10325. + Steven M. Ayer
  10326. +
  10327. + Copyright (C) 2002 Compaq Computer Corporation
  10328. +
  10329. + This program is free software; you can redistribute it and/or
  10330. + modify it under the terms of the GNU General Public License as
  10331. + published by the Free Software Foundation; either version 2, or (at
  10332. + your option) any later version.
  10333. +
  10334. + This program is distributed in the hope that it will be useful, but
  10335. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10336. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10337. + General Public License for more details.
  10338. +*/
  10339. +
  10340. +#ifndef PKG_DEPENDS_H
  10341. +#define PKG_DEPENDS_H
  10342. +
  10343. +#include "pkg.h"
  10344. +#include "pkg_hash.h"
  10345. +
  10346. +enum depend_type {
  10347. + PREDEPEND,
  10348. + DEPEND,
  10349. + CONFLICTS,
  10350. + GREEDY_DEPEND,
  10351. + RECOMMEND,
  10352. + SUGGEST
  10353. +};
  10354. +typedef enum depend_type depend_type_t;
  10355. +
  10356. +enum version_constraint {
  10357. + NONE,
  10358. + EARLIER,
  10359. + EARLIER_EQUAL,
  10360. + EQUAL,
  10361. + LATER_EQUAL,
  10362. + LATER
  10363. +};
  10364. +typedef enum version_constraint version_constraint_t;
  10365. +
  10366. +struct depend{
  10367. + version_constraint_t constraint;
  10368. + char * version;
  10369. + abstract_pkg_t * pkg;
  10370. +};
  10371. +typedef struct depend depend_t;
  10372. +
  10373. +struct compound_depend{
  10374. + depend_type_t type;
  10375. + int possibility_count;
  10376. + struct depend ** possibilities;
  10377. +};
  10378. +typedef struct compound_depend compound_depend_t;
  10379. +
  10380. +#include "hash_table.h"
  10381. +
  10382. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10383. +int buildConflicts(hash_table_t * hash, pkg_t * pkg);
  10384. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10385. +int buildDepends(hash_table_t * hash, pkg_t * pkg);
  10386. +
  10387. +/**
  10388. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10389. + * the same abstract package and 0 otherwise.
  10390. + */
  10391. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
  10392. +
  10393. +/**
  10394. + * pkg_provides returns 1 if pkg->provides contains providee and 0
  10395. + * otherwise.
  10396. + */
  10397. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
  10398. +
  10399. +/**
  10400. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10401. + * otherwise.
  10402. + */
  10403. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
  10404. +
  10405. +/**
  10406. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
  10407. + * otherwise.
  10408. + */
  10409. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
  10410. +
  10411. +/**
  10412. + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
  10413. + * otherwise.
  10414. + */
  10415. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
  10416. +
  10417. +char *pkg_depend_str(pkg_t *pkg, int index_);
  10418. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
  10419. +void freeDepends(pkg_t *pkg);
  10420. +void printDepends(pkg_t * pkg);
  10421. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
  10422. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
  10423. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
  10424. +int pkg_dependence_satisfiable(depend_t *depend);
  10425. +int pkg_dependence_satisfied(depend_t *depend);
  10426. +
  10427. +#endif
  10428. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_dest.c busybox-1.15.2/archival/libipkg/pkg_dest.c
  10429. --- busybox-1.15.2.orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
  10430. +++ busybox-1.15.2/archival/libipkg/pkg_dest.c 2010-03-14 20:53:41.000000000 +0100
  10431. @@ -0,0 +1,92 @@
  10432. +/* pkg_dest.c - the itsy package management system
  10433. +
  10434. + Carl D. Worth
  10435. +
  10436. + Copyright (C) 2001 University of Southern California
  10437. +
  10438. + This program is free software; you can redistribute it and/or
  10439. + modify it under the terms of the GNU General Public License as
  10440. + published by the Free Software Foundation; either version 2, or (at
  10441. + your option) any later version.
  10442. +
  10443. + This program is distributed in the hope that it will be useful, but
  10444. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10445. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10446. + General Public License for more details.
  10447. +*/
  10448. +
  10449. +#include "ipkg.h"
  10450. +
  10451. +#include "pkg_dest.h"
  10452. +#include "file_util.h"
  10453. +#include "str_util.h"
  10454. +#include "sprintf_alloc.h"
  10455. +
  10456. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
  10457. +{
  10458. + dest->name = strdup(name);
  10459. +
  10460. + /* Guarantee that dest->root_dir ends with a '/' */
  10461. + if (str_ends_with(root_dir, "/")) {
  10462. + dest->root_dir = strdup(root_dir);
  10463. + } else {
  10464. + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
  10465. + }
  10466. + file_mkdir_hier(dest->root_dir, 0755);
  10467. +
  10468. + sprintf_alloc(&dest->ipkg_dir, "%s%s",
  10469. + dest->root_dir, IPKG_STATE_DIR_PREFIX);
  10470. + file_mkdir_hier(dest->ipkg_dir, 0755);
  10471. +
  10472. + if (str_starts_with (lists_dir, "/"))
  10473. + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
  10474. + else
  10475. + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
  10476. +
  10477. + file_mkdir_hier(dest->lists_dir, 0755);
  10478. +
  10479. + sprintf_alloc(&dest->info_dir, "%s/%s",
  10480. + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
  10481. + file_mkdir_hier(dest->info_dir, 0755);
  10482. +
  10483. + sprintf_alloc(&dest->status_file_name, "%s/%s",
  10484. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10485. +
  10486. + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
  10487. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10488. +
  10489. + dest->status_file = NULL;
  10490. +
  10491. + return 0;
  10492. +}
  10493. +
  10494. +void pkg_dest_deinit(pkg_dest_t *dest)
  10495. +{
  10496. + free(dest->name);
  10497. + dest->name = NULL;
  10498. +
  10499. + free(dest->root_dir);
  10500. + dest->root_dir = NULL;
  10501. +
  10502. + free(dest->ipkg_dir);
  10503. + dest->ipkg_dir = NULL;
  10504. +
  10505. + free(dest->lists_dir);
  10506. + dest->lists_dir = NULL;
  10507. +
  10508. + free(dest->info_dir);
  10509. + dest->info_dir = NULL;
  10510. +
  10511. + free(dest->status_file_name);
  10512. + dest->status_file_name = NULL;
  10513. +
  10514. + free(dest->status_file_tmp_name);
  10515. + dest->status_file_tmp_name = NULL;
  10516. +
  10517. + if (dest->status_file) {
  10518. + fclose(dest->status_file);
  10519. + }
  10520. + dest->status_file = NULL;
  10521. +
  10522. + dest->root_dir = NULL;
  10523. +}
  10524. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_dest.h busybox-1.15.2/archival/libipkg/pkg_dest.h
  10525. --- busybox-1.15.2.orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
  10526. +++ busybox-1.15.2/archival/libipkg/pkg_dest.h 2010-03-14 20:53:41.000000000 +0100
  10527. @@ -0,0 +1,38 @@
  10528. +/* pkg_dest.h - the itsy package management system
  10529. +
  10530. + Carl D. Worth
  10531. +
  10532. + Copyright (C) 2001 University of Southern California
  10533. +
  10534. + This program is free software; you can redistribute it and/or
  10535. + modify it under the terms of the GNU General Public License as
  10536. + published by the Free Software Foundation; either version 2, or (at
  10537. + your option) any later version.
  10538. +
  10539. + This program is distributed in the hope that it will be useful, but
  10540. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10541. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10542. + General Public License for more details.
  10543. +*/
  10544. +
  10545. +#ifndef PKG_DEST_H
  10546. +#define PKG_DEST_H
  10547. +
  10548. +typedef struct pkg_dest pkg_dest_t;
  10549. +struct pkg_dest
  10550. +{
  10551. + char *name;
  10552. + char *root_dir;
  10553. + char *ipkg_dir;
  10554. + char *lists_dir;
  10555. + char *info_dir;
  10556. + char *status_file_name;
  10557. + char *status_file_tmp_name;
  10558. + FILE *status_file;
  10559. +};
  10560. +
  10561. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
  10562. +void pkg_dest_deinit(pkg_dest_t *dest);
  10563. +
  10564. +#endif
  10565. +
  10566. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_dest_list.c busybox-1.15.2/archival/libipkg/pkg_dest_list.c
  10567. --- busybox-1.15.2.orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
  10568. +++ busybox-1.15.2/archival/libipkg/pkg_dest_list.c 2010-03-14 20:53:41.000000000 +0100
  10569. @@ -0,0 +1,85 @@
  10570. +/* pkg_dest_list.c - the itsy package management system
  10571. +
  10572. + Carl D. Worth
  10573. +
  10574. + Copyright (C) 2001 University of Southern California
  10575. +
  10576. + This program is free software; you can redistribute it and/or
  10577. + modify it under the terms of the GNU General Public License as
  10578. + published by the Free Software Foundation; either version 2, or (at
  10579. + your option) any later version.
  10580. +
  10581. + This program is distributed in the hope that it will be useful, but
  10582. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10583. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10584. + General Public License for more details.
  10585. +*/
  10586. +
  10587. +#include "ipkg.h"
  10588. +
  10589. +#include "pkg_dest.h"
  10590. +#include "void_list.h"
  10591. +#include "pkg_dest_list.h"
  10592. +
  10593. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
  10594. +{
  10595. + return void_list_elt_init((void_list_elt_t *) elt, data);
  10596. +}
  10597. +
  10598. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
  10599. +{
  10600. + void_list_elt_deinit((void_list_elt_t *) elt);
  10601. +}
  10602. +
  10603. +int pkg_dest_list_init(pkg_dest_list_t *list)
  10604. +{
  10605. + return void_list_init((void_list_t *) list);
  10606. +}
  10607. +
  10608. +void pkg_dest_list_deinit(pkg_dest_list_t *list)
  10609. +{
  10610. + pkg_dest_list_elt_t *iter;
  10611. + pkg_dest_t *pkg_dest;
  10612. +
  10613. + for (iter = list->head; iter; iter = iter->next) {
  10614. + pkg_dest = iter->data;
  10615. + pkg_dest_deinit(pkg_dest);
  10616. +
  10617. + /* malloced in pkg_dest_list_append */
  10618. + free(pkg_dest);
  10619. + iter->data = NULL;
  10620. + }
  10621. + void_list_deinit((void_list_t *) list);
  10622. +}
  10623. +
  10624. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10625. + const char *root_dir,const char *lists_dir)
  10626. +{
  10627. + int err;
  10628. + pkg_dest_t *pkg_dest;
  10629. +
  10630. + /* freed in plg_dest_list_deinit */
  10631. + pkg_dest = malloc(sizeof(pkg_dest_t));
  10632. + if (pkg_dest == NULL) {
  10633. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10634. + return NULL;
  10635. + }
  10636. +
  10637. + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
  10638. + err = void_list_append((void_list_t *) list, pkg_dest);
  10639. + if (err) {
  10640. + return NULL;
  10641. + }
  10642. +
  10643. + return pkg_dest;
  10644. +}
  10645. +
  10646. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
  10647. +{
  10648. + return void_list_push((void_list_t *) list, data);
  10649. +}
  10650. +
  10651. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
  10652. +{
  10653. + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
  10654. +}
  10655. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_dest_list.h busybox-1.15.2/archival/libipkg/pkg_dest_list.h
  10656. --- busybox-1.15.2.orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
  10657. +++ busybox-1.15.2/archival/libipkg/pkg_dest_list.h 2010-03-14 20:53:41.000000000 +0100
  10658. @@ -0,0 +1,50 @@
  10659. +/* pkg_dest_list.h - the itsy package management system
  10660. +
  10661. + Carl D. Worth
  10662. +
  10663. + Copyright (C) 2001 University of Southern California
  10664. +
  10665. + This program is free software; you can redistribute it and/or
  10666. + modify it under the terms of the GNU General Public License as
  10667. + published by the Free Software Foundation; either version 2, or (at
  10668. + your option) any later version.
  10669. +
  10670. + This program is distributed in the hope that it will be useful, but
  10671. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10672. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10673. + General Public License for more details.
  10674. +*/
  10675. +
  10676. +#ifndef PKG_DEST_LIST_H
  10677. +#define PKG_DEST_LIST_H
  10678. +
  10679. +#include "pkg_dest.h"
  10680. +
  10681. +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
  10682. +struct pkg_dest_list_elt
  10683. +{
  10684. + pkg_dest_list_elt_t *next;
  10685. + pkg_dest_t *data;
  10686. +};
  10687. +
  10688. +typedef struct pkg_dest_list pkg_dest_list_t;
  10689. +struct pkg_dest_list
  10690. +{
  10691. + pkg_dest_list_elt_t pre_head;
  10692. + pkg_dest_list_elt_t *head;
  10693. + pkg_dest_list_elt_t *tail;
  10694. +};
  10695. +
  10696. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
  10697. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
  10698. +
  10699. +int pkg_dest_list_init(pkg_dest_list_t *list);
  10700. +void pkg_dest_list_deinit(pkg_dest_list_t *list);
  10701. +
  10702. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10703. + const char *root_dir,const char* lists_dir);
  10704. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
  10705. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
  10706. +
  10707. +#endif
  10708. +
  10709. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_extract.c busybox-1.15.2/archival/libipkg/pkg_extract.c
  10710. --- busybox-1.15.2.orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
  10711. +++ busybox-1.15.2/archival/libipkg/pkg_extract.c 2010-03-14 20:53:41.000000000 +0100
  10712. @@ -0,0 +1,225 @@
  10713. +/* pkg_extract.c - the itsy package management system
  10714. +
  10715. + Carl D. Worth
  10716. +
  10717. + Copyright (C) 2001 University of Southern California
  10718. +
  10719. + This program is free software; you can redistribute it and/or
  10720. + modify it under the terms of the GNU General Public License as
  10721. + published by the Free Software Foundation; either version 2, or (at
  10722. + your option) any later version.
  10723. +
  10724. + This program is distributed in the hope that it will be useful, but
  10725. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10726. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10727. + General Public License for more details.
  10728. +*/
  10729. +
  10730. +#include "ipkg.h"
  10731. +#include <errno.h>
  10732. +#include <fcntl.h>
  10733. +#include <stdio.h>
  10734. +
  10735. +#include "pkg_extract.h"
  10736. +
  10737. +#include "libbb.h"
  10738. +#include "file_util.h"
  10739. +#include "sprintf_alloc.h"
  10740. +#include "unarchive.h"
  10741. +
  10742. +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
  10743. +#define IPKG_DATA_ARCHIVE "data.tar.gz"
  10744. +#define IPKG_CONTROL_FILE "control"
  10745. +
  10746. +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
  10747. +{
  10748. + archive_handle_t *archive;
  10749. + char *path;
  10750. +
  10751. + sprintf_alloc(&path, "%s/", dir);
  10752. + archive = init_handle();
  10753. + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
  10754. + archive->filter = filter_accept_list;
  10755. + llist_add_to(&(archive->accept), (char *)filename);
  10756. + archive->buffer = path;
  10757. + archive->action_data = data_extract_all_prefix;
  10758. + archive->ah_flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
  10759. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10760. + close(archive->src_fd);
  10761. + free(archive->accept);
  10762. + free(archive);
  10763. + free(path);
  10764. +}
  10765. +
  10766. +static void FAST_FUNC data_extract_file_name_to_buffer(archive_handle_t *archive)
  10767. +{
  10768. + unsigned int size = strlen(archive->file_header->name) + 2;
  10769. +
  10770. + if (archive->buffer == NULL) {
  10771. + archive->buffer = xmalloc(size);
  10772. + strcpy(archive->buffer, archive->file_header->name);
  10773. + } else {
  10774. + size += strlen(archive->buffer);
  10775. + archive->buffer = xrealloc(archive->buffer, size);
  10776. + strcat(archive->buffer, archive->file_header->name);
  10777. + }
  10778. + strcat(archive->buffer, "\n");
  10779. + data_skip(archive);
  10780. +}
  10781. +
  10782. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
  10783. +{
  10784. + archive_handle_t *archive;
  10785. + char *name;
  10786. + const char *filename = "./" IPKG_CONTROL_FILE;
  10787. +
  10788. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10789. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10790. + archive = init_handle();
  10791. + archive->src_fd = xopen(name, O_RDONLY);
  10792. + archive->filter = filter_accept_list;
  10793. + llist_add_to(&(archive->accept), (char *)filename);
  10794. + archive->action_data = data_extract_to_buffer;
  10795. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10796. + close(archive->src_fd);
  10797. + fputs(archive->buffer, stream);
  10798. + free(archive->buffer);
  10799. + free(archive->accept);
  10800. + free(archive);
  10801. + free(name);
  10802. +
  10803. + return 0;
  10804. +}
  10805. +
  10806. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
  10807. +{
  10808. + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
  10809. +}
  10810. +
  10811. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
  10812. +{
  10813. + archive_handle_t *archive;
  10814. + char *name;
  10815. + char *path;
  10816. +
  10817. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10818. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10819. + sprintf_alloc(&path, "%s/%s", dir, prefix);
  10820. + archive = init_handle();
  10821. + archive->src_fd = xopen(name, O_RDONLY);
  10822. + archive->filter = filter_accept_all;
  10823. + archive->buffer = path;
  10824. + archive->action_data = data_extract_all_prefix;
  10825. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
  10826. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10827. + close(archive->src_fd);
  10828. + free(archive);
  10829. + free(path);
  10830. + free(name);
  10831. +
  10832. + return 0;
  10833. +}
  10834. +
  10835. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
  10836. +{
  10837. + archive_handle_t *archive;
  10838. + char *name;
  10839. + char *path;
  10840. +
  10841. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  10842. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  10843. + sprintf_alloc(&path, "%s/", dir);
  10844. + archive = init_handle();
  10845. + archive->src_fd = xopen(name, O_RDONLY);
  10846. + archive->filter = filter_accept_all;
  10847. + archive->buffer = path;
  10848. + archive->action_data = data_extract_all_prefix;
  10849. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
  10850. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10851. + close(archive->src_fd);
  10852. + free(archive);
  10853. + free(path);
  10854. + free(name);
  10855. +
  10856. + return 0;
  10857. +}
  10858. +
  10859. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
  10860. +{
  10861. + int err=0;
  10862. + char *line, *data_file;
  10863. + FILE *file;
  10864. + FILE *tmp;
  10865. +
  10866. + file = fopen(file_name, "w");
  10867. + if (file == NULL) {
  10868. + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
  10869. + __FUNCTION__, file_name);
  10870. + return EINVAL;
  10871. + }
  10872. +
  10873. + tmp = tmpfile();
  10874. + if (pkg->installed_files) {
  10875. + str_list_elt_t *elt;
  10876. + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
  10877. + fprintf(file, "%s\n", elt->data);
  10878. + }
  10879. + } else {
  10880. + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
  10881. + if (err) {
  10882. + fclose(file);
  10883. + fclose(tmp);
  10884. + return err;
  10885. + }
  10886. +
  10887. + /* Fixup data file names by removing the initial '.' */
  10888. + rewind(tmp);
  10889. + while (1) {
  10890. + line = file_read_line_alloc(tmp);
  10891. + if (line == NULL) {
  10892. + break;
  10893. + }
  10894. +
  10895. + data_file = line;
  10896. + if (*data_file == '.') {
  10897. + data_file++;
  10898. + }
  10899. +
  10900. + if (*data_file != '/') {
  10901. + fputs("/", file);
  10902. + }
  10903. +
  10904. + /* I have no idea why, but this is what dpkg does */
  10905. + if (strcmp(data_file, "/\n") == 0) {
  10906. + fputs("/.\n", file);
  10907. + } else {
  10908. + fputs(data_file, file);
  10909. + }
  10910. + }
  10911. + }
  10912. + fclose(tmp);
  10913. + fclose(file);
  10914. +
  10915. + return err;
  10916. +}
  10917. +
  10918. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
  10919. +{
  10920. + archive_handle_t *archive;
  10921. + char *name;
  10922. +
  10923. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  10924. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  10925. + archive = init_handle();
  10926. + archive->src_fd = xopen(name, O_RDONLY);
  10927. + archive->filter = filter_accept_all;
  10928. + archive->action_data = data_extract_file_name_to_buffer;
  10929. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10930. + close(archive->src_fd);
  10931. + fputs(archive->buffer, file);
  10932. + free(archive->buffer);
  10933. + free(archive);
  10934. + free(name);
  10935. +
  10936. + return 0;
  10937. +}
  10938. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_extract.h busybox-1.15.2/archival/libipkg/pkg_extract.h
  10939. --- busybox-1.15.2.orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
  10940. +++ busybox-1.15.2/archival/libipkg/pkg_extract.h 2010-03-14 20:53:41.000000000 +0100
  10941. @@ -0,0 +1,32 @@
  10942. +/* pkg_extract.c - the itsy package management system
  10943. +
  10944. + Carl D. Worth
  10945. +
  10946. + Copyright (C) 2001 University of Southern California
  10947. +
  10948. + This program is free software; you can redistribute it and/or
  10949. + modify it under the terms of the GNU General Public License as
  10950. + published by the Free Software Foundation; either version 2, or (at
  10951. + your option) any later version.
  10952. +
  10953. + This program is distributed in the hope that it will be useful, but
  10954. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10955. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10956. + General Public License for more details.
  10957. +*/
  10958. +
  10959. +#ifndef PKG_EXTRACT_H
  10960. +#define PKG_EXTRACT_H
  10961. +
  10962. +#include "pkg.h"
  10963. +
  10964. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
  10965. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
  10966. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
  10967. + const char *dir,
  10968. + const char *prefix);
  10969. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
  10970. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
  10971. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
  10972. +
  10973. +#endif
  10974. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg.h busybox-1.15.2/archival/libipkg/pkg.h
  10975. --- busybox-1.15.2.orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
  10976. +++ busybox-1.15.2/archival/libipkg/pkg.h 2010-03-14 20:53:41.000000000 +0100
  10977. @@ -0,0 +1,229 @@
  10978. +/* pkg.h - the itsy package management system
  10979. +
  10980. + Carl D. Worth
  10981. +
  10982. + Copyright (C) 2001 University of Southern California
  10983. +
  10984. + This program is free software; you can redistribute it and/or
  10985. + modify it under the terms of the GNU General Public License as
  10986. + published by the Free Software Foundation; either version 2, or (at
  10987. + your option) any later version.
  10988. +
  10989. + This program is distributed in the hope that it will be useful, but
  10990. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10991. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10992. + General Public License for more details.
  10993. +*/
  10994. +
  10995. +#ifndef PKG_H
  10996. +#define PKG_H
  10997. +
  10998. +#include <sys/types.h>
  10999. +#include <sys/stat.h>
  11000. +#include <unistd.h>
  11001. +
  11002. +#include "pkg_vec.h"
  11003. +#include "str_list.h"
  11004. +#include "pkg_src.h"
  11005. +#include "pkg_dest.h"
  11006. +#include "ipkg_conf.h"
  11007. +#include "conffile_list.h"
  11008. +
  11009. +struct ipkg_conf;
  11010. +
  11011. +/* I think "Size" is currently the shortest field name */
  11012. +#define PKG_MINIMUM_FIELD_NAME_LEN 4
  11013. +
  11014. +enum pkg_state_want
  11015. +{
  11016. + SW_UNKNOWN = 1,
  11017. + SW_INSTALL,
  11018. + SW_DEINSTALL,
  11019. + SW_PURGE,
  11020. + SW_LAST_STATE_WANT
  11021. +};
  11022. +typedef enum pkg_state_want pkg_state_want_t;
  11023. +
  11024. +enum pkg_state_flag
  11025. +{
  11026. + SF_OK = 0,
  11027. + SF_REINSTREQ = 1,
  11028. + SF_HOLD = 2, /* do not upgrade version */
  11029. + SF_REPLACE = 4, /* replace this package */
  11030. + SF_NOPRUNE = 8, /* do not remove obsolete files */
  11031. + SF_PREFER = 16, /* prefer this version */
  11032. + SF_OBSOLETE = 32, /* old package in upgrade pair */
  11033. + SF_MARKED = 64, /* temporary mark */
  11034. + SF_FILELIST_CHANGED = 128, /* needs filelist written */
  11035. + SF_USER = 256,
  11036. + SF_LAST_STATE_FLAG
  11037. +};
  11038. +typedef enum pkg_state_flag pkg_state_flag_t;
  11039. +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
  11040. +
  11041. +enum pkg_state_status
  11042. +{
  11043. + SS_NOT_INSTALLED = 1,
  11044. + SS_UNPACKED,
  11045. + SS_HALF_CONFIGURED,
  11046. + SS_INSTALLED,
  11047. + SS_HALF_INSTALLED,
  11048. + SS_CONFIG_FILES,
  11049. + SS_POST_INST_FAILED,
  11050. + SS_REMOVAL_FAILED,
  11051. + SS_LAST_STATE_STATUS
  11052. +};
  11053. +typedef enum pkg_state_status pkg_state_status_t;
  11054. +
  11055. +struct abstract_pkg{
  11056. + char * name;
  11057. + int dependencies_checked;
  11058. + pkg_vec_t * pkgs;
  11059. + pkg_state_status_t state_status;
  11060. + pkg_state_flag_t state_flag;
  11061. + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
  11062. + abstract_pkg_vec_t * provided_by;
  11063. + abstract_pkg_vec_t * replaced_by;
  11064. +};
  11065. +
  11066. +#include "pkg_depends.h"
  11067. +
  11068. +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
  11069. +
  11070. + The 3 version fields should go into a single version struct. (This
  11071. + is especially important since, currently, pkg->version can easily
  11072. + be mistaken for pkg_verson_str_alloc(pkg) although they are very
  11073. + distinct. This has been the source of multiple bugs.
  11074. +
  11075. + The 3 state fields could possibly also go into their own struct.
  11076. +
  11077. + All fields which deal with lists of packages, (Depends,
  11078. + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
  11079. + be handled by a single struct in pkg_t
  11080. +
  11081. + All string fields for which there is a small set of possible
  11082. + values, (section, maintainer, architecture, maybe version?), that
  11083. + are reused among different packages -- for all such packages we
  11084. + should move from "char *"s to some atom datatype to share data
  11085. + storage and use less memory. We might even do reference counting,
  11086. + but probably not since most often we only create new pkg_t structs,
  11087. + we don't often free them. */
  11088. +struct pkg
  11089. +{
  11090. + char *name;
  11091. + unsigned long epoch;
  11092. + char *version;
  11093. + char *revision;
  11094. + char *familiar_revision;
  11095. + pkg_src_t *src;
  11096. + pkg_dest_t *dest;
  11097. + char *architecture;
  11098. + char *section;
  11099. + char *maintainer;
  11100. + char *description;
  11101. + pkg_state_want_t state_want;
  11102. + pkg_state_flag_t state_flag;
  11103. + pkg_state_status_t state_status;
  11104. + char **depends_str;
  11105. + int depends_count;
  11106. + char **pre_depends_str;
  11107. + int pre_depends_count;
  11108. + char **recommends_str;
  11109. + int recommends_count;
  11110. + char **suggests_str;
  11111. + int suggests_count;
  11112. + compound_depend_t * depends;
  11113. +
  11114. + /* Abhaya: new conflicts */
  11115. + char **conflicts_str;
  11116. + compound_depend_t * conflicts;
  11117. + int conflicts_count;
  11118. +
  11119. + char **replaces_str;
  11120. + int replaces_count;
  11121. + abstract_pkg_t ** replaces;
  11122. +
  11123. + char **provides_str;
  11124. + int provides_count;
  11125. + abstract_pkg_t ** provides;
  11126. +
  11127. + abstract_pkg_t *parent;
  11128. +
  11129. + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
  11130. +
  11131. + char *filename;
  11132. + char *local_filename;
  11133. + char *url;
  11134. + char *tmp_unpack_dir;
  11135. + char *md5sum;
  11136. + char *size;
  11137. + char *installed_size;
  11138. + char *priority;
  11139. + char *source;
  11140. + conffile_list_t conffiles;
  11141. + time_t installed_time;
  11142. + /* As pointer for lazy evaluation */
  11143. + str_list_t *installed_files;
  11144. + /* XXX: CLEANUP: I'd like to perhaps come up with a better
  11145. + mechanism to avoid the problem here, (which is that the
  11146. + installed_files list was being freed from an inner loop while
  11147. + still being used within an outer loop. */
  11148. + int installed_files_ref_cnt;
  11149. + int essential;
  11150. + int arch_priority;
  11151. +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
  11152. + int provided_by_hand;
  11153. +};
  11154. +
  11155. +pkg_t *pkg_new(void);
  11156. +int pkg_init(pkg_t *pkg);
  11157. +void pkg_deinit(pkg_t *pkg);
  11158. +int pkg_init_from_file(pkg_t *pkg, const char *filename);
  11159. +abstract_pkg_t *abstract_pkg_new(void);
  11160. +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
  11161. +
  11162. +/*
  11163. + * merges fields from newpkg into oldpkg.
  11164. + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
  11165. + */
  11166. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
  11167. +
  11168. +char *pkg_version_str_alloc(pkg_t *pkg);
  11169. +
  11170. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
  11171. +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
  11172. +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
  11173. +
  11174. +char * pkg_formatted_info(pkg_t *pkg );
  11175. +char * pkg_formatted_field(pkg_t *pkg, const char *field );
  11176. +
  11177. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
  11178. +
  11179. +void pkg_print_info(pkg_t *pkg, FILE *file);
  11180. +void pkg_print_status(pkg_t * pkg, FILE * file);
  11181. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
  11182. +str_list_t *pkg_get_installed_files(pkg_t *pkg);
  11183. +int pkg_free_installed_files(pkg_t *pkg);
  11184. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
  11185. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
  11186. +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
  11187. + const char *script, const char *args);
  11188. +
  11189. +/* enum mappings */
  11190. +char *pkg_state_want_to_str(pkg_state_want_t sw);
  11191. +pkg_state_want_t pkg_state_want_from_str(char *str);
  11192. +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
  11193. +pkg_state_flag_t pkg_state_flag_from_str(char *str);
  11194. +char *pkg_state_status_to_str(pkg_state_status_t ss);
  11195. +pkg_state_status_t pkg_state_status_from_str(char *str);
  11196. +
  11197. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
  11198. +
  11199. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
  11200. +int pkg_info_preinstall_check(ipkg_conf_t *conf);
  11201. +int pkg_free_installed_files(pkg_t *pkg);
  11202. +
  11203. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
  11204. +int pkg_write_changed_filelists(ipkg_conf_t *conf);
  11205. +
  11206. +#endif
  11207. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_hash.c busybox-1.15.2/archival/libipkg/pkg_hash.c
  11208. --- busybox-1.15.2.orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
  11209. +++ busybox-1.15.2/archival/libipkg/pkg_hash.c 2010-03-14 20:53:41.000000000 +0100
  11210. @@ -0,0 +1,623 @@
  11211. +/* ipkg_hash.c - the itsy package management system
  11212. +
  11213. + Steven M. Ayer
  11214. +
  11215. + Copyright (C) 2002 Compaq Computer Corporation
  11216. +
  11217. + This program is free software; you can redistribute it and/or
  11218. + modify it under the terms of the GNU General Public License as
  11219. + published by the Free Software Foundation; either version 2, or (at
  11220. + your option) any later version.
  11221. +
  11222. + This program is distributed in the hope that it will be useful, but
  11223. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11224. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11225. + General Public License for more details.
  11226. +*/
  11227. +
  11228. +#include "ipkg.h"
  11229. +#include <errno.h>
  11230. +#include <ctype.h>
  11231. +#include <stdlib.h>
  11232. +#include <string.h>
  11233. +
  11234. +#include "hash_table.h"
  11235. +#include "pkg.h"
  11236. +#include "ipkg_message.h"
  11237. +#include "pkg_vec.h"
  11238. +#include "pkg_hash.h"
  11239. +#include "pkg_parse.h"
  11240. +#include "ipkg_utils.h"
  11241. +
  11242. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11243. +
  11244. +/*
  11245. + * this will talk to both feeds-lists files and installed status files
  11246. + * example api:
  11247. + *
  11248. + * hash_table_t hash;
  11249. + * pkg_hash_init(name, &hash, 1000);
  11250. + * pkg_hash_add_from_file(<feed filename>);
  11251. + *
  11252. + * the query function is just there as a shell to prove to me that this
  11253. + * sort of works, but isn't far from doing something useful
  11254. + *
  11255. + * -sma, 12/21/01
  11256. + * modified: CDW 3 Jan. 2002
  11257. + */
  11258. +
  11259. +
  11260. +
  11261. +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
  11262. +{
  11263. + return hash_table_init(name, hash, len);
  11264. +}
  11265. +
  11266. +void pkg_hash_deinit(hash_table_t *hash)
  11267. +{
  11268. + hash_table_deinit(hash);
  11269. +}
  11270. +
  11271. +
  11272. +/* Find the default arch for a given package status file if none is given. */
  11273. +static char *pkg_get_default_arch(ipkg_conf_t *conf)
  11274. +{
  11275. + nv_pair_list_elt_t *l;
  11276. + const char *def_arch = HOST_CPU_STR; /* Default arch */
  11277. + int def_prio = 0; /* Other archs override this */
  11278. +
  11279. + l = conf->arch_list.head;
  11280. +
  11281. + while (l) {
  11282. + nv_pair_t *nv = l->data;
  11283. + int priority = strtol(nv->value, NULL, 0);
  11284. +
  11285. + /* Check if this arch has higher priority, and is valid */
  11286. + if ((priority > def_prio) &&
  11287. + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
  11288. + /* Our new default */
  11289. + def_prio = priority;
  11290. + def_arch = nv->name;
  11291. + }
  11292. + l = l->next;
  11293. + }
  11294. +
  11295. + return strdup(def_arch);
  11296. +}
  11297. +
  11298. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11299. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
  11300. +{
  11301. + hash_table_t *hash = &conf->pkg_hash;
  11302. + char **raw;
  11303. + char **raw_start;
  11304. + pkg_t *pkg;
  11305. +
  11306. + raw = raw_start = read_raw_pkgs_from_file(file_name);
  11307. + if (!raw)
  11308. + return -ENOMEM;
  11309. +
  11310. + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
  11311. + pkg = pkg_new();
  11312. + if (!pkg)
  11313. + return -ENOMEM;
  11314. +
  11315. + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
  11316. + if (!pkg->architecture) {
  11317. + char *version_str = pkg_version_str_alloc(pkg);
  11318. + pkg->architecture = pkg_get_default_arch(conf);
  11319. + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
  11320. + pkg->name, version_str, pkg->architecture);
  11321. + free(version_str);
  11322. + }
  11323. + hash_insert_pkg(hash, pkg, is_status_file,conf);
  11324. + } else {
  11325. + free(pkg);
  11326. + }
  11327. + }
  11328. +
  11329. + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
  11330. + memory after read_raw_pkgs_from_file */
  11331. + raw = raw_start;
  11332. + while (*raw) {
  11333. + free(*raw++);
  11334. + }
  11335. + free(raw_start);
  11336. + return 0;
  11337. +}
  11338. +
  11339. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
  11340. +{
  11341. + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
  11342. +}
  11343. +
  11344. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
  11345. +{
  11346. + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
  11347. + if (apkg)
  11348. + return NULL;
  11349. + return apkg->provided_by;
  11350. +}
  11351. +
  11352. +
  11353. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11354. + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
  11355. +{
  11356. + int i;
  11357. + int nprovides = 0;
  11358. + int nmatching = 0;
  11359. + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
  11360. + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
  11361. + abstract_pkg_vec_t *provided_apkg_vec;
  11362. + abstract_pkg_t **provided_apkgs;
  11363. + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
  11364. + pkg_t *latest_installed_parent = NULL;
  11365. + pkg_t *latest_matching = NULL;
  11366. + pkg_t *held_pkg = NULL;
  11367. + pkg_t *good_pkg_by_name = NULL;
  11368. +
  11369. + if (matching_apkgs == NULL || providers == NULL ||
  11370. + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
  11371. + return NULL;
  11372. +
  11373. + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
  11374. +
  11375. + provided_apkg_vec = apkg->provided_by;
  11376. + nprovides = provided_apkg_vec->len;
  11377. + provided_apkgs = provided_apkg_vec->pkgs;
  11378. + if (nprovides > 1)
  11379. + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
  11380. +
  11381. + /* accumulate all the providers */
  11382. + for (i = 0; i < nprovides; i++) {
  11383. + abstract_pkg_t *provider_apkg = provided_apkgs[i];
  11384. + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
  11385. + abstract_pkg_vec_insert(providers, provider_apkg);
  11386. + }
  11387. + nprovides = providers->len;
  11388. +
  11389. + for (i = 0; i < nprovides; i++) {
  11390. + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
  11391. + abstract_pkg_t *replacement_apkg = NULL;
  11392. + pkg_vec_t *vec;
  11393. +
  11394. + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
  11395. + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
  11396. + if (provider_apkg->replaced_by->len > 1) {
  11397. + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
  11398. + provider_apkg->name, replacement_apkg->name);
  11399. + }
  11400. + }
  11401. +
  11402. + if (replacement_apkg)
  11403. + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
  11404. + replacement_apkg->name, provider_apkg->name);
  11405. +
  11406. + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
  11407. + if (abstract_pkg_vec_contains(providers, replacement_apkg))
  11408. + continue;
  11409. + else
  11410. + provider_apkg = replacement_apkg;
  11411. + }
  11412. +
  11413. + if (!(vec = provider_apkg->pkgs)) {
  11414. + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
  11415. + continue;
  11416. + }
  11417. +
  11418. +
  11419. + /* now check for supported architecture */
  11420. + {
  11421. + int max_count = 0;
  11422. + int j;
  11423. +
  11424. + /* count packages matching max arch priority and keep track of last one */
  11425. + for (j = 0; j < vec->len; j++) {
  11426. + pkg_t *maybe = vec->pkgs[j];
  11427. + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
  11428. + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
  11429. + if (maybe->arch_priority > 0) {
  11430. + max_count++;
  11431. + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
  11432. + pkg_vec_insert(matching_pkgs, maybe);
  11433. + }
  11434. + }
  11435. + }
  11436. + }
  11437. +
  11438. + if (matching_pkgs->len > 1)
  11439. + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
  11440. + if (matching_apkgs->len > 1)
  11441. + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
  11442. +
  11443. +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
  11444. + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
  11445. +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
  11446. + Until now I always got the latest, but that breaks the downgrade option.
  11447. + If I stop at the first one, I would probably miss the new ones
  11448. + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
  11449. + or from a Packages feed.
  11450. + 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*/
  11451. +/*Pigi*/
  11452. +
  11453. + for (i = 0; i < matching_pkgs->len; i++) {
  11454. + pkg_t *matching = matching_pkgs->pkgs[i];
  11455. + if (constraint_fcn(matching, cdata)) { /* We found it */
  11456. + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
  11457. + good_pkg_by_name = matching;
  11458. + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
  11459. + break;
  11460. + }
  11461. + }
  11462. +
  11463. +
  11464. + for (i = 0; i < matching_pkgs->len; i++) {
  11465. + pkg_t *matching = matching_pkgs->pkgs[i];
  11466. + latest_matching = matching;
  11467. + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
  11468. + latest_installed_parent = matching;
  11469. + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
  11470. + if (held_pkg)
  11471. + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
  11472. + held_pkg->name, matching->name);
  11473. + held_pkg = matching;
  11474. + }
  11475. + }
  11476. +
  11477. + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
  11478. + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
  11479. + apkg->name, matching_apkgs->len);
  11480. + for (i = 0; i < matching_apkgs->len; i++) {
  11481. + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
  11482. + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
  11483. + }
  11484. + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
  11485. + }
  11486. +
  11487. + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
  11488. + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
  11489. + __FUNCTION__, apkg->name, matching_pkgs->len);
  11490. + for (i = 0; i < matching_pkgs->len; i++) {
  11491. + pkg_t *matching = matching_pkgs->pkgs[i];
  11492. + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
  11493. + matching->name, matching->version, matching->architecture);
  11494. + }
  11495. + }
  11496. +
  11497. + nmatching = matching_apkgs->len;
  11498. +
  11499. + pkg_vec_free(matching_pkgs);
  11500. + abstract_pkg_vec_free(matching_apkgs);
  11501. + abstract_pkg_vec_free(providers);
  11502. +
  11503. + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
  11504. + return good_pkg_by_name;
  11505. + }
  11506. + if (held_pkg) {
  11507. + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
  11508. + return held_pkg;
  11509. + }
  11510. + if (latest_installed_parent) {
  11511. + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
  11512. + return latest_installed_parent;
  11513. + }
  11514. + if (nmatching > 1) {
  11515. + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
  11516. + return NULL;
  11517. + }
  11518. + if (latest_matching) {
  11519. + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
  11520. + latest_matching->name, latest_matching->version, latest_matching->architecture);
  11521. + return latest_matching;
  11522. + }
  11523. + return NULL;
  11524. +}
  11525. +
  11526. +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
  11527. +{
  11528. + const char *name = (const char *)cdata;
  11529. + if (strcmp(pkg->name, name) == 0)
  11530. + return 1;
  11531. + else
  11532. + return 0;
  11533. +}
  11534. +
  11535. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
  11536. +{
  11537. + hash_table_t *hash = &conf->pkg_hash;
  11538. + abstract_pkg_t *apkg = NULL;
  11539. +
  11540. + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
  11541. + return NULL;
  11542. +
  11543. + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
  11544. +}
  11545. +
  11546. +
  11547. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11548. + const char *pkg_name,
  11549. + const char * version)
  11550. +{
  11551. + pkg_vec_t * vec;
  11552. + register int i;
  11553. + char *version_str = NULL;
  11554. +
  11555. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
  11556. + return NULL;
  11557. +
  11558. + for(i = 0; i < vec->len; i++) {
  11559. + version_str = pkg_version_str_alloc(vec->pkgs[i]);
  11560. + if(!strcmp(version_str, version)) {
  11561. + free(version_str);
  11562. + break;
  11563. + }
  11564. + free(version_str);
  11565. + }
  11566. +
  11567. + if(i == vec->len)
  11568. + return NULL;
  11569. +
  11570. + return vec->pkgs[i];
  11571. +}
  11572. +
  11573. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11574. + const char *pkg_name,
  11575. + pkg_dest_t *dest)
  11576. +{
  11577. + pkg_vec_t * vec;
  11578. + register int i;
  11579. +
  11580. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
  11581. + return NULL;
  11582. + }
  11583. +
  11584. + for(i = 0; i < vec->len; i++)
  11585. + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
  11586. + return vec->pkgs[i];
  11587. + }
  11588. + return NULL;
  11589. +}
  11590. +
  11591. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11592. + const char *pkg_name)
  11593. +{
  11594. + pkg_vec_t * vec;
  11595. + register int i;
  11596. +
  11597. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
  11598. + return NULL;
  11599. + }
  11600. +
  11601. + for(i = 0; i < vec->len; i++)
  11602. + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
  11603. + return vec->pkgs[i];
  11604. + }
  11605. +
  11606. + return NULL;
  11607. +}
  11608. +
  11609. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
  11610. +{
  11611. + abstract_pkg_t * ab_pkg;
  11612. +
  11613. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
  11614. + return NULL;
  11615. + }
  11616. +
  11617. + if (ab_pkg->pkgs) {
  11618. + return ab_pkg->pkgs;
  11619. + } else if (ab_pkg->provided_by) {
  11620. + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
  11621. + if (abpkg != NULL){
  11622. + return abpkg->pkgs;
  11623. + } else {
  11624. + return ab_pkg->pkgs;
  11625. + }
  11626. + } else {
  11627. + return NULL;
  11628. + }
  11629. +}
  11630. +
  11631. +static int pkg_compare_names(const void *p1, const void *p2)
  11632. +{
  11633. + const pkg_t *pkg1 = *(const pkg_t **)p1;
  11634. + const pkg_t *pkg2 = *(const pkg_t **)p2;
  11635. + if (pkg1->name == NULL)
  11636. + return 1;
  11637. + if (pkg2->name == NULL)
  11638. + return -1;
  11639. + return(strcmp(pkg1->name, pkg2->name));
  11640. +}
  11641. +
  11642. +
  11643. +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
  11644. +{
  11645. + int j;
  11646. + const char *name;
  11647. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11648. + pkg_vec_t *all = (pkg_vec_t *)data;
  11649. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11650. + name = pkg_name;
  11651. + if (pkg_vec) {
  11652. + for (j = 0; j < pkg_vec->len; j++) {
  11653. + pkg_t *pkg = pkg_vec->pkgs[j];
  11654. + pkg_vec_insert(all, pkg);
  11655. + }
  11656. + }
  11657. +}
  11658. +
  11659. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
  11660. +{
  11661. + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
  11662. + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
  11663. +}
  11664. +
  11665. +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
  11666. +{
  11667. + const char *name;
  11668. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11669. + pkg_vec_t *all = (pkg_vec_t *)data;
  11670. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11671. + int j;
  11672. + name = pkg_name;
  11673. + if (pkg_vec) {
  11674. + for (j = 0; j < pkg_vec->len; j++) {
  11675. + pkg_t *pkg = pkg_vec->pkgs[j];
  11676. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  11677. + pkg_vec_insert(all, pkg);
  11678. + }
  11679. + }
  11680. + }
  11681. +}
  11682. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
  11683. +{
  11684. + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
  11685. + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
  11686. +}
  11687. +
  11688. +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
  11689. +{
  11690. + int i;
  11691. + pkg_t *pkg;
  11692. + const char *name;
  11693. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11694. + ipkg_conf_t *conf = (ipkg_conf_t *)data;
  11695. + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
  11696. + name = pkg_name;
  11697. + fprintf(stdout, "%s\n", ab_pkg->name);
  11698. + i = 0;
  11699. + if (dependents != NULL)
  11700. + while (dependents [i] != NULL)
  11701. + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
  11702. + dependents = ab_pkg->provided_by->pkgs;
  11703. + i = 0;
  11704. + if (dependents != NULL)
  11705. + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
  11706. + printf ("\tprovided by - %s\n", dependents [i ++]->name);
  11707. + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
  11708. + if (pkg) {
  11709. + i = 0;
  11710. + while (i < pkg->depends_count)
  11711. + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
  11712. + }
  11713. +}
  11714. +void pkg_hash_dump(hash_table_t *hash, void *data)
  11715. +{
  11716. +
  11717. + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
  11718. + hash_table_foreach(hash, pkg_hash_dump_helper, data);
  11719. + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
  11720. +}
  11721. +
  11722. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11723. +{
  11724. + abstract_pkg_t * ab_pkg;
  11725. +
  11726. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
  11727. + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
  11728. +
  11729. + return ab_pkg;
  11730. +}
  11731. +
  11732. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  11733. +{
  11734. + abstract_pkg_t * ab_pkg;
  11735. + int arch_priority;
  11736. +
  11737. + if(!pkg)
  11738. + return pkg;
  11739. +
  11740. + arch_priority = pkg->arch_priority;
  11741. +
  11742. + if (buildDepends(hash, pkg)<0){
  11743. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11744. + return NULL;
  11745. + }
  11746. + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
  11747. +
  11748. + if (set_status) {
  11749. + if (pkg->state_status == SS_INSTALLED) {
  11750. + ab_pkg->state_status = SS_INSTALLED;
  11751. + } else if (pkg->state_status == SS_UNPACKED) {
  11752. + ab_pkg->state_status = SS_UNPACKED;
  11753. + }
  11754. + }
  11755. +
  11756. + if(!ab_pkg->pkgs)
  11757. + ab_pkg->pkgs = pkg_vec_alloc();
  11758. +
  11759. + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
  11760. + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
  11761. + pkg->parent = ab_pkg;
  11762. +
  11763. + if (buildProvides(hash, ab_pkg, pkg)<0){
  11764. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11765. + return NULL;
  11766. + }
  11767. + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
  11768. + if (buildConflicts(hash, pkg)<0){
  11769. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11770. + return NULL;
  11771. + }
  11772. + if (buildReplaces(hash, ab_pkg, pkg)<0) {
  11773. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11774. + return NULL;
  11775. + }
  11776. +
  11777. + buildDependedUponBy(pkg, ab_pkg);
  11778. + return pkg;
  11779. +}
  11780. +
  11781. +/*
  11782. + * this will assume that we've already determined that
  11783. + * the abstract pkg doesn't exist, 'cause we should know these things...
  11784. + */
  11785. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11786. +{
  11787. + abstract_pkg_t * ab_pkg;
  11788. +
  11789. + ab_pkg = abstract_pkg_new();
  11790. + if (ab_pkg == NULL) { return NULL; }
  11791. +
  11792. + ab_pkg->name = strdup(pkg_name);
  11793. + hash_table_insert(hash, pkg_name, ab_pkg);
  11794. +
  11795. + return ab_pkg;
  11796. +}
  11797. +
  11798. +
  11799. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
  11800. +{
  11801. + hash_table_t *file_hash = &conf->file_hash;
  11802. +
  11803. + return hash_table_get(file_hash, file_name);
  11804. +}
  11805. +
  11806. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
  11807. +{
  11808. + hash_table_t *file_hash = &conf->file_hash;
  11809. + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
  11810. + int file_name_len = strlen(file_name);
  11811. +
  11812. + if (file_name[file_name_len -1] == '/')
  11813. + return 0;
  11814. +
  11815. + if (conf->offline_root) {
  11816. + int len = strlen(conf->offline_root);
  11817. + if (strncmp(file_name, conf->offline_root, len) == 0) {
  11818. + file_name += len;
  11819. + }
  11820. + }
  11821. +
  11822. + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
  11823. + hash_table_insert(file_hash, file_name, owning_pkg);
  11824. + if (old_owning_pkg) {
  11825. + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
  11826. + /* mark this package to have its filelist written */
  11827. + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11828. + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11829. + }
  11830. + return 0;
  11831. +}
  11832. +
  11833. +
  11834. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_hash.h busybox-1.15.2/archival/libipkg/pkg_hash.h
  11835. --- busybox-1.15.2.orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
  11836. +++ busybox-1.15.2/archival/libipkg/pkg_hash.h 2010-03-14 20:53:41.000000000 +0100
  11837. @@ -0,0 +1,61 @@
  11838. +/* pkg_hash.h - the itsy package management system
  11839. +
  11840. + Steven M. Ayer
  11841. +
  11842. + Copyright (C) 2002 Compaq Computer Corporation
  11843. +
  11844. + This program is free software; you can redistribute it and/or
  11845. + modify it under the terms of the GNU General Public License as
  11846. + published by the Free Software Foundation; either version 2, or (at
  11847. + your option) any later version.
  11848. +
  11849. + This program is distributed in the hope that it will be useful, but
  11850. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11851. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11852. + General Public License for more details.
  11853. +*/
  11854. +
  11855. +#ifndef PKG_HASH_H
  11856. +#define PKG_HASH_H
  11857. +
  11858. +#include "pkg.h"
  11859. +#include "pkg_vec.h"
  11860. +#include "hash_table.h"
  11861. +
  11862. +
  11863. +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
  11864. +void pkg_hash_deinit(hash_table_t *hash);
  11865. +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
  11866. +
  11867. +void pkg_hash_dump(hash_table_t *hash, void *data);
  11868. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
  11869. +
  11870. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11871. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
  11872. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
  11873. +
  11874. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11875. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
  11876. +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11877. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
  11878. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11879. + const char *pkg_name,
  11880. + const char * version);
  11881. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
  11882. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11883. + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
  11884. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
  11885. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11886. + const char *pkg_name);
  11887. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11888. + const char *pkg_name,
  11889. + pkg_dest_t *dest);
  11890. +
  11891. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
  11892. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
  11893. +
  11894. +/* XXX: shouldn't this go in pkg_vec.[ch]? */
  11895. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11896. +
  11897. +#endif
  11898. +
  11899. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_parse.c busybox-1.15.2/archival/libipkg/pkg_parse.c
  11900. --- busybox-1.15.2.orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
  11901. +++ busybox-1.15.2/archival/libipkg/pkg_parse.c 2010-03-14 20:53:41.000000000 +0100
  11902. @@ -0,0 +1,368 @@
  11903. +/* pkg_parse.c - the itsy package management system
  11904. +
  11905. + Steven M. Ayer
  11906. +
  11907. + Copyright (C) 2002 Compaq Computer Corporation
  11908. +
  11909. + This program is free software; you can redistribute it and/or
  11910. + modify it under the terms of the GNU General Public License as
  11911. + published by the Free Software Foundation; either version 2, or (at
  11912. + your option) any later version.
  11913. +
  11914. + This program is distributed in the hope that it will be useful, but
  11915. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11916. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11917. + General Public License for more details.
  11918. +*/
  11919. +
  11920. +#include "ipkg.h"
  11921. +#include <errno.h>
  11922. +#include <ctype.h>
  11923. +
  11924. +#include "pkg.h"
  11925. +#include "ipkg_utils.h"
  11926. +#include "pkg_parse.h"
  11927. +
  11928. +int alterProvidesLine(char *raw, char *temp);
  11929. +
  11930. +int isGenericFieldType(char * type, char * line)
  11931. +{
  11932. + if(!strncmp(line, type, strlen(type)))
  11933. + return 1;
  11934. + return 0;
  11935. +}
  11936. +
  11937. +char * parseGenericFieldType(char * type, char * raw)
  11938. +{
  11939. + char * field_value = raw + (strlen(type) + 1);
  11940. + return trim_alloc(field_value);
  11941. +}
  11942. +
  11943. +void parseStatus(pkg_t *pkg, char * raw)
  11944. +{
  11945. + char sw_str[64], sf_str[64], ss_str[64];
  11946. +
  11947. + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
  11948. + pkg->state_want = pkg_state_want_from_str(sw_str);
  11949. + pkg->state_flag = pkg_state_flag_from_str(sf_str);
  11950. + pkg->state_status = pkg_state_status_from_str(ss_str);
  11951. +}
  11952. +
  11953. +char ** parseDependsString(char * raw, int * depends_count)
  11954. +{
  11955. + char ** depends = NULL;
  11956. + int line_count = 0;
  11957. + char buff[2048], * dest;
  11958. +
  11959. + while(raw && *raw && !isspace(*raw)) {
  11960. + raw++;
  11961. + }
  11962. +
  11963. + if(line_is_blank(raw)){
  11964. + *depends_count = line_count;
  11965. + return NULL;
  11966. + }
  11967. + while(raw && *raw){
  11968. + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
  11969. +
  11970. + while(isspace(*raw)) raw++;
  11971. +
  11972. + dest = buff;
  11973. + while((*raw != ',') && *raw)
  11974. + *dest++ = *raw++;
  11975. +
  11976. + *dest = '\0';
  11977. + depends[line_count] = trim_alloc(buff);
  11978. + if(depends[line_count] ==NULL)
  11979. + return NULL;
  11980. + line_count++;
  11981. + if(*raw == ',')
  11982. + raw++;
  11983. + }
  11984. + *depends_count = line_count;
  11985. + return depends;
  11986. +}
  11987. +
  11988. +void parseConffiles(pkg_t * pkg, char * raw)
  11989. +{
  11990. + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
  11991. +
  11992. + if(!strncmp(raw, "Conffiles:", 10))
  11993. + raw += strlen("Conffiles:");
  11994. +
  11995. + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
  11996. + conffile_list_append(&pkg->conffiles, file_name, md5sum);
  11997. + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
  11998. + while (*raw && isspace(*raw)) {
  11999. + raw++;
  12000. + }
  12001. + raw += strlen(file_name);
  12002. + while (*raw && isspace(*raw)) {
  12003. + raw++;
  12004. + }
  12005. + raw += strlen(md5sum);
  12006. + }
  12007. +}
  12008. +
  12009. +int parseVersion(pkg_t *pkg, char *raw)
  12010. +{
  12011. + char *colon, *eepochcolon;
  12012. +#ifdef USE_DEBVERSION
  12013. + char *hyphen;
  12014. +#endif
  12015. + unsigned long epoch;
  12016. +
  12017. + if (!*raw) {
  12018. + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
  12019. + return EINVAL;
  12020. + }
  12021. +
  12022. + if (strncmp(raw, "Version:", 8) == 0) {
  12023. + raw += 8;
  12024. + }
  12025. + while (*raw && isspace(*raw)) {
  12026. + raw++;
  12027. + }
  12028. +
  12029. + colon= strchr(raw,':');
  12030. + if (colon) {
  12031. + epoch= strtoul(raw,&eepochcolon,10);
  12032. + if (colon != eepochcolon) {
  12033. + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
  12034. + return EINVAL;
  12035. + }
  12036. + if (!*++colon) {
  12037. + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
  12038. + return EINVAL;
  12039. + }
  12040. + raw= colon;
  12041. + pkg->epoch= epoch;
  12042. + } else {
  12043. + pkg->epoch= 0;
  12044. + }
  12045. +
  12046. + pkg->revision = (char *)"";
  12047. + pkg->familiar_revision = (char *)"";
  12048. +
  12049. + pkg->version= malloc(strlen(raw)+1);
  12050. + if ( pkg->version == NULL ) {
  12051. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12052. + return ENOMEM;
  12053. + }
  12054. + strcpy(pkg->version, raw);
  12055. +
  12056. +#ifdef USE_DEBVERSION
  12057. + hyphen= strrchr(pkg->version,'-');
  12058. +
  12059. + if (hyphen) {
  12060. + *hyphen++= 0;
  12061. + if (strncmp("fam", hyphen, 3) == 0) {
  12062. + pkg->familiar_revision=hyphen+3;
  12063. + hyphen= strrchr(pkg->version,'-');
  12064. + if (hyphen) {
  12065. + *hyphen++= 0;
  12066. + pkg->revision = hyphen;
  12067. + }
  12068. + } else {
  12069. + pkg->revision = hyphen;
  12070. + }
  12071. + }
  12072. +#endif
  12073. +
  12074. +/*
  12075. + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
  12076. + pkg->epoch,
  12077. + pkg->version,
  12078. + pkg->revision,
  12079. + pkg->familiar_revision);
  12080. +*/
  12081. +
  12082. + return 0;
  12083. +}
  12084. +
  12085. +
  12086. +/* This code is needed to insert in first position the keyword for the aligning bug */
  12087. +
  12088. +int alterProvidesLine(char *raw, char *temp)
  12089. +{
  12090. +
  12091. +
  12092. + if (!*raw) {
  12093. + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
  12094. + return -EINVAL;
  12095. + }
  12096. +
  12097. + if ( temp == NULL ) {
  12098. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12099. + return -ENOMEM;
  12100. + }
  12101. +
  12102. + if (strncmp(raw, "Provides:", 9) == 0) {
  12103. + raw += 9;
  12104. + }
  12105. + while (*raw && isspace(*raw)) {
  12106. + raw++;
  12107. + }
  12108. +
  12109. + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
  12110. + while (*raw) {
  12111. + strncat( temp, raw++, 1);
  12112. + }
  12113. + return 0;
  12114. +
  12115. +}
  12116. +
  12117. +/* Some random thoughts from Carl:
  12118. +
  12119. + This function could be considerably simplified if we just kept
  12120. + an array of all the generic string-valued field names, and looped
  12121. + through those looking for a match. Also, these fields could perhaps
  12122. + be stored in the package as an array as well, (or, probably better,
  12123. + as an nv_pair_list_t).
  12124. +
  12125. + Fields which require special parsing or storage, (such as Depends:
  12126. + and Status:) could be handled as they are now.
  12127. +*/
  12128. +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
  12129. + to a dependency list. And, since we already have
  12130. + Depends/Pre-Depends and need to add Conflicts, Recommends, and
  12131. + Enhances, perhaps we could generalize all of these and save some
  12132. + code duplication.
  12133. +*/
  12134. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
  12135. +{
  12136. + int reading_conffiles, reading_description;
  12137. + int pkg_false_provides=1;
  12138. + char ** lines;
  12139. + char * provide=NULL;
  12140. +
  12141. + pkg->src = src;
  12142. + pkg->dest = dest;
  12143. +
  12144. + reading_conffiles = reading_description = 0;
  12145. +
  12146. + for (lines = *raw; *lines; lines++) {
  12147. + /* fprintf(stderr, "PARSING %s\n", *lines);*/
  12148. + if(isGenericFieldType((char *)"Package:", *lines))
  12149. + pkg->name = parseGenericFieldType((char *)"Package", *lines);
  12150. + else if(isGenericFieldType((char *)"Architecture:", *lines))
  12151. + pkg->architecture = parseGenericFieldType((char *)"Architecture", *lines);
  12152. + else if(isGenericFieldType((char *)"Filename:", *lines))
  12153. + pkg->filename = parseGenericFieldType((char *)"Filename", *lines);
  12154. + else if(isGenericFieldType((char *)"Section:", *lines))
  12155. + pkg->section = parseGenericFieldType((char *)"Section", *lines);
  12156. + else if(isGenericFieldType((char *)"MD5sum:", *lines))
  12157. + pkg->md5sum = parseGenericFieldType((char *)"MD5sum", *lines);
  12158. + /* The old ipkg wrote out status files with the wrong case for MD5sum,
  12159. + let's parse it either way */
  12160. + else if(isGenericFieldType((char *)"MD5Sum:", *lines))
  12161. + pkg->md5sum = parseGenericFieldType((char *)"MD5Sum", *lines);
  12162. + else if(isGenericFieldType((char *)"Size:", *lines))
  12163. + pkg->size = parseGenericFieldType((char *)"Size", *lines);
  12164. + else if(isGenericFieldType((char *)"Source:", *lines))
  12165. + pkg->source = parseGenericFieldType((char *)"Source", *lines);
  12166. + else if(isGenericFieldType((char *)"Installed-Size:", *lines))
  12167. + pkg->installed_size = parseGenericFieldType((char *)"Installed-Size", *lines);
  12168. + else if(isGenericFieldType((char *)"Installed-Time:", *lines)) {
  12169. + char *time_str = parseGenericFieldType((char *)"Installed-Time", *lines);
  12170. + pkg->installed_time = strtoul(time_str, NULL, 0);
  12171. + } else if(isGenericFieldType((char *)"Priority:", *lines))
  12172. + pkg->priority = parseGenericFieldType((char *)"Priority", *lines);
  12173. + else if(isGenericFieldType((char *)"Essential:", *lines)) {
  12174. + char *essential_value;
  12175. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12176. + if (strcmp(essential_value, "yes") == 0) {
  12177. + pkg->essential = 1;
  12178. + }
  12179. + free(essential_value);
  12180. + }
  12181. + else if(isGenericFieldType((char *)"Status", *lines))
  12182. + parseStatus(pkg, *lines);
  12183. + else if(isGenericFieldType((char *)"Version", *lines))
  12184. + parseVersion(pkg, *lines);
  12185. + else if(isGenericFieldType((char *)"Maintainer", *lines))
  12186. + pkg->maintainer = parseGenericFieldType((char *)"Maintainer", *lines);
  12187. + else if(isGenericFieldType((char *)"Conffiles", *lines)){
  12188. + parseConffiles(pkg, *lines);
  12189. + reading_conffiles = 1;
  12190. + }
  12191. + else if(isGenericFieldType((char *)"Description", *lines)) {
  12192. + pkg->description = parseGenericFieldType((char *)"Description", *lines);
  12193. + reading_conffiles = 0;
  12194. + reading_description = 1;
  12195. + }
  12196. +
  12197. + else if(isGenericFieldType((char *)"Provides", *lines)){
  12198. +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
  12199. + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
  12200. + if ( alterProvidesLine(*lines,provide) ){
  12201. + return EINVAL;
  12202. + }
  12203. + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
  12204. +/* Let's try to hack a bit here.
  12205. + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
  12206. + in alot of other places. We will remove it before writing down the status database */
  12207. + pkg_false_provides=0;
  12208. + free(provide);
  12209. + }
  12210. +
  12211. + else if(isGenericFieldType((char *)"Depends", *lines))
  12212. + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
  12213. + else if(isGenericFieldType((char *)"Pre-Depends", *lines))
  12214. + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
  12215. + else if(isGenericFieldType((char *)"Recommends", *lines))
  12216. + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
  12217. + else if(isGenericFieldType((char *)"Suggests", *lines))
  12218. + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
  12219. + /* Abhaya: support for conflicts */
  12220. + else if(isGenericFieldType((char *)"Conflicts", *lines))
  12221. + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
  12222. + else if(isGenericFieldType((char *)"Replaces", *lines))
  12223. + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
  12224. + else if(line_is_blank(*lines)) {
  12225. + lines++;
  12226. + break;
  12227. + }
  12228. + else if(**lines == ' '){
  12229. + if(reading_description) {
  12230. + /* we already know it's not blank, so the rest of description */
  12231. + pkg->description = realloc(pkg->description,
  12232. + strlen(pkg->description)
  12233. + + 1 + strlen(*lines) + 1);
  12234. + strcat(pkg->description, "\n");
  12235. + strcat(pkg->description, (*lines));
  12236. + }
  12237. + else if(reading_conffiles)
  12238. + parseConffiles(pkg, *lines);
  12239. + }
  12240. + }
  12241. + *raw = lines;
  12242. +/* If the ipk has not a Provides line, we insert our false line */
  12243. + if ( pkg_false_provides==1)
  12244. + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
  12245. +
  12246. + if (pkg->name) {
  12247. + return 0;
  12248. + } else {
  12249. + return EINVAL;
  12250. + }
  12251. +}
  12252. +
  12253. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
  12254. +{
  12255. + char ** lines;
  12256. +
  12257. + for (lines = *raw; *lines; lines++) {
  12258. + if(isGenericFieldType((char *)"Essential:", *lines)) {
  12259. + char *essential_value;
  12260. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12261. + if (strcmp(essential_value, "yes") == 0) {
  12262. + pkg->essential = 1;
  12263. + }
  12264. + free(essential_value);
  12265. + }
  12266. + }
  12267. + *raw = lines;
  12268. +
  12269. + return 0;
  12270. +}
  12271. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_parse.h busybox-1.15.2/archival/libipkg/pkg_parse.h
  12272. --- busybox-1.15.2.orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
  12273. +++ busybox-1.15.2/archival/libipkg/pkg_parse.h 2010-03-14 20:53:41.000000000 +0100
  12274. @@ -0,0 +1,31 @@
  12275. +/* pkg_parse.h - the itsy package management system
  12276. +
  12277. + Steven M. Ayer
  12278. +
  12279. + Copyright (C) 2002 Compaq Computer Corporation
  12280. +
  12281. + This program is free software; you can redistribute it and/or
  12282. + modify it under the terms of the GNU General Public License as
  12283. + published by the Free Software Foundation; either version 2, or (at
  12284. + your option) any later version.
  12285. +
  12286. + This program is distributed in the hope that it will be useful, but
  12287. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12288. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12289. + General Public License for more details.
  12290. +*/
  12291. +
  12292. +#ifndef PKG_PARSE_H
  12293. +#define PKG_PARSE_H
  12294. +
  12295. +int isGenericFieldType(char * type, char * line);
  12296. +char * parseGenericFieldType(char * type, char * raw);
  12297. +void parseStatus(pkg_t *pkg, char * raw);
  12298. +int parseVersion(pkg_t *pkg, char *raw);
  12299. +char ** parseDependsString(char * raw, int * depends_count);
  12300. +int parseVersion(pkg_t *pkg, char *raw);
  12301. +void parseConffiles(pkg_t * pkg, char * raw);
  12302. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
  12303. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
  12304. +
  12305. +#endif
  12306. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_src.c busybox-1.15.2/archival/libipkg/pkg_src.c
  12307. --- busybox-1.15.2.orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
  12308. +++ busybox-1.15.2/archival/libipkg/pkg_src.c 2010-03-14 20:53:41.000000000 +0100
  12309. @@ -0,0 +1,43 @@
  12310. +/* pkg_src.c - the itsy package management system
  12311. +
  12312. + Carl D. Worth
  12313. +
  12314. + Copyright (C) 2001 University of Southern California
  12315. +
  12316. + This program is free software; you can redistribute it and/or
  12317. + modify it under the terms of the GNU General Public License as
  12318. + published by the Free Software Foundation; either version 2, or (at
  12319. + your option) any later version.
  12320. +
  12321. + This program is distributed in the hope that it will be useful, but
  12322. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12323. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12324. + General Public License for more details.
  12325. +*/
  12326. +
  12327. +#include "ipkg.h"
  12328. +
  12329. +#include "pkg_src.h"
  12330. +#include "str_util.h"
  12331. +
  12332. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
  12333. +{
  12334. + src->gzip = gzip;
  12335. + src->name = str_dup_safe (name);
  12336. + src->value = str_dup_safe (base_url);
  12337. + if (extra_data)
  12338. + src->extra_data = str_dup_safe (extra_data);
  12339. + else
  12340. + src->extra_data = NULL;
  12341. + return 0;
  12342. +}
  12343. +
  12344. +void pkg_src_deinit(pkg_src_t *src)
  12345. +{
  12346. + free (src->name);
  12347. + free (src->value);
  12348. + if (src->extra_data)
  12349. + free (src->extra_data);
  12350. +}
  12351. +
  12352. +
  12353. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_src.h busybox-1.15.2/archival/libipkg/pkg_src.h
  12354. --- busybox-1.15.2.orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
  12355. +++ busybox-1.15.2/archival/libipkg/pkg_src.h 2010-03-14 20:53:41.000000000 +0100
  12356. @@ -0,0 +1,34 @@
  12357. +/* pkg_src.h - the itsy package management system
  12358. +
  12359. + Carl D. Worth
  12360. +
  12361. + Copyright (C) 2001 University of Southern California
  12362. +
  12363. + This program is free software; you can redistribute it and/or
  12364. + modify it under the terms of the GNU General Public License as
  12365. + published by the Free Software Foundation; either version 2, or (at
  12366. + your option) any later version.
  12367. +
  12368. + This program is distributed in the hope that it will be useful, but
  12369. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12370. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12371. + General Public License for more details.
  12372. +*/
  12373. +
  12374. +#ifndef PKG_SRC_H
  12375. +#define PKG_SRC_H
  12376. +
  12377. +#include "nv_pair.h"
  12378. +
  12379. +typedef struct
  12380. +{
  12381. + char *name;
  12382. + char *value;
  12383. + char *extra_data;
  12384. + int gzip;
  12385. +} pkg_src_t;
  12386. +
  12387. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
  12388. +void pkg_src_deinit(pkg_src_t *src);
  12389. +
  12390. +#endif
  12391. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_src_list.c busybox-1.15.2/archival/libipkg/pkg_src_list.c
  12392. --- busybox-1.15.2.orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
  12393. +++ busybox-1.15.2/archival/libipkg/pkg_src_list.c 2010-03-14 20:53:41.000000000 +0100
  12394. @@ -0,0 +1,75 @@
  12395. +/* pkg_src_list.c - the itsy package management system
  12396. +
  12397. + Carl D. Worth
  12398. +
  12399. + Copyright (C) 2001 University of Southern California
  12400. +
  12401. + This program is free software; you can redistribute it and/or
  12402. + modify it under the terms of the GNU General Public License as
  12403. + published by the Free Software Foundation; either version 2, or (at
  12404. + your option) any later version.
  12405. +
  12406. + This program is distributed in the hope that it will be useful, but
  12407. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12408. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12409. + General Public License for more details.
  12410. +*/
  12411. +
  12412. +#include "ipkg.h"
  12413. +
  12414. +#include "pkg_src_list.h"
  12415. +#include "void_list.h"
  12416. +
  12417. +int pkg_src_list_init(pkg_src_list_t *list)
  12418. +{
  12419. + return void_list_init((void_list_t *) list);
  12420. +}
  12421. +
  12422. +void pkg_src_list_deinit(pkg_src_list_t *list)
  12423. +{
  12424. + pkg_src_list_elt_t *iter;
  12425. + pkg_src_t *pkg_src;
  12426. +
  12427. + for (iter = list->head; iter; iter = iter->next) {
  12428. + pkg_src = iter->data;
  12429. + pkg_src_deinit(pkg_src);
  12430. +
  12431. + /* malloced in pkg_src_list_append */
  12432. + free(pkg_src);
  12433. + iter->data = NULL;
  12434. + }
  12435. + void_list_deinit((void_list_t *) list);
  12436. +}
  12437. +
  12438. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
  12439. + const char *name, const char *base_url, const char *extra_data,
  12440. + int gzip)
  12441. +{
  12442. + int err;
  12443. +
  12444. + /* freed in pkg_src_list_deinit */
  12445. + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
  12446. +
  12447. + if (pkg_src == NULL) {
  12448. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12449. + return NULL;
  12450. + }
  12451. + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
  12452. +
  12453. + err = void_list_append((void_list_t *) list, pkg_src);
  12454. + if (err) {
  12455. + return NULL;
  12456. + }
  12457. +
  12458. + return pkg_src;
  12459. +}
  12460. +
  12461. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
  12462. +{
  12463. + return void_list_push((void_list_t *) list, data);
  12464. +}
  12465. +
  12466. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
  12467. +{
  12468. + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
  12469. +}
  12470. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_src_list.h busybox-1.15.2/archival/libipkg/pkg_src_list.h
  12471. --- busybox-1.15.2.orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
  12472. +++ busybox-1.15.2/archival/libipkg/pkg_src_list.h 2010-03-14 20:53:41.000000000 +0100
  12473. @@ -0,0 +1,57 @@
  12474. +/* pkg_src_list.h - the itsy package management system
  12475. +
  12476. + Carl D. Worth
  12477. +
  12478. + Copyright (C) 2001 University of Southern California
  12479. +
  12480. + This program is free software; you can redistribute it and/or
  12481. + modify it under the terms of the GNU General Public License as
  12482. + published by the Free Software Foundation; either version 2, or (at
  12483. + your option) any later version.
  12484. +
  12485. + This program is distributed in the hope that it will be useful, but
  12486. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12487. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12488. + General Public License for more details.
  12489. +*/
  12490. +
  12491. +#ifndef PKG_SRC_LIST_H
  12492. +#define PKG_SRC_LIST_H
  12493. +
  12494. +#include "pkg_src.h"
  12495. +
  12496. +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
  12497. +struct pkg_src_list_elt
  12498. +{
  12499. + pkg_src_list_elt_t *next;
  12500. + pkg_src_t *data;
  12501. +};
  12502. +
  12503. +typedef struct pkg_src_list pkg_src_list_t;
  12504. +struct pkg_src_list
  12505. +{
  12506. + pkg_src_list_elt_t pre_head;
  12507. + pkg_src_list_elt_t *head;
  12508. + pkg_src_list_elt_t *tail;
  12509. +};
  12510. +
  12511. +static inline int pkg_src_list_empty(pkg_src_list_t *list)
  12512. +{
  12513. + if (list->head == NULL)
  12514. + return 1;
  12515. + else
  12516. + return 0;
  12517. +}
  12518. +
  12519. +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
  12520. +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
  12521. +
  12522. +int pkg_src_list_init(pkg_src_list_t *list);
  12523. +void pkg_src_list_deinit(pkg_src_list_t *list);
  12524. +
  12525. +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);
  12526. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
  12527. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
  12528. +
  12529. +#endif
  12530. +
  12531. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_vec.c busybox-1.15.2/archival/libipkg/pkg_vec.c
  12532. --- busybox-1.15.2.orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
  12533. +++ busybox-1.15.2/archival/libipkg/pkg_vec.c 2010-03-14 20:53:41.000000000 +0100
  12534. @@ -0,0 +1,231 @@
  12535. +/* pkg_vec.c - the itsy package management system
  12536. +
  12537. + Steven M. Ayer
  12538. +
  12539. + Copyright (C) 2002 Compaq Computer Corporation
  12540. +
  12541. + This program is free software; you can redistribute it and/or
  12542. + modify it under the terms of the GNU General Public License as
  12543. + published by the Free Software Foundation; either version 2, or (at
  12544. + your option) any later version.
  12545. +
  12546. + This program is distributed in the hope that it will be useful, but
  12547. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12548. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12549. + General Public License for more details.
  12550. +*/
  12551. +
  12552. +#include <stdlib.h>
  12553. +#include <fnmatch.h>
  12554. +#include "libbb.h"
  12555. +#include "xregex.h"
  12556. +#include "ipkg.h"
  12557. +#include "pkg.h"
  12558. +
  12559. +pkg_vec_t * pkg_vec_alloc(void)
  12560. +{
  12561. + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
  12562. + if (!vec) {
  12563. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12564. + return NULL;
  12565. + }
  12566. + vec->pkgs = NULL;
  12567. + vec->len = 0;
  12568. +
  12569. + return vec;
  12570. +}
  12571. +
  12572. +void pkg_vec_free(pkg_vec_t *vec)
  12573. +{
  12574. + free(vec->pkgs);
  12575. + free(vec);
  12576. +}
  12577. +
  12578. +/*
  12579. + * assumption: all names in a vector are identical
  12580. + * assumption: all version strings are trimmed,
  12581. + * so identical versions have identical version strings,
  12582. + * implying identical packages; let's marry these
  12583. + */
  12584. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  12585. +{
  12586. + int i;
  12587. + int found = 0;
  12588. +
  12589. + /* look for a duplicate pkg by name, version, and architecture */
  12590. + for (i = 0; i < vec->len; i++){
  12591. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
  12592. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
  12593. + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
  12594. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12595. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12596. + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
  12597. + found = 1;
  12598. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
  12599. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12600. + break;
  12601. + }
  12602. + }
  12603. +
  12604. + /* we didn't find one, add it */
  12605. + if (!found){
  12606. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
  12607. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12608. +
  12609. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12610. + vec->pkgs[vec->len] = pkg;
  12611. + vec->len++;
  12612. + return pkg;
  12613. + }
  12614. + /* update the one that we have */
  12615. + else {
  12616. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
  12617. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12618. + if (set_status) {
  12619. + /* this is from the status file, so need to merge with existing database */
  12620. + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
  12621. + pkg_merge(vec->pkgs[i], pkg, set_status);
  12622. + /* XXX: CLEANUP: It's not so polite to free something here
  12623. + that was passed in from above. */
  12624. + pkg_deinit(pkg);
  12625. + free(pkg);
  12626. + } else {
  12627. + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
  12628. + /* just overwrite the old one */
  12629. + pkg_deinit(vec->pkgs[i]);
  12630. + free(vec->pkgs[i]);
  12631. + vec->pkgs[i] = pkg;
  12632. + }
  12633. + return vec->pkgs[i];
  12634. + }
  12635. +}
  12636. +
  12637. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
  12638. +{
  12639. + int i;
  12640. + int found = 0;
  12641. +
  12642. + /* look for a duplicate pkg by name, version, and architecture */
  12643. + for (i = 0; i < vec->len; i++)
  12644. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12645. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12646. + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
  12647. + found = 1;
  12648. + break;
  12649. + }
  12650. +
  12651. + /* we didn't find one, add it */
  12652. + if(!found){
  12653. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12654. + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
  12655. + vec->len++;
  12656. + }
  12657. +}
  12658. +
  12659. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
  12660. +{
  12661. + int i;
  12662. + for (i = 0; i < vec->len; i++)
  12663. + if (vec->pkgs[i] == apkg)
  12664. + return 1;
  12665. + return 0;
  12666. +}
  12667. +
  12668. +typedef int (*compare_fcn_t)(const void *, const void *);
  12669. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
  12670. +{
  12671. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12672. +}
  12673. +
  12674. +int pkg_vec_clear_marks(pkg_vec_t *vec)
  12675. +{
  12676. + int npkgs = vec->len;
  12677. + int i;
  12678. + for (i = 0; i < npkgs; i++) {
  12679. + pkg_t *pkg = vec->pkgs[i];
  12680. + pkg->state_flag &= ~SF_MARKED;
  12681. + }
  12682. + return 0;
  12683. +}
  12684. +
  12685. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
  12686. +{
  12687. + int matching_count = 0;
  12688. + pkg_t **pkgs = vec->pkgs;
  12689. + int npkgs = vec->len;
  12690. + int i;
  12691. + for (i = 0; i < npkgs; i++) {
  12692. + pkg_t *pkg = pkgs[i];
  12693. + if (fnmatch(pattern, pkg->name, 0)==0) {
  12694. + pkg->state_flag |= SF_MARKED;
  12695. + matching_count++;
  12696. + }
  12697. + }
  12698. + return matching_count;
  12699. +}
  12700. +
  12701. +
  12702. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
  12703. +{
  12704. + abstract_pkg_vec_t * vec ;
  12705. + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
  12706. + if (!vec) {
  12707. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12708. + return NULL;
  12709. + }
  12710. + vec->pkgs = NULL;
  12711. + vec->len = 0;
  12712. +
  12713. + return vec;
  12714. +}
  12715. +
  12716. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
  12717. +{
  12718. + free(vec->pkgs);
  12719. + free(vec);
  12720. +}
  12721. +
  12722. +/*
  12723. + * assumption: all names in a vector are unique
  12724. + */
  12725. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
  12726. +{
  12727. + int i;
  12728. +
  12729. + /* look for a duplicate pkg by name */
  12730. + for(i = 0; i < vec->len; i++)
  12731. + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12732. + break;
  12733. +
  12734. + /* we didn't find one, add it */
  12735. + if(i == vec->len){
  12736. + vec->pkgs =
  12737. + (abstract_pkg_t **)
  12738. + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
  12739. + vec->pkgs[vec->len] = pkg;
  12740. + vec->len++;
  12741. + }
  12742. +}
  12743. +
  12744. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
  12745. +{
  12746. + if (vec->len > i)
  12747. + return vec->pkgs[i];
  12748. + else
  12749. + return NULL;
  12750. +}
  12751. +
  12752. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
  12753. +{
  12754. + int i;
  12755. + for (i = 0; i < vec->len; i++)
  12756. + if (vec->pkgs[i] == apkg)
  12757. + return 1;
  12758. + return 0;
  12759. +}
  12760. +
  12761. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
  12762. +{
  12763. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12764. +}
  12765. +
  12766. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_vec.h busybox-1.15.2/archival/libipkg/pkg_vec.h
  12767. --- busybox-1.15.2.orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
  12768. +++ busybox-1.15.2/archival/libipkg/pkg_vec.h 2010-03-14 20:53:41.000000000 +0100
  12769. @@ -0,0 +1,62 @@
  12770. +/* pkg_vec.h - the itsy package management system
  12771. +
  12772. + Steven M. Ayer
  12773. +
  12774. + Copyright (C) 2002 Compaq Computer Corporation
  12775. +
  12776. + This program is free software; you can redistribute it and/or
  12777. + modify it under the terms of the GNU General Public License as
  12778. + published by the Free Software Foundation; either version 2, or (at
  12779. + your option) any later version.
  12780. +
  12781. + This program is distributed in the hope that it will be useful, but
  12782. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12783. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12784. + General Public License for more details.
  12785. +*/
  12786. +
  12787. +#ifndef PKG_VEC_H
  12788. +#define PKG_VEC_H
  12789. +
  12790. +typedef struct pkg pkg_t;
  12791. +typedef struct abstract_pkg abstract_pkg_t;
  12792. +
  12793. +struct pkg_vec
  12794. +{
  12795. + pkg_t **pkgs;
  12796. + int len;
  12797. +};
  12798. +typedef struct pkg_vec pkg_vec_t;
  12799. +
  12800. +struct abstract_pkg_vec
  12801. +{
  12802. + abstract_pkg_t **pkgs;
  12803. + int len;
  12804. +};
  12805. +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
  12806. +
  12807. +
  12808. +pkg_vec_t * pkg_vec_alloc(void);
  12809. +void pkg_vec_free(pkg_vec_t *vec);
  12810. +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
  12811. +
  12812. +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
  12813. +/* pkg_vec_insert_merge: might munge pkg.
  12814. +* returns the pkg that is in the pkg graph */
  12815. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
  12816. +/* this one never munges pkg */
  12817. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
  12818. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
  12819. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
  12820. +
  12821. +int pkg_vec_clear_marks(pkg_vec_t *vec);
  12822. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
  12823. +
  12824. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
  12825. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
  12826. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
  12827. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
  12828. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
  12829. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
  12830. +#endif
  12831. +
  12832. diff -Nur busybox-1.15.2.orig/archival/libipkg/sprintf_alloc.h busybox-1.15.2/archival/libipkg/sprintf_alloc.h
  12833. --- busybox-1.15.2.orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
  12834. +++ busybox-1.15.2/archival/libipkg/sprintf_alloc.h 2010-03-14 20:53:41.000000000 +0100
  12835. @@ -0,0 +1,25 @@
  12836. +/* sprintf_alloca.c -- like sprintf with memory allocation
  12837. +
  12838. + Carl D. Worth
  12839. +
  12840. + Copyright (C) 2001 University of Southern California
  12841. +
  12842. + This program is free software; you can redistribute it and/or modify
  12843. + it under the terms of the GNU General Public License as published by
  12844. + the Free Software Foundation; either version 2, or (at your option)
  12845. + any later version.
  12846. +
  12847. + This program is distributed in the hope that it will be useful,
  12848. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  12849. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12850. + GNU General Public License for more details.
  12851. +*/
  12852. +
  12853. +#ifndef SPRINTF_ALLOC_H
  12854. +#define SPRINTF_ALLOC_H
  12855. +
  12856. +#include "libbb.h"
  12857. +
  12858. +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
  12859. +
  12860. +#endif
  12861. diff -Nur busybox-1.15.2.orig/archival/libipkg/str_list.c busybox-1.15.2/archival/libipkg/str_list.c
  12862. --- busybox-1.15.2.orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
  12863. +++ busybox-1.15.2/archival/libipkg/str_list.c 2010-03-14 20:53:41.000000000 +0100
  12864. @@ -0,0 +1,76 @@
  12865. +/* str_list.c - the itsy package management system
  12866. +
  12867. + Carl D. Worth
  12868. +
  12869. + Copyright (C) 2001 University of Southern California
  12870. +
  12871. + This program is free software; you can redistribute it and/or
  12872. + modify it under the terms of the GNU General Public License as
  12873. + published by the Free Software Foundation; either version 2, or (at
  12874. + your option) any later version.
  12875. +
  12876. + This program is distributed in the hope that it will be useful, but
  12877. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12878. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12879. + General Public License for more details.
  12880. +*/
  12881. +
  12882. +#include "ipkg.h"
  12883. +
  12884. +#include "str_list.h"
  12885. +
  12886. +int str_list_elt_init(str_list_elt_t *elt, char *data)
  12887. +{
  12888. + return void_list_elt_init((void_list_elt_t *) elt, data);
  12889. +}
  12890. +
  12891. +void str_list_elt_deinit(str_list_elt_t *elt)
  12892. +{
  12893. + void_list_elt_deinit((void_list_elt_t *) elt);
  12894. +}
  12895. +
  12896. +str_list_t *str_list_alloc(void)
  12897. +{
  12898. + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
  12899. + if (list)
  12900. + str_list_init(list);
  12901. + return list;
  12902. +}
  12903. +
  12904. +int str_list_init(str_list_t *list)
  12905. +{
  12906. + return void_list_init((void_list_t *) list);
  12907. +}
  12908. +
  12909. +void str_list_deinit(str_list_t *list)
  12910. +{
  12911. + void_list_deinit((void_list_t *) list);
  12912. +}
  12913. +
  12914. +int str_list_append(str_list_t *list, char *data)
  12915. +{
  12916. + return void_list_append((void_list_t *) list, data);
  12917. +}
  12918. +
  12919. +int str_list_push(str_list_t *list, char *data)
  12920. +{
  12921. + return void_list_push((void_list_t *) list, data);
  12922. +}
  12923. +
  12924. +str_list_elt_t *str_list_pop(str_list_t *list)
  12925. +{
  12926. + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
  12927. +}
  12928. +
  12929. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
  12930. +{
  12931. + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
  12932. + (void_list_elt_t **) iter);
  12933. +}
  12934. +
  12935. +char *str_list_remove_elt(str_list_t *list, const char *target_str)
  12936. +{
  12937. + return (char *)void_list_remove_elt((void_list_t *) list,
  12938. + (void *)target_str,
  12939. + (void_list_cmp_t)strcmp);
  12940. +}
  12941. diff -Nur busybox-1.15.2.orig/archival/libipkg/str_list.h busybox-1.15.2/archival/libipkg/str_list.h
  12942. --- busybox-1.15.2.orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
  12943. +++ busybox-1.15.2/archival/libipkg/str_list.h 2010-03-14 20:53:41.000000000 +0100
  12944. @@ -0,0 +1,51 @@
  12945. +/* str_list.h - the itsy package management system
  12946. +
  12947. + Carl D. Worth
  12948. +
  12949. + Copyright (C) 2001 University of Southern California
  12950. +
  12951. + This program is free software; you can redistribute it and/or
  12952. + modify it under the terms of the GNU General Public License as
  12953. + published by the Free Software Foundation; either version 2, or (at
  12954. + your option) any later version.
  12955. +
  12956. + This program is distributed in the hope that it will be useful, but
  12957. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12958. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12959. + General Public License for more details.
  12960. +*/
  12961. +
  12962. +#ifndef STR_LIST_H
  12963. +#define STR_LIST_H
  12964. +
  12965. +#include "void_list.h"
  12966. +
  12967. +typedef struct str_list_elt str_list_elt_t;
  12968. +struct str_list_elt
  12969. +{
  12970. + str_list_elt_t *next;
  12971. + char *data;
  12972. +};
  12973. +
  12974. +typedef struct xstr_list str_list_t;
  12975. +struct xstr_list
  12976. +{
  12977. + str_list_elt_t pre_head;
  12978. + str_list_elt_t *head;
  12979. + str_list_elt_t *tail;
  12980. +};
  12981. +
  12982. +int str_list_elt_init(str_list_elt_t *elt, char *data);
  12983. +void str_list_elt_deinit(str_list_elt_t *elt);
  12984. +
  12985. +str_list_t *str_list_alloc(void);
  12986. +int str_list_init(str_list_t *list);
  12987. +void str_list_deinit(str_list_t *list);
  12988. +
  12989. +int str_list_append(str_list_t *list, char *data);
  12990. +int str_list_push(str_list_t *list, char *data);
  12991. +str_list_elt_t *str_list_pop(str_list_t *list);
  12992. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
  12993. +char *str_list_remove_elt(str_list_t *list, const char *target_str);
  12994. +
  12995. +#endif
  12996. diff -Nur busybox-1.15.2.orig/archival/libipkg/str_util.c busybox-1.15.2/archival/libipkg/str_util.c
  12997. --- busybox-1.15.2.orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
  12998. +++ busybox-1.15.2/archival/libipkg/str_util.c 2010-03-14 20:53:41.000000000 +0100
  12999. @@ -0,0 +1,69 @@
  13000. +/* str_utils.c - the itsy package management system
  13001. +
  13002. + Carl D. Worth
  13003. +
  13004. + Copyright (C) 2001 University of Southern California
  13005. +
  13006. + This program is free software; you can redistribute it and/or
  13007. + modify it under the terms of the GNU General Public License as
  13008. + published by the Free Software Foundation; either version 2, or (at
  13009. + your option) any later version.
  13010. +
  13011. + This program is distributed in the hope that it will be useful, but
  13012. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13013. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13014. + General Public License for more details.
  13015. +*/
  13016. +
  13017. +#include "ipkg.h"
  13018. +
  13019. +int str_starts_with(const char *str, const char *prefix);
  13020. +int str_ends_with(const char *str, const char *suffix);
  13021. +int str_chomp(char *str);
  13022. +int str_toupper(char *str);
  13023. +char *str_dup_safe(const char *str);
  13024. +
  13025. +int str_starts_with(const char *str, const char *prefix)
  13026. +{
  13027. + return (strncmp(str, prefix, strlen(prefix)) == 0);
  13028. +}
  13029. +
  13030. +int str_ends_with(const char *str, const char *suffix)
  13031. +{
  13032. + int suffix_len;
  13033. + int str_len;
  13034. +
  13035. + str_len = strlen(str);
  13036. + suffix_len = strlen(suffix);
  13037. +
  13038. + if (str_len < suffix_len) {
  13039. + return 0;
  13040. + }
  13041. +
  13042. + return (strcmp(str + str_len - suffix_len, suffix) == 0);
  13043. +}
  13044. +
  13045. +int str_chomp(char *str)
  13046. +{
  13047. + if (str[strlen(str) - 1] == '\n') {
  13048. + str[strlen(str) - 1] = '\0';
  13049. + return 1;
  13050. + }
  13051. + return 0;
  13052. +}
  13053. +
  13054. +int str_toupper(char *str)
  13055. +{
  13056. + while (*str) {
  13057. + *str = toupper(*str);
  13058. + str++;
  13059. + }
  13060. +
  13061. + return 0;
  13062. +}
  13063. +
  13064. +char *str_dup_safe(const char *str)
  13065. +{
  13066. + return str ? strdup(str) : NULL;
  13067. +}
  13068. +
  13069. diff -Nur busybox-1.15.2.orig/archival/libipkg/str_util.h busybox-1.15.2/archival/libipkg/str_util.h
  13070. --- busybox-1.15.2.orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
  13071. +++ busybox-1.15.2/archival/libipkg/str_util.h 2010-03-14 20:53:41.000000000 +0100
  13072. @@ -0,0 +1,27 @@
  13073. +/* str_utils.h - the itsy package management system
  13074. +
  13075. + Carl D. Worth
  13076. +
  13077. + Copyright (C) 2001 University of Southern California
  13078. +
  13079. + This program is free software; you can redistribute it and/or
  13080. + modify it under the terms of the GNU General Public License as
  13081. + published by the Free Software Foundation; either version 2, or (at
  13082. + your option) any later version.
  13083. +
  13084. + This program is distributed in the hope that it will be useful, but
  13085. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13086. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13087. + General Public License for more details.
  13088. +*/
  13089. +
  13090. +#ifndef STR_UTILS_H
  13091. +#define STR_UTILS_H
  13092. +
  13093. +int str_starts_with(const char *str, const char *prefix);
  13094. +int str_ends_with(const char *str, const char *suffix);
  13095. +int str_chomp(char *str);
  13096. +int str_toupper(char *str);
  13097. +char *str_dup_safe(const char *str);
  13098. +
  13099. +#endif
  13100. diff -Nur busybox-1.15.2.orig/archival/libipkg/user.c busybox-1.15.2/archival/libipkg/user.c
  13101. --- busybox-1.15.2.orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
  13102. +++ busybox-1.15.2/archival/libipkg/user.c 2010-03-14 20:59:41.000000000 +0100
  13103. @@ -0,0 +1,49 @@
  13104. +/* user.c - the itsy package management system
  13105. +
  13106. + Jamey Hicks
  13107. +
  13108. + Copyright (C) 2002 Hewlett Packard Company
  13109. + Copyright (C) 2001 University of Southern California
  13110. +
  13111. + This program is free software; you can redistribute it and/or
  13112. + modify it under the terms of the GNU General Public License as
  13113. + published by the Free Software Foundation; either version 2, or (at
  13114. + your option) any later version.
  13115. +
  13116. + This program is distributed in the hope that it will be useful, but
  13117. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13118. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13119. + General Public License for more details.
  13120. +*/
  13121. +
  13122. +#include <stdio.h>
  13123. +#include <stdarg.h>
  13124. +#include "libbb.h"
  13125. +#include "file_util.h"
  13126. +#include "str_util.h"
  13127. +#include "libipkg.h"
  13128. +
  13129. +char *get_user_response(const char *format, ...);
  13130. +static char *question = NULL;
  13131. +static int question_len = 255;
  13132. +
  13133. +char *get_user_response(const char *format, ...)
  13134. +{
  13135. + int len = question_len;
  13136. + va_list ap;
  13137. + char *response;
  13138. + va_start(ap, format);
  13139. +
  13140. + do {
  13141. + if (question == NULL || len > question_len) {
  13142. + question = realloc(question, len + 1);
  13143. + question_len = len;
  13144. + }
  13145. + len = vsnprintf(question,question_len,format,ap);
  13146. + } while (len > question_len);
  13147. + response = strdup(ipkg_cb_response(question));
  13148. + str_chomp(response);
  13149. + str_tolower(response);
  13150. +
  13151. + return response;
  13152. +}
  13153. diff -Nur busybox-1.15.2.orig/archival/libipkg/user.h busybox-1.15.2/archival/libipkg/user.h
  13154. --- busybox-1.15.2.orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
  13155. +++ busybox-1.15.2/archival/libipkg/user.h 2010-03-14 20:53:41.000000000 +0100
  13156. @@ -0,0 +1,23 @@
  13157. +/* user.c - the itsy package management system
  13158. +
  13159. + Jamey Hicks
  13160. +
  13161. + Copyright (C) 2002 Hewlett Packard Company
  13162. + Copyright (C) 2001 University of Southern California
  13163. +
  13164. + This program is free software; you can redistribute it and/or
  13165. + modify it under the terms of the GNU General Public License as
  13166. + published by the Free Software Foundation; either version 2, or (at
  13167. + your option) any later version.
  13168. +
  13169. + This program is distributed in the hope that it will be useful, but
  13170. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13171. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13172. + General Public License for more details.
  13173. +*/
  13174. +
  13175. +#include <stdio.h>
  13176. +#include <stdarg.h>
  13177. +
  13178. +char *get_user_response(const char *format, ...);
  13179. +
  13180. diff -Nur busybox-1.15.2.orig/archival/libipkg/void_list.c busybox-1.15.2/archival/libipkg/void_list.c
  13181. --- busybox-1.15.2.orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
  13182. +++ busybox-1.15.2/archival/libipkg/void_list.c 2010-03-14 20:53:41.000000000 +0100
  13183. @@ -0,0 +1,194 @@
  13184. +/* void_list.c - the itsy package management system
  13185. +
  13186. + Carl D. Worth
  13187. +
  13188. + Copyright (C) 2001 University of Southern California
  13189. +
  13190. + This program is free software; you can redistribute it and/or
  13191. + modify it under the terms of the GNU General Public License as
  13192. + published by the Free Software Foundation; either version 2, or (at
  13193. + your option) any later version.
  13194. +
  13195. + This program is distributed in the hope that it will be useful, but
  13196. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13197. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13198. + General Public License for more details.
  13199. +*/
  13200. +
  13201. +#include "ipkg.h"
  13202. +#include <errno.h>
  13203. +
  13204. +#include "void_list.h"
  13205. +
  13206. +int void_list_elt_init(void_list_elt_t *elt, void *data)
  13207. +{
  13208. + elt->next = NULL;
  13209. + elt->data = data;
  13210. +
  13211. + return 0;
  13212. +}
  13213. +
  13214. +void void_list_elt_deinit(void_list_elt_t *elt)
  13215. +{
  13216. + void_list_elt_init(elt, NULL);
  13217. +}
  13218. +
  13219. +int void_list_init(void_list_t *list)
  13220. +{
  13221. + void_list_elt_init(&list->pre_head, NULL);
  13222. + list->head = NULL;
  13223. + list->pre_head.next = list->head;
  13224. + list->tail = NULL;
  13225. +
  13226. + return 0;
  13227. +}
  13228. +
  13229. +void void_list_deinit(void_list_t *list)
  13230. +{
  13231. + void_list_elt_t *elt;
  13232. +
  13233. + while (list->head) {
  13234. + elt = void_list_pop(list);
  13235. + void_list_elt_deinit(elt);
  13236. + /* malloced in void_list_append */
  13237. + free(elt);
  13238. + }
  13239. +}
  13240. +
  13241. +int void_list_append(void_list_t *list, void *data)
  13242. +{
  13243. + void_list_elt_t *elt;
  13244. +
  13245. + /* freed in void_list_deinit */
  13246. + elt = malloc(sizeof(void_list_elt_t));
  13247. + if (elt == NULL) {
  13248. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13249. + return ENOMEM;
  13250. + }
  13251. +
  13252. + void_list_elt_init(elt, data);
  13253. +
  13254. + if (list->tail) {
  13255. + list->tail->next = elt;
  13256. + list->tail = elt;
  13257. + } else {
  13258. + list->head = elt;
  13259. + list->pre_head.next = list->head;
  13260. + list->tail = elt;
  13261. + }
  13262. +
  13263. + return 0;
  13264. +}
  13265. +
  13266. +int void_list_push(void_list_t *list, void *data)
  13267. +{
  13268. + void_list_elt_t *elt;
  13269. +
  13270. + elt = malloc(sizeof(void_list_elt_t));
  13271. + if (elt == NULL) {
  13272. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13273. + return ENOMEM;
  13274. + }
  13275. +
  13276. + void_list_elt_init(elt, data);
  13277. +
  13278. + elt->next = list->head;
  13279. + list->head->next = elt;
  13280. + if (list->tail == NULL) {
  13281. + list->tail = list->head;
  13282. + }
  13283. +
  13284. + return 0;
  13285. +}
  13286. +
  13287. +void_list_elt_t *void_list_pop(void_list_t *list)
  13288. +{
  13289. + void_list_elt_t *elt;
  13290. +
  13291. + elt = list->head;
  13292. +
  13293. + if (list->head) {
  13294. + list->head = list->head->next;
  13295. + list->pre_head.next = list->head;
  13296. + if (list->head == NULL) {
  13297. + list->tail = NULL;
  13298. + }
  13299. + }
  13300. +
  13301. + return elt;
  13302. +}
  13303. +
  13304. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
  13305. +{
  13306. + void_list_elt_t *prior;
  13307. + void_list_elt_t *old_elt;
  13308. + void *old_data;
  13309. +
  13310. + old_elt = *iter;
  13311. + old_data = old_elt->data;
  13312. +
  13313. + if (old_elt == list->head) {
  13314. + prior = &list->pre_head;
  13315. + void_list_pop(list);
  13316. + } else {
  13317. + for (prior = list->head; prior; prior = prior->next) {
  13318. + if (prior->next == old_elt) {
  13319. + break;
  13320. + }
  13321. + }
  13322. + if (prior == NULL || prior->next != old_elt) {
  13323. + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
  13324. + return NULL;
  13325. + }
  13326. + prior->next = old_elt->next;
  13327. +
  13328. + if (old_elt == list->tail) {
  13329. + list->tail = prior;
  13330. + }
  13331. + }
  13332. +
  13333. + void_list_elt_deinit(old_elt);
  13334. + *iter = prior;
  13335. +
  13336. + return old_data;
  13337. +}
  13338. +
  13339. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13340. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
  13341. +{
  13342. + void_list_elt_t *prior;
  13343. + void_list_elt_t *old_elt = NULL;
  13344. + void *old_data = NULL;
  13345. +
  13346. + /* first element */
  13347. + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
  13348. + old_elt = list->head;
  13349. + old_data = list->head->data;
  13350. + void_list_pop(list);
  13351. + } else {
  13352. + int found = 0;
  13353. + for (prior = list->head; prior && prior->next; prior = prior->next) {
  13354. + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
  13355. + old_elt = prior->next;
  13356. + old_data = old_elt->data;
  13357. + found = 1;
  13358. + break;
  13359. + }
  13360. + }
  13361. + if (!found) {
  13362. + return NULL;
  13363. + }
  13364. + prior->next = old_elt->next;
  13365. +
  13366. + if (old_elt == list->tail) {
  13367. + list->tail = prior;
  13368. + }
  13369. + }
  13370. + if (old_elt)
  13371. + void_list_elt_deinit(old_elt);
  13372. +
  13373. + if (old_data)
  13374. + return old_data;
  13375. + else
  13376. + return NULL;
  13377. +}
  13378. diff -Nur busybox-1.15.2.orig/archival/libipkg/void_list.h busybox-1.15.2/archival/libipkg/void_list.h
  13379. --- busybox-1.15.2.orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
  13380. +++ busybox-1.15.2/archival/libipkg/void_list.h 2010-03-14 20:53:41.000000000 +0100
  13381. @@ -0,0 +1,59 @@
  13382. +/* void_list.h - the itsy package management system
  13383. +
  13384. + Carl D. Worth
  13385. +
  13386. + Copyright (C) 2001 University of Southern California
  13387. +
  13388. + This program is free software; you can redistribute it and/or
  13389. + modify it under the terms of the GNU General Public License as
  13390. + published by the Free Software Foundation; either version 2, or (at
  13391. + your option) any later version.
  13392. +
  13393. + This program is distributed in the hope that it will be useful, but
  13394. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13395. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13396. + General Public License for more details.
  13397. +*/
  13398. +
  13399. +#ifndef VOID_LIST_H
  13400. +#define VOID_LIST_H
  13401. +
  13402. +typedef struct void_list_elt void_list_elt_t;
  13403. +struct void_list_elt
  13404. +{
  13405. + void_list_elt_t *next;
  13406. + void *data;
  13407. +};
  13408. +
  13409. +typedef struct void_list void_list_t;
  13410. +struct void_list
  13411. +{
  13412. + void_list_elt_t pre_head;
  13413. + void_list_elt_t *head;
  13414. + void_list_elt_t *tail;
  13415. +};
  13416. +
  13417. +static inline int void_list_empty(void_list_t *list)
  13418. +{
  13419. + if (list->head == NULL)
  13420. + return 1;
  13421. + else
  13422. + return 0;
  13423. +}
  13424. +
  13425. +int void_list_elt_init(void_list_elt_t *elt, void *data);
  13426. +void void_list_elt_deinit(void_list_elt_t *elt);
  13427. +
  13428. +int void_list_init(void_list_t *list);
  13429. +void void_list_deinit(void_list_t *list);
  13430. +
  13431. +int void_list_append(void_list_t *list, void *data);
  13432. +int void_list_push(void_list_t *list, void *data);
  13433. +void_list_elt_t *void_list_pop(void_list_t *list);
  13434. +
  13435. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
  13436. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13437. +typedef int (*void_list_cmp_t)(const void *, const void *);
  13438. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
  13439. +
  13440. +#endif
  13441. diff -Nur busybox-1.15.2.orig/archival/libipkg/xsystem.c busybox-1.15.2/archival/libipkg/xsystem.c
  13442. --- busybox-1.15.2.orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
  13443. +++ busybox-1.15.2/archival/libipkg/xsystem.c 2010-03-14 20:53:41.000000000 +0100
  13444. @@ -0,0 +1,64 @@
  13445. +/* xsystem.c - system(3) with error messages
  13446. +
  13447. + Carl D. Worth
  13448. +
  13449. + Copyright (C) 2001 University of Southern California
  13450. +
  13451. + This program is free software; you can redistribute it and/or
  13452. + modify it under the terms of the GNU General Public License as
  13453. + published by the Free Software Foundation; either version 2, or (at
  13454. + your option) any later version.
  13455. +
  13456. + This program is distributed in the hope that it will be useful, but
  13457. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13458. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13459. + General Public License for more details.
  13460. +*/
  13461. +
  13462. +#include "ipkg.h"
  13463. +#include <sys/wait.h>
  13464. +
  13465. +#include "xsystem.h"
  13466. +
  13467. +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
  13468. + really need the /bin/sh invocation which takes resources and
  13469. + introduces security problems. I should switch all of this to a sort
  13470. + of execl() or execv() interface/implementation.
  13471. +*/
  13472. +
  13473. +/* Like system(3), but with error messages printed if the fork fails
  13474. + or if the child process dies due to an uncaught signal. Also, the
  13475. + return value is a bit simpler:
  13476. +
  13477. + -1 if there was any problem
  13478. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13479. + as defined in <sys/wait.h>.
  13480. +*/
  13481. +int xsystem(const char *cmd)
  13482. +{
  13483. + int err;
  13484. +
  13485. + err = system(cmd);
  13486. +
  13487. + if (err == -1) {
  13488. + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
  13489. + __FUNCTION__, cmd);
  13490. + return -1;
  13491. + }
  13492. +
  13493. + if (WIFSIGNALED(err)) {
  13494. + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
  13495. + __FUNCTION__, WTERMSIG(err), cmd);
  13496. + return -1;
  13497. + }
  13498. +
  13499. + if (WIFEXITED(err)) {
  13500. + /* Normal child exit */
  13501. + return WEXITSTATUS(err);
  13502. + }
  13503. +
  13504. + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
  13505. + __FUNCTION__, err);
  13506. + return -1;
  13507. +}
  13508. +
  13509. diff -Nur busybox-1.15.2.orig/archival/libipkg/xsystem.h busybox-1.15.2/archival/libipkg/xsystem.h
  13510. --- busybox-1.15.2.orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
  13511. +++ busybox-1.15.2/archival/libipkg/xsystem.h 2010-03-14 20:53:41.000000000 +0100
  13512. @@ -0,0 +1,34 @@
  13513. +/* xsystem.h - system(3) with error messages
  13514. +
  13515. + Carl D. Worth
  13516. +
  13517. + Copyright (C) 2001 University of Southern California
  13518. +
  13519. + This program is free software; you can redistribute it and/or
  13520. + modify it under the terms of the GNU General Public License as
  13521. + published by the Free Software Foundation; either version 2, or (at
  13522. + your option) any later version.
  13523. +
  13524. + This program is distributed in the hope that it will be useful, but
  13525. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13526. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13527. + General Public License for more details.
  13528. +*/
  13529. +
  13530. +#ifndef XSYSTEM_H
  13531. +#define XSYSTEM_H
  13532. +
  13533. +#include <stdlib.h>
  13534. +
  13535. +/* Like system(3), but with error messages printed if the fork fails
  13536. + or if the child process dies due to an uncaught signal. Also, the
  13537. + return value is a bit simpler:
  13538. +
  13539. + -1 if there was any problem
  13540. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13541. + as defined in <sys/wait.h>.
  13542. +*/
  13543. +int xsystem(const char *cmd);
  13544. +
  13545. +#endif
  13546. +
  13547. diff -Nur busybox-1.15.2.orig/archival/libunarchive/data_extract_all.c busybox-1.15.2/archival/libunarchive/data_extract_all.c
  13548. --- busybox-1.15.2.orig/archival/libunarchive/data_extract_all.c 2009-10-08 02:59:09.000000000 +0200
  13549. +++ busybox-1.15.2/archival/libunarchive/data_extract_all.c 2010-03-14 20:53:41.000000000 +0100
  13550. @@ -147,3 +147,16 @@
  13551. }
  13552. }
  13553. }
  13554. +
  13555. +extern void FAST_FUNC data_extract_all_prefix(archive_handle_t *archive_handle)
  13556. +{
  13557. + char *name_ptr = archive_handle->file_header->name;
  13558. +
  13559. + name_ptr += strspn(name_ptr, "./");
  13560. + if (name_ptr[0] != '\0') {
  13561. + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
  13562. + strcpy(archive_handle->file_header->name, archive_handle->buffer);
  13563. + strcat(archive_handle->file_header->name, name_ptr);
  13564. + data_extract_all(archive_handle);
  13565. + }
  13566. +}
  13567. diff -Nur busybox-1.15.2.orig/archival/libunarchive/Kbuild busybox-1.15.2/archival/libunarchive/Kbuild
  13568. --- busybox-1.15.2.orig/archival/libunarchive/Kbuild 2009-09-26 15:14:57.000000000 +0200
  13569. +++ busybox-1.15.2/archival/libunarchive/Kbuild 2010-03-14 20:53:41.000000000 +0100
  13570. @@ -41,6 +41,7 @@
  13571. lib-$(CONFIG_DPKG) += $(DPKG_FILES)
  13572. lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
  13573. lib-$(CONFIG_GUNZIP) += decompress_unzip.o
  13574. +lib-$(CONFIG_IPKG) += open_transformer.o get_header_tar.o get_header_tar_gz.o
  13575. lib-$(CONFIG_RPM2CPIO) += decompress_unzip.o get_header_cpio.o
  13576. lib-$(CONFIG_RPM) += open_transformer.o decompress_unzip.o get_header_cpio.o
  13577. lib-$(CONFIG_TAR) += get_header_tar.o
  13578. diff -Nur busybox-1.15.2.orig/include/applets.h busybox-1.15.2/include/applets.h
  13579. --- busybox-1.15.2.orig/include/applets.h 2009-09-26 15:14:57.000000000 +0200
  13580. +++ busybox-1.15.2/include/applets.h 2010-03-14 20:53:41.000000000 +0100
  13581. @@ -213,6 +213,7 @@
  13582. IF_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_DROP))
  13583. IF_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
  13584. IF_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
  13585. +IF_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_DROP))
  13586. IF_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_DROP))
  13587. IF_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_DROP))
  13588. IF_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_DROP))
  13589. diff -Nur busybox-1.15.2.orig/include/unarchive.h busybox-1.15.2/include/unarchive.h
  13590. --- busybox-1.15.2.orig/include/unarchive.h 2009-10-08 02:59:09.000000000 +0200
  13591. +++ busybox-1.15.2/include/unarchive.h 2010-03-14 20:53:41.000000000 +0100
  13592. @@ -93,6 +93,7 @@
  13593. extern void data_skip(archive_handle_t *archive_handle) FAST_FUNC;
  13594. extern void data_extract_all(archive_handle_t *archive_handle) FAST_FUNC;
  13595. +extern void data_extract_all_prefix(archive_handle_t *archive_handle) FAST_FUNC;
  13596. extern void data_extract_to_stdout(archive_handle_t *archive_handle) FAST_FUNC;
  13597. extern void data_extract_to_buffer(archive_handle_t *archive_handle) FAST_FUNC;
  13598. diff -Nur busybox-1.15.2.orig/include/usage.h busybox-1.15.2/include/usage.h
  13599. --- busybox-1.15.2.orig/include/usage.h 2009-10-08 02:59:09.000000000 +0200
  13600. +++ busybox-1.15.2/include/usage.h 2010-03-14 20:53:41.000000000 +0100
  13601. @@ -1557,6 +1557,82 @@
  13602. "$ ls -la /tmp/busybox*\n" \
  13603. "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
  13604. +#define ipkg_trivial_usage \
  13605. + "[options]... sub-command [arguments]..."
  13606. +#define ipkg_full_usage \
  13607. + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
  13608. + "\n" \
  13609. + "Sub-commands:\n" \
  13610. + "\nPackage Manipulation:\n" \
  13611. + "\tupdate Update list of available packages\n" \
  13612. + "\tupgrade Upgrade all installed packages to latest version\n" \
  13613. + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
  13614. + "\tinstall <file.ipk> Install package <file.ipk>\n" \
  13615. + "\tconfigure [<pkg>] Configure unpacked packages\n" \
  13616. + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
  13617. + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
  13618. + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
  13619. + "\n" \
  13620. + "Informational Commands:\n" \
  13621. + "\tlist List available packages and descriptions\n" \
  13622. + "\tlist_installed List all and only the installed packages and description \n" \
  13623. + "\tfiles <pkg> List all files belonging to <pkg>\n" \
  13624. + "\tsearch <file|regexp> Search for a package providing <file>\n" \
  13625. + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
  13626. + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
  13627. + "\tdownload <pkg> Download <pkg> to current directory.\n" \
  13628. + "\tcompare_versions <v1> <op> <v2>\n" \
  13629. + "\t compare versions using <= < > >= = << >>\n" \
  13630. + "\tprint_architecture prints the architecture.\n" \
  13631. + "\tprint_installation_architecture\n" \
  13632. + "\twhatdepends [-A] [pkgname|pat]+\n" \
  13633. + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
  13634. + "\twhatprovides [-A] [pkgname|pat]+\n" \
  13635. + "\twhatconflicts [-A] [pkgname|pat]+\n" \
  13636. + "\twhatreplaces [-A] [pkgname|pat]+\n" \
  13637. + "\t prints the installation architecture.\n" \
  13638. + "\n" \
  13639. + "\nOptions:\n" \
  13640. + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
  13641. + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
  13642. + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
  13643. + "\t 0 errors only\n" \
  13644. + "\t 1 normal messages (default)\n" \
  13645. + "\t 2 informative messages\n" \
  13646. + "\t 3 debug output\n" \
  13647. + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
  13648. + "\t-conf <conf_file> Default configuration file location\n" \
  13649. + " is /etc/ipkg.conf\n" \
  13650. + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
  13651. + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
  13652. + " <dest_name> should be a defined dest name from\n" \
  13653. + " the configuration file, (but can also be a\n" \
  13654. + " directory name in a pinch).\n" \
  13655. + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
  13656. + "\t-offline <offline_root> offline installation of packages.\n" \
  13657. + "\t-verbose_wget more wget messages\n" \
  13658. + "\n" \
  13659. + "Force Options (use when ipkg is too smart for its own good):\n" \
  13660. + "\t-force-depends Make dependency checks warnings instead of errors\n" \
  13661. + "\t Install/remove package in spite of failed dependences\n" \
  13662. + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
  13663. + " (no prompts). Note that this will not prevent\n" \
  13664. + " package installation scripts from prompting.\n" \
  13665. + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
  13666. + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
  13667. + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
  13668. + "\t-force_space Install even if there does not seem to be enough space.\n" \
  13669. + "\t-noaction No action -- test only\n" \
  13670. + "\t-nodeps Do not follow dependences\n" \
  13671. + "\t-force-removal-of-dependent-packages\n" \
  13672. + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
  13673. + "\t-test No action -- test only\n" \
  13674. + "\t-t Specify tmp-dir.\n" \
  13675. + "\t--tmp-dir Specify tmp-dir.\n" \
  13676. + "\n" \
  13677. + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
  13678. + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
  13679. +
  13680. #define halt_trivial_usage \
  13681. "[-d delay] [-n] [-f]" IF_FEATURE_WTMP(" [-w]")
  13682. #define halt_full_usage "\n\n" \
  13683. diff -Nur busybox-1.15.2.orig/Makefile busybox-1.15.2/Makefile
  13684. --- busybox-1.15.2.orig/Makefile 2009-10-08 03:06:38.000000000 +0200
  13685. +++ busybox-1.15.2/Makefile 2010-03-14 20:53:41.000000000 +0100
  13686. @@ -445,6 +445,7 @@
  13687. libs-y := \
  13688. archival/ \
  13689. + archival/libipkg/ \
  13690. archival/libunarchive/ \
  13691. console-tools/ \
  13692. coreutils/ \