001-ipkg.patch 423 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687
  1. diff -Nur busybox-1.16.1.orig/archival/Config.in busybox-1.16.1/archival/Config.in
  2. --- busybox-1.16.1.orig/archival/Config.in 2010-03-28 19:43:35.000000000 +0200
  3. +++ busybox-1.16.1/archival/Config.in 2010-06-29 17:31:21.805863709 +0200
  4. @@ -187,6 +187,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.16.1.orig/archival/ipkg.c busybox-1.16.1/archival/ipkg.c
  19. --- busybox-1.16.1.orig/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
  20. +++ busybox-1.16.1/archival/ipkg.c 2010-06-29 17:31:21.827118101 +0200
  21. @@ -0,0 +1,28 @@
  22. +/* ipkg.c - the itsy package management system
  23. +
  24. + Florina Boor
  25. +
  26. + Copyright (C) 2003 kernel concepts
  27. +
  28. + This program is free software; you can redistribute it and/or
  29. + modify it under the terms of the GNU General Public License as
  30. + published by the Free Software Foundation; either version 2, or (at
  31. + your option) any later version.
  32. +
  33. + This program is distributed in the hope that it will be useful, but
  34. + WITHOUT ANY WARRANTY; without even the implied warranty of
  35. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  36. + General Public License for more details.
  37. +
  38. + ipkg command line frontend using libipkg
  39. +
  40. +*/
  41. +
  42. +#include "libbb.h"
  43. +#include "libipkg/libipkg.h"
  44. +
  45. +int ipkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  46. +int ipkg_main(int argc, char **argv)
  47. +{
  48. + return ipkg_op(argc, argv);
  49. +}
  50. diff -Nur busybox-1.16.1.orig/archival/Kbuild busybox-1.16.1/archival/Kbuild
  51. --- busybox-1.16.1.orig/archival/Kbuild 2010-03-20 03:58:07.000000000 +0100
  52. +++ busybox-1.16.1/archival/Kbuild 2010-06-29 17:31:21.865866986 +0200
  53. @@ -16,6 +16,7 @@
  54. lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
  55. lib-$(CONFIG_GUNZIP) += bbunzip.o
  56. lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
  57. +lib-$(CONFIG_IPKG) += ipkg.o
  58. lib-$(CONFIG_LZOP) += lzop.o lzo1x_1.o lzo1x_1o.o lzo1x_d.o bbunzip.o
  59. lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o
  60. lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
  61. diff -Nur busybox-1.16.1.orig/archival/libipkg/args.c busybox-1.16.1/archival/libipkg/args.c
  62. --- busybox-1.16.1.orig/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
  63. +++ busybox-1.16.1/archival/libipkg/args.c 2010-06-29 17:31:21.905863813 +0200
  64. @@ -0,0 +1,242 @@
  65. +/* args.c - parse command-line args
  66. +
  67. + Carl D. Worth
  68. +
  69. + Copyright 2001 University of Southern California
  70. +
  71. + This program is free software; you can redistribute it and/or modify
  72. + it under the terms of the GNU General Public License as published by
  73. + the Free Software Foundation; either version 2, or (at your option)
  74. + any later version.
  75. +
  76. + This program is distributed in the hope that it will be useful,
  77. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  78. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  79. + GNU General Public License for more details.
  80. + */
  81. +
  82. +#include <getopt.h>
  83. +#include <stdlib.h>
  84. +#include <string.h>
  85. +#include <unistd.h>
  86. +
  87. +#include "ipkg.h"
  88. +#include "ipkg_message.h"
  89. +
  90. +#include "args.h"
  91. +#include "sprintf_alloc.h"
  92. +
  93. +#include "libbb.h"
  94. +
  95. +
  96. +static void print_version(void);
  97. +
  98. +enum long_args_opt
  99. +{
  100. + ARGS_OPT_FORCE_DEFAULTS = 129,
  101. + ARGS_OPT_FORCE_DEPENDS,
  102. + ARGS_OPT_FORCE_OVERWRITE,
  103. + ARGS_OPT_FORCE_DOWNGRADE,
  104. + ARGS_OPT_FORCE_REINSTALL,
  105. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
  106. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
  107. + ARGS_OPT_FORCE_SPACE,
  108. + ARGS_OPT_NOACTION,
  109. + ARGS_OPT_NODEPS,
  110. + ARGS_OPT_VERBOSE_WGET,
  111. + ARGS_OPT_VERBOSITY,
  112. + ARGS_OPT_MULTIPLE_PROVIDERS
  113. +};
  114. +
  115. +int args_init(args_t *args)
  116. +{
  117. + const char *conf_file_dir;
  118. +
  119. + memset(args, 0, sizeof(args_t));
  120. +
  121. + args->dest = ARGS_DEFAULT_DEST;
  122. +
  123. + conf_file_dir = getenv("IPKG_CONF_DIR");
  124. + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
  125. + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
  126. + }
  127. + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
  128. + ARGS_DEFAULT_CONF_FILE_NAME);
  129. +
  130. + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
  131. + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
  132. + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
  133. + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
  134. + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
  135. + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
  136. + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
  137. + args->noaction = ARGS_DEFAULT_NOACTION;
  138. + args->nodeps = ARGS_DEFAULT_NODEPS;
  139. + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
  140. + args->verbosity = ARGS_DEFAULT_VERBOSITY;
  141. + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
  142. + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
  143. + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
  144. + args->multiple_providers = 0;
  145. + args->nocheckfordirorfile = 0;
  146. + args->noreadfeedsfile = 0;
  147. +
  148. + return 1;
  149. +}
  150. +
  151. +void args_deinit(args_t *args)
  152. +{
  153. + free(args->conf_file);
  154. + args->conf_file = NULL;
  155. +}
  156. +
  157. +int args_parse(args_t *args, int argc, char *argv[])
  158. +{
  159. + int c;
  160. + int option_index = 0;
  161. + int parse_err = 0;
  162. + static struct option long_options[] = {
  163. + {"query-all", 0, 0, 'A'},
  164. + {"conf-file", 1, 0, 'f'},
  165. + {"conf", 1, 0, 'f'},
  166. + {"dest", 1, 0, 'd'},
  167. + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  168. + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  169. + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  170. + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  171. + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  172. + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  173. + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  174. + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  175. + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  176. + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  177. + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
  178. + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
  179. + {"recursive", 0, 0,
  180. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  181. + {"force-removal-of-dependent-packages", 0, 0,
  182. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  183. + {"force_removal_of_dependent_packages", 0, 0,
  184. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  185. + {"force-removal-of-essential-packages", 0, 0,
  186. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  187. + {"force_removal_of_essential_packages", 0, 0,
  188. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  189. + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  190. + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  191. + {"noaction", 0, 0, ARGS_OPT_NOACTION},
  192. + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
  193. + {"offline", 1, 0, 'o'},
  194. + {"offline-root", 1, 0, 'o'},
  195. + {"test", 0, 0, ARGS_OPT_NOACTION},
  196. + {"tmp-dir", 1, 0, 't'},
  197. + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  198. + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  199. + {"verbosity", 2, 0, 'V'},
  200. + {"version", 0, 0, 'v'},
  201. + {0, 0, 0, 0}
  202. + };
  203. +
  204. + while (1) {
  205. + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
  206. + if (c == -1)
  207. + break;
  208. +
  209. + switch (c) {
  210. + case 'A':
  211. + args->query_all = 1;
  212. + break;
  213. + case 'd':
  214. + args->dest = optarg;
  215. + break;
  216. + case 'f':
  217. + free(args->conf_file);
  218. + args->conf_file = strdup(optarg);
  219. + break;
  220. + case 'o':
  221. + args->offline_root = optarg;
  222. + break;
  223. + case 'n':
  224. + args->noaction = 1;
  225. + break;
  226. + case 't':
  227. + args->tmp_dir = strdup(optarg);
  228. + break;
  229. + case 'v':
  230. + print_version();
  231. + exit(0);
  232. + case 'V':
  233. + case ARGS_OPT_VERBOSITY:
  234. + if (optarg)
  235. + args->verbosity = atoi(optarg);
  236. + else
  237. + args->verbosity += 1;
  238. + break;
  239. + case ARGS_OPT_FORCE_DEFAULTS:
  240. + args->force_defaults = 1;
  241. + break;
  242. + case ARGS_OPT_FORCE_DEPENDS:
  243. + args->force_depends = 1;
  244. + break;
  245. + case ARGS_OPT_FORCE_OVERWRITE:
  246. + args->force_overwrite = 1;
  247. + break;
  248. + case ARGS_OPT_FORCE_DOWNGRADE:
  249. + args->force_downgrade = 1;
  250. + break;
  251. + case ARGS_OPT_FORCE_REINSTALL:
  252. + args->force_reinstall = 1;
  253. + break;
  254. + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
  255. + args->force_removal_of_essential_packages = 1;
  256. + break;
  257. + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
  258. + args->force_removal_of_dependent_packages = 1;
  259. + break;
  260. + case ARGS_OPT_FORCE_SPACE:
  261. + args->force_space = 1;
  262. + break;
  263. + case ARGS_OPT_VERBOSE_WGET:
  264. + args->verbose_wget = 1;
  265. + break;
  266. + case ARGS_OPT_MULTIPLE_PROVIDERS:
  267. + args->multiple_providers = 1;
  268. + break;
  269. + case ARGS_OPT_NODEPS:
  270. + args->nodeps = 1;
  271. + break;
  272. + case ARGS_OPT_NOACTION:
  273. + args->noaction = 1;
  274. + break;
  275. + case ':':
  276. + parse_err++;
  277. + break;
  278. + case '?':
  279. + parse_err++;
  280. + break;
  281. + default:
  282. + bb_error_msg("Confusion: getopt_long returned %d\n", c);
  283. + }
  284. + }
  285. +
  286. + if (parse_err) {
  287. + return -parse_err;
  288. + } else {
  289. + return optind;
  290. + }
  291. +}
  292. +
  293. +void args_usage(const char *complaint)
  294. +{
  295. + if (complaint) {
  296. + bb_error_msg("%s\n", complaint);
  297. + }
  298. + print_version();
  299. + bb_show_usage();
  300. + exit(1);
  301. +}
  302. +
  303. +static void print_version(void)
  304. +{
  305. + bb_error_msg("version %s\n", IPKG_VERSION);
  306. +}
  307. diff -Nur busybox-1.16.1.orig/archival/libipkg/args.h busybox-1.16.1/archival/libipkg/args.h
  308. --- busybox-1.16.1.orig/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
  309. +++ busybox-1.16.1/archival/libipkg/args.h 2010-06-29 17:31:21.945866019 +0200
  310. @@ -0,0 +1,72 @@
  311. +/* args.h - parse command-line args
  312. +
  313. + Carl D. Worth
  314. +
  315. + Copyright 2001 University of Southern California
  316. +
  317. + This program is free software; you can redistribute it and/or modify
  318. + it under the terms of the GNU General Public License as published by
  319. + the Free Software Foundation; either version 2, or (at your option)
  320. + any later version.
  321. +
  322. + This program is distributed in the hope that it will be useful,
  323. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  324. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  325. + GNU General Public License for more details.
  326. +*/
  327. +
  328. +#ifndef ARGS_H
  329. +#define ARGS_H
  330. +
  331. +struct args
  332. +{
  333. + char *conf_file;
  334. + char *dest;
  335. + char *tmp_dir;
  336. + int force_defaults;
  337. + int force_depends;
  338. + int force_overwrite;
  339. + int force_downgrade;
  340. + int force_reinstall;
  341. + int force_removal_of_essential_packages;
  342. + int force_removal_of_dependent_packages;
  343. + int force_space;
  344. + int noaction;
  345. + int nodeps;
  346. + int multiple_providers;
  347. + int query_all;
  348. + int verbose_wget;
  349. + int verbosity;
  350. + int nocheckfordirorfile;
  351. + int noreadfeedsfile;
  352. + char *offline_root;
  353. + char *offline_root_pre_script_cmd;
  354. + char *offline_root_post_script_cmd;
  355. +};
  356. +typedef struct args args_t;
  357. +
  358. +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
  359. +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
  360. +#define ARGS_DEFAULT_DEST NULL
  361. +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
  362. +#define ARGS_DEFAULT_FORCE_DEPENDS 0
  363. +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
  364. +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
  365. +#define ARGS_DEFAULT_FORCE_REINSTALL 0
  366. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
  367. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
  368. +#define ARGS_DEFAULT_FORCE_SPACE 0
  369. +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
  370. +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
  371. +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
  372. +#define ARGS_DEFAULT_NOACTION 0
  373. +#define ARGS_DEFAULT_NODEPS 0
  374. +#define ARGS_DEFAULT_VERBOSE_WGET 0
  375. +#define ARGS_DEFAULT_VERBOSITY 1
  376. +
  377. +int args_init(args_t *args);
  378. +void args_deinit(args_t *args);
  379. +int args_parse(args_t *args, int argc, char *argv[]);
  380. +void args_usage(const char *complaint);
  381. +
  382. +#endif
  383. diff -Nur busybox-1.16.1.orig/archival/libipkg/conffile.c busybox-1.16.1/archival/libipkg/conffile.c
  384. --- busybox-1.16.1.orig/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
  385. +++ busybox-1.16.1/archival/libipkg/conffile.c 2010-06-29 17:31:21.987118040 +0200
  386. @@ -0,0 +1,65 @@
  387. +/* conffile.c - the itsy package management system
  388. +
  389. + Carl D. Worth
  390. +
  391. + Copyright (C) 2001 University of Southern California
  392. +
  393. + This program is free software; you can redistribute it and/or
  394. + modify it under the terms of the GNU General Public License as
  395. + published by the Free Software Foundation; either version 2, or (at
  396. + your option) any later version.
  397. +
  398. + This program is distributed in the hope that it will be useful, but
  399. + WITHOUT ANY WARRANTY; without even the implied warranty of
  400. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  401. + General Public License for more details.
  402. +*/
  403. +
  404. +#include <string.h>
  405. +#include <stdlib.h>
  406. +
  407. +#include "libbb.h"
  408. +#include "ipkg.h"
  409. +#include "ipkg_message.h"
  410. +
  411. +#include "conffile.h"
  412. +#include "file_util.h"
  413. +#include "sprintf_alloc.h"
  414. +
  415. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum)
  416. +{
  417. + return nv_pair_init(conffile, file_name, (char *)md5sum);
  418. +}
  419. +
  420. +void conffile_deinit(conffile_t *conffile)
  421. +{
  422. + nv_pair_deinit(conffile);
  423. +}
  424. +
  425. +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
  426. +{
  427. + uint8_t *md5sum;
  428. + char *filename = conffile->name;
  429. + char *root_filename;
  430. + int ret;
  431. +
  432. + if (conffile->value == NULL) {
  433. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
  434. + return 1;
  435. + }
  436. +
  437. + root_filename = root_filename_alloc(conf, filename);
  438. +
  439. + md5sum = file_md5sum_alloc(root_filename);
  440. +
  441. + ret = strcmp((char *)md5sum, conffile->value);
  442. + if (ret) {
  443. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
  444. + conffile->name, md5sum, conffile->value);
  445. + }
  446. +
  447. + free(root_filename);
  448. + free(md5sum);
  449. +
  450. + return ret;
  451. +}
  452. diff -Nur busybox-1.16.1.orig/archival/libipkg/conffile.h busybox-1.16.1/archival/libipkg/conffile.h
  453. --- busybox-1.16.1.orig/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
  454. +++ busybox-1.16.1/archival/libipkg/conffile.h 2010-06-29 17:31:22.018368070 +0200
  455. @@ -0,0 +1,30 @@
  456. +/* conffile.h - the itsy package management system
  457. +
  458. + Carl D. Worth
  459. +
  460. + Copyright (C) 2001 University of Southern California
  461. +
  462. + This program is free software; you can redistribute it and/or
  463. + modify it under the terms of the GNU General Public License as
  464. + published by the Free Software Foundation; either version 2, or (at
  465. + your option) any later version.
  466. +
  467. + This program is distributed in the hope that it will be useful, but
  468. + WITHOUT ANY WARRANTY; without even the implied warranty of
  469. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  470. + General Public License for more details.
  471. +*/
  472. +
  473. +#ifndef CONFFILE_H
  474. +#define CONFFILE_H
  475. +
  476. +#include "nv_pair.h"
  477. +
  478. +typedef struct nv_pair conffile_t;
  479. +
  480. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum);
  481. +void conffile_deinit(conffile_t *conffile);
  482. +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
  483. +
  484. +#endif
  485. +
  486. diff -Nur busybox-1.16.1.orig/archival/libipkg/conffile_list.c busybox-1.16.1/archival/libipkg/conffile_list.c
  487. --- busybox-1.16.1.orig/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
  488. +++ busybox-1.16.1/archival/libipkg/conffile_list.c 2010-06-29 17:31:22.055873481 +0200
  489. @@ -0,0 +1,47 @@
  490. +/* conffile_list.c - the itsy package management system
  491. +
  492. + Carl D. Worth
  493. +
  494. + Copyright (C) 2001 University of Southern California
  495. +
  496. + This program is free software; you can redistribute it and/or
  497. + modify it under the terms of the GNU General Public License as
  498. + published by the Free Software Foundation; either version 2, or (at
  499. + your option) any later version.
  500. +
  501. + This program is distributed in the hope that it will be useful, but
  502. + WITHOUT ANY WARRANTY; without even the implied warranty of
  503. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  504. + General Public License for more details.
  505. +*/
  506. +
  507. +#include "ipkg.h"
  508. +
  509. +#include "conffile_list.h"
  510. +
  511. +int conffile_list_init(conffile_list_t *list)
  512. +{
  513. + return nv_pair_list_init(list);
  514. +}
  515. +
  516. +void conffile_list_deinit(conffile_list_t *list)
  517. +{
  518. + nv_pair_list_deinit(list);
  519. +}
  520. +
  521. +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
  522. + const char *md5sum)
  523. +{
  524. + return nv_pair_list_append(list, file_name, md5sum);
  525. +}
  526. +
  527. +int conffile_list_push(conffile_list_t *list, conffile_t *data)
  528. +{
  529. + return nv_pair_list_push(list, data);
  530. +}
  531. +
  532. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
  533. +{
  534. + return nv_pair_list_pop(list);
  535. +}
  536. +
  537. diff -Nur busybox-1.16.1.orig/archival/libipkg/conffile_list.h busybox-1.16.1/archival/libipkg/conffile_list.h
  538. --- busybox-1.16.1.orig/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
  539. +++ busybox-1.16.1/archival/libipkg/conffile_list.h 2010-06-29 17:31:22.089612450 +0200
  540. @@ -0,0 +1,36 @@
  541. +/* conffile_list.h - the itsy package management system
  542. +
  543. + Carl D. Worth
  544. +
  545. + Copyright (C) 2001 University of Southern California
  546. +
  547. + This program is free software; you can redistribute it and/or
  548. + modify it under the terms of the GNU General Public License as
  549. + published by the Free Software Foundation; either version 2, or (at
  550. + your option) any later version.
  551. +
  552. + This program is distributed in the hope that it will be useful, but
  553. + WITHOUT ANY WARRANTY; without even the implied warranty of
  554. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  555. + General Public License for more details.
  556. +*/
  557. +
  558. +#ifndef CONFFILE_LIST_H
  559. +#define CONFFILE_LIST_H
  560. +
  561. +#include "conffile.h"
  562. +#include "nv_pair_list.h"
  563. +
  564. +typedef struct nv_pair_list_elt conffile_list_elt_t;
  565. +typedef struct nv_pair_list conffile_list_t;
  566. +
  567. +int conffile_list_init(conffile_list_t *list);
  568. +void conffile_list_deinit(conffile_list_t *list);
  569. +
  570. +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
  571. + const char *root_dir);
  572. +int conffile_list_push(conffile_list_t *list, conffile_t *data);
  573. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
  574. +
  575. +#endif
  576. +
  577. diff -Nur busybox-1.16.1.orig/archival/libipkg/file_util.c busybox-1.16.1/archival/libipkg/file_util.c
  578. --- busybox-1.16.1.orig/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
  579. +++ busybox-1.16.1/archival/libipkg/file_util.c 2010-06-29 17:31:22.137606321 +0200
  580. @@ -0,0 +1,186 @@
  581. +/* file_util.c - convenience routines for common stat operations
  582. +
  583. + Carl D. Worth
  584. +
  585. + Copyright (C) 2001 University of Southern California
  586. +
  587. + This program is free software; you can redistribute it and/or
  588. + modify it under the terms of the GNU General Public License as
  589. + published by the Free Software Foundation; either version 2, or (at
  590. + your option) any later version.
  591. +
  592. + This program is distributed in the hope that it will be useful, but
  593. + WITHOUT ANY WARRANTY; without even the implied warranty of
  594. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  595. + General Public License for more details.
  596. +*/
  597. +
  598. +#include "ipkg.h"
  599. +#include <sys/types.h>
  600. +#include <sys/stat.h>
  601. +
  602. +#include "sprintf_alloc.h"
  603. +#include "file_util.h"
  604. +#include "libbb.h"
  605. +#undef strlen
  606. +
  607. +int file_exists(const char *file_name)
  608. +{
  609. + int err;
  610. + struct stat stat_buf;
  611. +
  612. + err = stat(file_name, &stat_buf);
  613. + if (err == 0) {
  614. + return 1;
  615. + } else {
  616. + return 0;
  617. + }
  618. +}
  619. +
  620. +int file_is_dir(const char *file_name)
  621. +{
  622. + int err;
  623. + struct stat stat_buf;
  624. +
  625. + err = stat(file_name, &stat_buf);
  626. + if (err) {
  627. + return 0;
  628. + }
  629. +
  630. + return S_ISDIR(stat_buf.st_mode);
  631. +}
  632. +
  633. +/* read a single line from a file, stopping at a newline or EOF.
  634. + If a newline is read, it will appear in the resulting string.
  635. + Return value is a malloc'ed char * which should be freed at
  636. + some point by the caller.
  637. +
  638. + Return value is NULL if the file is at EOF when called.
  639. +*/
  640. +#define FILE_READ_LINE_BUF_SIZE 1024
  641. +char *file_read_line_alloc(FILE *file)
  642. +{
  643. + char buf[FILE_READ_LINE_BUF_SIZE];
  644. + int buf_len;
  645. + char *line = NULL;
  646. + int line_size = 0;
  647. +
  648. + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
  649. + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
  650. + buf_len = strlen(buf);
  651. + if (line) {
  652. + line_size += buf_len;
  653. + line = realloc(line, line_size);
  654. + if (line == NULL) {
  655. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  656. + break;
  657. + }
  658. + strcat(line, buf);
  659. + } else {
  660. + line_size = buf_len + 1;
  661. + line = strdup(buf);
  662. + }
  663. + if (buf[buf_len - 1] == '\n') {
  664. + break;
  665. + }
  666. + }
  667. +
  668. + return line;
  669. +}
  670. +
  671. +int file_move(const char *src, const char *dest)
  672. +{
  673. + int err;
  674. +
  675. + err = rename(src, dest);
  676. +
  677. + if (err && errno == EXDEV) {
  678. + err = file_copy(src, dest);
  679. + unlink(src);
  680. + } else if (err) {
  681. + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
  682. + __FUNCTION__, src, dest, strerror(errno));
  683. + }
  684. +
  685. + return err;
  686. +}
  687. +
  688. +/* I put these here to keep libbb dependencies from creeping all over
  689. + the ipkg code */
  690. +int file_copy(const char *src, const char *dest)
  691. +{
  692. + int err;
  693. +
  694. + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
  695. + if (err) {
  696. + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
  697. + __FUNCTION__, src, dest);
  698. + }
  699. +
  700. + return err;
  701. +}
  702. +
  703. +int file_mkdir_hier(char *path, long mode)
  704. +{
  705. + return bb_make_directory(path, mode, FILEUTILS_RECUR);
  706. +}
  707. +
  708. +static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
  709. + unsigned hash_length)
  710. +{
  711. + /* xzalloc zero-terminates */
  712. + char *hex_value = xzalloc((hash_length * 2) + 1);
  713. + bin2hex(hex_value, (char*)hash_value, hash_length);
  714. + return (unsigned char *)hex_value;
  715. +}
  716. +
  717. +static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
  718. +{
  719. + int src_fd, hash_len, count;
  720. + union _ctx_ {
  721. + sha1_ctx_t sha1;
  722. + md5_ctx_t md5;
  723. + } context;
  724. + uint8_t *hash_value = NULL;
  725. + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
  726. + void FAST_FUNC (*update)(const void*, size_t, void*);
  727. + void FAST_FUNC (*final)(void*, void*);
  728. +
  729. + src_fd = open_or_warn_stdin(filename);
  730. + if (src_fd < 0) {
  731. + return NULL;
  732. + }
  733. +
  734. + /* figure specific hash algorithims */
  735. + if (ENABLE_MD5SUM && hash_algo == HASH_MD5) {
  736. + md5_begin(&context.md5);
  737. + update = (void*)md5_hash;
  738. + final = (void*)md5_end;
  739. + hash_len = 16;
  740. + } else {
  741. + bb_error_msg_and_die("algorithm not supported");
  742. + }
  743. +
  744. + while (0 < (count = safe_read(src_fd, in_buf, 4096))) {
  745. + update(in_buf, count, &context);
  746. + }
  747. +
  748. + if (count == 0) {
  749. + final(in_buf, &context);
  750. + hash_value = hash_bin_to_hex(in_buf, hash_len);
  751. + }
  752. +
  753. + RELEASE_CONFIG_BUFFER(in_buf);
  754. +
  755. + if (src_fd != STDIN_FILENO) {
  756. + close(src_fd);
  757. + }
  758. +
  759. + return hash_value;
  760. +}
  761. +
  762. +uint8_t *file_md5sum_alloc(const char *file_name)
  763. +{
  764. + return hash_file(file_name, HASH_MD5);
  765. +}
  766. +
  767. diff -Nur busybox-1.16.1.orig/archival/libipkg/file_util.h busybox-1.16.1/archival/libipkg/file_util.h
  768. --- busybox-1.16.1.orig/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
  769. +++ busybox-1.16.1/archival/libipkg/file_util.h 2010-06-29 17:31:22.220596553 +0200
  770. @@ -0,0 +1,29 @@
  771. +/* file_util.h - convenience routines for common file operations
  772. +
  773. + Carl D. Worth
  774. +
  775. + Copyright (C) 2001 University of Southern California
  776. +
  777. + This program is free software; you can redistribute it and/or
  778. + modify it under the terms of the GNU General Public License as
  779. + published by the Free Software Foundation; either version 2, or (at
  780. + your option) any later version.
  781. +
  782. + This program is distributed in the hope that it will be useful, but
  783. + WITHOUT ANY WARRANTY; without even the implied warranty of
  784. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  785. + General Public License for more details.
  786. +*/
  787. +
  788. +#ifndef FILE_UTIL_H
  789. +#define FILE_UTIL_H
  790. +
  791. +int file_exists(const char *file_name);
  792. +int file_is_dir(const char *file_name);
  793. +char *file_read_line_alloc(FILE *file);
  794. +int file_move(const char *src, const char *dest);
  795. +int file_copy(const char *src, const char *dest);
  796. +int file_mkdir_hier(char *path, long mode);
  797. +uint8_t *file_md5sum_alloc(const char *file_name);
  798. +
  799. +#endif
  800. diff -Nur busybox-1.16.1.orig/archival/libipkg/hash_table.c busybox-1.16.1/archival/libipkg/hash_table.c
  801. --- busybox-1.16.1.orig/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
  802. +++ busybox-1.16.1/archival/libipkg/hash_table.c 2010-06-29 17:31:22.257056261 +0200
  803. @@ -0,0 +1,155 @@
  804. +/* hash.c - hash tables for ipkg
  805. +
  806. + Steven M. Ayer, Jamey Hicks
  807. +
  808. + Copyright (C) 2002 Compaq Computer Corporation
  809. +
  810. + This program is free software; you can redistribute it and/or
  811. + modify it under the terms of the GNU General Public License as
  812. + published by the Free Software Foundation; either version 2, or (at
  813. + your option) any later version.
  814. +
  815. + This program is distributed in the hope that it will be useful, but
  816. + WITHOUT ANY WARRANTY; without even the implied warranty of
  817. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  818. + General Public License for more details.
  819. +*/
  820. +
  821. +#include <errno.h>
  822. +#include <stdio.h>
  823. +#include <stdlib.h>
  824. +#include <string.h>
  825. +#include "hash_table.h"
  826. +#include "ipkg_message.h"
  827. +
  828. +
  829. +static int hash_index(hash_table_t *hash, const char *pkg_name);
  830. +static int rotating(const char *key, int len, int prime);
  831. +
  832. +static int hash_index(hash_table_t *hash, const char *pkg_name)
  833. +{
  834. + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
  835. +}
  836. +
  837. +static int rotating(const char *key, int len, int prime)
  838. +{
  839. + unsigned int hash, i;
  840. + for (hash=len, i=0; i<len; ++i)
  841. + hash = (hash<<4)^(hash>>28)^key[i];
  842. + return (hash % prime);
  843. +}
  844. +
  845. +
  846. +/*
  847. + * this is an open table keyed by strings
  848. + */
  849. +int hash_table_init(const char *name, hash_table_t *hash, int len)
  850. +{
  851. + static int primes_table[] = {
  852. + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
  853. + 19471, 23143, 33961, 46499, 49727, 99529, 0
  854. + };
  855. + int *picker;
  856. +
  857. + if (hash->entries != NULL) {
  858. + /* we have been here already */
  859. + return 0;
  860. + }
  861. +
  862. + hash->name = name;
  863. + hash->entries = NULL;
  864. + hash->n_entries = 0;
  865. + hash->hash_entry_key = NULL;
  866. +
  867. + picker = primes_table;
  868. + while(*picker && (*picker++ < len));
  869. + if(!*picker)
  870. + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
  871. + --picker;
  872. +
  873. + hash->n_entries = *picker;
  874. + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
  875. + if (hash->entries == NULL) {
  876. + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
  877. + return ENOMEM;
  878. + }
  879. + return 0;
  880. +}
  881. +
  882. +void hash_table_deinit(hash_table_t *hash)
  883. +{
  884. + free(hash->entries);
  885. + hash->entries = NULL;
  886. + hash->n_entries = 0;
  887. +}
  888. +
  889. +void *hash_table_get(hash_table_t *hash, const char *key)
  890. +{
  891. + int ndx= hash_index(hash, key);
  892. + hash_entry_t *hash_entry = hash->entries + ndx;
  893. + while (hash_entry)
  894. + {
  895. + if (hash_entry->key)
  896. + {
  897. + if (strcmp(key, hash_entry->key) == 0) {
  898. + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
  899. + return hash_entry->data;
  900. + }
  901. + }
  902. + hash_entry = hash_entry->next;
  903. + }
  904. + return NULL;
  905. +}
  906. +
  907. +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
  908. +{
  909. + int ndx= hash_index(hash, key);
  910. + hash_entry_t *hash_entry = hash->entries + ndx;
  911. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
  912. + if (hash_entry->key) {
  913. + if (strcmp(hash_entry->key, key) == 0) {
  914. + /* alread in table, update the value */
  915. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
  916. + hash_entry->data = value;
  917. + return 0;
  918. + } else {
  919. + /*
  920. + * if this is a collision, we have to go to the end of the ll,
  921. + * then add a new entry
  922. + * before we can hook up the value
  923. + */
  924. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
  925. + while (hash_entry->next)
  926. + hash_entry = hash_entry->next;
  927. + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
  928. + if (!hash_entry->next) {
  929. + return -ENOMEM;
  930. + }
  931. + hash_entry = hash_entry->next;
  932. + hash_entry->next = NULL;
  933. + }
  934. + }
  935. + hash->n_elements++;
  936. + hash_entry->key = strdup(key);
  937. + hash_entry->data = value;
  938. +
  939. + return 0;
  940. +}
  941. +
  942. +
  943. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
  944. +{
  945. + int i;
  946. + if (!hash || !f)
  947. + return;
  948. +
  949. + for (i = 0; i < hash->n_entries; i++) {
  950. + hash_entry_t *hash_entry = (hash->entries + i);
  951. + do {
  952. + if(hash_entry->key) {
  953. + f(hash_entry->key, hash_entry->data, data);
  954. + }
  955. + } while((hash_entry = hash_entry->next));
  956. + }
  957. +}
  958. +
  959. diff -Nur busybox-1.16.1.orig/archival/libipkg/hash_table.h busybox-1.16.1/archival/libipkg/hash_table.h
  960. --- busybox-1.16.1.orig/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
  961. +++ busybox-1.16.1/archival/libipkg/hash_table.h 2010-06-29 17:31:22.305858166 +0200
  962. @@ -0,0 +1,44 @@
  963. +/* hash.h - hash tables for ipkg
  964. +
  965. + Steven M. Ayer, Jamey Hicks
  966. +
  967. + Copyright (C) 2002 Compaq Computer Corporation
  968. +
  969. + This program is free software; you can redistribute it and/or
  970. + modify it under the terms of the GNU General Public License as
  971. + published by the Free Software Foundation; either version 2, or (at
  972. + your option) any later version.
  973. +
  974. + This program is distributed in the hope that it will be useful, but
  975. + WITHOUT ANY WARRANTY; without even the implied warranty of
  976. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  977. + General Public License for more details.
  978. +*/
  979. +
  980. +#ifndef _HASH_TABLE_H_
  981. +#define _HASH_TABLE_H_
  982. +
  983. +typedef struct hash_entry hash_entry_t;
  984. +typedef struct hash_table hash_table_t;
  985. +
  986. +struct hash_entry {
  987. + const char * key;
  988. + void * data;
  989. + struct hash_entry * next;
  990. +};
  991. +
  992. +struct hash_table {
  993. + const char *name;
  994. + hash_entry_t * entries;
  995. + int n_entries; /* number of buckets */
  996. + int n_elements;
  997. + const char * (*hash_entry_key)(void * data);
  998. +};
  999. +
  1000. +int hash_table_init(const char *name, hash_table_t *hash, int len);
  1001. +void hash_table_deinit(hash_table_t *hash);
  1002. +void *hash_table_get(hash_table_t *hash, const char *key);
  1003. +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
  1004. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
  1005. +
  1006. +#endif /* _HASH_TABLE_H_ */
  1007. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_cmd.c busybox-1.16.1/archival/libipkg/ipkg_cmd.c
  1008. --- busybox-1.16.1.orig/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
  1009. +++ busybox-1.16.1/archival/libipkg/ipkg_cmd.c 2010-06-29 19:19:50.699618181 +0200
  1010. @@ -0,0 +1,1366 @@
  1011. +/* ipkg_cmd.c - the itsy package management system
  1012. +
  1013. + Carl D. Worth
  1014. +
  1015. + Copyright (C) 2001 University of Southern California
  1016. +
  1017. + This program is free software; you can redistribute it and/or
  1018. + modify it under the terms of the GNU General Public License as
  1019. + published by the Free Software Foundation; either version 2, or (at
  1020. + your option) any later version.
  1021. +
  1022. + This program is distributed in the hope that it will be useful, but
  1023. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1024. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1025. + General Public License for more details.
  1026. +*/
  1027. +
  1028. +#include <string.h>
  1029. +
  1030. +#include "ipkg.h"
  1031. +#include <libgen.h>
  1032. +#include <glob.h>
  1033. +#include <errno.h>
  1034. +#include <stdlib.h>
  1035. +#include <unistd.h>
  1036. +#include <signal.h>
  1037. +#include <stdio.h>
  1038. +#include <dirent.h>
  1039. +
  1040. +#include "ipkg_conf.h"
  1041. +#include "ipkg_cmd.h"
  1042. +#include "ipkg_message.h"
  1043. +#include "pkg.h"
  1044. +#include "pkg_dest.h"
  1045. +#include "pkg_parse.h"
  1046. +#include "sprintf_alloc.h"
  1047. +#include "pkg.h"
  1048. +#include "file_util.h"
  1049. +#include "str_util.h"
  1050. +#include "unarchive.h"
  1051. +
  1052. +#include <fnmatch.h>
  1053. +
  1054. +
  1055. +#include "ipkg_download.h"
  1056. +#include "ipkg_install.h"
  1057. +#include "ipkg_upgrade.h"
  1058. +#include "ipkg_remove.h"
  1059. +#include "ipkg_configure.h"
  1060. +#include "ipkg_message.h"
  1061. +
  1062. +#include "libipkg.h"
  1063. +static void *p_userdata = NULL;
  1064. +
  1065. +static int ipkg_update_cmd(ipkg_conf_t *conf);
  1066. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1067. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1068. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1069. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1070. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf);
  1071. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1072. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1073. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1074. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1075. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1076. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1077. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1078. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1079. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1080. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1081. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1082. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1083. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1084. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1085. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1086. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1087. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1088. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf);
  1089. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1090. +
  1091. +/* XXX: CLEANUP: The usage strings should be incorporated into this
  1092. + array for easier maintenance */
  1093. +static ipkg_cmd_t cmds[] = {
  1094. + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
  1095. + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
  1096. + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
  1097. + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
  1098. + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
  1099. + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
  1100. + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
  1101. + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
  1102. + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
  1103. + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
  1104. + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
  1105. + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
  1106. + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
  1107. + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
  1108. + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
  1109. + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1110. + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1111. + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1112. + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1113. + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1114. + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1115. + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
  1116. + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
  1117. + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
  1118. + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
  1119. + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
  1120. + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
  1121. + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
  1122. + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
  1123. +};
  1124. +
  1125. +int ipkg_state_changed;
  1126. +static void write_status_files_if_changed(ipkg_conf_t *conf)
  1127. +{
  1128. + if (ipkg_state_changed && !conf->noaction) {
  1129. + ipkg_message(conf, IPKG_INFO,
  1130. + " writing status file\n");
  1131. + ipkg_conf_write_status_files(conf);
  1132. + pkg_write_changed_filelists(conf);
  1133. + } else {
  1134. + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
  1135. + }
  1136. +}
  1137. +
  1138. +
  1139. +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
  1140. +
  1141. +ipkg_cmd_t *ipkg_cmd_find(const char *name)
  1142. +{
  1143. + int i;
  1144. + ipkg_cmd_t *cmd;
  1145. +
  1146. + for (i=0; i < num_cmds; i++) {
  1147. + cmd = &cmds[i];
  1148. + if (strcmp(name, cmd->name) == 0) {
  1149. + return cmd;
  1150. + }
  1151. + }
  1152. +
  1153. + return NULL;
  1154. +}
  1155. +
  1156. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
  1157. +{
  1158. + int result;
  1159. + p_userdata = userdata;
  1160. +
  1161. +
  1162. + result = (cmd->fun)(conf, argc, argv);
  1163. + if ( result == 0 ) {
  1164. + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
  1165. + } else {
  1166. + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
  1167. +
  1168. + }
  1169. + if ( error_list ) {
  1170. + reverse_error_list(&error_list);
  1171. +
  1172. + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
  1173. + /* Here we print the errors collected and free the list */
  1174. + while (error_list != NULL) {
  1175. + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
  1176. + error_list = error_list->next;
  1177. +
  1178. + }
  1179. + free_error_list(&error_list);
  1180. +
  1181. + }
  1182. +
  1183. + p_userdata = NULL;
  1184. + return result;
  1185. +}
  1186. +
  1187. +static int ipkg_update_cmd(ipkg_conf_t *conf)
  1188. +{
  1189. + int err;
  1190. + int failures;
  1191. + char *lists_dir;
  1192. + pkg_src_list_elt_t *iter;
  1193. + pkg_src_t *src;
  1194. +
  1195. +
  1196. + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
  1197. +
  1198. + if (! file_is_dir(lists_dir)) {
  1199. + if (file_exists(lists_dir)) {
  1200. + ipkg_message(conf, IPKG_ERROR,
  1201. + "%s: ERROR: %s exists, but is not a directory\n",
  1202. + __FUNCTION__, lists_dir);
  1203. + free(lists_dir);
  1204. + return EINVAL;
  1205. + }
  1206. + err = file_mkdir_hier(lists_dir, 0755);
  1207. + if (err) {
  1208. + ipkg_message(conf, IPKG_ERROR,
  1209. + "%s: ERROR: failed to make directory %s: %s\n",
  1210. + __FUNCTION__, lists_dir, strerror(errno));
  1211. + free(lists_dir);
  1212. + return EINVAL;
  1213. + }
  1214. + }
  1215. +
  1216. + failures = 0;
  1217. + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
  1218. + char *url, *list_file_name;
  1219. +
  1220. + src = iter->data;
  1221. +
  1222. + if (src->extra_data) /* debian style? */
  1223. + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
  1224. + src->gzip ? "Packages.gz" : "Packages");
  1225. + else
  1226. + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
  1227. +
  1228. + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
  1229. + if (src->gzip) {
  1230. + char *tmp;
  1231. + char *tmp_file_name;
  1232. + FILE *in, *out;
  1233. +
  1234. + tmp = strdup ("/tmp/ipkg.XXXXXX");
  1235. +
  1236. + if (mkdtemp (tmp) == NULL) {
  1237. + perror ("mkdtemp");
  1238. + failures++;
  1239. + continue;
  1240. + }
  1241. +
  1242. + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
  1243. + err = ipkg_download(conf, url, tmp_file_name);
  1244. + if (err == 0) {
  1245. + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
  1246. + in = fopen (tmp_file_name, "r");
  1247. + out = fopen (list_file_name, "w");
  1248. + if (in && out) {
  1249. + inflate_unzip_result res;
  1250. + inflate_unzip (&res, 0x8000, fileno(in), fileno(out));
  1251. + } else
  1252. + err = 1;
  1253. + if (in)
  1254. + fclose (in);
  1255. + if (out)
  1256. + fclose (out);
  1257. + unlink (tmp_file_name);
  1258. + rmdir (tmp);
  1259. + free (tmp);
  1260. + }
  1261. + } else
  1262. + err = ipkg_download(conf, url, list_file_name);
  1263. + if (err) {
  1264. + failures++;
  1265. + } else {
  1266. + ipkg_message(conf, IPKG_NOTICE,
  1267. + "Updated list of available packages in %s\n",
  1268. + list_file_name);
  1269. + }
  1270. + free(url);
  1271. + free(list_file_name);
  1272. + }
  1273. + free(lists_dir);
  1274. +
  1275. +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
  1276. +#warning here
  1277. + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
  1278. + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
  1279. + * -Jamey 3/1/03
  1280. + */
  1281. + {
  1282. + int i;
  1283. + int changed = 0;
  1284. + pkg_vec_t *available = pkg_vec_alloc();
  1285. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1286. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
  1287. + for (i = 0; i < available->len; i++) {
  1288. + pkg_t *pkg = available->pkgs[i];
  1289. + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
  1290. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
  1291. + pkg->state_want = SW_UNKNOWN;
  1292. + changed = 1;
  1293. + }
  1294. + }
  1295. + pkg_vec_free(available);
  1296. + if (changed) {
  1297. + write_status_files_if_changed(conf);
  1298. + }
  1299. + }
  1300. +#endif
  1301. +
  1302. + return failures;
  1303. +}
  1304. +
  1305. +
  1306. +/* scan the args passed and cache the local filenames of the packages */
  1307. +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
  1308. +{
  1309. + int i;
  1310. + int err;
  1311. +
  1312. + /*
  1313. + * First scan through package names/urls
  1314. + * For any urls, download the packages and install in database.
  1315. + * For any files, install package info in database.
  1316. + */
  1317. + for (i = 0; i < argc; i ++) {
  1318. + char *filename = argv [i];
  1319. + //char *tmp = basename (tmp);
  1320. + //int tmplen = strlen (tmp);
  1321. +
  1322. + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
  1323. + // continue;
  1324. + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
  1325. + // continue;
  1326. +
  1327. + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
  1328. +
  1329. + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
  1330. + if (err)
  1331. + return err;
  1332. + }
  1333. + return 0;
  1334. +}
  1335. +
  1336. +struct ipkg_intercept
  1337. +{
  1338. + char *oldpath;
  1339. + char *statedir;
  1340. +};
  1341. +
  1342. +typedef struct ipkg_intercept *ipkg_intercept_t;
  1343. +ipkg_intercept_t ipkg_prep_intercepts(void);
  1344. +
  1345. +ipkg_intercept_t ipkg_prep_intercepts(void)
  1346. +{
  1347. + ipkg_intercept_t ctx;
  1348. + char *newpath;
  1349. + int gen;
  1350. +
  1351. + ctx = malloc (sizeof (*ctx));
  1352. + ctx->oldpath = strdup (getenv ("PATH"));
  1353. +
  1354. + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
  1355. + setenv ("PATH", newpath, 1);
  1356. + free (newpath);
  1357. +
  1358. + gen = 0;
  1359. + retry:
  1360. + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
  1361. + if (mkdir (ctx->statedir, 0770) < 0) {
  1362. + if (errno == EEXIST) {
  1363. + free (ctx->statedir);
  1364. + gen++;
  1365. + goto retry;
  1366. + }
  1367. + perror (ctx->statedir);
  1368. + return NULL;
  1369. + }
  1370. + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
  1371. + return ctx;
  1372. +}
  1373. +
  1374. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx);
  1375. +
  1376. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
  1377. +{
  1378. + char *cmd;
  1379. + DIR *dir;
  1380. + int err = 0;
  1381. +
  1382. + setenv ("PATH", ctx->oldpath, 1);
  1383. + free (ctx->oldpath);
  1384. +
  1385. + dir = opendir (ctx->statedir);
  1386. + if (dir) {
  1387. + struct dirent *de;
  1388. + while (de = readdir (dir), de != NULL) {
  1389. + char *path;
  1390. +
  1391. + if (de->d_name[0] == '.')
  1392. + continue;
  1393. +
  1394. + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
  1395. + if (access (path, X_OK) == 0) {
  1396. + if (system (path)) {
  1397. + err = errno;
  1398. + perror (de->d_name);
  1399. + }
  1400. + }
  1401. + free (path);
  1402. + }
  1403. + } else
  1404. + perror (ctx->statedir);
  1405. +
  1406. + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
  1407. + system (cmd);
  1408. + free (cmd);
  1409. +
  1410. + free (ctx->statedir);
  1411. + free (ctx);
  1412. +
  1413. + return err;
  1414. +}
  1415. +
  1416. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
  1417. +{
  1418. + pkg_vec_t *all;
  1419. + int i;
  1420. + pkg_t *pkg;
  1421. + ipkg_intercept_t ic;
  1422. + int r, err = 0;
  1423. +
  1424. + ipkg_message(conf, IPKG_INFO,
  1425. + "Configuring unpacked packages\n");
  1426. + fflush( stdout );
  1427. +
  1428. + all = pkg_vec_alloc();
  1429. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  1430. +
  1431. + ic = ipkg_prep_intercepts();
  1432. +
  1433. + for(i = 0; i < all->len; i++) {
  1434. + pkg = all->pkgs[i];
  1435. +
  1436. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1437. + continue;
  1438. +
  1439. + if (pkg->state_status == SS_UNPACKED) {
  1440. + ipkg_message(conf, IPKG_NOTICE,
  1441. + "Configuring %s\n", pkg->name);
  1442. + fflush( stdout );
  1443. + r = ipkg_configure(conf, pkg);
  1444. + if (r == 0) {
  1445. + pkg->state_status = SS_INSTALLED;
  1446. + pkg->parent->state_status = SS_INSTALLED;
  1447. + pkg->state_flag &= ~SF_PREFER;
  1448. + } else {
  1449. + if (!err)
  1450. + err = r;
  1451. + }
  1452. + }
  1453. + }
  1454. +
  1455. + r = ipkg_finalize_intercepts (ic);
  1456. + if (r && !err)
  1457. + err = r;
  1458. +
  1459. + pkg_vec_free(all);
  1460. + return err;
  1461. +}
  1462. +
  1463. +static void sigint_handler(int sig)
  1464. +{
  1465. + signal(sig, SIG_DFL);
  1466. + ipkg_message(NULL, IPKG_NOTICE,
  1467. + "ipkg: interrupted. writing out status database\n");
  1468. + write_status_files_if_changed(global_conf);
  1469. + exit(128 + sig);
  1470. +}
  1471. +
  1472. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1473. +{
  1474. + int i;
  1475. + char *arg;
  1476. + int err=0;
  1477. +
  1478. + global_conf = conf;
  1479. + signal(SIGINT, sigint_handler);
  1480. +
  1481. + /*
  1482. + * Now scan through package names and install
  1483. + */
  1484. + for (i=0; i < argc; i++) {
  1485. + arg = argv[i];
  1486. +
  1487. + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
  1488. + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
  1489. + if (err != EINVAL && err != 0)
  1490. + return err;
  1491. + }
  1492. + pkg_info_preinstall_check(conf);
  1493. +
  1494. + for (i=0; i < argc; i++) {
  1495. + arg = argv[i];
  1496. + if (conf->multiple_providers)
  1497. + err = ipkg_install_multi_by_name(conf, arg);
  1498. + else{
  1499. + err = ipkg_install_by_name(conf, arg);
  1500. + }
  1501. + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
  1502. + ipkg_message(conf, IPKG_ERROR,
  1503. + "Cannot find package %s.\n"
  1504. + "Check the spelling or perhaps run 'ipkg update'\n",
  1505. + arg);
  1506. + }
  1507. + }
  1508. +
  1509. + /* recheck to verify that all dependences are satisfied */
  1510. + if (0) ipkg_satisfy_all_dependences(conf);
  1511. +
  1512. + ipkg_configure_packages(conf, NULL);
  1513. +
  1514. + write_status_files_if_changed(conf);
  1515. +
  1516. + return err;
  1517. +}
  1518. +
  1519. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1520. +{
  1521. + int i;
  1522. + pkg_t *pkg;
  1523. + int err;
  1524. +
  1525. + global_conf = conf;
  1526. + signal(SIGINT, sigint_handler);
  1527. +
  1528. + if (argc) {
  1529. + for (i=0; i < argc; i++) {
  1530. + char *arg = argv[i];
  1531. +
  1532. + err = ipkg_prepare_url_for_install(conf, arg, &arg);
  1533. + if (err != EINVAL && err != 0)
  1534. + return err;
  1535. + }
  1536. + pkg_info_preinstall_check(conf);
  1537. +
  1538. + for (i=0; i < argc; i++) {
  1539. + char *arg = argv[i];
  1540. + if (conf->restrict_to_default_dest) {
  1541. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1542. + argv[i],
  1543. + conf->default_dest);
  1544. + if (pkg == NULL) {
  1545. + ipkg_message(conf, IPKG_NOTICE,
  1546. + "Package %s not installed in %s\n",
  1547. + argv[i], conf->default_dest->name);
  1548. + continue;
  1549. + }
  1550. + } else {
  1551. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  1552. + argv[i]);
  1553. + }
  1554. + if (pkg)
  1555. + ipkg_upgrade_pkg(conf, pkg);
  1556. + else {
  1557. + ipkg_install_by_name(conf, arg);
  1558. + }
  1559. + }
  1560. + } else {
  1561. + pkg_vec_t *installed = pkg_vec_alloc();
  1562. +
  1563. + pkg_info_preinstall_check(conf);
  1564. +
  1565. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  1566. + for (i = 0; i < installed->len; i++) {
  1567. + pkg = installed->pkgs[i];
  1568. + ipkg_upgrade_pkg(conf, pkg);
  1569. + }
  1570. + pkg_vec_free(installed);
  1571. + }
  1572. +
  1573. + /* recheck to verify that all dependences are satisfied */
  1574. + if (0) ipkg_satisfy_all_dependences(conf);
  1575. +
  1576. + ipkg_configure_packages(conf, NULL);
  1577. +
  1578. + write_status_files_if_changed(conf);
  1579. +
  1580. + return 0;
  1581. +}
  1582. +
  1583. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1584. +{
  1585. + int i, err;
  1586. + char *arg;
  1587. + pkg_t *pkg;
  1588. +
  1589. + pkg_info_preinstall_check(conf);
  1590. + for (i = 0; i < argc; i++) {
  1591. + arg = argv[i];
  1592. +
  1593. + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
  1594. + if (pkg == NULL) {
  1595. + ipkg_message(conf, IPKG_ERROR,
  1596. + "Cannot find package %s.\n"
  1597. + "Check the spelling or perhaps run 'ipkg update'\n",
  1598. + arg);
  1599. + continue;
  1600. + }
  1601. +
  1602. + err = ipkg_download_pkg(conf, pkg, ".");
  1603. +
  1604. + if (err) {
  1605. + ipkg_message(conf, IPKG_ERROR,
  1606. + "Failed to download %s\n", pkg->name);
  1607. + } else {
  1608. + ipkg_message(conf, IPKG_NOTICE,
  1609. + "Downloaded %s as %s\n",
  1610. + pkg->name, pkg->local_filename);
  1611. + }
  1612. + }
  1613. +
  1614. + return 0;
  1615. +}
  1616. +
  1617. +
  1618. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1619. +{
  1620. + int i ;
  1621. + pkg_vec_t *available;
  1622. + pkg_t *pkg;
  1623. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1624. + char *newline;
  1625. + char *pkg_name = NULL;
  1626. + char *version_str;
  1627. +
  1628. + if (argc > 0) {
  1629. + pkg_name = argv[0];
  1630. + }
  1631. + available = pkg_vec_alloc();
  1632. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1633. + for (i=0; i < available->len; i++) {
  1634. + pkg = available->pkgs[i];
  1635. + /* if we have package name or pattern and pkg does not match, then skip it */
  1636. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1637. + continue;
  1638. + if (pkg->description) {
  1639. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1640. + } else {
  1641. + desc_short[0] = '\0';
  1642. + }
  1643. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1644. + newline = strchr(desc_short, '\n');
  1645. + if (newline) {
  1646. + *newline = '\0';
  1647. + }
  1648. + if (ipkg_cb_list) {
  1649. + version_str = pkg_version_str_alloc(pkg);
  1650. + ipkg_cb_list(pkg->name,desc_short,
  1651. + version_str,
  1652. + pkg->state_status,
  1653. + p_userdata);
  1654. + free(version_str);
  1655. + }
  1656. + }
  1657. + pkg_vec_free(available);
  1658. +
  1659. + return 0;
  1660. +}
  1661. +
  1662. +
  1663. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1664. +{
  1665. + int i ;
  1666. + pkg_vec_t *available;
  1667. + pkg_t *pkg;
  1668. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1669. + char *newline;
  1670. + char *pkg_name = NULL;
  1671. + char *version_str;
  1672. +
  1673. + if (argc > 0) {
  1674. + pkg_name = argv[0];
  1675. + }
  1676. + available = pkg_vec_alloc();
  1677. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1678. + for (i=0; i < available->len; i++) {
  1679. + pkg = available->pkgs[i];
  1680. + /* if we have package name or pattern and pkg does not match, then skip it */
  1681. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1682. + continue;
  1683. + if (pkg->description) {
  1684. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1685. + } else {
  1686. + desc_short[0] = '\0';
  1687. + }
  1688. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1689. + newline = strchr(desc_short, '\n');
  1690. + if (newline) {
  1691. + *newline = '\0';
  1692. + }
  1693. + if (ipkg_cb_list) {
  1694. + version_str = pkg_version_str_alloc(pkg);
  1695. + ipkg_cb_list(pkg->name,desc_short,
  1696. + version_str,
  1697. + pkg->state_status,
  1698. + p_userdata);
  1699. + free(version_str);
  1700. + }
  1701. + }
  1702. +
  1703. + return 0;
  1704. +}
  1705. +
  1706. +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
  1707. +{
  1708. + int i;
  1709. + pkg_vec_t *available;
  1710. + pkg_t *pkg;
  1711. + char *pkg_name = NULL;
  1712. + char **pkg_fields = NULL;
  1713. + int n_fields = 0;
  1714. + char *buff ; // = (char *)malloc(1);
  1715. +
  1716. + if (argc > 0) {
  1717. + pkg_name = argv[0];
  1718. + }
  1719. + if (argc > 1) {
  1720. + pkg_fields = &argv[1];
  1721. + n_fields = argc - 1;
  1722. + }
  1723. +
  1724. + available = pkg_vec_alloc();
  1725. + if (installed_only)
  1726. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1727. + else
  1728. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1729. + for (i=0; i < available->len; i++) {
  1730. + pkg = available->pkgs[i];
  1731. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1732. + continue;
  1733. + }
  1734. + buff = pkg_formatted_info(pkg);
  1735. + if ( buff ) {
  1736. + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
  1737. + pkg->state_status,
  1738. + buff,
  1739. + p_userdata);
  1740. + free(buff);
  1741. + }
  1742. + if (conf->verbosity > 1) {
  1743. + conffile_list_elt_t *iter;
  1744. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  1745. + conffile_t *cf = iter->data;
  1746. + int modified = conffile_has_been_modified(conf, cf);
  1747. + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
  1748. + cf->name, cf->value, modified);
  1749. + }
  1750. + }
  1751. + }
  1752. + pkg_vec_free(available);
  1753. +
  1754. + return 0;
  1755. +}
  1756. +
  1757. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1758. +{
  1759. + return ipkg_info_status_cmd(conf, argc, argv, 0);
  1760. +}
  1761. +
  1762. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1763. +{
  1764. + return ipkg_info_status_cmd(conf, argc, argv, 1);
  1765. +}
  1766. +
  1767. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1768. +{
  1769. +
  1770. + int err;
  1771. + if (argc > 0) {
  1772. + char *pkg_name = NULL;
  1773. +
  1774. + pkg_name = argv[0];
  1775. +
  1776. + err = ipkg_configure_packages (conf, pkg_name);
  1777. +
  1778. + } else {
  1779. + err = ipkg_configure_packages (conf, NULL);
  1780. + }
  1781. +
  1782. + write_status_files_if_changed(conf);
  1783. +
  1784. + return err;
  1785. +}
  1786. +
  1787. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf)
  1788. +{
  1789. + int i, err;
  1790. + char *globpattern;
  1791. + glob_t globbuf;
  1792. +
  1793. + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
  1794. + err = glob(globpattern, 0, NULL, &globbuf);
  1795. + free(globpattern);
  1796. + if (err) {
  1797. + return 0;
  1798. + }
  1799. +
  1800. + ipkg_message(conf, IPKG_NOTICE,
  1801. + "The following packages in %s will now be installed.\n",
  1802. + conf->pending_dir);
  1803. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1804. + ipkg_message(conf, IPKG_NOTICE,
  1805. + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
  1806. + }
  1807. + ipkg_message(conf, IPKG_NOTICE, "\n");
  1808. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1809. + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
  1810. + if (err == 0) {
  1811. + err = unlink(globbuf.gl_pathv[i]);
  1812. + if (err) {
  1813. + ipkg_message(conf, IPKG_ERROR,
  1814. + "%s: ERROR: failed to unlink %s: %s\n",
  1815. + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
  1816. + return err;
  1817. + }
  1818. + }
  1819. + }
  1820. + globfree(&globbuf);
  1821. +
  1822. + return err;
  1823. +}
  1824. +
  1825. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1826. +{
  1827. + int i,a,done;
  1828. + pkg_t *pkg;
  1829. + pkg_t *pkg_to_remove;
  1830. + pkg_vec_t *available;
  1831. + char *pkg_name = NULL;
  1832. + global_conf = conf;
  1833. + signal(SIGINT, sigint_handler);
  1834. +
  1835. +// ENH: Add the "no pkg removed" just in case.
  1836. +
  1837. + done = 0;
  1838. +
  1839. + available = pkg_vec_alloc();
  1840. + pkg_info_preinstall_check(conf);
  1841. + if ( argc > 0 ) {
  1842. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1843. + for (i=0; i < argc; i++) {
  1844. + pkg_name = malloc(strlen(argv[i])+2);
  1845. + strcpy(pkg_name,argv[i]);
  1846. + for (a=0; a < available->len; a++) {
  1847. + pkg = available->pkgs[a];
  1848. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1849. + continue;
  1850. + }
  1851. + if (conf->restrict_to_default_dest) {
  1852. + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1853. + pkg->name,
  1854. + conf->default_dest);
  1855. + } else {
  1856. + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
  1857. + }
  1858. +
  1859. + if (pkg == NULL) {
  1860. + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
  1861. + continue;
  1862. + }
  1863. + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
  1864. + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
  1865. + continue;
  1866. + }
  1867. + ipkg_remove_pkg(conf, pkg_to_remove,0);
  1868. + done = 1;
  1869. + }
  1870. + free (pkg_name);
  1871. + }
  1872. + pkg_vec_free(available);
  1873. + } else {
  1874. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  1875. + int flagged_pkg_count = 0;
  1876. + int removed;
  1877. +
  1878. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
  1879. +
  1880. + for (i = 0; i < installed_pkgs->len; i++) {
  1881. + pkg = installed_pkgs->pkgs[i];
  1882. + if (pkg->state_flag & SF_USER) {
  1883. + flagged_pkg_count++;
  1884. + } else {
  1885. + if (!pkg_has_installed_dependents(pkg, NULL))
  1886. + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
  1887. + }
  1888. + }
  1889. + if (!flagged_pkg_count) {
  1890. + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
  1891. + "so refusing to uninstall unflagged non-leaf packages\n");
  1892. + return 0;
  1893. + }
  1894. +
  1895. + /* find packages not flagged SF_USER (i.e., installed to
  1896. + * satisfy a dependence) and not having any dependents, and
  1897. + * remove them */
  1898. + do {
  1899. + removed = 0;
  1900. + for (i = 0; i < installed_pkgs->len; i++) {
  1901. + pkg = installed_pkgs->pkgs[i];
  1902. + if (!(pkg->state_flag & SF_USER)
  1903. + && !pkg_has_installed_dependents(pkg, NULL)) {
  1904. + removed++;
  1905. + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
  1906. + ipkg_remove_pkg(conf, pkg,0);
  1907. + done = 1;
  1908. + }
  1909. + }
  1910. + } while (removed);
  1911. + pkg_vec_free(installed_pkgs);
  1912. + }
  1913. +
  1914. + if ( done == 0 )
  1915. + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
  1916. +
  1917. + write_status_files_if_changed(conf);
  1918. + return 0;
  1919. +}
  1920. +
  1921. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1922. +{
  1923. + int i;
  1924. + pkg_t *pkg;
  1925. +
  1926. + global_conf = conf;
  1927. + signal(SIGINT, sigint_handler);
  1928. +
  1929. + pkg_info_preinstall_check(conf);
  1930. +
  1931. + for (i=0; i < argc; i++) {
  1932. + if (conf->restrict_to_default_dest) {
  1933. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1934. + argv[i],
  1935. + conf->default_dest);
  1936. + } else {
  1937. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1938. + }
  1939. +
  1940. + if (pkg == NULL) {
  1941. + ipkg_message(conf, IPKG_ERROR,
  1942. + "Package %s is not installed.\n", argv[i]);
  1943. + continue;
  1944. + }
  1945. + ipkg_purge_pkg(conf, pkg);
  1946. + }
  1947. +
  1948. + write_status_files_if_changed(conf);
  1949. + return 0;
  1950. +}
  1951. +
  1952. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1953. +{
  1954. + int i;
  1955. + pkg_t *pkg;
  1956. + char *flags = argv[0];
  1957. +
  1958. + global_conf = conf;
  1959. + signal(SIGINT, sigint_handler);
  1960. +
  1961. + for (i=1; i < argc; i++) {
  1962. + if (conf->restrict_to_default_dest) {
  1963. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1964. + argv[i],
  1965. + conf->default_dest);
  1966. + } else {
  1967. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1968. + }
  1969. +
  1970. + if (pkg == NULL) {
  1971. + ipkg_message(conf, IPKG_ERROR,
  1972. + "Package %s is not installed.\n", argv[i]);
  1973. + continue;
  1974. + }
  1975. + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
  1976. + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
  1977. + pkg->state_flag = pkg_state_flag_from_str(flags);
  1978. + }
  1979. +/* pb_ asked this feature 03292004 */
  1980. +/* Actually I will use only this two, but this is an open for various status */
  1981. + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
  1982. + pkg->state_status = pkg_state_status_from_str(flags);
  1983. + }
  1984. + ipkg_state_changed++;
  1985. + ipkg_message(conf, IPKG_NOTICE,
  1986. + "Setting flags for package %s to %s\n",
  1987. + pkg->name, flags);
  1988. + }
  1989. +
  1990. + write_status_files_if_changed(conf);
  1991. + return 0;
  1992. +}
  1993. +
  1994. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1995. +{
  1996. + pkg_t *pkg;
  1997. + str_list_t *installed_files;
  1998. + str_list_elt_t *iter;
  1999. + char *pkg_version;
  2000. + size_t buff_len = 8192;
  2001. + size_t used_len;
  2002. + char *buff ;
  2003. +
  2004. + buff = (char *)malloc(buff_len);
  2005. + if ( buff == NULL ) {
  2006. + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
  2007. + return ENOMEM;
  2008. + }
  2009. +
  2010. + if (argc < 1) {
  2011. + return EINVAL;
  2012. + }
  2013. +
  2014. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  2015. + argv[0]);
  2016. + if (pkg == NULL) {
  2017. + ipkg_message(conf, IPKG_ERROR,
  2018. + "Package %s not installed.\n", argv[0]);
  2019. + return 0;
  2020. + }
  2021. +
  2022. + installed_files = pkg_get_installed_files(pkg);
  2023. + pkg_version = pkg_version_str_alloc(pkg);
  2024. +
  2025. + printf("Package %s (%s) is installed on %s and has the following files:\n",
  2026. + pkg->name, pkg_version, pkg->dest->name);
  2027. + for (iter = installed_files->head; iter; iter = iter->next) {
  2028. + puts(iter->data);
  2029. + }
  2030. +
  2031. + free(pkg_version);
  2032. + pkg_free_installed_files(pkg);
  2033. +
  2034. + return 0;
  2035. +}
  2036. +
  2037. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2038. +{
  2039. +
  2040. + if (argc > 0) {
  2041. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2042. + const char *rel_str = "depends on";
  2043. + int i;
  2044. +
  2045. + pkg_info_preinstall_check(conf);
  2046. +
  2047. + if (conf->query_all)
  2048. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2049. + else
  2050. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2051. + for (i = 0; i < argc; i++) {
  2052. + const char *target = argv[i];
  2053. + int j;
  2054. +
  2055. + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
  2056. +
  2057. + for (j = 0; j < available_pkgs->len; j++) {
  2058. + pkg_t *pkg = available_pkgs->pkgs[j];
  2059. + if (fnmatch(target, pkg->name, 0) == 0) {
  2060. + int k;
  2061. + int count = pkg->depends_count + pkg->pre_depends_count;
  2062. + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
  2063. + target, pkg->architecture, rel_str);
  2064. + for (k = 0; k < count; k++) {
  2065. + compound_depend_t *cdepend = &pkg->depends[k];
  2066. + int l;
  2067. + for (l = 0; l < cdepend->possibility_count; l++) {
  2068. + depend_t *possibility = cdepend->possibilities[l];
  2069. + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
  2070. + if (conf->verbosity > 0) {
  2071. + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
  2072. + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
  2073. + if (possibility->version) {
  2074. + const char *typestr = NULL;
  2075. + switch (possibility->constraint) {
  2076. + case NONE: typestr = "none"; break;
  2077. + case EARLIER: typestr = "<"; break;
  2078. + case EARLIER_EQUAL: typestr = "<="; break;
  2079. + case EQUAL: typestr = "="; break;
  2080. + case LATER_EQUAL: typestr = ">="; break;
  2081. + case LATER: typestr = ">"; break;
  2082. + }
  2083. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2084. + }
  2085. + // free(ver);
  2086. + }
  2087. + ipkg_message(conf, IPKG_ERROR, "\n");
  2088. + }
  2089. + }
  2090. + }
  2091. + }
  2092. + }
  2093. + pkg_vec_free(available_pkgs);
  2094. + }
  2095. + return 0;
  2096. +}
  2097. +
  2098. +enum what_field_type {
  2099. + WHATDEPENDS,
  2100. + WHATCONFLICTS,
  2101. + WHATPROVIDES,
  2102. + WHATREPLACES,
  2103. + WHATRECOMMENDS,
  2104. + WHATSUGGESTS
  2105. +};
  2106. +
  2107. +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
  2108. +{
  2109. +
  2110. + if (argc > 0) {
  2111. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2112. + const char *rel_str = NULL;
  2113. + int i;
  2114. + int changed;
  2115. +
  2116. + switch (what_field_type) {
  2117. + case WHATDEPENDS: rel_str = "depends on"; break;
  2118. + case WHATCONFLICTS: rel_str = "conflicts with"; break;
  2119. + case WHATSUGGESTS: rel_str = "suggests"; break;
  2120. + case WHATRECOMMENDS: rel_str = "recommends"; break;
  2121. + case WHATPROVIDES: rel_str = "provides"; break;
  2122. + case WHATREPLACES: rel_str = "replaces"; break;
  2123. + }
  2124. +
  2125. + if (conf->query_all)
  2126. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2127. + else
  2128. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2129. +
  2130. + /* mark the root set */
  2131. + pkg_vec_clear_marks(available_pkgs);
  2132. + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
  2133. + for (i = 0; i < argc; i++) {
  2134. + const char *dependee_pattern = argv[i];
  2135. + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
  2136. + }
  2137. + for (i = 0; i < available_pkgs->len; i++) {
  2138. + pkg_t *pkg = available_pkgs->pkgs[i];
  2139. + if (pkg->state_flag & SF_MARKED) {
  2140. + /* mark the parent (abstract) package */
  2141. + pkg_mark_provides(pkg);
  2142. + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
  2143. + }
  2144. + }
  2145. +
  2146. + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
  2147. + do {
  2148. + int j;
  2149. + changed = 0;
  2150. +
  2151. + for (j = 0; j < available_pkgs->len; j++) {
  2152. + pkg_t *pkg = available_pkgs->pkgs[j];
  2153. + int k;
  2154. + int count = ((what_field_type == WHATCONFLICTS)
  2155. + ? pkg->conflicts_count
  2156. + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
  2157. + /* skip this package if it is already marked */
  2158. + if (pkg->parent->state_flag & SF_MARKED) {
  2159. + continue;
  2160. + }
  2161. + for (k = 0; k < count; k++) {
  2162. + compound_depend_t *cdepend =
  2163. + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
  2164. + int l;
  2165. + for (l = 0; l < cdepend->possibility_count; l++) {
  2166. + depend_t *possibility = cdepend->possibilities[l];
  2167. + if (possibility->pkg->state_flag & SF_MARKED) {
  2168. + /* mark the depending package so we won't visit it again */
  2169. + pkg->state_flag |= SF_MARKED;
  2170. + pkg_mark_provides(pkg);
  2171. + changed++;
  2172. +
  2173. + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
  2174. + if (conf->verbosity > 0) {
  2175. + char *ver = pkg_version_str_alloc(pkg);
  2176. + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
  2177. + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
  2178. + if (possibility->version) {
  2179. + const char *typestr = NULL;
  2180. + switch (possibility->constraint) {
  2181. + case NONE: typestr = "none"; break;
  2182. + case EARLIER: typestr = "<"; break;
  2183. + case EARLIER_EQUAL: typestr = "<="; break;
  2184. + case EQUAL: typestr = "="; break;
  2185. + case LATER_EQUAL: typestr = ">="; break;
  2186. + case LATER: typestr = ">"; break;
  2187. + }
  2188. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2189. + }
  2190. + free(ver);
  2191. + if (!pkg_dependence_satisfiable(possibility))
  2192. + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
  2193. + }
  2194. + ipkg_message(conf, IPKG_NOTICE, "\n");
  2195. + goto next_package;
  2196. + }
  2197. + }
  2198. + }
  2199. + next_package:
  2200. + ;
  2201. + }
  2202. + } while (changed && recursive);
  2203. + pkg_vec_free(available_pkgs);
  2204. + }
  2205. +
  2206. + return 0;
  2207. +}
  2208. +
  2209. +int pkg_mark_provides(pkg_t *pkg)
  2210. +{
  2211. + int provides_count = pkg->provides_count;
  2212. + abstract_pkg_t **provides = pkg->provides;
  2213. + int i;
  2214. + pkg->parent->state_flag |= SF_MARKED;
  2215. + for (i = 0; i < provides_count; i++) {
  2216. + provides[i]->state_flag |= SF_MARKED;
  2217. + }
  2218. + return 0;
  2219. +}
  2220. +
  2221. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2222. +{
  2223. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
  2224. +}
  2225. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2226. +{
  2227. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
  2228. +}
  2229. +
  2230. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2231. +{
  2232. + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
  2233. +}
  2234. +
  2235. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2236. +{
  2237. + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
  2238. +}
  2239. +
  2240. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2241. +{
  2242. + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
  2243. +}
  2244. +
  2245. +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
  2246. +{
  2247. +
  2248. + if (argc > 0) {
  2249. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2250. + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
  2251. + int i;
  2252. +
  2253. + pkg_info_preinstall_check(conf);
  2254. +
  2255. + if (conf->query_all)
  2256. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2257. + else
  2258. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2259. + for (i = 0; i < argc; i++) {
  2260. + const char *target = argv[i];
  2261. + int j;
  2262. +
  2263. + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
  2264. + rel_str, target);
  2265. + for (j = 0; j < available_pkgs->len; j++) {
  2266. + pkg_t *pkg = available_pkgs->pkgs[j];
  2267. + int k;
  2268. + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
  2269. + for (k = 0; k < count; k++) {
  2270. + abstract_pkg_t *apkg =
  2271. + ((what_field_type == WHATPROVIDES)
  2272. + ? pkg->provides[k]
  2273. + : pkg->replaces[k]);
  2274. + if (fnmatch(target, apkg->name, 0) == 0) {
  2275. + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
  2276. + if (strcmp(target, apkg->name) != 0)
  2277. + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
  2278. + ipkg_message(conf, IPKG_ERROR, "\n");
  2279. + }
  2280. + }
  2281. + }
  2282. + }
  2283. + pkg_vec_free(available_pkgs);
  2284. + }
  2285. + return 0;
  2286. +}
  2287. +
  2288. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2289. +{
  2290. + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
  2291. +}
  2292. +
  2293. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2294. +{
  2295. + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
  2296. +}
  2297. +
  2298. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2299. +{
  2300. + int i;
  2301. +
  2302. + pkg_vec_t *installed;
  2303. + pkg_t *pkg;
  2304. + str_list_t *installed_files;
  2305. + str_list_elt_t *iter;
  2306. + char *installed_file;
  2307. +
  2308. + if (argc < 1) {
  2309. + return EINVAL;
  2310. + }
  2311. +
  2312. + installed = pkg_vec_alloc();
  2313. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  2314. +
  2315. + for (i=0; i < installed->len; i++) {
  2316. + pkg = installed->pkgs[i];
  2317. +
  2318. + installed_files = pkg_get_installed_files(pkg);
  2319. +
  2320. + for (iter = installed_files->head; iter; iter = iter->next) {
  2321. + installed_file = iter->data;
  2322. + if (fnmatch(argv[0], installed_file, 0)==0) {
  2323. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2324. + installed_file,
  2325. + pkg_version_str_alloc(pkg),
  2326. + pkg->state_status, p_userdata);
  2327. + }
  2328. + }
  2329. +
  2330. + pkg_free_installed_files(pkg);
  2331. + }
  2332. +
  2333. + /* XXX: CLEANUP: It's not obvious from the name of
  2334. + pkg_hash_fetch_all_installed that we need to call
  2335. + pkg_vec_free to avoid a memory leak. */
  2336. + pkg_vec_free(installed);
  2337. +
  2338. + return 0;
  2339. +}
  2340. +
  2341. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2342. +{
  2343. + if (argc == 3) {
  2344. + /* this is a bit gross */
  2345. + struct pkg p1, p2;
  2346. + parseVersion(&p1, argv[0]);
  2347. + parseVersion(&p2, argv[2]);
  2348. + return pkg_version_satisfied(&p1, &p2, argv[1]);
  2349. + } else {
  2350. + ipkg_message(conf, IPKG_ERROR,
  2351. + "ipkg compare_versions <v1> <op> <v2>\n"
  2352. + "<op> is one of <= >= << >> =\n");
  2353. + return -1;
  2354. + }
  2355. +}
  2356. +
  2357. +#ifndef HOST_CPU_STR
  2358. +#define HOST_CPU_STR__(X) #X
  2359. +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
  2360. +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
  2361. +#endif
  2362. +
  2363. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf)
  2364. +{
  2365. + nv_pair_list_elt_t *l;
  2366. +
  2367. + l = conf->arch_list.head;
  2368. + while (l) {
  2369. + nv_pair_t *nv = l->data;
  2370. + printf("arch %s %s\n", nv->name, nv->value);
  2371. + l = l->next;
  2372. + }
  2373. + return 0;
  2374. +}
  2375. +
  2376. +
  2377. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_cmd.h busybox-1.16.1/archival/libipkg/ipkg_cmd.h
  2378. --- busybox-1.16.1.orig/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
  2379. +++ busybox-1.16.1/archival/libipkg/ipkg_cmd.h 2010-06-29 17:31:22.398358961 +0200
  2380. @@ -0,0 +1,41 @@
  2381. +/* ipkg_cmd.h - the itsy package management system
  2382. +
  2383. + Carl D. Worth
  2384. +
  2385. + Copyright (C) 2001 University of Southern California
  2386. +
  2387. + This program is free software; you can redistribute it and/or
  2388. + modify it under the terms of the GNU General Public License as
  2389. + published by the Free Software Foundation; either version 2, or (at
  2390. + your option) any later version.
  2391. +
  2392. + This program is distributed in the hope that it will be useful, but
  2393. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2394. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2395. + General Public License for more details.
  2396. +*/
  2397. +
  2398. +#ifndef IPKG_CMD_H
  2399. +#define IPKG_CMD_H
  2400. +
  2401. +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
  2402. +
  2403. +struct ipkg_cmd
  2404. +{
  2405. + const char *name;
  2406. + int requires_args;
  2407. + ipkg_cmd_fun_t fun;
  2408. +};
  2409. +typedef struct ipkg_cmd ipkg_cmd_t;
  2410. +
  2411. +ipkg_cmd_t *ipkg_cmd_find(const char *name);
  2412. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
  2413. + const char **argv, void *userdata);
  2414. +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
  2415. +/* install any packges with state_want == SW_INSTALL */
  2416. +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
  2417. +/* ensure that all dependences are satisfied */
  2418. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
  2419. +int pkg_mark_provides(pkg_t *pkg);
  2420. +
  2421. +#endif
  2422. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_conf.c busybox-1.16.1/archival/libipkg/ipkg_conf.c
  2423. --- busybox-1.16.1.orig/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
  2424. +++ busybox-1.16.1/archival/libipkg/ipkg_conf.c 2010-06-29 17:31:22.425857952 +0200
  2425. @@ -0,0 +1,711 @@
  2426. +/* ipkg_conf.c - the itsy package management system
  2427. +
  2428. + Carl D. Worth
  2429. +
  2430. + Copyright (C) 2001 University of Southern California
  2431. +
  2432. + This program is free software; you can redistribute it and/or
  2433. + modify it under the terms of the GNU General Public License as
  2434. + published by the Free Software Foundation; either version 2, or (at
  2435. + your option) any later version.
  2436. +
  2437. + This program is distributed in the hope that it will be useful, but
  2438. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2439. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2440. + General Public License for more details.
  2441. +*/
  2442. +
  2443. +#include <glob.h>
  2444. +
  2445. +#include "ipkg.h"
  2446. +#include "ipkg_conf.h"
  2447. +
  2448. +#include "xregex.h"
  2449. +#include "sprintf_alloc.h"
  2450. +#include "ipkg_conf.h"
  2451. +#include "ipkg_message.h"
  2452. +#include "file_util.h"
  2453. +#include "str_util.h"
  2454. +#include "xsystem.h"
  2455. +
  2456. +
  2457. +ipkg_conf_t *global_conf;
  2458. +
  2459. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2460. + pkg_src_list_t *pkg_src_list,
  2461. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2462. + char **tmp_lists_dir);
  2463. +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
  2464. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  2465. + const char *name, const char *value);
  2466. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2467. + const char *default_dest_name);
  2468. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
  2469. + pkg_src_list_t *nv_pair_list);
  2470. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
  2471. + nv_pair_list_t *nv_pair_list, char * lists_dir);
  2472. +
  2473. +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
  2474. +{
  2475. + ipkg_option_t tmp[] = {
  2476. + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
  2477. + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
  2478. + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
  2479. + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
  2480. + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
  2481. + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
  2482. + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
  2483. + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
  2484. + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
  2485. + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
  2486. + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
  2487. + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
  2488. + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
  2489. + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
  2490. + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
  2491. + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
  2492. + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
  2493. + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
  2494. + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
  2495. + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
  2496. + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
  2497. + { NULL }
  2498. + };
  2499. +
  2500. + *options = (ipkg_option_t *)malloc(sizeof(tmp));
  2501. + if ( options == NULL ){
  2502. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  2503. + return -1;
  2504. + }
  2505. +
  2506. + memcpy(*options, tmp, sizeof(tmp));
  2507. + return 0;
  2508. +};
  2509. +
  2510. +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
  2511. +{
  2512. + if (arg_str) {
  2513. + if (*conf_str) {
  2514. + free(*conf_str);
  2515. + }
  2516. + *conf_str = strdup(arg_str);
  2517. + }
  2518. +}
  2519. +
  2520. +static void ipkg_conf_free_string(char **conf_str)
  2521. +{
  2522. + if (*conf_str) {
  2523. + free(*conf_str);
  2524. + *conf_str = NULL;
  2525. + }
  2526. +}
  2527. +
  2528. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
  2529. +{
  2530. + int err;
  2531. + char *tmp_dir_base;
  2532. + nv_pair_list_t tmp_dest_nv_pair_list;
  2533. + char * lists_dir =NULL;
  2534. + glob_t globbuf;
  2535. + const char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
  2536. + char *pending_dir =NULL;
  2537. +
  2538. + memset(conf, 0, sizeof(ipkg_conf_t));
  2539. +
  2540. + pkg_src_list_init(&conf->pkg_src_list);
  2541. +
  2542. + nv_pair_list_init(&tmp_dest_nv_pair_list);
  2543. + pkg_dest_list_init(&conf->pkg_dest_list);
  2544. +
  2545. + nv_pair_list_init(&conf->arch_list);
  2546. +
  2547. + conf->restrict_to_default_dest = 0;
  2548. + conf->default_dest = NULL;
  2549. +
  2550. +
  2551. + if (args->tmp_dir)
  2552. + tmp_dir_base = args->tmp_dir;
  2553. + else
  2554. + tmp_dir_base = getenv("TMPDIR");
  2555. + sprintf_alloc(&conf->tmp_dir, "%s/%s",
  2556. + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
  2557. + IPKG_CONF_TMP_DIR_SUFFIX);
  2558. + conf->tmp_dir = mkdtemp(conf->tmp_dir);
  2559. + if (conf->tmp_dir == NULL) {
  2560. + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
  2561. + __FUNCTION__, conf->tmp_dir, strerror(errno));
  2562. + return errno;
  2563. + }
  2564. +
  2565. + conf->force_depends = 0;
  2566. + conf->force_defaults = 0;
  2567. + conf->force_overwrite = 0;
  2568. + conf->force_downgrade = 0;
  2569. + conf->force_reinstall = 0;
  2570. + conf->force_space = 0;
  2571. + conf->force_removal_of_essential_packages = 0;
  2572. + conf->force_removal_of_dependent_packages = 0;
  2573. + conf->nodeps = 0;
  2574. + conf->verbose_wget = 0;
  2575. + conf->offline_root = NULL;
  2576. + conf->offline_root_pre_script_cmd = NULL;
  2577. + conf->offline_root_post_script_cmd = NULL;
  2578. + conf->multiple_providers = 0;
  2579. + conf->verbosity = 1;
  2580. + conf->noaction = 0;
  2581. +
  2582. + conf->http_proxy = NULL;
  2583. + conf->ftp_proxy = NULL;
  2584. + conf->no_proxy = NULL;
  2585. + conf->proxy_user = NULL;
  2586. + conf->proxy_passwd = NULL;
  2587. +
  2588. + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2589. + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2590. + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2591. + lists_dir=(char *)malloc(1);
  2592. + lists_dir[0]='\0';
  2593. + if (args->conf_file) {
  2594. + struct stat stat_buf;
  2595. + err = stat(args->conf_file, &stat_buf);
  2596. + if (err == 0)
  2597. + if (ipkg_conf_parse_file(conf, args->conf_file,
  2598. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2599. + /* Memory leakage from ipkg_conf_parse-file */
  2600. + return -1;
  2601. + }
  2602. +
  2603. + }
  2604. +
  2605. + /* if (!lists_dir ){*/
  2606. + if (strlen(lists_dir)<=1 ){
  2607. + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
  2608. + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
  2609. + }
  2610. +
  2611. + if (args->offline_root) {
  2612. + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
  2613. + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
  2614. + free(lists_dir);
  2615. + lists_dir = tmp;
  2616. + }
  2617. +
  2618. + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
  2619. + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
  2620. +
  2621. + conf->lists_dir = strdup(lists_dir);
  2622. + conf->pending_dir = strdup(pending_dir);
  2623. +
  2624. + if (args->offline_root)
  2625. + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
  2626. + memset(&globbuf, 0, sizeof(globbuf));
  2627. + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
  2628. + if (!err) {
  2629. + int i;
  2630. + for (i = 0; i < globbuf.gl_pathc; i++) {
  2631. + if (globbuf.gl_pathv[i])
  2632. + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
  2633. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2634. + /* Memory leakage from ipkg_conf_parse-file */
  2635. + return -1;
  2636. + }
  2637. + }
  2638. + }
  2639. + globfree(&globbuf);
  2640. +
  2641. + /* if no architectures were defined, then default all, noarch, and host architecture */
  2642. + if (nv_pair_list_empty(&conf->arch_list)) {
  2643. + nv_pair_list_append(&conf->arch_list, "all", "1");
  2644. + nv_pair_list_append(&conf->arch_list, "noarch", "1");
  2645. + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
  2646. + }
  2647. +
  2648. + /* Even if there is no conf file, we'll need at least one dest. */
  2649. + if (tmp_dest_nv_pair_list.head == NULL) {
  2650. + nv_pair_list_append(&tmp_dest_nv_pair_list,
  2651. + IPKG_CONF_DEFAULT_DEST_NAME,
  2652. + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
  2653. + }
  2654. +
  2655. + /* After parsing the file, set options from command-line, (so that
  2656. + command-line arguments take precedence) */
  2657. + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
  2658. + really needs to be cleaned up. There is so much duplication
  2659. + right now it is ridiculous. Maybe ipkg_conf_t should just save
  2660. + a pointer to args_t (which could then not be freed), rather
  2661. + than duplicating every field here? */
  2662. + if (args->force_depends) {
  2663. + conf->force_depends = 1;
  2664. + }
  2665. + if (args->force_defaults) {
  2666. + conf->force_defaults = 1;
  2667. + }
  2668. + if (args->force_overwrite) {
  2669. + conf->force_overwrite = 1;
  2670. + }
  2671. + if (args->force_downgrade) {
  2672. + conf->force_downgrade = 1;
  2673. + }
  2674. + if (args->force_reinstall) {
  2675. + conf->force_reinstall = 1;
  2676. + }
  2677. + if (args->force_removal_of_dependent_packages) {
  2678. + conf->force_removal_of_dependent_packages = 1;
  2679. + }
  2680. + if (args->force_removal_of_essential_packages) {
  2681. + conf->force_removal_of_essential_packages = 1;
  2682. + }
  2683. + if (args->nodeps) {
  2684. + conf->nodeps = 1;
  2685. + }
  2686. + if (args->noaction) {
  2687. + conf->noaction = 1;
  2688. + }
  2689. + if (args->query_all) {
  2690. + conf->query_all = 1;
  2691. + }
  2692. + if (args->verbose_wget) {
  2693. + conf->verbose_wget = 1;
  2694. + }
  2695. + if (args->multiple_providers) {
  2696. + conf->multiple_providers = 1;
  2697. + }
  2698. + if (args->verbosity != conf->verbosity) {
  2699. + conf->verbosity = args->verbosity;
  2700. + }
  2701. +
  2702. + ipkg_conf_override_string(&conf->offline_root,
  2703. + args->offline_root);
  2704. + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
  2705. + args->offline_root_pre_script_cmd);
  2706. + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
  2707. + args->offline_root_post_script_cmd);
  2708. +
  2709. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  2710. + read anything from there.
  2711. +*/
  2712. + if ( !(args->nocheckfordirorfile)){
  2713. + /* need to run load the source list before dest list -Jamey */
  2714. + if ( !(args->noreadfeedsfile))
  2715. + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
  2716. +
  2717. + /* Now that we have resolved conf->offline_root, we can commit to
  2718. + the directory names for the dests and load in all the package
  2719. + lists. */
  2720. + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
  2721. +
  2722. + if (args->dest) {
  2723. + err = ipkg_conf_set_default_dest(conf, args->dest);
  2724. + if (err) {
  2725. + return err;
  2726. + }
  2727. + }
  2728. + }
  2729. + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
  2730. + free(lists_dir);
  2731. + free(pending_dir);
  2732. +
  2733. + return 0;
  2734. +}
  2735. +
  2736. +void ipkg_conf_deinit(ipkg_conf_t *conf)
  2737. +{
  2738. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  2739. +#error
  2740. + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
  2741. + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  2742. + __FUNCTION__, conf->tmp_dir);
  2743. +#else
  2744. + int err;
  2745. +
  2746. + err = rmdir(conf->tmp_dir);
  2747. + if (err) {
  2748. + if (errno == ENOTEMPTY) {
  2749. + char *cmd;
  2750. + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
  2751. + err = xsystem(cmd);
  2752. + free(cmd);
  2753. + }
  2754. + if (err)
  2755. + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
  2756. + }
  2757. +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
  2758. +
  2759. + free(conf->tmp_dir); /*XXX*/
  2760. +
  2761. + pkg_src_list_deinit(&conf->pkg_src_list);
  2762. + pkg_dest_list_deinit(&conf->pkg_dest_list);
  2763. + nv_pair_list_deinit(&conf->arch_list);
  2764. + if (&conf->pkg_hash)
  2765. + pkg_hash_deinit(&conf->pkg_hash);
  2766. + if (&conf->file_hash)
  2767. + hash_table_deinit(&conf->file_hash);
  2768. + if (&conf->obs_file_hash)
  2769. + hash_table_deinit(&conf->obs_file_hash);
  2770. +
  2771. + ipkg_conf_free_string(&conf->offline_root);
  2772. + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
  2773. + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
  2774. +
  2775. + if (conf->verbosity > 1) {
  2776. + int i;
  2777. + hash_table_t *hashes[] = {
  2778. + &conf->pkg_hash,
  2779. + &conf->file_hash,
  2780. + &conf->obs_file_hash };
  2781. + for (i = 0; i < 3; i++) {
  2782. + hash_table_t *hash = hashes[i];
  2783. + int c = 0;
  2784. + int n_conflicts = 0;
  2785. + int j;
  2786. + for (j = 0; j < hash->n_entries; j++) {
  2787. + int len = 0;
  2788. + hash_entry_t *e = &hash->entries[j];
  2789. + if (e->next)
  2790. + n_conflicts++;
  2791. + while (e && e->key) {
  2792. + len++;
  2793. + e = e->next;
  2794. + }
  2795. + if (len > c)
  2796. + c = len;
  2797. + }
  2798. + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
  2799. + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
  2800. + hash_table_deinit(hash);
  2801. + }
  2802. + }
  2803. +}
  2804. +
  2805. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2806. + const char *default_dest_name)
  2807. +{
  2808. + pkg_dest_list_elt_t *iter;
  2809. + pkg_dest_t *dest;
  2810. +
  2811. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  2812. + dest = iter->data;
  2813. + if (strcmp(dest->name, default_dest_name) == 0) {
  2814. + conf->default_dest = dest;
  2815. + conf->restrict_to_default_dest = 1;
  2816. + return 0;
  2817. + }
  2818. + }
  2819. +
  2820. + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
  2821. +
  2822. + return 1;
  2823. +}
  2824. +
  2825. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
  2826. +{
  2827. + pkg_src_list_elt_t *iter;
  2828. + pkg_src_t *src;
  2829. + char *list_file;
  2830. +
  2831. + for (iter = pkg_src_list->head; iter; iter = iter->next) {
  2832. + src = iter->data;
  2833. + if (src == NULL) {
  2834. + continue;
  2835. + }
  2836. +
  2837. + sprintf_alloc(&list_file, "%s/%s",
  2838. + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
  2839. + src->name);
  2840. +
  2841. + if (file_exists(list_file)) {
  2842. + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
  2843. + }
  2844. + free(list_file);
  2845. + }
  2846. +
  2847. + return 0;
  2848. +}
  2849. +
  2850. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
  2851. +{
  2852. + nv_pair_list_elt_t *iter;
  2853. + nv_pair_t *nv_pair;
  2854. + pkg_dest_t *dest;
  2855. + char *root_dir;
  2856. +
  2857. + for (iter = nv_pair_list->head; iter; iter = iter->next) {
  2858. + nv_pair = iter->data;
  2859. +
  2860. + if (conf->offline_root) {
  2861. + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
  2862. + } else {
  2863. + root_dir = strdup(nv_pair->value);
  2864. + }
  2865. + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
  2866. + free(root_dir);
  2867. + if (dest == NULL) {
  2868. + continue;
  2869. + }
  2870. + if (conf->default_dest == NULL) {
  2871. + conf->default_dest = dest;
  2872. + }
  2873. + if (file_exists(dest->status_file_name)) {
  2874. + pkg_hash_add_from_file(conf, dest->status_file_name,
  2875. + NULL, dest, 1);
  2876. + }
  2877. + }
  2878. +
  2879. + return 0;
  2880. +}
  2881. +
  2882. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2883. + pkg_src_list_t *pkg_src_list,
  2884. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2885. + char **lists_dir)
  2886. +{
  2887. + ipkg_option_t * options;
  2888. + FILE *file = fopen(filename, "r");
  2889. + regex_t valid_line_re, comment_re;
  2890. +#define regmatch_size 12
  2891. + regmatch_t regmatch[regmatch_size];
  2892. +
  2893. + if (ipkg_init_options_array(conf, &options)<0)
  2894. + return ENOMEM;
  2895. +
  2896. + if (file == NULL) {
  2897. + fprintf(stderr, "%s: failed to open %s: %s\n",
  2898. + __FUNCTION__, filename, strerror(errno));
  2899. + free(options);
  2900. + return errno;
  2901. + }
  2902. + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
  2903. +
  2904. + xregcomp(&comment_re,
  2905. + "^[[:space:]]*(#.*|[[:space:]]*)$",
  2906. + REG_EXTENDED);
  2907. + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
  2908. +
  2909. + while(1) {
  2910. + int line_num = 0;
  2911. + char *line;
  2912. + char *type, *name, *value, *extra;
  2913. +
  2914. + line = file_read_line_alloc(file);
  2915. + line_num++;
  2916. + if (line == NULL) {
  2917. + break;
  2918. + }
  2919. +
  2920. + str_chomp(line);
  2921. +
  2922. + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
  2923. + goto NEXT_LINE;
  2924. + }
  2925. +
  2926. + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
  2927. + str_chomp(line);
  2928. + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
  2929. + filename, line_num, line);
  2930. + goto NEXT_LINE;
  2931. + }
  2932. +
  2933. + /* This has to be so ugly to deal with optional quotation marks */
  2934. + if (regmatch[2].rm_so > 0) {
  2935. + type = strndup(line + regmatch[2].rm_so,
  2936. + regmatch[2].rm_eo - regmatch[2].rm_so);
  2937. + } else {
  2938. + type = strndup(line + regmatch[3].rm_so,
  2939. + regmatch[3].rm_eo - regmatch[3].rm_so);
  2940. + }
  2941. + if (regmatch[5].rm_so > 0) {
  2942. + name = strndup(line + regmatch[5].rm_so,
  2943. + regmatch[5].rm_eo - regmatch[5].rm_so);
  2944. + } else {
  2945. + name = strndup(line + regmatch[6].rm_so,
  2946. + regmatch[6].rm_eo - regmatch[6].rm_so);
  2947. + }
  2948. + if (regmatch[8].rm_so > 0) {
  2949. + value = strndup(line + regmatch[8].rm_so,
  2950. + regmatch[8].rm_eo - regmatch[8].rm_so);
  2951. + } else {
  2952. + value = strndup(line + regmatch[9].rm_so,
  2953. + regmatch[9].rm_eo - regmatch[9].rm_so);
  2954. + }
  2955. + extra = NULL;
  2956. + if (regmatch[11].rm_so > 0) {
  2957. + extra = strndup (line + regmatch[11].rm_so,
  2958. + regmatch[11].rm_eo - regmatch[11].rm_so);
  2959. + }
  2960. +
  2961. + /* We use the tmp_dest_nv_pair_list below instead of
  2962. + conf->pkg_dest_list because we might encounter an
  2963. + offline_root option later and that would invalidate the
  2964. + directories we would have computed in
  2965. + pkg_dest_list_init. (We do a similar thing with
  2966. + tmp_src_nv_pair_list for sake of symmetry.) */
  2967. + if (strcmp(type, "option") == 0) {
  2968. + ipkg_conf_set_option(options, name, value);
  2969. + } else if (strcmp(type, "src") == 0) {
  2970. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  2971. + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
  2972. + } else {
  2973. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  2974. + name, value);
  2975. + }
  2976. + } else if (strcmp(type, "src/gz") == 0) {
  2977. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  2978. + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
  2979. + } else {
  2980. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  2981. + name, value);
  2982. + }
  2983. + } else if (strcmp(type, "dest") == 0) {
  2984. + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
  2985. + } else if (strcmp(type, "lists_dir") == 0) {
  2986. + *lists_dir = realloc(*lists_dir,strlen(value)+1);
  2987. + if (*lists_dir == NULL) {
  2988. + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
  2989. + free(options);
  2990. + return EINVAL;
  2991. + }
  2992. + sprintf (*lists_dir,"%s",value);
  2993. + } else if (strcmp(type, "arch") == 0) {
  2994. + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
  2995. + if (!value) {
  2996. + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
  2997. + value = strdup("10");
  2998. + }
  2999. + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
  3000. + } else {
  3001. + fprintf(stderr, "WARNING: Ignoring unknown configuration "
  3002. + "parameter: %s %s %s\n", type, name, value);
  3003. + free(options);
  3004. + return EINVAL;
  3005. + }
  3006. +
  3007. + free(type);
  3008. + free(name);
  3009. + free(value);
  3010. + if (extra)
  3011. + free (extra);
  3012. +
  3013. + NEXT_LINE:
  3014. + free(line);
  3015. + }
  3016. +
  3017. + free(options);
  3018. + regfree(&comment_re);
  3019. + regfree(&valid_line_re);
  3020. + fclose(file);
  3021. +
  3022. + return 0;
  3023. +}
  3024. +
  3025. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  3026. + const char *name, const char *value)
  3027. +{
  3028. + int i = 0;
  3029. + while (options[i].name) {
  3030. + if (strcmp(options[i].name, name) == 0) {
  3031. + switch (options[i].type) {
  3032. + case IPKG_OPT_TYPE_BOOL:
  3033. + *((int *)options[i].value) = 1;
  3034. + return 0;
  3035. + case IPKG_OPT_TYPE_INT:
  3036. + if (value) {
  3037. + *((int *)options[i].value) = atoi(value);
  3038. + return 0;
  3039. + } else {
  3040. + printf("%s: Option %s need an argument\n",
  3041. + __FUNCTION__, name);
  3042. + return EINVAL;
  3043. + }
  3044. + case IPKG_OPT_TYPE_STRING:
  3045. + if (value) {
  3046. + *((char **)options[i].value) = strdup(value);
  3047. + return 0;
  3048. + } else {
  3049. + printf("%s: Option %s need an argument\n",
  3050. + __FUNCTION__, name);
  3051. + return EINVAL;
  3052. + }
  3053. + }
  3054. + }
  3055. + i++;
  3056. + }
  3057. +
  3058. + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
  3059. + __FUNCTION__, name, value);
  3060. + return EINVAL;
  3061. +}
  3062. +
  3063. +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
  3064. +{
  3065. + pkg_dest_list_elt_t *iter;
  3066. + pkg_dest_t *dest;
  3067. + pkg_vec_t *all;
  3068. + pkg_t *pkg;
  3069. + register int i;
  3070. + int err;
  3071. +
  3072. + if (conf->noaction)
  3073. + return 0;
  3074. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3075. + dest = iter->data;
  3076. + dest->status_file = fopen(dest->status_file_tmp_name, "w");
  3077. + if (dest->status_file == NULL) {
  3078. + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
  3079. + __FUNCTION__, dest->status_file_name, strerror(errno));
  3080. + }
  3081. + }
  3082. +
  3083. + all = pkg_vec_alloc();
  3084. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  3085. +
  3086. + for(i = 0; i < all->len; i++) {
  3087. + pkg = all->pkgs[i];
  3088. + /* We don't need most uninstalled packages in the status file */
  3089. + if (pkg->state_status == SS_NOT_INSTALLED
  3090. + && (pkg->state_want == SW_UNKNOWN
  3091. + || pkg->state_want == SW_DEINSTALL
  3092. + || pkg->state_want == SW_PURGE)) {
  3093. + continue;
  3094. + }
  3095. + if (!pkg) {
  3096. + fprintf(stderr, "Null package\n");
  3097. + }
  3098. + if (pkg->dest == NULL) {
  3099. + fprintf(stderr, "%s: ERROR: Can't write status for "
  3100. + "package %s since it has a NULL dest\n",
  3101. + __FUNCTION__, pkg->name);
  3102. + continue;
  3103. + }
  3104. + if (pkg->dest->status_file) {
  3105. + pkg_print_status(pkg, pkg->dest->status_file);
  3106. + }
  3107. + }
  3108. +
  3109. + pkg_vec_free(all);
  3110. +
  3111. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3112. + dest = iter->data;
  3113. + if (dest->status_file) {
  3114. + err = ferror(dest->status_file);
  3115. + fclose(dest->status_file);
  3116. + dest->status_file = NULL;
  3117. + if (!err) {
  3118. + file_move(dest->status_file_tmp_name, dest->status_file_name);
  3119. + } else {
  3120. + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
  3121. + "retaining old %s\n", __FUNCTION__,
  3122. + dest->status_file_tmp_name, dest->status_file_name);
  3123. + }
  3124. + }
  3125. + }
  3126. +
  3127. + return 0;
  3128. +}
  3129. +
  3130. +
  3131. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
  3132. +{
  3133. + char *root_filename;
  3134. + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
  3135. + return root_filename;
  3136. +}
  3137. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_conf.h busybox-1.16.1/archival/libipkg/ipkg_conf.h
  3138. --- busybox-1.16.1.orig/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
  3139. +++ busybox-1.16.1/archival/libipkg/ipkg_conf.h 2010-06-29 17:31:22.458368131 +0200
  3140. @@ -0,0 +1,107 @@
  3141. +/* ipkg_conf.h - the itsy package management system
  3142. +
  3143. + Carl D. Worth
  3144. +
  3145. + Copyright (C) 2001 University of Southern California
  3146. +
  3147. + This program is free software; you can redistribute it and/or
  3148. + modify it under the terms of the GNU General Public License as
  3149. + published by the Free Software Foundation; either version 2, or (at
  3150. + your option) any later version.
  3151. +
  3152. + This program is distributed in the hope that it will be useful, but
  3153. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3154. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3155. + General Public License for more details.
  3156. +*/
  3157. +
  3158. +#ifndef IPKG_CONF_H
  3159. +#define IPKG_CONF_H
  3160. +
  3161. +typedef struct ipkg_conf ipkg_conf_t;
  3162. +
  3163. +#include "hash_table.h"
  3164. +#include "ipkg.h"
  3165. +#include "args.h"
  3166. +#include "pkg.h"
  3167. +#include "pkg_hash.h"
  3168. +#include "pkg_src_list.h"
  3169. +#include "pkg_dest_list.h"
  3170. +#include "nv_pair_list.h"
  3171. +
  3172. +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
  3173. +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
  3174. +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
  3175. +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
  3176. +
  3177. +/* In case the config file defines no dest */
  3178. +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
  3179. +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
  3180. +
  3181. +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
  3182. +
  3183. +struct ipkg_conf
  3184. +{
  3185. + pkg_src_list_t pkg_src_list;
  3186. + pkg_dest_list_t pkg_dest_list;
  3187. + nv_pair_list_t arch_list;
  3188. +
  3189. + int restrict_to_default_dest;
  3190. + pkg_dest_t *default_dest;
  3191. +
  3192. + char *tmp_dir;
  3193. + char *lists_dir;
  3194. + char *pending_dir;
  3195. +
  3196. + /* options */
  3197. + int force_depends;
  3198. + int force_defaults;
  3199. + int force_overwrite;
  3200. + int force_downgrade;
  3201. + int force_reinstall;
  3202. + int force_space;
  3203. + int force_removal_of_dependent_packages;
  3204. + int force_removal_of_essential_packages;
  3205. + int nodeps; /* do not follow dependences */
  3206. + int verbose_wget;
  3207. + int multiple_providers;
  3208. + char *offline_root;
  3209. + char *offline_root_pre_script_cmd;
  3210. + char *offline_root_post_script_cmd;
  3211. + int query_all;
  3212. + int verbosity;
  3213. + int noaction;
  3214. +
  3215. + /* proxy options */
  3216. + char *http_proxy;
  3217. + char *ftp_proxy;
  3218. + char *no_proxy;
  3219. + char *proxy_user;
  3220. + char *proxy_passwd;
  3221. +
  3222. + hash_table_t pkg_hash;
  3223. + hash_table_t file_hash;
  3224. + hash_table_t obs_file_hash;
  3225. +};
  3226. +
  3227. +enum ipkg_option_type {
  3228. + IPKG_OPT_TYPE_BOOL,
  3229. + IPKG_OPT_TYPE_INT,
  3230. + IPKG_OPT_TYPE_STRING
  3231. +};
  3232. +typedef enum ipkg_option_type ipkg_option_type_t;
  3233. +
  3234. +typedef struct ipkg_option ipkg_option_t;
  3235. +struct ipkg_option {
  3236. + const char *name;
  3237. + const ipkg_option_type_t type;
  3238. + const void *value;
  3239. +};
  3240. +
  3241. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
  3242. +void ipkg_conf_deinit(ipkg_conf_t *conf);
  3243. +
  3244. +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
  3245. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
  3246. +
  3247. +#endif
  3248. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_configure.c busybox-1.16.1/archival/libipkg/ipkg_configure.c
  3249. --- busybox-1.16.1.orig/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
  3250. +++ busybox-1.16.1/archival/libipkg/ipkg_configure.c 2010-06-29 17:31:22.488368061 +0200
  3251. @@ -0,0 +1,40 @@
  3252. +/* ipkg_configure.c - the itsy package management system
  3253. +
  3254. + Carl D. Worth
  3255. +
  3256. + Copyright (C) 2001 University of Southern California
  3257. +
  3258. + This program is free software; you can redistribute it and/or
  3259. + modify it under the terms of the GNU General Public License as
  3260. + published by the Free Software Foundation; either version 2, or (at
  3261. + your option) any later version.
  3262. +
  3263. + This program is distributed in the hope that it will be useful, but
  3264. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3265. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3266. + General Public License for more details.
  3267. +*/
  3268. +
  3269. +#include "ipkg.h"
  3270. +
  3271. +#include "ipkg_configure.h"
  3272. +
  3273. +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
  3274. +{
  3275. + int err;
  3276. +
  3277. + /* DPKG_INCOMPATIBILITY:
  3278. + dpkg actually does some conffile handling here, rather than at the
  3279. + end of ipkg_install(). Do we care? */
  3280. + /* DPKG_INCOMPATIBILITY:
  3281. + dpkg actually includes a version number to this script call */
  3282. + err = pkg_run_script(conf, pkg, "postinst", "configure");
  3283. + if (err) {
  3284. + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
  3285. + return err;
  3286. + }
  3287. +
  3288. + ipkg_state_changed++;
  3289. + return 0;
  3290. +}
  3291. +
  3292. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_configure.h busybox-1.16.1/archival/libipkg/ipkg_configure.h
  3293. --- busybox-1.16.1.orig/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
  3294. +++ busybox-1.16.1/archival/libipkg/ipkg_configure.h 2010-06-29 17:31:22.527882534 +0200
  3295. @@ -0,0 +1,25 @@
  3296. +/* ipkg_configure.h - the itsy package management system
  3297. +
  3298. + Carl D. Worth
  3299. +
  3300. + Copyright (C) 2001 University of Southern California
  3301. +
  3302. + This program is free software; you can redistribute it and/or
  3303. + modify it under the terms of the GNU General Public License as
  3304. + published by the Free Software Foundation; either version 2, or (at
  3305. + your option) any later version.
  3306. +
  3307. + This program is distributed in the hope that it will be useful, but
  3308. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3309. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3310. + General Public License for more details.
  3311. +*/
  3312. +
  3313. +#ifndef IPKG_CONFIGURE_H
  3314. +#define IPKG_CONFIGURE_H
  3315. +
  3316. +#include "ipkg_conf.h"
  3317. +
  3318. +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
  3319. +
  3320. +#endif
  3321. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_download.c busybox-1.16.1/archival/libipkg/ipkg_download.c
  3322. --- busybox-1.16.1.orig/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
  3323. +++ busybox-1.16.1/archival/libipkg/ipkg_download.c 2010-06-29 17:31:22.569385415 +0200
  3324. @@ -0,0 +1,195 @@
  3325. +/* ipkg_download.c - the itsy package management system
  3326. +
  3327. + Carl D. Worth
  3328. +
  3329. + Copyright (C) 2001 University of Southern California
  3330. +
  3331. + This program is free software; you can redistribute it and/or
  3332. + modify it under the terms of the GNU General Public License as
  3333. + published by the Free Software Foundation; either version 2, or (at
  3334. + your option) any later version.
  3335. +
  3336. + This program is distributed in the hope that it will be useful, but
  3337. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3338. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3339. + General Public License for more details.
  3340. +*/
  3341. +
  3342. +#include "ipkg.h"
  3343. +#include "ipkg_download.h"
  3344. +#include "ipkg_message.h"
  3345. +
  3346. +#include "sprintf_alloc.h"
  3347. +#include "xsystem.h"
  3348. +#include "file_util.h"
  3349. +#include "str_util.h"
  3350. +
  3351. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
  3352. +{
  3353. + int err = 0;
  3354. +
  3355. + char *src_basec = strdup(src);
  3356. + char *src_base = basename(src_basec);
  3357. + char *tmp_file_location;
  3358. + char *cmd;
  3359. +
  3360. + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
  3361. +
  3362. + fflush(stdout);
  3363. +
  3364. + if (str_starts_with(src, "file:")) {
  3365. + int ret;
  3366. + const char *file_src = src + 5;
  3367. + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
  3368. + ret = file_copy(src + 5, dest_file_name);
  3369. + ipkg_message(conf,IPKG_INFO,"Done.\n");
  3370. + return ret;
  3371. + }
  3372. +
  3373. + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
  3374. + err = unlink(tmp_file_location);
  3375. + if (err && errno != ENOENT) {
  3376. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
  3377. + __FUNCTION__, tmp_file_location, strerror(errno));
  3378. + free(tmp_file_location);
  3379. + return errno;
  3380. + }
  3381. +
  3382. + if (conf->http_proxy) {
  3383. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
  3384. + setenv("http_proxy", conf->http_proxy, 1);
  3385. + }
  3386. + if (conf->ftp_proxy) {
  3387. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
  3388. + setenv("ftp_proxy", conf->ftp_proxy, 1);
  3389. + }
  3390. + if (conf->no_proxy) {
  3391. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
  3392. + setenv("no_proxy", conf->no_proxy, 1);
  3393. + }
  3394. +
  3395. + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
  3396. + sprintf_alloc(&cmd, "wget %s %s%s %s%s %s -P %s %s",
  3397. + (conf->http_proxy || conf->ftp_proxy) ? "-Y on" : "",
  3398. + conf->proxy_user ? "--proxy-user=" : "",
  3399. + conf->proxy_user ? conf->proxy_user : "",
  3400. + conf->proxy_passwd ? "--proxy-passwd=" : "",
  3401. + conf->proxy_passwd ? conf->proxy_passwd : "",
  3402. + conf->verbose_wget ? "" : "-q",
  3403. + conf->tmp_dir,
  3404. + src);
  3405. + err = xsystem(cmd);
  3406. + if (err) {
  3407. + if (err != -1) {
  3408. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
  3409. + __FUNCTION__, err, cmd);
  3410. + }
  3411. + unlink(tmp_file_location);
  3412. + free(tmp_file_location);
  3413. + free(src_basec);
  3414. + free(cmd);
  3415. + return EINVAL;
  3416. + }
  3417. + free(cmd);
  3418. +
  3419. + err = file_move(tmp_file_location, dest_file_name);
  3420. +
  3421. + free(tmp_file_location);
  3422. + free(src_basec);
  3423. +
  3424. + if (err) {
  3425. + return err;
  3426. + }
  3427. +
  3428. + return 0;
  3429. +}
  3430. +
  3431. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
  3432. +{
  3433. + int err;
  3434. + char *url;
  3435. +
  3436. + if (pkg->src == NULL) {
  3437. + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
  3438. + pkg->name, pkg->parent->name);
  3439. + return -1;
  3440. + }
  3441. +
  3442. + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
  3443. +
  3444. + /* XXX: BUG: The pkg->filename might be something like
  3445. + "../../foo.ipk". While this is correct, and exactly what we
  3446. + want to use to construct url above, here we actually need to
  3447. + use just the filename part, without any directory. */
  3448. + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
  3449. +
  3450. + err = ipkg_download(conf, url, pkg->local_filename);
  3451. + free(url);
  3452. +
  3453. + return err;
  3454. +}
  3455. +
  3456. +/*
  3457. + * Downloads file from url, installs in package database, return package name.
  3458. + */
  3459. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
  3460. +{
  3461. + int err = 0;
  3462. + pkg_t *pkg;
  3463. + pkg = pkg_new();
  3464. + if (pkg == NULL)
  3465. + return ENOMEM;
  3466. +
  3467. + if (str_starts_with(url, "http://")
  3468. + || str_starts_with(url, "ftp://")) {
  3469. + char *tmp_file;
  3470. + char *file_basec = strdup(url);
  3471. + char *file_base = basename(file_basec);
  3472. +
  3473. + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
  3474. + err = ipkg_download(conf, url, tmp_file);
  3475. + if (err)
  3476. + return err;
  3477. +
  3478. + err = pkg_init_from_file(pkg, tmp_file);
  3479. + if (err)
  3480. + return err;
  3481. + pkg->local_filename = strdup(tmp_file);
  3482. +
  3483. + free(tmp_file);
  3484. + free(file_basec);
  3485. +
  3486. + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
  3487. + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
  3488. +
  3489. + err = pkg_init_from_file(pkg, url);
  3490. + if (err)
  3491. + return err;
  3492. + pkg->local_filename = strdup(url);
  3493. + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
  3494. + pkg->provided_by_hand = 1;
  3495. +
  3496. + } else {
  3497. + pkg_deinit(pkg);
  3498. + free(pkg);
  3499. + return 0;
  3500. + }
  3501. +
  3502. + if (!pkg->architecture) {
  3503. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3504. + return -EINVAL;
  3505. + }
  3506. +
  3507. + pkg->dest = conf->default_dest;
  3508. + pkg->state_want = SW_INSTALL;
  3509. + pkg->state_flag |= SF_PREFER;
  3510. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3511. + if ( pkg == NULL ){
  3512. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  3513. + return 0;
  3514. + }
  3515. + if (namep) {
  3516. + *namep = strdup(pkg->name);
  3517. + }
  3518. + return 0;
  3519. +}
  3520. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_download.h busybox-1.16.1/archival/libipkg/ipkg_download.h
  3521. --- busybox-1.16.1.orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
  3522. +++ busybox-1.16.1/archival/libipkg/ipkg_download.h 2010-06-29 17:31:22.608368046 +0200
  3523. @@ -0,0 +1,30 @@
  3524. +/* ipkg_download.h - the itsy package management system
  3525. +
  3526. + Carl D. Worth
  3527. +
  3528. + Copyright (C) 2001 University of Southern California
  3529. +
  3530. + This program is free software; you can redistribute it and/or
  3531. + modify it under the terms of the GNU General Public License as
  3532. + published by the Free Software Foundation; either version 2, or (at
  3533. + your option) any later version.
  3534. +
  3535. + This program is distributed in the hope that it will be useful, but
  3536. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3537. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3538. + General Public License for more details.
  3539. +*/
  3540. +
  3541. +#ifndef IPKG_DOWNLOAD_H
  3542. +#define IPKG_DOWNLOAD_H
  3543. +
  3544. +#include "ipkg_conf.h"
  3545. +
  3546. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
  3547. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
  3548. +/*
  3549. + * Downloads file from url, installs in package database, return package name.
  3550. + */
  3551. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
  3552. +
  3553. +#endif
  3554. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg.h busybox-1.16.1/archival/libipkg/ipkg.h
  3555. --- busybox-1.16.1.orig/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
  3556. +++ busybox-1.16.1/archival/libipkg/ipkg.h 2010-06-29 17:31:22.647281522 +0200
  3557. @@ -0,0 +1,68 @@
  3558. +/* ipkg.h - the itsy package management system
  3559. +
  3560. + Carl D. Worth
  3561. +
  3562. + Copyright (C) 2001 University of Southern California
  3563. +
  3564. + This program is free software; you can redistribute it and/or
  3565. + modify it under the terms of the GNU General Public License as
  3566. + published by the Free Software Foundation; either version 2, or (at
  3567. + your option) any later version.
  3568. +
  3569. + This program is distributed in the hope that it will be useful, but
  3570. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3571. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3572. + General Public License for more details.
  3573. +*/
  3574. +
  3575. +#ifndef IPKG_H
  3576. +#define IPKG_H
  3577. +
  3578. +#include "libbb.h"
  3579. +
  3580. +#include "ipkg_includes.h"
  3581. +#include "ipkg_conf.h"
  3582. +#include "ipkg_message.h"
  3583. +
  3584. +#define IPKG_PKG_EXTENSION ".ipk"
  3585. +#define DPKG_PKG_EXTENSION ".deb"
  3586. +
  3587. +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
  3588. +#define IPKG_PKG_VERSION_SEP_CHAR '_'
  3589. +
  3590. +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
  3591. +#define IPKG_LISTS_DIR_SUFFIX "lists"
  3592. +#define IPKG_INFO_DIR_SUFFIX "info"
  3593. +#define IPKG_STATUS_FILE_SUFFIX "status"
  3594. +
  3595. +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
  3596. +
  3597. +#define IPKG_LIST_DESCRIPTION_LENGTH 128
  3598. +
  3599. +#define IPKG_VERSION "1.00"
  3600. +
  3601. +
  3602. +enum ipkg_error {
  3603. + IPKG_SUCCESS = 0,
  3604. + IPKG_PKG_DEPS_UNSATISFIED,
  3605. + IPKG_PKG_IS_ESSENTIAL,
  3606. + IPKG_PKG_HAS_DEPENDENTS,
  3607. + IPKG_PKG_HAS_NO_CANDIDATE
  3608. +};
  3609. +typedef enum ipkg_error ipkg_error_t;
  3610. +
  3611. +extern int ipkg_state_changed;
  3612. +
  3613. +
  3614. +struct errlist {
  3615. + char * errmsg;
  3616. + struct errlist * next;
  3617. +} ;
  3618. +
  3619. +extern struct errlist* error_list;
  3620. +
  3621. +extern ipkg_conf_t *global_conf;
  3622. +
  3623. +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
  3624. +
  3625. +#endif
  3626. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_includes.h busybox-1.16.1/archival/libipkg/ipkg_includes.h
  3627. --- busybox-1.16.1.orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
  3628. +++ busybox-1.16.1/archival/libipkg/ipkg_includes.h 2010-06-29 17:32:10.339618090 +0200
  3629. @@ -0,0 +1,81 @@
  3630. +#ifndef IPKG_INCLUDES_H
  3631. +#define IPKG_INCLUDES_H
  3632. +
  3633. +/* Define to 1 if you have the <memory.h> header file. */
  3634. +#define HAVE_MEMORY_H 1
  3635. +
  3636. +/* Define to 1 if you have the <regex.h> header file. */
  3637. +#define HAVE_REGEX_H 1
  3638. +
  3639. +/* Define to 1 if you have the <stdlib.h> header file. */
  3640. +#define HAVE_STDLIB_H 1
  3641. +
  3642. +/* Define to 1 if you have the <strings.h> header file. */
  3643. +#define HAVE_STRINGS_H 1
  3644. +
  3645. +/* Define to 1 if you have the <string.h> header file. */
  3646. +#define HAVE_STRING_H 1
  3647. +
  3648. +/* Define to 1 if you have the <sys/stat.h> header file. */
  3649. +#define HAVE_SYS_STAT_H 1
  3650. +
  3651. +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
  3652. +#define HAVE_SYS_WAIT_H 1
  3653. +
  3654. +/* Define to 1 if you have the <unistd.h> header file. */
  3655. +#define HAVE_UNISTD_H 1
  3656. +
  3657. +/* Define to 1 if you have the ANSI C header files. */
  3658. +#define STDC_HEADERS 1
  3659. +
  3660. +
  3661. +#include <stdio.h>
  3662. +
  3663. +#if STDC_HEADERS
  3664. +# include <stdlib.h>
  3665. +# include <stdarg.h>
  3666. +# include <stddef.h>
  3667. +# include <ctype.h>
  3668. +# include <errno.h>
  3669. +#else
  3670. +# if HAVE_STDLIB_H
  3671. +# include <stdlib.h>
  3672. +# endif
  3673. +#endif
  3674. +
  3675. +#if HAVE_REGEX_H
  3676. +# include <regex.h>
  3677. +#endif
  3678. +
  3679. +#if HAVE_STRING_H
  3680. +# if !STDC_HEADERS && HAVE_MEMORY_H
  3681. +# include <memory.h>
  3682. +# endif
  3683. +/* XXX: What's the right way to pick up GNU's strndup declaration? */
  3684. +# if __GNUC__
  3685. +# define __USE_GNU 1
  3686. +# endif
  3687. +# include <string.h>
  3688. +# undef __USE_GNU
  3689. +#endif
  3690. +
  3691. +#if HAVE_STRINGS_H
  3692. +# include <strings.h>
  3693. +#endif
  3694. +
  3695. +#if HAVE_SYS_STAT_H
  3696. +# include <sys/stat.h>
  3697. +#endif
  3698. +
  3699. +#if HAVE_SYS_WAIT_H
  3700. +# include <sys/wait.h>
  3701. +#endif
  3702. +
  3703. +#if HAVE_UNISTD_H
  3704. +# include <sys/types.h>
  3705. +# include <unistd.h>
  3706. +#endif
  3707. +
  3708. +#include <sys/mount.h>
  3709. +
  3710. +#endif /* IPKG_INCLUDES_H */
  3711. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_install.c busybox-1.16.1/archival/libipkg/ipkg_install.c
  3712. --- busybox-1.16.1.orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
  3713. +++ busybox-1.16.1/archival/libipkg/ipkg_install.c 2010-06-29 17:31:22.727172508 +0200
  3714. @@ -0,0 +1,1982 @@
  3715. +/* ipkg_install.c - the itsy package management system
  3716. +
  3717. + Carl D. Worth
  3718. +
  3719. + Copyright (C) 2001 University of Southern California
  3720. +
  3721. + This program is free software; you can redistribute it and/or
  3722. + modify it under the terms of the GNU General Public License as
  3723. + published by the Free Software Foundation; either version 2, or (at
  3724. + your option) any later version.
  3725. +
  3726. + This program is distributed in the hope that it will be useful, but
  3727. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3728. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3729. + General Public License for more details.
  3730. +*/
  3731. +
  3732. +#include "ipkg.h"
  3733. +#include <errno.h>
  3734. +#include <dirent.h>
  3735. +#include <glob.h>
  3736. +#include <time.h>
  3737. +#include <signal.h>
  3738. +typedef void (*sighandler_t)(int);
  3739. +
  3740. +#include "pkg.h"
  3741. +#include "pkg_hash.h"
  3742. +#include "pkg_extract.h"
  3743. +
  3744. +#include "ipkg_install.h"
  3745. +#include "ipkg_configure.h"
  3746. +#include "ipkg_download.h"
  3747. +#include "ipkg_remove.h"
  3748. +
  3749. +#include "ipkg_utils.h"
  3750. +#include "ipkg_message.h"
  3751. +
  3752. +#include "sprintf_alloc.h"
  3753. +#include "file_util.h"
  3754. +#include "str_util.h"
  3755. +#include "xsystem.h"
  3756. +#include "user.h"
  3757. +
  3758. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  3759. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
  3760. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
  3761. +
  3762. +/*
  3763. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3764. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3765. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3766. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3767. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3768. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3769. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3770. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
  3771. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3772. +*/
  3773. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3774. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3775. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg);
  3776. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3777. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg);
  3778. +
  3779. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3780. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3781. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
  3782. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
  3783. +
  3784. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
  3785. +
  3786. +static int user_prefers_old_conffile(const char *file, const char *backup);
  3787. +
  3788. +static char *backup_filename_alloc(const char *file_name);
  3789. +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
  3790. +static int backup_exists_for(const char *file_name);
  3791. +static int backup_remove(const char *file_name);
  3792. +
  3793. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees);
  3794. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3795. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3796. +
  3797. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
  3798. +{
  3799. + int err, cmp;
  3800. + pkg_t *pkg, *old;
  3801. + char *old_version, *new_version;
  3802. +
  3803. + pkg = pkg_new();
  3804. + if (pkg == NULL) {
  3805. + return ENOMEM;
  3806. + }
  3807. +
  3808. + err = pkg_init_from_file(pkg, filename);
  3809. + if (err) {
  3810. + return err;
  3811. + }
  3812. +
  3813. + if (!pkg->architecture) {
  3814. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3815. + return -EINVAL;
  3816. + }
  3817. +
  3818. + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
  3819. + freeing the pkg that we pass in. It might be nice to clean this up
  3820. + if possible. */
  3821. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3822. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  3823. +
  3824. + pkg->local_filename = strdup(filename);
  3825. +
  3826. + if (old) {
  3827. + old_version = pkg_version_str_alloc(old);
  3828. + new_version = pkg_version_str_alloc(pkg);
  3829. +
  3830. + cmp = pkg_compare_versions(old, pkg);
  3831. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3832. + cmp = -1 ; /* then we force ipkg to downgrade */
  3833. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3834. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3835. + }
  3836. + if (cmp > 0) {
  3837. + ipkg_message(conf, IPKG_NOTICE,
  3838. + "Not downgrading package %s on %s from %s to %s.\n",
  3839. + old->name, old->dest->name, old_version, new_version);
  3840. + pkg->state_want = SW_DEINSTALL;
  3841. + pkg->state_flag |= SF_OBSOLETE;
  3842. + free(old_version);
  3843. + free(new_version);
  3844. + return 0;
  3845. + } else {
  3846. + free(old_version);
  3847. + free(new_version);
  3848. + }
  3849. + }
  3850. +
  3851. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3852. + return ipkg_install_pkg(conf, pkg,0);
  3853. +}
  3854. +
  3855. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3856. +{
  3857. + int cmp;
  3858. + pkg_t *old, *new;
  3859. + char *old_version, *new_version;
  3860. +
  3861. + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
  3862. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  3863. + if ( old )
  3864. + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
  3865. +
  3866. + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
  3867. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  3868. + if ( new )
  3869. + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
  3870. +
  3871. +/* Pigi Basically here is broken the version stuff.
  3872. + What's happening is that nothing provide the version to differents
  3873. + functions, so the returned struct is always the latest.
  3874. + That's why the install by name don't work.
  3875. +*/
  3876. + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
  3877. +
  3878. + if ( old )
  3879. + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
  3880. + if ( new )
  3881. + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
  3882. + ipkg_message(conf, IPKG_DEBUG2, " \n");
  3883. +
  3884. + if (new == NULL) {
  3885. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3886. + }
  3887. +
  3888. + new->state_flag |= SF_USER;
  3889. + if (old) {
  3890. + old_version = pkg_version_str_alloc(old);
  3891. + new_version = pkg_version_str_alloc(new);
  3892. +
  3893. + cmp = pkg_compare_versions(old, new);
  3894. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3895. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
  3896. + cmp = -1 ; /* then we force ipkg to downgrade */
  3897. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3898. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3899. + }
  3900. + ipkg_message(conf, IPKG_DEBUG,
  3901. + "Comparing visible versions of pkg %s:"
  3902. + "\n\t%s is installed "
  3903. + "\n\t%s is available "
  3904. + "\n\t%d was comparison result\n",
  3905. + pkg_name, old_version, new_version, cmp);
  3906. + if (cmp == 0 && !conf->force_reinstall) {
  3907. + ipkg_message(conf, IPKG_NOTICE,
  3908. + "Package %s (%s) installed in %s is up to date.\n",
  3909. + old->name, old_version, old->dest->name);
  3910. + free(old_version);
  3911. + free(new_version);
  3912. + return 0;
  3913. + } else if (cmp > 0) {
  3914. + ipkg_message(conf, IPKG_NOTICE,
  3915. + "Not downgrading package %s on %s from %s to %s.\n",
  3916. + old->name, old->dest->name, old_version, new_version);
  3917. + free(old_version);
  3918. + free(new_version);
  3919. + return 0;
  3920. + } else if (cmp < 0) {
  3921. + new->dest = old->dest;
  3922. + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
  3923. + }
  3924. + }
  3925. +
  3926. + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
  3927. + supposed to be an ipkg_error_t, but ipkg_install_pkg could
  3928. + return any kind of integer, (might be errno from a syscall,
  3929. + etc.). This is a real mess and will need to be cleaned up if
  3930. + anyone ever wants to make a nice libipkg. */
  3931. +
  3932. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3933. + return ipkg_install_pkg(conf, new,0);
  3934. +}
  3935. +
  3936. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3937. +{
  3938. + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
  3939. + int i;
  3940. + ipkg_error_t err;
  3941. + abstract_pkg_t *ppkg ;
  3942. +
  3943. + if (providers == NULL)
  3944. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3945. +
  3946. + for (i = 0; i < providers->len; i++) {
  3947. + ppkg = abstract_pkg_vec_get(providers, i);
  3948. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
  3949. + err = ipkg_install_by_name(conf, ppkg->name);
  3950. + if (err)
  3951. + return err;
  3952. +/* XXX Maybe ppkg should be freed ? */
  3953. + }
  3954. + return 0;
  3955. +}
  3956. +
  3957. +/*
  3958. + * Walk dependence graph starting with pkg, collect packages to be
  3959. + * installed into pkgs_needed, in dependence order.
  3960. + */
  3961. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
  3962. +{
  3963. + int i, err;
  3964. + pkg_vec_t *depends = pkg_vec_alloc();
  3965. + char **unresolved = NULL;
  3966. + int ndepends;
  3967. +
  3968. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  3969. + pkg, depends,
  3970. + &unresolved);
  3971. +
  3972. + if (unresolved) {
  3973. + ipkg_message(conf, IPKG_ERROR,
  3974. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  3975. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  3976. + while (*unresolved) {
  3977. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  3978. + unresolved++;
  3979. + }
  3980. + ipkg_message(conf, IPKG_ERROR, "\n");
  3981. + if (! conf->force_depends) {
  3982. + ipkg_message(conf, IPKG_INFO,
  3983. + "This could mean that your package list is out of date or that the packages\n"
  3984. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  3985. + "of this problem try again with the '-force-depends' option.\n");
  3986. + pkg_vec_free(depends);
  3987. + return IPKG_PKG_DEPS_UNSATISFIED;
  3988. + }
  3989. + }
  3990. +
  3991. + if (ndepends <= 0) {
  3992. + pkg_vec_free(depends);
  3993. + return 0;
  3994. + }
  3995. +
  3996. + for (i = 0; i < depends->len; i++) {
  3997. + pkg_t *dep = depends->pkgs[i];
  3998. + /* The package was uninstalled when we started, but another
  3999. + dep earlier in this loop may have depended on it and pulled
  4000. + it in, so check first. */
  4001. + if ((dep->state_status != SS_INSTALLED)
  4002. + && (dep->state_status != SS_UNPACKED)
  4003. + && (dep->state_want != SW_INSTALL)) {
  4004. +
  4005. + /* Mark packages as to-be-installed */
  4006. + dep->state_want = SW_INSTALL;
  4007. +
  4008. + /* Dependencies should be installed the same place as pkg */
  4009. + if (dep->dest == NULL) {
  4010. + dep->dest = pkg->dest;
  4011. + }
  4012. +
  4013. + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
  4014. + if (err) {
  4015. + pkg_vec_free(depends);
  4016. + return err;
  4017. + }
  4018. + }
  4019. + }
  4020. + if (pkgs_needed)
  4021. + pkg_vec_insert(pkgs_needed, pkg);
  4022. +
  4023. + pkg_vec_free(depends);
  4024. +
  4025. + return 0;
  4026. +}
  4027. +
  4028. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
  4029. +{
  4030. + int cmp;
  4031. + pkg_t *old, *new;
  4032. + char *old_version, *new_version;
  4033. +
  4034. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  4035. +
  4036. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  4037. + if (new == NULL) {
  4038. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4039. + }
  4040. + if (old) {
  4041. + old_version = pkg_version_str_alloc(old);
  4042. + new_version = pkg_version_str_alloc(new);
  4043. +
  4044. + cmp = pkg_compare_versions(old, new);
  4045. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4046. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
  4047. + cmp = -1 ; /* then we force ipkg to downgrade */
  4048. + /* We need to use a value < 0 because in the 0 case we are asking to */
  4049. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4050. + }
  4051. + ipkg_message(conf, IPKG_DEBUG,
  4052. + "comparing visible versions of pkg %s:"
  4053. + "\n\t%s is installed "
  4054. + "\n\t%s is available "
  4055. + "\n\t%d was comparison result\n",
  4056. + pkg_name, old_version, new_version, cmp);
  4057. + if (cmp == 0 && !conf->force_reinstall) {
  4058. + ipkg_message(conf, IPKG_NOTICE,
  4059. + "Package %s (%s) installed in %s is up to date.\n",
  4060. + old->name, old_version, old->dest->name);
  4061. + free(old_version);
  4062. + free(new_version);
  4063. + return 0;
  4064. + } else if (cmp > 0) {
  4065. + ipkg_message(conf, IPKG_NOTICE,
  4066. + "Not downgrading package %s on %s from %s to %s.\n",
  4067. + old->name, old->dest->name, old_version, new_version);
  4068. + free(old_version);
  4069. + free(new_version);
  4070. + return 0;
  4071. + } else if (cmp < 0) {
  4072. + new->dest = old->dest;
  4073. + old->state_want = SW_DEINSTALL;
  4074. + old->state_flag |= SF_OBSOLETE;
  4075. + }
  4076. + }
  4077. + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
  4078. +}
  4079. +
  4080. +
  4081. +
  4082. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
  4083. +{
  4084. + int i, err;
  4085. + pkg_vec_t *depends = pkg_vec_alloc();
  4086. + pkg_t *dep;
  4087. + char **unresolved = NULL;
  4088. + int ndepends;
  4089. +
  4090. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4091. + pkg, depends,
  4092. + &unresolved);
  4093. +
  4094. + if (unresolved) {
  4095. + ipkg_message(conf, IPKG_ERROR,
  4096. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4097. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4098. + while (*unresolved) {
  4099. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4100. + unresolved++;
  4101. + }
  4102. + ipkg_message(conf, IPKG_ERROR, "\n");
  4103. + if (! conf->force_depends) {
  4104. + ipkg_message(conf, IPKG_INFO,
  4105. + "This could mean that your package list is out of date or that the packages\n"
  4106. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4107. + "of this problem try again with the '-force-depends' option.\n");
  4108. + pkg_vec_free(depends);
  4109. + return IPKG_PKG_DEPS_UNSATISFIED;
  4110. + }
  4111. + }
  4112. +
  4113. + if (ndepends <= 0) {
  4114. + return 0;
  4115. + }
  4116. +
  4117. + /* Mark packages as to-be-installed */
  4118. + for (i=0; i < depends->len; i++) {
  4119. + /* Dependencies should be installed the same place as pkg */
  4120. + if (depends->pkgs[i]->dest == NULL) {
  4121. + depends->pkgs[i]->dest = pkg->dest;
  4122. + }
  4123. + depends->pkgs[i]->state_want = SW_INSTALL;
  4124. + }
  4125. +
  4126. + for (i = 0; i < depends->len; i++) {
  4127. + dep = depends->pkgs[i];
  4128. + /* The package was uninstalled when we started, but another
  4129. + dep earlier in this loop may have depended on it and pulled
  4130. + it in, so check first. */
  4131. + if ((dep->state_status != SS_INSTALLED)
  4132. + && (dep->state_status != SS_UNPACKED)) {
  4133. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4134. + err = ipkg_install_pkg(conf, dep,0);
  4135. + if (err) {
  4136. + pkg_vec_free(depends);
  4137. + return err;
  4138. + }
  4139. + }
  4140. + }
  4141. +
  4142. + pkg_vec_free(depends);
  4143. +
  4144. + return 0;
  4145. +}
  4146. +
  4147. +
  4148. +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
  4149. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
  4150. +{
  4151. + if (conf->nodeps == 0) {
  4152. + int i;
  4153. + pkg_vec_t *installed = pkg_vec_alloc();
  4154. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  4155. + for (i = 0; i < installed->len; i++) {
  4156. + pkg_t *pkg = installed->pkgs[i];
  4157. + satisfy_dependencies_for(conf, pkg);
  4158. + }
  4159. + pkg_vec_free(installed);
  4160. + }
  4161. + return 0;
  4162. +}
  4163. +
  4164. +
  4165. +
  4166. +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
  4167. +{
  4168. + int i;
  4169. + pkg_vec_t *conflicts = NULL;
  4170. + int level;
  4171. + const char *prefix;
  4172. + if (conf->force_depends) {
  4173. + level = IPKG_NOTICE;
  4174. + prefix = "Warning";
  4175. + } else {
  4176. + level = IPKG_ERROR;
  4177. + prefix = "ERROR";
  4178. + }
  4179. +
  4180. + if (!conf->force_depends)
  4181. + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(pkg);
  4182. +
  4183. + if (conflicts) {
  4184. + ipkg_message(conf, level,
  4185. + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
  4186. + i = 0;
  4187. + while (i < conflicts->len)
  4188. + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
  4189. + ipkg_message(conf, level, "\n");
  4190. + pkg_vec_free(conflicts);
  4191. + return IPKG_PKG_DEPS_UNSATISFIED;
  4192. + }
  4193. + return 0;
  4194. +}
  4195. +
  4196. +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
  4197. +{
  4198. + str_list_t *new_list = pkg_get_installed_files(new_pkg);
  4199. + str_list_elt_t *iter;
  4200. +
  4201. + for (iter = new_list->head; iter; iter = iter->next) {
  4202. + char *new_file = iter->data;
  4203. + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
  4204. + if (!new_file)
  4205. + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
  4206. + if (!owner || (owner == old_pkg))
  4207. + file_hash_set_file_owner(conf, new_file, new_pkg);
  4208. + }
  4209. + if (old_pkg) {
  4210. + str_list_t *old_list = pkg_get_installed_files(old_pkg);
  4211. + for (iter = old_list->head; iter; iter = iter->next) {
  4212. + char *old_file = iter->data;
  4213. + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
  4214. + if (owner == old_pkg) {
  4215. + /* obsolete */
  4216. + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
  4217. + }
  4218. + }
  4219. + }
  4220. + return 0;
  4221. +}
  4222. +
  4223. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
  4224. +{
  4225. + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
  4226. +
  4227. + /* sma 6.20.02: yup; here's the first bit */
  4228. + /*
  4229. + * XXX: BUG easy for cworth
  4230. + * 1) please point the call below to the correct current root destination
  4231. + * 2) we need to resolve how to check the required space for a pending pkg,
  4232. + * my diddling with the .ipk file size below isn't going to cut it.
  4233. + * 3) return a proper error code instead of 1
  4234. + */
  4235. + int comp_size, blocks_available;
  4236. +
  4237. + if (!conf->force_space && pkg->installed_size != NULL) {
  4238. + blocks_available = get_available_blocks(conf->default_dest->root_dir);
  4239. +
  4240. + comp_size = strtoul(pkg->installed_size, NULL, 0);
  4241. + /* round up a blocks count without doing fancy-but-slow casting jazz */
  4242. + comp_size = (int)((comp_size + 1023) / 1024);
  4243. +
  4244. + if (comp_size >= blocks_available) {
  4245. + ipkg_message(conf, IPKG_ERROR,
  4246. + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
  4247. + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
  4248. + return ENOSPC;
  4249. + }
  4250. + }
  4251. + return 0;
  4252. +}
  4253. +
  4254. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
  4255. +{
  4256. + int err;
  4257. + char *conffiles_file_name;
  4258. + char *root_dir;
  4259. + FILE *conffiles_file;
  4260. +
  4261. + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
  4262. +
  4263. + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
  4264. + if (pkg->tmp_unpack_dir == NULL) {
  4265. + ipkg_message(conf, IPKG_ERROR,
  4266. + "%s: Failed to create temporary directory '%s': %s\n",
  4267. + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
  4268. + return errno;
  4269. + }
  4270. +
  4271. + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
  4272. + if (err) {
  4273. + return err;
  4274. + }
  4275. +
  4276. + /* XXX: CLEANUP: There might be a cleaner place to read in the
  4277. + conffiles. Seems like I should be able to get everything to go
  4278. + through pkg_init_from_file. If so, maybe it would make sense to
  4279. + move all of unpack_pkg_control_files to that function. */
  4280. +
  4281. + /* Don't need to re-read conffiles if we already have it */
  4282. + if (pkg->conffiles.head) {
  4283. + return 0;
  4284. + }
  4285. +
  4286. + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
  4287. + if (! file_exists(conffiles_file_name)) {
  4288. + free(conffiles_file_name);
  4289. + return 0;
  4290. + }
  4291. +
  4292. + conffiles_file = fopen(conffiles_file_name, "r");
  4293. + if (conffiles_file == NULL) {
  4294. + fprintf(stderr, "%s: failed to open %s: %s\n",
  4295. + __FUNCTION__, conffiles_file_name, strerror(errno));
  4296. + free(conffiles_file_name);
  4297. + return errno;
  4298. + }
  4299. + free(conffiles_file_name);
  4300. +
  4301. + while (1) {
  4302. + char *cf_name;
  4303. + char *cf_name_in_dest;
  4304. +
  4305. + cf_name = file_read_line_alloc(conffiles_file);
  4306. + if (cf_name == NULL) {
  4307. + break;
  4308. + }
  4309. + str_chomp(cf_name);
  4310. + if (cf_name[0] == '\0') {
  4311. + continue;
  4312. + }
  4313. +
  4314. + /* Prepend dest->root_dir to conffile name.
  4315. + Take pains to avoid multiple slashes. */
  4316. + root_dir = pkg->dest->root_dir;
  4317. + if (conf->offline_root)
  4318. + /* skip the offline_root prefix */
  4319. + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
  4320. + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
  4321. + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
  4322. +
  4323. + /* Can't get an md5sum now, (file isn't extracted yet).
  4324. + We'll wait until resolve_conffiles */
  4325. + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
  4326. +
  4327. + free(cf_name);
  4328. + free(cf_name_in_dest);
  4329. + }
  4330. +
  4331. + fclose(conffiles_file);
  4332. +
  4333. + return 0;
  4334. +}
  4335. +
  4336. +/* returns number of installed replacees */
  4337. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees)
  4338. +{
  4339. + abstract_pkg_t **replaces = pkg->replaces;
  4340. + int replaces_count = pkg->replaces_count;
  4341. + int i, j;
  4342. + for (i = 0; i < replaces_count; i++) {
  4343. + abstract_pkg_t *ab_pkg = replaces[i];
  4344. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  4345. + if (pkg_vec) {
  4346. + for (j = 0; j < pkg_vec->len; j++) {
  4347. + pkg_t *replacee = pkg_vec->pkgs[j];
  4348. + if (!pkg_conflicts(pkg, replacee))
  4349. + continue;
  4350. + if (replacee->state_status == SS_INSTALLED) {
  4351. + pkg_vec_insert(installed_replacees, replacee);
  4352. + }
  4353. + }
  4354. + }
  4355. + }
  4356. + return installed_replacees->len;
  4357. +}
  4358. +
  4359. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4360. +{
  4361. + int i;
  4362. + int replaces_count = replacees->len;
  4363. + for (i = 0; i < replaces_count; i++) {
  4364. + pkg_t *replacee = replacees->pkgs[i];
  4365. + int err;
  4366. + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
  4367. + err = ipkg_remove_pkg(conf, replacee,0);
  4368. + if (err)
  4369. + return err;
  4370. + }
  4371. + return 0;
  4372. +}
  4373. +
  4374. +/* to unwind the removal: make sure they are installed */
  4375. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4376. +{
  4377. + int i, err;
  4378. + int replaces_count = replacees->len;
  4379. + for (i = 0; i < replaces_count; i++) {
  4380. + pkg_t *replacee = replacees->pkgs[i];
  4381. + if (replacee->state_status != SS_INSTALLED) {
  4382. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4383. + err = ipkg_install_pkg(conf, replacee,0);
  4384. + if (err)
  4385. + return err;
  4386. + }
  4387. + }
  4388. + return 0;
  4389. +}
  4390. +
  4391. +int caught_sigint = 0;
  4392. +static void ipkg_install_pkg_sigint_handler(int sig)
  4393. +{
  4394. + caught_sigint = sig;
  4395. +}
  4396. +
  4397. +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
  4398. +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
  4399. +{
  4400. + if (old_pkg) {
  4401. + char message_out[15];
  4402. + char *old_version = pkg_version_str_alloc(old_pkg);
  4403. + char *new_version = pkg_version_str_alloc(pkg);
  4404. + int cmp = pkg_compare_versions(old_pkg, pkg);
  4405. + int rc = 0;
  4406. +
  4407. + memset(message_out,'\x0',15);
  4408. + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
  4409. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4410. + cmp = -1 ; /* then we force ipkg to downgrade */
  4411. + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
  4412. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4413. + }
  4414. +
  4415. + if (cmp > 0) {
  4416. + ipkg_message(conf, IPKG_NOTICE,
  4417. + "Not downgrading package %s on %s from %s to %s.\n",
  4418. + old_pkg->name, old_pkg->dest->name, old_version, new_version);
  4419. + rc = 1;
  4420. + } else if (cmp < 0) {
  4421. + ipkg_message(conf, IPKG_NOTICE,
  4422. + "%s%s on %s from %s to %s...\n",
  4423. + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
  4424. + pkg->dest = old_pkg->dest;
  4425. + rc = 0;
  4426. + } else /* cmp == 0 */ {
  4427. + if (conf->force_reinstall) {
  4428. + ipkg_message(conf, IPKG_NOTICE,
  4429. + "Reinstalling %s (%s) on %s...\n",
  4430. + pkg->name, new_version, old_pkg->dest->name);
  4431. + pkg->dest = old_pkg->dest;
  4432. + rc = 0;
  4433. + } else {
  4434. + ipkg_message(conf, IPKG_NOTICE,
  4435. + "Not installing %s (%s) on %s -- already installed.\n",
  4436. + pkg->name, new_version, old_pkg->dest->name);
  4437. + rc = 1;
  4438. + }
  4439. + }
  4440. + free(old_version);
  4441. + free(new_version);
  4442. + return rc;
  4443. + } else {
  4444. + char message_out[15], *version ;
  4445. + memset(message_out,'\x0',15);
  4446. + if ( message )
  4447. + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
  4448. + else
  4449. + strncpy( message_out,"Installing ",strlen("Installing ") );
  4450. + version = pkg_version_str_alloc(pkg);
  4451. +
  4452. + ipkg_message(conf, IPKG_NOTICE,
  4453. + "%s%s (%s) to %s...\n", message_out,
  4454. + pkg->name, version, pkg->dest->name);
  4455. + free(version);
  4456. + return 0;
  4457. + }
  4458. +}
  4459. +
  4460. +/* and now the meat... */
  4461. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
  4462. +{
  4463. + int err = 0;
  4464. + int message = 0;
  4465. + pkg_t *old_pkg = NULL;
  4466. + pkg_vec_t *replacees;
  4467. + abstract_pkg_t *ab_pkg = NULL;
  4468. + int old_state_flag;
  4469. + uint8_t *file_md5;
  4470. +
  4471. +
  4472. + if ( from_upgrade )
  4473. + message = 1; /* Coming from an upgrade, and should change the output message */
  4474. +
  4475. + if (!pkg) {
  4476. + ipkg_message(conf, IPKG_ERROR,
  4477. + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
  4478. + return -EINVAL;
  4479. + }
  4480. +
  4481. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
  4482. +
  4483. + if (!pkg_arch_supported(conf, pkg)) {
  4484. + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
  4485. + pkg->architecture, pkg->name);
  4486. + return -EINVAL;
  4487. + }
  4488. + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
  4489. + err = satisfy_dependencies_for(conf, pkg);
  4490. + if (err) { return err; }
  4491. +
  4492. + ipkg_message(conf, IPKG_NOTICE,
  4493. + "Package %s is already installed in %s.\n",
  4494. + pkg->name, pkg->dest->name);
  4495. + return 0;
  4496. + }
  4497. +
  4498. + if (pkg->dest == NULL) {
  4499. + pkg->dest = conf->default_dest;
  4500. + }
  4501. +
  4502. + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  4503. +
  4504. + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
  4505. + if (err) { return err; }
  4506. +
  4507. + pkg->state_want = SW_INSTALL;
  4508. + if (old_pkg){
  4509. + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
  4510. + }
  4511. +
  4512. +
  4513. + /* Abhaya: conflicts check */
  4514. + err = check_conflicts_for(conf, pkg);
  4515. + if (err) { return err; }
  4516. +
  4517. + /* this setup is to remove the upgrade scenario in the end when
  4518. + installing pkg A, A deps B & B deps on A. So both B and A are
  4519. + installed. Then A's installation is started resulting in an
  4520. + uncecessary upgrade */
  4521. + if (pkg->state_status == SS_INSTALLED
  4522. + && conf->force_reinstall == 0) return 0;
  4523. +
  4524. + err = verify_pkg_installable(conf, pkg);
  4525. + if (err) { return err; }
  4526. +
  4527. + if (pkg->local_filename == NULL) {
  4528. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  4529. + if (err) {
  4530. + ipkg_message(conf, IPKG_ERROR,
  4531. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  4532. + pkg->name);
  4533. + return err;
  4534. + }
  4535. + }
  4536. +
  4537. +/* Check for md5 values */
  4538. + if (pkg->md5sum)
  4539. + {
  4540. + file_md5 = file_md5sum_alloc(pkg->local_filename);
  4541. + if (strcmp((char *)file_md5, pkg->md5sum))
  4542. + {
  4543. + ipkg_message(conf, IPKG_ERROR,
  4544. + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
  4545. + pkg->name);
  4546. + free(file_md5);
  4547. + return err;
  4548. + }
  4549. + free(file_md5);
  4550. + }
  4551. +
  4552. + if (pkg->tmp_unpack_dir == NULL) {
  4553. + unpack_pkg_control_files(conf, pkg);
  4554. + }
  4555. +
  4556. + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
  4557. +/* Pigi: check if it will pass from here when replacing. It seems to fail */
  4558. +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
  4559. + err = update_file_ownership(conf, pkg, old_pkg);
  4560. + if (err) { return err; }
  4561. +
  4562. + if (conf->nodeps == 0) {
  4563. + err = satisfy_dependencies_for(conf, pkg);
  4564. + if (err) { return err; }
  4565. + }
  4566. +
  4567. + replacees = pkg_vec_alloc();
  4568. + pkg_get_installed_replacees(pkg, replacees);
  4569. +
  4570. + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
  4571. + {
  4572. + sigset_t newset, oldset;
  4573. + sighandler_t old_handler = NULL;
  4574. + int use_signal = 0;
  4575. + caught_sigint = 0;
  4576. + if (use_signal) {
  4577. + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
  4578. + } else {
  4579. + sigemptyset(&newset);
  4580. + sigaddset(&newset, SIGINT);
  4581. + sigprocmask(SIG_BLOCK, &newset, &oldset);
  4582. + }
  4583. +
  4584. + ipkg_state_changed++;
  4585. + pkg->state_flag |= SF_FILELIST_CHANGED;
  4586. +
  4587. + /* XXX: BUG: we really should treat replacement more like an upgrade
  4588. + * Instead, we're going to remove the replacees
  4589. + */
  4590. + err = pkg_remove_installed_replacees(conf, replacees);
  4591. + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
  4592. +
  4593. + /*
  4594. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  4595. + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
  4596. +
  4597. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  4598. + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
  4599. + */
  4600. +
  4601. + err = preinst_configure(conf, pkg, old_pkg);
  4602. + /*
  4603. + if (err) goto UNWIND_PREINST_CONFIGURE;
  4604. + */
  4605. +
  4606. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  4607. + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
  4608. +
  4609. + err = check_data_file_clashes(conf, pkg, old_pkg);
  4610. + /*
  4611. + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
  4612. +
  4613. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  4614. + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
  4615. + */
  4616. +
  4617. + if (conf->noaction) return 0;
  4618. +
  4619. + /* point of no return: no unwinding after this */
  4620. + if (old_pkg && !conf->force_reinstall) {
  4621. + old_pkg->state_want = SW_DEINSTALL;
  4622. +
  4623. + if (old_pkg->state_flag & SF_NOPRUNE) {
  4624. + ipkg_message(conf, IPKG_INFO,
  4625. + " not removing obsolesced files because package marked noprune\n");
  4626. + } else {
  4627. + ipkg_message(conf, IPKG_INFO,
  4628. + " removing obsolesced files\n");
  4629. + remove_obsolesced_files(conf, pkg, old_pkg);
  4630. + }
  4631. + /* removing files from old package, to avoid ghost files */
  4632. + remove_data_files_and_list(conf, old_pkg);
  4633. +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
  4634. + remove_maintainer_scripts_except_postrm(conf, old_pkg);
  4635. + remove_postrm(conf, old_pkg);
  4636. +/* Pigi */
  4637. +
  4638. + }
  4639. +
  4640. +
  4641. + ipkg_message(conf, IPKG_INFO,
  4642. + " installing maintainer scripts\n");
  4643. + install_maintainer_scripts(conf, pkg, old_pkg);
  4644. +
  4645. + /* the following just returns 0
  4646. + remove_disappeared(conf, pkg);
  4647. + */
  4648. +
  4649. + ipkg_message(conf, IPKG_INFO,
  4650. + " installing data files\n");
  4651. + install_data_files(conf, pkg);
  4652. +
  4653. +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
  4654. + err = check_data_file_clashes_change(conf, pkg);
  4655. +
  4656. + ipkg_message(conf, IPKG_INFO,
  4657. + " resolving conf files\n");
  4658. + resolve_conffiles(conf, pkg);
  4659. +
  4660. + pkg->state_status = SS_UNPACKED;
  4661. + old_state_flag = pkg->state_flag;
  4662. + pkg->state_flag &= ~SF_PREFER;
  4663. + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
  4664. +
  4665. + if (old_pkg && !conf->force_reinstall) {
  4666. + old_pkg->state_status = SS_NOT_INSTALLED;
  4667. + }
  4668. +
  4669. + time(&pkg->installed_time);
  4670. +
  4671. + ipkg_message(conf, IPKG_INFO,
  4672. + " cleanup temp files\n");
  4673. + cleanup_temporary_files(conf, pkg);
  4674. +
  4675. + ab_pkg = pkg->parent;
  4676. + if (ab_pkg)
  4677. + ab_pkg->state_status = pkg->state_status;
  4678. +
  4679. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  4680. +
  4681. + if (use_signal)
  4682. + signal(SIGINT, old_handler);
  4683. + else
  4684. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4685. +
  4686. + return 0;
  4687. +
  4688. +
  4689. + /*
  4690. + UNWIND_POSTRM_UPGRADE_OLD_PKG:
  4691. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4692. + UNWIND_CHECK_DATA_FILE_CLASHES:
  4693. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  4694. + */
  4695. + UNWIND_BACKUP_MODIFIED_CONFFILES:
  4696. + backup_modified_conffiles_unwind(pkg, old_pkg);
  4697. + /*
  4698. + UNWIND_PREINST_CONFIGURE:
  4699. + preinst_configure_unwind(conf, pkg, old_pkg);
  4700. + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
  4701. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  4702. + UNWIND_PRERM_UPGRADE_OLD_PKG:
  4703. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4704. + */
  4705. + UNWIND_REMOVE_INSTALLED_REPLACEES:
  4706. + pkg_remove_installed_replacees_unwind(conf, replacees);
  4707. +
  4708. + ipkg_message(conf, IPKG_INFO,
  4709. + " cleanup temp files\n");
  4710. + cleanup_temporary_files(conf, pkg);
  4711. +
  4712. + ipkg_message(conf, IPKG_INFO,
  4713. + "Failed.\n");
  4714. + if (use_signal)
  4715. + signal(SIGINT, old_handler);
  4716. + else
  4717. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4718. +
  4719. + return err;
  4720. + }
  4721. +}
  4722. +
  4723. +/*
  4724. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4725. +{
  4726. + DPKG_INCOMPATIBILITY:
  4727. + dpkg does some things here that we don't do yet. Do we care?
  4728. +
  4729. + 1. If a version of the package is already installed, call
  4730. + old-prerm upgrade new-version
  4731. + 2. If the script runs but exits with a non-zero exit status
  4732. + new-prerm failed-upgrade old-version
  4733. + Error unwind, for both the above cases:
  4734. + old-postinst abort-upgrade new-version
  4735. + return 0;
  4736. +}
  4737. +*/
  4738. +
  4739. +/*
  4740. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4741. +{
  4742. + DPKG_INCOMPATIBILITY:
  4743. + dpkg does some things here that we don't do yet. Do we care?
  4744. + (See prerm_upgrade_old_package for details)
  4745. +
  4746. + return 0;
  4747. +}
  4748. +*/
  4749. +
  4750. +/*
  4751. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4752. +{
  4753. + DPKG_INCOMPATIBILITY:
  4754. + dpkg does some things here that we don't do yet. Do we care?
  4755. + 2. If a 'conflicting' package is being removed at the same time:
  4756. + 1. If any packages depended on that conflicting package and
  4757. + --auto-deconfigure is specified, call, for each such package:
  4758. + deconfigured's-prerm deconfigure \
  4759. + in-favour package-being-installed version \
  4760. + removing conflicting-package version
  4761. + Error unwind:
  4762. + deconfigured's-postinst abort-deconfigure \
  4763. + in-favour package-being-installed-but-failed version \
  4764. + removing conflicting-package version
  4765. +
  4766. + The deconfigured packages are marked as requiring
  4767. + configuration, so that if --install is used they will be
  4768. + configured again if possible.
  4769. + 2. To prepare for removal of the conflicting package, call:
  4770. + conflictor's-prerm remove in-favour package new-version
  4771. + Error unwind:
  4772. + conflictor's-postinst abort-remove in-favour package new-version
  4773. + return 0;
  4774. +}
  4775. +*/
  4776. +
  4777. +/*
  4778. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4779. +{
  4780. + DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
  4781. + do yet. Do we care? (See prerm_deconfigure_conflictors for
  4782. + details)
  4783. + return 0;
  4784. +}
  4785. +*/
  4786. +
  4787. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4788. +{
  4789. + int err;
  4790. + char *preinst_args;
  4791. +
  4792. + if (old_pkg) {
  4793. + char *old_version = pkg_version_str_alloc(old_pkg);
  4794. + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
  4795. + free(old_version);
  4796. + } else if (pkg->state_status == SS_CONFIG_FILES) {
  4797. + char *pkg_version = pkg_version_str_alloc(pkg);
  4798. + sprintf_alloc(&preinst_args, "install %s", pkg_version);
  4799. + free(pkg_version);
  4800. + } else {
  4801. + preinst_args = strdup("install");
  4802. + }
  4803. +
  4804. + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
  4805. + if (err) {
  4806. + ipkg_message(conf, IPKG_ERROR,
  4807. + "Aborting installation of %s\n", pkg->name);
  4808. + return 1;
  4809. + }
  4810. +
  4811. + free(preinst_args);
  4812. +
  4813. + return 0;
  4814. +}
  4815. +
  4816. +/*
  4817. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4818. +{
  4819. + DPKG_INCOMPATIBILITY:
  4820. + dpkg does the following error unwind, should we?
  4821. + pkg->postrm abort-upgrade old-version
  4822. + OR pkg->postrm abort-install old-version
  4823. + OR pkg->postrm abort-install
  4824. + return 0;
  4825. +}
  4826. +*/
  4827. +
  4828. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4829. +{
  4830. + int err;
  4831. + conffile_list_elt_t *iter;
  4832. + conffile_t *cf;
  4833. +
  4834. + if (conf->noaction) return 0;
  4835. +
  4836. + /* Backup all modified conffiles */
  4837. + if (old_pkg) {
  4838. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4839. + char *cf_name;
  4840. +
  4841. + cf = iter->data;
  4842. + cf_name = root_filename_alloc(conf, cf->name);
  4843. +
  4844. + /* Don't worry if the conffile is just plain gone */
  4845. + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
  4846. + err = backup_make_backup(conf, cf_name);
  4847. + if (err) {
  4848. + return err;
  4849. + }
  4850. + }
  4851. + free(cf_name);
  4852. + }
  4853. + }
  4854. +
  4855. + /* Backup all conffiles that were not conffiles in old_pkg */
  4856. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4857. + char *cf_name;
  4858. + cf = iter->data;
  4859. + cf_name = root_filename_alloc(conf, cf->name);
  4860. + /* Ignore if this was a conffile in old_pkg as well */
  4861. + if (pkg_get_conffile(old_pkg, cf->name)) {
  4862. + continue;
  4863. + }
  4864. +
  4865. + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
  4866. + err = backup_make_backup(conf, cf_name);
  4867. + if (err) {
  4868. + return err;
  4869. + }
  4870. + }
  4871. + free(cf_name);
  4872. + }
  4873. +
  4874. + return 0;
  4875. +}
  4876. +
  4877. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg)
  4878. +{
  4879. + conffile_list_elt_t *iter;
  4880. +
  4881. + if (old_pkg) {
  4882. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4883. + backup_remove(iter->data->name);
  4884. + }
  4885. + }
  4886. +
  4887. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4888. + backup_remove(iter->data->name);
  4889. + }
  4890. +
  4891. + return 0;
  4892. +}
  4893. +
  4894. +
  4895. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4896. +{
  4897. + /* DPKG_INCOMPATIBILITY:
  4898. + ipkg takes a slightly different approach than dpkg at this
  4899. + point. dpkg installs each file in the new package while
  4900. + creating a backup for any file that is replaced, (so that it
  4901. + can unwind if necessary). To avoid complexity and redundant
  4902. + storage, ipkg doesn't do any installation until later, (at the
  4903. + point at which dpkg removes the backups.
  4904. +
  4905. + But, we do have to check for data file clashes, since after
  4906. + installing a package with a file clash, removing either of the
  4907. + packages involved in the clash has the potential to break the
  4908. + other package.
  4909. + */
  4910. + str_list_t *files_list;
  4911. + str_list_elt_t *iter;
  4912. +
  4913. + int clashes = 0;
  4914. +
  4915. + files_list = pkg_get_installed_files(pkg);
  4916. + for (iter = files_list->head; iter; iter = iter->next) {
  4917. + char *root_filename;
  4918. + char *filename = iter->data;
  4919. + root_filename = root_filename_alloc(conf, filename);
  4920. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  4921. + pkg_t *owner;
  4922. + pkg_t *obs;
  4923. + /* Pre-existing conffiles are OK */
  4924. + /* @@@@ should have way to check that it is a conffile -Jamey */
  4925. + if (backup_exists_for(root_filename)) {
  4926. + continue;
  4927. + }
  4928. +
  4929. + /* Pre-existing files are OK if force-overwrite was asserted. */
  4930. + if (conf->force_overwrite) {
  4931. + /* but we need to change who owns this file */
  4932. + file_hash_set_file_owner(conf, filename, pkg);
  4933. + continue;
  4934. + }
  4935. +
  4936. + owner = file_hash_get_file_owner(conf, filename);
  4937. +
  4938. + /* Pre-existing files are OK if owned by the pkg being upgraded. */
  4939. + if (owner && old_pkg) {
  4940. + if (strcmp(owner->name, old_pkg->name) == 0) {
  4941. + continue;
  4942. + }
  4943. + }
  4944. +
  4945. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  4946. + if (owner) {
  4947. + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
  4948. + if (pkg_replaces(pkg, owner)) {
  4949. + continue;
  4950. + }
  4951. +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
  4952. + then it's ok to overwrite. */
  4953. + if (strcmp(owner->name,pkg->name)==0){
  4954. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  4955. + continue;
  4956. + }
  4957. + }
  4958. +
  4959. + /* Pre-existing files are OK if they are obsolete */
  4960. + obs = hash_table_get(&conf->obs_file_hash, filename);
  4961. + if (obs) {
  4962. + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
  4963. + continue;
  4964. + }
  4965. +
  4966. + /* We have found a clash. */
  4967. + ipkg_message(conf, IPKG_ERROR,
  4968. + "Package %s wants to install file %s\n"
  4969. + "\tBut that file is already provided by package ",
  4970. + pkg->name, filename);
  4971. + if (owner) {
  4972. + ipkg_message(conf, IPKG_ERROR,
  4973. + "%s\n", owner->name);
  4974. + } else {
  4975. + ipkg_message(conf, IPKG_ERROR,
  4976. + "<no package>\nPlease move this file out of the way and try again.\n");
  4977. + }
  4978. + clashes++;
  4979. + }
  4980. + free(root_filename);
  4981. + }
  4982. + pkg_free_installed_files(pkg);
  4983. +
  4984. + return clashes;
  4985. +}
  4986. +
  4987. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg)
  4988. +{
  4989. + /* Basically that's the worst hack I could do to be able to change ownership of
  4990. + file list, but, being that we have no way to unwind the mods, due to structure
  4991. + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
  4992. + What we do here is change the ownership of file in hash if a replace ( or similar events
  4993. + happens )
  4994. + Only the action that are needed to change name should be considered.
  4995. + @@@ To change after 1.0 release.
  4996. + */
  4997. + str_list_t *files_list;
  4998. + str_list_elt_t *iter;
  4999. +
  5000. + int clashes = 0;
  5001. +
  5002. + files_list = pkg_get_installed_files(pkg);
  5003. + for (iter = files_list->head; iter; iter = iter->next) {
  5004. + char *root_filename;
  5005. + char *filename = iter->data;
  5006. + root_filename = root_filename_alloc(conf, filename);
  5007. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5008. + pkg_t *owner;
  5009. +
  5010. + if (conf->force_overwrite) {
  5011. + /* but we need to change who owns this file */
  5012. + file_hash_set_file_owner(conf, filename, pkg);
  5013. + continue;
  5014. + }
  5015. +
  5016. + owner = file_hash_get_file_owner(conf, filename);
  5017. +
  5018. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5019. + if (owner) {
  5020. + if (pkg_replaces(pkg, owner)) {
  5021. +/* It's now time to change the owner of that file.
  5022. + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
  5023. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5024. + file_hash_set_file_owner(conf, filename, pkg);
  5025. + continue;
  5026. + }
  5027. + }
  5028. +
  5029. + }
  5030. + free(root_filename);
  5031. + }
  5032. + pkg_free_installed_files(pkg);
  5033. +
  5034. + return clashes;
  5035. +}
  5036. +
  5037. +/*
  5038. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5039. +{
  5040. + Nothing to do since check_data_file_clashes doesn't change state
  5041. + return 0;
  5042. +}
  5043. +*/
  5044. +
  5045. +/*
  5046. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5047. +{
  5048. + DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
  5049. + 1. If the package is being upgraded, call
  5050. + old-postrm upgrade new-version
  5051. + 2. If this fails, attempt:
  5052. + new-postrm failed-upgrade old-version
  5053. + Error unwind, for both cases:
  5054. + old-preinst abort-upgrade new-version
  5055. + return 0;
  5056. +}
  5057. +*/
  5058. +
  5059. +/*
  5060. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5061. +{
  5062. + DPKG_INCOMPATIBILITY:
  5063. + dpkg does some things here that we don't do yet. Do we care?
  5064. + (See postrm_upgrade_old_pkg for details)
  5065. + return 0;
  5066. +}
  5067. +*/
  5068. +
  5069. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5070. +{
  5071. + int err;
  5072. + str_list_t *old_files;
  5073. + str_list_elt_t *of;
  5074. + str_list_t *new_files;
  5075. + str_list_elt_t *nf;
  5076. +
  5077. + if (old_pkg == NULL) {
  5078. + return 0;
  5079. + }
  5080. +
  5081. + old_files = pkg_get_installed_files(old_pkg);
  5082. + new_files = pkg_get_installed_files(pkg);
  5083. +
  5084. + for (of = old_files->head; of; of = of->next) {
  5085. + pkg_t *owner;
  5086. + char *old, *new;
  5087. + old = of->data;
  5088. + for (nf = new_files->head; nf; nf = nf->next) {
  5089. + new = nf->data;
  5090. + if (strcmp(old, new) == 0) {
  5091. + goto NOT_OBSOLETE;
  5092. + }
  5093. + }
  5094. + if (file_is_dir(old)) {
  5095. + continue;
  5096. + }
  5097. + owner = file_hash_get_file_owner(conf, old);
  5098. + if (owner != old_pkg) {
  5099. + /* in case obsolete file no longer belongs to old_pkg */
  5100. + continue;
  5101. + }
  5102. +
  5103. + /* old file is obsolete */
  5104. + ipkg_message(conf, IPKG_INFO,
  5105. + " removing obsolete file %s\n", old);
  5106. + if (!conf->noaction) {
  5107. + err = unlink(old);
  5108. + if (err) {
  5109. + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
  5110. + strerror(errno));
  5111. + }
  5112. + }
  5113. +
  5114. + NOT_OBSOLETE:
  5115. + ;
  5116. + }
  5117. +
  5118. + pkg_free_installed_files(old_pkg);
  5119. + pkg_free_installed_files(pkg);
  5120. +
  5121. + return 0;
  5122. +}
  5123. +
  5124. +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5125. +{
  5126. + int i;
  5127. + int err = 0;
  5128. + char *globpattern;
  5129. + glob_t globbuf;
  5130. + if (0) {
  5131. + if (!pkg->dest) {
  5132. + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
  5133. + return -1;
  5134. + }
  5135. + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
  5136. + err = glob(globpattern, 0, NULL, &globbuf);
  5137. + free(globpattern);
  5138. + if (err) {
  5139. + return err;
  5140. + }
  5141. + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
  5142. + for (i = 0; i < globbuf.gl_pathc; i++) {
  5143. + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
  5144. + globbuf.gl_pathv[i], old_pkg->name);
  5145. + if (!conf->noaction)
  5146. + unlink(globbuf.gl_pathv[i]);
  5147. + }
  5148. + globfree(&globbuf);
  5149. + }
  5150. + return err;
  5151. +}
  5152. +
  5153. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5154. +{
  5155. + int ret;
  5156. + char *prefix;
  5157. +
  5158. + if (old_pkg)
  5159. + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
  5160. + sprintf_alloc(&prefix, "%s.", pkg->name);
  5161. + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
  5162. + pkg->dest->info_dir,
  5163. + prefix);
  5164. + free(prefix);
  5165. + return ret;
  5166. +}
  5167. +
  5168. +/*
  5169. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
  5170. +{
  5171. + DPKG_INCOMPATIBILITY:
  5172. + This is a fairly sophisticated dpkg operation. Shall we
  5173. + skip it?
  5174. +
  5175. + Any packages all of whose files have been overwritten during the
  5176. + installation, and which aren't required for dependencies, are
  5177. + considered to have been removed. For each such package
  5178. + 1. disappearer's-postrm disappear overwriter overwriter-version
  5179. + 2. The package's maintainer scripts are removed
  5180. + 3. It is noted in the status database as being in a sane state,
  5181. + namely not installed (any conffiles it may have are ignored,
  5182. + rather than being removed by dpkg). Note that disappearing
  5183. + packages do not have their prerm called, because dpkg doesn't
  5184. + know in advance that the package is going to vanish.
  5185. +
  5186. +
  5187. + return 0;
  5188. +}
  5189. +*/
  5190. +
  5191. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
  5192. +{
  5193. + int err;
  5194. +
  5195. + /* ipkg takes a slightly different approach to data file backups
  5196. + than dpkg. Rather than removing backups at this point, we
  5197. + actually do the data file installation now. See comments in
  5198. + check_data_file_clashes() for more details. */
  5199. +
  5200. + ipkg_message(conf, IPKG_INFO,
  5201. + " extracting data files to %s\n", pkg->dest->root_dir);
  5202. + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
  5203. + if (err) {
  5204. + return err;
  5205. + }
  5206. +
  5207. + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
  5208. + so we can't save ourself from removing important packages
  5209. + At this point we (should) have extracted the .control file, so it
  5210. + would be a good idea to reload the data in it, and set the Essential
  5211. + state in *pkg. From now on the Essential is back in status file and
  5212. + we can protect again.
  5213. + We should operate this way:
  5214. + fopen the file ( pkg->dest->root_dir/pkg->name.control )
  5215. + check for "Essential" in it
  5216. + set the value in pkg->essential.
  5217. + This new routine could be useful also for every other flag
  5218. + Pigi: 16/03/2004 */
  5219. + set_flags_from_control(conf, pkg) ;
  5220. +
  5221. + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
  5222. + err = pkg_write_filelist(conf, pkg);
  5223. + if (err)
  5224. + return err;
  5225. +
  5226. + /* XXX: FEATURE: ipkg should identify any files which existed
  5227. + before installation and which were overwritten, (see
  5228. + check_data_file_clashes()). What it must do is remove any such
  5229. + files from the filelist of the old package which provided the
  5230. + file. Otherwise, if the old package were removed at some point
  5231. + it would break the new package. Removing the new package will
  5232. + also break the old one, but this cannot be helped since the old
  5233. + package's file has already been deleted. This is the importance
  5234. + of check_data_file_clashes(), and only allowing ipkg to install
  5235. + a clashing package with a user force. */
  5236. +
  5237. + return 0;
  5238. +}
  5239. +
  5240. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
  5241. +{
  5242. + conffile_list_elt_t *iter;
  5243. + conffile_t *cf;
  5244. + char *cf_backup;
  5245. + uint8_t *md5sum;
  5246. +
  5247. +
  5248. + if (conf->noaction) return 0;
  5249. +
  5250. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  5251. + char *root_filename;
  5252. + cf = iter->data;
  5253. + root_filename = root_filename_alloc(conf, cf->name);
  5254. +
  5255. + /* Might need to initialize the md5sum for each conffile */
  5256. + if (cf->value == NULL) {
  5257. + cf->value = (char *)file_md5sum_alloc(root_filename);
  5258. + }
  5259. +
  5260. + if (!file_exists(root_filename)) {
  5261. + free(root_filename);
  5262. + continue;
  5263. + }
  5264. +
  5265. + cf_backup = backup_filename_alloc(root_filename);
  5266. +
  5267. +
  5268. + if (file_exists(cf_backup)) {
  5269. + /* Let's compute md5 to test if files are changed */
  5270. + md5sum = file_md5sum_alloc(cf_backup);
  5271. + if (strcmp( cf->value, (char *)md5sum) != 0 ) {
  5272. + if (conf->force_defaults
  5273. + || user_prefers_old_conffile(cf->name, cf_backup) ) {
  5274. + rename(cf_backup, root_filename);
  5275. + }
  5276. + }
  5277. + unlink(cf_backup);
  5278. + free(md5sum);
  5279. + }
  5280. +
  5281. + free(cf_backup);
  5282. + free(root_filename);
  5283. + }
  5284. +
  5285. + return 0;
  5286. +}
  5287. +
  5288. +static int user_prefers_old_conffile(const char *file_name, const char *backup)
  5289. +{
  5290. + char *response;
  5291. + const char *short_file_name;
  5292. +
  5293. + short_file_name = strrchr(file_name, '/');
  5294. + if (short_file_name) {
  5295. + short_file_name++;
  5296. + } else {
  5297. + short_file_name = file_name;
  5298. + }
  5299. +
  5300. + while (1) {
  5301. + response = get_user_response(" Configuration file '%s'\n"
  5302. + " ==> File on system created by you or by a script.\n"
  5303. + " ==> File also in package provided by package maintainer.\n"
  5304. + " What would you like to do about it ? Your options are:\n"
  5305. + " Y or I : install the package maintainer's version\n"
  5306. + " N or O : keep your currently-installed version\n"
  5307. +#ifdef CONFIG_DIFF
  5308. + " D : show the differences between the versions\n"
  5309. +#endif
  5310. + " The default action is to keep your current version.\n"
  5311. + " *** %s (Y/I/N/O"
  5312. +#ifdef CONFIG_DIFF
  5313. + "/D"
  5314. +#endif
  5315. + ") [default=N] ? ", file_name, short_file_name);
  5316. + if (strcmp(response, "y") == 0
  5317. + || strcmp(response, "i") == 0
  5318. + || strcmp(response, "yes") == 0) {
  5319. + free(response);
  5320. + return 0;
  5321. + }
  5322. +
  5323. +#ifdef CONFIG_DIFF
  5324. + if (strcmp(response, "d") == 0) {
  5325. + char *cmd;
  5326. +
  5327. + free(response);
  5328. + /* XXX: BUG rewrite to use exec or busybox's internal diff */
  5329. + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
  5330. + xsystem(cmd);
  5331. + free(cmd);
  5332. + printf(" [Press ENTER to continue]\n");
  5333. + response = file_read_line_alloc(stdin);
  5334. + free(response);
  5335. + continue;
  5336. + }
  5337. +#endif
  5338. +
  5339. + free(response);
  5340. + return 1;
  5341. + }
  5342. +}
  5343. +
  5344. +/* XXX: CLEANUP: I'd like to move all of the code for
  5345. + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
  5346. + it would make sense to cleanup pkg->tmp_unpack_dir directly from
  5347. + pkg_deinit for example). */
  5348. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
  5349. +{
  5350. + DIR *tmp_dir;
  5351. + struct dirent *dirent;
  5352. + char *tmp_file;
  5353. +
  5354. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  5355. +#error
  5356. + ipkg_message(conf, IPKG_DEBUG,
  5357. + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  5358. + __FUNCTION__, pkg->tmp_unpack_dir);
  5359. + return 0;
  5360. +#endif
  5361. +
  5362. + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
  5363. + tmp_dir = opendir(pkg->tmp_unpack_dir);
  5364. + if (tmp_dir) {
  5365. + while (1) {
  5366. + dirent = readdir(tmp_dir);
  5367. + if (dirent == NULL) {
  5368. + break;
  5369. + }
  5370. + sprintf_alloc(&tmp_file, "%s/%s",
  5371. + pkg->tmp_unpack_dir, dirent->d_name);
  5372. + if (! file_is_dir(tmp_file)) {
  5373. + unlink(tmp_file);
  5374. + }
  5375. + free(tmp_file);
  5376. + }
  5377. + closedir(tmp_dir);
  5378. + rmdir(pkg->tmp_unpack_dir);
  5379. + free(pkg->tmp_unpack_dir);
  5380. + pkg->tmp_unpack_dir = NULL;
  5381. + }
  5382. + }
  5383. +
  5384. + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
  5385. + pkg->name, pkg->local_filename, conf->tmp_dir);
  5386. + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
  5387. + unlink(pkg->local_filename);
  5388. + free(pkg->local_filename);
  5389. + pkg->local_filename = NULL;
  5390. + }
  5391. +
  5392. + return 0;
  5393. +}
  5394. +
  5395. +static char *backup_filename_alloc(const char *file_name)
  5396. +{
  5397. + char *backup;
  5398. +
  5399. + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
  5400. +
  5401. + return backup;
  5402. +}
  5403. +
  5404. +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
  5405. +{
  5406. + int err;
  5407. + char *backup;
  5408. +
  5409. + backup = backup_filename_alloc(file_name);
  5410. + err = file_copy(file_name, backup);
  5411. + if (err) {
  5412. + ipkg_message(conf, IPKG_ERROR,
  5413. + "%s: Failed to copy %s to %s\n",
  5414. + __FUNCTION__, file_name, backup);
  5415. + }
  5416. +
  5417. + free(backup);
  5418. +
  5419. + return err;
  5420. +}
  5421. +
  5422. +static int backup_exists_for(const char *file_name)
  5423. +{
  5424. + int ret;
  5425. + char *backup;
  5426. +
  5427. + backup = backup_filename_alloc(file_name);
  5428. +
  5429. + ret = file_exists(backup);
  5430. +
  5431. + free(backup);
  5432. +
  5433. + return ret;
  5434. +}
  5435. +
  5436. +static int backup_remove(const char *file_name)
  5437. +{
  5438. + char *backup;
  5439. +
  5440. + backup = backup_filename_alloc(file_name);
  5441. + unlink(backup);
  5442. + free(backup);
  5443. +
  5444. + return 0;
  5445. +}
  5446. +
  5447. +
  5448. +
  5449. +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
  5450. +
  5451. +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
  5452. +{
  5453. + /* first, remove the packages that need removing */
  5454. + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
  5455. + pkg_t *pkg = pkgs_to_remove->pkgs[i];
  5456. + err = ipkg_remove_pkg(conf, pkg,0);
  5457. + if (err) return err;
  5458. + }
  5459. + return 0;
  5460. +}
  5461. +
  5462. +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)
  5463. +{
  5464. + int i;
  5465. + /* now one more pass checking on the ones that need to be installed */
  5466. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5467. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5468. + if (pkg->dest == NULL)
  5469. + pkg->dest = conf->default_dest;
  5470. +
  5471. + pkg->state_want = SW_INSTALL;
  5472. +
  5473. + /* Abhaya: conflicts check */
  5474. + err = check_conflicts_for(conf, pkg);
  5475. + if (err) { return err; }
  5476. + }
  5477. + return 0;
  5478. +}
  5479. +
  5480. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5481. +{
  5482. + int i;
  5483. + /* now one more pass checking on the ones that need to be installed */
  5484. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5485. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5486. +
  5487. + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
  5488. + pkg_vec_t *replacees = pkg_vec_alloc();
  5489. + pkg_get_installed_replacees(pkg, replacees);
  5490. +
  5491. + /* XXX: BUG: we really should treat replacement more like an upgrade
  5492. + * Instead, we're going to remove the replacees
  5493. + */
  5494. + err = pkg_remove_installed_replacees(conf, replacees);
  5495. + if (err) return err;
  5496. + pkg->state_flag |= SF_REMOVED_REPLACEES;
  5497. + }
  5498. + return 0;
  5499. +}
  5500. +
  5501. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5502. +{
  5503. + int i;
  5504. + /* now one more pass checking on the ones that need to be installed */
  5505. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5506. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5507. + if (pkg->local_filename == NULL) {
  5508. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  5509. + if (err) {
  5510. + ipkg_message(conf, IPKG_ERROR,
  5511. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  5512. + pkg->name);
  5513. + return err;
  5514. + }
  5515. + }
  5516. + if (pkg->tmp_unpack_dir == NULL) {
  5517. + err = unpack_pkg_control_files(conf, pkg);
  5518. + if (err) return err;
  5519. + }
  5520. + }
  5521. + return 0;
  5522. +}
  5523. +
  5524. +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5525. +{
  5526. + int i;
  5527. + /* now one more pass checking on the ones that need to be installed */
  5528. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5529. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5530. + pkg_t *old_pkg = pkg->old_pkg;
  5531. +
  5532. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  5533. + if (err) return err;
  5534. +
  5535. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  5536. + if (err) return err;
  5537. +
  5538. + err = preinst_configure(conf, pkg, old_pkg);
  5539. + if (err) return err;
  5540. +
  5541. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  5542. + if (err) return err;
  5543. +
  5544. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  5545. + if (err) return err;
  5546. + }
  5547. + return 0;
  5548. +}
  5549. +
  5550. +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5551. +{
  5552. + int i;
  5553. + /* now one more pass checking on the ones that need to be installed */
  5554. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5555. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5556. + pkg_t *old_pkg = pkg->old_pkg;
  5557. +
  5558. + if (old_pkg) {
  5559. + old_pkg->state_want = SW_DEINSTALL;
  5560. +
  5561. + if (old_pkg->state_flag & SF_NOPRUNE) {
  5562. + ipkg_message(conf, IPKG_INFO,
  5563. + " not removing obsolesced files because package marked noprune\n");
  5564. + } else {
  5565. + ipkg_message(conf, IPKG_INFO,
  5566. + " removing obsolesced files\n");
  5567. + remove_obsolesced_files(conf, pkg, old_pkg);
  5568. + }
  5569. + }
  5570. +
  5571. + ipkg_message(conf, IPKG_INFO,
  5572. + " installing maintainer scripts\n");
  5573. + install_maintainer_scripts(conf, pkg, old_pkg);
  5574. +
  5575. + /* the following just returns 0 */
  5576. + remove_disappeared(conf, pkg);
  5577. +
  5578. + ipkg_message(conf, IPKG_INFO,
  5579. + " installing data files\n");
  5580. + install_data_files(conf, pkg);
  5581. +
  5582. + ipkg_message(conf, IPKG_INFO,
  5583. + " resolving conf files\n");
  5584. + resolve_conffiles(conf, pkg);
  5585. +
  5586. + pkg->state_status = SS_UNPACKED;
  5587. +
  5588. + if (old_pkg) {
  5589. + old_pkg->state_status = SS_NOT_INSTALLED;
  5590. + }
  5591. +
  5592. + time(&pkg->installed_time);
  5593. +
  5594. + ipkg_message(conf, IPKG_INFO,
  5595. + " cleanup temp files\n");
  5596. + cleanup_temporary_files(conf, pkg);
  5597. +
  5598. + if (pkg->parent)
  5599. + pkg->parent->state_status = pkg->state_status;
  5600. + }
  5601. + return 0;
  5602. +}
  5603. +
  5604. +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5605. +{
  5606. + int i;
  5607. + /* now one more pass checking on the ones that need to be installed */
  5608. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5609. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5610. + pkg_t *old_pkg = pkg->old_pkg;
  5611. +
  5612. + if (old_pkg) {
  5613. + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
  5614. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5615. + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
  5616. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  5617. + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
  5618. + backup_modified_conffiles_unwind(pkg, old_pkg);
  5619. + */
  5620. + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
  5621. + preinst_configure_unwind(conf, pkg, old_pkg);
  5622. + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
  5623. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  5624. + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
  5625. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5626. + */
  5627. +
  5628. + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
  5629. + remove_installed_replacees_unwind(conf, pkg, old_pkg);
  5630. +
  5631. + }
  5632. + }
  5633. + return 0;
  5634. +}
  5635. +
  5636. +/*
  5637. + * Perform all the actions.
  5638. + *
  5639. + * pkgs_to_remove are packages marked for removal.
  5640. + * pkgs_superseded are the old packages being replaced by upgrades.
  5641. + *
  5642. + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
  5643. + */
  5644. +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)
  5645. +{
  5646. + int err;
  5647. + int i;
  5648. +
  5649. + err = ipkg_remove_packages(conf, pkgs_to_remove);
  5650. + if (err) return err;
  5651. +
  5652. + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
  5653. + if (err) return err;
  5654. +
  5655. + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
  5656. + if (err) goto UNWIND;
  5657. +
  5658. + /* @@@@ look at ipkg_install_pkg for handling replacements */
  5659. + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
  5660. + if (err) goto UNWIND;
  5661. +
  5662. + /*
  5663. + * Now that we have the packages unpacked, we can look for data
  5664. + * file clashes. First, we mark the files from the superseded
  5665. + * packages as obsolete. Then we scan the files in
  5666. + * pkgs_to_install, and only complain about clashes with
  5667. + * non-obsolete files.
  5668. + */
  5669. +
  5670. + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
  5671. + if (err) goto UNWIND;
  5672. +
  5673. + /* this was before checking data file clashes */
  5674. + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
  5675. + if (err) goto UNWIND;
  5676. +
  5677. + /* point of no return: no unwinding after this */
  5678. + err = ipkg_process_actions_install(conf, pkgs_to_install);
  5679. + if (err) return err;
  5680. +
  5681. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  5682. + return 0;
  5683. +
  5684. + UNWIND:
  5685. + ipkg_process_actions_unwind(conf, pkgs_to_install);
  5686. +
  5687. + ipkg_message(conf, IPKG_INFO,
  5688. + " cleanup temp files\n");
  5689. + cleanup_temporary_files(conf, pkg);
  5690. +
  5691. + ipkg_message(conf, IPKG_INFO,
  5692. + "Failed.\n");
  5693. + return err;
  5694. +}
  5695. +
  5696. +#endif
  5697. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_install.h busybox-1.16.1/archival/libipkg/ipkg_install.h
  5698. --- busybox-1.16.1.orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
  5699. +++ busybox-1.16.1/archival/libipkg/ipkg_install.h 2010-06-29 17:31:22.768368136 +0200
  5700. @@ -0,0 +1,35 @@
  5701. +/* ipkg_install.h - the itsy package management system
  5702. +
  5703. + Carl D. Worth
  5704. +
  5705. + Copyright (C) 2001 University of Southern California
  5706. +
  5707. + This program is free software; you can redistribute it and/or
  5708. + modify it under the terms of the GNU General Public License as
  5709. + published by the Free Software Foundation; either version 2, or (at
  5710. + your option) any later version.
  5711. +
  5712. + This program is distributed in the hope that it will be useful, but
  5713. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5714. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5715. + General Public License for more details.
  5716. +*/
  5717. +
  5718. +#ifndef IPKG_INSTALL_H
  5719. +#define IPKG_INSTALL_H
  5720. +
  5721. +#include "pkg.h"
  5722. +#include "ipkg_conf.h"
  5723. +
  5724. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5725. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5726. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
  5727. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
  5728. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  5729. +
  5730. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
  5731. +
  5732. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
  5733. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
  5734. +
  5735. +#endif
  5736. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_message.c busybox-1.16.1/archival/libipkg/ipkg_message.c
  5737. --- busybox-1.16.1.orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
  5738. +++ busybox-1.16.1/archival/libipkg/ipkg_message.c 2010-06-29 17:31:22.798368009 +0200
  5739. @@ -0,0 +1,35 @@
  5740. +/* ipkg_message.c - the itsy package management system
  5741. +
  5742. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  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. +
  5756. +#include "ipkg.h"
  5757. +#include "ipkg_conf.h"
  5758. +#include "ipkg_message.h"
  5759. +#include "libipkg.h"
  5760. +
  5761. +void
  5762. +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
  5763. +{
  5764. + va_list ap;
  5765. + char ts[256];
  5766. +
  5767. + if (ipkg_cb_message)
  5768. + {
  5769. + va_start (ap, fmt);
  5770. + vsnprintf (ts,256,fmt, ap);
  5771. + va_end (ap);
  5772. + ipkg_cb_message(conf,level,ts);
  5773. + }
  5774. +}
  5775. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_message.h busybox-1.16.1/archival/libipkg/ipkg_message.h
  5776. --- busybox-1.16.1.orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
  5777. +++ busybox-1.16.1/archival/libipkg/ipkg_message.h 2010-06-29 17:31:22.839937503 +0200
  5778. @@ -0,0 +1,32 @@
  5779. +/* ipkg_message.h - the itsy package management system
  5780. +
  5781. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5782. +
  5783. + This program is free software; you can redistribute it and/or
  5784. + modify it under the terms of the GNU General Public License as
  5785. + published by the Free Software Foundation; either version 2, or (at
  5786. + your option) any later version.
  5787. +
  5788. + This program is distributed in the hope that it will be useful, but
  5789. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5790. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5791. + General Public License for more details.
  5792. +*/
  5793. +
  5794. +#ifndef _IPKG_MESSAGE_H_
  5795. +#define _IPKG_MESSAGE_H_
  5796. +
  5797. +#include "ipkg.h"
  5798. +#include "ipkg_conf.h"
  5799. +
  5800. +typedef enum {
  5801. + IPKG_ERROR, /* error conditions */
  5802. + IPKG_NOTICE, /* normal but significant condition */
  5803. + IPKG_INFO, /* informational message */
  5804. + IPKG_DEBUG, /* debug level message */
  5805. + IPKG_DEBUG2, /* more debug level message */
  5806. +} message_level_t;
  5807. +
  5808. +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
  5809. +
  5810. +#endif /* _IPKG_MESSAGE_H_ */
  5811. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_remove.c busybox-1.16.1/archival/libipkg/ipkg_remove.c
  5812. --- busybox-1.16.1.orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
  5813. +++ busybox-1.16.1/archival/libipkg/ipkg_remove.c 2010-06-29 17:31:22.876628032 +0200
  5814. @@ -0,0 +1,385 @@
  5815. +/* ipkg_remove.c - the itsy package management system
  5816. +
  5817. + Carl D. Worth
  5818. +
  5819. + Copyright (C) 2001 University of Southern California
  5820. +
  5821. + This program is free software; you can redistribute it and/or
  5822. + modify it under the terms of the GNU General Public License as
  5823. + published by the Free Software Foundation; either version 2, or (at
  5824. + your option) any later version.
  5825. +
  5826. + This program is distributed in the hope that it will be useful, but
  5827. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5828. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5829. + General Public License for more details.
  5830. +*/
  5831. +
  5832. +#include "ipkg.h"
  5833. +#include "ipkg_message.h"
  5834. +
  5835. +#include <glob.h>
  5836. +
  5837. +#include "ipkg_remove.h"
  5838. +
  5839. +#include "file_util.h"
  5840. +#include "sprintf_alloc.h"
  5841. +#include "str_util.h"
  5842. +
  5843. +#include "ipkg_cmd.h"
  5844. +
  5845. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents);
  5846. +
  5847. +/*
  5848. + * Returns number of the number of packages depending on the packages provided by this package.
  5849. + * Every package implicitly provides itself.
  5850. + */
  5851. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents)
  5852. +{
  5853. + int nprovides = pkg->provides_count;
  5854. + abstract_pkg_t **provides = pkg->provides;
  5855. + int n_installed_dependents = 0;
  5856. + int i;
  5857. + for (i = 0; i <= nprovides; i++) {
  5858. + abstract_pkg_t *providee = provides[i];
  5859. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5860. + abstract_pkg_t *dep_ab_pkg;
  5861. + if (dependers == NULL)
  5862. + continue;
  5863. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5864. + if (dep_ab_pkg->state_status == SS_INSTALLED){
  5865. + n_installed_dependents++;
  5866. + }
  5867. + }
  5868. +
  5869. + }
  5870. + /* if caller requested the set of installed dependents */
  5871. + if (pdependents) {
  5872. + int p = 0;
  5873. + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
  5874. +
  5875. + if ( dependents == NULL ){
  5876. + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
  5877. + return -1;
  5878. + }
  5879. +
  5880. + *pdependents = dependents;
  5881. + for (i = 0; i <= nprovides; i++) {
  5882. + abstract_pkg_t *providee = provides[i];
  5883. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5884. + abstract_pkg_t *dep_ab_pkg;
  5885. + if (dependers == NULL)
  5886. + continue;
  5887. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5888. + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
  5889. + dependents[p++] = dep_ab_pkg;
  5890. + dep_ab_pkg->state_flag |= SF_MARKED;
  5891. + }
  5892. + }
  5893. + }
  5894. + dependents[p] = NULL;
  5895. + /* now clear the marks */
  5896. + for (i = 0; i < p; i++) {
  5897. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5898. + dep_ab_pkg->state_flag &= ~SF_MARKED;
  5899. + }
  5900. + }
  5901. + return n_installed_dependents;
  5902. +}
  5903. +
  5904. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5905. +{
  5906. + int i;
  5907. + int a;
  5908. + int count;
  5909. + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
  5910. + abstract_pkg_t * ab_pkg;
  5911. +
  5912. + if((ab_pkg = pkg->parent) == NULL){
  5913. + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
  5914. + __FUNCTION__, pkg->name);
  5915. + return 0;
  5916. + }
  5917. +
  5918. + if (dependents == NULL)
  5919. + return 0;
  5920. +
  5921. + // here i am using the dependencies_checked
  5922. + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
  5923. + return 0; // has already been encountered in the process
  5924. + // of marking packages for removal - Karthik
  5925. + ab_pkg->dependencies_checked = 2;
  5926. +
  5927. + i = 0;
  5928. + count = 1;
  5929. + while (dependents [i] != NULL) {
  5930. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5931. +
  5932. + if (dep_ab_pkg->dependencies_checked == 2){
  5933. + i++;
  5934. + continue;
  5935. + }
  5936. + if (dep_ab_pkg->state_status == SS_INSTALLED) {
  5937. + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
  5938. + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
  5939. + if (dep_pkg->state_status == SS_INSTALLED) {
  5940. + pkg_vec_insert(dependent_pkgs, dep_pkg);
  5941. + count++;
  5942. + }
  5943. + }
  5944. + }
  5945. + i++;
  5946. + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
  5947. + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
  5948. + }
  5949. +
  5950. + if (count == 1)
  5951. + return 0;
  5952. +
  5953. +
  5954. + for (i = 0; i < dependent_pkgs->len; i++) {
  5955. + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
  5956. + if (err)
  5957. + return err;
  5958. + }
  5959. + return 0;
  5960. +}
  5961. +
  5962. +static int user_prefers_removing_dependents(ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5963. +{
  5964. + abstract_pkg_t *dep_ab_pkg;
  5965. + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
  5966. + while ((dep_ab_pkg = *dependents++) != NULL) {
  5967. + if (dep_ab_pkg->state_status == SS_INSTALLED)
  5968. + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
  5969. + }
  5970. + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
  5971. + ipkg_message(conf, IPKG_ERROR, "");
  5972. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
  5973. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
  5974. + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
  5975. + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
  5976. + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
  5977. + return 0;
  5978. +}
  5979. +
  5980. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
  5981. +{
  5982. +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
  5983. + thus I wan't check for essential, as I'm upgrading.
  5984. + I hope it won't break anything :)
  5985. +*/
  5986. + int err;
  5987. + abstract_pkg_t *parent_pkg = NULL;
  5988. +
  5989. + if (pkg->essential && !message) {
  5990. + if (conf->force_removal_of_essential_packages) {
  5991. + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
  5992. + "\tIf your system breaks, you get to keep both pieces\n",
  5993. + pkg->name);
  5994. + } else {
  5995. + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
  5996. + "\tRemoving an essential package may lead to an unusable system, but if\n"
  5997. + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
  5998. + "\tits will with the option: -force-removal-of-essential-packages\n",
  5999. + pkg->name);
  6000. + return IPKG_PKG_IS_ESSENTIAL;
  6001. + }
  6002. + }
  6003. +
  6004. + if ((parent_pkg = pkg->parent) == NULL)
  6005. + return 0;
  6006. +
  6007. + /* only attempt to remove dependent installed packages if
  6008. + * force_depends is not specified or the package is being
  6009. + * replaced.
  6010. + */
  6011. + if (!conf->force_depends
  6012. + && !(pkg->state_flag & SF_REPLACE)) {
  6013. + abstract_pkg_t **dependents;
  6014. + int has_installed_dependents =
  6015. + pkg_has_installed_dependents(pkg, &dependents);
  6016. +
  6017. + if (has_installed_dependents) {
  6018. + /*
  6019. + * if this package is depended up by others, then either we should
  6020. + * not remove it or we should remove it and all of its dependents
  6021. + */
  6022. +
  6023. + if (!conf->force_removal_of_dependent_packages
  6024. + && !user_prefers_removing_dependents(conf, pkg, dependents)) {
  6025. + return IPKG_PKG_HAS_DEPENDENTS;
  6026. + }
  6027. +
  6028. + /* remove packages depending on this package - Karthik */
  6029. + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
  6030. + free(dependents);
  6031. + if (err) return err;
  6032. + }
  6033. + }
  6034. +
  6035. + if ( message==0 ){
  6036. + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
  6037. + fflush(stdout);
  6038. + }
  6039. + pkg->state_flag |= SF_FILELIST_CHANGED;
  6040. +
  6041. + pkg->state_want = SW_DEINSTALL;
  6042. + ipkg_state_changed++;
  6043. +
  6044. + pkg_run_script(conf, pkg, "prerm", "remove");
  6045. +
  6046. + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
  6047. + maintains an empty filelist rather than deleting it. That seems
  6048. + like a big pain, and I don't see that that should make a big
  6049. + difference, but for anyone who wants tighter compatibility,
  6050. + feel free to fix this. */
  6051. + remove_data_files_and_list(conf, pkg);
  6052. +
  6053. + pkg_run_script(conf, pkg, "postrm", "remove");
  6054. +
  6055. + remove_maintainer_scripts_except_postrm(conf, pkg);
  6056. +
  6057. + /* Aman Gupta - Since ipkg is made for handheld devices with limited
  6058. + * space, it doesn't make sense to leave extra configurations, files,
  6059. + * and maintainer scripts left around. So, we make remove like purge,
  6060. + * and take out all the crap :) */
  6061. +
  6062. + remove_postrm(conf, pkg);
  6063. + pkg->state_status = SS_NOT_INSTALLED;
  6064. +
  6065. + if (parent_pkg)
  6066. + parent_pkg->state_status = SS_NOT_INSTALLED;
  6067. +
  6068. + return 0;
  6069. +}
  6070. +
  6071. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
  6072. +{
  6073. + ipkg_remove_pkg(conf, pkg,0);
  6074. + return 0;
  6075. +}
  6076. +
  6077. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
  6078. +{
  6079. + str_list_t installed_dirs;
  6080. + str_list_t *installed_files;
  6081. + str_list_elt_t *iter;
  6082. + char *file_name;
  6083. + conffile_t *conffile;
  6084. + int removed_a_dir;
  6085. + pkg_t *owner;
  6086. +
  6087. + str_list_init(&installed_dirs);
  6088. + installed_files = pkg_get_installed_files(pkg);
  6089. +
  6090. + for (iter = installed_files->head; iter; iter = iter->next) {
  6091. + file_name = iter->data;
  6092. +
  6093. + if (file_is_dir(file_name)) {
  6094. + str_list_append(&installed_dirs, strdup(file_name));
  6095. + continue;
  6096. + }
  6097. +
  6098. + conffile = pkg_get_conffile(pkg, file_name);
  6099. + if (conffile) {
  6100. + /* XXX: QUESTION: Is this right? I figure we only need to
  6101. + save the conffile if it has been modified. Is that what
  6102. + dpkg does? Or does dpkg preserve all conffiles? If so,
  6103. + this seems like a better thing to do to conserve
  6104. + space. */
  6105. + if (conffile_has_been_modified(conf, conffile)) {
  6106. + printf(" not deleting modified conffile %s\n", file_name);
  6107. + fflush(stdout);
  6108. + continue;
  6109. + }
  6110. + }
  6111. +
  6112. + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
  6113. + if (!conf->noaction)
  6114. + unlink(file_name);
  6115. + }
  6116. +
  6117. + if (!conf->noaction) {
  6118. + do {
  6119. + removed_a_dir = 0;
  6120. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6121. + file_name = iter->data;
  6122. +
  6123. + if (rmdir(file_name) == 0) {
  6124. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
  6125. + removed_a_dir = 1;
  6126. + str_list_remove(&installed_dirs, &iter);
  6127. + }
  6128. + }
  6129. + } while (removed_a_dir);
  6130. + }
  6131. +
  6132. + pkg_free_installed_files(pkg);
  6133. + /* We have to remove the file list now, so that
  6134. + find_pkg_owning_file does not always just report this package */
  6135. + pkg_remove_installed_files_list(conf, pkg);
  6136. +
  6137. + /* Don't print warning for dirs that are provided by other packages */
  6138. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6139. + file_name = iter->data;
  6140. +
  6141. + owner = file_hash_get_file_owner(conf, file_name);
  6142. + if (owner) {
  6143. + free(iter->data);
  6144. + iter->data = NULL;
  6145. + str_list_remove(&installed_dirs, &iter);
  6146. + }
  6147. + }
  6148. +
  6149. + /* cleanup */
  6150. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6151. + free(iter->data);
  6152. + iter->data = NULL;
  6153. + }
  6154. + str_list_deinit(&installed_dirs);
  6155. +
  6156. + return 0;
  6157. +}
  6158. +
  6159. +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6160. +{
  6161. + int i, err;
  6162. + char *globpattern;
  6163. + glob_t globbuf;
  6164. +
  6165. + if (conf->noaction) return 0;
  6166. +
  6167. + sprintf_alloc(&globpattern, "%s/%s.*",
  6168. + pkg->dest->info_dir, pkg->name);
  6169. + err = glob(globpattern, 0, NULL, &globbuf);
  6170. + free(globpattern);
  6171. + if (err) {
  6172. + return 0;
  6173. + }
  6174. +
  6175. + for (i = 0; i < globbuf.gl_pathc; i++) {
  6176. + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
  6177. + continue;
  6178. + }
  6179. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
  6180. + unlink(globbuf.gl_pathv[i]);
  6181. + }
  6182. + globfree(&globbuf);
  6183. +
  6184. + return 0;
  6185. +}
  6186. +
  6187. +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6188. +{
  6189. + char *postrm_file_name;
  6190. +
  6191. + if (conf->noaction) return 0;
  6192. +
  6193. + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
  6194. + pkg->dest->info_dir, pkg->name);
  6195. + unlink(postrm_file_name);
  6196. + free(postrm_file_name);
  6197. +
  6198. + return 0;
  6199. +}
  6200. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_remove.h busybox-1.16.1/archival/libipkg/ipkg_remove.h
  6201. --- busybox-1.16.1.orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
  6202. +++ busybox-1.16.1/archival/libipkg/ipkg_remove.h 2010-06-29 17:31:22.918368225 +0200
  6203. @@ -0,0 +1,33 @@
  6204. +/* ipkg_remove.h - the itsy package management system
  6205. +
  6206. + Carl D. Worth
  6207. +
  6208. + Copyright (C) 2001 University of Southern California
  6209. +
  6210. + This program is free software; you can redistribute it and/or
  6211. + modify it under the terms of the GNU General Public License as
  6212. + published by the Free Software Foundation; either version 2, or (at
  6213. + your option) any later version.
  6214. +
  6215. + This program is distributed in the hope that it will be useful, but
  6216. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6217. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6218. + General Public License for more details.
  6219. +*/
  6220. +
  6221. +#ifndef IPKG_REMOVE_H
  6222. +#define IPKG_REMOVE_H
  6223. +
  6224. +#include "pkg.h"
  6225. +#include "ipkg_conf.h"
  6226. +
  6227. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
  6228. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
  6229. +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
  6230. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents);
  6231. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
  6232. +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6233. +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6234. +
  6235. +
  6236. +#endif
  6237. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_upgrade.c busybox-1.16.1/archival/libipkg/ipkg_upgrade.c
  6238. --- busybox-1.16.1.orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
  6239. +++ busybox-1.16.1/archival/libipkg/ipkg_upgrade.c 2010-06-29 17:31:22.976264794 +0200
  6240. @@ -0,0 +1,79 @@
  6241. +/* ipkg_upgrade.c - the itsy package management system
  6242. +
  6243. + Carl D. Worth
  6244. + Copyright (C) 2001 University of Southern California
  6245. +
  6246. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6247. +
  6248. + This program is free software; you can redistribute it and/or
  6249. + modify it under the terms of the GNU General Public License as
  6250. + published by the Free Software Foundation; either version 2, or (at
  6251. + your option) any later version.
  6252. +
  6253. + This program is distributed in the hope that it will be useful, but
  6254. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6255. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6256. + General Public License for more details.
  6257. +*/
  6258. +
  6259. +#include "ipkg.h"
  6260. +#include "ipkg_install.h"
  6261. +#include "ipkg_message.h"
  6262. +
  6263. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6264. +
  6265. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
  6266. +{
  6267. + pkg_t *new;
  6268. + int cmp;
  6269. + char *old_version, *new_version;
  6270. +
  6271. + if (old->state_flag & SF_HOLD) {
  6272. + ipkg_message(conf, IPKG_NOTICE,
  6273. + "Not upgrading package %s which is marked "
  6274. + "hold (flags=%#x)\n", old->name, old->state_flag);
  6275. + return 0;
  6276. + }
  6277. +
  6278. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
  6279. + if (new == NULL) {
  6280. + old_version = pkg_version_str_alloc(old);
  6281. + ipkg_message(conf, IPKG_NOTICE,
  6282. + "Assuming locally installed package %s (%s) "
  6283. + "is up to date.\n", old->name, old_version);
  6284. + free(old_version);
  6285. + return 0;
  6286. + }
  6287. +
  6288. + old_version = pkg_version_str_alloc(old);
  6289. + new_version = pkg_version_str_alloc(new);
  6290. +
  6291. + cmp = pkg_compare_versions(old, new);
  6292. + ipkg_message(conf, IPKG_DEBUG,
  6293. + "comparing visible versions of pkg %s:"
  6294. + "\n\t%s is installed "
  6295. + "\n\t%s is available "
  6296. + "\n\t%d was comparison result\n",
  6297. + old->name, old_version, new_version, cmp);
  6298. + if (cmp == 0) {
  6299. + ipkg_message(conf, IPKG_INFO,
  6300. + "Package %s (%s) installed in %s is up to date.\n",
  6301. + old->name, old_version, old->dest->name);
  6302. + free(old_version);
  6303. + free(new_version);
  6304. + return 0;
  6305. + } else if (cmp > 0) {
  6306. + ipkg_message(conf, IPKG_NOTICE,
  6307. + "Not downgrading package %s on %s from %s to %s.\n",
  6308. + old->name, old->dest->name, old_version, new_version);
  6309. + free(old_version);
  6310. + free(new_version);
  6311. + return 0;
  6312. + } else if (cmp < 0) {
  6313. + new->dest = old->dest;
  6314. + old->state_want = SW_DEINSTALL;
  6315. + }
  6316. +
  6317. + new->state_flag |= SF_USER;
  6318. + return ipkg_install_pkg(conf, new,1);
  6319. +}
  6320. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_upgrade.h busybox-1.16.1/archival/libipkg/ipkg_upgrade.h
  6321. --- busybox-1.16.1.orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
  6322. +++ busybox-1.16.1/archival/libipkg/ipkg_upgrade.h 2010-06-29 17:31:23.015873328 +0200
  6323. @@ -0,0 +1,18 @@
  6324. +/* ipkg_upgrade.c - the itsy package management system
  6325. +
  6326. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6327. +
  6328. + This program is free software; you can redistribute it and/or
  6329. + modify it under the terms of the GNU General Public License as
  6330. + published by the Free Software Foundation; either version 2, or (at
  6331. + your option) any later version.
  6332. +
  6333. + This program is distributed in the hope that it will be useful, but
  6334. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6335. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6336. + General Public License for more details.
  6337. +*/
  6338. +
  6339. +#include "ipkg.h"
  6340. +
  6341. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6342. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_utils.c busybox-1.16.1/archival/libipkg/ipkg_utils.c
  6343. --- busybox-1.16.1.orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
  6344. +++ busybox-1.16.1/archival/libipkg/ipkg_utils.c 2010-06-29 17:31:23.067592883 +0200
  6345. @@ -0,0 +1,185 @@
  6346. +/* ipkg_utils.c - the itsy package management system
  6347. +
  6348. + Steven M. Ayer
  6349. +
  6350. + Copyright (C) 2002 Compaq Computer Corporation
  6351. +
  6352. + This program is free software; you can redistribute it and/or
  6353. + modify it under the terms of the GNU General Public License as
  6354. + published by the Free Software Foundation; either version 2, or (at
  6355. + your option) any later version.
  6356. +
  6357. + This program is distributed in the hope that it will be useful, but
  6358. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6359. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6360. + General Public License for more details.
  6361. +*/
  6362. +
  6363. +#include "ipkg.h"
  6364. +#include <errno.h>
  6365. +#include <ctype.h>
  6366. +#include <sys/vfs.h>
  6367. +
  6368. +#include "ipkg_utils.h"
  6369. +#include "pkg.h"
  6370. +#include "pkg_hash.h"
  6371. +
  6372. +void push_error_list(struct errlist ** errors, char * msg);
  6373. +void reverse_error_list(struct errlist **errors);
  6374. +void free_error_list(struct errlist **errors);
  6375. +
  6376. +struct errlist* error_list;
  6377. +
  6378. +int get_available_blocks(char * filesystem)
  6379. +{
  6380. + struct statfs sfs;
  6381. +
  6382. + if(statfs(filesystem, &sfs)){
  6383. + fprintf(stderr, "bad statfs\n");
  6384. + return 0;
  6385. + }
  6386. + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
  6387. + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
  6388. +}
  6389. +
  6390. +char **read_raw_pkgs_from_file(const char *file_name)
  6391. +{
  6392. + FILE *fp;
  6393. + char **ret;
  6394. +
  6395. + if(!(fp = fopen(file_name, "r"))){
  6396. + fprintf(stderr, "can't get %s open for read\n", file_name);
  6397. + return NULL;
  6398. + }
  6399. +
  6400. + ret = read_raw_pkgs_from_stream(fp);
  6401. +
  6402. + fclose(fp);
  6403. +
  6404. + return ret;
  6405. +}
  6406. +
  6407. +char **read_raw_pkgs_from_stream(FILE *fp)
  6408. +{
  6409. + char **raw = NULL, *buf, *scout;
  6410. + int count = 0;
  6411. + size_t size = 512;
  6412. +
  6413. + buf = malloc (size);
  6414. +
  6415. + while (fgets(buf, size, fp)) {
  6416. + while (strlen (buf) == (size - 1)
  6417. + && buf[size-2] != '\n') {
  6418. + size_t o = size - 1;
  6419. + size *= 2;
  6420. + buf = realloc (buf, size);
  6421. + if (fgets (buf + o, size - o, fp) == NULL)
  6422. + break;
  6423. + }
  6424. +
  6425. + if(!(count % 50))
  6426. + raw = realloc(raw, (count + 50) * sizeof(char *));
  6427. +
  6428. + if((scout = strchr(buf, '\n')))
  6429. + *scout = '\0';
  6430. +
  6431. + raw[count++] = strdup(buf);
  6432. + }
  6433. +
  6434. + raw = realloc(raw, (count + 1) * sizeof(char *));
  6435. + raw[count] = NULL;
  6436. +
  6437. + free (buf);
  6438. +
  6439. + return raw;
  6440. +}
  6441. +
  6442. +/* something to remove whitespace, a hash pooper */
  6443. +char *trim_alloc(char *line)
  6444. +{
  6445. + char *new;
  6446. + char *dest, *src, *end;
  6447. +
  6448. + new = malloc(strlen(line) + 1);
  6449. + if ( new == NULL ){
  6450. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  6451. + return NULL;
  6452. + }
  6453. + dest = new, src = line, end = line + (strlen(line) - 1);
  6454. +
  6455. + /* remove it from the front */
  6456. + while(src &&
  6457. + isspace(*src) &&
  6458. + *src)
  6459. + src++;
  6460. + /* and now from the back */
  6461. + while((end > src) &&
  6462. + isspace(*end))
  6463. + end--;
  6464. + end++;
  6465. + *end = '\0';
  6466. + strcpy(new, src);
  6467. + /* this does from the first space
  6468. + * blasting away any versions stuff in depends
  6469. + while(src &&
  6470. + !isspace(*src) &&
  6471. + *src)
  6472. + *dest++ = *src++;
  6473. + *dest = '\0';
  6474. + */
  6475. +
  6476. + return new;
  6477. +}
  6478. +
  6479. +int line_is_blank(const char *line)
  6480. +{
  6481. + const char *s;
  6482. +
  6483. + for (s = line; *s; s++) {
  6484. + if (!isspace(*s))
  6485. + return 0;
  6486. + }
  6487. + return 1;
  6488. +}
  6489. +
  6490. +void push_error_list(struct errlist ** errors, char * msg){
  6491. + struct errlist *err_lst_tmp;
  6492. +
  6493. +
  6494. + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
  6495. + err_lst_tmp->errmsg=strdup(msg) ;
  6496. + err_lst_tmp->next = *errors;
  6497. + *errors = err_lst_tmp;
  6498. +}
  6499. +
  6500. +
  6501. +void reverse_error_list(struct errlist **errors){
  6502. + struct errlist *result=NULL;
  6503. + struct errlist *current= *errors;
  6504. + struct errlist *next;
  6505. +
  6506. + while ( current != NULL ) {
  6507. + next = current->next;
  6508. + current->next=result;
  6509. + result=current;
  6510. + current=next;
  6511. + }
  6512. + *errors=result;
  6513. +
  6514. +}
  6515. +
  6516. +
  6517. +void free_error_list(struct errlist **errors){
  6518. + struct errlist *current = *errors;
  6519. +
  6520. + while (current != NULL) {
  6521. + free(current->errmsg);
  6522. + current = (*errors)->next;
  6523. + free(*errors);
  6524. + *errors = current;
  6525. + }
  6526. +
  6527. +
  6528. +}
  6529. +
  6530. +
  6531. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_utils.h busybox-1.16.1/archival/libipkg/ipkg_utils.h
  6532. --- busybox-1.16.1.orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
  6533. +++ busybox-1.16.1/archival/libipkg/ipkg_utils.h 2010-06-29 17:31:23.105873432 +0200
  6534. @@ -0,0 +1,29 @@
  6535. +/* ipkg_utils.h - the itsy package management system
  6536. +
  6537. + Steven M. Ayer
  6538. +
  6539. + Copyright (C) 2002 Compaq Computer Corporation
  6540. +
  6541. + This program is free software; you can redistribute it and/or
  6542. + modify it under the terms of the GNU General Public License as
  6543. + published by the Free Software Foundation; either version 2, or (at
  6544. + your option) any later version.
  6545. +
  6546. + This program is distributed in the hope that it will be useful, but
  6547. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6548. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6549. + General Public License for more details.
  6550. +*/
  6551. +
  6552. +#ifndef IPKG_UTILS_H
  6553. +#define IPKG_UTILS_H
  6554. +
  6555. +#include "pkg.h"
  6556. +
  6557. +int get_available_blocks(char * filesystem);
  6558. +char **read_raw_pkgs_from_file(const char *file_name);
  6559. +char **read_raw_pkgs_from_stream(FILE *fp);
  6560. +char *trim_alloc(char * line);
  6561. +int line_is_blank(const char *line);
  6562. +
  6563. +#endif
  6564. diff -Nur busybox-1.16.1.orig/archival/libipkg/Kbuild busybox-1.16.1/archival/libipkg/Kbuild
  6565. --- busybox-1.16.1.orig/archival/libipkg/Kbuild 1970-01-01 01:00:00.000000000 +0100
  6566. +++ busybox-1.16.1/archival/libipkg/Kbuild 2010-06-29 17:31:23.145868229 +0200
  6567. @@ -0,0 +1,60 @@
  6568. +# Makefile for busybox
  6569. +#
  6570. +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  6571. +# Copyright (C) 2006 OpenWrt.org
  6572. +#
  6573. +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  6574. +
  6575. +LIBIPKG_CORE_OBJS:= \
  6576. + args.o \
  6577. + libipkg.o \
  6578. + user.o \
  6579. +
  6580. +LIBIPKG_CMD_OBJS:= \
  6581. + ipkg_cmd.o \
  6582. + ipkg_configure.o \
  6583. + ipkg_download.o \
  6584. + ipkg_install.o \
  6585. + ipkg_remove.o \
  6586. + ipkg_upgrade.o \
  6587. +
  6588. +LIBIPKG_DB_OBJS:= \
  6589. + hash_table.o \
  6590. + ipkg_conf.o \
  6591. + ipkg_utils.o \
  6592. + pkg.o \
  6593. + pkg_depends.o \
  6594. + pkg_extract.o \
  6595. + pkg_hash.o \
  6596. + pkg_parse.o \
  6597. + pkg_vec.o \
  6598. +
  6599. +LIBIPKG_LIST_OBJS:= \
  6600. + conffile.o \
  6601. + conffile_list.o \
  6602. + nv_pair.o \
  6603. + nv_pair_list.o \
  6604. + pkg_dest.o \
  6605. + pkg_dest_list.o \
  6606. + pkg_src.o \
  6607. + pkg_src_list.o \
  6608. + str_list.o \
  6609. + void_list.o \
  6610. +
  6611. +LIBIPKG_UTIL_OBJS:= \
  6612. + file_util.o \
  6613. + ipkg_message.o \
  6614. + str_util.o \
  6615. + xsystem.o \
  6616. +
  6617. +lib-y :=
  6618. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
  6619. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
  6620. +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
  6621. +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
  6622. +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
  6623. +
  6624. +ifeq ($(strip $(IPKG_ARCH)),)
  6625. +IPKG_ARCH:=$(TARGET_ARCH)
  6626. +endif
  6627. +CFLAGS += -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
  6628. diff -Nur busybox-1.16.1.orig/archival/libipkg/libipkg.c busybox-1.16.1/archival/libipkg/libipkg.c
  6629. --- busybox-1.16.1.orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
  6630. +++ busybox-1.16.1/archival/libipkg/libipkg.c 2010-06-29 17:35:49.219617937 +0200
  6631. @@ -0,0 +1,532 @@
  6632. +/* ipkglib.c - the itsy package management system
  6633. +
  6634. + Florina Boor
  6635. +
  6636. + Copyright (C) 2003 kernel concepts
  6637. +
  6638. + This program is free software; you can redistribute it and/or
  6639. + modify it under the terms of the GNU General Public License as
  6640. + published by the Free Software Foundation; either version 2, or (at
  6641. + your option) any later version.
  6642. +
  6643. + This program is distributed in the hope that it will be useful, but
  6644. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6645. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6646. + General Public License for more details.
  6647. +*/
  6648. +
  6649. +#include "ipkg.h"
  6650. +#include "ipkg_includes.h"
  6651. +#include "libipkg.h"
  6652. +
  6653. +#include "args.h"
  6654. +#include "ipkg_conf.h"
  6655. +#include "ipkg_cmd.h"
  6656. +#include "file_util.h"
  6657. +
  6658. +int ipkg_file_what(args_t *args, const char *file, const char* command);
  6659. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  6660. + char *msg);
  6661. +int default_ipkg_list_callback(char *name, char *desc, char *version);
  6662. +int default_ipkg_files_callback(char *desc);
  6663. +int default_ipkg_status_callback(char *desc);
  6664. +char* default_ipkg_response_callback(char *question);
  6665. +
  6666. +
  6667. +ipkg_message_callback ipkg_cb_message = NULL;
  6668. +ipkg_response_callback ipkg_cb_response = NULL;
  6669. +ipkg_status_callback ipkg_cb_status = NULL;
  6670. +ipkg_list_callback ipkg_cb_list = NULL;
  6671. +
  6672. +
  6673. +int
  6674. +ipkg_init (ipkg_message_callback mcall,
  6675. + ipkg_response_callback rcall,
  6676. + args_t * args)
  6677. +{
  6678. + ipkg_cb_message = mcall;
  6679. + ipkg_cb_response = rcall;
  6680. +
  6681. + args_init (args);
  6682. +
  6683. + return 0;
  6684. +}
  6685. +
  6686. +
  6687. +int
  6688. +ipkg_deinit (args_t * args)
  6689. +{
  6690. + args_deinit (args);
  6691. + ipkg_cb_message = NULL;
  6692. + ipkg_cb_response = NULL;
  6693. +
  6694. + /* place other cleanup stuff here */
  6695. +
  6696. + return 0;
  6697. +}
  6698. +
  6699. +
  6700. +int
  6701. +ipkg_packages_list(args_t *args,
  6702. + const char *packages,
  6703. + ipkg_list_callback cblist,
  6704. + void *userdata)
  6705. +{
  6706. + ipkg_cmd_t *cmd;
  6707. + ipkg_conf_t ipkg_conf;
  6708. + int err;
  6709. +
  6710. + err = ipkg_conf_init (&ipkg_conf, args);
  6711. + if (err)
  6712. + {
  6713. + return err;
  6714. + }
  6715. +
  6716. + ipkg_cb_list = cblist;
  6717. + /* we need to do this because of static declarations,
  6718. + * maybe a good idea to change */
  6719. + cmd = ipkg_cmd_find ("list");
  6720. + if (packages)
  6721. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6722. + else
  6723. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6724. + ipkg_cb_list = NULL;
  6725. + ipkg_conf_deinit (&ipkg_conf);
  6726. + return (err);
  6727. +}
  6728. +
  6729. +
  6730. +int
  6731. +ipkg_packages_status(args_t *args,
  6732. + const char *packages,
  6733. + ipkg_status_callback cbstatus,
  6734. + void *userdata)
  6735. +{
  6736. + ipkg_cmd_t *cmd;
  6737. + ipkg_conf_t ipkg_conf;
  6738. + int err;
  6739. +
  6740. + err = ipkg_conf_init (&ipkg_conf, args);
  6741. + if (err)
  6742. + {
  6743. + return err;
  6744. + }
  6745. +
  6746. + ipkg_cb_status = cbstatus;
  6747. +
  6748. + /* we need to do this because of static declarations,
  6749. + * maybe a good idea to change */
  6750. + cmd = ipkg_cmd_find ("status");
  6751. + if (packages)
  6752. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6753. + else
  6754. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6755. +
  6756. + ipkg_cb_status = NULL;
  6757. + ipkg_conf_deinit (&ipkg_conf);
  6758. + return (err);
  6759. +}
  6760. +
  6761. +
  6762. +int
  6763. +ipkg_packages_info(args_t *args,
  6764. + const char *packages,
  6765. + ipkg_status_callback cbstatus,
  6766. + void *userdata)
  6767. +{
  6768. + ipkg_cmd_t *cmd;
  6769. + ipkg_conf_t ipkg_conf;
  6770. + int err;
  6771. +
  6772. + err = ipkg_conf_init (&ipkg_conf, args);
  6773. + if (err)
  6774. + {
  6775. + return err;
  6776. + }
  6777. +
  6778. + ipkg_cb_status = cbstatus;
  6779. +
  6780. + /* we need to do this because of static declarations,
  6781. + * maybe a good idea to change */
  6782. + cmd = ipkg_cmd_find ("info");
  6783. + if (packages)
  6784. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6785. + else
  6786. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6787. +
  6788. + ipkg_cb_status = NULL;
  6789. + ipkg_conf_deinit (&ipkg_conf);
  6790. + return (err);
  6791. +}
  6792. +
  6793. +
  6794. +int
  6795. +ipkg_packages_install (args_t * args, const char *name)
  6796. +{
  6797. + ipkg_cmd_t *cmd;
  6798. + ipkg_conf_t ipkg_conf;
  6799. + int err;
  6800. +
  6801. + /* this error should be handled in application */
  6802. + if (!name || !strlen (name))
  6803. + return (-1);
  6804. +
  6805. + err = ipkg_conf_init (&ipkg_conf, args);
  6806. + if (err)
  6807. + {
  6808. + return err;
  6809. + }
  6810. +
  6811. + /* we need to do this because of static declarations,
  6812. + * maybe a good idea to change */
  6813. + cmd = ipkg_cmd_find ("install");
  6814. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6815. +
  6816. + ipkg_conf_deinit(&ipkg_conf);
  6817. + return (err);
  6818. +}
  6819. +
  6820. +
  6821. +int
  6822. +ipkg_packages_remove(args_t *args, const char *name, int purge)
  6823. +{
  6824. + ipkg_cmd_t *cmd;
  6825. + ipkg_conf_t ipkg_conf;
  6826. + int err;
  6827. +
  6828. + /* this error should be handled in application */
  6829. + if (!name || !strlen (name))
  6830. + return (-1);
  6831. +
  6832. + err = ipkg_conf_init (&ipkg_conf, args);
  6833. + if (err)
  6834. + {
  6835. + return err;
  6836. + }
  6837. +
  6838. + /* we need to do this because of static declarations,
  6839. + * maybe a good idea to change */
  6840. + if (purge)
  6841. + cmd = ipkg_cmd_find ("purge");
  6842. + else
  6843. + cmd = ipkg_cmd_find ("remove");
  6844. +
  6845. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6846. +
  6847. + ipkg_conf_deinit(&ipkg_conf);
  6848. + return (err);
  6849. +}
  6850. +
  6851. +
  6852. +int
  6853. +ipkg_lists_update(args_t *args)
  6854. +{
  6855. + ipkg_cmd_t *cmd;
  6856. + ipkg_conf_t ipkg_conf;
  6857. + int err;
  6858. +
  6859. + err = ipkg_conf_init (&ipkg_conf, args);
  6860. + if (err)
  6861. + {
  6862. + return err;
  6863. + }
  6864. +
  6865. + /* we need to do this because of static declarations,
  6866. + * maybe a good idea to change */
  6867. + cmd = ipkg_cmd_find ("update");
  6868. +
  6869. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6870. +
  6871. + ipkg_conf_deinit(&ipkg_conf);
  6872. + return (err);
  6873. +}
  6874. +
  6875. +
  6876. +int
  6877. +ipkg_packages_upgrade(args_t *args)
  6878. +{
  6879. + ipkg_cmd_t *cmd;
  6880. + ipkg_conf_t ipkg_conf;
  6881. + int err;
  6882. +
  6883. + err = ipkg_conf_init (&ipkg_conf, args);
  6884. + if (err)
  6885. + {
  6886. + return err;
  6887. + }
  6888. +
  6889. + /* we need to do this because of static declarations,
  6890. + * maybe a good idea to change */
  6891. + cmd = ipkg_cmd_find ("upgrade");
  6892. +
  6893. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6894. +
  6895. + ipkg_conf_deinit(&ipkg_conf);
  6896. + return (err);
  6897. +}
  6898. +
  6899. +
  6900. +int
  6901. +ipkg_packages_download (args_t * args, const char *name)
  6902. +{
  6903. + ipkg_cmd_t *cmd;
  6904. + ipkg_conf_t ipkg_conf;
  6905. + int err;
  6906. +
  6907. + /* this error should be handled in application */
  6908. + if (!name || !strlen (name))
  6909. + return (-1);
  6910. +
  6911. + err = ipkg_conf_init (&ipkg_conf, args);
  6912. + if (err)
  6913. + {
  6914. + return err;
  6915. + }
  6916. +
  6917. + /* we need to do this because of static declarations,
  6918. + * maybe a good idea to change */
  6919. + cmd = ipkg_cmd_find ("download");
  6920. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6921. +
  6922. + ipkg_conf_deinit(&ipkg_conf);
  6923. + return (err);
  6924. +}
  6925. +
  6926. +
  6927. +int
  6928. +ipkg_package_files(args_t *args,
  6929. + const char *name,
  6930. + ipkg_list_callback cblist,
  6931. + void *userdata)
  6932. +{
  6933. + ipkg_cmd_t *cmd;
  6934. + ipkg_conf_t ipkg_conf;
  6935. + int err;
  6936. +
  6937. + /* this error should be handled in application */
  6938. + if (!name || !strlen (name))
  6939. + return (-1);
  6940. +
  6941. + err = ipkg_conf_init (&ipkg_conf, args);
  6942. + if (err)
  6943. + {
  6944. + return err;
  6945. + }
  6946. +
  6947. + ipkg_cb_list = cblist;
  6948. +
  6949. + /* we need to do this because of static declarations,
  6950. + * maybe a good idea to change */
  6951. + cmd = ipkg_cmd_find ("files");
  6952. +
  6953. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
  6954. +
  6955. + ipkg_cb_list = NULL;
  6956. + ipkg_conf_deinit(&ipkg_conf);
  6957. + return (err);
  6958. +}
  6959. +
  6960. +
  6961. +int
  6962. +ipkg_file_search(args_t *args,
  6963. + const char *file,
  6964. + ipkg_list_callback cblist,
  6965. + void *userdata)
  6966. +{
  6967. + ipkg_cmd_t *cmd;
  6968. + ipkg_conf_t ipkg_conf;
  6969. + int err;
  6970. +
  6971. + /* this error should be handled in application */
  6972. + if (!file || !strlen (file))
  6973. + return (-1);
  6974. +
  6975. + err = ipkg_conf_init (&ipkg_conf, args);
  6976. + if (err)
  6977. + {
  6978. + return err;
  6979. + }
  6980. +
  6981. + ipkg_cb_list = cblist;
  6982. +
  6983. + /* we need to do this because of static declarations,
  6984. + * maybe a good idea to change */
  6985. + cmd = ipkg_cmd_find ("search");
  6986. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
  6987. +
  6988. + ipkg_cb_list = NULL;
  6989. + ipkg_conf_deinit(&ipkg_conf);
  6990. + return(err);
  6991. +}
  6992. +
  6993. +
  6994. +int
  6995. +ipkg_file_what(args_t *args, const char *file, const char* command)
  6996. +{
  6997. + ipkg_cmd_t *cmd;
  6998. + ipkg_conf_t ipkg_conf;
  6999. + int err;
  7000. +
  7001. + /* this error should be handled in application */
  7002. + if (!file || !strlen (file))
  7003. + return (-1);
  7004. +
  7005. + err = ipkg_conf_init (&ipkg_conf, args);
  7006. + if (err)
  7007. + {
  7008. + return err;
  7009. + }
  7010. +
  7011. + /* we need to do this because of static declarations,
  7012. + * maybe a good idea to change */
  7013. + cmd = ipkg_cmd_find (command);
  7014. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
  7015. +
  7016. + ipkg_conf_deinit(&ipkg_conf);
  7017. + return(err);
  7018. +}
  7019. +
  7020. +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
  7021. +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
  7022. +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
  7023. +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
  7024. +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
  7025. +
  7026. +
  7027. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  7028. + char *msg)
  7029. +{
  7030. + if (conf && (conf->verbosity < level)) {
  7031. + return 0;
  7032. + } else {
  7033. + if ( level == IPKG_ERROR )
  7034. + push_error_list(&error_list, msg);
  7035. + else
  7036. + printf(msg);
  7037. + }
  7038. + return 0;
  7039. +}
  7040. +
  7041. +int default_ipkg_list_callback(char *name, char *desc, char *version)
  7042. +{
  7043. + if (desc)
  7044. + printf("%s - %s - %s\n", name, version, desc);
  7045. + else
  7046. + printf("%s - %s\n", name, version);
  7047. + return 0;
  7048. +}
  7049. +
  7050. +int default_ipkg_files_callback(char *desc)
  7051. +{
  7052. + if (desc)
  7053. + printf("%s\n", desc);
  7054. + return 0;
  7055. +}
  7056. +
  7057. +int default_ipkg_status_callback(char *desc)
  7058. +{
  7059. + printf("%s\n", desc);
  7060. + return 0;
  7061. +}
  7062. +
  7063. +char* default_ipkg_response_callback(char *question)
  7064. +{
  7065. + char *response = NULL;
  7066. + printf(question);
  7067. + fflush(stdout);
  7068. + do {
  7069. + response = (char *)file_read_line_alloc(stdin);
  7070. + } while (response == NULL);
  7071. + return response;
  7072. +}
  7073. +
  7074. +/* This is used for backward compatibility */
  7075. +int
  7076. +ipkg_op (int argc, char *argv[])
  7077. +{
  7078. + int err, optind_;
  7079. + args_t args;
  7080. + char *cmd_name;
  7081. + ipkg_cmd_t *cmd;
  7082. + ipkg_conf_t ipkg_conf;
  7083. + const char *message = "ipkg must have one sub-command argument";
  7084. +
  7085. + /* mount rootfs read-write */
  7086. + if (mount("","/",0,MS_REMOUNT,0)<0)
  7087. + fprintf (stderr, "Mounting rootfs read-write failed\n");
  7088. +
  7089. + args_init (&args);
  7090. +
  7091. + optind_ = args_parse (&args, argc, argv);
  7092. + if (optind_ == argc || optind_ < 0)
  7093. + {
  7094. + args_usage(message);
  7095. + }
  7096. +
  7097. + cmd_name = argv[optind_++];
  7098. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  7099. + read anything from there.
  7100. +*/
  7101. + if ( !strcmp(cmd_name,"print-architecture") ||
  7102. + !strcmp(cmd_name,"print_architecture") ||
  7103. + !strcmp(cmd_name,"print-installation-architecture") ||
  7104. + !strcmp(cmd_name,"print_installation_architecture") )
  7105. + args.nocheckfordirorfile = 1;
  7106. +
  7107. +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
  7108. + read anything from there.
  7109. +*/
  7110. + if ( !strcmp(cmd_name,"flag") ||
  7111. + !strcmp(cmd_name,"configure") ||
  7112. + !strcmp(cmd_name,"remove") ||
  7113. + !strcmp(cmd_name,"files") ||
  7114. + !strcmp(cmd_name,"search") ||
  7115. + !strcmp(cmd_name,"compare_versions") ||
  7116. + !strcmp(cmd_name,"compare-versions") ||
  7117. + !strcmp(cmd_name,"list_installed") ||
  7118. + !strcmp(cmd_name,"list-installed") ||
  7119. + !strcmp(cmd_name,"status") )
  7120. + args.noreadfeedsfile = 1;
  7121. +
  7122. +
  7123. + err = ipkg_conf_init (&ipkg_conf, &args);
  7124. + if (err)
  7125. + {
  7126. + return err;
  7127. + }
  7128. +
  7129. + args_deinit (&args);
  7130. +
  7131. + ipkg_cb_message = default_ipkg_message_callback;
  7132. + ipkg_cb_response = default_ipkg_response_callback;
  7133. + ipkg_cb_status = (ipkg_status_callback)default_ipkg_status_callback;
  7134. + if ( strcmp(cmd_name, "files")==0)
  7135. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_files_callback;
  7136. + else
  7137. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_list_callback;
  7138. +
  7139. + cmd = ipkg_cmd_find (cmd_name);
  7140. + if (cmd == NULL)
  7141. + {
  7142. + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
  7143. + cmd_name);
  7144. + args_usage (NULL);
  7145. + }
  7146. +
  7147. + if (cmd->requires_args && optind_ == argc)
  7148. + {
  7149. + fprintf (stderr,
  7150. + "%s: the ``%s'' command requires at least one argument\n",
  7151. + __FUNCTION__, cmd_name);
  7152. + args_usage (NULL);
  7153. + }
  7154. +
  7155. + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind_, (const char **) (argv + optind_), NULL);
  7156. +
  7157. + ipkg_conf_deinit (&ipkg_conf);
  7158. + /* mount rootfs read-only */
  7159. + if (mount("","/",0,MS_REMOUNT|MS_RDONLY,0)<0)
  7160. + fprintf (stderr, "Mounting rootfs read-only failed\n");
  7161. +
  7162. + return err;
  7163. +}
  7164. diff -Nur busybox-1.16.1.orig/archival/libipkg/libipkg.h busybox-1.16.1/archival/libipkg/libipkg.h
  7165. --- busybox-1.16.1.orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
  7166. +++ busybox-1.16.1/archival/libipkg/libipkg.h 2010-06-29 17:31:24.283460019 +0200
  7167. @@ -0,0 +1,78 @@
  7168. +/* ipkglib.h - the itsy package management system
  7169. +
  7170. + Florian Boor <florian.boor@kernelconcepts.de>
  7171. +
  7172. + This program is free software; you can redistribute it and/or
  7173. + modify it under the terms of the GNU General Public License as
  7174. + published by the Free Software Foundation; either version 2, or (at
  7175. + your option) any later version.
  7176. +
  7177. + This program is distributed in the hope that it will be useful, but
  7178. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7179. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7180. + General Public License for more details.
  7181. +*/
  7182. +
  7183. +#ifndef IPKGLIB_H
  7184. +#define IPKGLIB_H
  7185. +
  7186. +#include "ipkg_conf.h"
  7187. +#include "ipkg_message.h"
  7188. +
  7189. +#include "args.h"
  7190. +#include "pkg.h"
  7191. +
  7192. +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
  7193. + char *msg);
  7194. +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
  7195. + pkg_state_status_t status, void *userdata);
  7196. +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
  7197. + void *userdata);
  7198. +typedef char* (*ipkg_response_callback)(char *question);
  7199. +
  7200. +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
  7201. +extern int ipkg_init (ipkg_message_callback mcall,
  7202. + ipkg_response_callback rcall,
  7203. + args_t * args);
  7204. +
  7205. +extern int ipkg_deinit (args_t *args);
  7206. +extern int ipkg_packages_list(args_t *args,
  7207. + const char *packages,
  7208. + ipkg_list_callback cblist,
  7209. + void *userdata);
  7210. +extern int ipkg_packages_status(args_t *args,
  7211. + const char *packages,
  7212. + ipkg_status_callback cbstatus,
  7213. + void *userdata);
  7214. +extern int ipkg_packages_info(args_t *args,
  7215. + const char *packages,
  7216. + ipkg_status_callback cbstatus,
  7217. + void *userdata);
  7218. +extern int ipkg_packages_install(args_t *args, const char *name);
  7219. +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
  7220. +extern int ipkg_lists_update(args_t *args);
  7221. +extern int ipkg_packages_upgrade(args_t *args);
  7222. +extern int ipkg_packages_download(args_t *args, const char *name);
  7223. +extern int ipkg_package_files(args_t *args,
  7224. + const char *name,
  7225. + ipkg_list_callback cblist,
  7226. + void *userdata);
  7227. +extern int ipkg_file_search(args_t *args,
  7228. + const char *file,
  7229. + ipkg_list_callback cblist,
  7230. + void *userdata);
  7231. +extern int ipkg_package_whatdepends(args_t *args, const char *file);
  7232. +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
  7233. +extern int ipkg_package_whatprovides(args_t *args, const char *file);
  7234. +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
  7235. +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
  7236. +
  7237. +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
  7238. +extern ipkg_response_callback ipkg_cb_response;
  7239. +extern ipkg_status_callback ipkg_cb_status;
  7240. +extern ipkg_list_callback ipkg_cb_list;
  7241. +extern void push_error_list(struct errlist **errors,char * msg);
  7242. +extern void reverse_error_list(struct errlist **errors);
  7243. +extern void free_error_list(struct errlist **errors);
  7244. +
  7245. +#endif
  7246. diff -Nur busybox-1.16.1.orig/archival/libipkg/nv_pair.c busybox-1.16.1/archival/libipkg/nv_pair.c
  7247. --- busybox-1.16.1.orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
  7248. +++ busybox-1.16.1/archival/libipkg/nv_pair.c 2010-06-29 17:31:24.316180264 +0200
  7249. @@ -0,0 +1,40 @@
  7250. +/* nv_pair.c - the itsy package management system
  7251. +
  7252. + Carl D. Worth
  7253. +
  7254. + Copyright (C) 2001 University of Southern California
  7255. +
  7256. + This program is free software; you can redistribute it and/or
  7257. + modify it under the terms of the GNU General Public License as
  7258. + published by the Free Software Foundation; either version 2, or (at
  7259. + your option) any later version.
  7260. +
  7261. + This program is distributed in the hope that it will be useful, but
  7262. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7263. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7264. + General Public License for more details.
  7265. +*/
  7266. +
  7267. +#include "ipkg.h"
  7268. +
  7269. +#include "nv_pair.h"
  7270. +#include "str_util.h"
  7271. +
  7272. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
  7273. +{
  7274. + nv_pair->name = str_dup_safe(name);
  7275. + nv_pair->value = str_dup_safe(value);
  7276. +
  7277. + return 0;
  7278. +}
  7279. +
  7280. +void nv_pair_deinit(nv_pair_t *nv_pair)
  7281. +{
  7282. + free(nv_pair->name);
  7283. + nv_pair->name = NULL;
  7284. +
  7285. + free(nv_pair->value);
  7286. + nv_pair->value = NULL;
  7287. +}
  7288. +
  7289. +
  7290. diff -Nur busybox-1.16.1.orig/archival/libipkg/nv_pair.h busybox-1.16.1/archival/libipkg/nv_pair.h
  7291. --- busybox-1.16.1.orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
  7292. +++ busybox-1.16.1/archival/libipkg/nv_pair.h 2010-06-29 17:31:24.358376170 +0200
  7293. @@ -0,0 +1,32 @@
  7294. +/* nv_pair.h - the itsy package management system
  7295. +
  7296. + Carl D. Worth
  7297. +
  7298. + Copyright (C) 2001 University of Southern California
  7299. +
  7300. + This program is free software; you can redistribute it and/or
  7301. + modify it under the terms of the GNU General Public License as
  7302. + published by the Free Software Foundation; either version 2, or (at
  7303. + your option) any later version.
  7304. +
  7305. + This program is distributed in the hope that it will be useful, but
  7306. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7307. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7308. + General Public License for more details.
  7309. +*/
  7310. +
  7311. +#ifndef NV_PAIR_H
  7312. +#define NV_PAIR_H
  7313. +
  7314. +typedef struct nv_pair nv_pair_t;
  7315. +struct nv_pair
  7316. +{
  7317. + char *name;
  7318. + char *value;
  7319. +};
  7320. +
  7321. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
  7322. +void nv_pair_deinit(nv_pair_t *nv_pair);
  7323. +
  7324. +#endif
  7325. +
  7326. diff -Nur busybox-1.16.1.orig/archival/libipkg/nv_pair_list.c busybox-1.16.1/archival/libipkg/nv_pair_list.c
  7327. --- busybox-1.16.1.orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
  7328. +++ busybox-1.16.1/archival/libipkg/nv_pair_list.c 2010-06-29 17:31:24.395873641 +0200
  7329. @@ -0,0 +1,98 @@
  7330. +/* nv_pair_list.c - the itsy package management system
  7331. +
  7332. + Carl D. Worth
  7333. +
  7334. + Copyright (C) 2001 University of Southern California
  7335. +
  7336. + This program is free software; you can redistribute it and/or
  7337. + modify it under the terms of the GNU General Public License as
  7338. + published by the Free Software Foundation; either version 2, or (at
  7339. + your option) any later version.
  7340. +
  7341. + This program is distributed in the hope that it will be useful, but
  7342. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7343. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7344. + General Public License for more details.
  7345. +*/
  7346. +
  7347. +#include "ipkg.h"
  7348. +
  7349. +#include "nv_pair.h"
  7350. +#include "void_list.h"
  7351. +#include "nv_pair_list.h"
  7352. +
  7353. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
  7354. +{
  7355. + return void_list_elt_init((void_list_elt_t *) elt, data);
  7356. +}
  7357. +
  7358. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
  7359. +{
  7360. + void_list_elt_deinit((void_list_elt_t *) elt);
  7361. +}
  7362. +
  7363. +int nv_pair_list_init(nv_pair_list_t *list)
  7364. +{
  7365. + return void_list_init((void_list_t *) list);
  7366. +}
  7367. +
  7368. +void nv_pair_list_deinit(nv_pair_list_t *list)
  7369. +{
  7370. + nv_pair_list_elt_t *iter;
  7371. + nv_pair_t *nv_pair;
  7372. +
  7373. + for (iter = list->head; iter; iter = iter->next) {
  7374. + nv_pair = iter->data;
  7375. + nv_pair_deinit(nv_pair);
  7376. +
  7377. + /* malloced in nv_pair_list_append */
  7378. + free(nv_pair);
  7379. + iter->data = NULL;
  7380. + }
  7381. + void_list_deinit((void_list_t *) list);
  7382. +}
  7383. +
  7384. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
  7385. +{
  7386. + int err;
  7387. +
  7388. + /* freed in nv_pair_list_deinit */
  7389. + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
  7390. +
  7391. + if (nv_pair == NULL) {
  7392. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7393. + return NULL;
  7394. + }
  7395. + nv_pair_init(nv_pair, name, value);
  7396. +
  7397. + err = void_list_append((void_list_t *) list, nv_pair);
  7398. + if (err) {
  7399. + return NULL;
  7400. + }
  7401. +
  7402. + return nv_pair;
  7403. +}
  7404. +
  7405. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
  7406. +{
  7407. + return void_list_push((void_list_t *) list, data);
  7408. +}
  7409. +
  7410. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
  7411. +{
  7412. + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
  7413. +}
  7414. +
  7415. +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
  7416. +{
  7417. + nv_pair_list_elt_t *iter;
  7418. + nv_pair_t *nv_pair;
  7419. +
  7420. + for (iter = list->head; iter; iter = iter->next) {
  7421. + nv_pair = iter->data;
  7422. + if (strcmp(nv_pair->name, name) == 0) {
  7423. + return nv_pair->value;
  7424. + }
  7425. + }
  7426. + return NULL;
  7427. +}
  7428. diff -Nur busybox-1.16.1.orig/archival/libipkg/nv_pair_list.h busybox-1.16.1/archival/libipkg/nv_pair_list.h
  7429. --- busybox-1.16.1.orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
  7430. +++ busybox-1.16.1/archival/libipkg/nv_pair_list.h 2010-06-29 17:31:24.439618049 +0200
  7431. @@ -0,0 +1,60 @@
  7432. +/* nv_pair_list.h - the itsy package management system
  7433. +
  7434. + Carl D. Worth
  7435. +
  7436. + Copyright (C) 2001 University of Southern California
  7437. +
  7438. + This program is free software; you can redistribute it and/or
  7439. + modify it under the terms of the GNU General Public License as
  7440. + published by the Free Software Foundation; either version 2, or (at
  7441. + your option) any later version.
  7442. +
  7443. + This program is distributed in the hope that it will be useful, but
  7444. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7445. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7446. + General Public License for more details.
  7447. +*/
  7448. +
  7449. +#ifndef NV_PAIR_LIST_H
  7450. +#define NV_PAIR_LIST_H
  7451. +
  7452. +#include "nv_pair.h"
  7453. +#include "void_list.h"
  7454. +
  7455. +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
  7456. +struct nv_pair_list_elt
  7457. +{
  7458. + nv_pair_list_elt_t *next;
  7459. + nv_pair_t *data;
  7460. +};
  7461. +
  7462. +typedef struct nv_pair_list nv_pair_list_t;
  7463. +struct nv_pair_list
  7464. +{
  7465. + nv_pair_list_elt_t pre_head;
  7466. + nv_pair_list_elt_t *head;
  7467. + nv_pair_list_elt_t *tail;
  7468. +};
  7469. +
  7470. +static inline int nv_pair_list_empty(nv_pair_list_t *list)
  7471. +{
  7472. + if (list->head == NULL)
  7473. + return 1;
  7474. + else
  7475. + return 0;
  7476. +}
  7477. +
  7478. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
  7479. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
  7480. +
  7481. +int nv_pair_list_init(nv_pair_list_t *list);
  7482. +void nv_pair_list_deinit(nv_pair_list_t *list);
  7483. +
  7484. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
  7485. + const char *name, const char *value);
  7486. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
  7487. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
  7488. +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
  7489. +
  7490. +#endif
  7491. +
  7492. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg.c busybox-1.16.1/archival/libipkg/pkg.c
  7493. --- busybox-1.16.1.orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
  7494. +++ busybox-1.16.1/archival/libipkg/pkg.c 2010-06-29 17:31:24.502860549 +0200
  7495. @@ -0,0 +1,1757 @@
  7496. +/* pkg.c - the itsy package management system
  7497. +
  7498. + Carl D. Worth
  7499. +
  7500. + Copyright (C) 2001 University of Southern California
  7501. +
  7502. + This program is free software; you can redistribute it and/or
  7503. + modify it under the terms of the GNU General Public License as
  7504. + published by the Free Software Foundation; either version 2, or (at
  7505. + your option) any later version.
  7506. +
  7507. + This program is distributed in the hope that it will be useful, but
  7508. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7509. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7510. + General Public License for more details.
  7511. +*/
  7512. +
  7513. +#include "ipkg.h"
  7514. +#include <ctype.h>
  7515. +#include <string.h>
  7516. +#include <errno.h>
  7517. +
  7518. +#include "pkg.h"
  7519. +
  7520. +#include "pkg_parse.h"
  7521. +#include "pkg_extract.h"
  7522. +#include "ipkg_message.h"
  7523. +#include "ipkg_utils.h"
  7524. +
  7525. +#include "sprintf_alloc.h"
  7526. +#include "file_util.h"
  7527. +#include "str_util.h"
  7528. +#include "xsystem.h"
  7529. +#include "ipkg_conf.h"
  7530. +
  7531. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname);
  7532. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_);
  7533. +
  7534. +typedef struct enum_map enum_map_t;
  7535. +struct enum_map
  7536. +{
  7537. + int value;
  7538. + const char *str;
  7539. +};
  7540. +
  7541. +static const enum_map_t pkg_state_want_map[] = {
  7542. + { SW_UNKNOWN, "unknown"},
  7543. + { SW_INSTALL, "install"},
  7544. + { SW_DEINSTALL, "deinstall"},
  7545. + { SW_PURGE, "purge"}
  7546. +};
  7547. +
  7548. +static const enum_map_t pkg_state_flag_map[] = {
  7549. + { SF_OK, "ok"},
  7550. + { SF_REINSTREQ, "reinstreq"},
  7551. + { SF_HOLD, "hold"},
  7552. + { SF_REPLACE, "replace"},
  7553. + { SF_NOPRUNE, "noprune"},
  7554. + { SF_PREFER, "prefer"},
  7555. + { SF_OBSOLETE, "obsolete"},
  7556. + { SF_USER, "user"},
  7557. +};
  7558. +
  7559. +static const enum_map_t pkg_state_status_map[] = {
  7560. + { SS_NOT_INSTALLED, "not-installed" },
  7561. + { SS_UNPACKED, "unpacked" },
  7562. + { SS_HALF_CONFIGURED, "half-configured" },
  7563. + { SS_INSTALLED, "installed" },
  7564. + { SS_HALF_INSTALLED, "half-installed" },
  7565. + { SS_CONFIG_FILES, "config-files" },
  7566. + { SS_POST_INST_FAILED, "post-inst-failed" },
  7567. + { SS_REMOVAL_FAILED, "removal-failed" }
  7568. +};
  7569. +
  7570. +static int verrevcmp(const char *val, const char *ref);
  7571. +
  7572. +
  7573. +pkg_t *pkg_new(void)
  7574. +{
  7575. + pkg_t *pkg;
  7576. +
  7577. + pkg = malloc(sizeof(pkg_t));
  7578. + if (pkg == NULL) {
  7579. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7580. + return NULL;
  7581. + }
  7582. +
  7583. + pkg_init(pkg);
  7584. +
  7585. + return pkg;
  7586. +}
  7587. +
  7588. +int pkg_init(pkg_t *pkg)
  7589. +{
  7590. + memset(pkg, 0, sizeof(pkg_t));
  7591. + pkg->name = NULL;
  7592. + pkg->epoch = 0;
  7593. + pkg->version = NULL;
  7594. + pkg->revision = NULL;
  7595. + pkg->familiar_revision = NULL;
  7596. + pkg->dest = NULL;
  7597. + pkg->src = NULL;
  7598. + pkg->architecture = NULL;
  7599. + pkg->maintainer = NULL;
  7600. + pkg->section = NULL;
  7601. + pkg->description = NULL;
  7602. + pkg->state_want = SW_UNKNOWN;
  7603. + pkg->state_flag = SF_OK;
  7604. + pkg->state_status = SS_NOT_INSTALLED;
  7605. + pkg->depends_str = NULL;
  7606. + pkg->provides_str = NULL;
  7607. + pkg->depends_count = 0;
  7608. + pkg->depends = NULL;
  7609. + pkg->suggests_str = NULL;
  7610. + pkg->recommends_str = NULL;
  7611. + pkg->suggests_count = 0;
  7612. + pkg->recommends_count = 0;
  7613. +
  7614. + /* Abhaya: added init for conflicts fields */
  7615. + pkg->conflicts = NULL;
  7616. + pkg->conflicts_count = 0;
  7617. +
  7618. + /* added for replaces. Jamey 7/23/2002 */
  7619. + pkg->replaces = NULL;
  7620. + pkg->replaces_count = 0;
  7621. +
  7622. + pkg->pre_depends_count = 0;
  7623. + pkg->pre_depends_str = NULL;
  7624. + pkg->provides_count = 0;
  7625. + pkg->provides = NULL;
  7626. + pkg->filename = NULL;
  7627. + pkg->local_filename = NULL;
  7628. + pkg->tmp_unpack_dir = NULL;
  7629. + pkg->md5sum = NULL;
  7630. + pkg->size = NULL;
  7631. + pkg->installed_size = NULL;
  7632. + pkg->priority = NULL;
  7633. + pkg->source = NULL;
  7634. + conffile_list_init(&pkg->conffiles);
  7635. + pkg->installed_files = NULL;
  7636. + pkg->installed_files_ref_cnt = 0;
  7637. + pkg->essential = 0;
  7638. + pkg->provided_by_hand = 0;
  7639. +
  7640. + return 0;
  7641. +}
  7642. +
  7643. +void pkg_deinit(pkg_t *pkg)
  7644. +{
  7645. + free(pkg->name);
  7646. + pkg->name = NULL;
  7647. + pkg->epoch = 0;
  7648. + free(pkg->version);
  7649. + pkg->version = NULL;
  7650. + /* revision and familiar_revision share storage with version, so
  7651. + don't free */
  7652. + pkg->revision = NULL;
  7653. + pkg->familiar_revision = NULL;
  7654. + /* owned by ipkg_conf_t */
  7655. + pkg->dest = NULL;
  7656. + /* owned by ipkg_conf_t */
  7657. + pkg->src = NULL;
  7658. + free(pkg->architecture);
  7659. + pkg->architecture = NULL;
  7660. + free(pkg->maintainer);
  7661. + pkg->maintainer = NULL;
  7662. + free(pkg->section);
  7663. + pkg->section = NULL;
  7664. + free(pkg->description);
  7665. + pkg->description = NULL;
  7666. + pkg->state_want = SW_UNKNOWN;
  7667. + pkg->state_flag = SF_OK;
  7668. + pkg->state_status = SS_NOT_INSTALLED;
  7669. + free(pkg->depends_str);
  7670. + pkg->depends_str = NULL;
  7671. + free(pkg->provides_str);
  7672. + pkg->provides_str = NULL;
  7673. + pkg->depends_count = 0;
  7674. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
  7675. + pkg->pre_depends_count = 0;
  7676. + free(pkg->pre_depends_str);
  7677. + pkg->pre_depends_str = NULL;
  7678. + pkg->provides_count = 0;
  7679. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
  7680. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
  7681. + free(pkg->filename);
  7682. + pkg->filename = NULL;
  7683. + free(pkg->local_filename);
  7684. + pkg->local_filename = NULL;
  7685. + /* CLEANUP: It'd be nice to pullin the cleanup function from
  7686. + ipkg_install.c here. See comment in
  7687. + ipkg_install.c:cleanup_temporary_files */
  7688. + free(pkg->tmp_unpack_dir);
  7689. + pkg->tmp_unpack_dir = NULL;
  7690. + free(pkg->md5sum);
  7691. + pkg->md5sum = NULL;
  7692. + free(pkg->size);
  7693. + pkg->size = NULL;
  7694. + free(pkg->installed_size);
  7695. + pkg->installed_size = NULL;
  7696. + free(pkg->priority);
  7697. + pkg->priority = NULL;
  7698. + free(pkg->source);
  7699. + pkg->source = NULL;
  7700. + conffile_list_deinit(&pkg->conffiles);
  7701. + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
  7702. + since if they are calling deinit, they should know. Maybe do an
  7703. + assertion here instead? */
  7704. + pkg->installed_files_ref_cnt = 1;
  7705. + pkg_free_installed_files(pkg);
  7706. + pkg->essential = 0;
  7707. +}
  7708. +
  7709. +int pkg_init_from_file(pkg_t *pkg, const char *filename)
  7710. +{
  7711. + int err;
  7712. + char **raw;
  7713. + FILE *control_file;
  7714. +
  7715. + err = pkg_init(pkg);
  7716. + if (err) { return err; }
  7717. +
  7718. + pkg->local_filename = strdup(filename);
  7719. +
  7720. + control_file = tmpfile();
  7721. + err = pkg_extract_control_file_to_stream(pkg, control_file);
  7722. + if (err) { return err; }
  7723. +
  7724. + rewind(control_file);
  7725. + raw = read_raw_pkgs_from_stream(control_file);
  7726. + pkg_parse_raw(pkg, &raw, NULL, NULL);
  7727. +
  7728. + fclose(control_file);
  7729. +
  7730. + return 0;
  7731. +}
  7732. +
  7733. +/* Merge any new information in newpkg into oldpkg */
  7734. +/* XXX: CLEANUP: This function shouldn't actually modify anything in
  7735. + newpkg, but should leave it usable. This rework is so that
  7736. + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
  7737. +/*
  7738. + * uh, i thought that i had originally written this so that it took
  7739. + * two pkgs and returned a new one? we can do that again... -sma
  7740. + */
  7741. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
  7742. +{
  7743. + if (oldpkg == newpkg) {
  7744. + return 0;
  7745. + }
  7746. +
  7747. + if (!oldpkg->src)
  7748. + oldpkg->src = newpkg->src;
  7749. + if (!oldpkg->dest)
  7750. + oldpkg->dest = newpkg->dest;
  7751. + if (!oldpkg->architecture)
  7752. + oldpkg->architecture = str_dup_safe(newpkg->architecture);
  7753. + if (!oldpkg->arch_priority)
  7754. + oldpkg->arch_priority = newpkg->arch_priority;
  7755. + if (!oldpkg->section)
  7756. + oldpkg->section = str_dup_safe(newpkg->section);
  7757. + if(!oldpkg->maintainer)
  7758. + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
  7759. + if(!oldpkg->description)
  7760. + oldpkg->description = str_dup_safe(newpkg->description);
  7761. + if (set_status) {
  7762. + /* merge the state_flags from the new package */
  7763. + oldpkg->state_want = newpkg->state_want;
  7764. + oldpkg->state_status = newpkg->state_status;
  7765. + oldpkg->state_flag = newpkg->state_flag;
  7766. + } else {
  7767. + if (oldpkg->state_want == SW_UNKNOWN)
  7768. + oldpkg->state_want = newpkg->state_want;
  7769. + if (oldpkg->state_status == SS_NOT_INSTALLED)
  7770. + oldpkg->state_status = newpkg->state_status;
  7771. + oldpkg->state_flag |= newpkg->state_flag;
  7772. + }
  7773. +
  7774. + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
  7775. + oldpkg->depends_str = newpkg->depends_str;
  7776. + newpkg->depends_str = NULL;
  7777. + oldpkg->depends_count = newpkg->depends_count;
  7778. + newpkg->depends_count = 0;
  7779. +
  7780. + oldpkg->depends = newpkg->depends;
  7781. + newpkg->depends = NULL;
  7782. +
  7783. + oldpkg->pre_depends_str = newpkg->pre_depends_str;
  7784. + newpkg->pre_depends_str = NULL;
  7785. + oldpkg->pre_depends_count = newpkg->pre_depends_count;
  7786. + newpkg->pre_depends_count = 0;
  7787. +
  7788. + oldpkg->recommends_str = newpkg->recommends_str;
  7789. + newpkg->recommends_str = NULL;
  7790. + oldpkg->recommends_count = newpkg->recommends_count;
  7791. + newpkg->recommends_count = 0;
  7792. +
  7793. + oldpkg->suggests_str = newpkg->suggests_str;
  7794. + newpkg->suggests_str = NULL;
  7795. + oldpkg->suggests_count = newpkg->suggests_count;
  7796. + newpkg->suggests_count = 0;
  7797. + }
  7798. +
  7799. + if (!oldpkg->provides_str) {
  7800. + oldpkg->provides_str = newpkg->provides_str;
  7801. + newpkg->provides_str = NULL;
  7802. + oldpkg->provides_count = newpkg->provides_count;
  7803. + newpkg->provides_count = 0;
  7804. +
  7805. + oldpkg->provides = newpkg->provides;
  7806. + newpkg->provides = NULL;
  7807. + }
  7808. +
  7809. + if (!oldpkg->conflicts_str) {
  7810. + oldpkg->conflicts_str = newpkg->conflicts_str;
  7811. + newpkg->conflicts_str = NULL;
  7812. + oldpkg->conflicts_count = newpkg->conflicts_count;
  7813. + newpkg->conflicts_count = 0;
  7814. +
  7815. + oldpkg->conflicts = newpkg->conflicts;
  7816. + newpkg->conflicts = NULL;
  7817. + }
  7818. +
  7819. + if (!oldpkg->replaces_str) {
  7820. + oldpkg->replaces_str = newpkg->replaces_str;
  7821. + newpkg->replaces_str = NULL;
  7822. + oldpkg->replaces_count = newpkg->replaces_count;
  7823. + newpkg->replaces_count = 0;
  7824. +
  7825. + oldpkg->replaces = newpkg->replaces;
  7826. + newpkg->replaces = NULL;
  7827. + }
  7828. +
  7829. + if (!oldpkg->filename)
  7830. + oldpkg->filename = str_dup_safe(newpkg->filename);
  7831. + if (0)
  7832. + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
  7833. + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
  7834. + if (!oldpkg->local_filename)
  7835. + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
  7836. + if (!oldpkg->tmp_unpack_dir)
  7837. + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
  7838. + if (!oldpkg->md5sum)
  7839. + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
  7840. + if (!oldpkg->size)
  7841. + oldpkg->size = str_dup_safe(newpkg->size);
  7842. + if (!oldpkg->installed_size)
  7843. + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
  7844. + if (!oldpkg->priority)
  7845. + oldpkg->priority = str_dup_safe(newpkg->priority);
  7846. + if (!oldpkg->source)
  7847. + oldpkg->source = str_dup_safe(newpkg->source);
  7848. + if (oldpkg->conffiles.head == NULL){
  7849. + oldpkg->conffiles = newpkg->conffiles;
  7850. + conffile_list_init(&newpkg->conffiles);
  7851. + }
  7852. + if (!oldpkg->installed_files){
  7853. + oldpkg->installed_files = newpkg->installed_files;
  7854. + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
  7855. + newpkg->installed_files = NULL;
  7856. + }
  7857. + if (!oldpkg->essential)
  7858. + oldpkg->essential = newpkg->essential;
  7859. +
  7860. + return 0;
  7861. +}
  7862. +
  7863. +abstract_pkg_t *abstract_pkg_new(void)
  7864. +{
  7865. + abstract_pkg_t * ab_pkg;
  7866. +
  7867. + ab_pkg = malloc(sizeof(abstract_pkg_t));
  7868. +
  7869. + if (ab_pkg == NULL) {
  7870. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7871. + return NULL;
  7872. + }
  7873. +
  7874. + if ( abstract_pkg_init(ab_pkg) < 0 )
  7875. + return NULL;
  7876. +
  7877. + return ab_pkg;
  7878. +}
  7879. +
  7880. +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
  7881. +{
  7882. + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
  7883. +
  7884. + ab_pkg->provided_by = abstract_pkg_vec_alloc();
  7885. + if (ab_pkg->provided_by==NULL){
  7886. + return -1;
  7887. + }
  7888. + ab_pkg->dependencies_checked = 0;
  7889. + ab_pkg->state_status = SS_NOT_INSTALLED;
  7890. +
  7891. + return 0;
  7892. +}
  7893. +
  7894. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
  7895. + char * temp_str;
  7896. + char **raw =NULL;
  7897. + char **raw_start=NULL;
  7898. +
  7899. + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
  7900. + if (temp_str == NULL ){
  7901. + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
  7902. + return;
  7903. + }
  7904. + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
  7905. +
  7906. + raw = raw_start = read_raw_pkgs_from_file(temp_str);
  7907. + if (raw == NULL ){
  7908. + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
  7909. + return;
  7910. + }
  7911. +
  7912. + while(*raw){
  7913. + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
  7914. + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
  7915. + }
  7916. + }
  7917. + raw = raw_start;
  7918. + while (*raw) {
  7919. + if (raw!=NULL)
  7920. + free(*raw++);
  7921. + }
  7922. +
  7923. + free(raw_start);
  7924. + free(temp_str);
  7925. +
  7926. + return ;
  7927. +
  7928. +}
  7929. +
  7930. +char * pkg_formatted_info(pkg_t *pkg )
  7931. +{
  7932. + char *line;
  7933. + char * buff;
  7934. +
  7935. + buff = malloc(8192);
  7936. + if (buff == NULL) {
  7937. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7938. + return NULL;
  7939. + }
  7940. +
  7941. + buff[0] = '\0';
  7942. +
  7943. + line = pkg_formatted_field(pkg, "Package");
  7944. + strncat(buff ,line, strlen(line));
  7945. + free(line);
  7946. +
  7947. + line = pkg_formatted_field(pkg, "Version");
  7948. + strncat(buff ,line, strlen(line));
  7949. + free(line);
  7950. +
  7951. + line = pkg_formatted_field(pkg, "Depends");
  7952. + strncat(buff ,line, strlen(line));
  7953. + free(line);
  7954. +
  7955. + line = pkg_formatted_field(pkg, "Recommends");
  7956. + strncat(buff ,line, strlen(line));
  7957. + free(line);
  7958. +
  7959. + line = pkg_formatted_field(pkg, "Suggests");
  7960. + strncat(buff ,line, strlen(line));
  7961. + free(line);
  7962. +
  7963. + line = pkg_formatted_field(pkg, "Provides");
  7964. + strncat(buff ,line, strlen(line));
  7965. + free(line);
  7966. +
  7967. + line = pkg_formatted_field(pkg, "Replaces");
  7968. + strncat(buff ,line, strlen(line));
  7969. + free(line);
  7970. +
  7971. + line = pkg_formatted_field(pkg, "Conflicts");
  7972. + strncat(buff ,line, strlen(line));
  7973. + free(line);
  7974. +
  7975. + line = pkg_formatted_field(pkg, "Status");
  7976. + strncat(buff ,line, strlen(line));
  7977. + free(line);
  7978. +
  7979. + line = pkg_formatted_field(pkg, "Section");
  7980. + strncat(buff ,line, strlen(line));
  7981. + free(line);
  7982. +
  7983. + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
  7984. + strncat(buff ,line, strlen(line));
  7985. + free(line);
  7986. +
  7987. + line = pkg_formatted_field(pkg, "Architecture");
  7988. + strncat(buff ,line, strlen(line));
  7989. + free(line);
  7990. +
  7991. + line = pkg_formatted_field(pkg, "Maintainer");
  7992. + strncat(buff ,line, strlen(line));
  7993. + free(line);
  7994. +
  7995. + line = pkg_formatted_field(pkg, "MD5sum");
  7996. + strncat(buff ,line, strlen(line));
  7997. + free(line);
  7998. +
  7999. + line = pkg_formatted_field(pkg, "Size");
  8000. + strncat(buff ,line, strlen(line));
  8001. + free(line);
  8002. +
  8003. + line = pkg_formatted_field(pkg, "Filename");
  8004. + strncat(buff ,line, strlen(line));
  8005. + free(line);
  8006. +
  8007. + line = pkg_formatted_field(pkg, "Conffiles");
  8008. + strncat(buff ,line, strlen(line));
  8009. + free(line);
  8010. +
  8011. + line = pkg_formatted_field(pkg, "Source");
  8012. + strncat(buff ,line, strlen(line));
  8013. + free(line);
  8014. +
  8015. + line = pkg_formatted_field(pkg, "Description");
  8016. + strncat(buff ,line, strlen(line));
  8017. + free(line);
  8018. +
  8019. + line = pkg_formatted_field(pkg, "Installed-Time");
  8020. + strncat(buff ,line, strlen(line));
  8021. + free(line);
  8022. +
  8023. + return buff;
  8024. +}
  8025. +
  8026. +char * pkg_formatted_field(pkg_t *pkg, const char *field )
  8027. +{
  8028. + static size_t LINE_LEN = 128;
  8029. + char * temp = (char *)malloc(1);
  8030. + int len = 0;
  8031. + int flag_provide_false = 0;
  8032. +
  8033. +/*
  8034. + Pigi: After some discussion with Florian we decided to modify the full procedure in
  8035. + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
  8036. +*/
  8037. +
  8038. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8039. + goto UNKNOWN_FMT_FIELD;
  8040. + }
  8041. +
  8042. + temp[0]='\0';
  8043. +
  8044. + switch (field[0])
  8045. + {
  8046. + case 'a':
  8047. + case 'A':
  8048. + if (strcasecmp(field, "Architecture") == 0) {
  8049. + /* Architecture */
  8050. + if (pkg->architecture) {
  8051. + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
  8052. + if ( temp == NULL ){
  8053. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8054. + return NULL;
  8055. + }
  8056. + temp[0]='\0';
  8057. + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
  8058. + }
  8059. + } else {
  8060. + goto UNKNOWN_FMT_FIELD;
  8061. + }
  8062. + break;
  8063. + case 'c':
  8064. + case 'C':
  8065. + if (strcasecmp(field, "Conffiles") == 0) {
  8066. + /* Conffiles */
  8067. + conffile_list_elt_t *iter;
  8068. + char confstr_[LINE_LEN];
  8069. +
  8070. + if (pkg->conffiles.head == NULL) {
  8071. + return temp;
  8072. + }
  8073. +
  8074. + len = 14 ;
  8075. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8076. + if (iter->data->name && iter->data->value) {
  8077. + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
  8078. + }
  8079. + }
  8080. + temp = (char *)realloc(temp,len);
  8081. + if ( temp == NULL ){
  8082. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8083. + return NULL;
  8084. + }
  8085. + temp[0]='\0';
  8086. + strncpy(temp, "Conffiles:\n", 12);
  8087. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8088. + if (iter->data->name && iter->data->value) {
  8089. + snprintf(confstr_, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
  8090. + strncat(temp, confstr_, strlen(confstr_));
  8091. + }
  8092. + }
  8093. + } else if (strcasecmp(field, "Conflicts") == 0) {
  8094. + int i;
  8095. +
  8096. + if (pkg->conflicts_count) {
  8097. + char conflictstr[LINE_LEN];
  8098. + len = 14 ;
  8099. + for(i = 0; i < pkg->conflicts_count; i++) {
  8100. + len = len + (strlen(pkg->conflicts_str[i])+5);
  8101. + }
  8102. + temp = (char *)realloc(temp,len);
  8103. + if ( temp == NULL ){
  8104. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8105. + return NULL;
  8106. + }
  8107. + temp[0]='\0';
  8108. + strncpy(temp, "Conflicts:", 11);
  8109. + for(i = 0; i < pkg->conflicts_count; i++) {
  8110. + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
  8111. + strncat(temp, conflictstr, strlen(conflictstr));
  8112. + }
  8113. + strncat(temp, "\n", strlen("\n"));
  8114. + }
  8115. + } else {
  8116. + goto UNKNOWN_FMT_FIELD;
  8117. + }
  8118. + break;
  8119. + case 'd':
  8120. + case 'D':
  8121. + if (strcasecmp(field, "Depends") == 0) {
  8122. + /* Depends */
  8123. + int i;
  8124. +
  8125. + if (pkg->depends_count) {
  8126. + char depstr[LINE_LEN];
  8127. + len = 14 ;
  8128. + for(i = 0; i < pkg->depends_count; i++) {
  8129. + len = len + (strlen(pkg->depends_str[i])+4);
  8130. + }
  8131. + temp = (char *)realloc(temp,len);
  8132. + if ( temp == NULL ){
  8133. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8134. + return NULL;
  8135. + }
  8136. + temp[0]='\0';
  8137. + strncpy(temp, "Depends:", 10);
  8138. + for(i = 0; i < pkg->depends_count; i++) {
  8139. + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
  8140. + strncat(temp, depstr, strlen(depstr));
  8141. + }
  8142. + strncat(temp, "\n", strlen("\n"));
  8143. + }
  8144. + } else if (strcasecmp(field, "Description") == 0) {
  8145. + /* Description */
  8146. + if (pkg->description) {
  8147. + temp = (char *)realloc(temp,strlen(pkg->description)+16);
  8148. + if ( temp == NULL ){
  8149. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8150. + return NULL;
  8151. + }
  8152. + temp[0]='\0';
  8153. + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
  8154. + }
  8155. + } else {
  8156. + goto UNKNOWN_FMT_FIELD;
  8157. + }
  8158. + break;
  8159. + case 'e':
  8160. + case 'E': {
  8161. + /* Essential */
  8162. + if (pkg->essential) {
  8163. + temp = (char *)realloc(temp,16);
  8164. + if ( temp == NULL ){
  8165. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8166. + return NULL;
  8167. + }
  8168. + temp[0]='\0';
  8169. + snprintf(temp, (16), "Essential: yes\n");
  8170. + }
  8171. + }
  8172. + break;
  8173. + case 'f':
  8174. + case 'F': {
  8175. + /* Filename */
  8176. + if (pkg->filename) {
  8177. + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
  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->filename)+12), "Filename: %s\n", pkg->filename);
  8184. + }
  8185. + }
  8186. + break;
  8187. + case 'i':
  8188. + case 'I': {
  8189. + if (strcasecmp(field, "Installed-Size") == 0) {
  8190. + /* Installed-Size */
  8191. + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
  8192. + if ( temp == NULL ){
  8193. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8194. + return NULL;
  8195. + }
  8196. + temp[0]='\0';
  8197. + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
  8198. + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
  8199. + temp = (char *)realloc(temp,29);
  8200. + if ( temp == NULL ){
  8201. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8202. + return NULL;
  8203. + }
  8204. + temp[0]='\0';
  8205. + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
  8206. + }
  8207. + }
  8208. + break;
  8209. + case 'm':
  8210. + case 'M': {
  8211. + /* Maintainer | MD5sum */
  8212. + if (strcasecmp(field, "Maintainer") == 0) {
  8213. + /* Maintainer */
  8214. + if (pkg->maintainer) {
  8215. + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
  8216. + if ( temp == NULL ){
  8217. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8218. + return NULL;
  8219. + }
  8220. + temp[0]='\0';
  8221. + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
  8222. + }
  8223. + } else if (strcasecmp(field, "MD5sum") == 0) {
  8224. + /* MD5sum */
  8225. + if (pkg->md5sum) {
  8226. + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
  8227. + if ( temp == NULL ){
  8228. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8229. + return NULL;
  8230. + }
  8231. + temp[0]='\0';
  8232. + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
  8233. + }
  8234. + } else {
  8235. + goto UNKNOWN_FMT_FIELD;
  8236. + }
  8237. + }
  8238. + break;
  8239. + case 'p':
  8240. + case 'P': {
  8241. + if (strcasecmp(field, "Package") == 0) {
  8242. + /* Package */
  8243. + temp = (char *)realloc(temp,strlen(pkg->name)+11);
  8244. + if ( temp == NULL ){
  8245. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8246. + return NULL;
  8247. + }
  8248. + temp[0]='\0';
  8249. + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
  8250. + } else if (strcasecmp(field, "Priority") == 0) {
  8251. + /* Priority */
  8252. + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
  8253. + if ( temp == NULL ){
  8254. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8255. + return NULL;
  8256. + }
  8257. + temp[0]='\0';
  8258. + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
  8259. + } else if (strcasecmp(field, "Provides") == 0) {
  8260. + /* Provides */
  8261. + int i;
  8262. +
  8263. + if (pkg->provides_count) {
  8264. + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
  8265. + for ( i=0; i < pkg->provides_count; i++ ){
  8266. + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
  8267. + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
  8268. + flag_provide_false = 1;
  8269. + }
  8270. + }
  8271. + if ( !flag_provide_false || /* Pigi there is not my trick flag */
  8272. + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
  8273. + char provstr[LINE_LEN];
  8274. + len = 15;
  8275. + for(i = 0; i < pkg->provides_count; i++) {
  8276. + len = len + (strlen(pkg->provides_str[i])+5);
  8277. + }
  8278. + temp = (char *)realloc(temp,len);
  8279. + if ( temp == NULL ){
  8280. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8281. + return NULL;
  8282. + }
  8283. + temp[0]='\0';
  8284. + strncpy(temp, "Provides:", 12);
  8285. + for(i = 0; i < pkg->provides_count; i++) {
  8286. + if (strlen(pkg->provides_str[i])>0){;
  8287. + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
  8288. + strncat(temp, provstr, strlen(provstr));
  8289. + }
  8290. + }
  8291. + strncat(temp, "\n", strlen("\n"));
  8292. + }
  8293. + }
  8294. + } else {
  8295. + goto UNKNOWN_FMT_FIELD;
  8296. + }
  8297. + }
  8298. + break;
  8299. + case 'r':
  8300. + case 'R': {
  8301. + int i;
  8302. + /* Replaces | Recommends*/
  8303. + if (strcasecmp (field, "Replaces") == 0) {
  8304. + if (pkg->replaces_count) {
  8305. + char replstr[LINE_LEN];
  8306. + len = 14;
  8307. + for (i = 0; i < pkg->replaces_count; i++) {
  8308. + len = len + (strlen(pkg->replaces_str[i])+5);
  8309. + }
  8310. + temp = (char *)realloc(temp,len);
  8311. + if ( temp == NULL ){
  8312. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8313. + return NULL;
  8314. + }
  8315. + temp[0]='\0';
  8316. + strncpy(temp, "Replaces:", 12);
  8317. + for (i = 0; i < pkg->replaces_count; i++) {
  8318. + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
  8319. + strncat(temp, replstr, strlen(replstr));
  8320. + }
  8321. + strncat(temp, "\n", strlen("\n"));
  8322. + }
  8323. + } else if (strcasecmp (field, "Recommends") == 0) {
  8324. + if (pkg->recommends_count) {
  8325. + char recstr[LINE_LEN];
  8326. + len = 15;
  8327. + for(i = 0; i < pkg->recommends_count; i++) {
  8328. + len = len + (strlen( pkg->recommends_str[i])+5);
  8329. + }
  8330. + temp = (char *)realloc(temp,len);
  8331. + if ( temp == NULL ){
  8332. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8333. + return NULL;
  8334. + }
  8335. + temp[0]='\0';
  8336. + strncpy(temp, "Recommends:", 13);
  8337. + for(i = 0; i < pkg->recommends_count; i++) {
  8338. + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
  8339. + strncat(temp, recstr, strlen(recstr));
  8340. + }
  8341. + strncat(temp, "\n", strlen("\n"));
  8342. + }
  8343. + } else {
  8344. + goto UNKNOWN_FMT_FIELD;
  8345. + }
  8346. + }
  8347. + break;
  8348. + case 's':
  8349. + case 'S': {
  8350. + /* Section | Size | Source | Status | Suggests */
  8351. + if (strcasecmp(field, "Section") == 0) {
  8352. + /* Section */
  8353. + if (pkg->section) {
  8354. + temp = (char *)realloc(temp,strlen(pkg->section)+11);
  8355. + if ( temp == NULL ){
  8356. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8357. + return NULL;
  8358. + }
  8359. + temp[0]='\0';
  8360. + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
  8361. + }
  8362. + } else if (strcasecmp(field, "Size") == 0) {
  8363. + /* Size */
  8364. + if (pkg->size) {
  8365. + temp = (char *)realloc(temp,strlen(pkg->size)+8);
  8366. + if ( temp == NULL ){
  8367. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8368. + return NULL;
  8369. + }
  8370. + temp[0]='\0';
  8371. + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
  8372. + }
  8373. + } else if (strcasecmp(field, "Source") == 0) {
  8374. + /* Source */
  8375. + if (pkg->source) {
  8376. + temp = (char *)realloc(temp,strlen(pkg->source)+10);
  8377. + if ( temp == NULL ){
  8378. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8379. + return NULL;
  8380. + }
  8381. + temp[0]='\0';
  8382. + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
  8383. + }
  8384. + } else if (strcasecmp(field, "Status") == 0) {
  8385. + /* Status */
  8386. + /* Benjamin Pineau note: we should avoid direct usage of
  8387. + * strlen(arg) without keeping "arg" for later free()
  8388. + */
  8389. + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
  8390. + char *pstat=pkg_state_status_to_str(pkg->state_status);
  8391. + char *pwant=pkg_state_want_to_str(pkg->state_want);
  8392. +
  8393. + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
  8394. + temp = (char *)realloc(temp,sum_of_sizes);
  8395. + if ( temp == NULL ){
  8396. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8397. + return NULL;
  8398. + }
  8399. + temp[0]='\0';
  8400. + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
  8401. + free(pflag);
  8402. + free(pwant);
  8403. + if(pstat) /* pfstat can be NULL if ENOMEM */
  8404. + free(pstat);
  8405. + } else if (strcasecmp(field, "Suggests") == 0) {
  8406. + if (pkg->suggests_count) {
  8407. + int i;
  8408. + char sugstr[LINE_LEN];
  8409. + len = 13;
  8410. + for(i = 0; i < pkg->suggests_count; i++) {
  8411. + len = len + (strlen(pkg->suggests_str[i])+5);
  8412. + }
  8413. + temp = (char *)realloc(temp,len);
  8414. + if ( temp == NULL ){
  8415. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8416. + return NULL;
  8417. + }
  8418. + temp[0]='\0';
  8419. + strncpy(temp, "Suggests:", 10);
  8420. + for(i = 0; i < pkg->suggests_count; i++) {
  8421. + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
  8422. + strncat(temp, sugstr, strlen(sugstr));
  8423. + }
  8424. + strncat(temp, "\n", strlen("\n"));
  8425. + }
  8426. + } else {
  8427. + goto UNKNOWN_FMT_FIELD;
  8428. + }
  8429. + }
  8430. + break;
  8431. + case 'v':
  8432. + case 'V': {
  8433. + /* Version */
  8434. + char *version = pkg_version_str_alloc(pkg);
  8435. + temp = (char *)realloc(temp,strlen(version)+14);
  8436. + if ( temp == NULL ){
  8437. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8438. + return NULL;
  8439. + }
  8440. + temp[0]='\0';
  8441. + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
  8442. + free(version);
  8443. + }
  8444. + break;
  8445. + default:
  8446. + goto UNKNOWN_FMT_FIELD;
  8447. + }
  8448. +
  8449. + if ( strlen(temp)<2 ) {
  8450. + temp[0]='\0';
  8451. + }
  8452. + return temp;
  8453. +
  8454. + UNKNOWN_FMT_FIELD:
  8455. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
  8456. + if ( strlen(temp)<2 ) {
  8457. + temp[0]='\0';
  8458. + }
  8459. +
  8460. + return temp;
  8461. +}
  8462. +
  8463. +void pkg_print_info(pkg_t *pkg, FILE *file)
  8464. +{
  8465. + char * buff;
  8466. + if (pkg == NULL) {
  8467. + return;
  8468. + }
  8469. +
  8470. + buff = pkg_formatted_info(pkg);
  8471. + if ( buff == NULL )
  8472. + return;
  8473. + if (strlen(buff)>2){
  8474. + fwrite(buff, 1, strlen(buff), file);
  8475. + }
  8476. + free(buff);
  8477. +}
  8478. +
  8479. +void pkg_print_status(pkg_t * pkg, FILE * file)
  8480. +{
  8481. + if (pkg == NULL) {
  8482. + return;
  8483. + }
  8484. +
  8485. + /* XXX: QUESTION: Do we actually want more fields here? The
  8486. + original idea was to save space by installing only what was
  8487. + needed for actual computation, (package, version, status,
  8488. + essential, conffiles). The assumption is that all other fields
  8489. + can be found in th available file.
  8490. +
  8491. + But, someone proposed the idea to make it possible to
  8492. + reconstruct a .ipk from an installed package, (ie. for beaming
  8493. + from one handheld to another). So, maybe we actually want a few
  8494. + more fields here, (depends, suggests, etc.), so that that would
  8495. + be guaranteed to work even in the absence of more information
  8496. + from the available file.
  8497. +
  8498. + 28-MAR-03: kergoth and I discussed this yesterday. We think
  8499. + the essential info needs to be here for all installed packages
  8500. + because they may not appear in the Packages files on various
  8501. + feeds. Furthermore, one should be able to install from URL or
  8502. + local storage without requiring a Packages file from any feed.
  8503. + -Jamey
  8504. + */
  8505. + pkg_print_field(pkg, file, "Package");
  8506. + pkg_print_field(pkg, file, "Version");
  8507. + pkg_print_field(pkg, file, "Depends");
  8508. + pkg_print_field(pkg, file, "Recommends");
  8509. + pkg_print_field(pkg, file, "Suggests");
  8510. + pkg_print_field(pkg, file, "Provides");
  8511. + pkg_print_field(pkg, file, "Replaces");
  8512. + pkg_print_field(pkg, file, "Conflicts");
  8513. + pkg_print_field(pkg, file, "Status");
  8514. + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
  8515. + pkg_print_field(pkg, file, "Architecture");
  8516. + pkg_print_field(pkg, file, "Conffiles");
  8517. + pkg_print_field(pkg, file, "Installed-Time");
  8518. + fputs("\n", file);
  8519. +}
  8520. +
  8521. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
  8522. +{
  8523. + char *buff;
  8524. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8525. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
  8526. + __FUNCTION__, field);
  8527. + }
  8528. + buff = pkg_formatted_field(pkg, field);
  8529. + if (strlen(buff)>2) {
  8530. + fprintf(file, "%s", buff);
  8531. + fflush(file);
  8532. + }
  8533. + free(buff);
  8534. + return;
  8535. +}
  8536. +
  8537. +/*
  8538. + * libdpkg - Debian packaging suite library routines
  8539. + * vercmp.c - comparison of version numbers
  8540. + *
  8541. + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  8542. + */
  8543. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
  8544. +{
  8545. + int r;
  8546. +
  8547. + if (pkg->epoch > ref_pkg->epoch) {
  8548. + return 1;
  8549. + }
  8550. +
  8551. + if (pkg->epoch < ref_pkg->epoch) {
  8552. + return -1;
  8553. + }
  8554. +
  8555. + r = verrevcmp(pkg->version, ref_pkg->version);
  8556. + if (r) {
  8557. + return r;
  8558. + }
  8559. +
  8560. +#ifdef USE_DEBVERSION
  8561. + r = verrevcmp(pkg->revision, ref_pkg->revision);
  8562. + if (r) {
  8563. + return r;
  8564. + }
  8565. +
  8566. + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
  8567. +#endif
  8568. +
  8569. + return r;
  8570. +}
  8571. +
  8572. +int verrevcmp(const char *val, const char *ref)
  8573. +{
  8574. + int vc, rc;
  8575. + long vl, rl;
  8576. + const char *vp, *rp;
  8577. + const char *vsep, *rsep;
  8578. +
  8579. + if (!val) val= "";
  8580. + if (!ref) ref= "";
  8581. + for (;;) {
  8582. + vp= val; while (*vp && !isdigit(*vp)) vp++;
  8583. + rp= ref; while (*rp && !isdigit(*rp)) rp++;
  8584. + for (;;) {
  8585. + vc= (val == vp) ? 0 : *val++;
  8586. + rc= (ref == rp) ? 0 : *ref++;
  8587. + if (!rc && !vc) break;
  8588. + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
  8589. + if (rc && !isalpha(rc)) rc += 256;
  8590. + if (vc != rc) return vc - rc;
  8591. + }
  8592. + val= vp;
  8593. + ref= rp;
  8594. + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
  8595. + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
  8596. + if (vl != rl) return vl - rl;
  8597. +
  8598. + vc = *val;
  8599. + rc = *ref;
  8600. + vsep = strchr(".-", vc);
  8601. + rsep = strchr(".-", rc);
  8602. + if (vsep && !rsep) return -1;
  8603. + if (!vsep && rsep) return +1;
  8604. +
  8605. + if (!*val && !*ref) return 0;
  8606. + if (!*val) return -1;
  8607. + if (!*ref) return +1;
  8608. + }
  8609. +}
  8610. +
  8611. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
  8612. +{
  8613. + int r;
  8614. +
  8615. + r = pkg_compare_versions(it, ref);
  8616. +
  8617. + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
  8618. + return r <= 0;
  8619. + }
  8620. +
  8621. + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
  8622. + return r >= 0;
  8623. + }
  8624. +
  8625. + if (strcmp(op, "<<") == 0) {
  8626. + return r < 0;
  8627. + }
  8628. +
  8629. + if (strcmp(op, ">>") == 0) {
  8630. + return r > 0;
  8631. + }
  8632. +
  8633. + if (strcmp(op, "=") == 0) {
  8634. + return r == 0;
  8635. + }
  8636. +
  8637. + fprintf(stderr, "unknown operator: %s", op);
  8638. + return 0;
  8639. +}
  8640. +
  8641. +int pkg_name_version_and_architecture_compare(pkg_t *p1, pkg_t *p2)
  8642. +{
  8643. + const pkg_t *a = *(const pkg_t **)p1;
  8644. + const pkg_t *b = *(const pkg_t **)p2;
  8645. + int namecmp;
  8646. + int vercmp;
  8647. + if (!a->name || !b->name) {
  8648. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8649. + a, a->name, b, b->name);
  8650. + return 0;
  8651. + }
  8652. +
  8653. + namecmp = strcmp(a->name, b->name);
  8654. + if (namecmp)
  8655. + return namecmp;
  8656. + vercmp = pkg_compare_versions(a, b);
  8657. + if (vercmp)
  8658. + return vercmp;
  8659. + if (!a->arch_priority || !b->arch_priority) {
  8660. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
  8661. + a, a->arch_priority, b, b->arch_priority);
  8662. + return 0;
  8663. + }
  8664. + if (a->arch_priority > b->arch_priority)
  8665. + return 1;
  8666. + if (a->arch_priority < b->arch_priority)
  8667. + return -1;
  8668. + return 0;
  8669. +}
  8670. +
  8671. +int abstract_pkg_name_compare(abstract_pkg_t *p1, abstract_pkg_t *p2)
  8672. +{
  8673. + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
  8674. + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
  8675. + if (!a->name || !b->name) {
  8676. + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8677. + a, a->name, b, b->name);
  8678. + return 0;
  8679. + }
  8680. + return strcmp(a->name, b->name);
  8681. +}
  8682. +
  8683. +
  8684. +char *pkg_version_str_alloc(pkg_t *pkg)
  8685. +{
  8686. + char *complete_version;
  8687. + char *epoch_str;
  8688. +#ifdef USE_DEBVERSION
  8689. + char *revision_str;
  8690. + char *familiar_revision_str;
  8691. +#endif
  8692. +
  8693. + if (pkg->epoch) {
  8694. + sprintf_alloc(&epoch_str, "%lu:", (unsigned long)pkg->epoch);
  8695. + } else {
  8696. + epoch_str = strdup("");
  8697. + }
  8698. +
  8699. +#ifdef USE_DEBVERSION
  8700. + if (pkg->revision && strlen(pkg->revision)) {
  8701. + sprintf_alloc(&revision_str, "-%s", pkg->revision);
  8702. + } else {
  8703. + revision_str = strdup("");
  8704. + }
  8705. +
  8706. + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
  8707. + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
  8708. + } else {
  8709. + familiar_revision_str = strdup("");
  8710. + }
  8711. +#endif
  8712. +
  8713. +#ifdef USE_DEBVERSION
  8714. + sprintf_alloc(&complete_version, "%s%s%s%s",
  8715. + epoch_str, pkg->version, revision_str, familiar_revision_str);
  8716. +#else
  8717. + sprintf_alloc(&complete_version, "%s%s",
  8718. + epoch_str, pkg->version);
  8719. +#endif
  8720. +
  8721. + free(epoch_str);
  8722. +#ifdef USE_DEBVERSION
  8723. + free(revision_str);
  8724. + free(familiar_revision_str);
  8725. +#endif
  8726. +
  8727. + return complete_version;
  8728. +}
  8729. +
  8730. +str_list_t *pkg_get_installed_files(pkg_t *pkg)
  8731. +{
  8732. + int err;
  8733. + char *list_file_name = NULL;
  8734. + FILE *list_file = NULL;
  8735. + char *line;
  8736. + char *installed_file_name;
  8737. + int rootdirlen;
  8738. +
  8739. + pkg->installed_files_ref_cnt++;
  8740. +
  8741. + if (pkg->installed_files) {
  8742. + return pkg->installed_files;
  8743. + }
  8744. +
  8745. + pkg->installed_files = str_list_alloc();
  8746. + if (pkg->installed_files == NULL) {
  8747. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8748. + return NULL;
  8749. + }
  8750. +
  8751. + /* For uninstalled packages, get the file list firectly from the package.
  8752. + For installed packages, look at the package.list file in the database.
  8753. + */
  8754. + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
  8755. + if (pkg->local_filename == NULL) {
  8756. + return pkg->installed_files;
  8757. + }
  8758. + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
  8759. + file. In other words, change deb_extract so that it can
  8760. + simply return the file list as a char *[] rather than
  8761. + insisting on writing in to a FILE * as it does now. */
  8762. + list_file = tmpfile();
  8763. + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
  8764. + if (err) {
  8765. + fclose(list_file);
  8766. + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
  8767. + __FUNCTION__, pkg->local_filename, strerror(err));
  8768. + return pkg->installed_files;
  8769. + }
  8770. + rewind(list_file);
  8771. + } else {
  8772. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8773. + pkg->dest->info_dir, pkg->name);
  8774. + if (! file_exists(list_file_name)) {
  8775. + free(list_file_name);
  8776. + return pkg->installed_files;
  8777. + }
  8778. +
  8779. + list_file = fopen(list_file_name, "r");
  8780. + if (list_file == NULL) {
  8781. + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
  8782. + list_file_name, strerror(errno));
  8783. + free(list_file_name);
  8784. + return pkg->installed_files;
  8785. + }
  8786. + free(list_file_name);
  8787. + }
  8788. +
  8789. + rootdirlen = strlen( pkg->dest->root_dir );
  8790. + while (1) {
  8791. + char *file_name;
  8792. +
  8793. + line = file_read_line_alloc(list_file);
  8794. + if (line == NULL) {
  8795. + break;
  8796. + }
  8797. + str_chomp(line);
  8798. + file_name = line;
  8799. +
  8800. + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
  8801. + if( strncmp( pkg->dest->root_dir,
  8802. + file_name,
  8803. + rootdirlen ) ) {
  8804. + if (*file_name == '.') {
  8805. + file_name++;
  8806. + }
  8807. + if (*file_name == '/') {
  8808. + file_name++;
  8809. + }
  8810. +
  8811. + /* Freed in pkg_free_installed_files */
  8812. + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
  8813. + } else {
  8814. + // already contains root_dir as header -> ABSOLUTE
  8815. + sprintf_alloc(&installed_file_name, "%s", file_name);
  8816. + }
  8817. + str_list_append(pkg->installed_files, installed_file_name);
  8818. + free(line);
  8819. + }
  8820. +
  8821. + fclose(list_file);
  8822. +
  8823. + return pkg->installed_files;
  8824. +}
  8825. +
  8826. +/* XXX: CLEANUP: This function and it's counterpart,
  8827. + (pkg_get_installed_files), do not match our init/deinit naming
  8828. + convention. Nor the alloc/free convention. But, then again, neither
  8829. + of these conventions currrently fit the way these two functions
  8830. + work. */
  8831. +int pkg_free_installed_files(pkg_t *pkg)
  8832. +{
  8833. + str_list_elt_t *iter;
  8834. +
  8835. + pkg->installed_files_ref_cnt--;
  8836. + if (pkg->installed_files_ref_cnt > 0) {
  8837. + return 0;
  8838. + }
  8839. +
  8840. + if (pkg->installed_files) {
  8841. +
  8842. + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
  8843. + /* malloced in pkg_get_installed_files */
  8844. + free (iter->data);
  8845. + iter->data = NULL;
  8846. + }
  8847. +
  8848. + str_list_deinit(pkg->installed_files);
  8849. + }
  8850. +
  8851. + pkg->installed_files = NULL;
  8852. +
  8853. + return 0;
  8854. +}
  8855. +
  8856. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
  8857. +{
  8858. + int err;
  8859. + char *list_file_name;
  8860. +
  8861. + //I don't think pkg_free_installed_files should be called here. Jamey
  8862. + //pkg_free_installed_files(pkg);
  8863. +
  8864. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8865. + pkg->dest->info_dir, pkg->name);
  8866. + if (!conf->noaction) {
  8867. + err = unlink(list_file_name);
  8868. + free(list_file_name);
  8869. +
  8870. + if (err) {
  8871. + return errno;
  8872. + }
  8873. + }
  8874. + return 0;
  8875. +}
  8876. +
  8877. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
  8878. +{
  8879. + conffile_list_elt_t *iter;
  8880. + conffile_t *conffile;
  8881. +
  8882. + if (pkg == NULL) {
  8883. + return NULL;
  8884. + }
  8885. +
  8886. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8887. + conffile = iter->data;
  8888. +
  8889. + if (strcmp(conffile->name, file_name) == 0) {
  8890. + return conffile;
  8891. + }
  8892. + }
  8893. +
  8894. + return NULL;
  8895. +}
  8896. +
  8897. +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
  8898. + const char *script, const char *args)
  8899. +{
  8900. + int err;
  8901. + char *path;
  8902. + char *cmd;
  8903. +
  8904. + /* XXX: FEATURE: When conf->offline_root is set, we should run the
  8905. + maintainer script within a chroot environment. */
  8906. +
  8907. + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
  8908. + have scripts in pkg->tmp_unpack_dir. */
  8909. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  8910. + if (pkg->dest == NULL) {
  8911. + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
  8912. + __FUNCTION__, pkg->name);
  8913. + return EINVAL;
  8914. + }
  8915. + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
  8916. + } else {
  8917. + if (pkg->tmp_unpack_dir == NULL) {
  8918. + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
  8919. + __FUNCTION__, pkg->name);
  8920. + return EINVAL;
  8921. + }
  8922. + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
  8923. + }
  8924. +
  8925. + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
  8926. + if (conf->noaction) return 0;
  8927. +
  8928. + /* XXX: CLEANUP: There must be a better way to handle maintainer
  8929. + scripts when running with offline_root mode and/or a dest other
  8930. + than '/'. I've been playing around with some clever chroot
  8931. + tricks and I might come up with something workable. */
  8932. + if (conf->offline_root) {
  8933. + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
  8934. + }
  8935. +
  8936. + setenv("PKG_ROOT",
  8937. + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
  8938. +
  8939. + if (! file_exists(path)) {
  8940. + free(path);
  8941. + return 0;
  8942. + }
  8943. +
  8944. + if (conf->offline_root) {
  8945. + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
  8946. + free(path);
  8947. + return 0;
  8948. + }
  8949. +
  8950. + sprintf_alloc(&cmd, "%s %s", path, args);
  8951. + free(path);
  8952. +
  8953. + err = xsystem(cmd);
  8954. + free(cmd);
  8955. +
  8956. + if (err) {
  8957. + fprintf(stderr, "%s script returned status %d\n", script, err);
  8958. + return err;
  8959. + }
  8960. +
  8961. + return 0;
  8962. +}
  8963. +
  8964. +char *pkg_state_want_to_str(pkg_state_want_t sw)
  8965. +{
  8966. + int i;
  8967. +
  8968. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  8969. + if (pkg_state_want_map[i].value == sw) {
  8970. + return strdup(pkg_state_want_map[i].str);
  8971. + }
  8972. + }
  8973. +
  8974. + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
  8975. + __FUNCTION__, sw);
  8976. + return strdup("<STATE_WANT_UNKNOWN>");
  8977. +}
  8978. +
  8979. +pkg_state_want_t pkg_state_want_from_str(char *str)
  8980. +{
  8981. + int i;
  8982. +
  8983. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  8984. + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
  8985. + return pkg_state_want_map[i].value;
  8986. + }
  8987. + }
  8988. +
  8989. + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
  8990. + __FUNCTION__, str);
  8991. + return SW_UNKNOWN;
  8992. +}
  8993. +
  8994. +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
  8995. +{
  8996. + int i;
  8997. + int len = 3; /* ok\000 is minimum */
  8998. + char *str = NULL;
  8999. +
  9000. + /* clear the temporary flags before converting to string */
  9001. + sf &= SF_NONVOLATILE_FLAGS;
  9002. +
  9003. + if (sf == 0) {
  9004. + return strdup("ok");
  9005. + } else {
  9006. +
  9007. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9008. + if (sf & pkg_state_flag_map[i].value) {
  9009. + len += strlen(pkg_state_flag_map[i].str) + 1;
  9010. + }
  9011. + }
  9012. + str = malloc(len);
  9013. + if ( str == NULL ) {
  9014. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9015. + return NULL;
  9016. + }
  9017. + str[0] = 0;
  9018. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9019. + if (sf & pkg_state_flag_map[i].value) {
  9020. + strcat(str, pkg_state_flag_map[i].str);
  9021. + strcat(str, ",");
  9022. + }
  9023. + }
  9024. + len = strlen(str);
  9025. + str[len-1] = 0; /* squash last comma */
  9026. + return str;
  9027. + }
  9028. +}
  9029. +
  9030. +pkg_state_flag_t pkg_state_flag_from_str(char *str)
  9031. +{
  9032. + int i;
  9033. + int sf = SF_OK;
  9034. +
  9035. + if (strcmp(str, "ok") == 0) {
  9036. + return SF_OK;
  9037. + }
  9038. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9039. + const char *sfname = pkg_state_flag_map[i].str;
  9040. + int sfname_len = strlen(sfname);
  9041. + if (strncmp(str, sfname, sfname_len) == 0) {
  9042. + sf |= pkg_state_flag_map[i].value;
  9043. + str += sfname_len;
  9044. + if (str[0] == ',') {
  9045. + str++;
  9046. + } else {
  9047. + break;
  9048. + }
  9049. + }
  9050. + }
  9051. +
  9052. + return sf;
  9053. +}
  9054. +
  9055. +char *pkg_state_status_to_str(pkg_state_status_t ss)
  9056. +{
  9057. + int i;
  9058. +
  9059. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9060. + if (pkg_state_status_map[i].value == ss) {
  9061. + return strdup(pkg_state_status_map[i].str);
  9062. + }
  9063. + }
  9064. +
  9065. + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
  9066. + __FUNCTION__, ss);
  9067. + return strdup("<STATE_STATUS_UNKNOWN>");
  9068. +}
  9069. +
  9070. +pkg_state_status_t pkg_state_status_from_str(char *str)
  9071. +{
  9072. + int i;
  9073. +
  9074. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9075. + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
  9076. + return pkg_state_status_map[i].value;
  9077. + }
  9078. + }
  9079. +
  9080. + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
  9081. + __FUNCTION__, str);
  9082. + return SS_NOT_INSTALLED;
  9083. +}
  9084. +
  9085. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
  9086. +{
  9087. + nv_pair_list_elt_t *l;
  9088. +
  9089. + if (!pkg->architecture)
  9090. + return 1;
  9091. +
  9092. + l = conf->arch_list.head;
  9093. +
  9094. + while (l) {
  9095. + nv_pair_t *nv = l->data;
  9096. + if (strcmp(nv->name, pkg->architecture) == 0) {
  9097. + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
  9098. + return 1;
  9099. + }
  9100. + l = l->next;
  9101. + }
  9102. +
  9103. + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
  9104. + return 0;
  9105. +}
  9106. +
  9107. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
  9108. +{
  9109. + nv_pair_list_elt_t *l;
  9110. +
  9111. + l = conf->arch_list.head;
  9112. +
  9113. + while (l) {
  9114. + nv_pair_t *nv = l->data;
  9115. + if (strcmp(nv->name, archname) == 0) {
  9116. + int priority = strtol(nv->value, NULL, 0);
  9117. + return priority;
  9118. + }
  9119. + l = l->next;
  9120. + }
  9121. + return 0;
  9122. +}
  9123. +
  9124. +int pkg_info_preinstall_check(ipkg_conf_t *conf)
  9125. +{
  9126. + int i;
  9127. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9128. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  9129. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9130. +
  9131. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
  9132. + pkg_hash_fetch_available(pkg_hash, available_pkgs);
  9133. + /* update arch_priority for each package */
  9134. + for (i = 0; i < available_pkgs->len; i++) {
  9135. + pkg_t *pkg = available_pkgs->pkgs[i];
  9136. + int arch_priority = 1;
  9137. + if (!pkg)
  9138. + continue;
  9139. + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
  9140. + if (pkg->architecture)
  9141. + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
  9142. + else
  9143. + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
  9144. + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
  9145. + pkg->arch_priority = arch_priority;
  9146. + }
  9147. +
  9148. + for (i = 0; i < available_pkgs->len; i++) {
  9149. + pkg_t *pkg = available_pkgs->pkgs[i];
  9150. + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
  9151. + /* clear flags and want for any uninstallable package */
  9152. + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
  9153. + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
  9154. + pkg->state_want = SW_UNKNOWN;
  9155. + pkg->state_flag = 0;
  9156. + }
  9157. + }
  9158. + pkg_vec_free(available_pkgs);
  9159. +
  9160. + /* update the file owner data structure */
  9161. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
  9162. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9163. + for (i = 0; i < installed_pkgs->len; i++) {
  9164. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9165. + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
  9166. + str_list_elt_t *iter;
  9167. + if (installed_files == NULL) {
  9168. + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
  9169. + break;
  9170. + }
  9171. + for (iter = installed_files->head; iter; iter = iter->next) {
  9172. + char *installed_file = iter->data;
  9173. + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
  9174. + file_hash_set_file_owner(conf, installed_file, pkg);
  9175. + }
  9176. + }
  9177. + pkg_vec_free(installed_pkgs);
  9178. +
  9179. + return 0;
  9180. +}
  9181. +
  9182. +struct pkg_write_filelist_data {
  9183. + ipkg_conf_t *conf;
  9184. + pkg_t *pkg;
  9185. + FILE *stream;
  9186. +};
  9187. +
  9188. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
  9189. +{
  9190. + struct pkg_write_filelist_data *data = data_;
  9191. + pkg_t *entry = entry_;
  9192. + if (entry == data->pkg) {
  9193. + fprintf(data->stream, "%s\n", key);
  9194. + }
  9195. +}
  9196. +
  9197. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
  9198. +{
  9199. + struct pkg_write_filelist_data data;
  9200. + char *list_file_name = NULL;
  9201. + int err = 0;
  9202. +
  9203. + if (!pkg) {
  9204. + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
  9205. + return -EINVAL;
  9206. + }
  9207. + ipkg_message(conf, IPKG_INFO,
  9208. + " creating %s.list file\n", pkg->name);
  9209. + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
  9210. + if (!list_file_name) {
  9211. + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
  9212. + return -ENOMEM;
  9213. + }
  9214. + ipkg_message(conf, IPKG_INFO,
  9215. + " creating %s file for pkg %s\n", list_file_name, pkg->name);
  9216. + data.stream = fopen(list_file_name, "w");
  9217. + if (!data.stream) {
  9218. + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
  9219. + list_file_name, strerror(errno));
  9220. + return errno;
  9221. + }
  9222. + data.pkg = pkg;
  9223. + data.conf = conf;
  9224. + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
  9225. + fclose(data.stream);
  9226. + free(list_file_name);
  9227. +
  9228. + return err;
  9229. +}
  9230. +
  9231. +int pkg_write_changed_filelists(ipkg_conf_t *conf)
  9232. +{
  9233. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9234. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9235. + int i;
  9236. + int err;
  9237. + if (conf->noaction)
  9238. + return 0;
  9239. +
  9240. + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
  9241. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9242. + for (i = 0; i < installed_pkgs->len; i++) {
  9243. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9244. + if (pkg->state_flag & SF_FILELIST_CHANGED) {
  9245. + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
  9246. + err = pkg_write_filelist(conf, pkg);
  9247. + if (err)
  9248. + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
  9249. + }
  9250. + }
  9251. + return 0;
  9252. +}
  9253. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_depends.c busybox-1.16.1/archival/libipkg/pkg_depends.c
  9254. --- busybox-1.16.1.orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
  9255. +++ busybox-1.16.1/archival/libipkg/pkg_depends.c 2010-06-29 17:31:24.548368104 +0200
  9256. @@ -0,0 +1,1032 @@
  9257. +/* pkg_depends.c - the itsy package management system
  9258. +
  9259. + Steven M. Ayer
  9260. +
  9261. + Copyright (C) 2002 Compaq Computer Corporation
  9262. +
  9263. + This program is free software; you can redistribute it and/or
  9264. + modify it under the terms of the GNU General Public License as
  9265. + published by the Free Software Foundation; either version 2, or (at
  9266. + your option) any later version.
  9267. +
  9268. + This program is distributed in the hope that it will be useful, but
  9269. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9270. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9271. + General Public License for more details.
  9272. +*/
  9273. +
  9274. +#include "ipkg.h"
  9275. +#include <errno.h>
  9276. +#include <ctype.h>
  9277. +
  9278. +#include "pkg.h"
  9279. +#include "ipkg_utils.h"
  9280. +#include "pkg_hash.h"
  9281. +#include "ipkg_message.h"
  9282. +#include "pkg_parse.h"
  9283. +#include "hash_table.h"
  9284. +
  9285. +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
  9286. +static depend_t * depend_init(void);
  9287. +static void depend_deinit(depend_t *d);
  9288. +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
  9289. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
  9290. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
  9291. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg);
  9292. +
  9293. +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
  9294. +{
  9295. + depend_t *depend = (depend_t *)cdata;
  9296. + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
  9297. + return 1;
  9298. + else
  9299. + return 0;
  9300. +}
  9301. +
  9302. +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
  9303. +{
  9304. + depend_t *depend = (depend_t *)cdata;
  9305. +#if 0
  9306. + pkg_t * temp = pkg_new();
  9307. + int comparison;
  9308. + parseVersion(temp, depend->version);
  9309. + comparison = pkg_compare_versions(pkg, temp);
  9310. + free(temp);
  9311. +
  9312. + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
  9313. + __FUNCTION__, pkg->name, pkg->version,
  9314. + depend, depend->constraint, depend->version,
  9315. + comparison, version_constraints_satisfied(depend, pkg));
  9316. +#endif
  9317. + if (version_constraints_satisfied(depend, pkg))
  9318. + return 1;
  9319. + else
  9320. + return 0;
  9321. +}
  9322. +
  9323. +/* returns ndependences or negative error value */
  9324. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
  9325. + pkg_vec_t *unsatisfied, char *** unresolved)
  9326. +{
  9327. + pkg_t * satisfier_entry_pkg;
  9328. + register int i, j, k, l;
  9329. + int count, found;
  9330. + char ** the_lost;
  9331. + abstract_pkg_t * ab_pkg;
  9332. +
  9333. + /*
  9334. + * this is a setup to check for redundant/cyclic dependency checks,
  9335. + * which are marked at the abstract_pkg level
  9336. + */
  9337. + if (!(ab_pkg = pkg->parent)) {
  9338. + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
  9339. + *unresolved = NULL;
  9340. + return 0;
  9341. + }
  9342. + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
  9343. + *unresolved = NULL;
  9344. + return 0;
  9345. + } else {
  9346. + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
  9347. + }
  9348. + /**/
  9349. +
  9350. + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
  9351. + if (!count){
  9352. + *unresolved = NULL;
  9353. + return 0;
  9354. + }
  9355. +
  9356. + the_lost = NULL;
  9357. +
  9358. + /* foreach dependency */
  9359. + for (i = 0; i < count; i++) {
  9360. + compound_depend_t * compound_depend = &pkg->depends[i];
  9361. + depend_t ** possible_satisfiers = compound_depend->possibilities;;
  9362. + found = 0;
  9363. + satisfier_entry_pkg = NULL;
  9364. +
  9365. + if (compound_depend->type == GREEDY_DEPEND) {
  9366. + /* foreach possible satisfier */
  9367. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9368. + /* foreach provided_by, which includes the abstract_pkg itself */
  9369. + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
  9370. + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
  9371. + int nposs = ab_provider_vec->len;
  9372. + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
  9373. + for (l = 0; l < nposs; l++) {
  9374. + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
  9375. + /* if no depends on this one, try the first package that Provides this one */
  9376. + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
  9377. + continue;
  9378. + }
  9379. +
  9380. + /* cruise this possiblity's pkg_vec looking for an installed version */
  9381. + for (k = 0; k < test_vec->len; k++) {
  9382. + pkg_t *pkg_scout = test_vec->pkgs[k];
  9383. + /* not installed, and not already known about? */
  9384. + if ((pkg_scout->state_want != SW_INSTALL)
  9385. + && !pkg_scout->parent->dependencies_checked
  9386. + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
  9387. + char ** newstuff = NULL;
  9388. + int rc;
  9389. + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
  9390. + /* check for not-already-installed dependencies */
  9391. + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
  9392. + pkg_scout,
  9393. + tmp_vec,
  9394. + &newstuff);
  9395. + if (newstuff == NULL) {
  9396. + int ok = 1;
  9397. + for (i = 0; i < rc; i++) {
  9398. + pkg_t *p = tmp_vec->pkgs[i];
  9399. + if (p->state_want == SW_INSTALL)
  9400. + continue;
  9401. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
  9402. + ok = 0;
  9403. + break;
  9404. + }
  9405. + pkg_vec_free (tmp_vec);
  9406. + if (ok) {
  9407. + /* mark this one for installation */
  9408. + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
  9409. + pkg_vec_insert(unsatisfied, pkg_scout);
  9410. + }
  9411. + } else {
  9412. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
  9413. + free (newstuff);
  9414. + }
  9415. + }
  9416. + }
  9417. + }
  9418. + }
  9419. +
  9420. + continue;
  9421. + }
  9422. +
  9423. + /* foreach possible satisfier, look for installed package */
  9424. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9425. + /* foreach provided_by, which includes the abstract_pkg itself */
  9426. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9427. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9428. + pkg_t *satisfying_pkg =
  9429. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9430. + pkg_installed_and_constraint_satisfied,
  9431. + dependence_to_satisfy, 1);
  9432. + /* Being that I can't test constraing in pkg_hash, I will test it here */
  9433. + if (satisfying_pkg != NULL) {
  9434. + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9435. + satisfying_pkg = NULL;
  9436. + }
  9437. + }
  9438. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
  9439. + if (satisfying_pkg != NULL) {
  9440. + found = 1;
  9441. + break;
  9442. + }
  9443. +
  9444. + }
  9445. + /* if nothing installed matches, then look for uninstalled satisfier */
  9446. + if (!found) {
  9447. + /* foreach possible satisfier, look for installed package */
  9448. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9449. + /* foreach provided_by, which includes the abstract_pkg itself */
  9450. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9451. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9452. + pkg_t *satisfying_pkg =
  9453. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9454. + pkg_constraint_satisfied,
  9455. + dependence_to_satisfy, 1);
  9456. + /* Being that I can't test constraing in pkg_hash, I will test it here too */
  9457. + if (satisfying_pkg != NULL) {
  9458. + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9459. + satisfying_pkg = NULL;
  9460. + }
  9461. + }
  9462. +
  9463. + /* user request overrides package recommendation */
  9464. + if (satisfying_pkg != NULL
  9465. + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
  9466. + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
  9467. + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
  9468. + pkg->name, satisfying_pkg->name);
  9469. + continue;
  9470. + }
  9471. +
  9472. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
  9473. + if (satisfying_pkg != NULL) {
  9474. + satisfier_entry_pkg = satisfying_pkg;
  9475. + break;
  9476. + }
  9477. + }
  9478. + }
  9479. +
  9480. + /* we didn't find one, add something to the unsatisfied vector */
  9481. + if (!found) {
  9482. + if (!satisfier_entry_pkg) {
  9483. + /* failure to meet recommendations is not an error */
  9484. + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
  9485. + the_lost = add_unresolved_dep(pkg, the_lost, i);
  9486. + else
  9487. + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
  9488. + pkg->name, compound_depend->possibilities[0]->pkg->name);
  9489. + }
  9490. + else {
  9491. + if (compound_depend->type == SUGGEST) {
  9492. + /* just mention it politely */
  9493. + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
  9494. + pkg->name, satisfier_entry_pkg->name);
  9495. + } else {
  9496. + char ** newstuff = NULL;
  9497. +
  9498. + if (satisfier_entry_pkg != pkg &&
  9499. + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
  9500. + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
  9501. + pkg_hash_fetch_unsatisfied_dependencies(conf,
  9502. + satisfier_entry_pkg,
  9503. + unsatisfied,
  9504. + &newstuff);
  9505. + the_lost = merge_unresolved(the_lost, newstuff);
  9506. + }
  9507. + }
  9508. + }
  9509. + }
  9510. + }
  9511. + *unresolved = the_lost;
  9512. +
  9513. + return unsatisfied->len;
  9514. +}
  9515. +
  9516. +/*checking for conflicts !in replaces
  9517. + If a packages conflicts with another but is also replacing it, I should not consider it a
  9518. + really conflicts
  9519. + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
  9520. +*/
  9521. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
  9522. +{
  9523. + int i ;
  9524. + int replaces_count = pkg->replaces_count;
  9525. + abstract_pkg_t **replaces;
  9526. +
  9527. + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
  9528. + return 0;
  9529. +
  9530. + replaces = pkg->replaces;
  9531. +
  9532. + for (i = 0; i < replaces_count; i++) {
  9533. + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
  9534. + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
  9535. + return 1;
  9536. + }
  9537. + }
  9538. + return 0;
  9539. +
  9540. +}
  9541. +
  9542. +
  9543. +/* Abhaya: added support for conflicts */
  9544. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg)
  9545. +{
  9546. + pkg_vec_t * installed_conflicts, * test_vec;
  9547. + compound_depend_t * conflicts;
  9548. + depend_t ** possible_satisfiers;
  9549. + depend_t * possible_satisfier;
  9550. + register int i, j, k;
  9551. + int count;
  9552. + abstract_pkg_t * ab_pkg;
  9553. + pkg_t **pkg_scouts;
  9554. + pkg_t *pkg_scout;
  9555. +
  9556. + /*
  9557. + * this is a setup to check for redundant/cyclic dependency checks,
  9558. + * which are marked at the abstract_pkg level
  9559. + */
  9560. + if(!(ab_pkg = pkg->parent)){
  9561. + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
  9562. + return (pkg_vec_t *)NULL;
  9563. + }
  9564. +
  9565. + conflicts = pkg->conflicts;
  9566. + if(!conflicts){
  9567. + return (pkg_vec_t *)NULL;
  9568. + }
  9569. + installed_conflicts = pkg_vec_alloc();
  9570. +
  9571. + count = pkg->conflicts_count;
  9572. +
  9573. +
  9574. +
  9575. + /* foreach conflict */
  9576. + for(i = 0; i < pkg->conflicts_count; i++){
  9577. +
  9578. + possible_satisfiers = conflicts->possibilities;
  9579. +
  9580. + /* foreach possible satisfier */
  9581. + for(j = 0; j < conflicts->possibility_count; j++){
  9582. + possible_satisfier = possible_satisfiers[j];
  9583. + if (!possible_satisfier)
  9584. + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
  9585. + if (!possible_satisfier->pkg)
  9586. + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
  9587. + test_vec = possible_satisfier->pkg->pkgs;
  9588. + if (test_vec) {
  9589. + /* pkg_vec found, it is an actual package conflict
  9590. + * cruise this possiblity's pkg_vec looking for an installed version */
  9591. + pkg_scouts = test_vec->pkgs;
  9592. + for(k = 0; k < test_vec->len; k++){
  9593. + pkg_scout = pkg_scouts[k];
  9594. + if (!pkg_scout) {
  9595. + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
  9596. + continue;
  9597. + }
  9598. + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
  9599. + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
  9600. + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
  9601. + pkg_vec_insert(installed_conflicts, pkg_scout);
  9602. + }
  9603. + }
  9604. + }
  9605. + }
  9606. + }
  9607. + conflicts++;
  9608. + }
  9609. +
  9610. + if (installed_conflicts->len)
  9611. + return installed_conflicts;
  9612. + pkg_vec_free(installed_conflicts);
  9613. + return (pkg_vec_t *)NULL;
  9614. +}
  9615. +
  9616. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
  9617. +{
  9618. + pkg_t * temp;
  9619. + int comparison;
  9620. +
  9621. + if(depends->constraint == NONE)
  9622. + return 1;
  9623. +
  9624. + temp = pkg_new();
  9625. +
  9626. + parseVersion(temp, depends->version);
  9627. +
  9628. + comparison = pkg_compare_versions(pkg, temp);
  9629. +
  9630. + free(temp);
  9631. +
  9632. + if((depends->constraint == EARLIER) &&
  9633. + (comparison < 0))
  9634. + return 1;
  9635. + else if((depends->constraint == LATER) &&
  9636. + (comparison > 0))
  9637. + return 1;
  9638. + else if(comparison == 0)
  9639. + return 1;
  9640. + else if((depends->constraint == LATER_EQUAL) &&
  9641. + (comparison >= 0))
  9642. + return 1;
  9643. + else if((depends->constraint == EARLIER_EQUAL) &&
  9644. + (comparison <= 0))
  9645. + return 1;
  9646. +
  9647. + return 0;
  9648. +}
  9649. +
  9650. +int pkg_dependence_satisfiable(depend_t *depend)
  9651. +{
  9652. + abstract_pkg_t *apkg = depend->pkg;
  9653. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9654. + int n_providers = provider_apkgs->len;
  9655. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9656. + pkg_vec_t *pkg_vec;
  9657. + int n_pkgs ;
  9658. + int i;
  9659. + int j;
  9660. +
  9661. + for (i = 0; i < n_providers; i++) {
  9662. + abstract_pkg_t *papkg = apkgs[i];
  9663. + pkg_vec = papkg->pkgs;
  9664. + if (pkg_vec) {
  9665. + n_pkgs = pkg_vec->len;
  9666. + for (j = 0; j < n_pkgs; j++) {
  9667. + pkg_t *pkg = pkg_vec->pkgs[j];
  9668. + if (version_constraints_satisfied(depend, pkg)) {
  9669. + return 1;
  9670. + }
  9671. + }
  9672. + }
  9673. + }
  9674. + return 0;
  9675. +}
  9676. +
  9677. +int pkg_dependence_satisfied(depend_t *depend)
  9678. +{
  9679. + abstract_pkg_t *apkg = depend->pkg;
  9680. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9681. + int n_providers = provider_apkgs->len;
  9682. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9683. + int i;
  9684. + int n_pkgs;
  9685. + int j;
  9686. +
  9687. + for (i = 0; i < n_providers; i++) {
  9688. + abstract_pkg_t *papkg = apkgs[i];
  9689. + pkg_vec_t *pkg_vec = papkg->pkgs;
  9690. + if (pkg_vec) {
  9691. + n_pkgs = pkg_vec->len;
  9692. + for (j = 0; j < n_pkgs; j++) {
  9693. + pkg_t *pkg = pkg_vec->pkgs[j];
  9694. + if (version_constraints_satisfied(depend, pkg)) {
  9695. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
  9696. + return 1;
  9697. + }
  9698. + }
  9699. + }
  9700. + }
  9701. + return 0;
  9702. +}
  9703. +
  9704. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
  9705. +{
  9706. + register int i;
  9707. + pkg_t ** pkgs = vec->pkgs;
  9708. +
  9709. + for(i = 0; i < vec->len; i++)
  9710. + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
  9711. + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
  9712. + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
  9713. + return 1;
  9714. + return 0;
  9715. +}
  9716. +
  9717. +
  9718. +#ifdef DeadCode
  9719. +/**
  9720. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  9721. + * the same abstract package and 0 otherwise.
  9722. + */
  9723. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
  9724. +{
  9725. + abstract_pkg_t **provides = pkg->provides;
  9726. + int provides_count = pkg->provides_count;
  9727. + abstract_pkg_t **replacee_provides = replacee->provides;
  9728. + int replacee_provides_count = replacee->provides_count;
  9729. + int i, j;
  9730. + for (i = 0; i < provides_count; i++) {
  9731. + abstract_pkg_t *apkg = provides[i];
  9732. + for (j = 0; j < replacee_provides_count; j++) {
  9733. + abstract_pkg_t *replacee_apkg = replacee_provides[i];
  9734. + if (apkg == replacee_apkg)
  9735. + return 1;
  9736. + }
  9737. + }
  9738. + return 0;
  9739. +}
  9740. +#endif
  9741. +
  9742. +/**
  9743. + * pkg_provides_abstract returns 1 if pkg->provides contains providee
  9744. + * and 0 otherwise.
  9745. + */
  9746. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
  9747. +{
  9748. + abstract_pkg_t **provides = pkg->provides;
  9749. + int provides_count = pkg->provides_count;
  9750. + int i;
  9751. + for (i = 0; i < provides_count; i++) {
  9752. + if (provides[i] == providee)
  9753. + return 1;
  9754. + }
  9755. + return 0;
  9756. +}
  9757. +
  9758. +/**
  9759. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  9760. + * otherwise.
  9761. + */
  9762. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
  9763. +{
  9764. + abstract_pkg_t **replaces = pkg->replaces;
  9765. + int replaces_count = pkg->replaces_count;
  9766. + /* abstract_pkg_t **replacee_provides = pkg->provides;
  9767. + int replacee_provides_count = pkg->provides_count; */
  9768. + int i, j;
  9769. + for (i = 0; i < replaces_count; i++) {
  9770. + abstract_pkg_t *abstract_replacee = replaces[i];
  9771. + for (j = 0; j < replaces_count; j++) {
  9772. + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
  9773. + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
  9774. + if (replacee->provides[j] == abstract_replacee)
  9775. + return 1;
  9776. + }
  9777. + }
  9778. + return 0;
  9779. +}
  9780. +
  9781. +
  9782. +/**
  9783. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
  9784. + * otherwise.
  9785. + */
  9786. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
  9787. +{
  9788. + compound_depend_t *conflicts = pkg->conflicts;
  9789. + int conflicts_count = pkg->conflicts_count;
  9790. + int i, j;
  9791. + for (i = 0; i < conflicts_count; i++) {
  9792. + int possibility_count = conflicts[i].possibility_count;
  9793. + struct depend **possibilities = conflicts[i].possibilities;
  9794. + for (j = 0; j < possibility_count; j++) {
  9795. + if (possibilities[j]->pkg == conflictee) {
  9796. + return 1;
  9797. + }
  9798. + }
  9799. + }
  9800. + return 0;
  9801. +}
  9802. +
  9803. +/**
  9804. + * pkg_conflicts returns 1 if pkg->conflicts contains one of
  9805. + * conflictee's provides and 0 otherwise.
  9806. + */
  9807. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
  9808. +{
  9809. + compound_depend_t *conflicts = pkg->conflicts;
  9810. + int conflicts_count = pkg->conflicts_count;
  9811. + abstract_pkg_t **conflictee_provides = conflictee->provides;
  9812. + int conflictee_provides_count = conflictee->provides_count;
  9813. + int i, j, k;
  9814. + int possibility_count;
  9815. + struct depend **possibilities;
  9816. + abstract_pkg_t *possibility ;
  9817. +
  9818. + for (i = 0; i < conflicts_count; i++) {
  9819. + possibility_count = conflicts[i].possibility_count;
  9820. + possibilities = conflicts[i].possibilities;
  9821. + for (j = 0; j < possibility_count; j++) {
  9822. + possibility = possibilities[j]->pkg;
  9823. + for (k = 0; k < conflictee_provides_count; k++) {
  9824. + if (possibility == conflictee_provides[k]) {
  9825. + return 1;
  9826. + }
  9827. + }
  9828. + }
  9829. + }
  9830. + return 0;
  9831. +}
  9832. +
  9833. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
  9834. +{
  9835. + int oldlen = 0, newlen = 0;
  9836. + char ** result;
  9837. + register int i, j;
  9838. +
  9839. + if(!newstuff)
  9840. + return oldstuff;
  9841. +
  9842. + while(oldstuff && oldstuff[oldlen]) oldlen++;
  9843. + while(newstuff && newstuff[newlen]) newlen++;
  9844. +
  9845. + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
  9846. + if (result == NULL) {
  9847. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9848. + return NULL;
  9849. + }
  9850. +
  9851. + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
  9852. + *(result + i) = *(newstuff + j);
  9853. +
  9854. + *(result + i) = NULL;
  9855. +
  9856. + return result;
  9857. +}
  9858. +
  9859. +/*
  9860. + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
  9861. + * this is null terminated, no count is carried around
  9862. + */
  9863. +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
  9864. +{
  9865. + int count;
  9866. + char ** resized;
  9867. + char *depend_str = pkg_depend_str(pkg, ref_ndx);
  9868. +
  9869. + count = 0;
  9870. + while(the_lost && the_lost[count]) count++;
  9871. +
  9872. + count++; /* need one to hold the null */
  9873. + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
  9874. + if (resized == NULL) {
  9875. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9876. + return NULL;
  9877. + }
  9878. + resized[count - 1] = strdup(depend_str);
  9879. + resized[count] = NULL;
  9880. +
  9881. + return resized;
  9882. +}
  9883. +
  9884. +void printDepends(pkg_t * pkg)
  9885. +{
  9886. + register int i, j;
  9887. + compound_depend_t * depend;
  9888. + int count;
  9889. +
  9890. + count = pkg->pre_depends_count + pkg->depends_count;
  9891. +
  9892. + depend = pkg->depends;
  9893. + if(!depend){
  9894. + fprintf(stderr, "Depends pointer is NULL\n");
  9895. + return;
  9896. + }
  9897. + for(i = 0; i < count; i++){
  9898. + fprintf(stderr, "%s has %d possibilities:\n",
  9899. + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
  9900. + depend->possibility_count);
  9901. + for(j = 0; j < depend->possibility_count; j++)
  9902. + fprintf(stderr, "\t%s version %s (%d)\n",
  9903. + depend->possibilities[j]->pkg->name,
  9904. + depend->possibilities[j]->version,
  9905. + depend->possibilities[j]->constraint);
  9906. + depend++;
  9907. + }
  9908. +}
  9909. +
  9910. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  9911. +{
  9912. + register int i, j;
  9913. +
  9914. + /* every pkg provides itself */
  9915. + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
  9916. +
  9917. + if (!pkg->provides_count)
  9918. + return 0;
  9919. +
  9920. + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
  9921. + if (pkg->provides == NULL) {
  9922. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9923. + return -1 ;
  9924. + }
  9925. + pkg->provides[0] = ab_pkg;
  9926. +
  9927. + // if (strcmp(ab_pkg->name, pkg->name))
  9928. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  9929. +
  9930. + for(i = 0; i < pkg->provides_count; i++){
  9931. + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
  9932. +
  9933. + pkg->provides[i+1] = provided_abpkg;
  9934. +
  9935. + j = 0;
  9936. + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
  9937. + }
  9938. + return 0;
  9939. +}
  9940. +
  9941. +/* Abhaya: added conflicts support */
  9942. +int buildConflicts(hash_table_t * hash, pkg_t * pkg)
  9943. +{
  9944. + register int i;
  9945. + compound_depend_t * conflicts;
  9946. +
  9947. + if (!pkg->conflicts_count)
  9948. + return 0;
  9949. +
  9950. + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
  9951. + pkg->conflicts_count);
  9952. + if (conflicts == NULL) {
  9953. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9954. + return -1;
  9955. + }
  9956. + for (i = 0; i < pkg->conflicts_count; i++) {
  9957. + conflicts->type = CONFLICTS;
  9958. + parseDepends(conflicts, hash,
  9959. + pkg->conflicts_str[i]);
  9960. +#if 0
  9961. + for (j = 0; j < conflicts->possibility_count; j++) {
  9962. + depend_t *possibility = conflicts->possibilities[j];
  9963. + abstract_pkg_t *conflicting_apkg = possibility->pkg;
  9964. + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
  9965. + }
  9966. +#endif
  9967. + conflicts++;
  9968. + }
  9969. + return 0;
  9970. +}
  9971. +
  9972. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  9973. +{
  9974. + register int i, j;
  9975. +
  9976. + if (!pkg->replaces_count)
  9977. + return 0;
  9978. +
  9979. + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
  9980. + if (pkg->replaces == NULL) {
  9981. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9982. + return -1;
  9983. + }
  9984. +
  9985. + // if (strcmp(ab_pkg->name, pkg->name))
  9986. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  9987. +
  9988. + for(i = 0; i < pkg->replaces_count; i++){
  9989. + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
  9990. +
  9991. + pkg->replaces[i] = old_abpkg;
  9992. +
  9993. + j = 0;
  9994. + if (!old_abpkg->replaced_by)
  9995. + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
  9996. + if ( old_abpkg->replaced_by == NULL ){
  9997. + return -1;
  9998. + }
  9999. + /* if a package pkg both replaces and conflicts old_abpkg,
  10000. + * then add it to the replaced_by vector so that old_abpkg
  10001. + * will be upgraded to ab_pkg automatically */
  10002. + if (pkg_conflicts_abstract(pkg, old_abpkg))
  10003. + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
  10004. + }
  10005. + return 0;
  10006. +}
  10007. +
  10008. +int buildDepends(hash_table_t * hash, pkg_t * pkg)
  10009. +{
  10010. + int count;
  10011. + register int i;
  10012. + compound_depend_t * depends;
  10013. +
  10014. + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
  10015. + return 0;
  10016. +
  10017. + if (0 && pkg->pre_depends_count)
  10018. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10019. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10020. + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
  10021. + if (depends == NULL) {
  10022. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10023. + return -1;
  10024. + }
  10025. +
  10026. +
  10027. + for(i = 0; i < pkg->pre_depends_count; i++){
  10028. + parseDepends(depends, hash, pkg->pre_depends_str[i]);
  10029. + if (0 && pkg->pre_depends_count)
  10030. + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
  10031. + pkg->pre_depends_str[i], depends, depends->possibility_count);
  10032. + depends->type = PREDEPEND;
  10033. + depends++;
  10034. + }
  10035. +
  10036. + for(i = 0; i < pkg->recommends_count; i++){
  10037. + parseDepends(depends, hash, pkg->recommends_str[i]);
  10038. + if (0 && pkg->recommends_count)
  10039. + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
  10040. + pkg->recommends_str[i], depends, depends->possibility_count);
  10041. + depends->type = RECOMMEND;
  10042. + depends++;
  10043. + }
  10044. +
  10045. + for(i = 0; i < pkg->suggests_count; i++){
  10046. + parseDepends(depends, hash, pkg->suggests_str[i]);
  10047. + if (0 && pkg->suggests_count)
  10048. + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
  10049. + pkg->suggests_str[i], depends, depends->possibility_count);
  10050. + depends->type = SUGGEST;
  10051. + depends++;
  10052. + }
  10053. +
  10054. + for(i = 0; i < pkg->depends_count; i++){
  10055. + parseDepends(depends, hash, pkg->depends_str[i]);
  10056. + if (0 && pkg->depends_count)
  10057. + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
  10058. + pkg->depends_str[i], depends, depends->possibility_count);
  10059. + depends++;
  10060. + }
  10061. + return 0;
  10062. +}
  10063. +
  10064. +/*
  10065. + * pkg_depend_string: returns the depends string specified by index_.
  10066. + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
  10067. + * [0,npredepends) -> returns pre_depends_str[index_]
  10068. + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index_]
  10069. + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index_]
  10070. + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index_]
  10071. + */
  10072. +char *pkg_depend_str(pkg_t *pkg, int index_)
  10073. +{
  10074. + if (index_ < pkg->pre_depends_count) {
  10075. + return pkg->pre_depends_str[index_];
  10076. + }
  10077. + index_ -= pkg->pre_depends_count;
  10078. +
  10079. + if (index_ < pkg->recommends_count) {
  10080. + return pkg->recommends_str[index_];
  10081. + }
  10082. + index_ -= pkg->recommends_count;
  10083. +
  10084. + if (index_ < pkg->suggests_count) {
  10085. + return pkg->suggests_str[index_];
  10086. + }
  10087. + index_ -= pkg->suggests_count;
  10088. +
  10089. + if (index_ < pkg->depends_count) {
  10090. + return pkg->depends_str[index_];
  10091. + }
  10092. + fprintf(stderr, "pkg_depend_str: index_ %d out of range for pkg=%s\n", index_, pkg->name);
  10093. + return NULL;
  10094. +}
  10095. +
  10096. +void freeDepends(pkg_t *pkg)
  10097. +{
  10098. + int i;
  10099. +
  10100. + if (pkg == NULL || pkg->depends == NULL) {
  10101. + return;
  10102. + }
  10103. +
  10104. + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
  10105. + for (i=0; i < pkg->depends->possibility_count; i++) {
  10106. + depend_deinit(pkg->depends->possibilities[i]);
  10107. + }
  10108. + free(pkg->depends->possibilities);
  10109. + free(pkg->depends);
  10110. + pkg->depends = NULL;
  10111. +}
  10112. +
  10113. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
  10114. +{
  10115. + compound_depend_t * depends;
  10116. + int count, othercount;
  10117. + register int i, j;
  10118. + abstract_pkg_t * ab_depend;
  10119. + abstract_pkg_t ** temp;
  10120. +
  10121. + count = pkg->pre_depends_count + pkg->depends_count;
  10122. + depends = pkg->depends;
  10123. +
  10124. + if (0 && pkg->pre_depends_count)
  10125. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10126. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10127. + for (i = 0; i < count; i++) {
  10128. + if (0 && pkg->pre_depends_count)
  10129. + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
  10130. + for (j = 0; j < depends->possibility_count; j++){
  10131. + ab_depend = depends->possibilities[j]->pkg;
  10132. + if(!ab_depend->depended_upon_by)
  10133. + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
  10134. +
  10135. + temp = ab_depend->depended_upon_by;
  10136. + othercount = 1;
  10137. + while(*temp){
  10138. + temp++;
  10139. + othercount++;
  10140. + }
  10141. + *temp = ab_pkg;
  10142. +
  10143. + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
  10144. + (othercount + 1) * sizeof(abstract_pkg_t *));
  10145. + /* the array may have moved */
  10146. + temp = ab_depend->depended_upon_by + othercount;
  10147. + *temp = NULL;
  10148. + }
  10149. + depends++;
  10150. + }
  10151. +}
  10152. +
  10153. +static depend_t * depend_init(void)
  10154. +{
  10155. + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
  10156. + if ( d==NULL ){
  10157. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10158. + return NULL;
  10159. + }
  10160. + d->constraint = NONE;
  10161. + d->version = NULL;
  10162. + d->pkg = NULL;
  10163. +
  10164. + return d;
  10165. +}
  10166. +
  10167. +static void depend_deinit(depend_t *d)
  10168. +{
  10169. + free(d);
  10170. +}
  10171. +
  10172. +static int parseDepends(compound_depend_t *compound_depend,
  10173. + hash_table_t * hash, char * depend_str)
  10174. +{
  10175. + char * pkg_name, buffer[2048];
  10176. + int num_of_ors = 0;
  10177. + register int i;
  10178. + register char * src, * dest;
  10179. + depend_t ** possibilities;
  10180. +
  10181. + /* first count the number of ored possibilities for satisfying dependency */
  10182. + src = depend_str;
  10183. + while(*src)
  10184. + if(*src++ == '|')
  10185. + num_of_ors++;
  10186. +
  10187. + compound_depend->type = DEPEND;
  10188. +
  10189. + compound_depend->possibility_count = num_of_ors + 1;
  10190. + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
  10191. + if (!possibilities)
  10192. + return -ENOMEM;
  10193. + compound_depend->possibilities = possibilities;
  10194. +
  10195. + src = depend_str;
  10196. + for(i = 0; i < num_of_ors + 1; i++){
  10197. + possibilities[i] = depend_init();
  10198. + if (!possibilities[i])
  10199. + return -ENOMEM;
  10200. + /* gobble up just the name first */
  10201. + dest = buffer;
  10202. + while(*src &&
  10203. + !isspace(*src) &&
  10204. + (*src != '(') &&
  10205. + (*src != '*') &&
  10206. + (*src != '|'))
  10207. + *dest++ = *src++;
  10208. + *dest = '\0';
  10209. + pkg_name = trim_alloc(buffer);
  10210. + if (pkg_name == NULL )
  10211. + return -ENOMEM;
  10212. +
  10213. + /* now look at possible version info */
  10214. +
  10215. + /* skip to next chars */
  10216. + if(isspace(*src))
  10217. + while(*src && isspace(*src)) src++;
  10218. +
  10219. + /* extract constraint and version */
  10220. + if(*src == '('){
  10221. + src++;
  10222. + if(!strncmp(src, "<<", 2)){
  10223. + possibilities[i]->constraint = EARLIER;
  10224. + src += 2;
  10225. + }
  10226. + else if(!strncmp(src, "<=", 2)){
  10227. + possibilities[i]->constraint = EARLIER_EQUAL;
  10228. + src += 2;
  10229. + }
  10230. + else if(!strncmp(src, ">=", 2)){
  10231. + possibilities[i]->constraint = LATER_EQUAL;
  10232. + src += 2;
  10233. + }
  10234. + else if(!strncmp(src, ">>", 2)){
  10235. + possibilities[i]->constraint = LATER;
  10236. + src += 2;
  10237. + }
  10238. + else if(!strncmp(src, "=", 1)){
  10239. + possibilities[i]->constraint = EQUAL;
  10240. + src++;
  10241. + }
  10242. + /* should these be here to support deprecated designations; dpkg does */
  10243. + else if(!strncmp(src, "<", 1)){
  10244. + possibilities[i]->constraint = EARLIER_EQUAL;
  10245. + src++;
  10246. + }
  10247. + else if(!strncmp(src, ">", 1)){
  10248. + possibilities[i]->constraint = LATER_EQUAL;
  10249. + src++;
  10250. + }
  10251. +
  10252. + /* now we have any constraint, pass space to version string */
  10253. + while(isspace(*src)) src++;
  10254. +
  10255. + /* this would be the version string */
  10256. + dest = buffer;
  10257. + while(*src && *src != ')')
  10258. + *dest++ = *src++;
  10259. + *dest = '\0';
  10260. +
  10261. + possibilities[i]->version = trim_alloc(buffer);
  10262. + /* fprintf(stderr, "let's print the depends version string:");
  10263. + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
  10264. + if (possibilities[i]->version == NULL )
  10265. + return -ENOMEM;
  10266. +
  10267. +
  10268. + }
  10269. + /* hook up the dependency to its abstract pkg */
  10270. + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
  10271. +
  10272. + free(pkg_name);
  10273. +
  10274. + /* now get past the ) and any possible | chars */
  10275. + while(*src &&
  10276. + (isspace(*src) ||
  10277. + (*src == ')') ||
  10278. + (*src == '|')))
  10279. + src++;
  10280. + if (*src == '*')
  10281. + {
  10282. + compound_depend->type = GREEDY_DEPEND;
  10283. + src++;
  10284. + }
  10285. + }
  10286. +
  10287. + return 0;
  10288. +}
  10289. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_depends.h busybox-1.16.1/archival/libipkg/pkg_depends.h
  10290. --- busybox-1.16.1.orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
  10291. +++ busybox-1.16.1/archival/libipkg/pkg_depends.h 2010-06-29 17:31:24.588368223 +0200
  10292. @@ -0,0 +1,105 @@
  10293. +/* pkg_depends.h - the itsy package management system
  10294. +
  10295. + Steven M. Ayer
  10296. +
  10297. + Copyright (C) 2002 Compaq Computer Corporation
  10298. +
  10299. + This program is free software; you can redistribute it and/or
  10300. + modify it under the terms of the GNU General Public License as
  10301. + published by the Free Software Foundation; either version 2, or (at
  10302. + your option) any later version.
  10303. +
  10304. + This program is distributed in the hope that it will be useful, but
  10305. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10306. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10307. + General Public License for more details.
  10308. +*/
  10309. +
  10310. +#ifndef PKG_DEPENDS_H
  10311. +#define PKG_DEPENDS_H
  10312. +
  10313. +#include "pkg.h"
  10314. +#include "pkg_hash.h"
  10315. +
  10316. +enum depend_type {
  10317. + PREDEPEND,
  10318. + DEPEND,
  10319. + CONFLICTS,
  10320. + GREEDY_DEPEND,
  10321. + RECOMMEND,
  10322. + SUGGEST
  10323. +};
  10324. +typedef enum depend_type depend_type_t;
  10325. +
  10326. +enum version_constraint {
  10327. + NONE,
  10328. + EARLIER,
  10329. + EARLIER_EQUAL,
  10330. + EQUAL,
  10331. + LATER_EQUAL,
  10332. + LATER
  10333. +};
  10334. +typedef enum version_constraint version_constraint_t;
  10335. +
  10336. +struct depend{
  10337. + version_constraint_t constraint;
  10338. + char * version;
  10339. + abstract_pkg_t * pkg;
  10340. +};
  10341. +typedef struct depend depend_t;
  10342. +
  10343. +struct compound_depend{
  10344. + depend_type_t type;
  10345. + int possibility_count;
  10346. + struct depend ** possibilities;
  10347. +};
  10348. +typedef struct compound_depend compound_depend_t;
  10349. +
  10350. +#include "hash_table.h"
  10351. +
  10352. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10353. +int buildConflicts(hash_table_t * hash, pkg_t * pkg);
  10354. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10355. +int buildDepends(hash_table_t * hash, pkg_t * pkg);
  10356. +
  10357. +/**
  10358. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10359. + * the same abstract package and 0 otherwise.
  10360. + */
  10361. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
  10362. +
  10363. +/**
  10364. + * pkg_provides returns 1 if pkg->provides contains providee and 0
  10365. + * otherwise.
  10366. + */
  10367. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
  10368. +
  10369. +/**
  10370. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10371. + * otherwise.
  10372. + */
  10373. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
  10374. +
  10375. +/**
  10376. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
  10377. + * otherwise.
  10378. + */
  10379. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
  10380. +
  10381. +/**
  10382. + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
  10383. + * otherwise.
  10384. + */
  10385. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
  10386. +
  10387. +char *pkg_depend_str(pkg_t *pkg, int index_);
  10388. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
  10389. +void freeDepends(pkg_t *pkg);
  10390. +void printDepends(pkg_t * pkg);
  10391. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
  10392. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
  10393. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
  10394. +int pkg_dependence_satisfiable(depend_t *depend);
  10395. +int pkg_dependence_satisfied(depend_t *depend);
  10396. +
  10397. +#endif
  10398. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_dest.c busybox-1.16.1/archival/libipkg/pkg_dest.c
  10399. --- busybox-1.16.1.orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
  10400. +++ busybox-1.16.1/archival/libipkg/pkg_dest.c 2010-06-29 17:31:24.625873289 +0200
  10401. @@ -0,0 +1,92 @@
  10402. +/* pkg_dest.c - the itsy package management system
  10403. +
  10404. + Carl D. Worth
  10405. +
  10406. + Copyright (C) 2001 University of Southern California
  10407. +
  10408. + This program is free software; you can redistribute it and/or
  10409. + modify it under the terms of the GNU General Public License as
  10410. + published by the Free Software Foundation; either version 2, or (at
  10411. + your option) any later version.
  10412. +
  10413. + This program is distributed in the hope that it will be useful, but
  10414. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10415. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10416. + General Public License for more details.
  10417. +*/
  10418. +
  10419. +#include "ipkg.h"
  10420. +
  10421. +#include "pkg_dest.h"
  10422. +#include "file_util.h"
  10423. +#include "str_util.h"
  10424. +#include "sprintf_alloc.h"
  10425. +
  10426. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
  10427. +{
  10428. + dest->name = strdup(name);
  10429. +
  10430. + /* Guarantee that dest->root_dir ends with a '/' */
  10431. + if (str_ends_with(root_dir, "/")) {
  10432. + dest->root_dir = strdup(root_dir);
  10433. + } else {
  10434. + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
  10435. + }
  10436. + file_mkdir_hier(dest->root_dir, 0755);
  10437. +
  10438. + sprintf_alloc(&dest->ipkg_dir, "%s%s",
  10439. + dest->root_dir, IPKG_STATE_DIR_PREFIX);
  10440. + file_mkdir_hier(dest->ipkg_dir, 0755);
  10441. +
  10442. + if (str_starts_with (lists_dir, "/"))
  10443. + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
  10444. + else
  10445. + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
  10446. +
  10447. + file_mkdir_hier(dest->lists_dir, 0755);
  10448. +
  10449. + sprintf_alloc(&dest->info_dir, "%s/%s",
  10450. + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
  10451. + file_mkdir_hier(dest->info_dir, 0755);
  10452. +
  10453. + sprintf_alloc(&dest->status_file_name, "%s/%s",
  10454. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10455. +
  10456. + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
  10457. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10458. +
  10459. + dest->status_file = NULL;
  10460. +
  10461. + return 0;
  10462. +}
  10463. +
  10464. +void pkg_dest_deinit(pkg_dest_t *dest)
  10465. +{
  10466. + free(dest->name);
  10467. + dest->name = NULL;
  10468. +
  10469. + free(dest->root_dir);
  10470. + dest->root_dir = NULL;
  10471. +
  10472. + free(dest->ipkg_dir);
  10473. + dest->ipkg_dir = NULL;
  10474. +
  10475. + free(dest->lists_dir);
  10476. + dest->lists_dir = NULL;
  10477. +
  10478. + free(dest->info_dir);
  10479. + dest->info_dir = NULL;
  10480. +
  10481. + free(dest->status_file_name);
  10482. + dest->status_file_name = NULL;
  10483. +
  10484. + free(dest->status_file_tmp_name);
  10485. + dest->status_file_tmp_name = NULL;
  10486. +
  10487. + if (dest->status_file) {
  10488. + fclose(dest->status_file);
  10489. + }
  10490. + dest->status_file = NULL;
  10491. +
  10492. + dest->root_dir = NULL;
  10493. +}
  10494. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_dest.h busybox-1.16.1/archival/libipkg/pkg_dest.h
  10495. --- busybox-1.16.1.orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
  10496. +++ busybox-1.16.1/archival/libipkg/pkg_dest.h 2010-06-29 17:31:24.669618111 +0200
  10497. @@ -0,0 +1,38 @@
  10498. +/* pkg_dest.h - the itsy package management system
  10499. +
  10500. + Carl D. Worth
  10501. +
  10502. + Copyright (C) 2001 University of Southern California
  10503. +
  10504. + This program is free software; you can redistribute it and/or
  10505. + modify it under the terms of the GNU General Public License as
  10506. + published by the Free Software Foundation; either version 2, or (at
  10507. + your option) any later version.
  10508. +
  10509. + This program is distributed in the hope that it will be useful, but
  10510. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10511. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10512. + General Public License for more details.
  10513. +*/
  10514. +
  10515. +#ifndef PKG_DEST_H
  10516. +#define PKG_DEST_H
  10517. +
  10518. +typedef struct pkg_dest pkg_dest_t;
  10519. +struct pkg_dest
  10520. +{
  10521. + char *name;
  10522. + char *root_dir;
  10523. + char *ipkg_dir;
  10524. + char *lists_dir;
  10525. + char *info_dir;
  10526. + char *status_file_name;
  10527. + char *status_file_tmp_name;
  10528. + FILE *status_file;
  10529. +};
  10530. +
  10531. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
  10532. +void pkg_dest_deinit(pkg_dest_t *dest);
  10533. +
  10534. +#endif
  10535. +
  10536. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_dest_list.c busybox-1.16.1/archival/libipkg/pkg_dest_list.c
  10537. --- busybox-1.16.1.orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
  10538. +++ busybox-1.16.1/archival/libipkg/pkg_dest_list.c 2010-06-29 17:31:24.715868178 +0200
  10539. @@ -0,0 +1,85 @@
  10540. +/* pkg_dest_list.c - the itsy package management system
  10541. +
  10542. + Carl D. Worth
  10543. +
  10544. + Copyright (C) 2001 University of Southern California
  10545. +
  10546. + This program is free software; you can redistribute it and/or
  10547. + modify it under the terms of the GNU General Public License as
  10548. + published by the Free Software Foundation; either version 2, or (at
  10549. + your option) any later version.
  10550. +
  10551. + This program is distributed in the hope that it will be useful, but
  10552. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10553. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10554. + General Public License for more details.
  10555. +*/
  10556. +
  10557. +#include "ipkg.h"
  10558. +
  10559. +#include "pkg_dest.h"
  10560. +#include "void_list.h"
  10561. +#include "pkg_dest_list.h"
  10562. +
  10563. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
  10564. +{
  10565. + return void_list_elt_init((void_list_elt_t *) elt, data);
  10566. +}
  10567. +
  10568. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
  10569. +{
  10570. + void_list_elt_deinit((void_list_elt_t *) elt);
  10571. +}
  10572. +
  10573. +int pkg_dest_list_init(pkg_dest_list_t *list)
  10574. +{
  10575. + return void_list_init((void_list_t *) list);
  10576. +}
  10577. +
  10578. +void pkg_dest_list_deinit(pkg_dest_list_t *list)
  10579. +{
  10580. + pkg_dest_list_elt_t *iter;
  10581. + pkg_dest_t *pkg_dest;
  10582. +
  10583. + for (iter = list->head; iter; iter = iter->next) {
  10584. + pkg_dest = iter->data;
  10585. + pkg_dest_deinit(pkg_dest);
  10586. +
  10587. + /* malloced in pkg_dest_list_append */
  10588. + free(pkg_dest);
  10589. + iter->data = NULL;
  10590. + }
  10591. + void_list_deinit((void_list_t *) list);
  10592. +}
  10593. +
  10594. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10595. + const char *root_dir,const char *lists_dir)
  10596. +{
  10597. + int err;
  10598. + pkg_dest_t *pkg_dest;
  10599. +
  10600. + /* freed in plg_dest_list_deinit */
  10601. + pkg_dest = malloc(sizeof(pkg_dest_t));
  10602. + if (pkg_dest == NULL) {
  10603. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10604. + return NULL;
  10605. + }
  10606. +
  10607. + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
  10608. + err = void_list_append((void_list_t *) list, pkg_dest);
  10609. + if (err) {
  10610. + return NULL;
  10611. + }
  10612. +
  10613. + return pkg_dest;
  10614. +}
  10615. +
  10616. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
  10617. +{
  10618. + return void_list_push((void_list_t *) list, data);
  10619. +}
  10620. +
  10621. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
  10622. +{
  10623. + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
  10624. +}
  10625. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_dest_list.h busybox-1.16.1/archival/libipkg/pkg_dest_list.h
  10626. --- busybox-1.16.1.orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
  10627. +++ busybox-1.16.1/archival/libipkg/pkg_dest_list.h 2010-06-29 17:31:24.760275316 +0200
  10628. @@ -0,0 +1,50 @@
  10629. +/* pkg_dest_list.h - the itsy package management system
  10630. +
  10631. + Carl D. Worth
  10632. +
  10633. + Copyright (C) 2001 University of Southern California
  10634. +
  10635. + This program is free software; you can redistribute it and/or
  10636. + modify it under the terms of the GNU General Public License as
  10637. + published by the Free Software Foundation; either version 2, or (at
  10638. + your option) any later version.
  10639. +
  10640. + This program is distributed in the hope that it will be useful, but
  10641. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10642. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10643. + General Public License for more details.
  10644. +*/
  10645. +
  10646. +#ifndef PKG_DEST_LIST_H
  10647. +#define PKG_DEST_LIST_H
  10648. +
  10649. +#include "pkg_dest.h"
  10650. +
  10651. +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
  10652. +struct pkg_dest_list_elt
  10653. +{
  10654. + pkg_dest_list_elt_t *next;
  10655. + pkg_dest_t *data;
  10656. +};
  10657. +
  10658. +typedef struct pkg_dest_list pkg_dest_list_t;
  10659. +struct pkg_dest_list
  10660. +{
  10661. + pkg_dest_list_elt_t pre_head;
  10662. + pkg_dest_list_elt_t *head;
  10663. + pkg_dest_list_elt_t *tail;
  10664. +};
  10665. +
  10666. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
  10667. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
  10668. +
  10669. +int pkg_dest_list_init(pkg_dest_list_t *list);
  10670. +void pkg_dest_list_deinit(pkg_dest_list_t *list);
  10671. +
  10672. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10673. + const char *root_dir,const char* lists_dir);
  10674. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
  10675. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
  10676. +
  10677. +#endif
  10678. +
  10679. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_extract.c busybox-1.16.1/archival/libipkg/pkg_extract.c
  10680. --- busybox-1.16.1.orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
  10681. +++ busybox-1.16.1/archival/libipkg/pkg_extract.c 2010-06-29 17:31:24.818364193 +0200
  10682. @@ -0,0 +1,255 @@
  10683. +/* pkg_extract.c - the itsy package management system
  10684. +
  10685. + Carl D. Worth
  10686. +
  10687. + Copyright (C) 2001 University of Southern California
  10688. +
  10689. + This program is free software; you can redistribute it and/or
  10690. + modify it under the terms of the GNU General Public License as
  10691. + published by the Free Software Foundation; either version 2, or (at
  10692. + your option) any later version.
  10693. +
  10694. + This program is distributed in the hope that it will be useful, but
  10695. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10696. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10697. + General Public License for more details.
  10698. +*/
  10699. +
  10700. +#include "ipkg.h"
  10701. +#include <errno.h>
  10702. +#include <fcntl.h>
  10703. +#include <stdio.h>
  10704. +
  10705. +#include "pkg_extract.h"
  10706. +
  10707. +#include "libbb.h"
  10708. +#include "file_util.h"
  10709. +#include "sprintf_alloc.h"
  10710. +#include "unarchive.h"
  10711. +
  10712. +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
  10713. +#define IPKG_DATA_ARCHIVE "data.tar.gz"
  10714. +#define IPKG_CONTROL_FILE "control"
  10715. +
  10716. +static void FAST_FUNC ipkg_data_extract_all_prefix(archive_handle_t *archive_handle)
  10717. +{
  10718. + char *name_ptr = archive_handle->file_header->name;
  10719. +
  10720. + /* Skip all leading "/" */
  10721. + while (*name_ptr == '/')
  10722. + name_ptr++;
  10723. + /* Skip all leading "./" and "../" */
  10724. + while (name_ptr[0] == '.') {
  10725. + if (name_ptr[1] == '.' && name_ptr[2] == '/')
  10726. + name_ptr++;
  10727. + if (name_ptr[1] != '/')
  10728. + break;
  10729. + name_ptr += 2;
  10730. + }
  10731. +
  10732. + if (name_ptr[0] != '\0') {
  10733. + archive_handle->file_header->name = xasprintf("%s%s", archive_handle->dpkg__buffer, name_ptr);
  10734. + data_extract_all(archive_handle);
  10735. + }
  10736. +}
  10737. +
  10738. +static void FAST_FUNC ipkg_data_extract_to_buffer(archive_handle_t *archive_handle)
  10739. +{
  10740. + unsigned size = archive_handle->file_header->size;
  10741. +
  10742. + archive_handle->dpkg__buffer = xzalloc(size + 1);
  10743. + xread(archive_handle->src_fd, archive_handle->dpkg__buffer, size);
  10744. +}
  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->dpkg__buffer = path;
  10757. + archive->action_data = ipkg_data_extract_all_prefix;
  10758. + archive->ah_flags |= ARCHIVE_UNLINK_OLD;
  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->dpkg__buffer == NULL) {
  10771. + archive->dpkg__buffer = xmalloc(size);
  10772. + strcpy(archive->dpkg__buffer, archive->file_header->name);
  10773. + } else {
  10774. + size += strlen(archive->dpkg__buffer);
  10775. + archive->dpkg__buffer = xrealloc(archive->dpkg__buffer, size);
  10776. + strcat(archive->dpkg__buffer, archive->file_header->name);
  10777. + }
  10778. + strcat(archive->dpkg__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 = ipkg_data_extract_to_buffer;
  10795. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10796. + close(archive->src_fd);
  10797. + fputs(archive->dpkg__buffer, stream);
  10798. + free(archive->dpkg__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->dpkg__buffer = path;
  10824. + archive->action_data = ipkg_data_extract_all_prefix;
  10825. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  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->dpkg__buffer = path;
  10848. + archive->action_data = ipkg_data_extract_all_prefix;
  10849. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  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->dpkg__buffer, file);
  10932. + free(archive->dpkg__buffer);
  10933. + free(archive);
  10934. + free(name);
  10935. +
  10936. + return 0;
  10937. +}
  10938. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_extract.h busybox-1.16.1/archival/libipkg/pkg_extract.h
  10939. --- busybox-1.16.1.orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
  10940. +++ busybox-1.16.1/archival/libipkg/pkg_extract.h 2010-06-29 17:31:24.858368110 +0200
  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.16.1.orig/archival/libipkg/pkg.h busybox-1.16.1/archival/libipkg/pkg.h
  10975. --- busybox-1.16.1.orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
  10976. +++ busybox-1.16.1/archival/libipkg/pkg.h 2010-06-29 17:31:24.897965989 +0200
  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.16.1.orig/archival/libipkg/pkg_hash.c busybox-1.16.1/archival/libipkg/pkg_hash.c
  11208. --- busybox-1.16.1.orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
  11209. +++ busybox-1.16.1/archival/libipkg/pkg_hash.c 2010-06-29 17:31:24.956062867 +0200
  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.16.1.orig/archival/libipkg/pkg_hash.h busybox-1.16.1/archival/libipkg/pkg_hash.h
  11835. --- busybox-1.16.1.orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
  11836. +++ busybox-1.16.1/archival/libipkg/pkg_hash.h 2010-06-29 17:31:25.005861391 +0200
  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.16.1.orig/archival/libipkg/pkg_parse.c busybox-1.16.1/archival/libipkg/pkg_parse.c
  11900. --- busybox-1.16.1.orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
  11901. +++ busybox-1.16.1/archival/libipkg/pkg_parse.c 2010-06-29 17:31:25.059133294 +0200
  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.16.1.orig/archival/libipkg/pkg_parse.h busybox-1.16.1/archival/libipkg/pkg_parse.h
  12272. --- busybox-1.16.1.orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
  12273. +++ busybox-1.16.1/archival/libipkg/pkg_parse.h 2010-06-29 17:31:25.098367969 +0200
  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.16.1.orig/archival/libipkg/pkg_src.c busybox-1.16.1/archival/libipkg/pkg_src.c
  12307. --- busybox-1.16.1.orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
  12308. +++ busybox-1.16.1/archival/libipkg/pkg_src.c 2010-06-29 17:31:25.135873346 +0200
  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.16.1.orig/archival/libipkg/pkg_src.h busybox-1.16.1/archival/libipkg/pkg_src.h
  12354. --- busybox-1.16.1.orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
  12355. +++ busybox-1.16.1/archival/libipkg/pkg_src.h 2010-06-29 17:31:25.195873136 +0200
  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.16.1.orig/archival/libipkg/pkg_src_list.c busybox-1.16.1/archival/libipkg/pkg_src_list.c
  12392. --- busybox-1.16.1.orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
  12393. +++ busybox-1.16.1/archival/libipkg/pkg_src_list.c 2010-06-29 17:31:25.238287396 +0200
  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.16.1.orig/archival/libipkg/pkg_src_list.h busybox-1.16.1/archival/libipkg/pkg_src_list.h
  12471. --- busybox-1.16.1.orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
  12472. +++ busybox-1.16.1/archival/libipkg/pkg_src_list.h 2010-06-29 17:31:25.278367968 +0200
  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.16.1.orig/archival/libipkg/pkg_vec.c busybox-1.16.1/archival/libipkg/pkg_vec.c
  12532. --- busybox-1.16.1.orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
  12533. +++ busybox-1.16.1/archival/libipkg/pkg_vec.c 2010-06-29 17:31:25.319617983 +0200
  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.16.1.orig/archival/libipkg/pkg_vec.h busybox-1.16.1/archival/libipkg/pkg_vec.h
  12767. --- busybox-1.16.1.orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
  12768. +++ busybox-1.16.1/archival/libipkg/pkg_vec.h 2010-06-29 17:31:25.358368186 +0200
  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.16.1.orig/archival/libipkg/sprintf_alloc.h busybox-1.16.1/archival/libipkg/sprintf_alloc.h
  12833. --- busybox-1.16.1.orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
  12834. +++ busybox-1.16.1/archival/libipkg/sprintf_alloc.h 2010-06-29 17:31:25.395865857 +0200
  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.16.1.orig/archival/libipkg/str_list.c busybox-1.16.1/archival/libipkg/str_list.c
  12862. --- busybox-1.16.1.orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
  12863. +++ busybox-1.16.1/archival/libipkg/str_list.c 2010-06-29 17:31:25.437577685 +0200
  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.16.1.orig/archival/libipkg/str_list.h busybox-1.16.1/archival/libipkg/str_list.h
  12942. --- busybox-1.16.1.orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
  12943. +++ busybox-1.16.1/archival/libipkg/str_list.h 2010-06-29 17:31:25.487410851 +0200
  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.16.1.orig/archival/libipkg/str_util.c busybox-1.16.1/archival/libipkg/str_util.c
  12997. --- busybox-1.16.1.orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
  12998. +++ busybox-1.16.1/archival/libipkg/str_util.c 2010-06-29 17:31:25.540714295 +0200
  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.16.1.orig/archival/libipkg/str_util.h busybox-1.16.1/archival/libipkg/str_util.h
  13070. --- busybox-1.16.1.orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
  13071. +++ busybox-1.16.1/archival/libipkg/str_util.h 2010-06-29 17:31:25.578749246 +0200
  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.16.1.orig/archival/libipkg/user.c busybox-1.16.1/archival/libipkg/user.c
  13101. --- busybox-1.16.1.orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
  13102. +++ busybox-1.16.1/archival/libipkg/user.c 2010-06-29 17:31:25.628536327 +0200
  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.16.1.orig/archival/libipkg/user.h busybox-1.16.1/archival/libipkg/user.h
  13154. --- busybox-1.16.1.orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
  13155. +++ busybox-1.16.1/archival/libipkg/user.h 2010-06-29 17:31:25.678337891 +0200
  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.16.1.orig/archival/libipkg/void_list.c busybox-1.16.1/archival/libipkg/void_list.c
  13181. --- busybox-1.16.1.orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
  13182. +++ busybox-1.16.1/archival/libipkg/void_list.c 2010-06-29 17:31:25.715873105 +0200
  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.16.1.orig/archival/libipkg/void_list.h busybox-1.16.1/archival/libipkg/void_list.h
  13379. --- busybox-1.16.1.orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
  13380. +++ busybox-1.16.1/archival/libipkg/void_list.h 2010-06-29 17:31:25.758368030 +0200
  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.16.1.orig/archival/libipkg/xsystem.c busybox-1.16.1/archival/libipkg/xsystem.c
  13442. --- busybox-1.16.1.orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
  13443. +++ busybox-1.16.1/archival/libipkg/xsystem.c 2010-06-29 17:31:25.799781135 +0200
  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.16.1.orig/archival/libipkg/xsystem.h busybox-1.16.1/archival/libipkg/xsystem.h
  13510. --- busybox-1.16.1.orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
  13511. +++ busybox-1.16.1/archival/libipkg/xsystem.h 2010-06-29 17:31:25.855865061 +0200
  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.16.1.orig/archival/libunarchive/Kbuild busybox-1.16.1/archival/libunarchive/Kbuild
  13548. --- busybox-1.16.1.orig/archival/libunarchive/Kbuild 2010-03-20 03:58:07.000000000 +0100
  13549. +++ busybox-1.16.1/archival/libunarchive/Kbuild 2010-06-29 17:31:25.898368046 +0200
  13550. @@ -40,6 +40,7 @@
  13551. lib-$(CONFIG_DPKG) += $(DPKG_FILES)
  13552. lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
  13553. lib-$(CONFIG_GUNZIP) += decompress_unzip.o
  13554. +lib-$(CONFIG_IPKG) += open_transformer.o get_header_tar.o get_header_tar_gz.o
  13555. lib-$(CONFIG_RPM2CPIO) += decompress_unzip.o get_header_cpio.o
  13556. lib-$(CONFIG_RPM) += open_transformer.o decompress_unzip.o get_header_cpio.o
  13557. lib-$(CONFIG_TAR) += get_header_tar.o
  13558. diff -Nur busybox-1.16.1.orig/include/applets.h busybox-1.16.1/include/applets.h
  13559. --- busybox-1.16.1.orig/include/applets.h 2010-03-28 19:43:35.000000000 +0200
  13560. +++ busybox-1.16.1/include/applets.h 2010-06-29 17:31:25.938368064 +0200
  13561. @@ -214,6 +214,7 @@
  13562. IF_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_DROP))
  13563. IF_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
  13564. IF_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
  13565. +IF_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_DROP))
  13566. IF_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_DROP))
  13567. IF_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_DROP))
  13568. IF_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_DROP))
  13569. diff -Nur busybox-1.16.1.orig/include/unarchive.h busybox-1.16.1/include/unarchive.h
  13570. --- busybox-1.16.1.orig/include/unarchive.h 2010-03-28 19:43:35.000000000 +0200
  13571. +++ busybox-1.16.1/include/unarchive.h 2010-06-29 17:31:25.978368044 +0200
  13572. @@ -53,7 +53,7 @@
  13573. off_t offset;
  13574. /* Archiver specific. Can make it a union if it ever gets big */
  13575. -#if ENABLE_TAR || ENABLE_DPKG || ENABLE_DPKG_DEB
  13576. +#if ENABLE_TAR || ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13577. smallint tar__end;
  13578. # if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
  13579. char* tar__longname;
  13580. @@ -65,7 +65,7 @@
  13581. struct hardlinks_t *cpio__hardlinks_to_create;
  13582. struct hardlinks_t *cpio__created_hardlinks;
  13583. #endif
  13584. -#if ENABLE_DPKG || ENABLE_DPKG_DEB
  13585. +#if ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13586. /* Temporary storage */
  13587. char *dpkg__buffer;
  13588. /* How to process any sub archive, e.g. get_header_tar_gz */
  13589. diff -Nur busybox-1.16.1.orig/include/usage.h busybox-1.16.1/include/usage.h
  13590. --- busybox-1.16.1.orig/include/usage.h 2010-03-28 19:44:04.000000000 +0200
  13591. +++ busybox-1.16.1/include/usage.h 2010-06-29 17:31:26.018367985 +0200
  13592. @@ -1592,6 +1592,82 @@
  13593. "$ ls -la /tmp/busybox*\n" \
  13594. "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
  13595. +#define ipkg_trivial_usage \
  13596. + "[options]... sub-command [arguments]..."
  13597. +#define ipkg_full_usage \
  13598. + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
  13599. + "\n" \
  13600. + "Sub-commands:\n" \
  13601. + "\nPackage Manipulation:\n" \
  13602. + "\tupdate Update list of available packages\n" \
  13603. + "\tupgrade Upgrade all installed packages to latest version\n" \
  13604. + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
  13605. + "\tinstall <file.ipk> Install package <file.ipk>\n" \
  13606. + "\tconfigure [<pkg>] Configure unpacked packages\n" \
  13607. + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
  13608. + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
  13609. + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
  13610. + "\n" \
  13611. + "Informational Commands:\n" \
  13612. + "\tlist List available packages and descriptions\n" \
  13613. + "\tlist_installed List all and only the installed packages and description \n" \
  13614. + "\tfiles <pkg> List all files belonging to <pkg>\n" \
  13615. + "\tsearch <file|regexp> Search for a package providing <file>\n" \
  13616. + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
  13617. + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
  13618. + "\tdownload <pkg> Download <pkg> to current directory.\n" \
  13619. + "\tcompare_versions <v1> <op> <v2>\n" \
  13620. + "\t compare versions using <= < > >= = << >>\n" \
  13621. + "\tprint_architecture prints the architecture.\n" \
  13622. + "\tprint_installation_architecture\n" \
  13623. + "\twhatdepends [-A] [pkgname|pat]+\n" \
  13624. + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
  13625. + "\twhatprovides [-A] [pkgname|pat]+\n" \
  13626. + "\twhatconflicts [-A] [pkgname|pat]+\n" \
  13627. + "\twhatreplaces [-A] [pkgname|pat]+\n" \
  13628. + "\t prints the installation architecture.\n" \
  13629. + "\n" \
  13630. + "\nOptions:\n" \
  13631. + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
  13632. + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
  13633. + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
  13634. + "\t 0 errors only\n" \
  13635. + "\t 1 normal messages (default)\n" \
  13636. + "\t 2 informative messages\n" \
  13637. + "\t 3 debug output\n" \
  13638. + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
  13639. + "\t-conf <conf_file> Default configuration file location\n" \
  13640. + " is /etc/ipkg.conf\n" \
  13641. + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
  13642. + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
  13643. + " <dest_name> should be a defined dest name from\n" \
  13644. + " the configuration file, (but can also be a\n" \
  13645. + " directory name in a pinch).\n" \
  13646. + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
  13647. + "\t-offline <offline_root> offline installation of packages.\n" \
  13648. + "\t-verbose_wget more wget messages\n" \
  13649. + "\n" \
  13650. + "Force Options (use when ipkg is too smart for its own good):\n" \
  13651. + "\t-force-depends Make dependency checks warnings instead of errors\n" \
  13652. + "\t Install/remove package in spite of failed dependences\n" \
  13653. + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
  13654. + " (no prompts). Note that this will not prevent\n" \
  13655. + " package installation scripts from prompting.\n" \
  13656. + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
  13657. + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
  13658. + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
  13659. + "\t-force_space Install even if there does not seem to be enough space.\n" \
  13660. + "\t-noaction No action -- test only\n" \
  13661. + "\t-nodeps Do not follow dependences\n" \
  13662. + "\t-force-removal-of-dependent-packages\n" \
  13663. + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
  13664. + "\t-test No action -- test only\n" \
  13665. + "\t-t Specify tmp-dir.\n" \
  13666. + "\t--tmp-dir Specify tmp-dir.\n" \
  13667. + "\n" \
  13668. + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
  13669. + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
  13670. +
  13671. #define halt_trivial_usage \
  13672. "[-d DELAY] [-n] [-f]" IF_FEATURE_WTMP(" [-w]")
  13673. #define halt_full_usage "\n\n" \
  13674. diff -Nur busybox-1.16.1.orig/Makefile busybox-1.16.1/Makefile
  13675. --- busybox-1.16.1.orig/Makefile 2010-03-28 19:44:09.000000000 +0200
  13676. +++ busybox-1.16.1/Makefile 2010-06-29 17:31:26.058368031 +0200
  13677. @@ -454,6 +454,7 @@
  13678. libs-y := \
  13679. archival/ \
  13680. + archival/libipkg/ \
  13681. archival/libunarchive/ \
  13682. console-tools/ \
  13683. coreutils/ \