001-ipkg.patch 423 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705
  1. diff -Nur busybox-1.17.0.orig/archival/Config.src busybox-1.17.0/archival/Config.src
  2. --- busybox-1.17.0.orig/archival/Config.src 2010-06-25 01:32:35.000000000 +0200
  3. +++ busybox-1.17.0/archival/Config.src 2010-07-08 12:04:28.571001869 +0200
  4. @@ -202,6 +202,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 y
  18. diff -Nur busybox-1.17.0.orig/archival/ipkg.c busybox-1.17.0/archival/ipkg.c
  19. --- busybox-1.17.0.orig/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
  20. +++ busybox-1.17.0/archival/ipkg.c 2010-07-08 12:01:56.199003930 +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.17.0.orig/archival/Kbuild.src busybox-1.17.0/archival/Kbuild.src
  51. --- busybox-1.17.0.orig/archival/Kbuild.src 2010-06-24 04:40:43.000000000 +0200
  52. +++ busybox-1.17.0/archival/Kbuild.src 2010-07-08 12:02:53.135001644 +0200
  53. @@ -23,6 +23,7 @@
  54. lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o
  55. lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
  56. lib-$(CONFIG_BZIP2) += bzip2.o bbunzip.o
  57. +lib-$(CONFIG_IPKG) += ipkg.o
  58. lib-$(CONFIG_UNXZ) += bbunzip.o
  59. lib-$(CONFIG_UNLZMA) += bbunzip.o
  60. diff -Nur busybox-1.17.0.orig/archival/libipkg/args.c busybox-1.17.0/archival/libipkg/args.c
  61. --- busybox-1.17.0.orig/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
  62. +++ busybox-1.17.0/archival/libipkg/args.c 2010-07-08 12:01:56.199003930 +0200
  63. @@ -0,0 +1,242 @@
  64. +/* args.c - parse command-line args
  65. +
  66. + Carl D. Worth
  67. +
  68. + Copyright 2001 University of Southern California
  69. +
  70. + This program is free software; you can redistribute it and/or modify
  71. + it under the terms of the GNU General Public License as published by
  72. + the Free Software Foundation; either version 2, or (at your option)
  73. + any later version.
  74. +
  75. + This program is distributed in the hope that it will be useful,
  76. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  77. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  78. + GNU General Public License for more details.
  79. + */
  80. +
  81. +#include <getopt.h>
  82. +#include <stdlib.h>
  83. +#include <string.h>
  84. +#include <unistd.h>
  85. +
  86. +#include "ipkg.h"
  87. +#include "ipkg_message.h"
  88. +
  89. +#include "args.h"
  90. +#include "sprintf_alloc.h"
  91. +
  92. +#include "libbb.h"
  93. +
  94. +
  95. +static void print_version(void);
  96. +
  97. +enum long_args_opt
  98. +{
  99. + ARGS_OPT_FORCE_DEFAULTS = 129,
  100. + ARGS_OPT_FORCE_DEPENDS,
  101. + ARGS_OPT_FORCE_OVERWRITE,
  102. + ARGS_OPT_FORCE_DOWNGRADE,
  103. + ARGS_OPT_FORCE_REINSTALL,
  104. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
  105. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
  106. + ARGS_OPT_FORCE_SPACE,
  107. + ARGS_OPT_NOACTION,
  108. + ARGS_OPT_NODEPS,
  109. + ARGS_OPT_VERBOSE_WGET,
  110. + ARGS_OPT_VERBOSITY,
  111. + ARGS_OPT_MULTIPLE_PROVIDERS
  112. +};
  113. +
  114. +int args_init(args_t *args)
  115. +{
  116. + const char *conf_file_dir;
  117. +
  118. + memset(args, 0, sizeof(args_t));
  119. +
  120. + args->dest = ARGS_DEFAULT_DEST;
  121. +
  122. + conf_file_dir = getenv("IPKG_CONF_DIR");
  123. + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
  124. + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
  125. + }
  126. + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
  127. + ARGS_DEFAULT_CONF_FILE_NAME);
  128. +
  129. + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
  130. + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
  131. + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
  132. + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
  133. + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
  134. + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
  135. + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
  136. + args->noaction = ARGS_DEFAULT_NOACTION;
  137. + args->nodeps = ARGS_DEFAULT_NODEPS;
  138. + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
  139. + args->verbosity = ARGS_DEFAULT_VERBOSITY;
  140. + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
  141. + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
  142. + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
  143. + args->multiple_providers = 0;
  144. + args->nocheckfordirorfile = 0;
  145. + args->noreadfeedsfile = 0;
  146. +
  147. + return 1;
  148. +}
  149. +
  150. +void args_deinit(args_t *args)
  151. +{
  152. + free(args->conf_file);
  153. + args->conf_file = NULL;
  154. +}
  155. +
  156. +int args_parse(args_t *args, int argc, char *argv[])
  157. +{
  158. + int c;
  159. + int option_index = 0;
  160. + int parse_err = 0;
  161. + static struct option long_options[] = {
  162. + {"query-all", 0, 0, 'A'},
  163. + {"conf-file", 1, 0, 'f'},
  164. + {"conf", 1, 0, 'f'},
  165. + {"dest", 1, 0, 'd'},
  166. + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  167. + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  168. + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  169. + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  170. + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  171. + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  172. + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  173. + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  174. + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  175. + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  176. + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
  177. + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
  178. + {"recursive", 0, 0,
  179. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  180. + {"force-removal-of-dependent-packages", 0, 0,
  181. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  182. + {"force_removal_of_dependent_packages", 0, 0,
  183. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  184. + {"force-removal-of-essential-packages", 0, 0,
  185. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  186. + {"force_removal_of_essential_packages", 0, 0,
  187. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  188. + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  189. + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  190. + {"noaction", 0, 0, ARGS_OPT_NOACTION},
  191. + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
  192. + {"offline", 1, 0, 'o'},
  193. + {"offline-root", 1, 0, 'o'},
  194. + {"test", 0, 0, ARGS_OPT_NOACTION},
  195. + {"tmp-dir", 1, 0, 't'},
  196. + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  197. + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  198. + {"verbosity", 2, 0, 'V'},
  199. + {"version", 0, 0, 'v'},
  200. + {0, 0, 0, 0}
  201. + };
  202. +
  203. + while (1) {
  204. + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
  205. + if (c == -1)
  206. + break;
  207. +
  208. + switch (c) {
  209. + case 'A':
  210. + args->query_all = 1;
  211. + break;
  212. + case 'd':
  213. + args->dest = optarg;
  214. + break;
  215. + case 'f':
  216. + free(args->conf_file);
  217. + args->conf_file = strdup(optarg);
  218. + break;
  219. + case 'o':
  220. + args->offline_root = optarg;
  221. + break;
  222. + case 'n':
  223. + args->noaction = 1;
  224. + break;
  225. + case 't':
  226. + args->tmp_dir = strdup(optarg);
  227. + break;
  228. + case 'v':
  229. + print_version();
  230. + exit(0);
  231. + case 'V':
  232. + case ARGS_OPT_VERBOSITY:
  233. + if (optarg)
  234. + args->verbosity = atoi(optarg);
  235. + else
  236. + args->verbosity += 1;
  237. + break;
  238. + case ARGS_OPT_FORCE_DEFAULTS:
  239. + args->force_defaults = 1;
  240. + break;
  241. + case ARGS_OPT_FORCE_DEPENDS:
  242. + args->force_depends = 1;
  243. + break;
  244. + case ARGS_OPT_FORCE_OVERWRITE:
  245. + args->force_overwrite = 1;
  246. + break;
  247. + case ARGS_OPT_FORCE_DOWNGRADE:
  248. + args->force_downgrade = 1;
  249. + break;
  250. + case ARGS_OPT_FORCE_REINSTALL:
  251. + args->force_reinstall = 1;
  252. + break;
  253. + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
  254. + args->force_removal_of_essential_packages = 1;
  255. + break;
  256. + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
  257. + args->force_removal_of_dependent_packages = 1;
  258. + break;
  259. + case ARGS_OPT_FORCE_SPACE:
  260. + args->force_space = 1;
  261. + break;
  262. + case ARGS_OPT_VERBOSE_WGET:
  263. + args->verbose_wget = 1;
  264. + break;
  265. + case ARGS_OPT_MULTIPLE_PROVIDERS:
  266. + args->multiple_providers = 1;
  267. + break;
  268. + case ARGS_OPT_NODEPS:
  269. + args->nodeps = 1;
  270. + break;
  271. + case ARGS_OPT_NOACTION:
  272. + args->noaction = 1;
  273. + break;
  274. + case ':':
  275. + parse_err++;
  276. + break;
  277. + case '?':
  278. + parse_err++;
  279. + break;
  280. + default:
  281. + bb_error_msg("Confusion: getopt_long returned %d\n", c);
  282. + }
  283. + }
  284. +
  285. + if (parse_err) {
  286. + return -parse_err;
  287. + } else {
  288. + return optind;
  289. + }
  290. +}
  291. +
  292. +void args_usage(const char *complaint)
  293. +{
  294. + if (complaint) {
  295. + bb_error_msg("%s\n", complaint);
  296. + }
  297. + print_version();
  298. + bb_show_usage();
  299. + exit(1);
  300. +}
  301. +
  302. +static void print_version(void)
  303. +{
  304. + bb_error_msg("version %s\n", IPKG_VERSION);
  305. +}
  306. diff -Nur busybox-1.17.0.orig/archival/libipkg/args.h busybox-1.17.0/archival/libipkg/args.h
  307. --- busybox-1.17.0.orig/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
  308. +++ busybox-1.17.0/archival/libipkg/args.h 2010-07-08 12:01:56.199003930 +0200
  309. @@ -0,0 +1,72 @@
  310. +/* args.h - parse command-line args
  311. +
  312. + Carl D. Worth
  313. +
  314. + Copyright 2001 University of Southern California
  315. +
  316. + This program is free software; you can redistribute it and/or modify
  317. + it under the terms of the GNU General Public License as published by
  318. + the Free Software Foundation; either version 2, or (at your option)
  319. + any later version.
  320. +
  321. + This program is distributed in the hope that it will be useful,
  322. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  323. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  324. + GNU General Public License for more details.
  325. +*/
  326. +
  327. +#ifndef ARGS_H
  328. +#define ARGS_H
  329. +
  330. +struct args
  331. +{
  332. + char *conf_file;
  333. + char *dest;
  334. + char *tmp_dir;
  335. + int force_defaults;
  336. + int force_depends;
  337. + int force_overwrite;
  338. + int force_downgrade;
  339. + int force_reinstall;
  340. + int force_removal_of_essential_packages;
  341. + int force_removal_of_dependent_packages;
  342. + int force_space;
  343. + int noaction;
  344. + int nodeps;
  345. + int multiple_providers;
  346. + int query_all;
  347. + int verbose_wget;
  348. + int verbosity;
  349. + int nocheckfordirorfile;
  350. + int noreadfeedsfile;
  351. + char *offline_root;
  352. + char *offline_root_pre_script_cmd;
  353. + char *offline_root_post_script_cmd;
  354. +};
  355. +typedef struct args args_t;
  356. +
  357. +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
  358. +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
  359. +#define ARGS_DEFAULT_DEST NULL
  360. +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
  361. +#define ARGS_DEFAULT_FORCE_DEPENDS 0
  362. +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
  363. +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
  364. +#define ARGS_DEFAULT_FORCE_REINSTALL 0
  365. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
  366. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
  367. +#define ARGS_DEFAULT_FORCE_SPACE 0
  368. +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
  369. +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
  370. +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
  371. +#define ARGS_DEFAULT_NOACTION 0
  372. +#define ARGS_DEFAULT_NODEPS 0
  373. +#define ARGS_DEFAULT_VERBOSE_WGET 0
  374. +#define ARGS_DEFAULT_VERBOSITY 1
  375. +
  376. +int args_init(args_t *args);
  377. +void args_deinit(args_t *args);
  378. +int args_parse(args_t *args, int argc, char *argv[]);
  379. +void args_usage(const char *complaint);
  380. +
  381. +#endif
  382. diff -Nur busybox-1.17.0.orig/archival/libipkg/conffile.c busybox-1.17.0/archival/libipkg/conffile.c
  383. --- busybox-1.17.0.orig/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
  384. +++ busybox-1.17.0/archival/libipkg/conffile.c 2010-07-08 12:01:56.199003930 +0200
  385. @@ -0,0 +1,65 @@
  386. +/* conffile.c - the itsy package management system
  387. +
  388. + Carl D. Worth
  389. +
  390. + Copyright (C) 2001 University of Southern California
  391. +
  392. + This program is free software; you can redistribute it and/or
  393. + modify it under the terms of the GNU General Public License as
  394. + published by the Free Software Foundation; either version 2, or (at
  395. + your option) any later version.
  396. +
  397. + This program is distributed in the hope that it will be useful, but
  398. + WITHOUT ANY WARRANTY; without even the implied warranty of
  399. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  400. + General Public License for more details.
  401. +*/
  402. +
  403. +#include <string.h>
  404. +#include <stdlib.h>
  405. +
  406. +#include "libbb.h"
  407. +#include "ipkg.h"
  408. +#include "ipkg_message.h"
  409. +
  410. +#include "conffile.h"
  411. +#include "file_util.h"
  412. +#include "sprintf_alloc.h"
  413. +
  414. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum)
  415. +{
  416. + return nv_pair_init(conffile, file_name, (char *)md5sum);
  417. +}
  418. +
  419. +void conffile_deinit(conffile_t *conffile)
  420. +{
  421. + nv_pair_deinit(conffile);
  422. +}
  423. +
  424. +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
  425. +{
  426. + uint8_t *md5sum;
  427. + char *filename = conffile->name;
  428. + char *root_filename;
  429. + int ret;
  430. +
  431. + if (conffile->value == NULL) {
  432. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
  433. + return 1;
  434. + }
  435. +
  436. + root_filename = root_filename_alloc(conf, filename);
  437. +
  438. + md5sum = file_md5sum_alloc(root_filename);
  439. +
  440. + ret = strcmp((char *)md5sum, conffile->value);
  441. + if (ret) {
  442. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
  443. + conffile->name, md5sum, conffile->value);
  444. + }
  445. +
  446. + free(root_filename);
  447. + free(md5sum);
  448. +
  449. + return ret;
  450. +}
  451. diff -Nur busybox-1.17.0.orig/archival/libipkg/conffile.h busybox-1.17.0/archival/libipkg/conffile.h
  452. --- busybox-1.17.0.orig/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
  453. +++ busybox-1.17.0/archival/libipkg/conffile.h 2010-07-08 12:01:56.203011424 +0200
  454. @@ -0,0 +1,30 @@
  455. +/* conffile.h - the itsy package management system
  456. +
  457. + Carl D. Worth
  458. +
  459. + Copyright (C) 2001 University of Southern California
  460. +
  461. + This program is free software; you can redistribute it and/or
  462. + modify it under the terms of the GNU General Public License as
  463. + published by the Free Software Foundation; either version 2, or (at
  464. + your option) any later version.
  465. +
  466. + This program is distributed in the hope that it will be useful, but
  467. + WITHOUT ANY WARRANTY; without even the implied warranty of
  468. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  469. + General Public License for more details.
  470. +*/
  471. +
  472. +#ifndef CONFFILE_H
  473. +#define CONFFILE_H
  474. +
  475. +#include "nv_pair.h"
  476. +
  477. +typedef struct nv_pair conffile_t;
  478. +
  479. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum);
  480. +void conffile_deinit(conffile_t *conffile);
  481. +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
  482. +
  483. +#endif
  484. +
  485. diff -Nur busybox-1.17.0.orig/archival/libipkg/conffile_list.c busybox-1.17.0/archival/libipkg/conffile_list.c
  486. --- busybox-1.17.0.orig/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
  487. +++ busybox-1.17.0/archival/libipkg/conffile_list.c 2010-07-08 12:01:56.203011424 +0200
  488. @@ -0,0 +1,47 @@
  489. +/* conffile_list.c - the itsy package management system
  490. +
  491. + Carl D. Worth
  492. +
  493. + Copyright (C) 2001 University of Southern California
  494. +
  495. + This program is free software; you can redistribute it and/or
  496. + modify it under the terms of the GNU General Public License as
  497. + published by the Free Software Foundation; either version 2, or (at
  498. + your option) any later version.
  499. +
  500. + This program is distributed in the hope that it will be useful, but
  501. + WITHOUT ANY WARRANTY; without even the implied warranty of
  502. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  503. + General Public License for more details.
  504. +*/
  505. +
  506. +#include "ipkg.h"
  507. +
  508. +#include "conffile_list.h"
  509. +
  510. +int conffile_list_init(conffile_list_t *list)
  511. +{
  512. + return nv_pair_list_init(list);
  513. +}
  514. +
  515. +void conffile_list_deinit(conffile_list_t *list)
  516. +{
  517. + nv_pair_list_deinit(list);
  518. +}
  519. +
  520. +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
  521. + const char *md5sum)
  522. +{
  523. + return nv_pair_list_append(list, file_name, md5sum);
  524. +}
  525. +
  526. +int conffile_list_push(conffile_list_t *list, conffile_t *data)
  527. +{
  528. + return nv_pair_list_push(list, data);
  529. +}
  530. +
  531. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
  532. +{
  533. + return nv_pair_list_pop(list);
  534. +}
  535. +
  536. diff -Nur busybox-1.17.0.orig/archival/libipkg/conffile_list.h busybox-1.17.0/archival/libipkg/conffile_list.h
  537. --- busybox-1.17.0.orig/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
  538. +++ busybox-1.17.0/archival/libipkg/conffile_list.h 2010-07-08 12:01:56.203011424 +0200
  539. @@ -0,0 +1,36 @@
  540. +/* conffile_list.h - the itsy package management system
  541. +
  542. + Carl D. Worth
  543. +
  544. + Copyright (C) 2001 University of Southern California
  545. +
  546. + This program is free software; you can redistribute it and/or
  547. + modify it under the terms of the GNU General Public License as
  548. + published by the Free Software Foundation; either version 2, or (at
  549. + your option) any later version.
  550. +
  551. + This program is distributed in the hope that it will be useful, but
  552. + WITHOUT ANY WARRANTY; without even the implied warranty of
  553. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  554. + General Public License for more details.
  555. +*/
  556. +
  557. +#ifndef CONFFILE_LIST_H
  558. +#define CONFFILE_LIST_H
  559. +
  560. +#include "conffile.h"
  561. +#include "nv_pair_list.h"
  562. +
  563. +typedef struct nv_pair_list_elt conffile_list_elt_t;
  564. +typedef struct nv_pair_list conffile_list_t;
  565. +
  566. +int conffile_list_init(conffile_list_t *list);
  567. +void conffile_list_deinit(conffile_list_t *list);
  568. +
  569. +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
  570. + const char *root_dir);
  571. +int conffile_list_push(conffile_list_t *list, conffile_t *data);
  572. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
  573. +
  574. +#endif
  575. +
  576. diff -Nur busybox-1.17.0.orig/archival/libipkg/file_util.c busybox-1.17.0/archival/libipkg/file_util.c
  577. --- busybox-1.17.0.orig/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
  578. +++ busybox-1.17.0/archival/libipkg/file_util.c 2010-07-08 12:01:56.203011424 +0200
  579. @@ -0,0 +1,186 @@
  580. +/* file_util.c - convenience routines for common stat operations
  581. +
  582. + Carl D. Worth
  583. +
  584. + Copyright (C) 2001 University of Southern California
  585. +
  586. + This program is free software; you can redistribute it and/or
  587. + modify it under the terms of the GNU General Public License as
  588. + published by the Free Software Foundation; either version 2, or (at
  589. + your option) any later version.
  590. +
  591. + This program is distributed in the hope that it will be useful, but
  592. + WITHOUT ANY WARRANTY; without even the implied warranty of
  593. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  594. + General Public License for more details.
  595. +*/
  596. +
  597. +#include "ipkg.h"
  598. +#include <sys/types.h>
  599. +#include <sys/stat.h>
  600. +
  601. +#include "sprintf_alloc.h"
  602. +#include "file_util.h"
  603. +#include "libbb.h"
  604. +#undef strlen
  605. +
  606. +int file_exists(const char *file_name)
  607. +{
  608. + int err;
  609. + struct stat stat_buf;
  610. +
  611. + err = stat(file_name, &stat_buf);
  612. + if (err == 0) {
  613. + return 1;
  614. + } else {
  615. + return 0;
  616. + }
  617. +}
  618. +
  619. +int file_is_dir(const char *file_name)
  620. +{
  621. + int err;
  622. + struct stat stat_buf;
  623. +
  624. + err = stat(file_name, &stat_buf);
  625. + if (err) {
  626. + return 0;
  627. + }
  628. +
  629. + return S_ISDIR(stat_buf.st_mode);
  630. +}
  631. +
  632. +/* read a single line from a file, stopping at a newline or EOF.
  633. + If a newline is read, it will appear in the resulting string.
  634. + Return value is a malloc'ed char * which should be freed at
  635. + some point by the caller.
  636. +
  637. + Return value is NULL if the file is at EOF when called.
  638. +*/
  639. +#define FILE_READ_LINE_BUF_SIZE 1024
  640. +char *file_read_line_alloc(FILE *file)
  641. +{
  642. + char buf[FILE_READ_LINE_BUF_SIZE];
  643. + int buf_len;
  644. + char *line = NULL;
  645. + int line_size = 0;
  646. +
  647. + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
  648. + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
  649. + buf_len = strlen(buf);
  650. + if (line) {
  651. + line_size += buf_len;
  652. + line = realloc(line, line_size);
  653. + if (line == NULL) {
  654. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  655. + break;
  656. + }
  657. + strcat(line, buf);
  658. + } else {
  659. + line_size = buf_len + 1;
  660. + line = strdup(buf);
  661. + }
  662. + if (buf[buf_len - 1] == '\n') {
  663. + break;
  664. + }
  665. + }
  666. +
  667. + return line;
  668. +}
  669. +
  670. +int file_move(const char *src, const char *dest)
  671. +{
  672. + int err;
  673. +
  674. + err = rename(src, dest);
  675. +
  676. + if (err && errno == EXDEV) {
  677. + err = file_copy(src, dest);
  678. + unlink(src);
  679. + } else if (err) {
  680. + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
  681. + __FUNCTION__, src, dest, strerror(errno));
  682. + }
  683. +
  684. + return err;
  685. +}
  686. +
  687. +/* I put these here to keep libbb dependencies from creeping all over
  688. + the ipkg code */
  689. +int file_copy(const char *src, const char *dest)
  690. +{
  691. + int err;
  692. +
  693. + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
  694. + if (err) {
  695. + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
  696. + __FUNCTION__, src, dest);
  697. + }
  698. +
  699. + return err;
  700. +}
  701. +
  702. +int file_mkdir_hier(char *path, long mode)
  703. +{
  704. + return bb_make_directory(path, mode, FILEUTILS_RECUR);
  705. +}
  706. +
  707. +static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
  708. + unsigned hash_length)
  709. +{
  710. + /* xzalloc zero-terminates */
  711. + char *hex_value = xzalloc((hash_length * 2) + 1);
  712. + bin2hex(hex_value, (char*)hash_value, hash_length);
  713. + return (unsigned char *)hex_value;
  714. +}
  715. +
  716. +static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
  717. +{
  718. + int src_fd, hash_len, count;
  719. + union _ctx_ {
  720. + sha1_ctx_t sha1;
  721. + md5_ctx_t md5;
  722. + } context;
  723. + uint8_t *hash_value = NULL;
  724. + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
  725. + void FAST_FUNC (*update)(const void*, size_t, void*);
  726. + void FAST_FUNC (*final)(void*, void*);
  727. +
  728. + src_fd = open_or_warn_stdin(filename);
  729. + if (src_fd < 0) {
  730. + return NULL;
  731. + }
  732. +
  733. + /* figure specific hash algorithims */
  734. + if (ENABLE_MD5SUM && hash_algo == HASH_MD5) {
  735. + md5_begin(&context.md5);
  736. + update = (void*)md5_hash;
  737. + final = (void*)md5_end;
  738. + hash_len = 16;
  739. + } else {
  740. + bb_error_msg_and_die("algorithm not supported");
  741. + }
  742. +
  743. + while (0 < (count = safe_read(src_fd, in_buf, 4096))) {
  744. + update(in_buf, count, &context);
  745. + }
  746. +
  747. + if (count == 0) {
  748. + final(in_buf, &context);
  749. + hash_value = hash_bin_to_hex(in_buf, hash_len);
  750. + }
  751. +
  752. + RELEASE_CONFIG_BUFFER(in_buf);
  753. +
  754. + if (src_fd != STDIN_FILENO) {
  755. + close(src_fd);
  756. + }
  757. +
  758. + return hash_value;
  759. +}
  760. +
  761. +uint8_t *file_md5sum_alloc(const char *file_name)
  762. +{
  763. + return hash_file(file_name, HASH_MD5);
  764. +}
  765. +
  766. diff -Nur busybox-1.17.0.orig/archival/libipkg/file_util.h busybox-1.17.0/archival/libipkg/file_util.h
  767. --- busybox-1.17.0.orig/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
  768. +++ busybox-1.17.0/archival/libipkg/file_util.h 2010-07-08 12:01:56.203011424 +0200
  769. @@ -0,0 +1,29 @@
  770. +/* file_util.h - convenience routines for common file operations
  771. +
  772. + Carl D. Worth
  773. +
  774. + Copyright (C) 2001 University of Southern California
  775. +
  776. + This program is free software; you can redistribute it and/or
  777. + modify it under the terms of the GNU General Public License as
  778. + published by the Free Software Foundation; either version 2, or (at
  779. + your option) any later version.
  780. +
  781. + This program is distributed in the hope that it will be useful, but
  782. + WITHOUT ANY WARRANTY; without even the implied warranty of
  783. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  784. + General Public License for more details.
  785. +*/
  786. +
  787. +#ifndef FILE_UTIL_H
  788. +#define FILE_UTIL_H
  789. +
  790. +int file_exists(const char *file_name);
  791. +int file_is_dir(const char *file_name);
  792. +char *file_read_line_alloc(FILE *file);
  793. +int file_move(const char *src, const char *dest);
  794. +int file_copy(const char *src, const char *dest);
  795. +int file_mkdir_hier(char *path, long mode);
  796. +uint8_t *file_md5sum_alloc(const char *file_name);
  797. +
  798. +#endif
  799. diff -Nur busybox-1.17.0.orig/archival/libipkg/hash_table.c busybox-1.17.0/archival/libipkg/hash_table.c
  800. --- busybox-1.17.0.orig/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
  801. +++ busybox-1.17.0/archival/libipkg/hash_table.c 2010-07-08 12:01:56.203011424 +0200
  802. @@ -0,0 +1,155 @@
  803. +/* hash.c - hash tables for ipkg
  804. +
  805. + Steven M. Ayer, Jamey Hicks
  806. +
  807. + Copyright (C) 2002 Compaq Computer Corporation
  808. +
  809. + This program is free software; you can redistribute it and/or
  810. + modify it under the terms of the GNU General Public License as
  811. + published by the Free Software Foundation; either version 2, or (at
  812. + your option) any later version.
  813. +
  814. + This program is distributed in the hope that it will be useful, but
  815. + WITHOUT ANY WARRANTY; without even the implied warranty of
  816. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  817. + General Public License for more details.
  818. +*/
  819. +
  820. +#include <errno.h>
  821. +#include <stdio.h>
  822. +#include <stdlib.h>
  823. +#include <string.h>
  824. +#include "hash_table.h"
  825. +#include "ipkg_message.h"
  826. +
  827. +
  828. +static int hash_index(hash_table_t *hash, const char *pkg_name);
  829. +static int rotating(const char *key, int len, int prime);
  830. +
  831. +static int hash_index(hash_table_t *hash, const char *pkg_name)
  832. +{
  833. + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
  834. +}
  835. +
  836. +static int rotating(const char *key, int len, int prime)
  837. +{
  838. + unsigned int hash, i;
  839. + for (hash=len, i=0; i<len; ++i)
  840. + hash = (hash<<4)^(hash>>28)^key[i];
  841. + return (hash % prime);
  842. +}
  843. +
  844. +
  845. +/*
  846. + * this is an open table keyed by strings
  847. + */
  848. +int hash_table_init(const char *name, hash_table_t *hash, int len)
  849. +{
  850. + static int primes_table[] = {
  851. + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
  852. + 19471, 23143, 33961, 46499, 49727, 99529, 0
  853. + };
  854. + int *picker;
  855. +
  856. + if (hash->entries != NULL) {
  857. + /* we have been here already */
  858. + return 0;
  859. + }
  860. +
  861. + hash->name = name;
  862. + hash->entries = NULL;
  863. + hash->n_entries = 0;
  864. + hash->hash_entry_key = NULL;
  865. +
  866. + picker = primes_table;
  867. + while(*picker && (*picker++ < len));
  868. + if(!*picker)
  869. + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
  870. + --picker;
  871. +
  872. + hash->n_entries = *picker;
  873. + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
  874. + if (hash->entries == NULL) {
  875. + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
  876. + return ENOMEM;
  877. + }
  878. + return 0;
  879. +}
  880. +
  881. +void hash_table_deinit(hash_table_t *hash)
  882. +{
  883. + free(hash->entries);
  884. + hash->entries = NULL;
  885. + hash->n_entries = 0;
  886. +}
  887. +
  888. +void *hash_table_get(hash_table_t *hash, const char *key)
  889. +{
  890. + int ndx= hash_index(hash, key);
  891. + hash_entry_t *hash_entry = hash->entries + ndx;
  892. + while (hash_entry)
  893. + {
  894. + if (hash_entry->key)
  895. + {
  896. + if (strcmp(key, hash_entry->key) == 0) {
  897. + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
  898. + return hash_entry->data;
  899. + }
  900. + }
  901. + hash_entry = hash_entry->next;
  902. + }
  903. + return NULL;
  904. +}
  905. +
  906. +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
  907. +{
  908. + int ndx= hash_index(hash, key);
  909. + hash_entry_t *hash_entry = hash->entries + ndx;
  910. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
  911. + if (hash_entry->key) {
  912. + if (strcmp(hash_entry->key, key) == 0) {
  913. + /* alread in table, update the value */
  914. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
  915. + hash_entry->data = value;
  916. + return 0;
  917. + } else {
  918. + /*
  919. + * if this is a collision, we have to go to the end of the ll,
  920. + * then add a new entry
  921. + * before we can hook up the value
  922. + */
  923. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
  924. + while (hash_entry->next)
  925. + hash_entry = hash_entry->next;
  926. + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
  927. + if (!hash_entry->next) {
  928. + return -ENOMEM;
  929. + }
  930. + hash_entry = hash_entry->next;
  931. + hash_entry->next = NULL;
  932. + }
  933. + }
  934. + hash->n_elements++;
  935. + hash_entry->key = strdup(key);
  936. + hash_entry->data = value;
  937. +
  938. + return 0;
  939. +}
  940. +
  941. +
  942. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
  943. +{
  944. + int i;
  945. + if (!hash || !f)
  946. + return;
  947. +
  948. + for (i = 0; i < hash->n_entries; i++) {
  949. + hash_entry_t *hash_entry = (hash->entries + i);
  950. + do {
  951. + if(hash_entry->key) {
  952. + f(hash_entry->key, hash_entry->data, data);
  953. + }
  954. + } while((hash_entry = hash_entry->next));
  955. + }
  956. +}
  957. +
  958. diff -Nur busybox-1.17.0.orig/archival/libipkg/hash_table.h busybox-1.17.0/archival/libipkg/hash_table.h
  959. --- busybox-1.17.0.orig/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
  960. +++ busybox-1.17.0/archival/libipkg/hash_table.h 2010-07-08 12:01:56.203011424 +0200
  961. @@ -0,0 +1,44 @@
  962. +/* hash.h - hash tables for ipkg
  963. +
  964. + Steven M. Ayer, Jamey Hicks
  965. +
  966. + Copyright (C) 2002 Compaq Computer Corporation
  967. +
  968. + This program is free software; you can redistribute it and/or
  969. + modify it under the terms of the GNU General Public License as
  970. + published by the Free Software Foundation; either version 2, or (at
  971. + your option) any later version.
  972. +
  973. + This program is distributed in the hope that it will be useful, but
  974. + WITHOUT ANY WARRANTY; without even the implied warranty of
  975. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  976. + General Public License for more details.
  977. +*/
  978. +
  979. +#ifndef _HASH_TABLE_H_
  980. +#define _HASH_TABLE_H_
  981. +
  982. +typedef struct hash_entry hash_entry_t;
  983. +typedef struct hash_table hash_table_t;
  984. +
  985. +struct hash_entry {
  986. + const char * key;
  987. + void * data;
  988. + struct hash_entry * next;
  989. +};
  990. +
  991. +struct hash_table {
  992. + const char *name;
  993. + hash_entry_t * entries;
  994. + int n_entries; /* number of buckets */
  995. + int n_elements;
  996. + const char * (*hash_entry_key)(void * data);
  997. +};
  998. +
  999. +int hash_table_init(const char *name, hash_table_t *hash, int len);
  1000. +void hash_table_deinit(hash_table_t *hash);
  1001. +void *hash_table_get(hash_table_t *hash, const char *key);
  1002. +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
  1003. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
  1004. +
  1005. +#endif /* _HASH_TABLE_H_ */
  1006. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_cmd.c busybox-1.17.0/archival/libipkg/ipkg_cmd.c
  1007. --- busybox-1.17.0.orig/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
  1008. +++ busybox-1.17.0/archival/libipkg/ipkg_cmd.c 2010-07-08 12:01:56.206999641 +0200
  1009. @@ -0,0 +1,1366 @@
  1010. +/* ipkg_cmd.c - the itsy package management system
  1011. +
  1012. + Carl D. Worth
  1013. +
  1014. + Copyright (C) 2001 University of Southern California
  1015. +
  1016. + This program is free software; you can redistribute it and/or
  1017. + modify it under the terms of the GNU General Public License as
  1018. + published by the Free Software Foundation; either version 2, or (at
  1019. + your option) any later version.
  1020. +
  1021. + This program is distributed in the hope that it will be useful, but
  1022. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1023. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1024. + General Public License for more details.
  1025. +*/
  1026. +
  1027. +#include <string.h>
  1028. +
  1029. +#include "ipkg.h"
  1030. +#include <libgen.h>
  1031. +#include <glob.h>
  1032. +#include <errno.h>
  1033. +#include <stdlib.h>
  1034. +#include <unistd.h>
  1035. +#include <signal.h>
  1036. +#include <stdio.h>
  1037. +#include <dirent.h>
  1038. +
  1039. +#include "ipkg_conf.h"
  1040. +#include "ipkg_cmd.h"
  1041. +#include "ipkg_message.h"
  1042. +#include "pkg.h"
  1043. +#include "pkg_dest.h"
  1044. +#include "pkg_parse.h"
  1045. +#include "sprintf_alloc.h"
  1046. +#include "pkg.h"
  1047. +#include "file_util.h"
  1048. +#include "str_util.h"
  1049. +#include "unarchive.h"
  1050. +
  1051. +#include <fnmatch.h>
  1052. +
  1053. +
  1054. +#include "ipkg_download.h"
  1055. +#include "ipkg_install.h"
  1056. +#include "ipkg_upgrade.h"
  1057. +#include "ipkg_remove.h"
  1058. +#include "ipkg_configure.h"
  1059. +#include "ipkg_message.h"
  1060. +
  1061. +#include "libipkg.h"
  1062. +static void *p_userdata = NULL;
  1063. +
  1064. +static int ipkg_update_cmd(ipkg_conf_t *conf);
  1065. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1066. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1067. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1068. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1069. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf);
  1070. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1071. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1072. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1073. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1074. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1075. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1076. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1077. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1078. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1079. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1080. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1081. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1082. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1083. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1084. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1085. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1086. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1087. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf);
  1088. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1089. +
  1090. +/* XXX: CLEANUP: The usage strings should be incorporated into this
  1091. + array for easier maintenance */
  1092. +static ipkg_cmd_t cmds[] = {
  1093. + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
  1094. + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
  1095. + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
  1096. + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
  1097. + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
  1098. + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
  1099. + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
  1100. + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
  1101. + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
  1102. + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
  1103. + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
  1104. + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
  1105. + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
  1106. + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
  1107. + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
  1108. + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1109. + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1110. + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1111. + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1112. + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1113. + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1114. + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
  1115. + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
  1116. + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
  1117. + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
  1118. + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
  1119. + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
  1120. + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
  1121. + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
  1122. +};
  1123. +
  1124. +int ipkg_state_changed;
  1125. +static void write_status_files_if_changed(ipkg_conf_t *conf)
  1126. +{
  1127. + if (ipkg_state_changed && !conf->noaction) {
  1128. + ipkg_message(conf, IPKG_INFO,
  1129. + " writing status file\n");
  1130. + ipkg_conf_write_status_files(conf);
  1131. + pkg_write_changed_filelists(conf);
  1132. + } else {
  1133. + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
  1134. + }
  1135. +}
  1136. +
  1137. +
  1138. +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
  1139. +
  1140. +ipkg_cmd_t *ipkg_cmd_find(const char *name)
  1141. +{
  1142. + int i;
  1143. + ipkg_cmd_t *cmd;
  1144. +
  1145. + for (i=0; i < num_cmds; i++) {
  1146. + cmd = &cmds[i];
  1147. + if (strcmp(name, cmd->name) == 0) {
  1148. + return cmd;
  1149. + }
  1150. + }
  1151. +
  1152. + return NULL;
  1153. +}
  1154. +
  1155. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
  1156. +{
  1157. + int result;
  1158. + p_userdata = userdata;
  1159. +
  1160. +
  1161. + result = (cmd->fun)(conf, argc, argv);
  1162. + if ( result == 0 ) {
  1163. + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
  1164. + } else {
  1165. + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
  1166. +
  1167. + }
  1168. + if ( error_list ) {
  1169. + reverse_error_list(&error_list);
  1170. +
  1171. + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
  1172. + /* Here we print the errors collected and free the list */
  1173. + while (error_list != NULL) {
  1174. + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
  1175. + error_list = error_list->next;
  1176. +
  1177. + }
  1178. + free_error_list(&error_list);
  1179. +
  1180. + }
  1181. +
  1182. + p_userdata = NULL;
  1183. + return result;
  1184. +}
  1185. +
  1186. +static int ipkg_update_cmd(ipkg_conf_t *conf)
  1187. +{
  1188. + int err;
  1189. + int failures;
  1190. + char *lists_dir;
  1191. + pkg_src_list_elt_t *iter;
  1192. + pkg_src_t *src;
  1193. +
  1194. +
  1195. + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
  1196. +
  1197. + if (! file_is_dir(lists_dir)) {
  1198. + if (file_exists(lists_dir)) {
  1199. + ipkg_message(conf, IPKG_ERROR,
  1200. + "%s: ERROR: %s exists, but is not a directory\n",
  1201. + __FUNCTION__, lists_dir);
  1202. + free(lists_dir);
  1203. + return EINVAL;
  1204. + }
  1205. + err = file_mkdir_hier(lists_dir, 0755);
  1206. + if (err) {
  1207. + ipkg_message(conf, IPKG_ERROR,
  1208. + "%s: ERROR: failed to make directory %s: %s\n",
  1209. + __FUNCTION__, lists_dir, strerror(errno));
  1210. + free(lists_dir);
  1211. + return EINVAL;
  1212. + }
  1213. + }
  1214. +
  1215. + failures = 0;
  1216. + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
  1217. + char *url, *list_file_name;
  1218. +
  1219. + src = iter->data;
  1220. +
  1221. + if (src->extra_data) /* debian style? */
  1222. + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
  1223. + src->gzip ? "Packages.gz" : "Packages");
  1224. + else
  1225. + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
  1226. +
  1227. + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
  1228. + if (src->gzip) {
  1229. + char *tmp;
  1230. + char *tmp_file_name;
  1231. + FILE *in, *out;
  1232. +
  1233. + tmp = strdup ("/tmp/ipkg.XXXXXX");
  1234. +
  1235. + if (mkdtemp (tmp) == NULL) {
  1236. + perror ("mkdtemp");
  1237. + failures++;
  1238. + continue;
  1239. + }
  1240. +
  1241. + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
  1242. + err = ipkg_download(conf, url, tmp_file_name);
  1243. + if (err == 0) {
  1244. + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
  1245. + in = fopen (tmp_file_name, "r");
  1246. + out = fopen (list_file_name, "w");
  1247. + if (in && out) {
  1248. + inflate_unzip_result res;
  1249. + inflate_unzip (&res, 0x8000, fileno(in), fileno(out));
  1250. + } else
  1251. + err = 1;
  1252. + if (in)
  1253. + fclose (in);
  1254. + if (out)
  1255. + fclose (out);
  1256. + unlink (tmp_file_name);
  1257. + rmdir (tmp);
  1258. + free (tmp);
  1259. + }
  1260. + } else
  1261. + err = ipkg_download(conf, url, list_file_name);
  1262. + if (err) {
  1263. + failures++;
  1264. + } else {
  1265. + ipkg_message(conf, IPKG_NOTICE,
  1266. + "Updated list of available packages in %s\n",
  1267. + list_file_name);
  1268. + }
  1269. + free(url);
  1270. + free(list_file_name);
  1271. + }
  1272. + free(lists_dir);
  1273. +
  1274. +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
  1275. +#warning here
  1276. + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
  1277. + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
  1278. + * -Jamey 3/1/03
  1279. + */
  1280. + {
  1281. + int i;
  1282. + int changed = 0;
  1283. + pkg_vec_t *available = pkg_vec_alloc();
  1284. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1285. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
  1286. + for (i = 0; i < available->len; i++) {
  1287. + pkg_t *pkg = available->pkgs[i];
  1288. + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
  1289. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
  1290. + pkg->state_want = SW_UNKNOWN;
  1291. + changed = 1;
  1292. + }
  1293. + }
  1294. + pkg_vec_free(available);
  1295. + if (changed) {
  1296. + write_status_files_if_changed(conf);
  1297. + }
  1298. + }
  1299. +#endif
  1300. +
  1301. + return failures;
  1302. +}
  1303. +
  1304. +
  1305. +/* scan the args passed and cache the local filenames of the packages */
  1306. +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
  1307. +{
  1308. + int i;
  1309. + int err;
  1310. +
  1311. + /*
  1312. + * First scan through package names/urls
  1313. + * For any urls, download the packages and install in database.
  1314. + * For any files, install package info in database.
  1315. + */
  1316. + for (i = 0; i < argc; i ++) {
  1317. + char *filename = argv [i];
  1318. + //char *tmp = basename (tmp);
  1319. + //int tmplen = strlen (tmp);
  1320. +
  1321. + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
  1322. + // continue;
  1323. + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
  1324. + // continue;
  1325. +
  1326. + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
  1327. +
  1328. + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
  1329. + if (err)
  1330. + return err;
  1331. + }
  1332. + return 0;
  1333. +}
  1334. +
  1335. +struct ipkg_intercept
  1336. +{
  1337. + char *oldpath;
  1338. + char *statedir;
  1339. +};
  1340. +
  1341. +typedef struct ipkg_intercept *ipkg_intercept_t;
  1342. +ipkg_intercept_t ipkg_prep_intercepts(void);
  1343. +
  1344. +ipkg_intercept_t ipkg_prep_intercepts(void)
  1345. +{
  1346. + ipkg_intercept_t ctx;
  1347. + char *newpath;
  1348. + int gen;
  1349. +
  1350. + ctx = malloc (sizeof (*ctx));
  1351. + ctx->oldpath = strdup (getenv ("PATH"));
  1352. +
  1353. + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
  1354. + setenv ("PATH", newpath, 1);
  1355. + free (newpath);
  1356. +
  1357. + gen = 0;
  1358. + retry:
  1359. + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
  1360. + if (mkdir (ctx->statedir, 0770) < 0) {
  1361. + if (errno == EEXIST) {
  1362. + free (ctx->statedir);
  1363. + gen++;
  1364. + goto retry;
  1365. + }
  1366. + perror (ctx->statedir);
  1367. + return NULL;
  1368. + }
  1369. + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
  1370. + return ctx;
  1371. +}
  1372. +
  1373. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx);
  1374. +
  1375. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
  1376. +{
  1377. + char *cmd;
  1378. + DIR *dir;
  1379. + int err = 0;
  1380. +
  1381. + setenv ("PATH", ctx->oldpath, 1);
  1382. + free (ctx->oldpath);
  1383. +
  1384. + dir = opendir (ctx->statedir);
  1385. + if (dir) {
  1386. + struct dirent *de;
  1387. + while (de = readdir (dir), de != NULL) {
  1388. + char *path;
  1389. +
  1390. + if (de->d_name[0] == '.')
  1391. + continue;
  1392. +
  1393. + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
  1394. + if (access (path, X_OK) == 0) {
  1395. + if (system (path)) {
  1396. + err = errno;
  1397. + perror (de->d_name);
  1398. + }
  1399. + }
  1400. + free (path);
  1401. + }
  1402. + } else
  1403. + perror (ctx->statedir);
  1404. +
  1405. + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
  1406. + system (cmd);
  1407. + free (cmd);
  1408. +
  1409. + free (ctx->statedir);
  1410. + free (ctx);
  1411. +
  1412. + return err;
  1413. +}
  1414. +
  1415. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
  1416. +{
  1417. + pkg_vec_t *all;
  1418. + int i;
  1419. + pkg_t *pkg;
  1420. + ipkg_intercept_t ic;
  1421. + int r, err = 0;
  1422. +
  1423. + ipkg_message(conf, IPKG_INFO,
  1424. + "Configuring unpacked packages\n");
  1425. + fflush( stdout );
  1426. +
  1427. + all = pkg_vec_alloc();
  1428. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  1429. +
  1430. + ic = ipkg_prep_intercepts();
  1431. +
  1432. + for(i = 0; i < all->len; i++) {
  1433. + pkg = all->pkgs[i];
  1434. +
  1435. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1436. + continue;
  1437. +
  1438. + if (pkg->state_status == SS_UNPACKED) {
  1439. + ipkg_message(conf, IPKG_NOTICE,
  1440. + "Configuring %s\n", pkg->name);
  1441. + fflush( stdout );
  1442. + r = ipkg_configure(conf, pkg);
  1443. + if (r == 0) {
  1444. + pkg->state_status = SS_INSTALLED;
  1445. + pkg->parent->state_status = SS_INSTALLED;
  1446. + pkg->state_flag &= ~SF_PREFER;
  1447. + } else {
  1448. + if (!err)
  1449. + err = r;
  1450. + }
  1451. + }
  1452. + }
  1453. +
  1454. + r = ipkg_finalize_intercepts (ic);
  1455. + if (r && !err)
  1456. + err = r;
  1457. +
  1458. + pkg_vec_free(all);
  1459. + return err;
  1460. +}
  1461. +
  1462. +static void sigint_handler(int sig)
  1463. +{
  1464. + signal(sig, SIG_DFL);
  1465. + ipkg_message(NULL, IPKG_NOTICE,
  1466. + "ipkg: interrupted. writing out status database\n");
  1467. + write_status_files_if_changed(global_conf);
  1468. + exit(128 + sig);
  1469. +}
  1470. +
  1471. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1472. +{
  1473. + int i;
  1474. + char *arg;
  1475. + int err=0;
  1476. +
  1477. + global_conf = conf;
  1478. + signal(SIGINT, sigint_handler);
  1479. +
  1480. + /*
  1481. + * Now scan through package names and install
  1482. + */
  1483. + for (i=0; i < argc; i++) {
  1484. + arg = argv[i];
  1485. +
  1486. + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
  1487. + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
  1488. + if (err != EINVAL && err != 0)
  1489. + return err;
  1490. + }
  1491. + pkg_info_preinstall_check(conf);
  1492. +
  1493. + for (i=0; i < argc; i++) {
  1494. + arg = argv[i];
  1495. + if (conf->multiple_providers)
  1496. + err = ipkg_install_multi_by_name(conf, arg);
  1497. + else{
  1498. + err = ipkg_install_by_name(conf, arg);
  1499. + }
  1500. + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
  1501. + ipkg_message(conf, IPKG_ERROR,
  1502. + "Cannot find package %s.\n"
  1503. + "Check the spelling or perhaps run 'ipkg update'\n",
  1504. + arg);
  1505. + }
  1506. + }
  1507. +
  1508. + /* recheck to verify that all dependences are satisfied */
  1509. + if (0) ipkg_satisfy_all_dependences(conf);
  1510. +
  1511. + ipkg_configure_packages(conf, NULL);
  1512. +
  1513. + write_status_files_if_changed(conf);
  1514. +
  1515. + return err;
  1516. +}
  1517. +
  1518. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1519. +{
  1520. + int i;
  1521. + pkg_t *pkg;
  1522. + int err;
  1523. +
  1524. + global_conf = conf;
  1525. + signal(SIGINT, sigint_handler);
  1526. +
  1527. + if (argc) {
  1528. + for (i=0; i < argc; i++) {
  1529. + char *arg = argv[i];
  1530. +
  1531. + err = ipkg_prepare_url_for_install(conf, arg, &arg);
  1532. + if (err != EINVAL && err != 0)
  1533. + return err;
  1534. + }
  1535. + pkg_info_preinstall_check(conf);
  1536. +
  1537. + for (i=0; i < argc; i++) {
  1538. + char *arg = argv[i];
  1539. + if (conf->restrict_to_default_dest) {
  1540. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1541. + argv[i],
  1542. + conf->default_dest);
  1543. + if (pkg == NULL) {
  1544. + ipkg_message(conf, IPKG_NOTICE,
  1545. + "Package %s not installed in %s\n",
  1546. + argv[i], conf->default_dest->name);
  1547. + continue;
  1548. + }
  1549. + } else {
  1550. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  1551. + argv[i]);
  1552. + }
  1553. + if (pkg)
  1554. + ipkg_upgrade_pkg(conf, pkg);
  1555. + else {
  1556. + ipkg_install_by_name(conf, arg);
  1557. + }
  1558. + }
  1559. + } else {
  1560. + pkg_vec_t *installed = pkg_vec_alloc();
  1561. +
  1562. + pkg_info_preinstall_check(conf);
  1563. +
  1564. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  1565. + for (i = 0; i < installed->len; i++) {
  1566. + pkg = installed->pkgs[i];
  1567. + ipkg_upgrade_pkg(conf, pkg);
  1568. + }
  1569. + pkg_vec_free(installed);
  1570. + }
  1571. +
  1572. + /* recheck to verify that all dependences are satisfied */
  1573. + if (0) ipkg_satisfy_all_dependences(conf);
  1574. +
  1575. + ipkg_configure_packages(conf, NULL);
  1576. +
  1577. + write_status_files_if_changed(conf);
  1578. +
  1579. + return 0;
  1580. +}
  1581. +
  1582. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1583. +{
  1584. + int i, err;
  1585. + char *arg;
  1586. + pkg_t *pkg;
  1587. +
  1588. + pkg_info_preinstall_check(conf);
  1589. + for (i = 0; i < argc; i++) {
  1590. + arg = argv[i];
  1591. +
  1592. + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
  1593. + if (pkg == NULL) {
  1594. + ipkg_message(conf, IPKG_ERROR,
  1595. + "Cannot find package %s.\n"
  1596. + "Check the spelling or perhaps run 'ipkg update'\n",
  1597. + arg);
  1598. + continue;
  1599. + }
  1600. +
  1601. + err = ipkg_download_pkg(conf, pkg, ".");
  1602. +
  1603. + if (err) {
  1604. + ipkg_message(conf, IPKG_ERROR,
  1605. + "Failed to download %s\n", pkg->name);
  1606. + } else {
  1607. + ipkg_message(conf, IPKG_NOTICE,
  1608. + "Downloaded %s as %s\n",
  1609. + pkg->name, pkg->local_filename);
  1610. + }
  1611. + }
  1612. +
  1613. + return 0;
  1614. +}
  1615. +
  1616. +
  1617. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1618. +{
  1619. + int i ;
  1620. + pkg_vec_t *available;
  1621. + pkg_t *pkg;
  1622. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1623. + char *newline;
  1624. + char *pkg_name = NULL;
  1625. + char *version_str;
  1626. +
  1627. + if (argc > 0) {
  1628. + pkg_name = argv[0];
  1629. + }
  1630. + available = pkg_vec_alloc();
  1631. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1632. + for (i=0; i < available->len; i++) {
  1633. + pkg = available->pkgs[i];
  1634. + /* if we have package name or pattern and pkg does not match, then skip it */
  1635. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1636. + continue;
  1637. + if (pkg->description) {
  1638. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1639. + } else {
  1640. + desc_short[0] = '\0';
  1641. + }
  1642. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1643. + newline = strchr(desc_short, '\n');
  1644. + if (newline) {
  1645. + *newline = '\0';
  1646. + }
  1647. + if (ipkg_cb_list) {
  1648. + version_str = pkg_version_str_alloc(pkg);
  1649. + ipkg_cb_list(pkg->name,desc_short,
  1650. + version_str,
  1651. + pkg->state_status,
  1652. + p_userdata);
  1653. + free(version_str);
  1654. + }
  1655. + }
  1656. + pkg_vec_free(available);
  1657. +
  1658. + return 0;
  1659. +}
  1660. +
  1661. +
  1662. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1663. +{
  1664. + int i ;
  1665. + pkg_vec_t *available;
  1666. + pkg_t *pkg;
  1667. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1668. + char *newline;
  1669. + char *pkg_name = NULL;
  1670. + char *version_str;
  1671. +
  1672. + if (argc > 0) {
  1673. + pkg_name = argv[0];
  1674. + }
  1675. + available = pkg_vec_alloc();
  1676. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1677. + for (i=0; i < available->len; i++) {
  1678. + pkg = available->pkgs[i];
  1679. + /* if we have package name or pattern and pkg does not match, then skip it */
  1680. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1681. + continue;
  1682. + if (pkg->description) {
  1683. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1684. + } else {
  1685. + desc_short[0] = '\0';
  1686. + }
  1687. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1688. + newline = strchr(desc_short, '\n');
  1689. + if (newline) {
  1690. + *newline = '\0';
  1691. + }
  1692. + if (ipkg_cb_list) {
  1693. + version_str = pkg_version_str_alloc(pkg);
  1694. + ipkg_cb_list(pkg->name,desc_short,
  1695. + version_str,
  1696. + pkg->state_status,
  1697. + p_userdata);
  1698. + free(version_str);
  1699. + }
  1700. + }
  1701. +
  1702. + return 0;
  1703. +}
  1704. +
  1705. +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
  1706. +{
  1707. + int i;
  1708. + pkg_vec_t *available;
  1709. + pkg_t *pkg;
  1710. + char *pkg_name = NULL;
  1711. + char **pkg_fields = NULL;
  1712. + int n_fields = 0;
  1713. + char *buff ; // = (char *)malloc(1);
  1714. +
  1715. + if (argc > 0) {
  1716. + pkg_name = argv[0];
  1717. + }
  1718. + if (argc > 1) {
  1719. + pkg_fields = &argv[1];
  1720. + n_fields = argc - 1;
  1721. + }
  1722. +
  1723. + available = pkg_vec_alloc();
  1724. + if (installed_only)
  1725. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1726. + else
  1727. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1728. + for (i=0; i < available->len; i++) {
  1729. + pkg = available->pkgs[i];
  1730. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1731. + continue;
  1732. + }
  1733. + buff = pkg_formatted_info(pkg);
  1734. + if ( buff ) {
  1735. + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
  1736. + pkg->state_status,
  1737. + buff,
  1738. + p_userdata);
  1739. + free(buff);
  1740. + }
  1741. + if (conf->verbosity > 1) {
  1742. + conffile_list_elt_t *iter;
  1743. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  1744. + conffile_t *cf = iter->data;
  1745. + int modified = conffile_has_been_modified(conf, cf);
  1746. + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
  1747. + cf->name, cf->value, modified);
  1748. + }
  1749. + }
  1750. + }
  1751. + pkg_vec_free(available);
  1752. +
  1753. + return 0;
  1754. +}
  1755. +
  1756. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1757. +{
  1758. + return ipkg_info_status_cmd(conf, argc, argv, 0);
  1759. +}
  1760. +
  1761. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1762. +{
  1763. + return ipkg_info_status_cmd(conf, argc, argv, 1);
  1764. +}
  1765. +
  1766. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1767. +{
  1768. +
  1769. + int err;
  1770. + if (argc > 0) {
  1771. + char *pkg_name = NULL;
  1772. +
  1773. + pkg_name = argv[0];
  1774. +
  1775. + err = ipkg_configure_packages (conf, pkg_name);
  1776. +
  1777. + } else {
  1778. + err = ipkg_configure_packages (conf, NULL);
  1779. + }
  1780. +
  1781. + write_status_files_if_changed(conf);
  1782. +
  1783. + return err;
  1784. +}
  1785. +
  1786. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf)
  1787. +{
  1788. + int i, err;
  1789. + char *globpattern;
  1790. + glob_t globbuf;
  1791. +
  1792. + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
  1793. + err = glob(globpattern, 0, NULL, &globbuf);
  1794. + free(globpattern);
  1795. + if (err) {
  1796. + return 0;
  1797. + }
  1798. +
  1799. + ipkg_message(conf, IPKG_NOTICE,
  1800. + "The following packages in %s will now be installed.\n",
  1801. + conf->pending_dir);
  1802. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1803. + ipkg_message(conf, IPKG_NOTICE,
  1804. + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
  1805. + }
  1806. + ipkg_message(conf, IPKG_NOTICE, "\n");
  1807. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1808. + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
  1809. + if (err == 0) {
  1810. + err = unlink(globbuf.gl_pathv[i]);
  1811. + if (err) {
  1812. + ipkg_message(conf, IPKG_ERROR,
  1813. + "%s: ERROR: failed to unlink %s: %s\n",
  1814. + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
  1815. + return err;
  1816. + }
  1817. + }
  1818. + }
  1819. + globfree(&globbuf);
  1820. +
  1821. + return err;
  1822. +}
  1823. +
  1824. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1825. +{
  1826. + int i,a,done;
  1827. + pkg_t *pkg;
  1828. + pkg_t *pkg_to_remove;
  1829. + pkg_vec_t *available;
  1830. + char *pkg_name = NULL;
  1831. + global_conf = conf;
  1832. + signal(SIGINT, sigint_handler);
  1833. +
  1834. +// ENH: Add the "no pkg removed" just in case.
  1835. +
  1836. + done = 0;
  1837. +
  1838. + available = pkg_vec_alloc();
  1839. + pkg_info_preinstall_check(conf);
  1840. + if ( argc > 0 ) {
  1841. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1842. + for (i=0; i < argc; i++) {
  1843. + pkg_name = malloc(strlen(argv[i])+2);
  1844. + strcpy(pkg_name,argv[i]);
  1845. + for (a=0; a < available->len; a++) {
  1846. + pkg = available->pkgs[a];
  1847. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1848. + continue;
  1849. + }
  1850. + if (conf->restrict_to_default_dest) {
  1851. + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1852. + pkg->name,
  1853. + conf->default_dest);
  1854. + } else {
  1855. + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
  1856. + }
  1857. +
  1858. + if (pkg == NULL) {
  1859. + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
  1860. + continue;
  1861. + }
  1862. + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
  1863. + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
  1864. + continue;
  1865. + }
  1866. + ipkg_remove_pkg(conf, pkg_to_remove,0);
  1867. + done = 1;
  1868. + }
  1869. + free (pkg_name);
  1870. + }
  1871. + pkg_vec_free(available);
  1872. + } else {
  1873. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  1874. + int flagged_pkg_count = 0;
  1875. + int removed;
  1876. +
  1877. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
  1878. +
  1879. + for (i = 0; i < installed_pkgs->len; i++) {
  1880. + pkg = installed_pkgs->pkgs[i];
  1881. + if (pkg->state_flag & SF_USER) {
  1882. + flagged_pkg_count++;
  1883. + } else {
  1884. + if (!pkg_has_installed_dependents(pkg, NULL))
  1885. + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
  1886. + }
  1887. + }
  1888. + if (!flagged_pkg_count) {
  1889. + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
  1890. + "so refusing to uninstall unflagged non-leaf packages\n");
  1891. + return 0;
  1892. + }
  1893. +
  1894. + /* find packages not flagged SF_USER (i.e., installed to
  1895. + * satisfy a dependence) and not having any dependents, and
  1896. + * remove them */
  1897. + do {
  1898. + removed = 0;
  1899. + for (i = 0; i < installed_pkgs->len; i++) {
  1900. + pkg = installed_pkgs->pkgs[i];
  1901. + if (!(pkg->state_flag & SF_USER)
  1902. + && !pkg_has_installed_dependents(pkg, NULL)) {
  1903. + removed++;
  1904. + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
  1905. + ipkg_remove_pkg(conf, pkg,0);
  1906. + done = 1;
  1907. + }
  1908. + }
  1909. + } while (removed);
  1910. + pkg_vec_free(installed_pkgs);
  1911. + }
  1912. +
  1913. + if ( done == 0 )
  1914. + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
  1915. +
  1916. + write_status_files_if_changed(conf);
  1917. + return 0;
  1918. +}
  1919. +
  1920. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1921. +{
  1922. + int i;
  1923. + pkg_t *pkg;
  1924. +
  1925. + global_conf = conf;
  1926. + signal(SIGINT, sigint_handler);
  1927. +
  1928. + pkg_info_preinstall_check(conf);
  1929. +
  1930. + for (i=0; i < argc; i++) {
  1931. + if (conf->restrict_to_default_dest) {
  1932. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1933. + argv[i],
  1934. + conf->default_dest);
  1935. + } else {
  1936. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1937. + }
  1938. +
  1939. + if (pkg == NULL) {
  1940. + ipkg_message(conf, IPKG_ERROR,
  1941. + "Package %s is not installed.\n", argv[i]);
  1942. + continue;
  1943. + }
  1944. + ipkg_purge_pkg(conf, pkg);
  1945. + }
  1946. +
  1947. + write_status_files_if_changed(conf);
  1948. + return 0;
  1949. +}
  1950. +
  1951. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1952. +{
  1953. + int i;
  1954. + pkg_t *pkg;
  1955. + char *flags = argv[0];
  1956. +
  1957. + global_conf = conf;
  1958. + signal(SIGINT, sigint_handler);
  1959. +
  1960. + for (i=1; i < argc; i++) {
  1961. + if (conf->restrict_to_default_dest) {
  1962. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1963. + argv[i],
  1964. + conf->default_dest);
  1965. + } else {
  1966. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1967. + }
  1968. +
  1969. + if (pkg == NULL) {
  1970. + ipkg_message(conf, IPKG_ERROR,
  1971. + "Package %s is not installed.\n", argv[i]);
  1972. + continue;
  1973. + }
  1974. + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
  1975. + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
  1976. + pkg->state_flag = pkg_state_flag_from_str(flags);
  1977. + }
  1978. +/* pb_ asked this feature 03292004 */
  1979. +/* Actually I will use only this two, but this is an open for various status */
  1980. + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
  1981. + pkg->state_status = pkg_state_status_from_str(flags);
  1982. + }
  1983. + ipkg_state_changed++;
  1984. + ipkg_message(conf, IPKG_NOTICE,
  1985. + "Setting flags for package %s to %s\n",
  1986. + pkg->name, flags);
  1987. + }
  1988. +
  1989. + write_status_files_if_changed(conf);
  1990. + return 0;
  1991. +}
  1992. +
  1993. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1994. +{
  1995. + pkg_t *pkg;
  1996. + str_list_t *installed_files;
  1997. + str_list_elt_t *iter;
  1998. + char *pkg_version;
  1999. + size_t buff_len = 8192;
  2000. + size_t used_len;
  2001. + char *buff ;
  2002. +
  2003. + buff = (char *)malloc(buff_len);
  2004. + if ( buff == NULL ) {
  2005. + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
  2006. + return ENOMEM;
  2007. + }
  2008. +
  2009. + if (argc < 1) {
  2010. + return EINVAL;
  2011. + }
  2012. +
  2013. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  2014. + argv[0]);
  2015. + if (pkg == NULL) {
  2016. + ipkg_message(conf, IPKG_ERROR,
  2017. + "Package %s not installed.\n", argv[0]);
  2018. + return 0;
  2019. + }
  2020. +
  2021. + installed_files = pkg_get_installed_files(pkg);
  2022. + pkg_version = pkg_version_str_alloc(pkg);
  2023. +
  2024. + printf("Package %s (%s) is installed on %s and has the following files:\n",
  2025. + pkg->name, pkg_version, pkg->dest->name);
  2026. + for (iter = installed_files->head; iter; iter = iter->next) {
  2027. + puts(iter->data);
  2028. + }
  2029. +
  2030. + free(pkg_version);
  2031. + pkg_free_installed_files(pkg);
  2032. +
  2033. + return 0;
  2034. +}
  2035. +
  2036. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2037. +{
  2038. +
  2039. + if (argc > 0) {
  2040. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2041. + const char *rel_str = "depends on";
  2042. + int i;
  2043. +
  2044. + pkg_info_preinstall_check(conf);
  2045. +
  2046. + if (conf->query_all)
  2047. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2048. + else
  2049. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2050. + for (i = 0; i < argc; i++) {
  2051. + const char *target = argv[i];
  2052. + int j;
  2053. +
  2054. + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
  2055. +
  2056. + for (j = 0; j < available_pkgs->len; j++) {
  2057. + pkg_t *pkg = available_pkgs->pkgs[j];
  2058. + if (fnmatch(target, pkg->name, 0) == 0) {
  2059. + int k;
  2060. + int count = pkg->depends_count + pkg->pre_depends_count;
  2061. + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
  2062. + target, pkg->architecture, rel_str);
  2063. + for (k = 0; k < count; k++) {
  2064. + compound_depend_t *cdepend = &pkg->depends[k];
  2065. + int l;
  2066. + for (l = 0; l < cdepend->possibility_count; l++) {
  2067. + depend_t *possibility = cdepend->possibilities[l];
  2068. + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
  2069. + if (conf->verbosity > 0) {
  2070. + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
  2071. + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
  2072. + if (possibility->version) {
  2073. + const char *typestr = NULL;
  2074. + switch (possibility->constraint) {
  2075. + case NONE: typestr = "none"; break;
  2076. + case EARLIER: typestr = "<"; break;
  2077. + case EARLIER_EQUAL: typestr = "<="; break;
  2078. + case EQUAL: typestr = "="; break;
  2079. + case LATER_EQUAL: typestr = ">="; break;
  2080. + case LATER: typestr = ">"; break;
  2081. + }
  2082. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2083. + }
  2084. + // free(ver);
  2085. + }
  2086. + ipkg_message(conf, IPKG_ERROR, "\n");
  2087. + }
  2088. + }
  2089. + }
  2090. + }
  2091. + }
  2092. + pkg_vec_free(available_pkgs);
  2093. + }
  2094. + return 0;
  2095. +}
  2096. +
  2097. +enum what_field_type {
  2098. + WHATDEPENDS,
  2099. + WHATCONFLICTS,
  2100. + WHATPROVIDES,
  2101. + WHATREPLACES,
  2102. + WHATRECOMMENDS,
  2103. + WHATSUGGESTS
  2104. +};
  2105. +
  2106. +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
  2107. +{
  2108. +
  2109. + if (argc > 0) {
  2110. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2111. + const char *rel_str = NULL;
  2112. + int i;
  2113. + int changed;
  2114. +
  2115. + switch (what_field_type) {
  2116. + case WHATDEPENDS: rel_str = "depends on"; break;
  2117. + case WHATCONFLICTS: rel_str = "conflicts with"; break;
  2118. + case WHATSUGGESTS: rel_str = "suggests"; break;
  2119. + case WHATRECOMMENDS: rel_str = "recommends"; break;
  2120. + case WHATPROVIDES: rel_str = "provides"; break;
  2121. + case WHATREPLACES: rel_str = "replaces"; break;
  2122. + }
  2123. +
  2124. + if (conf->query_all)
  2125. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2126. + else
  2127. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2128. +
  2129. + /* mark the root set */
  2130. + pkg_vec_clear_marks(available_pkgs);
  2131. + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
  2132. + for (i = 0; i < argc; i++) {
  2133. + const char *dependee_pattern = argv[i];
  2134. + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
  2135. + }
  2136. + for (i = 0; i < available_pkgs->len; i++) {
  2137. + pkg_t *pkg = available_pkgs->pkgs[i];
  2138. + if (pkg->state_flag & SF_MARKED) {
  2139. + /* mark the parent (abstract) package */
  2140. + pkg_mark_provides(pkg);
  2141. + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
  2142. + }
  2143. + }
  2144. +
  2145. + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
  2146. + do {
  2147. + int j;
  2148. + changed = 0;
  2149. +
  2150. + for (j = 0; j < available_pkgs->len; j++) {
  2151. + pkg_t *pkg = available_pkgs->pkgs[j];
  2152. + int k;
  2153. + int count = ((what_field_type == WHATCONFLICTS)
  2154. + ? pkg->conflicts_count
  2155. + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
  2156. + /* skip this package if it is already marked */
  2157. + if (pkg->parent->state_flag & SF_MARKED) {
  2158. + continue;
  2159. + }
  2160. + for (k = 0; k < count; k++) {
  2161. + compound_depend_t *cdepend =
  2162. + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
  2163. + int l;
  2164. + for (l = 0; l < cdepend->possibility_count; l++) {
  2165. + depend_t *possibility = cdepend->possibilities[l];
  2166. + if (possibility->pkg->state_flag & SF_MARKED) {
  2167. + /* mark the depending package so we won't visit it again */
  2168. + pkg->state_flag |= SF_MARKED;
  2169. + pkg_mark_provides(pkg);
  2170. + changed++;
  2171. +
  2172. + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
  2173. + if (conf->verbosity > 0) {
  2174. + char *ver = pkg_version_str_alloc(pkg);
  2175. + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
  2176. + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
  2177. + if (possibility->version) {
  2178. + const char *typestr = NULL;
  2179. + switch (possibility->constraint) {
  2180. + case NONE: typestr = "none"; break;
  2181. + case EARLIER: typestr = "<"; break;
  2182. + case EARLIER_EQUAL: typestr = "<="; break;
  2183. + case EQUAL: typestr = "="; break;
  2184. + case LATER_EQUAL: typestr = ">="; break;
  2185. + case LATER: typestr = ">"; break;
  2186. + }
  2187. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2188. + }
  2189. + free(ver);
  2190. + if (!pkg_dependence_satisfiable(possibility))
  2191. + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
  2192. + }
  2193. + ipkg_message(conf, IPKG_NOTICE, "\n");
  2194. + goto next_package;
  2195. + }
  2196. + }
  2197. + }
  2198. + next_package:
  2199. + ;
  2200. + }
  2201. + } while (changed && recursive);
  2202. + pkg_vec_free(available_pkgs);
  2203. + }
  2204. +
  2205. + return 0;
  2206. +}
  2207. +
  2208. +int pkg_mark_provides(pkg_t *pkg)
  2209. +{
  2210. + int provides_count = pkg->provides_count;
  2211. + abstract_pkg_t **provides = pkg->provides;
  2212. + int i;
  2213. + pkg->parent->state_flag |= SF_MARKED;
  2214. + for (i = 0; i < provides_count; i++) {
  2215. + provides[i]->state_flag |= SF_MARKED;
  2216. + }
  2217. + return 0;
  2218. +}
  2219. +
  2220. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2221. +{
  2222. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
  2223. +}
  2224. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2225. +{
  2226. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
  2227. +}
  2228. +
  2229. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2230. +{
  2231. + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
  2232. +}
  2233. +
  2234. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2235. +{
  2236. + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
  2237. +}
  2238. +
  2239. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2240. +{
  2241. + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
  2242. +}
  2243. +
  2244. +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
  2245. +{
  2246. +
  2247. + if (argc > 0) {
  2248. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2249. + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
  2250. + int i;
  2251. +
  2252. + pkg_info_preinstall_check(conf);
  2253. +
  2254. + if (conf->query_all)
  2255. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2256. + else
  2257. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2258. + for (i = 0; i < argc; i++) {
  2259. + const char *target = argv[i];
  2260. + int j;
  2261. +
  2262. + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
  2263. + rel_str, target);
  2264. + for (j = 0; j < available_pkgs->len; j++) {
  2265. + pkg_t *pkg = available_pkgs->pkgs[j];
  2266. + int k;
  2267. + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
  2268. + for (k = 0; k < count; k++) {
  2269. + abstract_pkg_t *apkg =
  2270. + ((what_field_type == WHATPROVIDES)
  2271. + ? pkg->provides[k]
  2272. + : pkg->replaces[k]);
  2273. + if (fnmatch(target, apkg->name, 0) == 0) {
  2274. + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
  2275. + if (strcmp(target, apkg->name) != 0)
  2276. + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
  2277. + ipkg_message(conf, IPKG_ERROR, "\n");
  2278. + }
  2279. + }
  2280. + }
  2281. + }
  2282. + pkg_vec_free(available_pkgs);
  2283. + }
  2284. + return 0;
  2285. +}
  2286. +
  2287. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2288. +{
  2289. + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
  2290. +}
  2291. +
  2292. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2293. +{
  2294. + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
  2295. +}
  2296. +
  2297. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2298. +{
  2299. + int i;
  2300. +
  2301. + pkg_vec_t *installed;
  2302. + pkg_t *pkg;
  2303. + str_list_t *installed_files;
  2304. + str_list_elt_t *iter;
  2305. + char *installed_file;
  2306. +
  2307. + if (argc < 1) {
  2308. + return EINVAL;
  2309. + }
  2310. +
  2311. + installed = pkg_vec_alloc();
  2312. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  2313. +
  2314. + for (i=0; i < installed->len; i++) {
  2315. + pkg = installed->pkgs[i];
  2316. +
  2317. + installed_files = pkg_get_installed_files(pkg);
  2318. +
  2319. + for (iter = installed_files->head; iter; iter = iter->next) {
  2320. + installed_file = iter->data;
  2321. + if (fnmatch(argv[0], installed_file, 0)==0) {
  2322. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2323. + installed_file,
  2324. + pkg_version_str_alloc(pkg),
  2325. + pkg->state_status, p_userdata);
  2326. + }
  2327. + }
  2328. +
  2329. + pkg_free_installed_files(pkg);
  2330. + }
  2331. +
  2332. + /* XXX: CLEANUP: It's not obvious from the name of
  2333. + pkg_hash_fetch_all_installed that we need to call
  2334. + pkg_vec_free to avoid a memory leak. */
  2335. + pkg_vec_free(installed);
  2336. +
  2337. + return 0;
  2338. +}
  2339. +
  2340. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2341. +{
  2342. + if (argc == 3) {
  2343. + /* this is a bit gross */
  2344. + struct pkg p1, p2;
  2345. + parseVersion(&p1, argv[0]);
  2346. + parseVersion(&p2, argv[2]);
  2347. + return pkg_version_satisfied(&p1, &p2, argv[1]);
  2348. + } else {
  2349. + ipkg_message(conf, IPKG_ERROR,
  2350. + "ipkg compare_versions <v1> <op> <v2>\n"
  2351. + "<op> is one of <= >= << >> =\n");
  2352. + return -1;
  2353. + }
  2354. +}
  2355. +
  2356. +#ifndef HOST_CPU_STR
  2357. +#define HOST_CPU_STR__(X) #X
  2358. +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
  2359. +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
  2360. +#endif
  2361. +
  2362. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf)
  2363. +{
  2364. + nv_pair_list_elt_t *l;
  2365. +
  2366. + l = conf->arch_list.head;
  2367. + while (l) {
  2368. + nv_pair_t *nv = l->data;
  2369. + printf("arch %s %s\n", nv->name, nv->value);
  2370. + l = l->next;
  2371. + }
  2372. + return 0;
  2373. +}
  2374. +
  2375. +
  2376. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_cmd.h busybox-1.17.0/archival/libipkg/ipkg_cmd.h
  2377. --- busybox-1.17.0.orig/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
  2378. +++ busybox-1.17.0/archival/libipkg/ipkg_cmd.h 2010-07-08 12:01:56.206999641 +0200
  2379. @@ -0,0 +1,41 @@
  2380. +/* ipkg_cmd.h - the itsy package management system
  2381. +
  2382. + Carl D. Worth
  2383. +
  2384. + Copyright (C) 2001 University of Southern California
  2385. +
  2386. + This program is free software; you can redistribute it and/or
  2387. + modify it under the terms of the GNU General Public License as
  2388. + published by the Free Software Foundation; either version 2, or (at
  2389. + your option) any later version.
  2390. +
  2391. + This program is distributed in the hope that it will be useful, but
  2392. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2393. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2394. + General Public License for more details.
  2395. +*/
  2396. +
  2397. +#ifndef IPKG_CMD_H
  2398. +#define IPKG_CMD_H
  2399. +
  2400. +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
  2401. +
  2402. +struct ipkg_cmd
  2403. +{
  2404. + const char *name;
  2405. + int requires_args;
  2406. + ipkg_cmd_fun_t fun;
  2407. +};
  2408. +typedef struct ipkg_cmd ipkg_cmd_t;
  2409. +
  2410. +ipkg_cmd_t *ipkg_cmd_find(const char *name);
  2411. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
  2412. + const char **argv, void *userdata);
  2413. +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
  2414. +/* install any packges with state_want == SW_INSTALL */
  2415. +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
  2416. +/* ensure that all dependences are satisfied */
  2417. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
  2418. +int pkg_mark_provides(pkg_t *pkg);
  2419. +
  2420. +#endif
  2421. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_conf.c busybox-1.17.0/archival/libipkg/ipkg_conf.c
  2422. --- busybox-1.17.0.orig/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
  2423. +++ busybox-1.17.0/archival/libipkg/ipkg_conf.c 2010-07-08 12:01:56.211000430 +0200
  2424. @@ -0,0 +1,711 @@
  2425. +/* ipkg_conf.c - the itsy package management system
  2426. +
  2427. + Carl D. Worth
  2428. +
  2429. + Copyright (C) 2001 University of Southern California
  2430. +
  2431. + This program is free software; you can redistribute it and/or
  2432. + modify it under the terms of the GNU General Public License as
  2433. + published by the Free Software Foundation; either version 2, or (at
  2434. + your option) any later version.
  2435. +
  2436. + This program is distributed in the hope that it will be useful, but
  2437. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2438. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2439. + General Public License for more details.
  2440. +*/
  2441. +
  2442. +#include <glob.h>
  2443. +
  2444. +#include "ipkg.h"
  2445. +#include "ipkg_conf.h"
  2446. +
  2447. +#include "xregex.h"
  2448. +#include "sprintf_alloc.h"
  2449. +#include "ipkg_conf.h"
  2450. +#include "ipkg_message.h"
  2451. +#include "file_util.h"
  2452. +#include "str_util.h"
  2453. +#include "xsystem.h"
  2454. +
  2455. +
  2456. +ipkg_conf_t *global_conf;
  2457. +
  2458. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2459. + pkg_src_list_t *pkg_src_list,
  2460. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2461. + char **tmp_lists_dir);
  2462. +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
  2463. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  2464. + const char *name, const char *value);
  2465. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2466. + const char *default_dest_name);
  2467. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
  2468. + pkg_src_list_t *nv_pair_list);
  2469. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
  2470. + nv_pair_list_t *nv_pair_list, char * lists_dir);
  2471. +
  2472. +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
  2473. +{
  2474. + ipkg_option_t tmp[] = {
  2475. + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
  2476. + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
  2477. + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
  2478. + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
  2479. + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
  2480. + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
  2481. + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
  2482. + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
  2483. + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
  2484. + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
  2485. + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
  2486. + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
  2487. + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
  2488. + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
  2489. + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
  2490. + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
  2491. + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
  2492. + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
  2493. + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
  2494. + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
  2495. + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
  2496. + { NULL }
  2497. + };
  2498. +
  2499. + *options = (ipkg_option_t *)malloc(sizeof(tmp));
  2500. + if ( options == NULL ){
  2501. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  2502. + return -1;
  2503. + }
  2504. +
  2505. + memcpy(*options, tmp, sizeof(tmp));
  2506. + return 0;
  2507. +};
  2508. +
  2509. +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
  2510. +{
  2511. + if (arg_str) {
  2512. + if (*conf_str) {
  2513. + free(*conf_str);
  2514. + }
  2515. + *conf_str = strdup(arg_str);
  2516. + }
  2517. +}
  2518. +
  2519. +static void ipkg_conf_free_string(char **conf_str)
  2520. +{
  2521. + if (*conf_str) {
  2522. + free(*conf_str);
  2523. + *conf_str = NULL;
  2524. + }
  2525. +}
  2526. +
  2527. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
  2528. +{
  2529. + int err;
  2530. + char *tmp_dir_base;
  2531. + nv_pair_list_t tmp_dest_nv_pair_list;
  2532. + char * lists_dir =NULL;
  2533. + glob_t globbuf;
  2534. + const char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
  2535. + char *pending_dir =NULL;
  2536. +
  2537. + memset(conf, 0, sizeof(ipkg_conf_t));
  2538. +
  2539. + pkg_src_list_init(&conf->pkg_src_list);
  2540. +
  2541. + nv_pair_list_init(&tmp_dest_nv_pair_list);
  2542. + pkg_dest_list_init(&conf->pkg_dest_list);
  2543. +
  2544. + nv_pair_list_init(&conf->arch_list);
  2545. +
  2546. + conf->restrict_to_default_dest = 0;
  2547. + conf->default_dest = NULL;
  2548. +
  2549. +
  2550. + if (args->tmp_dir)
  2551. + tmp_dir_base = args->tmp_dir;
  2552. + else
  2553. + tmp_dir_base = getenv("TMPDIR");
  2554. + sprintf_alloc(&conf->tmp_dir, "%s/%s",
  2555. + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
  2556. + IPKG_CONF_TMP_DIR_SUFFIX);
  2557. + conf->tmp_dir = mkdtemp(conf->tmp_dir);
  2558. + if (conf->tmp_dir == NULL) {
  2559. + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
  2560. + __FUNCTION__, conf->tmp_dir, strerror(errno));
  2561. + return errno;
  2562. + }
  2563. +
  2564. + conf->force_depends = 0;
  2565. + conf->force_defaults = 0;
  2566. + conf->force_overwrite = 0;
  2567. + conf->force_downgrade = 0;
  2568. + conf->force_reinstall = 0;
  2569. + conf->force_space = 0;
  2570. + conf->force_removal_of_essential_packages = 0;
  2571. + conf->force_removal_of_dependent_packages = 0;
  2572. + conf->nodeps = 0;
  2573. + conf->verbose_wget = 0;
  2574. + conf->offline_root = NULL;
  2575. + conf->offline_root_pre_script_cmd = NULL;
  2576. + conf->offline_root_post_script_cmd = NULL;
  2577. + conf->multiple_providers = 0;
  2578. + conf->verbosity = 1;
  2579. + conf->noaction = 0;
  2580. +
  2581. + conf->http_proxy = NULL;
  2582. + conf->ftp_proxy = NULL;
  2583. + conf->no_proxy = NULL;
  2584. + conf->proxy_user = NULL;
  2585. + conf->proxy_passwd = NULL;
  2586. +
  2587. + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2588. + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2589. + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2590. + lists_dir=(char *)malloc(1);
  2591. + lists_dir[0]='\0';
  2592. + if (args->conf_file) {
  2593. + struct stat stat_buf;
  2594. + err = stat(args->conf_file, &stat_buf);
  2595. + if (err == 0)
  2596. + if (ipkg_conf_parse_file(conf, args->conf_file,
  2597. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2598. + /* Memory leakage from ipkg_conf_parse-file */
  2599. + return -1;
  2600. + }
  2601. +
  2602. + }
  2603. +
  2604. + /* if (!lists_dir ){*/
  2605. + if (strlen(lists_dir)<=1 ){
  2606. + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
  2607. + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
  2608. + }
  2609. +
  2610. + if (args->offline_root) {
  2611. + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
  2612. + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
  2613. + free(lists_dir);
  2614. + lists_dir = tmp;
  2615. + }
  2616. +
  2617. + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
  2618. + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
  2619. +
  2620. + conf->lists_dir = strdup(lists_dir);
  2621. + conf->pending_dir = strdup(pending_dir);
  2622. +
  2623. + if (args->offline_root)
  2624. + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
  2625. + memset(&globbuf, 0, sizeof(globbuf));
  2626. + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
  2627. + if (!err) {
  2628. + int i;
  2629. + for (i = 0; i < globbuf.gl_pathc; i++) {
  2630. + if (globbuf.gl_pathv[i])
  2631. + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
  2632. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2633. + /* Memory leakage from ipkg_conf_parse-file */
  2634. + return -1;
  2635. + }
  2636. + }
  2637. + }
  2638. + globfree(&globbuf);
  2639. +
  2640. + /* if no architectures were defined, then default all, noarch, and host architecture */
  2641. + if (nv_pair_list_empty(&conf->arch_list)) {
  2642. + nv_pair_list_append(&conf->arch_list, "all", "1");
  2643. + nv_pair_list_append(&conf->arch_list, "noarch", "1");
  2644. + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
  2645. + }
  2646. +
  2647. + /* Even if there is no conf file, we'll need at least one dest. */
  2648. + if (tmp_dest_nv_pair_list.head == NULL) {
  2649. + nv_pair_list_append(&tmp_dest_nv_pair_list,
  2650. + IPKG_CONF_DEFAULT_DEST_NAME,
  2651. + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
  2652. + }
  2653. +
  2654. + /* After parsing the file, set options from command-line, (so that
  2655. + command-line arguments take precedence) */
  2656. + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
  2657. + really needs to be cleaned up. There is so much duplication
  2658. + right now it is ridiculous. Maybe ipkg_conf_t should just save
  2659. + a pointer to args_t (which could then not be freed), rather
  2660. + than duplicating every field here? */
  2661. + if (args->force_depends) {
  2662. + conf->force_depends = 1;
  2663. + }
  2664. + if (args->force_defaults) {
  2665. + conf->force_defaults = 1;
  2666. + }
  2667. + if (args->force_overwrite) {
  2668. + conf->force_overwrite = 1;
  2669. + }
  2670. + if (args->force_downgrade) {
  2671. + conf->force_downgrade = 1;
  2672. + }
  2673. + if (args->force_reinstall) {
  2674. + conf->force_reinstall = 1;
  2675. + }
  2676. + if (args->force_removal_of_dependent_packages) {
  2677. + conf->force_removal_of_dependent_packages = 1;
  2678. + }
  2679. + if (args->force_removal_of_essential_packages) {
  2680. + conf->force_removal_of_essential_packages = 1;
  2681. + }
  2682. + if (args->nodeps) {
  2683. + conf->nodeps = 1;
  2684. + }
  2685. + if (args->noaction) {
  2686. + conf->noaction = 1;
  2687. + }
  2688. + if (args->query_all) {
  2689. + conf->query_all = 1;
  2690. + }
  2691. + if (args->verbose_wget) {
  2692. + conf->verbose_wget = 1;
  2693. + }
  2694. + if (args->multiple_providers) {
  2695. + conf->multiple_providers = 1;
  2696. + }
  2697. + if (args->verbosity != conf->verbosity) {
  2698. + conf->verbosity = args->verbosity;
  2699. + }
  2700. +
  2701. + ipkg_conf_override_string(&conf->offline_root,
  2702. + args->offline_root);
  2703. + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
  2704. + args->offline_root_pre_script_cmd);
  2705. + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
  2706. + args->offline_root_post_script_cmd);
  2707. +
  2708. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  2709. + read anything from there.
  2710. +*/
  2711. + if ( !(args->nocheckfordirorfile)){
  2712. + /* need to run load the source list before dest list -Jamey */
  2713. + if ( !(args->noreadfeedsfile))
  2714. + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
  2715. +
  2716. + /* Now that we have resolved conf->offline_root, we can commit to
  2717. + the directory names for the dests and load in all the package
  2718. + lists. */
  2719. + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
  2720. +
  2721. + if (args->dest) {
  2722. + err = ipkg_conf_set_default_dest(conf, args->dest);
  2723. + if (err) {
  2724. + return err;
  2725. + }
  2726. + }
  2727. + }
  2728. + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
  2729. + free(lists_dir);
  2730. + free(pending_dir);
  2731. +
  2732. + return 0;
  2733. +}
  2734. +
  2735. +void ipkg_conf_deinit(ipkg_conf_t *conf)
  2736. +{
  2737. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  2738. +#error
  2739. + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
  2740. + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  2741. + __FUNCTION__, conf->tmp_dir);
  2742. +#else
  2743. + int err;
  2744. +
  2745. + err = rmdir(conf->tmp_dir);
  2746. + if (err) {
  2747. + if (errno == ENOTEMPTY) {
  2748. + char *cmd;
  2749. + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
  2750. + err = xsystem(cmd);
  2751. + free(cmd);
  2752. + }
  2753. + if (err)
  2754. + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
  2755. + }
  2756. +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
  2757. +
  2758. + free(conf->tmp_dir); /*XXX*/
  2759. +
  2760. + pkg_src_list_deinit(&conf->pkg_src_list);
  2761. + pkg_dest_list_deinit(&conf->pkg_dest_list);
  2762. + nv_pair_list_deinit(&conf->arch_list);
  2763. + if (&conf->pkg_hash)
  2764. + pkg_hash_deinit(&conf->pkg_hash);
  2765. + if (&conf->file_hash)
  2766. + hash_table_deinit(&conf->file_hash);
  2767. + if (&conf->obs_file_hash)
  2768. + hash_table_deinit(&conf->obs_file_hash);
  2769. +
  2770. + ipkg_conf_free_string(&conf->offline_root);
  2771. + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
  2772. + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
  2773. +
  2774. + if (conf->verbosity > 1) {
  2775. + int i;
  2776. + hash_table_t *hashes[] = {
  2777. + &conf->pkg_hash,
  2778. + &conf->file_hash,
  2779. + &conf->obs_file_hash };
  2780. + for (i = 0; i < 3; i++) {
  2781. + hash_table_t *hash = hashes[i];
  2782. + int c = 0;
  2783. + int n_conflicts = 0;
  2784. + int j;
  2785. + for (j = 0; j < hash->n_entries; j++) {
  2786. + int len = 0;
  2787. + hash_entry_t *e = &hash->entries[j];
  2788. + if (e->next)
  2789. + n_conflicts++;
  2790. + while (e && e->key) {
  2791. + len++;
  2792. + e = e->next;
  2793. + }
  2794. + if (len > c)
  2795. + c = len;
  2796. + }
  2797. + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
  2798. + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
  2799. + hash_table_deinit(hash);
  2800. + }
  2801. + }
  2802. +}
  2803. +
  2804. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2805. + const char *default_dest_name)
  2806. +{
  2807. + pkg_dest_list_elt_t *iter;
  2808. + pkg_dest_t *dest;
  2809. +
  2810. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  2811. + dest = iter->data;
  2812. + if (strcmp(dest->name, default_dest_name) == 0) {
  2813. + conf->default_dest = dest;
  2814. + conf->restrict_to_default_dest = 1;
  2815. + return 0;
  2816. + }
  2817. + }
  2818. +
  2819. + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
  2820. +
  2821. + return 1;
  2822. +}
  2823. +
  2824. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
  2825. +{
  2826. + pkg_src_list_elt_t *iter;
  2827. + pkg_src_t *src;
  2828. + char *list_file;
  2829. +
  2830. + for (iter = pkg_src_list->head; iter; iter = iter->next) {
  2831. + src = iter->data;
  2832. + if (src == NULL) {
  2833. + continue;
  2834. + }
  2835. +
  2836. + sprintf_alloc(&list_file, "%s/%s",
  2837. + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
  2838. + src->name);
  2839. +
  2840. + if (file_exists(list_file)) {
  2841. + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
  2842. + }
  2843. + free(list_file);
  2844. + }
  2845. +
  2846. + return 0;
  2847. +}
  2848. +
  2849. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
  2850. +{
  2851. + nv_pair_list_elt_t *iter;
  2852. + nv_pair_t *nv_pair;
  2853. + pkg_dest_t *dest;
  2854. + char *root_dir;
  2855. +
  2856. + for (iter = nv_pair_list->head; iter; iter = iter->next) {
  2857. + nv_pair = iter->data;
  2858. +
  2859. + if (conf->offline_root) {
  2860. + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
  2861. + } else {
  2862. + root_dir = strdup(nv_pair->value);
  2863. + }
  2864. + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
  2865. + free(root_dir);
  2866. + if (dest == NULL) {
  2867. + continue;
  2868. + }
  2869. + if (conf->default_dest == NULL) {
  2870. + conf->default_dest = dest;
  2871. + }
  2872. + if (file_exists(dest->status_file_name)) {
  2873. + pkg_hash_add_from_file(conf, dest->status_file_name,
  2874. + NULL, dest, 1);
  2875. + }
  2876. + }
  2877. +
  2878. + return 0;
  2879. +}
  2880. +
  2881. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2882. + pkg_src_list_t *pkg_src_list,
  2883. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2884. + char **lists_dir)
  2885. +{
  2886. + ipkg_option_t * options;
  2887. + FILE *file = fopen(filename, "r");
  2888. + regex_t valid_line_re, comment_re;
  2889. +#define regmatch_size 12
  2890. + regmatch_t regmatch[regmatch_size];
  2891. +
  2892. + if (ipkg_init_options_array(conf, &options)<0)
  2893. + return ENOMEM;
  2894. +
  2895. + if (file == NULL) {
  2896. + fprintf(stderr, "%s: failed to open %s: %s\n",
  2897. + __FUNCTION__, filename, strerror(errno));
  2898. + free(options);
  2899. + return errno;
  2900. + }
  2901. + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
  2902. +
  2903. + xregcomp(&comment_re,
  2904. + "^[[:space:]]*(#.*|[[:space:]]*)$",
  2905. + REG_EXTENDED);
  2906. + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
  2907. +
  2908. + while(1) {
  2909. + int line_num = 0;
  2910. + char *line;
  2911. + char *type, *name, *value, *extra;
  2912. +
  2913. + line = file_read_line_alloc(file);
  2914. + line_num++;
  2915. + if (line == NULL) {
  2916. + break;
  2917. + }
  2918. +
  2919. + str_chomp(line);
  2920. +
  2921. + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
  2922. + goto NEXT_LINE;
  2923. + }
  2924. +
  2925. + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
  2926. + str_chomp(line);
  2927. + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
  2928. + filename, line_num, line);
  2929. + goto NEXT_LINE;
  2930. + }
  2931. +
  2932. + /* This has to be so ugly to deal with optional quotation marks */
  2933. + if (regmatch[2].rm_so > 0) {
  2934. + type = strndup(line + regmatch[2].rm_so,
  2935. + regmatch[2].rm_eo - regmatch[2].rm_so);
  2936. + } else {
  2937. + type = strndup(line + regmatch[3].rm_so,
  2938. + regmatch[3].rm_eo - regmatch[3].rm_so);
  2939. + }
  2940. + if (regmatch[5].rm_so > 0) {
  2941. + name = strndup(line + regmatch[5].rm_so,
  2942. + regmatch[5].rm_eo - regmatch[5].rm_so);
  2943. + } else {
  2944. + name = strndup(line + regmatch[6].rm_so,
  2945. + regmatch[6].rm_eo - regmatch[6].rm_so);
  2946. + }
  2947. + if (regmatch[8].rm_so > 0) {
  2948. + value = strndup(line + regmatch[8].rm_so,
  2949. + regmatch[8].rm_eo - regmatch[8].rm_so);
  2950. + } else {
  2951. + value = strndup(line + regmatch[9].rm_so,
  2952. + regmatch[9].rm_eo - regmatch[9].rm_so);
  2953. + }
  2954. + extra = NULL;
  2955. + if (regmatch[11].rm_so > 0) {
  2956. + extra = strndup (line + regmatch[11].rm_so,
  2957. + regmatch[11].rm_eo - regmatch[11].rm_so);
  2958. + }
  2959. +
  2960. + /* We use the tmp_dest_nv_pair_list below instead of
  2961. + conf->pkg_dest_list because we might encounter an
  2962. + offline_root option later and that would invalidate the
  2963. + directories we would have computed in
  2964. + pkg_dest_list_init. (We do a similar thing with
  2965. + tmp_src_nv_pair_list for sake of symmetry.) */
  2966. + if (strcmp(type, "option") == 0) {
  2967. + ipkg_conf_set_option(options, name, value);
  2968. + } else if (strcmp(type, "src") == 0) {
  2969. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  2970. + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
  2971. + } else {
  2972. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  2973. + name, value);
  2974. + }
  2975. + } else if (strcmp(type, "src/gz") == 0) {
  2976. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  2977. + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
  2978. + } else {
  2979. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  2980. + name, value);
  2981. + }
  2982. + } else if (strcmp(type, "dest") == 0) {
  2983. + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
  2984. + } else if (strcmp(type, "lists_dir") == 0) {
  2985. + *lists_dir = realloc(*lists_dir,strlen(value)+1);
  2986. + if (*lists_dir == NULL) {
  2987. + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
  2988. + free(options);
  2989. + return EINVAL;
  2990. + }
  2991. + sprintf (*lists_dir,"%s",value);
  2992. + } else if (strcmp(type, "arch") == 0) {
  2993. + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
  2994. + if (!value) {
  2995. + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
  2996. + value = strdup("10");
  2997. + }
  2998. + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
  2999. + } else {
  3000. + fprintf(stderr, "WARNING: Ignoring unknown configuration "
  3001. + "parameter: %s %s %s\n", type, name, value);
  3002. + free(options);
  3003. + return EINVAL;
  3004. + }
  3005. +
  3006. + free(type);
  3007. + free(name);
  3008. + free(value);
  3009. + if (extra)
  3010. + free (extra);
  3011. +
  3012. + NEXT_LINE:
  3013. + free(line);
  3014. + }
  3015. +
  3016. + free(options);
  3017. + regfree(&comment_re);
  3018. + regfree(&valid_line_re);
  3019. + fclose(file);
  3020. +
  3021. + return 0;
  3022. +}
  3023. +
  3024. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  3025. + const char *name, const char *value)
  3026. +{
  3027. + int i = 0;
  3028. + while (options[i].name) {
  3029. + if (strcmp(options[i].name, name) == 0) {
  3030. + switch (options[i].type) {
  3031. + case IPKG_OPT_TYPE_BOOL:
  3032. + *((int *)options[i].value) = 1;
  3033. + return 0;
  3034. + case IPKG_OPT_TYPE_INT:
  3035. + if (value) {
  3036. + *((int *)options[i].value) = atoi(value);
  3037. + return 0;
  3038. + } else {
  3039. + printf("%s: Option %s need an argument\n",
  3040. + __FUNCTION__, name);
  3041. + return EINVAL;
  3042. + }
  3043. + case IPKG_OPT_TYPE_STRING:
  3044. + if (value) {
  3045. + *((char **)options[i].value) = strdup(value);
  3046. + return 0;
  3047. + } else {
  3048. + printf("%s: Option %s need an argument\n",
  3049. + __FUNCTION__, name);
  3050. + return EINVAL;
  3051. + }
  3052. + }
  3053. + }
  3054. + i++;
  3055. + }
  3056. +
  3057. + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
  3058. + __FUNCTION__, name, value);
  3059. + return EINVAL;
  3060. +}
  3061. +
  3062. +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
  3063. +{
  3064. + pkg_dest_list_elt_t *iter;
  3065. + pkg_dest_t *dest;
  3066. + pkg_vec_t *all;
  3067. + pkg_t *pkg;
  3068. + register int i;
  3069. + int err;
  3070. +
  3071. + if (conf->noaction)
  3072. + return 0;
  3073. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3074. + dest = iter->data;
  3075. + dest->status_file = fopen(dest->status_file_tmp_name, "w");
  3076. + if (dest->status_file == NULL) {
  3077. + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
  3078. + __FUNCTION__, dest->status_file_name, strerror(errno));
  3079. + }
  3080. + }
  3081. +
  3082. + all = pkg_vec_alloc();
  3083. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  3084. +
  3085. + for(i = 0; i < all->len; i++) {
  3086. + pkg = all->pkgs[i];
  3087. + /* We don't need most uninstalled packages in the status file */
  3088. + if (pkg->state_status == SS_NOT_INSTALLED
  3089. + && (pkg->state_want == SW_UNKNOWN
  3090. + || pkg->state_want == SW_DEINSTALL
  3091. + || pkg->state_want == SW_PURGE)) {
  3092. + continue;
  3093. + }
  3094. + if (!pkg) {
  3095. + fprintf(stderr, "Null package\n");
  3096. + }
  3097. + if (pkg->dest == NULL) {
  3098. + fprintf(stderr, "%s: ERROR: Can't write status for "
  3099. + "package %s since it has a NULL dest\n",
  3100. + __FUNCTION__, pkg->name);
  3101. + continue;
  3102. + }
  3103. + if (pkg->dest->status_file) {
  3104. + pkg_print_status(pkg, pkg->dest->status_file);
  3105. + }
  3106. + }
  3107. +
  3108. + pkg_vec_free(all);
  3109. +
  3110. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3111. + dest = iter->data;
  3112. + if (dest->status_file) {
  3113. + err = ferror(dest->status_file);
  3114. + fclose(dest->status_file);
  3115. + dest->status_file = NULL;
  3116. + if (!err) {
  3117. + file_move(dest->status_file_tmp_name, dest->status_file_name);
  3118. + } else {
  3119. + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
  3120. + "retaining old %s\n", __FUNCTION__,
  3121. + dest->status_file_tmp_name, dest->status_file_name);
  3122. + }
  3123. + }
  3124. + }
  3125. +
  3126. + return 0;
  3127. +}
  3128. +
  3129. +
  3130. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
  3131. +{
  3132. + char *root_filename;
  3133. + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
  3134. + return root_filename;
  3135. +}
  3136. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_conf.h busybox-1.17.0/archival/libipkg/ipkg_conf.h
  3137. --- busybox-1.17.0.orig/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
  3138. +++ busybox-1.17.0/archival/libipkg/ipkg_conf.h 2010-07-08 12:01:56.211000430 +0200
  3139. @@ -0,0 +1,107 @@
  3140. +/* ipkg_conf.h - the itsy package management system
  3141. +
  3142. + Carl D. Worth
  3143. +
  3144. + Copyright (C) 2001 University of Southern California
  3145. +
  3146. + This program is free software; you can redistribute it and/or
  3147. + modify it under the terms of the GNU General Public License as
  3148. + published by the Free Software Foundation; either version 2, or (at
  3149. + your option) any later version.
  3150. +
  3151. + This program is distributed in the hope that it will be useful, but
  3152. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3153. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3154. + General Public License for more details.
  3155. +*/
  3156. +
  3157. +#ifndef IPKG_CONF_H
  3158. +#define IPKG_CONF_H
  3159. +
  3160. +typedef struct ipkg_conf ipkg_conf_t;
  3161. +
  3162. +#include "hash_table.h"
  3163. +#include "ipkg.h"
  3164. +#include "args.h"
  3165. +#include "pkg.h"
  3166. +#include "pkg_hash.h"
  3167. +#include "pkg_src_list.h"
  3168. +#include "pkg_dest_list.h"
  3169. +#include "nv_pair_list.h"
  3170. +
  3171. +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
  3172. +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
  3173. +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
  3174. +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
  3175. +
  3176. +/* In case the config file defines no dest */
  3177. +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
  3178. +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
  3179. +
  3180. +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
  3181. +
  3182. +struct ipkg_conf
  3183. +{
  3184. + pkg_src_list_t pkg_src_list;
  3185. + pkg_dest_list_t pkg_dest_list;
  3186. + nv_pair_list_t arch_list;
  3187. +
  3188. + int restrict_to_default_dest;
  3189. + pkg_dest_t *default_dest;
  3190. +
  3191. + char *tmp_dir;
  3192. + char *lists_dir;
  3193. + char *pending_dir;
  3194. +
  3195. + /* options */
  3196. + int force_depends;
  3197. + int force_defaults;
  3198. + int force_overwrite;
  3199. + int force_downgrade;
  3200. + int force_reinstall;
  3201. + int force_space;
  3202. + int force_removal_of_dependent_packages;
  3203. + int force_removal_of_essential_packages;
  3204. + int nodeps; /* do not follow dependences */
  3205. + int verbose_wget;
  3206. + int multiple_providers;
  3207. + char *offline_root;
  3208. + char *offline_root_pre_script_cmd;
  3209. + char *offline_root_post_script_cmd;
  3210. + int query_all;
  3211. + int verbosity;
  3212. + int noaction;
  3213. +
  3214. + /* proxy options */
  3215. + char *http_proxy;
  3216. + char *ftp_proxy;
  3217. + char *no_proxy;
  3218. + char *proxy_user;
  3219. + char *proxy_passwd;
  3220. +
  3221. + hash_table_t pkg_hash;
  3222. + hash_table_t file_hash;
  3223. + hash_table_t obs_file_hash;
  3224. +};
  3225. +
  3226. +enum ipkg_option_type {
  3227. + IPKG_OPT_TYPE_BOOL,
  3228. + IPKG_OPT_TYPE_INT,
  3229. + IPKG_OPT_TYPE_STRING
  3230. +};
  3231. +typedef enum ipkg_option_type ipkg_option_type_t;
  3232. +
  3233. +typedef struct ipkg_option ipkg_option_t;
  3234. +struct ipkg_option {
  3235. + const char *name;
  3236. + const ipkg_option_type_t type;
  3237. + const void *value;
  3238. +};
  3239. +
  3240. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
  3241. +void ipkg_conf_deinit(ipkg_conf_t *conf);
  3242. +
  3243. +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
  3244. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
  3245. +
  3246. +#endif
  3247. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_configure.c busybox-1.17.0/archival/libipkg/ipkg_configure.c
  3248. --- busybox-1.17.0.orig/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
  3249. +++ busybox-1.17.0/archival/libipkg/ipkg_configure.c 2010-07-08 12:01:56.211000430 +0200
  3250. @@ -0,0 +1,40 @@
  3251. +/* ipkg_configure.c - the itsy package management system
  3252. +
  3253. + Carl D. Worth
  3254. +
  3255. + Copyright (C) 2001 University of Southern California
  3256. +
  3257. + This program is free software; you can redistribute it and/or
  3258. + modify it under the terms of the GNU General Public License as
  3259. + published by the Free Software Foundation; either version 2, or (at
  3260. + your option) any later version.
  3261. +
  3262. + This program is distributed in the hope that it will be useful, but
  3263. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3264. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3265. + General Public License for more details.
  3266. +*/
  3267. +
  3268. +#include "ipkg.h"
  3269. +
  3270. +#include "ipkg_configure.h"
  3271. +
  3272. +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
  3273. +{
  3274. + int err;
  3275. +
  3276. + /* DPKG_INCOMPATIBILITY:
  3277. + dpkg actually does some conffile handling here, rather than at the
  3278. + end of ipkg_install(). Do we care? */
  3279. + /* DPKG_INCOMPATIBILITY:
  3280. + dpkg actually includes a version number to this script call */
  3281. + err = pkg_run_script(conf, pkg, "postinst", "configure");
  3282. + if (err) {
  3283. + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
  3284. + return err;
  3285. + }
  3286. +
  3287. + ipkg_state_changed++;
  3288. + return 0;
  3289. +}
  3290. +
  3291. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_configure.h busybox-1.17.0/archival/libipkg/ipkg_configure.h
  3292. --- busybox-1.17.0.orig/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
  3293. +++ busybox-1.17.0/archival/libipkg/ipkg_configure.h 2010-07-08 12:01:56.211000430 +0200
  3294. @@ -0,0 +1,25 @@
  3295. +/* ipkg_configure.h - the itsy package management system
  3296. +
  3297. + Carl D. Worth
  3298. +
  3299. + Copyright (C) 2001 University of Southern California
  3300. +
  3301. + This program is free software; you can redistribute it and/or
  3302. + modify it under the terms of the GNU General Public License as
  3303. + published by the Free Software Foundation; either version 2, or (at
  3304. + your option) any later version.
  3305. +
  3306. + This program is distributed in the hope that it will be useful, but
  3307. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3308. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3309. + General Public License for more details.
  3310. +*/
  3311. +
  3312. +#ifndef IPKG_CONFIGURE_H
  3313. +#define IPKG_CONFIGURE_H
  3314. +
  3315. +#include "ipkg_conf.h"
  3316. +
  3317. +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
  3318. +
  3319. +#endif
  3320. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_download.c busybox-1.17.0/archival/libipkg/ipkg_download.c
  3321. --- busybox-1.17.0.orig/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
  3322. +++ busybox-1.17.0/archival/libipkg/ipkg_download.c 2010-07-08 12:01:56.211000430 +0200
  3323. @@ -0,0 +1,195 @@
  3324. +/* ipkg_download.c - the itsy package management system
  3325. +
  3326. + Carl D. Worth
  3327. +
  3328. + Copyright (C) 2001 University of Southern California
  3329. +
  3330. + This program is free software; you can redistribute it and/or
  3331. + modify it under the terms of the GNU General Public License as
  3332. + published by the Free Software Foundation; either version 2, or (at
  3333. + your option) any later version.
  3334. +
  3335. + This program is distributed in the hope that it will be useful, but
  3336. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3337. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3338. + General Public License for more details.
  3339. +*/
  3340. +
  3341. +#include "ipkg.h"
  3342. +#include "ipkg_download.h"
  3343. +#include "ipkg_message.h"
  3344. +
  3345. +#include "sprintf_alloc.h"
  3346. +#include "xsystem.h"
  3347. +#include "file_util.h"
  3348. +#include "str_util.h"
  3349. +
  3350. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
  3351. +{
  3352. + int err = 0;
  3353. +
  3354. + char *src_basec = strdup(src);
  3355. + char *src_base = basename(src_basec);
  3356. + char *tmp_file_location;
  3357. + char *cmd;
  3358. +
  3359. + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
  3360. +
  3361. + fflush(stdout);
  3362. +
  3363. + if (str_starts_with(src, "file:")) {
  3364. + int ret;
  3365. + const char *file_src = src + 5;
  3366. + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
  3367. + ret = file_copy(src + 5, dest_file_name);
  3368. + ipkg_message(conf,IPKG_INFO,"Done.\n");
  3369. + return ret;
  3370. + }
  3371. +
  3372. + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
  3373. + err = unlink(tmp_file_location);
  3374. + if (err && errno != ENOENT) {
  3375. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
  3376. + __FUNCTION__, tmp_file_location, strerror(errno));
  3377. + free(tmp_file_location);
  3378. + return errno;
  3379. + }
  3380. +
  3381. + if (conf->http_proxy) {
  3382. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
  3383. + setenv("http_proxy", conf->http_proxy, 1);
  3384. + }
  3385. + if (conf->ftp_proxy) {
  3386. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
  3387. + setenv("ftp_proxy", conf->ftp_proxy, 1);
  3388. + }
  3389. + if (conf->no_proxy) {
  3390. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
  3391. + setenv("no_proxy", conf->no_proxy, 1);
  3392. + }
  3393. +
  3394. + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
  3395. + sprintf_alloc(&cmd, "wget %s %s%s %s%s %s -P %s %s",
  3396. + (conf->http_proxy || conf->ftp_proxy) ? "-Y on" : "",
  3397. + conf->proxy_user ? "--proxy-user=" : "",
  3398. + conf->proxy_user ? conf->proxy_user : "",
  3399. + conf->proxy_passwd ? "--proxy-passwd=" : "",
  3400. + conf->proxy_passwd ? conf->proxy_passwd : "",
  3401. + conf->verbose_wget ? "" : "-q",
  3402. + conf->tmp_dir,
  3403. + src);
  3404. + err = xsystem(cmd);
  3405. + if (err) {
  3406. + if (err != -1) {
  3407. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
  3408. + __FUNCTION__, err, cmd);
  3409. + }
  3410. + unlink(tmp_file_location);
  3411. + free(tmp_file_location);
  3412. + free(src_basec);
  3413. + free(cmd);
  3414. + return EINVAL;
  3415. + }
  3416. + free(cmd);
  3417. +
  3418. + err = file_move(tmp_file_location, dest_file_name);
  3419. +
  3420. + free(tmp_file_location);
  3421. + free(src_basec);
  3422. +
  3423. + if (err) {
  3424. + return err;
  3425. + }
  3426. +
  3427. + return 0;
  3428. +}
  3429. +
  3430. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
  3431. +{
  3432. + int err;
  3433. + char *url;
  3434. +
  3435. + if (pkg->src == NULL) {
  3436. + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
  3437. + pkg->name, pkg->parent->name);
  3438. + return -1;
  3439. + }
  3440. +
  3441. + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
  3442. +
  3443. + /* XXX: BUG: The pkg->filename might be something like
  3444. + "../../foo.ipk". While this is correct, and exactly what we
  3445. + want to use to construct url above, here we actually need to
  3446. + use just the filename part, without any directory. */
  3447. + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
  3448. +
  3449. + err = ipkg_download(conf, url, pkg->local_filename);
  3450. + free(url);
  3451. +
  3452. + return err;
  3453. +}
  3454. +
  3455. +/*
  3456. + * Downloads file from url, installs in package database, return package name.
  3457. + */
  3458. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
  3459. +{
  3460. + int err = 0;
  3461. + pkg_t *pkg;
  3462. + pkg = pkg_new();
  3463. + if (pkg == NULL)
  3464. + return ENOMEM;
  3465. +
  3466. + if (str_starts_with(url, "http://")
  3467. + || str_starts_with(url, "ftp://")) {
  3468. + char *tmp_file;
  3469. + char *file_basec = strdup(url);
  3470. + char *file_base = basename(file_basec);
  3471. +
  3472. + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
  3473. + err = ipkg_download(conf, url, tmp_file);
  3474. + if (err)
  3475. + return err;
  3476. +
  3477. + err = pkg_init_from_file(pkg, tmp_file);
  3478. + if (err)
  3479. + return err;
  3480. + pkg->local_filename = strdup(tmp_file);
  3481. +
  3482. + free(tmp_file);
  3483. + free(file_basec);
  3484. +
  3485. + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
  3486. + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
  3487. +
  3488. + err = pkg_init_from_file(pkg, url);
  3489. + if (err)
  3490. + return err;
  3491. + pkg->local_filename = strdup(url);
  3492. + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
  3493. + pkg->provided_by_hand = 1;
  3494. +
  3495. + } else {
  3496. + pkg_deinit(pkg);
  3497. + free(pkg);
  3498. + return 0;
  3499. + }
  3500. +
  3501. + if (!pkg->architecture) {
  3502. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3503. + return -EINVAL;
  3504. + }
  3505. +
  3506. + pkg->dest = conf->default_dest;
  3507. + pkg->state_want = SW_INSTALL;
  3508. + pkg->state_flag |= SF_PREFER;
  3509. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3510. + if ( pkg == NULL ){
  3511. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  3512. + return 0;
  3513. + }
  3514. + if (namep) {
  3515. + *namep = strdup(pkg->name);
  3516. + }
  3517. + return 0;
  3518. +}
  3519. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_download.h busybox-1.17.0/archival/libipkg/ipkg_download.h
  3520. --- busybox-1.17.0.orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
  3521. +++ busybox-1.17.0/archival/libipkg/ipkg_download.h 2010-07-08 12:01:56.211000430 +0200
  3522. @@ -0,0 +1,30 @@
  3523. +/* ipkg_download.h - the itsy package management system
  3524. +
  3525. + Carl D. Worth
  3526. +
  3527. + Copyright (C) 2001 University of Southern California
  3528. +
  3529. + This program is free software; you can redistribute it and/or
  3530. + modify it under the terms of the GNU General Public License as
  3531. + published by the Free Software Foundation; either version 2, or (at
  3532. + your option) any later version.
  3533. +
  3534. + This program is distributed in the hope that it will be useful, but
  3535. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3536. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3537. + General Public License for more details.
  3538. +*/
  3539. +
  3540. +#ifndef IPKG_DOWNLOAD_H
  3541. +#define IPKG_DOWNLOAD_H
  3542. +
  3543. +#include "ipkg_conf.h"
  3544. +
  3545. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
  3546. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
  3547. +/*
  3548. + * Downloads file from url, installs in package database, return package name.
  3549. + */
  3550. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
  3551. +
  3552. +#endif
  3553. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg.h busybox-1.17.0/archival/libipkg/ipkg.h
  3554. --- busybox-1.17.0.orig/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
  3555. +++ busybox-1.17.0/archival/libipkg/ipkg.h 2010-07-08 12:01:56.211000430 +0200
  3556. @@ -0,0 +1,68 @@
  3557. +/* ipkg.h - the itsy package management system
  3558. +
  3559. + Carl D. Worth
  3560. +
  3561. + Copyright (C) 2001 University of Southern California
  3562. +
  3563. + This program is free software; you can redistribute it and/or
  3564. + modify it under the terms of the GNU General Public License as
  3565. + published by the Free Software Foundation; either version 2, or (at
  3566. + your option) any later version.
  3567. +
  3568. + This program is distributed in the hope that it will be useful, but
  3569. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3570. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3571. + General Public License for more details.
  3572. +*/
  3573. +
  3574. +#ifndef IPKG_H
  3575. +#define IPKG_H
  3576. +
  3577. +#include "libbb.h"
  3578. +
  3579. +#include "ipkg_includes.h"
  3580. +#include "ipkg_conf.h"
  3581. +#include "ipkg_message.h"
  3582. +
  3583. +#define IPKG_PKG_EXTENSION ".ipk"
  3584. +#define DPKG_PKG_EXTENSION ".deb"
  3585. +
  3586. +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
  3587. +#define IPKG_PKG_VERSION_SEP_CHAR '_'
  3588. +
  3589. +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
  3590. +#define IPKG_LISTS_DIR_SUFFIX "lists"
  3591. +#define IPKG_INFO_DIR_SUFFIX "info"
  3592. +#define IPKG_STATUS_FILE_SUFFIX "status"
  3593. +
  3594. +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
  3595. +
  3596. +#define IPKG_LIST_DESCRIPTION_LENGTH 128
  3597. +
  3598. +#define IPKG_VERSION "1.00"
  3599. +
  3600. +
  3601. +enum ipkg_error {
  3602. + IPKG_SUCCESS = 0,
  3603. + IPKG_PKG_DEPS_UNSATISFIED,
  3604. + IPKG_PKG_IS_ESSENTIAL,
  3605. + IPKG_PKG_HAS_DEPENDENTS,
  3606. + IPKG_PKG_HAS_NO_CANDIDATE
  3607. +};
  3608. +typedef enum ipkg_error ipkg_error_t;
  3609. +
  3610. +extern int ipkg_state_changed;
  3611. +
  3612. +
  3613. +struct errlist {
  3614. + char * errmsg;
  3615. + struct errlist * next;
  3616. +} ;
  3617. +
  3618. +extern struct errlist* error_list;
  3619. +
  3620. +extern ipkg_conf_t *global_conf;
  3621. +
  3622. +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
  3623. +
  3624. +#endif
  3625. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_includes.h busybox-1.17.0/archival/libipkg/ipkg_includes.h
  3626. --- busybox-1.17.0.orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
  3627. +++ busybox-1.17.0/archival/libipkg/ipkg_includes.h 2010-07-08 12:01:56.214999822 +0200
  3628. @@ -0,0 +1,81 @@
  3629. +#ifndef IPKG_INCLUDES_H
  3630. +#define IPKG_INCLUDES_H
  3631. +
  3632. +/* Define to 1 if you have the <memory.h> header file. */
  3633. +#define HAVE_MEMORY_H 1
  3634. +
  3635. +/* Define to 1 if you have the <regex.h> header file. */
  3636. +#define HAVE_REGEX_H 1
  3637. +
  3638. +/* Define to 1 if you have the <stdlib.h> header file. */
  3639. +#define HAVE_STDLIB_H 1
  3640. +
  3641. +/* Define to 1 if you have the <strings.h> header file. */
  3642. +#define HAVE_STRINGS_H 1
  3643. +
  3644. +/* Define to 1 if you have the <string.h> header file. */
  3645. +#define HAVE_STRING_H 1
  3646. +
  3647. +/* Define to 1 if you have the <sys/stat.h> header file. */
  3648. +#define HAVE_SYS_STAT_H 1
  3649. +
  3650. +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
  3651. +#define HAVE_SYS_WAIT_H 1
  3652. +
  3653. +/* Define to 1 if you have the <unistd.h> header file. */
  3654. +#define HAVE_UNISTD_H 1
  3655. +
  3656. +/* Define to 1 if you have the ANSI C header files. */
  3657. +#define STDC_HEADERS 1
  3658. +
  3659. +
  3660. +#include <stdio.h>
  3661. +
  3662. +#if STDC_HEADERS
  3663. +# include <stdlib.h>
  3664. +# include <stdarg.h>
  3665. +# include <stddef.h>
  3666. +# include <ctype.h>
  3667. +# include <errno.h>
  3668. +#else
  3669. +# if HAVE_STDLIB_H
  3670. +# include <stdlib.h>
  3671. +# endif
  3672. +#endif
  3673. +
  3674. +#if HAVE_REGEX_H
  3675. +# include <regex.h>
  3676. +#endif
  3677. +
  3678. +#if HAVE_STRING_H
  3679. +# if !STDC_HEADERS && HAVE_MEMORY_H
  3680. +# include <memory.h>
  3681. +# endif
  3682. +/* XXX: What's the right way to pick up GNU's strndup declaration? */
  3683. +# if __GNUC__
  3684. +# define __USE_GNU 1
  3685. +# endif
  3686. +# include <string.h>
  3687. +# undef __USE_GNU
  3688. +#endif
  3689. +
  3690. +#if HAVE_STRINGS_H
  3691. +# include <strings.h>
  3692. +#endif
  3693. +
  3694. +#if HAVE_SYS_STAT_H
  3695. +# include <sys/stat.h>
  3696. +#endif
  3697. +
  3698. +#if HAVE_SYS_WAIT_H
  3699. +# include <sys/wait.h>
  3700. +#endif
  3701. +
  3702. +#if HAVE_UNISTD_H
  3703. +# include <sys/types.h>
  3704. +# include <unistd.h>
  3705. +#endif
  3706. +
  3707. +#include <sys/mount.h>
  3708. +
  3709. +#endif /* IPKG_INCLUDES_H */
  3710. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_install.c busybox-1.17.0/archival/libipkg/ipkg_install.c
  3711. --- busybox-1.17.0.orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
  3712. +++ busybox-1.17.0/archival/libipkg/ipkg_install.c 2010-07-08 12:01:56.219000332 +0200
  3713. @@ -0,0 +1,1982 @@
  3714. +/* ipkg_install.c - the itsy package management system
  3715. +
  3716. + Carl D. Worth
  3717. +
  3718. + Copyright (C) 2001 University of Southern California
  3719. +
  3720. + This program is free software; you can redistribute it and/or
  3721. + modify it under the terms of the GNU General Public License as
  3722. + published by the Free Software Foundation; either version 2, or (at
  3723. + your option) any later version.
  3724. +
  3725. + This program is distributed in the hope that it will be useful, but
  3726. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3727. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3728. + General Public License for more details.
  3729. +*/
  3730. +
  3731. +#include "ipkg.h"
  3732. +#include <errno.h>
  3733. +#include <dirent.h>
  3734. +#include <glob.h>
  3735. +#include <time.h>
  3736. +#include <signal.h>
  3737. +typedef void (*sighandler_t)(int);
  3738. +
  3739. +#include "pkg.h"
  3740. +#include "pkg_hash.h"
  3741. +#include "pkg_extract.h"
  3742. +
  3743. +#include "ipkg_install.h"
  3744. +#include "ipkg_configure.h"
  3745. +#include "ipkg_download.h"
  3746. +#include "ipkg_remove.h"
  3747. +
  3748. +#include "ipkg_utils.h"
  3749. +#include "ipkg_message.h"
  3750. +
  3751. +#include "sprintf_alloc.h"
  3752. +#include "file_util.h"
  3753. +#include "str_util.h"
  3754. +#include "xsystem.h"
  3755. +#include "user.h"
  3756. +
  3757. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  3758. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
  3759. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
  3760. +
  3761. +/*
  3762. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3763. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3764. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3765. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3766. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3767. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3768. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3769. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
  3770. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3771. +*/
  3772. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3773. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3774. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg);
  3775. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3776. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg);
  3777. +
  3778. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3779. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3780. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
  3781. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
  3782. +
  3783. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
  3784. +
  3785. +static int user_prefers_old_conffile(const char *file, const char *backup);
  3786. +
  3787. +static char *backup_filename_alloc(const char *file_name);
  3788. +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
  3789. +static int backup_exists_for(const char *file_name);
  3790. +static int backup_remove(const char *file_name);
  3791. +
  3792. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees);
  3793. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3794. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3795. +
  3796. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
  3797. +{
  3798. + int err, cmp;
  3799. + pkg_t *pkg, *old;
  3800. + char *old_version, *new_version;
  3801. +
  3802. + pkg = pkg_new();
  3803. + if (pkg == NULL) {
  3804. + return ENOMEM;
  3805. + }
  3806. +
  3807. + err = pkg_init_from_file(pkg, filename);
  3808. + if (err) {
  3809. + return err;
  3810. + }
  3811. +
  3812. + if (!pkg->architecture) {
  3813. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3814. + return -EINVAL;
  3815. + }
  3816. +
  3817. + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
  3818. + freeing the pkg that we pass in. It might be nice to clean this up
  3819. + if possible. */
  3820. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3821. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  3822. +
  3823. + pkg->local_filename = strdup(filename);
  3824. +
  3825. + if (old) {
  3826. + old_version = pkg_version_str_alloc(old);
  3827. + new_version = pkg_version_str_alloc(pkg);
  3828. +
  3829. + cmp = pkg_compare_versions(old, pkg);
  3830. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3831. + cmp = -1 ; /* then we force ipkg to downgrade */
  3832. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3833. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3834. + }
  3835. + if (cmp > 0) {
  3836. + ipkg_message(conf, IPKG_NOTICE,
  3837. + "Not downgrading package %s on %s from %s to %s.\n",
  3838. + old->name, old->dest->name, old_version, new_version);
  3839. + pkg->state_want = SW_DEINSTALL;
  3840. + pkg->state_flag |= SF_OBSOLETE;
  3841. + free(old_version);
  3842. + free(new_version);
  3843. + return 0;
  3844. + } else {
  3845. + free(old_version);
  3846. + free(new_version);
  3847. + }
  3848. + }
  3849. +
  3850. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3851. + return ipkg_install_pkg(conf, pkg,0);
  3852. +}
  3853. +
  3854. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3855. +{
  3856. + int cmp;
  3857. + pkg_t *old, *new;
  3858. + char *old_version, *new_version;
  3859. +
  3860. + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
  3861. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  3862. + if ( old )
  3863. + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
  3864. +
  3865. + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
  3866. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  3867. + if ( new )
  3868. + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
  3869. +
  3870. +/* Pigi Basically here is broken the version stuff.
  3871. + What's happening is that nothing provide the version to differents
  3872. + functions, so the returned struct is always the latest.
  3873. + That's why the install by name don't work.
  3874. +*/
  3875. + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
  3876. +
  3877. + if ( old )
  3878. + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
  3879. + if ( new )
  3880. + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
  3881. + ipkg_message(conf, IPKG_DEBUG2, " \n");
  3882. +
  3883. + if (new == NULL) {
  3884. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3885. + }
  3886. +
  3887. + new->state_flag |= SF_USER;
  3888. + if (old) {
  3889. + old_version = pkg_version_str_alloc(old);
  3890. + new_version = pkg_version_str_alloc(new);
  3891. +
  3892. + cmp = pkg_compare_versions(old, new);
  3893. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3894. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
  3895. + cmp = -1 ; /* then we force ipkg to downgrade */
  3896. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3897. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3898. + }
  3899. + ipkg_message(conf, IPKG_DEBUG,
  3900. + "Comparing visible versions of pkg %s:"
  3901. + "\n\t%s is installed "
  3902. + "\n\t%s is available "
  3903. + "\n\t%d was comparison result\n",
  3904. + pkg_name, old_version, new_version, cmp);
  3905. + if (cmp == 0 && !conf->force_reinstall) {
  3906. + ipkg_message(conf, IPKG_NOTICE,
  3907. + "Package %s (%s) installed in %s is up to date.\n",
  3908. + old->name, old_version, old->dest->name);
  3909. + free(old_version);
  3910. + free(new_version);
  3911. + return 0;
  3912. + } else if (cmp > 0) {
  3913. + ipkg_message(conf, IPKG_NOTICE,
  3914. + "Not downgrading package %s on %s from %s to %s.\n",
  3915. + old->name, old->dest->name, old_version, new_version);
  3916. + free(old_version);
  3917. + free(new_version);
  3918. + return 0;
  3919. + } else if (cmp < 0) {
  3920. + new->dest = old->dest;
  3921. + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
  3922. + }
  3923. + }
  3924. +
  3925. + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
  3926. + supposed to be an ipkg_error_t, but ipkg_install_pkg could
  3927. + return any kind of integer, (might be errno from a syscall,
  3928. + etc.). This is a real mess and will need to be cleaned up if
  3929. + anyone ever wants to make a nice libipkg. */
  3930. +
  3931. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3932. + return ipkg_install_pkg(conf, new,0);
  3933. +}
  3934. +
  3935. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3936. +{
  3937. + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
  3938. + int i;
  3939. + ipkg_error_t err;
  3940. + abstract_pkg_t *ppkg ;
  3941. +
  3942. + if (providers == NULL)
  3943. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3944. +
  3945. + for (i = 0; i < providers->len; i++) {
  3946. + ppkg = abstract_pkg_vec_get(providers, i);
  3947. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
  3948. + err = ipkg_install_by_name(conf, ppkg->name);
  3949. + if (err)
  3950. + return err;
  3951. +/* XXX Maybe ppkg should be freed ? */
  3952. + }
  3953. + return 0;
  3954. +}
  3955. +
  3956. +/*
  3957. + * Walk dependence graph starting with pkg, collect packages to be
  3958. + * installed into pkgs_needed, in dependence order.
  3959. + */
  3960. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
  3961. +{
  3962. + int i, err;
  3963. + pkg_vec_t *depends = pkg_vec_alloc();
  3964. + char **unresolved = NULL;
  3965. + int ndepends;
  3966. +
  3967. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  3968. + pkg, depends,
  3969. + &unresolved);
  3970. +
  3971. + if (unresolved) {
  3972. + ipkg_message(conf, IPKG_ERROR,
  3973. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  3974. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  3975. + while (*unresolved) {
  3976. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  3977. + unresolved++;
  3978. + }
  3979. + ipkg_message(conf, IPKG_ERROR, "\n");
  3980. + if (! conf->force_depends) {
  3981. + ipkg_message(conf, IPKG_INFO,
  3982. + "This could mean that your package list is out of date or that the packages\n"
  3983. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  3984. + "of this problem try again with the '-force-depends' option.\n");
  3985. + pkg_vec_free(depends);
  3986. + return IPKG_PKG_DEPS_UNSATISFIED;
  3987. + }
  3988. + }
  3989. +
  3990. + if (ndepends <= 0) {
  3991. + pkg_vec_free(depends);
  3992. + return 0;
  3993. + }
  3994. +
  3995. + for (i = 0; i < depends->len; i++) {
  3996. + pkg_t *dep = depends->pkgs[i];
  3997. + /* The package was uninstalled when we started, but another
  3998. + dep earlier in this loop may have depended on it and pulled
  3999. + it in, so check first. */
  4000. + if ((dep->state_status != SS_INSTALLED)
  4001. + && (dep->state_status != SS_UNPACKED)
  4002. + && (dep->state_want != SW_INSTALL)) {
  4003. +
  4004. + /* Mark packages as to-be-installed */
  4005. + dep->state_want = SW_INSTALL;
  4006. +
  4007. + /* Dependencies should be installed the same place as pkg */
  4008. + if (dep->dest == NULL) {
  4009. + dep->dest = pkg->dest;
  4010. + }
  4011. +
  4012. + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
  4013. + if (err) {
  4014. + pkg_vec_free(depends);
  4015. + return err;
  4016. + }
  4017. + }
  4018. + }
  4019. + if (pkgs_needed)
  4020. + pkg_vec_insert(pkgs_needed, pkg);
  4021. +
  4022. + pkg_vec_free(depends);
  4023. +
  4024. + return 0;
  4025. +}
  4026. +
  4027. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
  4028. +{
  4029. + int cmp;
  4030. + pkg_t *old, *new;
  4031. + char *old_version, *new_version;
  4032. +
  4033. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  4034. +
  4035. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  4036. + if (new == NULL) {
  4037. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4038. + }
  4039. + if (old) {
  4040. + old_version = pkg_version_str_alloc(old);
  4041. + new_version = pkg_version_str_alloc(new);
  4042. +
  4043. + cmp = pkg_compare_versions(old, new);
  4044. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4045. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
  4046. + cmp = -1 ; /* then we force ipkg to downgrade */
  4047. + /* We need to use a value < 0 because in the 0 case we are asking to */
  4048. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4049. + }
  4050. + ipkg_message(conf, IPKG_DEBUG,
  4051. + "comparing visible versions of pkg %s:"
  4052. + "\n\t%s is installed "
  4053. + "\n\t%s is available "
  4054. + "\n\t%d was comparison result\n",
  4055. + pkg_name, old_version, new_version, cmp);
  4056. + if (cmp == 0 && !conf->force_reinstall) {
  4057. + ipkg_message(conf, IPKG_NOTICE,
  4058. + "Package %s (%s) installed in %s is up to date.\n",
  4059. + old->name, old_version, old->dest->name);
  4060. + free(old_version);
  4061. + free(new_version);
  4062. + return 0;
  4063. + } else if (cmp > 0) {
  4064. + ipkg_message(conf, IPKG_NOTICE,
  4065. + "Not downgrading package %s on %s from %s to %s.\n",
  4066. + old->name, old->dest->name, old_version, new_version);
  4067. + free(old_version);
  4068. + free(new_version);
  4069. + return 0;
  4070. + } else if (cmp < 0) {
  4071. + new->dest = old->dest;
  4072. + old->state_want = SW_DEINSTALL;
  4073. + old->state_flag |= SF_OBSOLETE;
  4074. + }
  4075. + }
  4076. + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
  4077. +}
  4078. +
  4079. +
  4080. +
  4081. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
  4082. +{
  4083. + int i, err;
  4084. + pkg_vec_t *depends = pkg_vec_alloc();
  4085. + pkg_t *dep;
  4086. + char **unresolved = NULL;
  4087. + int ndepends;
  4088. +
  4089. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4090. + pkg, depends,
  4091. + &unresolved);
  4092. +
  4093. + if (unresolved) {
  4094. + ipkg_message(conf, IPKG_ERROR,
  4095. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4096. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4097. + while (*unresolved) {
  4098. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4099. + unresolved++;
  4100. + }
  4101. + ipkg_message(conf, IPKG_ERROR, "\n");
  4102. + if (! conf->force_depends) {
  4103. + ipkg_message(conf, IPKG_INFO,
  4104. + "This could mean that your package list is out of date or that the packages\n"
  4105. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4106. + "of this problem try again with the '-force-depends' option.\n");
  4107. + pkg_vec_free(depends);
  4108. + return IPKG_PKG_DEPS_UNSATISFIED;
  4109. + }
  4110. + }
  4111. +
  4112. + if (ndepends <= 0) {
  4113. + return 0;
  4114. + }
  4115. +
  4116. + /* Mark packages as to-be-installed */
  4117. + for (i=0; i < depends->len; i++) {
  4118. + /* Dependencies should be installed the same place as pkg */
  4119. + if (depends->pkgs[i]->dest == NULL) {
  4120. + depends->pkgs[i]->dest = pkg->dest;
  4121. + }
  4122. + depends->pkgs[i]->state_want = SW_INSTALL;
  4123. + }
  4124. +
  4125. + for (i = 0; i < depends->len; i++) {
  4126. + dep = depends->pkgs[i];
  4127. + /* The package was uninstalled when we started, but another
  4128. + dep earlier in this loop may have depended on it and pulled
  4129. + it in, so check first. */
  4130. + if ((dep->state_status != SS_INSTALLED)
  4131. + && (dep->state_status != SS_UNPACKED)) {
  4132. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4133. + err = ipkg_install_pkg(conf, dep,0);
  4134. + if (err) {
  4135. + pkg_vec_free(depends);
  4136. + return err;
  4137. + }
  4138. + }
  4139. + }
  4140. +
  4141. + pkg_vec_free(depends);
  4142. +
  4143. + return 0;
  4144. +}
  4145. +
  4146. +
  4147. +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
  4148. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
  4149. +{
  4150. + if (conf->nodeps == 0) {
  4151. + int i;
  4152. + pkg_vec_t *installed = pkg_vec_alloc();
  4153. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  4154. + for (i = 0; i < installed->len; i++) {
  4155. + pkg_t *pkg = installed->pkgs[i];
  4156. + satisfy_dependencies_for(conf, pkg);
  4157. + }
  4158. + pkg_vec_free(installed);
  4159. + }
  4160. + return 0;
  4161. +}
  4162. +
  4163. +
  4164. +
  4165. +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
  4166. +{
  4167. + int i;
  4168. + pkg_vec_t *conflicts = NULL;
  4169. + int level;
  4170. + const char *prefix;
  4171. + if (conf->force_depends) {
  4172. + level = IPKG_NOTICE;
  4173. + prefix = "Warning";
  4174. + } else {
  4175. + level = IPKG_ERROR;
  4176. + prefix = "ERROR";
  4177. + }
  4178. +
  4179. + if (!conf->force_depends)
  4180. + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(pkg);
  4181. +
  4182. + if (conflicts) {
  4183. + ipkg_message(conf, level,
  4184. + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
  4185. + i = 0;
  4186. + while (i < conflicts->len)
  4187. + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
  4188. + ipkg_message(conf, level, "\n");
  4189. + pkg_vec_free(conflicts);
  4190. + return IPKG_PKG_DEPS_UNSATISFIED;
  4191. + }
  4192. + return 0;
  4193. +}
  4194. +
  4195. +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
  4196. +{
  4197. + str_list_t *new_list = pkg_get_installed_files(new_pkg);
  4198. + str_list_elt_t *iter;
  4199. +
  4200. + for (iter = new_list->head; iter; iter = iter->next) {
  4201. + char *new_file = iter->data;
  4202. + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
  4203. + if (!new_file)
  4204. + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
  4205. + if (!owner || (owner == old_pkg))
  4206. + file_hash_set_file_owner(conf, new_file, new_pkg);
  4207. + }
  4208. + if (old_pkg) {
  4209. + str_list_t *old_list = pkg_get_installed_files(old_pkg);
  4210. + for (iter = old_list->head; iter; iter = iter->next) {
  4211. + char *old_file = iter->data;
  4212. + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
  4213. + if (owner == old_pkg) {
  4214. + /* obsolete */
  4215. + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
  4216. + }
  4217. + }
  4218. + }
  4219. + return 0;
  4220. +}
  4221. +
  4222. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
  4223. +{
  4224. + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
  4225. +
  4226. + /* sma 6.20.02: yup; here's the first bit */
  4227. + /*
  4228. + * XXX: BUG easy for cworth
  4229. + * 1) please point the call below to the correct current root destination
  4230. + * 2) we need to resolve how to check the required space for a pending pkg,
  4231. + * my diddling with the .ipk file size below isn't going to cut it.
  4232. + * 3) return a proper error code instead of 1
  4233. + */
  4234. + int comp_size, blocks_available;
  4235. +
  4236. + if (!conf->force_space && pkg->installed_size != NULL) {
  4237. + blocks_available = get_available_blocks(conf->default_dest->root_dir);
  4238. +
  4239. + comp_size = strtoul(pkg->installed_size, NULL, 0);
  4240. + /* round up a blocks count without doing fancy-but-slow casting jazz */
  4241. + comp_size = (int)((comp_size + 1023) / 1024);
  4242. +
  4243. + if (comp_size >= blocks_available) {
  4244. + ipkg_message(conf, IPKG_ERROR,
  4245. + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
  4246. + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
  4247. + return ENOSPC;
  4248. + }
  4249. + }
  4250. + return 0;
  4251. +}
  4252. +
  4253. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
  4254. +{
  4255. + int err;
  4256. + char *conffiles_file_name;
  4257. + char *root_dir;
  4258. + FILE *conffiles_file;
  4259. +
  4260. + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
  4261. +
  4262. + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
  4263. + if (pkg->tmp_unpack_dir == NULL) {
  4264. + ipkg_message(conf, IPKG_ERROR,
  4265. + "%s: Failed to create temporary directory '%s': %s\n",
  4266. + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
  4267. + return errno;
  4268. + }
  4269. +
  4270. + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
  4271. + if (err) {
  4272. + return err;
  4273. + }
  4274. +
  4275. + /* XXX: CLEANUP: There might be a cleaner place to read in the
  4276. + conffiles. Seems like I should be able to get everything to go
  4277. + through pkg_init_from_file. If so, maybe it would make sense to
  4278. + move all of unpack_pkg_control_files to that function. */
  4279. +
  4280. + /* Don't need to re-read conffiles if we already have it */
  4281. + if (pkg->conffiles.head) {
  4282. + return 0;
  4283. + }
  4284. +
  4285. + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
  4286. + if (! file_exists(conffiles_file_name)) {
  4287. + free(conffiles_file_name);
  4288. + return 0;
  4289. + }
  4290. +
  4291. + conffiles_file = fopen(conffiles_file_name, "r");
  4292. + if (conffiles_file == NULL) {
  4293. + fprintf(stderr, "%s: failed to open %s: %s\n",
  4294. + __FUNCTION__, conffiles_file_name, strerror(errno));
  4295. + free(conffiles_file_name);
  4296. + return errno;
  4297. + }
  4298. + free(conffiles_file_name);
  4299. +
  4300. + while (1) {
  4301. + char *cf_name;
  4302. + char *cf_name_in_dest;
  4303. +
  4304. + cf_name = file_read_line_alloc(conffiles_file);
  4305. + if (cf_name == NULL) {
  4306. + break;
  4307. + }
  4308. + str_chomp(cf_name);
  4309. + if (cf_name[0] == '\0') {
  4310. + continue;
  4311. + }
  4312. +
  4313. + /* Prepend dest->root_dir to conffile name.
  4314. + Take pains to avoid multiple slashes. */
  4315. + root_dir = pkg->dest->root_dir;
  4316. + if (conf->offline_root)
  4317. + /* skip the offline_root prefix */
  4318. + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
  4319. + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
  4320. + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
  4321. +
  4322. + /* Can't get an md5sum now, (file isn't extracted yet).
  4323. + We'll wait until resolve_conffiles */
  4324. + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
  4325. +
  4326. + free(cf_name);
  4327. + free(cf_name_in_dest);
  4328. + }
  4329. +
  4330. + fclose(conffiles_file);
  4331. +
  4332. + return 0;
  4333. +}
  4334. +
  4335. +/* returns number of installed replacees */
  4336. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees)
  4337. +{
  4338. + abstract_pkg_t **replaces = pkg->replaces;
  4339. + int replaces_count = pkg->replaces_count;
  4340. + int i, j;
  4341. + for (i = 0; i < replaces_count; i++) {
  4342. + abstract_pkg_t *ab_pkg = replaces[i];
  4343. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  4344. + if (pkg_vec) {
  4345. + for (j = 0; j < pkg_vec->len; j++) {
  4346. + pkg_t *replacee = pkg_vec->pkgs[j];
  4347. + if (!pkg_conflicts(pkg, replacee))
  4348. + continue;
  4349. + if (replacee->state_status == SS_INSTALLED) {
  4350. + pkg_vec_insert(installed_replacees, replacee);
  4351. + }
  4352. + }
  4353. + }
  4354. + }
  4355. + return installed_replacees->len;
  4356. +}
  4357. +
  4358. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4359. +{
  4360. + int i;
  4361. + int replaces_count = replacees->len;
  4362. + for (i = 0; i < replaces_count; i++) {
  4363. + pkg_t *replacee = replacees->pkgs[i];
  4364. + int err;
  4365. + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
  4366. + err = ipkg_remove_pkg(conf, replacee,0);
  4367. + if (err)
  4368. + return err;
  4369. + }
  4370. + return 0;
  4371. +}
  4372. +
  4373. +/* to unwind the removal: make sure they are installed */
  4374. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4375. +{
  4376. + int i, err;
  4377. + int replaces_count = replacees->len;
  4378. + for (i = 0; i < replaces_count; i++) {
  4379. + pkg_t *replacee = replacees->pkgs[i];
  4380. + if (replacee->state_status != SS_INSTALLED) {
  4381. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4382. + err = ipkg_install_pkg(conf, replacee,0);
  4383. + if (err)
  4384. + return err;
  4385. + }
  4386. + }
  4387. + return 0;
  4388. +}
  4389. +
  4390. +int caught_sigint = 0;
  4391. +static void ipkg_install_pkg_sigint_handler(int sig)
  4392. +{
  4393. + caught_sigint = sig;
  4394. +}
  4395. +
  4396. +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
  4397. +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
  4398. +{
  4399. + if (old_pkg) {
  4400. + char message_out[15];
  4401. + char *old_version = pkg_version_str_alloc(old_pkg);
  4402. + char *new_version = pkg_version_str_alloc(pkg);
  4403. + int cmp = pkg_compare_versions(old_pkg, pkg);
  4404. + int rc = 0;
  4405. +
  4406. + memset(message_out,'\x0',15);
  4407. + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
  4408. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4409. + cmp = -1 ; /* then we force ipkg to downgrade */
  4410. + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
  4411. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4412. + }
  4413. +
  4414. + if (cmp > 0) {
  4415. + ipkg_message(conf, IPKG_NOTICE,
  4416. + "Not downgrading package %s on %s from %s to %s.\n",
  4417. + old_pkg->name, old_pkg->dest->name, old_version, new_version);
  4418. + rc = 1;
  4419. + } else if (cmp < 0) {
  4420. + ipkg_message(conf, IPKG_NOTICE,
  4421. + "%s%s on %s from %s to %s...\n",
  4422. + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
  4423. + pkg->dest = old_pkg->dest;
  4424. + rc = 0;
  4425. + } else /* cmp == 0 */ {
  4426. + if (conf->force_reinstall) {
  4427. + ipkg_message(conf, IPKG_NOTICE,
  4428. + "Reinstalling %s (%s) on %s...\n",
  4429. + pkg->name, new_version, old_pkg->dest->name);
  4430. + pkg->dest = old_pkg->dest;
  4431. + rc = 0;
  4432. + } else {
  4433. + ipkg_message(conf, IPKG_NOTICE,
  4434. + "Not installing %s (%s) on %s -- already installed.\n",
  4435. + pkg->name, new_version, old_pkg->dest->name);
  4436. + rc = 1;
  4437. + }
  4438. + }
  4439. + free(old_version);
  4440. + free(new_version);
  4441. + return rc;
  4442. + } else {
  4443. + char message_out[15], *version ;
  4444. + memset(message_out,'\x0',15);
  4445. + if ( message )
  4446. + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
  4447. + else
  4448. + strncpy( message_out,"Installing ",strlen("Installing ") );
  4449. + version = pkg_version_str_alloc(pkg);
  4450. +
  4451. + ipkg_message(conf, IPKG_NOTICE,
  4452. + "%s%s (%s) to %s...\n", message_out,
  4453. + pkg->name, version, pkg->dest->name);
  4454. + free(version);
  4455. + return 0;
  4456. + }
  4457. +}
  4458. +
  4459. +/* and now the meat... */
  4460. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
  4461. +{
  4462. + int err = 0;
  4463. + int message = 0;
  4464. + pkg_t *old_pkg = NULL;
  4465. + pkg_vec_t *replacees;
  4466. + abstract_pkg_t *ab_pkg = NULL;
  4467. + int old_state_flag;
  4468. + uint8_t *file_md5;
  4469. +
  4470. +
  4471. + if ( from_upgrade )
  4472. + message = 1; /* Coming from an upgrade, and should change the output message */
  4473. +
  4474. + if (!pkg) {
  4475. + ipkg_message(conf, IPKG_ERROR,
  4476. + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
  4477. + return -EINVAL;
  4478. + }
  4479. +
  4480. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
  4481. +
  4482. + if (!pkg_arch_supported(conf, pkg)) {
  4483. + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
  4484. + pkg->architecture, pkg->name);
  4485. + return -EINVAL;
  4486. + }
  4487. + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
  4488. + err = satisfy_dependencies_for(conf, pkg);
  4489. + if (err) { return err; }
  4490. +
  4491. + ipkg_message(conf, IPKG_NOTICE,
  4492. + "Package %s is already installed in %s.\n",
  4493. + pkg->name, pkg->dest->name);
  4494. + return 0;
  4495. + }
  4496. +
  4497. + if (pkg->dest == NULL) {
  4498. + pkg->dest = conf->default_dest;
  4499. + }
  4500. +
  4501. + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  4502. +
  4503. + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
  4504. + if (err) { return err; }
  4505. +
  4506. + pkg->state_want = SW_INSTALL;
  4507. + if (old_pkg){
  4508. + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
  4509. + }
  4510. +
  4511. +
  4512. + /* Abhaya: conflicts check */
  4513. + err = check_conflicts_for(conf, pkg);
  4514. + if (err) { return err; }
  4515. +
  4516. + /* this setup is to remove the upgrade scenario in the end when
  4517. + installing pkg A, A deps B & B deps on A. So both B and A are
  4518. + installed. Then A's installation is started resulting in an
  4519. + uncecessary upgrade */
  4520. + if (pkg->state_status == SS_INSTALLED
  4521. + && conf->force_reinstall == 0) return 0;
  4522. +
  4523. + err = verify_pkg_installable(conf, pkg);
  4524. + if (err) { return err; }
  4525. +
  4526. + if (pkg->local_filename == NULL) {
  4527. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  4528. + if (err) {
  4529. + ipkg_message(conf, IPKG_ERROR,
  4530. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  4531. + pkg->name);
  4532. + return err;
  4533. + }
  4534. + }
  4535. +
  4536. +/* Check for md5 values */
  4537. + if (pkg->md5sum)
  4538. + {
  4539. + file_md5 = file_md5sum_alloc(pkg->local_filename);
  4540. + if (strcmp((char *)file_md5, pkg->md5sum))
  4541. + {
  4542. + ipkg_message(conf, IPKG_ERROR,
  4543. + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
  4544. + pkg->name);
  4545. + free(file_md5);
  4546. + return err;
  4547. + }
  4548. + free(file_md5);
  4549. + }
  4550. +
  4551. + if (pkg->tmp_unpack_dir == NULL) {
  4552. + unpack_pkg_control_files(conf, pkg);
  4553. + }
  4554. +
  4555. + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
  4556. +/* Pigi: check if it will pass from here when replacing. It seems to fail */
  4557. +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
  4558. + err = update_file_ownership(conf, pkg, old_pkg);
  4559. + if (err) { return err; }
  4560. +
  4561. + if (conf->nodeps == 0) {
  4562. + err = satisfy_dependencies_for(conf, pkg);
  4563. + if (err) { return err; }
  4564. + }
  4565. +
  4566. + replacees = pkg_vec_alloc();
  4567. + pkg_get_installed_replacees(pkg, replacees);
  4568. +
  4569. + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
  4570. + {
  4571. + sigset_t newset, oldset;
  4572. + sighandler_t old_handler = NULL;
  4573. + int use_signal = 0;
  4574. + caught_sigint = 0;
  4575. + if (use_signal) {
  4576. + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
  4577. + } else {
  4578. + sigemptyset(&newset);
  4579. + sigaddset(&newset, SIGINT);
  4580. + sigprocmask(SIG_BLOCK, &newset, &oldset);
  4581. + }
  4582. +
  4583. + ipkg_state_changed++;
  4584. + pkg->state_flag |= SF_FILELIST_CHANGED;
  4585. +
  4586. + /* XXX: BUG: we really should treat replacement more like an upgrade
  4587. + * Instead, we're going to remove the replacees
  4588. + */
  4589. + err = pkg_remove_installed_replacees(conf, replacees);
  4590. + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
  4591. +
  4592. + /*
  4593. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  4594. + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
  4595. +
  4596. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  4597. + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
  4598. + */
  4599. +
  4600. + err = preinst_configure(conf, pkg, old_pkg);
  4601. + /*
  4602. + if (err) goto UNWIND_PREINST_CONFIGURE;
  4603. + */
  4604. +
  4605. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  4606. + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
  4607. +
  4608. + err = check_data_file_clashes(conf, pkg, old_pkg);
  4609. + /*
  4610. + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
  4611. +
  4612. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  4613. + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
  4614. + */
  4615. +
  4616. + if (conf->noaction) return 0;
  4617. +
  4618. + /* point of no return: no unwinding after this */
  4619. + if (old_pkg && !conf->force_reinstall) {
  4620. + old_pkg->state_want = SW_DEINSTALL;
  4621. +
  4622. + if (old_pkg->state_flag & SF_NOPRUNE) {
  4623. + ipkg_message(conf, IPKG_INFO,
  4624. + " not removing obsolesced files because package marked noprune\n");
  4625. + } else {
  4626. + ipkg_message(conf, IPKG_INFO,
  4627. + " removing obsolesced files\n");
  4628. + remove_obsolesced_files(conf, pkg, old_pkg);
  4629. + }
  4630. + /* removing files from old package, to avoid ghost files */
  4631. + remove_data_files_and_list(conf, old_pkg);
  4632. +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
  4633. + remove_maintainer_scripts_except_postrm(conf, old_pkg);
  4634. + remove_postrm(conf, old_pkg);
  4635. +/* Pigi */
  4636. +
  4637. + }
  4638. +
  4639. +
  4640. + ipkg_message(conf, IPKG_INFO,
  4641. + " installing maintainer scripts\n");
  4642. + install_maintainer_scripts(conf, pkg, old_pkg);
  4643. +
  4644. + /* the following just returns 0
  4645. + remove_disappeared(conf, pkg);
  4646. + */
  4647. +
  4648. + ipkg_message(conf, IPKG_INFO,
  4649. + " installing data files\n");
  4650. + install_data_files(conf, pkg);
  4651. +
  4652. +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
  4653. + err = check_data_file_clashes_change(conf, pkg);
  4654. +
  4655. + ipkg_message(conf, IPKG_INFO,
  4656. + " resolving conf files\n");
  4657. + resolve_conffiles(conf, pkg);
  4658. +
  4659. + pkg->state_status = SS_UNPACKED;
  4660. + old_state_flag = pkg->state_flag;
  4661. + pkg->state_flag &= ~SF_PREFER;
  4662. + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
  4663. +
  4664. + if (old_pkg && !conf->force_reinstall) {
  4665. + old_pkg->state_status = SS_NOT_INSTALLED;
  4666. + }
  4667. +
  4668. + time(&pkg->installed_time);
  4669. +
  4670. + ipkg_message(conf, IPKG_INFO,
  4671. + " cleanup temp files\n");
  4672. + cleanup_temporary_files(conf, pkg);
  4673. +
  4674. + ab_pkg = pkg->parent;
  4675. + if (ab_pkg)
  4676. + ab_pkg->state_status = pkg->state_status;
  4677. +
  4678. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  4679. +
  4680. + if (use_signal)
  4681. + signal(SIGINT, old_handler);
  4682. + else
  4683. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4684. +
  4685. + return 0;
  4686. +
  4687. +
  4688. + /*
  4689. + UNWIND_POSTRM_UPGRADE_OLD_PKG:
  4690. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4691. + UNWIND_CHECK_DATA_FILE_CLASHES:
  4692. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  4693. + */
  4694. + UNWIND_BACKUP_MODIFIED_CONFFILES:
  4695. + backup_modified_conffiles_unwind(pkg, old_pkg);
  4696. + /*
  4697. + UNWIND_PREINST_CONFIGURE:
  4698. + preinst_configure_unwind(conf, pkg, old_pkg);
  4699. + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
  4700. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  4701. + UNWIND_PRERM_UPGRADE_OLD_PKG:
  4702. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4703. + */
  4704. + UNWIND_REMOVE_INSTALLED_REPLACEES:
  4705. + pkg_remove_installed_replacees_unwind(conf, replacees);
  4706. +
  4707. + ipkg_message(conf, IPKG_INFO,
  4708. + " cleanup temp files\n");
  4709. + cleanup_temporary_files(conf, pkg);
  4710. +
  4711. + ipkg_message(conf, IPKG_INFO,
  4712. + "Failed.\n");
  4713. + if (use_signal)
  4714. + signal(SIGINT, old_handler);
  4715. + else
  4716. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4717. +
  4718. + return err;
  4719. + }
  4720. +}
  4721. +
  4722. +/*
  4723. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4724. +{
  4725. + DPKG_INCOMPATIBILITY:
  4726. + dpkg does some things here that we don't do yet. Do we care?
  4727. +
  4728. + 1. If a version of the package is already installed, call
  4729. + old-prerm upgrade new-version
  4730. + 2. If the script runs but exits with a non-zero exit status
  4731. + new-prerm failed-upgrade old-version
  4732. + Error unwind, for both the above cases:
  4733. + old-postinst abort-upgrade new-version
  4734. + return 0;
  4735. +}
  4736. +*/
  4737. +
  4738. +/*
  4739. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4740. +{
  4741. + DPKG_INCOMPATIBILITY:
  4742. + dpkg does some things here that we don't do yet. Do we care?
  4743. + (See prerm_upgrade_old_package for details)
  4744. +
  4745. + return 0;
  4746. +}
  4747. +*/
  4748. +
  4749. +/*
  4750. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4751. +{
  4752. + DPKG_INCOMPATIBILITY:
  4753. + dpkg does some things here that we don't do yet. Do we care?
  4754. + 2. If a 'conflicting' package is being removed at the same time:
  4755. + 1. If any packages depended on that conflicting package and
  4756. + --auto-deconfigure is specified, call, for each such package:
  4757. + deconfigured's-prerm deconfigure \
  4758. + in-favour package-being-installed version \
  4759. + removing conflicting-package version
  4760. + Error unwind:
  4761. + deconfigured's-postinst abort-deconfigure \
  4762. + in-favour package-being-installed-but-failed version \
  4763. + removing conflicting-package version
  4764. +
  4765. + The deconfigured packages are marked as requiring
  4766. + configuration, so that if --install is used they will be
  4767. + configured again if possible.
  4768. + 2. To prepare for removal of the conflicting package, call:
  4769. + conflictor's-prerm remove in-favour package new-version
  4770. + Error unwind:
  4771. + conflictor's-postinst abort-remove in-favour package new-version
  4772. + return 0;
  4773. +}
  4774. +*/
  4775. +
  4776. +/*
  4777. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4778. +{
  4779. + DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
  4780. + do yet. Do we care? (See prerm_deconfigure_conflictors for
  4781. + details)
  4782. + return 0;
  4783. +}
  4784. +*/
  4785. +
  4786. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4787. +{
  4788. + int err;
  4789. + char *preinst_args;
  4790. +
  4791. + if (old_pkg) {
  4792. + char *old_version = pkg_version_str_alloc(old_pkg);
  4793. + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
  4794. + free(old_version);
  4795. + } else if (pkg->state_status == SS_CONFIG_FILES) {
  4796. + char *pkg_version = pkg_version_str_alloc(pkg);
  4797. + sprintf_alloc(&preinst_args, "install %s", pkg_version);
  4798. + free(pkg_version);
  4799. + } else {
  4800. + preinst_args = strdup("install");
  4801. + }
  4802. +
  4803. + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
  4804. + if (err) {
  4805. + ipkg_message(conf, IPKG_ERROR,
  4806. + "Aborting installation of %s\n", pkg->name);
  4807. + return 1;
  4808. + }
  4809. +
  4810. + free(preinst_args);
  4811. +
  4812. + return 0;
  4813. +}
  4814. +
  4815. +/*
  4816. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4817. +{
  4818. + DPKG_INCOMPATIBILITY:
  4819. + dpkg does the following error unwind, should we?
  4820. + pkg->postrm abort-upgrade old-version
  4821. + OR pkg->postrm abort-install old-version
  4822. + OR pkg->postrm abort-install
  4823. + return 0;
  4824. +}
  4825. +*/
  4826. +
  4827. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4828. +{
  4829. + int err;
  4830. + conffile_list_elt_t *iter;
  4831. + conffile_t *cf;
  4832. +
  4833. + if (conf->noaction) return 0;
  4834. +
  4835. + /* Backup all modified conffiles */
  4836. + if (old_pkg) {
  4837. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4838. + char *cf_name;
  4839. +
  4840. + cf = iter->data;
  4841. + cf_name = root_filename_alloc(conf, cf->name);
  4842. +
  4843. + /* Don't worry if the conffile is just plain gone */
  4844. + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
  4845. + err = backup_make_backup(conf, cf_name);
  4846. + if (err) {
  4847. + return err;
  4848. + }
  4849. + }
  4850. + free(cf_name);
  4851. + }
  4852. + }
  4853. +
  4854. + /* Backup all conffiles that were not conffiles in old_pkg */
  4855. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4856. + char *cf_name;
  4857. + cf = iter->data;
  4858. + cf_name = root_filename_alloc(conf, cf->name);
  4859. + /* Ignore if this was a conffile in old_pkg as well */
  4860. + if (pkg_get_conffile(old_pkg, cf->name)) {
  4861. + continue;
  4862. + }
  4863. +
  4864. + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
  4865. + err = backup_make_backup(conf, cf_name);
  4866. + if (err) {
  4867. + return err;
  4868. + }
  4869. + }
  4870. + free(cf_name);
  4871. + }
  4872. +
  4873. + return 0;
  4874. +}
  4875. +
  4876. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg)
  4877. +{
  4878. + conffile_list_elt_t *iter;
  4879. +
  4880. + if (old_pkg) {
  4881. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4882. + backup_remove(iter->data->name);
  4883. + }
  4884. + }
  4885. +
  4886. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4887. + backup_remove(iter->data->name);
  4888. + }
  4889. +
  4890. + return 0;
  4891. +}
  4892. +
  4893. +
  4894. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4895. +{
  4896. + /* DPKG_INCOMPATIBILITY:
  4897. + ipkg takes a slightly different approach than dpkg at this
  4898. + point. dpkg installs each file in the new package while
  4899. + creating a backup for any file that is replaced, (so that it
  4900. + can unwind if necessary). To avoid complexity and redundant
  4901. + storage, ipkg doesn't do any installation until later, (at the
  4902. + point at which dpkg removes the backups.
  4903. +
  4904. + But, we do have to check for data file clashes, since after
  4905. + installing a package with a file clash, removing either of the
  4906. + packages involved in the clash has the potential to break the
  4907. + other package.
  4908. + */
  4909. + str_list_t *files_list;
  4910. + str_list_elt_t *iter;
  4911. +
  4912. + int clashes = 0;
  4913. +
  4914. + files_list = pkg_get_installed_files(pkg);
  4915. + for (iter = files_list->head; iter; iter = iter->next) {
  4916. + char *root_filename;
  4917. + char *filename = iter->data;
  4918. + root_filename = root_filename_alloc(conf, filename);
  4919. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  4920. + pkg_t *owner;
  4921. + pkg_t *obs;
  4922. + /* Pre-existing conffiles are OK */
  4923. + /* @@@@ should have way to check that it is a conffile -Jamey */
  4924. + if (backup_exists_for(root_filename)) {
  4925. + continue;
  4926. + }
  4927. +
  4928. + /* Pre-existing files are OK if force-overwrite was asserted. */
  4929. + if (conf->force_overwrite) {
  4930. + /* but we need to change who owns this file */
  4931. + file_hash_set_file_owner(conf, filename, pkg);
  4932. + continue;
  4933. + }
  4934. +
  4935. + owner = file_hash_get_file_owner(conf, filename);
  4936. +
  4937. + /* Pre-existing files are OK if owned by the pkg being upgraded. */
  4938. + if (owner && old_pkg) {
  4939. + if (strcmp(owner->name, old_pkg->name) == 0) {
  4940. + continue;
  4941. + }
  4942. + }
  4943. +
  4944. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  4945. + if (owner) {
  4946. + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
  4947. + if (pkg_replaces(pkg, owner)) {
  4948. + continue;
  4949. + }
  4950. +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
  4951. + then it's ok to overwrite. */
  4952. + if (strcmp(owner->name,pkg->name)==0){
  4953. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  4954. + continue;
  4955. + }
  4956. + }
  4957. +
  4958. + /* Pre-existing files are OK if they are obsolete */
  4959. + obs = hash_table_get(&conf->obs_file_hash, filename);
  4960. + if (obs) {
  4961. + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
  4962. + continue;
  4963. + }
  4964. +
  4965. + /* We have found a clash. */
  4966. + ipkg_message(conf, IPKG_ERROR,
  4967. + "Package %s wants to install file %s\n"
  4968. + "\tBut that file is already provided by package ",
  4969. + pkg->name, filename);
  4970. + if (owner) {
  4971. + ipkg_message(conf, IPKG_ERROR,
  4972. + "%s\n", owner->name);
  4973. + } else {
  4974. + ipkg_message(conf, IPKG_ERROR,
  4975. + "<no package>\nPlease move this file out of the way and try again.\n");
  4976. + }
  4977. + clashes++;
  4978. + }
  4979. + free(root_filename);
  4980. + }
  4981. + pkg_free_installed_files(pkg);
  4982. +
  4983. + return clashes;
  4984. +}
  4985. +
  4986. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg)
  4987. +{
  4988. + /* Basically that's the worst hack I could do to be able to change ownership of
  4989. + file list, but, being that we have no way to unwind the mods, due to structure
  4990. + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
  4991. + What we do here is change the ownership of file in hash if a replace ( or similar events
  4992. + happens )
  4993. + Only the action that are needed to change name should be considered.
  4994. + @@@ To change after 1.0 release.
  4995. + */
  4996. + str_list_t *files_list;
  4997. + str_list_elt_t *iter;
  4998. +
  4999. + int clashes = 0;
  5000. +
  5001. + files_list = pkg_get_installed_files(pkg);
  5002. + for (iter = files_list->head; iter; iter = iter->next) {
  5003. + char *root_filename;
  5004. + char *filename = iter->data;
  5005. + root_filename = root_filename_alloc(conf, filename);
  5006. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5007. + pkg_t *owner;
  5008. +
  5009. + if (conf->force_overwrite) {
  5010. + /* but we need to change who owns this file */
  5011. + file_hash_set_file_owner(conf, filename, pkg);
  5012. + continue;
  5013. + }
  5014. +
  5015. + owner = file_hash_get_file_owner(conf, filename);
  5016. +
  5017. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5018. + if (owner) {
  5019. + if (pkg_replaces(pkg, owner)) {
  5020. +/* It's now time to change the owner of that file.
  5021. + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
  5022. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5023. + file_hash_set_file_owner(conf, filename, pkg);
  5024. + continue;
  5025. + }
  5026. + }
  5027. +
  5028. + }
  5029. + free(root_filename);
  5030. + }
  5031. + pkg_free_installed_files(pkg);
  5032. +
  5033. + return clashes;
  5034. +}
  5035. +
  5036. +/*
  5037. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5038. +{
  5039. + Nothing to do since check_data_file_clashes doesn't change state
  5040. + return 0;
  5041. +}
  5042. +*/
  5043. +
  5044. +/*
  5045. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5046. +{
  5047. + DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
  5048. + 1. If the package is being upgraded, call
  5049. + old-postrm upgrade new-version
  5050. + 2. If this fails, attempt:
  5051. + new-postrm failed-upgrade old-version
  5052. + Error unwind, for both cases:
  5053. + old-preinst abort-upgrade new-version
  5054. + return 0;
  5055. +}
  5056. +*/
  5057. +
  5058. +/*
  5059. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5060. +{
  5061. + DPKG_INCOMPATIBILITY:
  5062. + dpkg does some things here that we don't do yet. Do we care?
  5063. + (See postrm_upgrade_old_pkg for details)
  5064. + return 0;
  5065. +}
  5066. +*/
  5067. +
  5068. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5069. +{
  5070. + int err;
  5071. + str_list_t *old_files;
  5072. + str_list_elt_t *of;
  5073. + str_list_t *new_files;
  5074. + str_list_elt_t *nf;
  5075. +
  5076. + if (old_pkg == NULL) {
  5077. + return 0;
  5078. + }
  5079. +
  5080. + old_files = pkg_get_installed_files(old_pkg);
  5081. + new_files = pkg_get_installed_files(pkg);
  5082. +
  5083. + for (of = old_files->head; of; of = of->next) {
  5084. + pkg_t *owner;
  5085. + char *old, *new;
  5086. + old = of->data;
  5087. + for (nf = new_files->head; nf; nf = nf->next) {
  5088. + new = nf->data;
  5089. + if (strcmp(old, new) == 0) {
  5090. + goto NOT_OBSOLETE;
  5091. + }
  5092. + }
  5093. + if (file_is_dir(old)) {
  5094. + continue;
  5095. + }
  5096. + owner = file_hash_get_file_owner(conf, old);
  5097. + if (owner != old_pkg) {
  5098. + /* in case obsolete file no longer belongs to old_pkg */
  5099. + continue;
  5100. + }
  5101. +
  5102. + /* old file is obsolete */
  5103. + ipkg_message(conf, IPKG_INFO,
  5104. + " removing obsolete file %s\n", old);
  5105. + if (!conf->noaction) {
  5106. + err = unlink(old);
  5107. + if (err) {
  5108. + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
  5109. + strerror(errno));
  5110. + }
  5111. + }
  5112. +
  5113. + NOT_OBSOLETE:
  5114. + ;
  5115. + }
  5116. +
  5117. + pkg_free_installed_files(old_pkg);
  5118. + pkg_free_installed_files(pkg);
  5119. +
  5120. + return 0;
  5121. +}
  5122. +
  5123. +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5124. +{
  5125. + int i;
  5126. + int err = 0;
  5127. + char *globpattern;
  5128. + glob_t globbuf;
  5129. + if (0) {
  5130. + if (!pkg->dest) {
  5131. + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
  5132. + return -1;
  5133. + }
  5134. + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
  5135. + err = glob(globpattern, 0, NULL, &globbuf);
  5136. + free(globpattern);
  5137. + if (err) {
  5138. + return err;
  5139. + }
  5140. + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
  5141. + for (i = 0; i < globbuf.gl_pathc; i++) {
  5142. + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
  5143. + globbuf.gl_pathv[i], old_pkg->name);
  5144. + if (!conf->noaction)
  5145. + unlink(globbuf.gl_pathv[i]);
  5146. + }
  5147. + globfree(&globbuf);
  5148. + }
  5149. + return err;
  5150. +}
  5151. +
  5152. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5153. +{
  5154. + int ret;
  5155. + char *prefix;
  5156. +
  5157. + if (old_pkg)
  5158. + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
  5159. + sprintf_alloc(&prefix, "%s.", pkg->name);
  5160. + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
  5161. + pkg->dest->info_dir,
  5162. + prefix);
  5163. + free(prefix);
  5164. + return ret;
  5165. +}
  5166. +
  5167. +/*
  5168. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
  5169. +{
  5170. + DPKG_INCOMPATIBILITY:
  5171. + This is a fairly sophisticated dpkg operation. Shall we
  5172. + skip it?
  5173. +
  5174. + Any packages all of whose files have been overwritten during the
  5175. + installation, and which aren't required for dependencies, are
  5176. + considered to have been removed. For each such package
  5177. + 1. disappearer's-postrm disappear overwriter overwriter-version
  5178. + 2. The package's maintainer scripts are removed
  5179. + 3. It is noted in the status database as being in a sane state,
  5180. + namely not installed (any conffiles it may have are ignored,
  5181. + rather than being removed by dpkg). Note that disappearing
  5182. + packages do not have their prerm called, because dpkg doesn't
  5183. + know in advance that the package is going to vanish.
  5184. +
  5185. +
  5186. + return 0;
  5187. +}
  5188. +*/
  5189. +
  5190. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
  5191. +{
  5192. + int err;
  5193. +
  5194. + /* ipkg takes a slightly different approach to data file backups
  5195. + than dpkg. Rather than removing backups at this point, we
  5196. + actually do the data file installation now. See comments in
  5197. + check_data_file_clashes() for more details. */
  5198. +
  5199. + ipkg_message(conf, IPKG_INFO,
  5200. + " extracting data files to %s\n", pkg->dest->root_dir);
  5201. + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
  5202. + if (err) {
  5203. + return err;
  5204. + }
  5205. +
  5206. + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
  5207. + so we can't save ourself from removing important packages
  5208. + At this point we (should) have extracted the .control file, so it
  5209. + would be a good idea to reload the data in it, and set the Essential
  5210. + state in *pkg. From now on the Essential is back in status file and
  5211. + we can protect again.
  5212. + We should operate this way:
  5213. + fopen the file ( pkg->dest->root_dir/pkg->name.control )
  5214. + check for "Essential" in it
  5215. + set the value in pkg->essential.
  5216. + This new routine could be useful also for every other flag
  5217. + Pigi: 16/03/2004 */
  5218. + set_flags_from_control(conf, pkg) ;
  5219. +
  5220. + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
  5221. + err = pkg_write_filelist(conf, pkg);
  5222. + if (err)
  5223. + return err;
  5224. +
  5225. + /* XXX: FEATURE: ipkg should identify any files which existed
  5226. + before installation and which were overwritten, (see
  5227. + check_data_file_clashes()). What it must do is remove any such
  5228. + files from the filelist of the old package which provided the
  5229. + file. Otherwise, if the old package were removed at some point
  5230. + it would break the new package. Removing the new package will
  5231. + also break the old one, but this cannot be helped since the old
  5232. + package's file has already been deleted. This is the importance
  5233. + of check_data_file_clashes(), and only allowing ipkg to install
  5234. + a clashing package with a user force. */
  5235. +
  5236. + return 0;
  5237. +}
  5238. +
  5239. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
  5240. +{
  5241. + conffile_list_elt_t *iter;
  5242. + conffile_t *cf;
  5243. + char *cf_backup;
  5244. + uint8_t *md5sum;
  5245. +
  5246. +
  5247. + if (conf->noaction) return 0;
  5248. +
  5249. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  5250. + char *root_filename;
  5251. + cf = iter->data;
  5252. + root_filename = root_filename_alloc(conf, cf->name);
  5253. +
  5254. + /* Might need to initialize the md5sum for each conffile */
  5255. + if (cf->value == NULL) {
  5256. + cf->value = (char *)file_md5sum_alloc(root_filename);
  5257. + }
  5258. +
  5259. + if (!file_exists(root_filename)) {
  5260. + free(root_filename);
  5261. + continue;
  5262. + }
  5263. +
  5264. + cf_backup = backup_filename_alloc(root_filename);
  5265. +
  5266. +
  5267. + if (file_exists(cf_backup)) {
  5268. + /* Let's compute md5 to test if files are changed */
  5269. + md5sum = file_md5sum_alloc(cf_backup);
  5270. + if (strcmp( cf->value, (char *)md5sum) != 0 ) {
  5271. + if (conf->force_defaults
  5272. + || user_prefers_old_conffile(cf->name, cf_backup) ) {
  5273. + rename(cf_backup, root_filename);
  5274. + }
  5275. + }
  5276. + unlink(cf_backup);
  5277. + free(md5sum);
  5278. + }
  5279. +
  5280. + free(cf_backup);
  5281. + free(root_filename);
  5282. + }
  5283. +
  5284. + return 0;
  5285. +}
  5286. +
  5287. +static int user_prefers_old_conffile(const char *file_name, const char *backup)
  5288. +{
  5289. + char *response;
  5290. + const char *short_file_name;
  5291. +
  5292. + short_file_name = strrchr(file_name, '/');
  5293. + if (short_file_name) {
  5294. + short_file_name++;
  5295. + } else {
  5296. + short_file_name = file_name;
  5297. + }
  5298. +
  5299. + while (1) {
  5300. + response = get_user_response(" Configuration file '%s'\n"
  5301. + " ==> File on system created by you or by a script.\n"
  5302. + " ==> File also in package provided by package maintainer.\n"
  5303. + " What would you like to do about it ? Your options are:\n"
  5304. + " Y or I : install the package maintainer's version\n"
  5305. + " N or O : keep your currently-installed version\n"
  5306. +#ifdef CONFIG_DIFF
  5307. + " D : show the differences between the versions\n"
  5308. +#endif
  5309. + " The default action is to keep your current version.\n"
  5310. + " *** %s (Y/I/N/O"
  5311. +#ifdef CONFIG_DIFF
  5312. + "/D"
  5313. +#endif
  5314. + ") [default=N] ? ", file_name, short_file_name);
  5315. + if (strcmp(response, "y") == 0
  5316. + || strcmp(response, "i") == 0
  5317. + || strcmp(response, "yes") == 0) {
  5318. + free(response);
  5319. + return 0;
  5320. + }
  5321. +
  5322. +#ifdef CONFIG_DIFF
  5323. + if (strcmp(response, "d") == 0) {
  5324. + char *cmd;
  5325. +
  5326. + free(response);
  5327. + /* XXX: BUG rewrite to use exec or busybox's internal diff */
  5328. + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
  5329. + xsystem(cmd);
  5330. + free(cmd);
  5331. + printf(" [Press ENTER to continue]\n");
  5332. + response = file_read_line_alloc(stdin);
  5333. + free(response);
  5334. + continue;
  5335. + }
  5336. +#endif
  5337. +
  5338. + free(response);
  5339. + return 1;
  5340. + }
  5341. +}
  5342. +
  5343. +/* XXX: CLEANUP: I'd like to move all of the code for
  5344. + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
  5345. + it would make sense to cleanup pkg->tmp_unpack_dir directly from
  5346. + pkg_deinit for example). */
  5347. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
  5348. +{
  5349. + DIR *tmp_dir;
  5350. + struct dirent *dirent;
  5351. + char *tmp_file;
  5352. +
  5353. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  5354. +#error
  5355. + ipkg_message(conf, IPKG_DEBUG,
  5356. + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  5357. + __FUNCTION__, pkg->tmp_unpack_dir);
  5358. + return 0;
  5359. +#endif
  5360. +
  5361. + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
  5362. + tmp_dir = opendir(pkg->tmp_unpack_dir);
  5363. + if (tmp_dir) {
  5364. + while (1) {
  5365. + dirent = readdir(tmp_dir);
  5366. + if (dirent == NULL) {
  5367. + break;
  5368. + }
  5369. + sprintf_alloc(&tmp_file, "%s/%s",
  5370. + pkg->tmp_unpack_dir, dirent->d_name);
  5371. + if (! file_is_dir(tmp_file)) {
  5372. + unlink(tmp_file);
  5373. + }
  5374. + free(tmp_file);
  5375. + }
  5376. + closedir(tmp_dir);
  5377. + rmdir(pkg->tmp_unpack_dir);
  5378. + free(pkg->tmp_unpack_dir);
  5379. + pkg->tmp_unpack_dir = NULL;
  5380. + }
  5381. + }
  5382. +
  5383. + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
  5384. + pkg->name, pkg->local_filename, conf->tmp_dir);
  5385. + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
  5386. + unlink(pkg->local_filename);
  5387. + free(pkg->local_filename);
  5388. + pkg->local_filename = NULL;
  5389. + }
  5390. +
  5391. + return 0;
  5392. +}
  5393. +
  5394. +static char *backup_filename_alloc(const char *file_name)
  5395. +{
  5396. + char *backup;
  5397. +
  5398. + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
  5399. +
  5400. + return backup;
  5401. +}
  5402. +
  5403. +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
  5404. +{
  5405. + int err;
  5406. + char *backup;
  5407. +
  5408. + backup = backup_filename_alloc(file_name);
  5409. + err = file_copy(file_name, backup);
  5410. + if (err) {
  5411. + ipkg_message(conf, IPKG_ERROR,
  5412. + "%s: Failed to copy %s to %s\n",
  5413. + __FUNCTION__, file_name, backup);
  5414. + }
  5415. +
  5416. + free(backup);
  5417. +
  5418. + return err;
  5419. +}
  5420. +
  5421. +static int backup_exists_for(const char *file_name)
  5422. +{
  5423. + int ret;
  5424. + char *backup;
  5425. +
  5426. + backup = backup_filename_alloc(file_name);
  5427. +
  5428. + ret = file_exists(backup);
  5429. +
  5430. + free(backup);
  5431. +
  5432. + return ret;
  5433. +}
  5434. +
  5435. +static int backup_remove(const char *file_name)
  5436. +{
  5437. + char *backup;
  5438. +
  5439. + backup = backup_filename_alloc(file_name);
  5440. + unlink(backup);
  5441. + free(backup);
  5442. +
  5443. + return 0;
  5444. +}
  5445. +
  5446. +
  5447. +
  5448. +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
  5449. +
  5450. +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
  5451. +{
  5452. + /* first, remove the packages that need removing */
  5453. + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
  5454. + pkg_t *pkg = pkgs_to_remove->pkgs[i];
  5455. + err = ipkg_remove_pkg(conf, pkg,0);
  5456. + if (err) return err;
  5457. + }
  5458. + return 0;
  5459. +}
  5460. +
  5461. +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)
  5462. +{
  5463. + int i;
  5464. + /* now one more pass checking on the ones that need to be installed */
  5465. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5466. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5467. + if (pkg->dest == NULL)
  5468. + pkg->dest = conf->default_dest;
  5469. +
  5470. + pkg->state_want = SW_INSTALL;
  5471. +
  5472. + /* Abhaya: conflicts check */
  5473. + err = check_conflicts_for(conf, pkg);
  5474. + if (err) { return err; }
  5475. + }
  5476. + return 0;
  5477. +}
  5478. +
  5479. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5480. +{
  5481. + int i;
  5482. + /* now one more pass checking on the ones that need to be installed */
  5483. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5484. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5485. +
  5486. + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
  5487. + pkg_vec_t *replacees = pkg_vec_alloc();
  5488. + pkg_get_installed_replacees(pkg, replacees);
  5489. +
  5490. + /* XXX: BUG: we really should treat replacement more like an upgrade
  5491. + * Instead, we're going to remove the replacees
  5492. + */
  5493. + err = pkg_remove_installed_replacees(conf, replacees);
  5494. + if (err) return err;
  5495. + pkg->state_flag |= SF_REMOVED_REPLACEES;
  5496. + }
  5497. + return 0;
  5498. +}
  5499. +
  5500. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5501. +{
  5502. + int i;
  5503. + /* now one more pass checking on the ones that need to be installed */
  5504. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5505. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5506. + if (pkg->local_filename == NULL) {
  5507. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  5508. + if (err) {
  5509. + ipkg_message(conf, IPKG_ERROR,
  5510. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  5511. + pkg->name);
  5512. + return err;
  5513. + }
  5514. + }
  5515. + if (pkg->tmp_unpack_dir == NULL) {
  5516. + err = unpack_pkg_control_files(conf, pkg);
  5517. + if (err) return err;
  5518. + }
  5519. + }
  5520. + return 0;
  5521. +}
  5522. +
  5523. +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5524. +{
  5525. + int i;
  5526. + /* now one more pass checking on the ones that need to be installed */
  5527. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5528. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5529. + pkg_t *old_pkg = pkg->old_pkg;
  5530. +
  5531. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  5532. + if (err) return err;
  5533. +
  5534. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  5535. + if (err) return err;
  5536. +
  5537. + err = preinst_configure(conf, pkg, old_pkg);
  5538. + if (err) return err;
  5539. +
  5540. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  5541. + if (err) return err;
  5542. +
  5543. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  5544. + if (err) return err;
  5545. + }
  5546. + return 0;
  5547. +}
  5548. +
  5549. +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5550. +{
  5551. + int i;
  5552. + /* now one more pass checking on the ones that need to be installed */
  5553. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5554. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5555. + pkg_t *old_pkg = pkg->old_pkg;
  5556. +
  5557. + if (old_pkg) {
  5558. + old_pkg->state_want = SW_DEINSTALL;
  5559. +
  5560. + if (old_pkg->state_flag & SF_NOPRUNE) {
  5561. + ipkg_message(conf, IPKG_INFO,
  5562. + " not removing obsolesced files because package marked noprune\n");
  5563. + } else {
  5564. + ipkg_message(conf, IPKG_INFO,
  5565. + " removing obsolesced files\n");
  5566. + remove_obsolesced_files(conf, pkg, old_pkg);
  5567. + }
  5568. + }
  5569. +
  5570. + ipkg_message(conf, IPKG_INFO,
  5571. + " installing maintainer scripts\n");
  5572. + install_maintainer_scripts(conf, pkg, old_pkg);
  5573. +
  5574. + /* the following just returns 0 */
  5575. + remove_disappeared(conf, pkg);
  5576. +
  5577. + ipkg_message(conf, IPKG_INFO,
  5578. + " installing data files\n");
  5579. + install_data_files(conf, pkg);
  5580. +
  5581. + ipkg_message(conf, IPKG_INFO,
  5582. + " resolving conf files\n");
  5583. + resolve_conffiles(conf, pkg);
  5584. +
  5585. + pkg->state_status = SS_UNPACKED;
  5586. +
  5587. + if (old_pkg) {
  5588. + old_pkg->state_status = SS_NOT_INSTALLED;
  5589. + }
  5590. +
  5591. + time(&pkg->installed_time);
  5592. +
  5593. + ipkg_message(conf, IPKG_INFO,
  5594. + " cleanup temp files\n");
  5595. + cleanup_temporary_files(conf, pkg);
  5596. +
  5597. + if (pkg->parent)
  5598. + pkg->parent->state_status = pkg->state_status;
  5599. + }
  5600. + return 0;
  5601. +}
  5602. +
  5603. +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5604. +{
  5605. + int i;
  5606. + /* now one more pass checking on the ones that need to be installed */
  5607. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5608. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5609. + pkg_t *old_pkg = pkg->old_pkg;
  5610. +
  5611. + if (old_pkg) {
  5612. + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
  5613. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5614. + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
  5615. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  5616. + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
  5617. + backup_modified_conffiles_unwind(pkg, old_pkg);
  5618. + */
  5619. + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
  5620. + preinst_configure_unwind(conf, pkg, old_pkg);
  5621. + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
  5622. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  5623. + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
  5624. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5625. + */
  5626. +
  5627. + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
  5628. + remove_installed_replacees_unwind(conf, pkg, old_pkg);
  5629. +
  5630. + }
  5631. + }
  5632. + return 0;
  5633. +}
  5634. +
  5635. +/*
  5636. + * Perform all the actions.
  5637. + *
  5638. + * pkgs_to_remove are packages marked for removal.
  5639. + * pkgs_superseded are the old packages being replaced by upgrades.
  5640. + *
  5641. + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
  5642. + */
  5643. +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)
  5644. +{
  5645. + int err;
  5646. + int i;
  5647. +
  5648. + err = ipkg_remove_packages(conf, pkgs_to_remove);
  5649. + if (err) return err;
  5650. +
  5651. + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
  5652. + if (err) return err;
  5653. +
  5654. + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
  5655. + if (err) goto UNWIND;
  5656. +
  5657. + /* @@@@ look at ipkg_install_pkg for handling replacements */
  5658. + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
  5659. + if (err) goto UNWIND;
  5660. +
  5661. + /*
  5662. + * Now that we have the packages unpacked, we can look for data
  5663. + * file clashes. First, we mark the files from the superseded
  5664. + * packages as obsolete. Then we scan the files in
  5665. + * pkgs_to_install, and only complain about clashes with
  5666. + * non-obsolete files.
  5667. + */
  5668. +
  5669. + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
  5670. + if (err) goto UNWIND;
  5671. +
  5672. + /* this was before checking data file clashes */
  5673. + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
  5674. + if (err) goto UNWIND;
  5675. +
  5676. + /* point of no return: no unwinding after this */
  5677. + err = ipkg_process_actions_install(conf, pkgs_to_install);
  5678. + if (err) return err;
  5679. +
  5680. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  5681. + return 0;
  5682. +
  5683. + UNWIND:
  5684. + ipkg_process_actions_unwind(conf, pkgs_to_install);
  5685. +
  5686. + ipkg_message(conf, IPKG_INFO,
  5687. + " cleanup temp files\n");
  5688. + cleanup_temporary_files(conf, pkg);
  5689. +
  5690. + ipkg_message(conf, IPKG_INFO,
  5691. + "Failed.\n");
  5692. + return err;
  5693. +}
  5694. +
  5695. +#endif
  5696. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_install.h busybox-1.17.0/archival/libipkg/ipkg_install.h
  5697. --- busybox-1.17.0.orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
  5698. +++ busybox-1.17.0/archival/libipkg/ipkg_install.h 2010-07-08 12:01:56.219000332 +0200
  5699. @@ -0,0 +1,35 @@
  5700. +/* ipkg_install.h - the itsy package management system
  5701. +
  5702. + Carl D. Worth
  5703. +
  5704. + Copyright (C) 2001 University of Southern California
  5705. +
  5706. + This program is free software; you can redistribute it and/or
  5707. + modify it under the terms of the GNU General Public License as
  5708. + published by the Free Software Foundation; either version 2, or (at
  5709. + your option) any later version.
  5710. +
  5711. + This program is distributed in the hope that it will be useful, but
  5712. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5713. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5714. + General Public License for more details.
  5715. +*/
  5716. +
  5717. +#ifndef IPKG_INSTALL_H
  5718. +#define IPKG_INSTALL_H
  5719. +
  5720. +#include "pkg.h"
  5721. +#include "ipkg_conf.h"
  5722. +
  5723. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5724. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5725. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
  5726. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
  5727. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  5728. +
  5729. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
  5730. +
  5731. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
  5732. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
  5733. +
  5734. +#endif
  5735. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_message.c busybox-1.17.0/archival/libipkg/ipkg_message.c
  5736. --- busybox-1.17.0.orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
  5737. +++ busybox-1.17.0/archival/libipkg/ipkg_message.c 2010-07-08 12:01:56.219000332 +0200
  5738. @@ -0,0 +1,35 @@
  5739. +/* ipkg_message.c - the itsy package management system
  5740. +
  5741. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5742. +
  5743. + This program is free software; you can redistribute it and/or
  5744. + modify it under the terms of the GNU General Public License as
  5745. + published by the Free Software Foundation; either version 2, or (at
  5746. + your option) any later version.
  5747. +
  5748. + This program is distributed in the hope that it will be useful, but
  5749. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5750. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5751. + General Public License for more details.
  5752. +*/
  5753. +
  5754. +
  5755. +#include "ipkg.h"
  5756. +#include "ipkg_conf.h"
  5757. +#include "ipkg_message.h"
  5758. +#include "libipkg.h"
  5759. +
  5760. +void
  5761. +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
  5762. +{
  5763. + va_list ap;
  5764. + char ts[256];
  5765. +
  5766. + if (ipkg_cb_message)
  5767. + {
  5768. + va_start (ap, fmt);
  5769. + vsnprintf (ts,256,fmt, ap);
  5770. + va_end (ap);
  5771. + ipkg_cb_message(conf,level,ts);
  5772. + }
  5773. +}
  5774. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_message.h busybox-1.17.0/archival/libipkg/ipkg_message.h
  5775. --- busybox-1.17.0.orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
  5776. +++ busybox-1.17.0/archival/libipkg/ipkg_message.h 2010-07-08 12:01:56.219000332 +0200
  5777. @@ -0,0 +1,32 @@
  5778. +/* ipkg_message.h - the itsy package management system
  5779. +
  5780. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5781. +
  5782. + This program is free software; you can redistribute it and/or
  5783. + modify it under the terms of the GNU General Public License as
  5784. + published by the Free Software Foundation; either version 2, or (at
  5785. + your option) any later version.
  5786. +
  5787. + This program is distributed in the hope that it will be useful, but
  5788. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5789. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5790. + General Public License for more details.
  5791. +*/
  5792. +
  5793. +#ifndef _IPKG_MESSAGE_H_
  5794. +#define _IPKG_MESSAGE_H_
  5795. +
  5796. +#include "ipkg.h"
  5797. +#include "ipkg_conf.h"
  5798. +
  5799. +typedef enum {
  5800. + IPKG_ERROR, /* error conditions */
  5801. + IPKG_NOTICE, /* normal but significant condition */
  5802. + IPKG_INFO, /* informational message */
  5803. + IPKG_DEBUG, /* debug level message */
  5804. + IPKG_DEBUG2, /* more debug level message */
  5805. +} message_level_t;
  5806. +
  5807. +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
  5808. +
  5809. +#endif /* _IPKG_MESSAGE_H_ */
  5810. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_remove.c busybox-1.17.0/archival/libipkg/ipkg_remove.c
  5811. --- busybox-1.17.0.orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
  5812. +++ busybox-1.17.0/archival/libipkg/ipkg_remove.c 2010-07-08 12:01:56.219000332 +0200
  5813. @@ -0,0 +1,385 @@
  5814. +/* ipkg_remove.c - the itsy package management system
  5815. +
  5816. + Carl D. Worth
  5817. +
  5818. + Copyright (C) 2001 University of Southern California
  5819. +
  5820. + This program is free software; you can redistribute it and/or
  5821. + modify it under the terms of the GNU General Public License as
  5822. + published by the Free Software Foundation; either version 2, or (at
  5823. + your option) any later version.
  5824. +
  5825. + This program is distributed in the hope that it will be useful, but
  5826. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5827. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5828. + General Public License for more details.
  5829. +*/
  5830. +
  5831. +#include "ipkg.h"
  5832. +#include "ipkg_message.h"
  5833. +
  5834. +#include <glob.h>
  5835. +
  5836. +#include "ipkg_remove.h"
  5837. +
  5838. +#include "file_util.h"
  5839. +#include "sprintf_alloc.h"
  5840. +#include "str_util.h"
  5841. +
  5842. +#include "ipkg_cmd.h"
  5843. +
  5844. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents);
  5845. +
  5846. +/*
  5847. + * Returns number of the number of packages depending on the packages provided by this package.
  5848. + * Every package implicitly provides itself.
  5849. + */
  5850. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents)
  5851. +{
  5852. + int nprovides = pkg->provides_count;
  5853. + abstract_pkg_t **provides = pkg->provides;
  5854. + int n_installed_dependents = 0;
  5855. + int i;
  5856. + for (i = 0; i <= nprovides; i++) {
  5857. + abstract_pkg_t *providee = provides[i];
  5858. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5859. + abstract_pkg_t *dep_ab_pkg;
  5860. + if (dependers == NULL)
  5861. + continue;
  5862. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5863. + if (dep_ab_pkg->state_status == SS_INSTALLED){
  5864. + n_installed_dependents++;
  5865. + }
  5866. + }
  5867. +
  5868. + }
  5869. + /* if caller requested the set of installed dependents */
  5870. + if (pdependents) {
  5871. + int p = 0;
  5872. + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
  5873. +
  5874. + if ( dependents == NULL ){
  5875. + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
  5876. + return -1;
  5877. + }
  5878. +
  5879. + *pdependents = dependents;
  5880. + for (i = 0; i <= nprovides; i++) {
  5881. + abstract_pkg_t *providee = provides[i];
  5882. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5883. + abstract_pkg_t *dep_ab_pkg;
  5884. + if (dependers == NULL)
  5885. + continue;
  5886. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5887. + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
  5888. + dependents[p++] = dep_ab_pkg;
  5889. + dep_ab_pkg->state_flag |= SF_MARKED;
  5890. + }
  5891. + }
  5892. + }
  5893. + dependents[p] = NULL;
  5894. + /* now clear the marks */
  5895. + for (i = 0; i < p; i++) {
  5896. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5897. + dep_ab_pkg->state_flag &= ~SF_MARKED;
  5898. + }
  5899. + }
  5900. + return n_installed_dependents;
  5901. +}
  5902. +
  5903. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5904. +{
  5905. + int i;
  5906. + int a;
  5907. + int count;
  5908. + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
  5909. + abstract_pkg_t * ab_pkg;
  5910. +
  5911. + if((ab_pkg = pkg->parent) == NULL){
  5912. + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
  5913. + __FUNCTION__, pkg->name);
  5914. + return 0;
  5915. + }
  5916. +
  5917. + if (dependents == NULL)
  5918. + return 0;
  5919. +
  5920. + // here i am using the dependencies_checked
  5921. + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
  5922. + return 0; // has already been encountered in the process
  5923. + // of marking packages for removal - Karthik
  5924. + ab_pkg->dependencies_checked = 2;
  5925. +
  5926. + i = 0;
  5927. + count = 1;
  5928. + while (dependents [i] != NULL) {
  5929. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5930. +
  5931. + if (dep_ab_pkg->dependencies_checked == 2){
  5932. + i++;
  5933. + continue;
  5934. + }
  5935. + if (dep_ab_pkg->state_status == SS_INSTALLED) {
  5936. + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
  5937. + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
  5938. + if (dep_pkg->state_status == SS_INSTALLED) {
  5939. + pkg_vec_insert(dependent_pkgs, dep_pkg);
  5940. + count++;
  5941. + }
  5942. + }
  5943. + }
  5944. + i++;
  5945. + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
  5946. + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
  5947. + }
  5948. +
  5949. + if (count == 1)
  5950. + return 0;
  5951. +
  5952. +
  5953. + for (i = 0; i < dependent_pkgs->len; i++) {
  5954. + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
  5955. + if (err)
  5956. + return err;
  5957. + }
  5958. + return 0;
  5959. +}
  5960. +
  5961. +static int user_prefers_removing_dependents(ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5962. +{
  5963. + abstract_pkg_t *dep_ab_pkg;
  5964. + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
  5965. + while ((dep_ab_pkg = *dependents++) != NULL) {
  5966. + if (dep_ab_pkg->state_status == SS_INSTALLED)
  5967. + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
  5968. + }
  5969. + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
  5970. + ipkg_message(conf, IPKG_ERROR, "");
  5971. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
  5972. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
  5973. + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
  5974. + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
  5975. + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
  5976. + return 0;
  5977. +}
  5978. +
  5979. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
  5980. +{
  5981. +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
  5982. + thus I wan't check for essential, as I'm upgrading.
  5983. + I hope it won't break anything :)
  5984. +*/
  5985. + int err;
  5986. + abstract_pkg_t *parent_pkg = NULL;
  5987. +
  5988. + if (pkg->essential && !message) {
  5989. + if (conf->force_removal_of_essential_packages) {
  5990. + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
  5991. + "\tIf your system breaks, you get to keep both pieces\n",
  5992. + pkg->name);
  5993. + } else {
  5994. + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
  5995. + "\tRemoving an essential package may lead to an unusable system, but if\n"
  5996. + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
  5997. + "\tits will with the option: -force-removal-of-essential-packages\n",
  5998. + pkg->name);
  5999. + return IPKG_PKG_IS_ESSENTIAL;
  6000. + }
  6001. + }
  6002. +
  6003. + if ((parent_pkg = pkg->parent) == NULL)
  6004. + return 0;
  6005. +
  6006. + /* only attempt to remove dependent installed packages if
  6007. + * force_depends is not specified or the package is being
  6008. + * replaced.
  6009. + */
  6010. + if (!conf->force_depends
  6011. + && !(pkg->state_flag & SF_REPLACE)) {
  6012. + abstract_pkg_t **dependents;
  6013. + int has_installed_dependents =
  6014. + pkg_has_installed_dependents(pkg, &dependents);
  6015. +
  6016. + if (has_installed_dependents) {
  6017. + /*
  6018. + * if this package is depended up by others, then either we should
  6019. + * not remove it or we should remove it and all of its dependents
  6020. + */
  6021. +
  6022. + if (!conf->force_removal_of_dependent_packages
  6023. + && !user_prefers_removing_dependents(conf, pkg, dependents)) {
  6024. + return IPKG_PKG_HAS_DEPENDENTS;
  6025. + }
  6026. +
  6027. + /* remove packages depending on this package - Karthik */
  6028. + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
  6029. + free(dependents);
  6030. + if (err) return err;
  6031. + }
  6032. + }
  6033. +
  6034. + if ( message==0 ){
  6035. + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
  6036. + fflush(stdout);
  6037. + }
  6038. + pkg->state_flag |= SF_FILELIST_CHANGED;
  6039. +
  6040. + pkg->state_want = SW_DEINSTALL;
  6041. + ipkg_state_changed++;
  6042. +
  6043. + pkg_run_script(conf, pkg, "prerm", "remove");
  6044. +
  6045. + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
  6046. + maintains an empty filelist rather than deleting it. That seems
  6047. + like a big pain, and I don't see that that should make a big
  6048. + difference, but for anyone who wants tighter compatibility,
  6049. + feel free to fix this. */
  6050. + remove_data_files_and_list(conf, pkg);
  6051. +
  6052. + pkg_run_script(conf, pkg, "postrm", "remove");
  6053. +
  6054. + remove_maintainer_scripts_except_postrm(conf, pkg);
  6055. +
  6056. + /* Aman Gupta - Since ipkg is made for handheld devices with limited
  6057. + * space, it doesn't make sense to leave extra configurations, files,
  6058. + * and maintainer scripts left around. So, we make remove like purge,
  6059. + * and take out all the crap :) */
  6060. +
  6061. + remove_postrm(conf, pkg);
  6062. + pkg->state_status = SS_NOT_INSTALLED;
  6063. +
  6064. + if (parent_pkg)
  6065. + parent_pkg->state_status = SS_NOT_INSTALLED;
  6066. +
  6067. + return 0;
  6068. +}
  6069. +
  6070. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
  6071. +{
  6072. + ipkg_remove_pkg(conf, pkg,0);
  6073. + return 0;
  6074. +}
  6075. +
  6076. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
  6077. +{
  6078. + str_list_t installed_dirs;
  6079. + str_list_t *installed_files;
  6080. + str_list_elt_t *iter;
  6081. + char *file_name;
  6082. + conffile_t *conffile;
  6083. + int removed_a_dir;
  6084. + pkg_t *owner;
  6085. +
  6086. + str_list_init(&installed_dirs);
  6087. + installed_files = pkg_get_installed_files(pkg);
  6088. +
  6089. + for (iter = installed_files->head; iter; iter = iter->next) {
  6090. + file_name = iter->data;
  6091. +
  6092. + if (file_is_dir(file_name)) {
  6093. + str_list_append(&installed_dirs, strdup(file_name));
  6094. + continue;
  6095. + }
  6096. +
  6097. + conffile = pkg_get_conffile(pkg, file_name);
  6098. + if (conffile) {
  6099. + /* XXX: QUESTION: Is this right? I figure we only need to
  6100. + save the conffile if it has been modified. Is that what
  6101. + dpkg does? Or does dpkg preserve all conffiles? If so,
  6102. + this seems like a better thing to do to conserve
  6103. + space. */
  6104. + if (conffile_has_been_modified(conf, conffile)) {
  6105. + printf(" not deleting modified conffile %s\n", file_name);
  6106. + fflush(stdout);
  6107. + continue;
  6108. + }
  6109. + }
  6110. +
  6111. + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
  6112. + if (!conf->noaction)
  6113. + unlink(file_name);
  6114. + }
  6115. +
  6116. + if (!conf->noaction) {
  6117. + do {
  6118. + removed_a_dir = 0;
  6119. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6120. + file_name = iter->data;
  6121. +
  6122. + if (rmdir(file_name) == 0) {
  6123. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
  6124. + removed_a_dir = 1;
  6125. + str_list_remove(&installed_dirs, &iter);
  6126. + }
  6127. + }
  6128. + } while (removed_a_dir);
  6129. + }
  6130. +
  6131. + pkg_free_installed_files(pkg);
  6132. + /* We have to remove the file list now, so that
  6133. + find_pkg_owning_file does not always just report this package */
  6134. + pkg_remove_installed_files_list(conf, pkg);
  6135. +
  6136. + /* Don't print warning for dirs that are provided by other packages */
  6137. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6138. + file_name = iter->data;
  6139. +
  6140. + owner = file_hash_get_file_owner(conf, file_name);
  6141. + if (owner) {
  6142. + free(iter->data);
  6143. + iter->data = NULL;
  6144. + str_list_remove(&installed_dirs, &iter);
  6145. + }
  6146. + }
  6147. +
  6148. + /* cleanup */
  6149. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6150. + free(iter->data);
  6151. + iter->data = NULL;
  6152. + }
  6153. + str_list_deinit(&installed_dirs);
  6154. +
  6155. + return 0;
  6156. +}
  6157. +
  6158. +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6159. +{
  6160. + int i, err;
  6161. + char *globpattern;
  6162. + glob_t globbuf;
  6163. +
  6164. + if (conf->noaction) return 0;
  6165. +
  6166. + sprintf_alloc(&globpattern, "%s/%s.*",
  6167. + pkg->dest->info_dir, pkg->name);
  6168. + err = glob(globpattern, 0, NULL, &globbuf);
  6169. + free(globpattern);
  6170. + if (err) {
  6171. + return 0;
  6172. + }
  6173. +
  6174. + for (i = 0; i < globbuf.gl_pathc; i++) {
  6175. + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
  6176. + continue;
  6177. + }
  6178. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
  6179. + unlink(globbuf.gl_pathv[i]);
  6180. + }
  6181. + globfree(&globbuf);
  6182. +
  6183. + return 0;
  6184. +}
  6185. +
  6186. +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6187. +{
  6188. + char *postrm_file_name;
  6189. +
  6190. + if (conf->noaction) return 0;
  6191. +
  6192. + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
  6193. + pkg->dest->info_dir, pkg->name);
  6194. + unlink(postrm_file_name);
  6195. + free(postrm_file_name);
  6196. +
  6197. + return 0;
  6198. +}
  6199. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_remove.h busybox-1.17.0/archival/libipkg/ipkg_remove.h
  6200. --- busybox-1.17.0.orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
  6201. +++ busybox-1.17.0/archival/libipkg/ipkg_remove.h 2010-07-08 12:01:56.223000282 +0200
  6202. @@ -0,0 +1,33 @@
  6203. +/* ipkg_remove.h - the itsy package management system
  6204. +
  6205. + Carl D. Worth
  6206. +
  6207. + Copyright (C) 2001 University of Southern California
  6208. +
  6209. + This program is free software; you can redistribute it and/or
  6210. + modify it under the terms of the GNU General Public License as
  6211. + published by the Free Software Foundation; either version 2, or (at
  6212. + your option) any later version.
  6213. +
  6214. + This program is distributed in the hope that it will be useful, but
  6215. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6216. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6217. + General Public License for more details.
  6218. +*/
  6219. +
  6220. +#ifndef IPKG_REMOVE_H
  6221. +#define IPKG_REMOVE_H
  6222. +
  6223. +#include "pkg.h"
  6224. +#include "ipkg_conf.h"
  6225. +
  6226. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
  6227. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
  6228. +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
  6229. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents);
  6230. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
  6231. +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6232. +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6233. +
  6234. +
  6235. +#endif
  6236. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_upgrade.c busybox-1.17.0/archival/libipkg/ipkg_upgrade.c
  6237. --- busybox-1.17.0.orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
  6238. +++ busybox-1.17.0/archival/libipkg/ipkg_upgrade.c 2010-07-08 12:01:56.223000282 +0200
  6239. @@ -0,0 +1,79 @@
  6240. +/* ipkg_upgrade.c - the itsy package management system
  6241. +
  6242. + Carl D. Worth
  6243. + Copyright (C) 2001 University of Southern California
  6244. +
  6245. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6246. +
  6247. + This program is free software; you can redistribute it and/or
  6248. + modify it under the terms of the GNU General Public License as
  6249. + published by the Free Software Foundation; either version 2, or (at
  6250. + your option) any later version.
  6251. +
  6252. + This program is distributed in the hope that it will be useful, but
  6253. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6254. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6255. + General Public License for more details.
  6256. +*/
  6257. +
  6258. +#include "ipkg.h"
  6259. +#include "ipkg_install.h"
  6260. +#include "ipkg_message.h"
  6261. +
  6262. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6263. +
  6264. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
  6265. +{
  6266. + pkg_t *new;
  6267. + int cmp;
  6268. + char *old_version, *new_version;
  6269. +
  6270. + if (old->state_flag & SF_HOLD) {
  6271. + ipkg_message(conf, IPKG_NOTICE,
  6272. + "Not upgrading package %s which is marked "
  6273. + "hold (flags=%#x)\n", old->name, old->state_flag);
  6274. + return 0;
  6275. + }
  6276. +
  6277. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
  6278. + if (new == NULL) {
  6279. + old_version = pkg_version_str_alloc(old);
  6280. + ipkg_message(conf, IPKG_NOTICE,
  6281. + "Assuming locally installed package %s (%s) "
  6282. + "is up to date.\n", old->name, old_version);
  6283. + free(old_version);
  6284. + return 0;
  6285. + }
  6286. +
  6287. + old_version = pkg_version_str_alloc(old);
  6288. + new_version = pkg_version_str_alloc(new);
  6289. +
  6290. + cmp = pkg_compare_versions(old, new);
  6291. + ipkg_message(conf, IPKG_DEBUG,
  6292. + "comparing visible versions of pkg %s:"
  6293. + "\n\t%s is installed "
  6294. + "\n\t%s is available "
  6295. + "\n\t%d was comparison result\n",
  6296. + old->name, old_version, new_version, cmp);
  6297. + if (cmp == 0) {
  6298. + ipkg_message(conf, IPKG_INFO,
  6299. + "Package %s (%s) installed in %s is up to date.\n",
  6300. + old->name, old_version, old->dest->name);
  6301. + free(old_version);
  6302. + free(new_version);
  6303. + return 0;
  6304. + } else if (cmp > 0) {
  6305. + ipkg_message(conf, IPKG_NOTICE,
  6306. + "Not downgrading package %s on %s from %s to %s.\n",
  6307. + old->name, old->dest->name, old_version, new_version);
  6308. + free(old_version);
  6309. + free(new_version);
  6310. + return 0;
  6311. + } else if (cmp < 0) {
  6312. + new->dest = old->dest;
  6313. + old->state_want = SW_DEINSTALL;
  6314. + }
  6315. +
  6316. + new->state_flag |= SF_USER;
  6317. + return ipkg_install_pkg(conf, new,1);
  6318. +}
  6319. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_upgrade.h busybox-1.17.0/archival/libipkg/ipkg_upgrade.h
  6320. --- busybox-1.17.0.orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
  6321. +++ busybox-1.17.0/archival/libipkg/ipkg_upgrade.h 2010-07-08 12:01:56.223000282 +0200
  6322. @@ -0,0 +1,18 @@
  6323. +/* ipkg_upgrade.c - the itsy package management system
  6324. +
  6325. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6326. +
  6327. + This program is free software; you can redistribute it and/or
  6328. + modify it under the terms of the GNU General Public License as
  6329. + published by the Free Software Foundation; either version 2, or (at
  6330. + your option) any later version.
  6331. +
  6332. + This program is distributed in the hope that it will be useful, but
  6333. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6334. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6335. + General Public License for more details.
  6336. +*/
  6337. +
  6338. +#include "ipkg.h"
  6339. +
  6340. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6341. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_utils.c busybox-1.17.0/archival/libipkg/ipkg_utils.c
  6342. --- busybox-1.17.0.orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
  6343. +++ busybox-1.17.0/archival/libipkg/ipkg_utils.c 2010-07-08 12:01:56.227000792 +0200
  6344. @@ -0,0 +1,185 @@
  6345. +/* ipkg_utils.c - the itsy package management system
  6346. +
  6347. + Steven M. Ayer
  6348. +
  6349. + Copyright (C) 2002 Compaq Computer Corporation
  6350. +
  6351. + This program is free software; you can redistribute it and/or
  6352. + modify it under the terms of the GNU General Public License as
  6353. + published by the Free Software Foundation; either version 2, or (at
  6354. + your option) any later version.
  6355. +
  6356. + This program is distributed in the hope that it will be useful, but
  6357. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6358. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6359. + General Public License for more details.
  6360. +*/
  6361. +
  6362. +#include "ipkg.h"
  6363. +#include <errno.h>
  6364. +#include <ctype.h>
  6365. +#include <sys/vfs.h>
  6366. +
  6367. +#include "ipkg_utils.h"
  6368. +#include "pkg.h"
  6369. +#include "pkg_hash.h"
  6370. +
  6371. +void push_error_list(struct errlist ** errors, char * msg);
  6372. +void reverse_error_list(struct errlist **errors);
  6373. +void free_error_list(struct errlist **errors);
  6374. +
  6375. +struct errlist* error_list;
  6376. +
  6377. +int get_available_blocks(char * filesystem)
  6378. +{
  6379. + struct statfs sfs;
  6380. +
  6381. + if(statfs(filesystem, &sfs)){
  6382. + fprintf(stderr, "bad statfs\n");
  6383. + return 0;
  6384. + }
  6385. + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
  6386. + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
  6387. +}
  6388. +
  6389. +char **read_raw_pkgs_from_file(const char *file_name)
  6390. +{
  6391. + FILE *fp;
  6392. + char **ret;
  6393. +
  6394. + if(!(fp = fopen(file_name, "r"))){
  6395. + fprintf(stderr, "can't get %s open for read\n", file_name);
  6396. + return NULL;
  6397. + }
  6398. +
  6399. + ret = read_raw_pkgs_from_stream(fp);
  6400. +
  6401. + fclose(fp);
  6402. +
  6403. + return ret;
  6404. +}
  6405. +
  6406. +char **read_raw_pkgs_from_stream(FILE *fp)
  6407. +{
  6408. + char **raw = NULL, *buf, *scout;
  6409. + int count = 0;
  6410. + size_t size = 512;
  6411. +
  6412. + buf = malloc (size);
  6413. +
  6414. + while (fgets(buf, size, fp)) {
  6415. + while (strlen (buf) == (size - 1)
  6416. + && buf[size-2] != '\n') {
  6417. + size_t o = size - 1;
  6418. + size *= 2;
  6419. + buf = realloc (buf, size);
  6420. + if (fgets (buf + o, size - o, fp) == NULL)
  6421. + break;
  6422. + }
  6423. +
  6424. + if(!(count % 50))
  6425. + raw = realloc(raw, (count + 50) * sizeof(char *));
  6426. +
  6427. + if((scout = strchr(buf, '\n')))
  6428. + *scout = '\0';
  6429. +
  6430. + raw[count++] = strdup(buf);
  6431. + }
  6432. +
  6433. + raw = realloc(raw, (count + 1) * sizeof(char *));
  6434. + raw[count] = NULL;
  6435. +
  6436. + free (buf);
  6437. +
  6438. + return raw;
  6439. +}
  6440. +
  6441. +/* something to remove whitespace, a hash pooper */
  6442. +char *trim_alloc(char *line)
  6443. +{
  6444. + char *new;
  6445. + char *dest, *src, *end;
  6446. +
  6447. + new = malloc(strlen(line) + 1);
  6448. + if ( new == NULL ){
  6449. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  6450. + return NULL;
  6451. + }
  6452. + dest = new, src = line, end = line + (strlen(line) - 1);
  6453. +
  6454. + /* remove it from the front */
  6455. + while(src &&
  6456. + isspace(*src) &&
  6457. + *src)
  6458. + src++;
  6459. + /* and now from the back */
  6460. + while((end > src) &&
  6461. + isspace(*end))
  6462. + end--;
  6463. + end++;
  6464. + *end = '\0';
  6465. + strcpy(new, src);
  6466. + /* this does from the first space
  6467. + * blasting away any versions stuff in depends
  6468. + while(src &&
  6469. + !isspace(*src) &&
  6470. + *src)
  6471. + *dest++ = *src++;
  6472. + *dest = '\0';
  6473. + */
  6474. +
  6475. + return new;
  6476. +}
  6477. +
  6478. +int line_is_blank(const char *line)
  6479. +{
  6480. + const char *s;
  6481. +
  6482. + for (s = line; *s; s++) {
  6483. + if (!isspace(*s))
  6484. + return 0;
  6485. + }
  6486. + return 1;
  6487. +}
  6488. +
  6489. +void push_error_list(struct errlist ** errors, char * msg){
  6490. + struct errlist *err_lst_tmp;
  6491. +
  6492. +
  6493. + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
  6494. + err_lst_tmp->errmsg=strdup(msg) ;
  6495. + err_lst_tmp->next = *errors;
  6496. + *errors = err_lst_tmp;
  6497. +}
  6498. +
  6499. +
  6500. +void reverse_error_list(struct errlist **errors){
  6501. + struct errlist *result=NULL;
  6502. + struct errlist *current= *errors;
  6503. + struct errlist *next;
  6504. +
  6505. + while ( current != NULL ) {
  6506. + next = current->next;
  6507. + current->next=result;
  6508. + result=current;
  6509. + current=next;
  6510. + }
  6511. + *errors=result;
  6512. +
  6513. +}
  6514. +
  6515. +
  6516. +void free_error_list(struct errlist **errors){
  6517. + struct errlist *current = *errors;
  6518. +
  6519. + while (current != NULL) {
  6520. + free(current->errmsg);
  6521. + current = (*errors)->next;
  6522. + free(*errors);
  6523. + *errors = current;
  6524. + }
  6525. +
  6526. +
  6527. +}
  6528. +
  6529. +
  6530. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_utils.h busybox-1.17.0/archival/libipkg/ipkg_utils.h
  6531. --- busybox-1.17.0.orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
  6532. +++ busybox-1.17.0/archival/libipkg/ipkg_utils.h 2010-07-08 12:01:56.227000792 +0200
  6533. @@ -0,0 +1,29 @@
  6534. +/* ipkg_utils.h - the itsy package management system
  6535. +
  6536. + Steven M. Ayer
  6537. +
  6538. + Copyright (C) 2002 Compaq Computer Corporation
  6539. +
  6540. + This program is free software; you can redistribute it and/or
  6541. + modify it under the terms of the GNU General Public License as
  6542. + published by the Free Software Foundation; either version 2, or (at
  6543. + your option) any later version.
  6544. +
  6545. + This program is distributed in the hope that it will be useful, but
  6546. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6547. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6548. + General Public License for more details.
  6549. +*/
  6550. +
  6551. +#ifndef IPKG_UTILS_H
  6552. +#define IPKG_UTILS_H
  6553. +
  6554. +#include "pkg.h"
  6555. +
  6556. +int get_available_blocks(char * filesystem);
  6557. +char **read_raw_pkgs_from_file(const char *file_name);
  6558. +char **read_raw_pkgs_from_stream(FILE *fp);
  6559. +char *trim_alloc(char * line);
  6560. +int line_is_blank(const char *line);
  6561. +
  6562. +#endif
  6563. diff -Nur busybox-1.17.0.orig/archival/libipkg/Kbuild busybox-1.17.0/archival/libipkg/Kbuild
  6564. --- busybox-1.17.0.orig/archival/libipkg/Kbuild 1970-01-01 01:00:00.000000000 +0100
  6565. +++ busybox-1.17.0/archival/libipkg/Kbuild 2010-07-08 12:01:56.227000792 +0200
  6566. @@ -0,0 +1,60 @@
  6567. +# Makefile for busybox
  6568. +#
  6569. +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  6570. +# Copyright (C) 2006 OpenWrt.org
  6571. +#
  6572. +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  6573. +
  6574. +LIBIPKG_CORE_OBJS:= \
  6575. + args.o \
  6576. + libipkg.o \
  6577. + user.o \
  6578. +
  6579. +LIBIPKG_CMD_OBJS:= \
  6580. + ipkg_cmd.o \
  6581. + ipkg_configure.o \
  6582. + ipkg_download.o \
  6583. + ipkg_install.o \
  6584. + ipkg_remove.o \
  6585. + ipkg_upgrade.o \
  6586. +
  6587. +LIBIPKG_DB_OBJS:= \
  6588. + hash_table.o \
  6589. + ipkg_conf.o \
  6590. + ipkg_utils.o \
  6591. + pkg.o \
  6592. + pkg_depends.o \
  6593. + pkg_extract.o \
  6594. + pkg_hash.o \
  6595. + pkg_parse.o \
  6596. + pkg_vec.o \
  6597. +
  6598. +LIBIPKG_LIST_OBJS:= \
  6599. + conffile.o \
  6600. + conffile_list.o \
  6601. + nv_pair.o \
  6602. + nv_pair_list.o \
  6603. + pkg_dest.o \
  6604. + pkg_dest_list.o \
  6605. + pkg_src.o \
  6606. + pkg_src_list.o \
  6607. + str_list.o \
  6608. + void_list.o \
  6609. +
  6610. +LIBIPKG_UTIL_OBJS:= \
  6611. + file_util.o \
  6612. + ipkg_message.o \
  6613. + str_util.o \
  6614. + xsystem.o \
  6615. +
  6616. +lib-y :=
  6617. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
  6618. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
  6619. +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
  6620. +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
  6621. +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
  6622. +
  6623. +ifeq ($(strip $(IPKG_ARCH)),)
  6624. +IPKG_ARCH:=$(TARGET_ARCH)
  6625. +endif
  6626. +CFLAGS += -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
  6627. diff -Nur busybox-1.17.0.orig/archival/libipkg/libipkg.c busybox-1.17.0/archival/libipkg/libipkg.c
  6628. --- busybox-1.17.0.orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
  6629. +++ busybox-1.17.0/archival/libipkg/libipkg.c 2010-07-08 12:01:56.231000184 +0200
  6630. @@ -0,0 +1,550 @@
  6631. +/* ipkglib.c - the itsy package management system
  6632. +
  6633. + Florina Boor
  6634. +
  6635. + Copyright (C) 2003 kernel concepts
  6636. +
  6637. + This program is free software; you can redistribute it and/or
  6638. + modify it under the terms of the GNU General Public License as
  6639. + published by the Free Software Foundation; either version 2, or (at
  6640. + your option) any later version.
  6641. +
  6642. + This program is distributed in the hope that it will be useful, but
  6643. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6644. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6645. + General Public License for more details.
  6646. +*/
  6647. +
  6648. +#include "ipkg.h"
  6649. +#include "ipkg_includes.h"
  6650. +#include "libipkg.h"
  6651. +
  6652. +#include "args.h"
  6653. +#include "ipkg_conf.h"
  6654. +#include "ipkg_cmd.h"
  6655. +#include "file_util.h"
  6656. +
  6657. +int ipkg_file_what(args_t *args, const char *file, const char* command);
  6658. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  6659. + char *msg);
  6660. +int default_ipkg_list_callback(char *name, char *desc, char *version);
  6661. +int default_ipkg_files_callback(char *desc);
  6662. +int default_ipkg_status_callback(char *desc);
  6663. +char* default_ipkg_response_callback(char *question);
  6664. +
  6665. +
  6666. +ipkg_message_callback ipkg_cb_message = NULL;
  6667. +ipkg_response_callback ipkg_cb_response = NULL;
  6668. +ipkg_status_callback ipkg_cb_status = NULL;
  6669. +ipkg_list_callback ipkg_cb_list = NULL;
  6670. +
  6671. +
  6672. +int
  6673. +ipkg_init (ipkg_message_callback mcall,
  6674. + ipkg_response_callback rcall,
  6675. + args_t * args)
  6676. +{
  6677. + ipkg_cb_message = mcall;
  6678. + ipkg_cb_response = rcall;
  6679. +
  6680. + args_init (args);
  6681. +
  6682. + return 0;
  6683. +}
  6684. +
  6685. +
  6686. +int
  6687. +ipkg_deinit (args_t * args)
  6688. +{
  6689. + args_deinit (args);
  6690. + ipkg_cb_message = NULL;
  6691. + ipkg_cb_response = NULL;
  6692. +
  6693. + /* place other cleanup stuff here */
  6694. +
  6695. + return 0;
  6696. +}
  6697. +
  6698. +
  6699. +int
  6700. +ipkg_packages_list(args_t *args,
  6701. + const char *packages,
  6702. + ipkg_list_callback cblist,
  6703. + void *userdata)
  6704. +{
  6705. + ipkg_cmd_t *cmd;
  6706. + ipkg_conf_t ipkg_conf;
  6707. + int err;
  6708. +
  6709. + err = ipkg_conf_init (&ipkg_conf, args);
  6710. + if (err)
  6711. + {
  6712. + return err;
  6713. + }
  6714. +
  6715. + ipkg_cb_list = cblist;
  6716. + /* we need to do this because of static declarations,
  6717. + * maybe a good idea to change */
  6718. + cmd = ipkg_cmd_find ("list");
  6719. + if (packages)
  6720. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6721. + else
  6722. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6723. + ipkg_cb_list = NULL;
  6724. + ipkg_conf_deinit (&ipkg_conf);
  6725. + return (err);
  6726. +}
  6727. +
  6728. +
  6729. +int
  6730. +ipkg_packages_status(args_t *args,
  6731. + const char *packages,
  6732. + ipkg_status_callback cbstatus,
  6733. + void *userdata)
  6734. +{
  6735. + ipkg_cmd_t *cmd;
  6736. + ipkg_conf_t ipkg_conf;
  6737. + int err;
  6738. +
  6739. + err = ipkg_conf_init (&ipkg_conf, args);
  6740. + if (err)
  6741. + {
  6742. + return err;
  6743. + }
  6744. +
  6745. + ipkg_cb_status = cbstatus;
  6746. +
  6747. + /* we need to do this because of static declarations,
  6748. + * maybe a good idea to change */
  6749. + cmd = ipkg_cmd_find ("status");
  6750. + if (packages)
  6751. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6752. + else
  6753. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6754. +
  6755. + ipkg_cb_status = NULL;
  6756. + ipkg_conf_deinit (&ipkg_conf);
  6757. + return (err);
  6758. +}
  6759. +
  6760. +
  6761. +int
  6762. +ipkg_packages_info(args_t *args,
  6763. + const char *packages,
  6764. + ipkg_status_callback cbstatus,
  6765. + void *userdata)
  6766. +{
  6767. + ipkg_cmd_t *cmd;
  6768. + ipkg_conf_t ipkg_conf;
  6769. + int err;
  6770. +
  6771. + err = ipkg_conf_init (&ipkg_conf, args);
  6772. + if (err)
  6773. + {
  6774. + return err;
  6775. + }
  6776. +
  6777. + ipkg_cb_status = cbstatus;
  6778. +
  6779. + /* we need to do this because of static declarations,
  6780. + * maybe a good idea to change */
  6781. + cmd = ipkg_cmd_find ("info");
  6782. + if (packages)
  6783. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6784. + else
  6785. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6786. +
  6787. + ipkg_cb_status = NULL;
  6788. + ipkg_conf_deinit (&ipkg_conf);
  6789. + return (err);
  6790. +}
  6791. +
  6792. +
  6793. +int
  6794. +ipkg_packages_install (args_t * args, const char *name)
  6795. +{
  6796. + ipkg_cmd_t *cmd;
  6797. + ipkg_conf_t ipkg_conf;
  6798. + int err;
  6799. +
  6800. + /* this error should be handled in application */
  6801. + if (!name || !strlen (name))
  6802. + return (-1);
  6803. +
  6804. + err = ipkg_conf_init (&ipkg_conf, args);
  6805. + if (err)
  6806. + {
  6807. + return err;
  6808. + }
  6809. +
  6810. + /* we need to do this because of static declarations,
  6811. + * maybe a good idea to change */
  6812. + cmd = ipkg_cmd_find ("install");
  6813. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6814. +
  6815. + ipkg_conf_deinit(&ipkg_conf);
  6816. + return (err);
  6817. +}
  6818. +
  6819. +
  6820. +int
  6821. +ipkg_packages_remove(args_t *args, const char *name, int purge)
  6822. +{
  6823. + ipkg_cmd_t *cmd;
  6824. + ipkg_conf_t ipkg_conf;
  6825. + int err;
  6826. +
  6827. + /* this error should be handled in application */
  6828. + if (!name || !strlen (name))
  6829. + return (-1);
  6830. +
  6831. + err = ipkg_conf_init (&ipkg_conf, args);
  6832. + if (err)
  6833. + {
  6834. + return err;
  6835. + }
  6836. +
  6837. + /* we need to do this because of static declarations,
  6838. + * maybe a good idea to change */
  6839. + if (purge)
  6840. + cmd = ipkg_cmd_find ("purge");
  6841. + else
  6842. + cmd = ipkg_cmd_find ("remove");
  6843. +
  6844. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6845. +
  6846. + ipkg_conf_deinit(&ipkg_conf);
  6847. + return (err);
  6848. +}
  6849. +
  6850. +
  6851. +int
  6852. +ipkg_lists_update(args_t *args)
  6853. +{
  6854. + ipkg_cmd_t *cmd;
  6855. + ipkg_conf_t ipkg_conf;
  6856. + int err;
  6857. +
  6858. + err = ipkg_conf_init (&ipkg_conf, args);
  6859. + if (err)
  6860. + {
  6861. + return err;
  6862. + }
  6863. +
  6864. + /* we need to do this because of static declarations,
  6865. + * maybe a good idea to change */
  6866. + cmd = ipkg_cmd_find ("update");
  6867. +
  6868. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6869. +
  6870. + ipkg_conf_deinit(&ipkg_conf);
  6871. + return (err);
  6872. +}
  6873. +
  6874. +
  6875. +int
  6876. +ipkg_packages_upgrade(args_t *args)
  6877. +{
  6878. + ipkg_cmd_t *cmd;
  6879. + ipkg_conf_t ipkg_conf;
  6880. + int err;
  6881. +
  6882. + err = ipkg_conf_init (&ipkg_conf, args);
  6883. + if (err)
  6884. + {
  6885. + return err;
  6886. + }
  6887. +
  6888. + /* we need to do this because of static declarations,
  6889. + * maybe a good idea to change */
  6890. + cmd = ipkg_cmd_find ("upgrade");
  6891. +
  6892. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6893. +
  6894. + ipkg_conf_deinit(&ipkg_conf);
  6895. + return (err);
  6896. +}
  6897. +
  6898. +
  6899. +int
  6900. +ipkg_packages_download (args_t * args, const char *name)
  6901. +{
  6902. + ipkg_cmd_t *cmd;
  6903. + ipkg_conf_t ipkg_conf;
  6904. + int err;
  6905. +
  6906. + /* this error should be handled in application */
  6907. + if (!name || !strlen (name))
  6908. + return (-1);
  6909. +
  6910. + err = ipkg_conf_init (&ipkg_conf, args);
  6911. + if (err)
  6912. + {
  6913. + return err;
  6914. + }
  6915. +
  6916. + /* we need to do this because of static declarations,
  6917. + * maybe a good idea to change */
  6918. + cmd = ipkg_cmd_find ("download");
  6919. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6920. +
  6921. + ipkg_conf_deinit(&ipkg_conf);
  6922. + return (err);
  6923. +}
  6924. +
  6925. +
  6926. +int
  6927. +ipkg_package_files(args_t *args,
  6928. + const char *name,
  6929. + ipkg_list_callback cblist,
  6930. + void *userdata)
  6931. +{
  6932. + ipkg_cmd_t *cmd;
  6933. + ipkg_conf_t ipkg_conf;
  6934. + int err;
  6935. +
  6936. + /* this error should be handled in application */
  6937. + if (!name || !strlen (name))
  6938. + return (-1);
  6939. +
  6940. + err = ipkg_conf_init (&ipkg_conf, args);
  6941. + if (err)
  6942. + {
  6943. + return err;
  6944. + }
  6945. +
  6946. + ipkg_cb_list = cblist;
  6947. +
  6948. + /* we need to do this because of static declarations,
  6949. + * maybe a good idea to change */
  6950. + cmd = ipkg_cmd_find ("files");
  6951. +
  6952. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
  6953. +
  6954. + ipkg_cb_list = NULL;
  6955. + ipkg_conf_deinit(&ipkg_conf);
  6956. + return (err);
  6957. +}
  6958. +
  6959. +
  6960. +int
  6961. +ipkg_file_search(args_t *args,
  6962. + const char *file,
  6963. + ipkg_list_callback cblist,
  6964. + void *userdata)
  6965. +{
  6966. + ipkg_cmd_t *cmd;
  6967. + ipkg_conf_t ipkg_conf;
  6968. + int err;
  6969. +
  6970. + /* this error should be handled in application */
  6971. + if (!file || !strlen (file))
  6972. + return (-1);
  6973. +
  6974. + err = ipkg_conf_init (&ipkg_conf, args);
  6975. + if (err)
  6976. + {
  6977. + return err;
  6978. + }
  6979. +
  6980. + ipkg_cb_list = cblist;
  6981. +
  6982. + /* we need to do this because of static declarations,
  6983. + * maybe a good idea to change */
  6984. + cmd = ipkg_cmd_find ("search");
  6985. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
  6986. +
  6987. + ipkg_cb_list = NULL;
  6988. + ipkg_conf_deinit(&ipkg_conf);
  6989. + return(err);
  6990. +}
  6991. +
  6992. +
  6993. +int
  6994. +ipkg_file_what(args_t *args, const char *file, const char* command)
  6995. +{
  6996. + ipkg_cmd_t *cmd;
  6997. + ipkg_conf_t ipkg_conf;
  6998. + int err;
  6999. +
  7000. + /* this error should be handled in application */
  7001. + if (!file || !strlen (file))
  7002. + return (-1);
  7003. +
  7004. + err = ipkg_conf_init (&ipkg_conf, args);
  7005. + if (err)
  7006. + {
  7007. + return err;
  7008. + }
  7009. +
  7010. + /* we need to do this because of static declarations,
  7011. + * maybe a good idea to change */
  7012. + cmd = ipkg_cmd_find (command);
  7013. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
  7014. +
  7015. + ipkg_conf_deinit(&ipkg_conf);
  7016. + return(err);
  7017. +}
  7018. +
  7019. +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
  7020. +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
  7021. +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
  7022. +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
  7023. +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
  7024. +
  7025. +
  7026. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  7027. + char *msg)
  7028. +{
  7029. + if (conf && (conf->verbosity < level)) {
  7030. + return 0;
  7031. + } else {
  7032. + if ( level == IPKG_ERROR )
  7033. + push_error_list(&error_list, msg);
  7034. + else
  7035. + printf(msg);
  7036. + }
  7037. + return 0;
  7038. +}
  7039. +
  7040. +int default_ipkg_list_callback(char *name, char *desc, char *version)
  7041. +{
  7042. + if (desc)
  7043. + printf("%s - %s - %s\n", name, version, desc);
  7044. + else
  7045. + printf("%s - %s\n", name, version);
  7046. + return 0;
  7047. +}
  7048. +
  7049. +int default_ipkg_files_callback(char *desc)
  7050. +{
  7051. + if (desc)
  7052. + printf("%s\n", desc);
  7053. + return 0;
  7054. +}
  7055. +
  7056. +int default_ipkg_status_callback(char *desc)
  7057. +{
  7058. + printf("%s\n", desc);
  7059. + return 0;
  7060. +}
  7061. +
  7062. +char* default_ipkg_response_callback(char *question)
  7063. +{
  7064. + char *response = NULL;
  7065. + printf(question);
  7066. + fflush(stdout);
  7067. + do {
  7068. + response = (char *)file_read_line_alloc(stdin);
  7069. + } while (response == NULL);
  7070. + return response;
  7071. +}
  7072. +
  7073. +/* This is used for backward compatibility */
  7074. +int
  7075. +ipkg_op (int argc, char *argv[])
  7076. +{
  7077. + int err, optind_;
  7078. + args_t args;
  7079. + char *cmd_name;
  7080. + ipkg_cmd_t *cmd;
  7081. + ipkg_conf_t ipkg_conf;
  7082. + const char *message = "ipkg must have one sub-command argument";
  7083. +
  7084. +
  7085. + args_init (&args);
  7086. +
  7087. + optind_ = args_parse (&args, argc, argv);
  7088. + if (optind_ == argc || optind_ < 0)
  7089. + {
  7090. + args_usage(message);
  7091. + }
  7092. +
  7093. + cmd_name = argv[optind_++];
  7094. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  7095. + read anything from there.
  7096. +*/
  7097. + if ( !strcmp(cmd_name,"print-architecture") ||
  7098. + !strcmp(cmd_name,"print_architecture") ||
  7099. + !strcmp(cmd_name,"print-installation-architecture") ||
  7100. + !strcmp(cmd_name,"print_installation_architecture") )
  7101. + args.nocheckfordirorfile = 1;
  7102. +
  7103. +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
  7104. + read anything from there.
  7105. +*/
  7106. + if ( !strcmp(cmd_name,"flag") ||
  7107. + !strcmp(cmd_name,"configure") ||
  7108. + !strcmp(cmd_name,"remove") ||
  7109. + !strcmp(cmd_name,"files") ||
  7110. + !strcmp(cmd_name,"search") ||
  7111. + !strcmp(cmd_name,"compare_versions") ||
  7112. + !strcmp(cmd_name,"compare-versions") ||
  7113. + !strcmp(cmd_name,"list_installed") ||
  7114. + !strcmp(cmd_name,"list-installed") ||
  7115. + !strcmp(cmd_name,"status") )
  7116. + args.noreadfeedsfile = 1;
  7117. +
  7118. +
  7119. + if ( !strcmp(cmd_name,"install") ||
  7120. + !strcmp(cmd_name,"update") ||
  7121. + !strcmp(cmd_name,"upgrade") ||
  7122. + !strcmp(cmd_name,"flag") ||
  7123. + !strcmp(cmd_name,"configure") ||
  7124. + !strcmp(cmd_name,"remove") ) {
  7125. + /* mount rootfs read-write */
  7126. + if (mount("","/",0,MS_REMOUNT,0)<0)
  7127. + fprintf (stderr, "Mounting rootfs read-write failed\n");
  7128. + }
  7129. +
  7130. +
  7131. + err = ipkg_conf_init (&ipkg_conf, &args);
  7132. + if (err)
  7133. + {
  7134. + return err;
  7135. + }
  7136. +
  7137. + args_deinit (&args);
  7138. +
  7139. + ipkg_cb_message = default_ipkg_message_callback;
  7140. + ipkg_cb_response = default_ipkg_response_callback;
  7141. + ipkg_cb_status = (ipkg_status_callback)default_ipkg_status_callback;
  7142. + if ( strcmp(cmd_name, "files")==0)
  7143. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_files_callback;
  7144. + else
  7145. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_list_callback;
  7146. +
  7147. + cmd = ipkg_cmd_find (cmd_name);
  7148. + if (cmd == NULL)
  7149. + {
  7150. + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
  7151. + cmd_name);
  7152. + args_usage (NULL);
  7153. + }
  7154. +
  7155. + if (cmd->requires_args && optind_ == argc)
  7156. + {
  7157. + fprintf (stderr,
  7158. + "%s: the ``%s'' command requires at least one argument\n",
  7159. + __FUNCTION__, cmd_name);
  7160. + args_usage (NULL);
  7161. + }
  7162. +
  7163. + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind_, (const char **) (argv + optind_), NULL);
  7164. +
  7165. + ipkg_conf_deinit (&ipkg_conf);
  7166. +
  7167. + if ( !strcmp(cmd_name,"install") ||
  7168. + !strcmp(cmd_name,"update") ||
  7169. + !strcmp(cmd_name,"upgrade") ||
  7170. + !strcmp(cmd_name,"flag") ||
  7171. + !strcmp(cmd_name,"configure") ||
  7172. + !strcmp(cmd_name,"remove") ) {
  7173. + sync();
  7174. + /* mount rootfs read-only */
  7175. + if (mount("","/",0,MS_REMOUNT|MS_RDONLY,0)<0)
  7176. + fprintf (stderr, "Mounting rootfs read-only failed\n");
  7177. + }
  7178. +
  7179. + return err;
  7180. +}
  7181. diff -Nur busybox-1.17.0.orig/archival/libipkg/libipkg.h busybox-1.17.0/archival/libipkg/libipkg.h
  7182. --- busybox-1.17.0.orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
  7183. +++ busybox-1.17.0/archival/libipkg/libipkg.h 2010-07-08 12:01:56.231000184 +0200
  7184. @@ -0,0 +1,78 @@
  7185. +/* ipkglib.h - the itsy package management system
  7186. +
  7187. + Florian Boor <florian.boor@kernelconcepts.de>
  7188. +
  7189. + This program is free software; you can redistribute it and/or
  7190. + modify it under the terms of the GNU General Public License as
  7191. + published by the Free Software Foundation; either version 2, or (at
  7192. + your option) any later version.
  7193. +
  7194. + This program is distributed in the hope that it will be useful, but
  7195. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7196. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7197. + General Public License for more details.
  7198. +*/
  7199. +
  7200. +#ifndef IPKGLIB_H
  7201. +#define IPKGLIB_H
  7202. +
  7203. +#include "ipkg_conf.h"
  7204. +#include "ipkg_message.h"
  7205. +
  7206. +#include "args.h"
  7207. +#include "pkg.h"
  7208. +
  7209. +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
  7210. + char *msg);
  7211. +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
  7212. + pkg_state_status_t status, void *userdata);
  7213. +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
  7214. + void *userdata);
  7215. +typedef char* (*ipkg_response_callback)(char *question);
  7216. +
  7217. +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
  7218. +extern int ipkg_init (ipkg_message_callback mcall,
  7219. + ipkg_response_callback rcall,
  7220. + args_t * args);
  7221. +
  7222. +extern int ipkg_deinit (args_t *args);
  7223. +extern int ipkg_packages_list(args_t *args,
  7224. + const char *packages,
  7225. + ipkg_list_callback cblist,
  7226. + void *userdata);
  7227. +extern int ipkg_packages_status(args_t *args,
  7228. + const char *packages,
  7229. + ipkg_status_callback cbstatus,
  7230. + void *userdata);
  7231. +extern int ipkg_packages_info(args_t *args,
  7232. + const char *packages,
  7233. + ipkg_status_callback cbstatus,
  7234. + void *userdata);
  7235. +extern int ipkg_packages_install(args_t *args, const char *name);
  7236. +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
  7237. +extern int ipkg_lists_update(args_t *args);
  7238. +extern int ipkg_packages_upgrade(args_t *args);
  7239. +extern int ipkg_packages_download(args_t *args, const char *name);
  7240. +extern int ipkg_package_files(args_t *args,
  7241. + const char *name,
  7242. + ipkg_list_callback cblist,
  7243. + void *userdata);
  7244. +extern int ipkg_file_search(args_t *args,
  7245. + const char *file,
  7246. + ipkg_list_callback cblist,
  7247. + void *userdata);
  7248. +extern int ipkg_package_whatdepends(args_t *args, const char *file);
  7249. +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
  7250. +extern int ipkg_package_whatprovides(args_t *args, const char *file);
  7251. +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
  7252. +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
  7253. +
  7254. +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
  7255. +extern ipkg_response_callback ipkg_cb_response;
  7256. +extern ipkg_status_callback ipkg_cb_status;
  7257. +extern ipkg_list_callback ipkg_cb_list;
  7258. +extern void push_error_list(struct errlist **errors,char * msg);
  7259. +extern void reverse_error_list(struct errlist **errors);
  7260. +extern void free_error_list(struct errlist **errors);
  7261. +
  7262. +#endif
  7263. diff -Nur busybox-1.17.0.orig/archival/libipkg/nv_pair.c busybox-1.17.0/archival/libipkg/nv_pair.c
  7264. --- busybox-1.17.0.orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
  7265. +++ busybox-1.17.0/archival/libipkg/nv_pair.c 2010-07-08 12:01:56.231000184 +0200
  7266. @@ -0,0 +1,40 @@
  7267. +/* nv_pair.c - the itsy package management system
  7268. +
  7269. + Carl D. Worth
  7270. +
  7271. + Copyright (C) 2001 University of Southern California
  7272. +
  7273. + This program is free software; you can redistribute it and/or
  7274. + modify it under the terms of the GNU General Public License as
  7275. + published by the Free Software Foundation; either version 2, or (at
  7276. + your option) any later version.
  7277. +
  7278. + This program is distributed in the hope that it will be useful, but
  7279. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7280. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7281. + General Public License for more details.
  7282. +*/
  7283. +
  7284. +#include "ipkg.h"
  7285. +
  7286. +#include "nv_pair.h"
  7287. +#include "str_util.h"
  7288. +
  7289. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
  7290. +{
  7291. + nv_pair->name = str_dup_safe(name);
  7292. + nv_pair->value = str_dup_safe(value);
  7293. +
  7294. + return 0;
  7295. +}
  7296. +
  7297. +void nv_pair_deinit(nv_pair_t *nv_pair)
  7298. +{
  7299. + free(nv_pair->name);
  7300. + nv_pair->name = NULL;
  7301. +
  7302. + free(nv_pair->value);
  7303. + nv_pair->value = NULL;
  7304. +}
  7305. +
  7306. +
  7307. diff -Nur busybox-1.17.0.orig/archival/libipkg/nv_pair.h busybox-1.17.0/archival/libipkg/nv_pair.h
  7308. --- busybox-1.17.0.orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
  7309. +++ busybox-1.17.0/archival/libipkg/nv_pair.h 2010-07-08 12:01:56.231000184 +0200
  7310. @@ -0,0 +1,32 @@
  7311. +/* nv_pair.h - the itsy package management system
  7312. +
  7313. + Carl D. Worth
  7314. +
  7315. + Copyright (C) 2001 University of Southern California
  7316. +
  7317. + This program is free software; you can redistribute it and/or
  7318. + modify it under the terms of the GNU General Public License as
  7319. + published by the Free Software Foundation; either version 2, or (at
  7320. + your option) any later version.
  7321. +
  7322. + This program is distributed in the hope that it will be useful, but
  7323. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7324. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7325. + General Public License for more details.
  7326. +*/
  7327. +
  7328. +#ifndef NV_PAIR_H
  7329. +#define NV_PAIR_H
  7330. +
  7331. +typedef struct nv_pair nv_pair_t;
  7332. +struct nv_pair
  7333. +{
  7334. + char *name;
  7335. + char *value;
  7336. +};
  7337. +
  7338. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
  7339. +void nv_pair_deinit(nv_pair_t *nv_pair);
  7340. +
  7341. +#endif
  7342. +
  7343. diff -Nur busybox-1.17.0.orig/archival/libipkg/nv_pair_list.c busybox-1.17.0/archival/libipkg/nv_pair_list.c
  7344. --- busybox-1.17.0.orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
  7345. +++ busybox-1.17.0/archival/libipkg/nv_pair_list.c 2010-07-08 12:01:56.231000184 +0200
  7346. @@ -0,0 +1,98 @@
  7347. +/* nv_pair_list.c - the itsy package management system
  7348. +
  7349. + Carl D. Worth
  7350. +
  7351. + Copyright (C) 2001 University of Southern California
  7352. +
  7353. + This program is free software; you can redistribute it and/or
  7354. + modify it under the terms of the GNU General Public License as
  7355. + published by the Free Software Foundation; either version 2, or (at
  7356. + your option) any later version.
  7357. +
  7358. + This program is distributed in the hope that it will be useful, but
  7359. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7360. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7361. + General Public License for more details.
  7362. +*/
  7363. +
  7364. +#include "ipkg.h"
  7365. +
  7366. +#include "nv_pair.h"
  7367. +#include "void_list.h"
  7368. +#include "nv_pair_list.h"
  7369. +
  7370. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
  7371. +{
  7372. + return void_list_elt_init((void_list_elt_t *) elt, data);
  7373. +}
  7374. +
  7375. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
  7376. +{
  7377. + void_list_elt_deinit((void_list_elt_t *) elt);
  7378. +}
  7379. +
  7380. +int nv_pair_list_init(nv_pair_list_t *list)
  7381. +{
  7382. + return void_list_init((void_list_t *) list);
  7383. +}
  7384. +
  7385. +void nv_pair_list_deinit(nv_pair_list_t *list)
  7386. +{
  7387. + nv_pair_list_elt_t *iter;
  7388. + nv_pair_t *nv_pair;
  7389. +
  7390. + for (iter = list->head; iter; iter = iter->next) {
  7391. + nv_pair = iter->data;
  7392. + nv_pair_deinit(nv_pair);
  7393. +
  7394. + /* malloced in nv_pair_list_append */
  7395. + free(nv_pair);
  7396. + iter->data = NULL;
  7397. + }
  7398. + void_list_deinit((void_list_t *) list);
  7399. +}
  7400. +
  7401. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
  7402. +{
  7403. + int err;
  7404. +
  7405. + /* freed in nv_pair_list_deinit */
  7406. + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
  7407. +
  7408. + if (nv_pair == NULL) {
  7409. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7410. + return NULL;
  7411. + }
  7412. + nv_pair_init(nv_pair, name, value);
  7413. +
  7414. + err = void_list_append((void_list_t *) list, nv_pair);
  7415. + if (err) {
  7416. + return NULL;
  7417. + }
  7418. +
  7419. + return nv_pair;
  7420. +}
  7421. +
  7422. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
  7423. +{
  7424. + return void_list_push((void_list_t *) list, data);
  7425. +}
  7426. +
  7427. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
  7428. +{
  7429. + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
  7430. +}
  7431. +
  7432. +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
  7433. +{
  7434. + nv_pair_list_elt_t *iter;
  7435. + nv_pair_t *nv_pair;
  7436. +
  7437. + for (iter = list->head; iter; iter = iter->next) {
  7438. + nv_pair = iter->data;
  7439. + if (strcmp(nv_pair->name, name) == 0) {
  7440. + return nv_pair->value;
  7441. + }
  7442. + }
  7443. + return NULL;
  7444. +}
  7445. diff -Nur busybox-1.17.0.orig/archival/libipkg/nv_pair_list.h busybox-1.17.0/archival/libipkg/nv_pair_list.h
  7446. --- busybox-1.17.0.orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
  7447. +++ busybox-1.17.0/archival/libipkg/nv_pair_list.h 2010-07-08 12:01:56.235001811 +0200
  7448. @@ -0,0 +1,60 @@
  7449. +/* nv_pair_list.h - the itsy package management system
  7450. +
  7451. + Carl D. Worth
  7452. +
  7453. + Copyright (C) 2001 University of Southern California
  7454. +
  7455. + This program is free software; you can redistribute it and/or
  7456. + modify it under the terms of the GNU General Public License as
  7457. + published by the Free Software Foundation; either version 2, or (at
  7458. + your option) any later version.
  7459. +
  7460. + This program is distributed in the hope that it will be useful, but
  7461. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7462. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7463. + General Public License for more details.
  7464. +*/
  7465. +
  7466. +#ifndef NV_PAIR_LIST_H
  7467. +#define NV_PAIR_LIST_H
  7468. +
  7469. +#include "nv_pair.h"
  7470. +#include "void_list.h"
  7471. +
  7472. +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
  7473. +struct nv_pair_list_elt
  7474. +{
  7475. + nv_pair_list_elt_t *next;
  7476. + nv_pair_t *data;
  7477. +};
  7478. +
  7479. +typedef struct nv_pair_list nv_pair_list_t;
  7480. +struct nv_pair_list
  7481. +{
  7482. + nv_pair_list_elt_t pre_head;
  7483. + nv_pair_list_elt_t *head;
  7484. + nv_pair_list_elt_t *tail;
  7485. +};
  7486. +
  7487. +static inline int nv_pair_list_empty(nv_pair_list_t *list)
  7488. +{
  7489. + if (list->head == NULL)
  7490. + return 1;
  7491. + else
  7492. + return 0;
  7493. +}
  7494. +
  7495. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
  7496. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
  7497. +
  7498. +int nv_pair_list_init(nv_pair_list_t *list);
  7499. +void nv_pair_list_deinit(nv_pair_list_t *list);
  7500. +
  7501. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
  7502. + const char *name, const char *value);
  7503. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
  7504. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
  7505. +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
  7506. +
  7507. +#endif
  7508. +
  7509. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg.c busybox-1.17.0/archival/libipkg/pkg.c
  7510. --- busybox-1.17.0.orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
  7511. +++ busybox-1.17.0/archival/libipkg/pkg.c 2010-07-08 12:01:56.239000923 +0200
  7512. @@ -0,0 +1,1757 @@
  7513. +/* pkg.c - the itsy package management system
  7514. +
  7515. + Carl D. Worth
  7516. +
  7517. + Copyright (C) 2001 University of Southern California
  7518. +
  7519. + This program is free software; you can redistribute it and/or
  7520. + modify it under the terms of the GNU General Public License as
  7521. + published by the Free Software Foundation; either version 2, or (at
  7522. + your option) any later version.
  7523. +
  7524. + This program is distributed in the hope that it will be useful, but
  7525. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7526. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7527. + General Public License for more details.
  7528. +*/
  7529. +
  7530. +#include "ipkg.h"
  7531. +#include <ctype.h>
  7532. +#include <string.h>
  7533. +#include <errno.h>
  7534. +
  7535. +#include "pkg.h"
  7536. +
  7537. +#include "pkg_parse.h"
  7538. +#include "pkg_extract.h"
  7539. +#include "ipkg_message.h"
  7540. +#include "ipkg_utils.h"
  7541. +
  7542. +#include "sprintf_alloc.h"
  7543. +#include "file_util.h"
  7544. +#include "str_util.h"
  7545. +#include "xsystem.h"
  7546. +#include "ipkg_conf.h"
  7547. +
  7548. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname);
  7549. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_);
  7550. +
  7551. +typedef struct enum_map enum_map_t;
  7552. +struct enum_map
  7553. +{
  7554. + int value;
  7555. + const char *str;
  7556. +};
  7557. +
  7558. +static const enum_map_t pkg_state_want_map[] = {
  7559. + { SW_UNKNOWN, "unknown"},
  7560. + { SW_INSTALL, "install"},
  7561. + { SW_DEINSTALL, "deinstall"},
  7562. + { SW_PURGE, "purge"}
  7563. +};
  7564. +
  7565. +static const enum_map_t pkg_state_flag_map[] = {
  7566. + { SF_OK, "ok"},
  7567. + { SF_REINSTREQ, "reinstreq"},
  7568. + { SF_HOLD, "hold"},
  7569. + { SF_REPLACE, "replace"},
  7570. + { SF_NOPRUNE, "noprune"},
  7571. + { SF_PREFER, "prefer"},
  7572. + { SF_OBSOLETE, "obsolete"},
  7573. + { SF_USER, "user"},
  7574. +};
  7575. +
  7576. +static const enum_map_t pkg_state_status_map[] = {
  7577. + { SS_NOT_INSTALLED, "not-installed" },
  7578. + { SS_UNPACKED, "unpacked" },
  7579. + { SS_HALF_CONFIGURED, "half-configured" },
  7580. + { SS_INSTALLED, "installed" },
  7581. + { SS_HALF_INSTALLED, "half-installed" },
  7582. + { SS_CONFIG_FILES, "config-files" },
  7583. + { SS_POST_INST_FAILED, "post-inst-failed" },
  7584. + { SS_REMOVAL_FAILED, "removal-failed" }
  7585. +};
  7586. +
  7587. +static int verrevcmp(const char *val, const char *ref);
  7588. +
  7589. +
  7590. +pkg_t *pkg_new(void)
  7591. +{
  7592. + pkg_t *pkg;
  7593. +
  7594. + pkg = malloc(sizeof(pkg_t));
  7595. + if (pkg == NULL) {
  7596. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7597. + return NULL;
  7598. + }
  7599. +
  7600. + pkg_init(pkg);
  7601. +
  7602. + return pkg;
  7603. +}
  7604. +
  7605. +int pkg_init(pkg_t *pkg)
  7606. +{
  7607. + memset(pkg, 0, sizeof(pkg_t));
  7608. + pkg->name = NULL;
  7609. + pkg->epoch = 0;
  7610. + pkg->version = NULL;
  7611. + pkg->revision = NULL;
  7612. + pkg->familiar_revision = NULL;
  7613. + pkg->dest = NULL;
  7614. + pkg->src = NULL;
  7615. + pkg->architecture = NULL;
  7616. + pkg->maintainer = NULL;
  7617. + pkg->section = NULL;
  7618. + pkg->description = NULL;
  7619. + pkg->state_want = SW_UNKNOWN;
  7620. + pkg->state_flag = SF_OK;
  7621. + pkg->state_status = SS_NOT_INSTALLED;
  7622. + pkg->depends_str = NULL;
  7623. + pkg->provides_str = NULL;
  7624. + pkg->depends_count = 0;
  7625. + pkg->depends = NULL;
  7626. + pkg->suggests_str = NULL;
  7627. + pkg->recommends_str = NULL;
  7628. + pkg->suggests_count = 0;
  7629. + pkg->recommends_count = 0;
  7630. +
  7631. + /* Abhaya: added init for conflicts fields */
  7632. + pkg->conflicts = NULL;
  7633. + pkg->conflicts_count = 0;
  7634. +
  7635. + /* added for replaces. Jamey 7/23/2002 */
  7636. + pkg->replaces = NULL;
  7637. + pkg->replaces_count = 0;
  7638. +
  7639. + pkg->pre_depends_count = 0;
  7640. + pkg->pre_depends_str = NULL;
  7641. + pkg->provides_count = 0;
  7642. + pkg->provides = NULL;
  7643. + pkg->filename = NULL;
  7644. + pkg->local_filename = NULL;
  7645. + pkg->tmp_unpack_dir = NULL;
  7646. + pkg->md5sum = NULL;
  7647. + pkg->size = NULL;
  7648. + pkg->installed_size = NULL;
  7649. + pkg->priority = NULL;
  7650. + pkg->source = NULL;
  7651. + conffile_list_init(&pkg->conffiles);
  7652. + pkg->installed_files = NULL;
  7653. + pkg->installed_files_ref_cnt = 0;
  7654. + pkg->essential = 0;
  7655. + pkg->provided_by_hand = 0;
  7656. +
  7657. + return 0;
  7658. +}
  7659. +
  7660. +void pkg_deinit(pkg_t *pkg)
  7661. +{
  7662. + free(pkg->name);
  7663. + pkg->name = NULL;
  7664. + pkg->epoch = 0;
  7665. + free(pkg->version);
  7666. + pkg->version = NULL;
  7667. + /* revision and familiar_revision share storage with version, so
  7668. + don't free */
  7669. + pkg->revision = NULL;
  7670. + pkg->familiar_revision = NULL;
  7671. + /* owned by ipkg_conf_t */
  7672. + pkg->dest = NULL;
  7673. + /* owned by ipkg_conf_t */
  7674. + pkg->src = NULL;
  7675. + free(pkg->architecture);
  7676. + pkg->architecture = NULL;
  7677. + free(pkg->maintainer);
  7678. + pkg->maintainer = NULL;
  7679. + free(pkg->section);
  7680. + pkg->section = NULL;
  7681. + free(pkg->description);
  7682. + pkg->description = NULL;
  7683. + pkg->state_want = SW_UNKNOWN;
  7684. + pkg->state_flag = SF_OK;
  7685. + pkg->state_status = SS_NOT_INSTALLED;
  7686. + free(pkg->depends_str);
  7687. + pkg->depends_str = NULL;
  7688. + free(pkg->provides_str);
  7689. + pkg->provides_str = NULL;
  7690. + pkg->depends_count = 0;
  7691. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
  7692. + pkg->pre_depends_count = 0;
  7693. + free(pkg->pre_depends_str);
  7694. + pkg->pre_depends_str = NULL;
  7695. + pkg->provides_count = 0;
  7696. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
  7697. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
  7698. + free(pkg->filename);
  7699. + pkg->filename = NULL;
  7700. + free(pkg->local_filename);
  7701. + pkg->local_filename = NULL;
  7702. + /* CLEANUP: It'd be nice to pullin the cleanup function from
  7703. + ipkg_install.c here. See comment in
  7704. + ipkg_install.c:cleanup_temporary_files */
  7705. + free(pkg->tmp_unpack_dir);
  7706. + pkg->tmp_unpack_dir = NULL;
  7707. + free(pkg->md5sum);
  7708. + pkg->md5sum = NULL;
  7709. + free(pkg->size);
  7710. + pkg->size = NULL;
  7711. + free(pkg->installed_size);
  7712. + pkg->installed_size = NULL;
  7713. + free(pkg->priority);
  7714. + pkg->priority = NULL;
  7715. + free(pkg->source);
  7716. + pkg->source = NULL;
  7717. + conffile_list_deinit(&pkg->conffiles);
  7718. + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
  7719. + since if they are calling deinit, they should know. Maybe do an
  7720. + assertion here instead? */
  7721. + pkg->installed_files_ref_cnt = 1;
  7722. + pkg_free_installed_files(pkg);
  7723. + pkg->essential = 0;
  7724. +}
  7725. +
  7726. +int pkg_init_from_file(pkg_t *pkg, const char *filename)
  7727. +{
  7728. + int err;
  7729. + char **raw;
  7730. + FILE *control_file;
  7731. +
  7732. + err = pkg_init(pkg);
  7733. + if (err) { return err; }
  7734. +
  7735. + pkg->local_filename = strdup(filename);
  7736. +
  7737. + control_file = tmpfile();
  7738. + err = pkg_extract_control_file_to_stream(pkg, control_file);
  7739. + if (err) { return err; }
  7740. +
  7741. + rewind(control_file);
  7742. + raw = read_raw_pkgs_from_stream(control_file);
  7743. + pkg_parse_raw(pkg, &raw, NULL, NULL);
  7744. +
  7745. + fclose(control_file);
  7746. +
  7747. + return 0;
  7748. +}
  7749. +
  7750. +/* Merge any new information in newpkg into oldpkg */
  7751. +/* XXX: CLEANUP: This function shouldn't actually modify anything in
  7752. + newpkg, but should leave it usable. This rework is so that
  7753. + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
  7754. +/*
  7755. + * uh, i thought that i had originally written this so that it took
  7756. + * two pkgs and returned a new one? we can do that again... -sma
  7757. + */
  7758. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
  7759. +{
  7760. + if (oldpkg == newpkg) {
  7761. + return 0;
  7762. + }
  7763. +
  7764. + if (!oldpkg->src)
  7765. + oldpkg->src = newpkg->src;
  7766. + if (!oldpkg->dest)
  7767. + oldpkg->dest = newpkg->dest;
  7768. + if (!oldpkg->architecture)
  7769. + oldpkg->architecture = str_dup_safe(newpkg->architecture);
  7770. + if (!oldpkg->arch_priority)
  7771. + oldpkg->arch_priority = newpkg->arch_priority;
  7772. + if (!oldpkg->section)
  7773. + oldpkg->section = str_dup_safe(newpkg->section);
  7774. + if(!oldpkg->maintainer)
  7775. + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
  7776. + if(!oldpkg->description)
  7777. + oldpkg->description = str_dup_safe(newpkg->description);
  7778. + if (set_status) {
  7779. + /* merge the state_flags from the new package */
  7780. + oldpkg->state_want = newpkg->state_want;
  7781. + oldpkg->state_status = newpkg->state_status;
  7782. + oldpkg->state_flag = newpkg->state_flag;
  7783. + } else {
  7784. + if (oldpkg->state_want == SW_UNKNOWN)
  7785. + oldpkg->state_want = newpkg->state_want;
  7786. + if (oldpkg->state_status == SS_NOT_INSTALLED)
  7787. + oldpkg->state_status = newpkg->state_status;
  7788. + oldpkg->state_flag |= newpkg->state_flag;
  7789. + }
  7790. +
  7791. + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
  7792. + oldpkg->depends_str = newpkg->depends_str;
  7793. + newpkg->depends_str = NULL;
  7794. + oldpkg->depends_count = newpkg->depends_count;
  7795. + newpkg->depends_count = 0;
  7796. +
  7797. + oldpkg->depends = newpkg->depends;
  7798. + newpkg->depends = NULL;
  7799. +
  7800. + oldpkg->pre_depends_str = newpkg->pre_depends_str;
  7801. + newpkg->pre_depends_str = NULL;
  7802. + oldpkg->pre_depends_count = newpkg->pre_depends_count;
  7803. + newpkg->pre_depends_count = 0;
  7804. +
  7805. + oldpkg->recommends_str = newpkg->recommends_str;
  7806. + newpkg->recommends_str = NULL;
  7807. + oldpkg->recommends_count = newpkg->recommends_count;
  7808. + newpkg->recommends_count = 0;
  7809. +
  7810. + oldpkg->suggests_str = newpkg->suggests_str;
  7811. + newpkg->suggests_str = NULL;
  7812. + oldpkg->suggests_count = newpkg->suggests_count;
  7813. + newpkg->suggests_count = 0;
  7814. + }
  7815. +
  7816. + if (!oldpkg->provides_str) {
  7817. + oldpkg->provides_str = newpkg->provides_str;
  7818. + newpkg->provides_str = NULL;
  7819. + oldpkg->provides_count = newpkg->provides_count;
  7820. + newpkg->provides_count = 0;
  7821. +
  7822. + oldpkg->provides = newpkg->provides;
  7823. + newpkg->provides = NULL;
  7824. + }
  7825. +
  7826. + if (!oldpkg->conflicts_str) {
  7827. + oldpkg->conflicts_str = newpkg->conflicts_str;
  7828. + newpkg->conflicts_str = NULL;
  7829. + oldpkg->conflicts_count = newpkg->conflicts_count;
  7830. + newpkg->conflicts_count = 0;
  7831. +
  7832. + oldpkg->conflicts = newpkg->conflicts;
  7833. + newpkg->conflicts = NULL;
  7834. + }
  7835. +
  7836. + if (!oldpkg->replaces_str) {
  7837. + oldpkg->replaces_str = newpkg->replaces_str;
  7838. + newpkg->replaces_str = NULL;
  7839. + oldpkg->replaces_count = newpkg->replaces_count;
  7840. + newpkg->replaces_count = 0;
  7841. +
  7842. + oldpkg->replaces = newpkg->replaces;
  7843. + newpkg->replaces = NULL;
  7844. + }
  7845. +
  7846. + if (!oldpkg->filename)
  7847. + oldpkg->filename = str_dup_safe(newpkg->filename);
  7848. + if (0)
  7849. + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
  7850. + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
  7851. + if (!oldpkg->local_filename)
  7852. + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
  7853. + if (!oldpkg->tmp_unpack_dir)
  7854. + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
  7855. + if (!oldpkg->md5sum)
  7856. + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
  7857. + if (!oldpkg->size)
  7858. + oldpkg->size = str_dup_safe(newpkg->size);
  7859. + if (!oldpkg->installed_size)
  7860. + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
  7861. + if (!oldpkg->priority)
  7862. + oldpkg->priority = str_dup_safe(newpkg->priority);
  7863. + if (!oldpkg->source)
  7864. + oldpkg->source = str_dup_safe(newpkg->source);
  7865. + if (oldpkg->conffiles.head == NULL){
  7866. + oldpkg->conffiles = newpkg->conffiles;
  7867. + conffile_list_init(&newpkg->conffiles);
  7868. + }
  7869. + if (!oldpkg->installed_files){
  7870. + oldpkg->installed_files = newpkg->installed_files;
  7871. + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
  7872. + newpkg->installed_files = NULL;
  7873. + }
  7874. + if (!oldpkg->essential)
  7875. + oldpkg->essential = newpkg->essential;
  7876. +
  7877. + return 0;
  7878. +}
  7879. +
  7880. +abstract_pkg_t *abstract_pkg_new(void)
  7881. +{
  7882. + abstract_pkg_t * ab_pkg;
  7883. +
  7884. + ab_pkg = malloc(sizeof(abstract_pkg_t));
  7885. +
  7886. + if (ab_pkg == NULL) {
  7887. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7888. + return NULL;
  7889. + }
  7890. +
  7891. + if ( abstract_pkg_init(ab_pkg) < 0 )
  7892. + return NULL;
  7893. +
  7894. + return ab_pkg;
  7895. +}
  7896. +
  7897. +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
  7898. +{
  7899. + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
  7900. +
  7901. + ab_pkg->provided_by = abstract_pkg_vec_alloc();
  7902. + if (ab_pkg->provided_by==NULL){
  7903. + return -1;
  7904. + }
  7905. + ab_pkg->dependencies_checked = 0;
  7906. + ab_pkg->state_status = SS_NOT_INSTALLED;
  7907. +
  7908. + return 0;
  7909. +}
  7910. +
  7911. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
  7912. + char * temp_str;
  7913. + char **raw =NULL;
  7914. + char **raw_start=NULL;
  7915. +
  7916. + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
  7917. + if (temp_str == NULL ){
  7918. + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
  7919. + return;
  7920. + }
  7921. + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
  7922. +
  7923. + raw = raw_start = read_raw_pkgs_from_file(temp_str);
  7924. + if (raw == NULL ){
  7925. + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
  7926. + return;
  7927. + }
  7928. +
  7929. + while(*raw){
  7930. + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
  7931. + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
  7932. + }
  7933. + }
  7934. + raw = raw_start;
  7935. + while (*raw) {
  7936. + if (raw!=NULL)
  7937. + free(*raw++);
  7938. + }
  7939. +
  7940. + free(raw_start);
  7941. + free(temp_str);
  7942. +
  7943. + return ;
  7944. +
  7945. +}
  7946. +
  7947. +char * pkg_formatted_info(pkg_t *pkg )
  7948. +{
  7949. + char *line;
  7950. + char * buff;
  7951. +
  7952. + buff = malloc(8192);
  7953. + if (buff == NULL) {
  7954. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7955. + return NULL;
  7956. + }
  7957. +
  7958. + buff[0] = '\0';
  7959. +
  7960. + line = pkg_formatted_field(pkg, "Package");
  7961. + strncat(buff ,line, strlen(line));
  7962. + free(line);
  7963. +
  7964. + line = pkg_formatted_field(pkg, "Version");
  7965. + strncat(buff ,line, strlen(line));
  7966. + free(line);
  7967. +
  7968. + line = pkg_formatted_field(pkg, "Depends");
  7969. + strncat(buff ,line, strlen(line));
  7970. + free(line);
  7971. +
  7972. + line = pkg_formatted_field(pkg, "Recommends");
  7973. + strncat(buff ,line, strlen(line));
  7974. + free(line);
  7975. +
  7976. + line = pkg_formatted_field(pkg, "Suggests");
  7977. + strncat(buff ,line, strlen(line));
  7978. + free(line);
  7979. +
  7980. + line = pkg_formatted_field(pkg, "Provides");
  7981. + strncat(buff ,line, strlen(line));
  7982. + free(line);
  7983. +
  7984. + line = pkg_formatted_field(pkg, "Replaces");
  7985. + strncat(buff ,line, strlen(line));
  7986. + free(line);
  7987. +
  7988. + line = pkg_formatted_field(pkg, "Conflicts");
  7989. + strncat(buff ,line, strlen(line));
  7990. + free(line);
  7991. +
  7992. + line = pkg_formatted_field(pkg, "Status");
  7993. + strncat(buff ,line, strlen(line));
  7994. + free(line);
  7995. +
  7996. + line = pkg_formatted_field(pkg, "Section");
  7997. + strncat(buff ,line, strlen(line));
  7998. + free(line);
  7999. +
  8000. + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
  8001. + strncat(buff ,line, strlen(line));
  8002. + free(line);
  8003. +
  8004. + line = pkg_formatted_field(pkg, "Architecture");
  8005. + strncat(buff ,line, strlen(line));
  8006. + free(line);
  8007. +
  8008. + line = pkg_formatted_field(pkg, "Maintainer");
  8009. + strncat(buff ,line, strlen(line));
  8010. + free(line);
  8011. +
  8012. + line = pkg_formatted_field(pkg, "MD5sum");
  8013. + strncat(buff ,line, strlen(line));
  8014. + free(line);
  8015. +
  8016. + line = pkg_formatted_field(pkg, "Size");
  8017. + strncat(buff ,line, strlen(line));
  8018. + free(line);
  8019. +
  8020. + line = pkg_formatted_field(pkg, "Filename");
  8021. + strncat(buff ,line, strlen(line));
  8022. + free(line);
  8023. +
  8024. + line = pkg_formatted_field(pkg, "Conffiles");
  8025. + strncat(buff ,line, strlen(line));
  8026. + free(line);
  8027. +
  8028. + line = pkg_formatted_field(pkg, "Source");
  8029. + strncat(buff ,line, strlen(line));
  8030. + free(line);
  8031. +
  8032. + line = pkg_formatted_field(pkg, "Description");
  8033. + strncat(buff ,line, strlen(line));
  8034. + free(line);
  8035. +
  8036. + line = pkg_formatted_field(pkg, "Installed-Time");
  8037. + strncat(buff ,line, strlen(line));
  8038. + free(line);
  8039. +
  8040. + return buff;
  8041. +}
  8042. +
  8043. +char * pkg_formatted_field(pkg_t *pkg, const char *field )
  8044. +{
  8045. + static size_t LINE_LEN = 128;
  8046. + char * temp = (char *)malloc(1);
  8047. + int len = 0;
  8048. + int flag_provide_false = 0;
  8049. +
  8050. +/*
  8051. + Pigi: After some discussion with Florian we decided to modify the full procedure in
  8052. + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
  8053. +*/
  8054. +
  8055. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8056. + goto UNKNOWN_FMT_FIELD;
  8057. + }
  8058. +
  8059. + temp[0]='\0';
  8060. +
  8061. + switch (field[0])
  8062. + {
  8063. + case 'a':
  8064. + case 'A':
  8065. + if (strcasecmp(field, "Architecture") == 0) {
  8066. + /* Architecture */
  8067. + if (pkg->architecture) {
  8068. + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
  8069. + if ( temp == NULL ){
  8070. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8071. + return NULL;
  8072. + }
  8073. + temp[0]='\0';
  8074. + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
  8075. + }
  8076. + } else {
  8077. + goto UNKNOWN_FMT_FIELD;
  8078. + }
  8079. + break;
  8080. + case 'c':
  8081. + case 'C':
  8082. + if (strcasecmp(field, "Conffiles") == 0) {
  8083. + /* Conffiles */
  8084. + conffile_list_elt_t *iter;
  8085. + char confstr_[LINE_LEN];
  8086. +
  8087. + if (pkg->conffiles.head == NULL) {
  8088. + return temp;
  8089. + }
  8090. +
  8091. + len = 14 ;
  8092. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8093. + if (iter->data->name && iter->data->value) {
  8094. + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
  8095. + }
  8096. + }
  8097. + temp = (char *)realloc(temp,len);
  8098. + if ( temp == NULL ){
  8099. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8100. + return NULL;
  8101. + }
  8102. + temp[0]='\0';
  8103. + strncpy(temp, "Conffiles:\n", 12);
  8104. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8105. + if (iter->data->name && iter->data->value) {
  8106. + snprintf(confstr_, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
  8107. + strncat(temp, confstr_, strlen(confstr_));
  8108. + }
  8109. + }
  8110. + } else if (strcasecmp(field, "Conflicts") == 0) {
  8111. + int i;
  8112. +
  8113. + if (pkg->conflicts_count) {
  8114. + char conflictstr[LINE_LEN];
  8115. + len = 14 ;
  8116. + for(i = 0; i < pkg->conflicts_count; i++) {
  8117. + len = len + (strlen(pkg->conflicts_str[i])+5);
  8118. + }
  8119. + temp = (char *)realloc(temp,len);
  8120. + if ( temp == NULL ){
  8121. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8122. + return NULL;
  8123. + }
  8124. + temp[0]='\0';
  8125. + strncpy(temp, "Conflicts:", 11);
  8126. + for(i = 0; i < pkg->conflicts_count; i++) {
  8127. + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
  8128. + strncat(temp, conflictstr, strlen(conflictstr));
  8129. + }
  8130. + strncat(temp, "\n", strlen("\n"));
  8131. + }
  8132. + } else {
  8133. + goto UNKNOWN_FMT_FIELD;
  8134. + }
  8135. + break;
  8136. + case 'd':
  8137. + case 'D':
  8138. + if (strcasecmp(field, "Depends") == 0) {
  8139. + /* Depends */
  8140. + int i;
  8141. +
  8142. + if (pkg->depends_count) {
  8143. + char depstr[LINE_LEN];
  8144. + len = 14 ;
  8145. + for(i = 0; i < pkg->depends_count; i++) {
  8146. + len = len + (strlen(pkg->depends_str[i])+4);
  8147. + }
  8148. + temp = (char *)realloc(temp,len);
  8149. + if ( temp == NULL ){
  8150. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8151. + return NULL;
  8152. + }
  8153. + temp[0]='\0';
  8154. + strncpy(temp, "Depends:", 10);
  8155. + for(i = 0; i < pkg->depends_count; i++) {
  8156. + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
  8157. + strncat(temp, depstr, strlen(depstr));
  8158. + }
  8159. + strncat(temp, "\n", strlen("\n"));
  8160. + }
  8161. + } else if (strcasecmp(field, "Description") == 0) {
  8162. + /* Description */
  8163. + if (pkg->description) {
  8164. + temp = (char *)realloc(temp,strlen(pkg->description)+16);
  8165. + if ( temp == NULL ){
  8166. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8167. + return NULL;
  8168. + }
  8169. + temp[0]='\0';
  8170. + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
  8171. + }
  8172. + } else {
  8173. + goto UNKNOWN_FMT_FIELD;
  8174. + }
  8175. + break;
  8176. + case 'e':
  8177. + case 'E': {
  8178. + /* Essential */
  8179. + if (pkg->essential) {
  8180. + temp = (char *)realloc(temp,16);
  8181. + if ( temp == NULL ){
  8182. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8183. + return NULL;
  8184. + }
  8185. + temp[0]='\0';
  8186. + snprintf(temp, (16), "Essential: yes\n");
  8187. + }
  8188. + }
  8189. + break;
  8190. + case 'f':
  8191. + case 'F': {
  8192. + /* Filename */
  8193. + if (pkg->filename) {
  8194. + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
  8195. + if ( temp == NULL ){
  8196. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8197. + return NULL;
  8198. + }
  8199. + temp[0]='\0';
  8200. + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
  8201. + }
  8202. + }
  8203. + break;
  8204. + case 'i':
  8205. + case 'I': {
  8206. + if (strcasecmp(field, "Installed-Size") == 0) {
  8207. + /* Installed-Size */
  8208. + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
  8209. + if ( temp == NULL ){
  8210. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8211. + return NULL;
  8212. + }
  8213. + temp[0]='\0';
  8214. + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
  8215. + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
  8216. + temp = (char *)realloc(temp,29);
  8217. + if ( temp == NULL ){
  8218. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8219. + return NULL;
  8220. + }
  8221. + temp[0]='\0';
  8222. + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
  8223. + }
  8224. + }
  8225. + break;
  8226. + case 'm':
  8227. + case 'M': {
  8228. + /* Maintainer | MD5sum */
  8229. + if (strcasecmp(field, "Maintainer") == 0) {
  8230. + /* Maintainer */
  8231. + if (pkg->maintainer) {
  8232. + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
  8233. + if ( temp == NULL ){
  8234. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8235. + return NULL;
  8236. + }
  8237. + temp[0]='\0';
  8238. + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
  8239. + }
  8240. + } else if (strcasecmp(field, "MD5sum") == 0) {
  8241. + /* MD5sum */
  8242. + if (pkg->md5sum) {
  8243. + temp = (char *)realloc(temp,strlen(pkg->md5sum)+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->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
  8250. + }
  8251. + } else {
  8252. + goto UNKNOWN_FMT_FIELD;
  8253. + }
  8254. + }
  8255. + break;
  8256. + case 'p':
  8257. + case 'P': {
  8258. + if (strcasecmp(field, "Package") == 0) {
  8259. + /* Package */
  8260. + temp = (char *)realloc(temp,strlen(pkg->name)+11);
  8261. + if ( temp == NULL ){
  8262. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8263. + return NULL;
  8264. + }
  8265. + temp[0]='\0';
  8266. + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
  8267. + } else if (strcasecmp(field, "Priority") == 0) {
  8268. + /* Priority */
  8269. + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
  8270. + if ( temp == NULL ){
  8271. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8272. + return NULL;
  8273. + }
  8274. + temp[0]='\0';
  8275. + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
  8276. + } else if (strcasecmp(field, "Provides") == 0) {
  8277. + /* Provides */
  8278. + int i;
  8279. +
  8280. + if (pkg->provides_count) {
  8281. + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
  8282. + for ( i=0; i < pkg->provides_count; i++ ){
  8283. + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
  8284. + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
  8285. + flag_provide_false = 1;
  8286. + }
  8287. + }
  8288. + if ( !flag_provide_false || /* Pigi there is not my trick flag */
  8289. + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
  8290. + char provstr[LINE_LEN];
  8291. + len = 15;
  8292. + for(i = 0; i < pkg->provides_count; i++) {
  8293. + len = len + (strlen(pkg->provides_str[i])+5);
  8294. + }
  8295. + temp = (char *)realloc(temp,len);
  8296. + if ( temp == NULL ){
  8297. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8298. + return NULL;
  8299. + }
  8300. + temp[0]='\0';
  8301. + strncpy(temp, "Provides:", 12);
  8302. + for(i = 0; i < pkg->provides_count; i++) {
  8303. + if (strlen(pkg->provides_str[i])>0){;
  8304. + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
  8305. + strncat(temp, provstr, strlen(provstr));
  8306. + }
  8307. + }
  8308. + strncat(temp, "\n", strlen("\n"));
  8309. + }
  8310. + }
  8311. + } else {
  8312. + goto UNKNOWN_FMT_FIELD;
  8313. + }
  8314. + }
  8315. + break;
  8316. + case 'r':
  8317. + case 'R': {
  8318. + int i;
  8319. + /* Replaces | Recommends*/
  8320. + if (strcasecmp (field, "Replaces") == 0) {
  8321. + if (pkg->replaces_count) {
  8322. + char replstr[LINE_LEN];
  8323. + len = 14;
  8324. + for (i = 0; i < pkg->replaces_count; i++) {
  8325. + len = len + (strlen(pkg->replaces_str[i])+5);
  8326. + }
  8327. + temp = (char *)realloc(temp,len);
  8328. + if ( temp == NULL ){
  8329. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8330. + return NULL;
  8331. + }
  8332. + temp[0]='\0';
  8333. + strncpy(temp, "Replaces:", 12);
  8334. + for (i = 0; i < pkg->replaces_count; i++) {
  8335. + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
  8336. + strncat(temp, replstr, strlen(replstr));
  8337. + }
  8338. + strncat(temp, "\n", strlen("\n"));
  8339. + }
  8340. + } else if (strcasecmp (field, "Recommends") == 0) {
  8341. + if (pkg->recommends_count) {
  8342. + char recstr[LINE_LEN];
  8343. + len = 15;
  8344. + for(i = 0; i < pkg->recommends_count; i++) {
  8345. + len = len + (strlen( pkg->recommends_str[i])+5);
  8346. + }
  8347. + temp = (char *)realloc(temp,len);
  8348. + if ( temp == NULL ){
  8349. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8350. + return NULL;
  8351. + }
  8352. + temp[0]='\0';
  8353. + strncpy(temp, "Recommends:", 13);
  8354. + for(i = 0; i < pkg->recommends_count; i++) {
  8355. + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
  8356. + strncat(temp, recstr, strlen(recstr));
  8357. + }
  8358. + strncat(temp, "\n", strlen("\n"));
  8359. + }
  8360. + } else {
  8361. + goto UNKNOWN_FMT_FIELD;
  8362. + }
  8363. + }
  8364. + break;
  8365. + case 's':
  8366. + case 'S': {
  8367. + /* Section | Size | Source | Status | Suggests */
  8368. + if (strcasecmp(field, "Section") == 0) {
  8369. + /* Section */
  8370. + if (pkg->section) {
  8371. + temp = (char *)realloc(temp,strlen(pkg->section)+11);
  8372. + if ( temp == NULL ){
  8373. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8374. + return NULL;
  8375. + }
  8376. + temp[0]='\0';
  8377. + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
  8378. + }
  8379. + } else if (strcasecmp(field, "Size") == 0) {
  8380. + /* Size */
  8381. + if (pkg->size) {
  8382. + temp = (char *)realloc(temp,strlen(pkg->size)+8);
  8383. + if ( temp == NULL ){
  8384. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8385. + return NULL;
  8386. + }
  8387. + temp[0]='\0';
  8388. + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
  8389. + }
  8390. + } else if (strcasecmp(field, "Source") == 0) {
  8391. + /* Source */
  8392. + if (pkg->source) {
  8393. + temp = (char *)realloc(temp,strlen(pkg->source)+10);
  8394. + if ( temp == NULL ){
  8395. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8396. + return NULL;
  8397. + }
  8398. + temp[0]='\0';
  8399. + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
  8400. + }
  8401. + } else if (strcasecmp(field, "Status") == 0) {
  8402. + /* Status */
  8403. + /* Benjamin Pineau note: we should avoid direct usage of
  8404. + * strlen(arg) without keeping "arg" for later free()
  8405. + */
  8406. + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
  8407. + char *pstat=pkg_state_status_to_str(pkg->state_status);
  8408. + char *pwant=pkg_state_want_to_str(pkg->state_want);
  8409. +
  8410. + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
  8411. + temp = (char *)realloc(temp,sum_of_sizes);
  8412. + if ( temp == NULL ){
  8413. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8414. + return NULL;
  8415. + }
  8416. + temp[0]='\0';
  8417. + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
  8418. + free(pflag);
  8419. + free(pwant);
  8420. + if(pstat) /* pfstat can be NULL if ENOMEM */
  8421. + free(pstat);
  8422. + } else if (strcasecmp(field, "Suggests") == 0) {
  8423. + if (pkg->suggests_count) {
  8424. + int i;
  8425. + char sugstr[LINE_LEN];
  8426. + len = 13;
  8427. + for(i = 0; i < pkg->suggests_count; i++) {
  8428. + len = len + (strlen(pkg->suggests_str[i])+5);
  8429. + }
  8430. + temp = (char *)realloc(temp,len);
  8431. + if ( temp == NULL ){
  8432. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8433. + return NULL;
  8434. + }
  8435. + temp[0]='\0';
  8436. + strncpy(temp, "Suggests:", 10);
  8437. + for(i = 0; i < pkg->suggests_count; i++) {
  8438. + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
  8439. + strncat(temp, sugstr, strlen(sugstr));
  8440. + }
  8441. + strncat(temp, "\n", strlen("\n"));
  8442. + }
  8443. + } else {
  8444. + goto UNKNOWN_FMT_FIELD;
  8445. + }
  8446. + }
  8447. + break;
  8448. + case 'v':
  8449. + case 'V': {
  8450. + /* Version */
  8451. + char *version = pkg_version_str_alloc(pkg);
  8452. + temp = (char *)realloc(temp,strlen(version)+14);
  8453. + if ( temp == NULL ){
  8454. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8455. + return NULL;
  8456. + }
  8457. + temp[0]='\0';
  8458. + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
  8459. + free(version);
  8460. + }
  8461. + break;
  8462. + default:
  8463. + goto UNKNOWN_FMT_FIELD;
  8464. + }
  8465. +
  8466. + if ( strlen(temp)<2 ) {
  8467. + temp[0]='\0';
  8468. + }
  8469. + return temp;
  8470. +
  8471. + UNKNOWN_FMT_FIELD:
  8472. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
  8473. + if ( strlen(temp)<2 ) {
  8474. + temp[0]='\0';
  8475. + }
  8476. +
  8477. + return temp;
  8478. +}
  8479. +
  8480. +void pkg_print_info(pkg_t *pkg, FILE *file)
  8481. +{
  8482. + char * buff;
  8483. + if (pkg == NULL) {
  8484. + return;
  8485. + }
  8486. +
  8487. + buff = pkg_formatted_info(pkg);
  8488. + if ( buff == NULL )
  8489. + return;
  8490. + if (strlen(buff)>2){
  8491. + fwrite(buff, 1, strlen(buff), file);
  8492. + }
  8493. + free(buff);
  8494. +}
  8495. +
  8496. +void pkg_print_status(pkg_t * pkg, FILE * file)
  8497. +{
  8498. + if (pkg == NULL) {
  8499. + return;
  8500. + }
  8501. +
  8502. + /* XXX: QUESTION: Do we actually want more fields here? The
  8503. + original idea was to save space by installing only what was
  8504. + needed for actual computation, (package, version, status,
  8505. + essential, conffiles). The assumption is that all other fields
  8506. + can be found in th available file.
  8507. +
  8508. + But, someone proposed the idea to make it possible to
  8509. + reconstruct a .ipk from an installed package, (ie. for beaming
  8510. + from one handheld to another). So, maybe we actually want a few
  8511. + more fields here, (depends, suggests, etc.), so that that would
  8512. + be guaranteed to work even in the absence of more information
  8513. + from the available file.
  8514. +
  8515. + 28-MAR-03: kergoth and I discussed this yesterday. We think
  8516. + the essential info needs to be here for all installed packages
  8517. + because they may not appear in the Packages files on various
  8518. + feeds. Furthermore, one should be able to install from URL or
  8519. + local storage without requiring a Packages file from any feed.
  8520. + -Jamey
  8521. + */
  8522. + pkg_print_field(pkg, file, "Package");
  8523. + pkg_print_field(pkg, file, "Version");
  8524. + pkg_print_field(pkg, file, "Depends");
  8525. + pkg_print_field(pkg, file, "Recommends");
  8526. + pkg_print_field(pkg, file, "Suggests");
  8527. + pkg_print_field(pkg, file, "Provides");
  8528. + pkg_print_field(pkg, file, "Replaces");
  8529. + pkg_print_field(pkg, file, "Conflicts");
  8530. + pkg_print_field(pkg, file, "Status");
  8531. + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
  8532. + pkg_print_field(pkg, file, "Architecture");
  8533. + pkg_print_field(pkg, file, "Conffiles");
  8534. + pkg_print_field(pkg, file, "Installed-Time");
  8535. + fputs("\n", file);
  8536. +}
  8537. +
  8538. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
  8539. +{
  8540. + char *buff;
  8541. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8542. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
  8543. + __FUNCTION__, field);
  8544. + }
  8545. + buff = pkg_formatted_field(pkg, field);
  8546. + if (strlen(buff)>2) {
  8547. + fprintf(file, "%s", buff);
  8548. + fflush(file);
  8549. + }
  8550. + free(buff);
  8551. + return;
  8552. +}
  8553. +
  8554. +/*
  8555. + * libdpkg - Debian packaging suite library routines
  8556. + * vercmp.c - comparison of version numbers
  8557. + *
  8558. + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  8559. + */
  8560. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
  8561. +{
  8562. + int r;
  8563. +
  8564. + if (pkg->epoch > ref_pkg->epoch) {
  8565. + return 1;
  8566. + }
  8567. +
  8568. + if (pkg->epoch < ref_pkg->epoch) {
  8569. + return -1;
  8570. + }
  8571. +
  8572. + r = verrevcmp(pkg->version, ref_pkg->version);
  8573. + if (r) {
  8574. + return r;
  8575. + }
  8576. +
  8577. +#ifdef USE_DEBVERSION
  8578. + r = verrevcmp(pkg->revision, ref_pkg->revision);
  8579. + if (r) {
  8580. + return r;
  8581. + }
  8582. +
  8583. + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
  8584. +#endif
  8585. +
  8586. + return r;
  8587. +}
  8588. +
  8589. +int verrevcmp(const char *val, const char *ref)
  8590. +{
  8591. + int vc, rc;
  8592. + long vl, rl;
  8593. + const char *vp, *rp;
  8594. + const char *vsep, *rsep;
  8595. +
  8596. + if (!val) val= "";
  8597. + if (!ref) ref= "";
  8598. + for (;;) {
  8599. + vp= val; while (*vp && !isdigit(*vp)) vp++;
  8600. + rp= ref; while (*rp && !isdigit(*rp)) rp++;
  8601. + for (;;) {
  8602. + vc= (val == vp) ? 0 : *val++;
  8603. + rc= (ref == rp) ? 0 : *ref++;
  8604. + if (!rc && !vc) break;
  8605. + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
  8606. + if (rc && !isalpha(rc)) rc += 256;
  8607. + if (vc != rc) return vc - rc;
  8608. + }
  8609. + val= vp;
  8610. + ref= rp;
  8611. + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
  8612. + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
  8613. + if (vl != rl) return vl - rl;
  8614. +
  8615. + vc = *val;
  8616. + rc = *ref;
  8617. + vsep = strchr(".-", vc);
  8618. + rsep = strchr(".-", rc);
  8619. + if (vsep && !rsep) return -1;
  8620. + if (!vsep && rsep) return +1;
  8621. +
  8622. + if (!*val && !*ref) return 0;
  8623. + if (!*val) return -1;
  8624. + if (!*ref) return +1;
  8625. + }
  8626. +}
  8627. +
  8628. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
  8629. +{
  8630. + int r;
  8631. +
  8632. + r = pkg_compare_versions(it, ref);
  8633. +
  8634. + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
  8635. + return r <= 0;
  8636. + }
  8637. +
  8638. + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
  8639. + return r >= 0;
  8640. + }
  8641. +
  8642. + if (strcmp(op, "<<") == 0) {
  8643. + return r < 0;
  8644. + }
  8645. +
  8646. + if (strcmp(op, ">>") == 0) {
  8647. + return r > 0;
  8648. + }
  8649. +
  8650. + if (strcmp(op, "=") == 0) {
  8651. + return r == 0;
  8652. + }
  8653. +
  8654. + fprintf(stderr, "unknown operator: %s", op);
  8655. + return 0;
  8656. +}
  8657. +
  8658. +int pkg_name_version_and_architecture_compare(pkg_t *p1, pkg_t *p2)
  8659. +{
  8660. + const pkg_t *a = *(const pkg_t **)p1;
  8661. + const pkg_t *b = *(const pkg_t **)p2;
  8662. + int namecmp;
  8663. + int vercmp;
  8664. + if (!a->name || !b->name) {
  8665. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8666. + a, a->name, b, b->name);
  8667. + return 0;
  8668. + }
  8669. +
  8670. + namecmp = strcmp(a->name, b->name);
  8671. + if (namecmp)
  8672. + return namecmp;
  8673. + vercmp = pkg_compare_versions(a, b);
  8674. + if (vercmp)
  8675. + return vercmp;
  8676. + if (!a->arch_priority || !b->arch_priority) {
  8677. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
  8678. + a, a->arch_priority, b, b->arch_priority);
  8679. + return 0;
  8680. + }
  8681. + if (a->arch_priority > b->arch_priority)
  8682. + return 1;
  8683. + if (a->arch_priority < b->arch_priority)
  8684. + return -1;
  8685. + return 0;
  8686. +}
  8687. +
  8688. +int abstract_pkg_name_compare(abstract_pkg_t *p1, abstract_pkg_t *p2)
  8689. +{
  8690. + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
  8691. + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
  8692. + if (!a->name || !b->name) {
  8693. + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8694. + a, a->name, b, b->name);
  8695. + return 0;
  8696. + }
  8697. + return strcmp(a->name, b->name);
  8698. +}
  8699. +
  8700. +
  8701. +char *pkg_version_str_alloc(pkg_t *pkg)
  8702. +{
  8703. + char *complete_version;
  8704. + char *epoch_str;
  8705. +#ifdef USE_DEBVERSION
  8706. + char *revision_str;
  8707. + char *familiar_revision_str;
  8708. +#endif
  8709. +
  8710. + if (pkg->epoch) {
  8711. + sprintf_alloc(&epoch_str, "%lu:", (unsigned long)pkg->epoch);
  8712. + } else {
  8713. + epoch_str = strdup("");
  8714. + }
  8715. +
  8716. +#ifdef USE_DEBVERSION
  8717. + if (pkg->revision && strlen(pkg->revision)) {
  8718. + sprintf_alloc(&revision_str, "-%s", pkg->revision);
  8719. + } else {
  8720. + revision_str = strdup("");
  8721. + }
  8722. +
  8723. + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
  8724. + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
  8725. + } else {
  8726. + familiar_revision_str = strdup("");
  8727. + }
  8728. +#endif
  8729. +
  8730. +#ifdef USE_DEBVERSION
  8731. + sprintf_alloc(&complete_version, "%s%s%s%s",
  8732. + epoch_str, pkg->version, revision_str, familiar_revision_str);
  8733. +#else
  8734. + sprintf_alloc(&complete_version, "%s%s",
  8735. + epoch_str, pkg->version);
  8736. +#endif
  8737. +
  8738. + free(epoch_str);
  8739. +#ifdef USE_DEBVERSION
  8740. + free(revision_str);
  8741. + free(familiar_revision_str);
  8742. +#endif
  8743. +
  8744. + return complete_version;
  8745. +}
  8746. +
  8747. +str_list_t *pkg_get_installed_files(pkg_t *pkg)
  8748. +{
  8749. + int err;
  8750. + char *list_file_name = NULL;
  8751. + FILE *list_file = NULL;
  8752. + char *line;
  8753. + char *installed_file_name;
  8754. + int rootdirlen;
  8755. +
  8756. + pkg->installed_files_ref_cnt++;
  8757. +
  8758. + if (pkg->installed_files) {
  8759. + return pkg->installed_files;
  8760. + }
  8761. +
  8762. + pkg->installed_files = str_list_alloc();
  8763. + if (pkg->installed_files == NULL) {
  8764. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8765. + return NULL;
  8766. + }
  8767. +
  8768. + /* For uninstalled packages, get the file list firectly from the package.
  8769. + For installed packages, look at the package.list file in the database.
  8770. + */
  8771. + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
  8772. + if (pkg->local_filename == NULL) {
  8773. + return pkg->installed_files;
  8774. + }
  8775. + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
  8776. + file. In other words, change deb_extract so that it can
  8777. + simply return the file list as a char *[] rather than
  8778. + insisting on writing in to a FILE * as it does now. */
  8779. + list_file = tmpfile();
  8780. + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
  8781. + if (err) {
  8782. + fclose(list_file);
  8783. + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
  8784. + __FUNCTION__, pkg->local_filename, strerror(err));
  8785. + return pkg->installed_files;
  8786. + }
  8787. + rewind(list_file);
  8788. + } else {
  8789. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8790. + pkg->dest->info_dir, pkg->name);
  8791. + if (! file_exists(list_file_name)) {
  8792. + free(list_file_name);
  8793. + return pkg->installed_files;
  8794. + }
  8795. +
  8796. + list_file = fopen(list_file_name, "r");
  8797. + if (list_file == NULL) {
  8798. + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
  8799. + list_file_name, strerror(errno));
  8800. + free(list_file_name);
  8801. + return pkg->installed_files;
  8802. + }
  8803. + free(list_file_name);
  8804. + }
  8805. +
  8806. + rootdirlen = strlen( pkg->dest->root_dir );
  8807. + while (1) {
  8808. + char *file_name;
  8809. +
  8810. + line = file_read_line_alloc(list_file);
  8811. + if (line == NULL) {
  8812. + break;
  8813. + }
  8814. + str_chomp(line);
  8815. + file_name = line;
  8816. +
  8817. + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
  8818. + if( strncmp( pkg->dest->root_dir,
  8819. + file_name,
  8820. + rootdirlen ) ) {
  8821. + if (*file_name == '.') {
  8822. + file_name++;
  8823. + }
  8824. + if (*file_name == '/') {
  8825. + file_name++;
  8826. + }
  8827. +
  8828. + /* Freed in pkg_free_installed_files */
  8829. + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
  8830. + } else {
  8831. + // already contains root_dir as header -> ABSOLUTE
  8832. + sprintf_alloc(&installed_file_name, "%s", file_name);
  8833. + }
  8834. + str_list_append(pkg->installed_files, installed_file_name);
  8835. + free(line);
  8836. + }
  8837. +
  8838. + fclose(list_file);
  8839. +
  8840. + return pkg->installed_files;
  8841. +}
  8842. +
  8843. +/* XXX: CLEANUP: This function and it's counterpart,
  8844. + (pkg_get_installed_files), do not match our init/deinit naming
  8845. + convention. Nor the alloc/free convention. But, then again, neither
  8846. + of these conventions currrently fit the way these two functions
  8847. + work. */
  8848. +int pkg_free_installed_files(pkg_t *pkg)
  8849. +{
  8850. + str_list_elt_t *iter;
  8851. +
  8852. + pkg->installed_files_ref_cnt--;
  8853. + if (pkg->installed_files_ref_cnt > 0) {
  8854. + return 0;
  8855. + }
  8856. +
  8857. + if (pkg->installed_files) {
  8858. +
  8859. + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
  8860. + /* malloced in pkg_get_installed_files */
  8861. + free (iter->data);
  8862. + iter->data = NULL;
  8863. + }
  8864. +
  8865. + str_list_deinit(pkg->installed_files);
  8866. + }
  8867. +
  8868. + pkg->installed_files = NULL;
  8869. +
  8870. + return 0;
  8871. +}
  8872. +
  8873. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
  8874. +{
  8875. + int err;
  8876. + char *list_file_name;
  8877. +
  8878. + //I don't think pkg_free_installed_files should be called here. Jamey
  8879. + //pkg_free_installed_files(pkg);
  8880. +
  8881. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8882. + pkg->dest->info_dir, pkg->name);
  8883. + if (!conf->noaction) {
  8884. + err = unlink(list_file_name);
  8885. + free(list_file_name);
  8886. +
  8887. + if (err) {
  8888. + return errno;
  8889. + }
  8890. + }
  8891. + return 0;
  8892. +}
  8893. +
  8894. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
  8895. +{
  8896. + conffile_list_elt_t *iter;
  8897. + conffile_t *conffile;
  8898. +
  8899. + if (pkg == NULL) {
  8900. + return NULL;
  8901. + }
  8902. +
  8903. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8904. + conffile = iter->data;
  8905. +
  8906. + if (strcmp(conffile->name, file_name) == 0) {
  8907. + return conffile;
  8908. + }
  8909. + }
  8910. +
  8911. + return NULL;
  8912. +}
  8913. +
  8914. +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
  8915. + const char *script, const char *args)
  8916. +{
  8917. + int err;
  8918. + char *path;
  8919. + char *cmd;
  8920. +
  8921. + /* XXX: FEATURE: When conf->offline_root is set, we should run the
  8922. + maintainer script within a chroot environment. */
  8923. +
  8924. + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
  8925. + have scripts in pkg->tmp_unpack_dir. */
  8926. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  8927. + if (pkg->dest == NULL) {
  8928. + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
  8929. + __FUNCTION__, pkg->name);
  8930. + return EINVAL;
  8931. + }
  8932. + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
  8933. + } else {
  8934. + if (pkg->tmp_unpack_dir == NULL) {
  8935. + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
  8936. + __FUNCTION__, pkg->name);
  8937. + return EINVAL;
  8938. + }
  8939. + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
  8940. + }
  8941. +
  8942. + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
  8943. + if (conf->noaction) return 0;
  8944. +
  8945. + /* XXX: CLEANUP: There must be a better way to handle maintainer
  8946. + scripts when running with offline_root mode and/or a dest other
  8947. + than '/'. I've been playing around with some clever chroot
  8948. + tricks and I might come up with something workable. */
  8949. + if (conf->offline_root) {
  8950. + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
  8951. + }
  8952. +
  8953. + setenv("PKG_ROOT",
  8954. + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
  8955. +
  8956. + if (! file_exists(path)) {
  8957. + free(path);
  8958. + return 0;
  8959. + }
  8960. +
  8961. + if (conf->offline_root) {
  8962. + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
  8963. + free(path);
  8964. + return 0;
  8965. + }
  8966. +
  8967. + sprintf_alloc(&cmd, "%s %s", path, args);
  8968. + free(path);
  8969. +
  8970. + err = xsystem(cmd);
  8971. + free(cmd);
  8972. +
  8973. + if (err) {
  8974. + fprintf(stderr, "%s script returned status %d\n", script, err);
  8975. + return err;
  8976. + }
  8977. +
  8978. + return 0;
  8979. +}
  8980. +
  8981. +char *pkg_state_want_to_str(pkg_state_want_t sw)
  8982. +{
  8983. + int i;
  8984. +
  8985. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  8986. + if (pkg_state_want_map[i].value == sw) {
  8987. + return strdup(pkg_state_want_map[i].str);
  8988. + }
  8989. + }
  8990. +
  8991. + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
  8992. + __FUNCTION__, sw);
  8993. + return strdup("<STATE_WANT_UNKNOWN>");
  8994. +}
  8995. +
  8996. +pkg_state_want_t pkg_state_want_from_str(char *str)
  8997. +{
  8998. + int i;
  8999. +
  9000. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9001. + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
  9002. + return pkg_state_want_map[i].value;
  9003. + }
  9004. + }
  9005. +
  9006. + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
  9007. + __FUNCTION__, str);
  9008. + return SW_UNKNOWN;
  9009. +}
  9010. +
  9011. +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
  9012. +{
  9013. + int i;
  9014. + int len = 3; /* ok\000 is minimum */
  9015. + char *str = NULL;
  9016. +
  9017. + /* clear the temporary flags before converting to string */
  9018. + sf &= SF_NONVOLATILE_FLAGS;
  9019. +
  9020. + if (sf == 0) {
  9021. + return strdup("ok");
  9022. + } else {
  9023. +
  9024. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9025. + if (sf & pkg_state_flag_map[i].value) {
  9026. + len += strlen(pkg_state_flag_map[i].str) + 1;
  9027. + }
  9028. + }
  9029. + str = malloc(len);
  9030. + if ( str == NULL ) {
  9031. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9032. + return NULL;
  9033. + }
  9034. + str[0] = 0;
  9035. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9036. + if (sf & pkg_state_flag_map[i].value) {
  9037. + strcat(str, pkg_state_flag_map[i].str);
  9038. + strcat(str, ",");
  9039. + }
  9040. + }
  9041. + len = strlen(str);
  9042. + str[len-1] = 0; /* squash last comma */
  9043. + return str;
  9044. + }
  9045. +}
  9046. +
  9047. +pkg_state_flag_t pkg_state_flag_from_str(char *str)
  9048. +{
  9049. + int i;
  9050. + int sf = SF_OK;
  9051. +
  9052. + if (strcmp(str, "ok") == 0) {
  9053. + return SF_OK;
  9054. + }
  9055. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9056. + const char *sfname = pkg_state_flag_map[i].str;
  9057. + int sfname_len = strlen(sfname);
  9058. + if (strncmp(str, sfname, sfname_len) == 0) {
  9059. + sf |= pkg_state_flag_map[i].value;
  9060. + str += sfname_len;
  9061. + if (str[0] == ',') {
  9062. + str++;
  9063. + } else {
  9064. + break;
  9065. + }
  9066. + }
  9067. + }
  9068. +
  9069. + return sf;
  9070. +}
  9071. +
  9072. +char *pkg_state_status_to_str(pkg_state_status_t ss)
  9073. +{
  9074. + int i;
  9075. +
  9076. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9077. + if (pkg_state_status_map[i].value == ss) {
  9078. + return strdup(pkg_state_status_map[i].str);
  9079. + }
  9080. + }
  9081. +
  9082. + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
  9083. + __FUNCTION__, ss);
  9084. + return strdup("<STATE_STATUS_UNKNOWN>");
  9085. +}
  9086. +
  9087. +pkg_state_status_t pkg_state_status_from_str(char *str)
  9088. +{
  9089. + int i;
  9090. +
  9091. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9092. + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
  9093. + return pkg_state_status_map[i].value;
  9094. + }
  9095. + }
  9096. +
  9097. + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
  9098. + __FUNCTION__, str);
  9099. + return SS_NOT_INSTALLED;
  9100. +}
  9101. +
  9102. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
  9103. +{
  9104. + nv_pair_list_elt_t *l;
  9105. +
  9106. + if (!pkg->architecture)
  9107. + return 1;
  9108. +
  9109. + l = conf->arch_list.head;
  9110. +
  9111. + while (l) {
  9112. + nv_pair_t *nv = l->data;
  9113. + if (strcmp(nv->name, pkg->architecture) == 0) {
  9114. + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
  9115. + return 1;
  9116. + }
  9117. + l = l->next;
  9118. + }
  9119. +
  9120. + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
  9121. + return 0;
  9122. +}
  9123. +
  9124. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
  9125. +{
  9126. + nv_pair_list_elt_t *l;
  9127. +
  9128. + l = conf->arch_list.head;
  9129. +
  9130. + while (l) {
  9131. + nv_pair_t *nv = l->data;
  9132. + if (strcmp(nv->name, archname) == 0) {
  9133. + int priority = strtol(nv->value, NULL, 0);
  9134. + return priority;
  9135. + }
  9136. + l = l->next;
  9137. + }
  9138. + return 0;
  9139. +}
  9140. +
  9141. +int pkg_info_preinstall_check(ipkg_conf_t *conf)
  9142. +{
  9143. + int i;
  9144. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9145. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  9146. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9147. +
  9148. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
  9149. + pkg_hash_fetch_available(pkg_hash, available_pkgs);
  9150. + /* update arch_priority for each package */
  9151. + for (i = 0; i < available_pkgs->len; i++) {
  9152. + pkg_t *pkg = available_pkgs->pkgs[i];
  9153. + int arch_priority = 1;
  9154. + if (!pkg)
  9155. + continue;
  9156. + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
  9157. + if (pkg->architecture)
  9158. + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
  9159. + else
  9160. + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
  9161. + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
  9162. + pkg->arch_priority = arch_priority;
  9163. + }
  9164. +
  9165. + for (i = 0; i < available_pkgs->len; i++) {
  9166. + pkg_t *pkg = available_pkgs->pkgs[i];
  9167. + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
  9168. + /* clear flags and want for any uninstallable package */
  9169. + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
  9170. + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
  9171. + pkg->state_want = SW_UNKNOWN;
  9172. + pkg->state_flag = 0;
  9173. + }
  9174. + }
  9175. + pkg_vec_free(available_pkgs);
  9176. +
  9177. + /* update the file owner data structure */
  9178. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
  9179. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9180. + for (i = 0; i < installed_pkgs->len; i++) {
  9181. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9182. + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
  9183. + str_list_elt_t *iter;
  9184. + if (installed_files == NULL) {
  9185. + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
  9186. + break;
  9187. + }
  9188. + for (iter = installed_files->head; iter; iter = iter->next) {
  9189. + char *installed_file = iter->data;
  9190. + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
  9191. + file_hash_set_file_owner(conf, installed_file, pkg);
  9192. + }
  9193. + }
  9194. + pkg_vec_free(installed_pkgs);
  9195. +
  9196. + return 0;
  9197. +}
  9198. +
  9199. +struct pkg_write_filelist_data {
  9200. + ipkg_conf_t *conf;
  9201. + pkg_t *pkg;
  9202. + FILE *stream;
  9203. +};
  9204. +
  9205. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
  9206. +{
  9207. + struct pkg_write_filelist_data *data = data_;
  9208. + pkg_t *entry = entry_;
  9209. + if (entry == data->pkg) {
  9210. + fprintf(data->stream, "%s\n", key);
  9211. + }
  9212. +}
  9213. +
  9214. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
  9215. +{
  9216. + struct pkg_write_filelist_data data;
  9217. + char *list_file_name = NULL;
  9218. + int err = 0;
  9219. +
  9220. + if (!pkg) {
  9221. + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
  9222. + return -EINVAL;
  9223. + }
  9224. + ipkg_message(conf, IPKG_INFO,
  9225. + " creating %s.list file\n", pkg->name);
  9226. + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
  9227. + if (!list_file_name) {
  9228. + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
  9229. + return -ENOMEM;
  9230. + }
  9231. + ipkg_message(conf, IPKG_INFO,
  9232. + " creating %s file for pkg %s\n", list_file_name, pkg->name);
  9233. + data.stream = fopen(list_file_name, "w");
  9234. + if (!data.stream) {
  9235. + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
  9236. + list_file_name, strerror(errno));
  9237. + return errno;
  9238. + }
  9239. + data.pkg = pkg;
  9240. + data.conf = conf;
  9241. + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
  9242. + fclose(data.stream);
  9243. + free(list_file_name);
  9244. +
  9245. + return err;
  9246. +}
  9247. +
  9248. +int pkg_write_changed_filelists(ipkg_conf_t *conf)
  9249. +{
  9250. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9251. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9252. + int i;
  9253. + int err;
  9254. + if (conf->noaction)
  9255. + return 0;
  9256. +
  9257. + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
  9258. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9259. + for (i = 0; i < installed_pkgs->len; i++) {
  9260. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9261. + if (pkg->state_flag & SF_FILELIST_CHANGED) {
  9262. + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
  9263. + err = pkg_write_filelist(conf, pkg);
  9264. + if (err)
  9265. + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
  9266. + }
  9267. + }
  9268. + return 0;
  9269. +}
  9270. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_depends.c busybox-1.17.0/archival/libipkg/pkg_depends.c
  9271. --- busybox-1.17.0.orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
  9272. +++ busybox-1.17.0/archival/libipkg/pkg_depends.c 2010-07-08 12:01:56.239000923 +0200
  9273. @@ -0,0 +1,1032 @@
  9274. +/* pkg_depends.c - the itsy package management system
  9275. +
  9276. + Steven M. Ayer
  9277. +
  9278. + Copyright (C) 2002 Compaq Computer Corporation
  9279. +
  9280. + This program is free software; you can redistribute it and/or
  9281. + modify it under the terms of the GNU General Public License as
  9282. + published by the Free Software Foundation; either version 2, or (at
  9283. + your option) any later version.
  9284. +
  9285. + This program is distributed in the hope that it will be useful, but
  9286. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9287. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9288. + General Public License for more details.
  9289. +*/
  9290. +
  9291. +#include "ipkg.h"
  9292. +#include <errno.h>
  9293. +#include <ctype.h>
  9294. +
  9295. +#include "pkg.h"
  9296. +#include "ipkg_utils.h"
  9297. +#include "pkg_hash.h"
  9298. +#include "ipkg_message.h"
  9299. +#include "pkg_parse.h"
  9300. +#include "hash_table.h"
  9301. +
  9302. +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
  9303. +static depend_t * depend_init(void);
  9304. +static void depend_deinit(depend_t *d);
  9305. +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
  9306. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
  9307. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
  9308. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg);
  9309. +
  9310. +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
  9311. +{
  9312. + depend_t *depend = (depend_t *)cdata;
  9313. + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
  9314. + return 1;
  9315. + else
  9316. + return 0;
  9317. +}
  9318. +
  9319. +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
  9320. +{
  9321. + depend_t *depend = (depend_t *)cdata;
  9322. +#if 0
  9323. + pkg_t * temp = pkg_new();
  9324. + int comparison;
  9325. + parseVersion(temp, depend->version);
  9326. + comparison = pkg_compare_versions(pkg, temp);
  9327. + free(temp);
  9328. +
  9329. + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
  9330. + __FUNCTION__, pkg->name, pkg->version,
  9331. + depend, depend->constraint, depend->version,
  9332. + comparison, version_constraints_satisfied(depend, pkg));
  9333. +#endif
  9334. + if (version_constraints_satisfied(depend, pkg))
  9335. + return 1;
  9336. + else
  9337. + return 0;
  9338. +}
  9339. +
  9340. +/* returns ndependences or negative error value */
  9341. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
  9342. + pkg_vec_t *unsatisfied, char *** unresolved)
  9343. +{
  9344. + pkg_t * satisfier_entry_pkg;
  9345. + register int i, j, k, l;
  9346. + int count, found;
  9347. + char ** the_lost;
  9348. + abstract_pkg_t * ab_pkg;
  9349. +
  9350. + /*
  9351. + * this is a setup to check for redundant/cyclic dependency checks,
  9352. + * which are marked at the abstract_pkg level
  9353. + */
  9354. + if (!(ab_pkg = pkg->parent)) {
  9355. + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
  9356. + *unresolved = NULL;
  9357. + return 0;
  9358. + }
  9359. + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
  9360. + *unresolved = NULL;
  9361. + return 0;
  9362. + } else {
  9363. + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
  9364. + }
  9365. + /**/
  9366. +
  9367. + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
  9368. + if (!count){
  9369. + *unresolved = NULL;
  9370. + return 0;
  9371. + }
  9372. +
  9373. + the_lost = NULL;
  9374. +
  9375. + /* foreach dependency */
  9376. + for (i = 0; i < count; i++) {
  9377. + compound_depend_t * compound_depend = &pkg->depends[i];
  9378. + depend_t ** possible_satisfiers = compound_depend->possibilities;;
  9379. + found = 0;
  9380. + satisfier_entry_pkg = NULL;
  9381. +
  9382. + if (compound_depend->type == GREEDY_DEPEND) {
  9383. + /* foreach possible satisfier */
  9384. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9385. + /* foreach provided_by, which includes the abstract_pkg itself */
  9386. + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
  9387. + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
  9388. + int nposs = ab_provider_vec->len;
  9389. + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
  9390. + for (l = 0; l < nposs; l++) {
  9391. + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
  9392. + /* if no depends on this one, try the first package that Provides this one */
  9393. + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
  9394. + continue;
  9395. + }
  9396. +
  9397. + /* cruise this possiblity's pkg_vec looking for an installed version */
  9398. + for (k = 0; k < test_vec->len; k++) {
  9399. + pkg_t *pkg_scout = test_vec->pkgs[k];
  9400. + /* not installed, and not already known about? */
  9401. + if ((pkg_scout->state_want != SW_INSTALL)
  9402. + && !pkg_scout->parent->dependencies_checked
  9403. + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
  9404. + char ** newstuff = NULL;
  9405. + int rc;
  9406. + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
  9407. + /* check for not-already-installed dependencies */
  9408. + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
  9409. + pkg_scout,
  9410. + tmp_vec,
  9411. + &newstuff);
  9412. + if (newstuff == NULL) {
  9413. + int ok = 1;
  9414. + for (i = 0; i < rc; i++) {
  9415. + pkg_t *p = tmp_vec->pkgs[i];
  9416. + if (p->state_want == SW_INSTALL)
  9417. + continue;
  9418. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
  9419. + ok = 0;
  9420. + break;
  9421. + }
  9422. + pkg_vec_free (tmp_vec);
  9423. + if (ok) {
  9424. + /* mark this one for installation */
  9425. + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
  9426. + pkg_vec_insert(unsatisfied, pkg_scout);
  9427. + }
  9428. + } else {
  9429. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
  9430. + free (newstuff);
  9431. + }
  9432. + }
  9433. + }
  9434. + }
  9435. + }
  9436. +
  9437. + continue;
  9438. + }
  9439. +
  9440. + /* foreach possible satisfier, look for installed package */
  9441. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9442. + /* foreach provided_by, which includes the abstract_pkg itself */
  9443. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9444. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9445. + pkg_t *satisfying_pkg =
  9446. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9447. + pkg_installed_and_constraint_satisfied,
  9448. + dependence_to_satisfy, 1);
  9449. + /* Being that I can't test constraing in pkg_hash, I will test it here */
  9450. + if (satisfying_pkg != NULL) {
  9451. + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9452. + satisfying_pkg = NULL;
  9453. + }
  9454. + }
  9455. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
  9456. + if (satisfying_pkg != NULL) {
  9457. + found = 1;
  9458. + break;
  9459. + }
  9460. +
  9461. + }
  9462. + /* if nothing installed matches, then look for uninstalled satisfier */
  9463. + if (!found) {
  9464. + /* foreach possible satisfier, look for installed package */
  9465. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9466. + /* foreach provided_by, which includes the abstract_pkg itself */
  9467. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9468. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9469. + pkg_t *satisfying_pkg =
  9470. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9471. + pkg_constraint_satisfied,
  9472. + dependence_to_satisfy, 1);
  9473. + /* Being that I can't test constraing in pkg_hash, I will test it here too */
  9474. + if (satisfying_pkg != NULL) {
  9475. + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9476. + satisfying_pkg = NULL;
  9477. + }
  9478. + }
  9479. +
  9480. + /* user request overrides package recommendation */
  9481. + if (satisfying_pkg != NULL
  9482. + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
  9483. + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
  9484. + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
  9485. + pkg->name, satisfying_pkg->name);
  9486. + continue;
  9487. + }
  9488. +
  9489. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
  9490. + if (satisfying_pkg != NULL) {
  9491. + satisfier_entry_pkg = satisfying_pkg;
  9492. + break;
  9493. + }
  9494. + }
  9495. + }
  9496. +
  9497. + /* we didn't find one, add something to the unsatisfied vector */
  9498. + if (!found) {
  9499. + if (!satisfier_entry_pkg) {
  9500. + /* failure to meet recommendations is not an error */
  9501. + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
  9502. + the_lost = add_unresolved_dep(pkg, the_lost, i);
  9503. + else
  9504. + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
  9505. + pkg->name, compound_depend->possibilities[0]->pkg->name);
  9506. + }
  9507. + else {
  9508. + if (compound_depend->type == SUGGEST) {
  9509. + /* just mention it politely */
  9510. + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
  9511. + pkg->name, satisfier_entry_pkg->name);
  9512. + } else {
  9513. + char ** newstuff = NULL;
  9514. +
  9515. + if (satisfier_entry_pkg != pkg &&
  9516. + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
  9517. + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
  9518. + pkg_hash_fetch_unsatisfied_dependencies(conf,
  9519. + satisfier_entry_pkg,
  9520. + unsatisfied,
  9521. + &newstuff);
  9522. + the_lost = merge_unresolved(the_lost, newstuff);
  9523. + }
  9524. + }
  9525. + }
  9526. + }
  9527. + }
  9528. + *unresolved = the_lost;
  9529. +
  9530. + return unsatisfied->len;
  9531. +}
  9532. +
  9533. +/*checking for conflicts !in replaces
  9534. + If a packages conflicts with another but is also replacing it, I should not consider it a
  9535. + really conflicts
  9536. + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
  9537. +*/
  9538. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
  9539. +{
  9540. + int i ;
  9541. + int replaces_count = pkg->replaces_count;
  9542. + abstract_pkg_t **replaces;
  9543. +
  9544. + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
  9545. + return 0;
  9546. +
  9547. + replaces = pkg->replaces;
  9548. +
  9549. + for (i = 0; i < replaces_count; i++) {
  9550. + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
  9551. + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
  9552. + return 1;
  9553. + }
  9554. + }
  9555. + return 0;
  9556. +
  9557. +}
  9558. +
  9559. +
  9560. +/* Abhaya: added support for conflicts */
  9561. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg)
  9562. +{
  9563. + pkg_vec_t * installed_conflicts, * test_vec;
  9564. + compound_depend_t * conflicts;
  9565. + depend_t ** possible_satisfiers;
  9566. + depend_t * possible_satisfier;
  9567. + register int i, j, k;
  9568. + int count;
  9569. + abstract_pkg_t * ab_pkg;
  9570. + pkg_t **pkg_scouts;
  9571. + pkg_t *pkg_scout;
  9572. +
  9573. + /*
  9574. + * this is a setup to check for redundant/cyclic dependency checks,
  9575. + * which are marked at the abstract_pkg level
  9576. + */
  9577. + if(!(ab_pkg = pkg->parent)){
  9578. + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
  9579. + return (pkg_vec_t *)NULL;
  9580. + }
  9581. +
  9582. + conflicts = pkg->conflicts;
  9583. + if(!conflicts){
  9584. + return (pkg_vec_t *)NULL;
  9585. + }
  9586. + installed_conflicts = pkg_vec_alloc();
  9587. +
  9588. + count = pkg->conflicts_count;
  9589. +
  9590. +
  9591. +
  9592. + /* foreach conflict */
  9593. + for(i = 0; i < pkg->conflicts_count; i++){
  9594. +
  9595. + possible_satisfiers = conflicts->possibilities;
  9596. +
  9597. + /* foreach possible satisfier */
  9598. + for(j = 0; j < conflicts->possibility_count; j++){
  9599. + possible_satisfier = possible_satisfiers[j];
  9600. + if (!possible_satisfier)
  9601. + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
  9602. + if (!possible_satisfier->pkg)
  9603. + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
  9604. + test_vec = possible_satisfier->pkg->pkgs;
  9605. + if (test_vec) {
  9606. + /* pkg_vec found, it is an actual package conflict
  9607. + * cruise this possiblity's pkg_vec looking for an installed version */
  9608. + pkg_scouts = test_vec->pkgs;
  9609. + for(k = 0; k < test_vec->len; k++){
  9610. + pkg_scout = pkg_scouts[k];
  9611. + if (!pkg_scout) {
  9612. + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
  9613. + continue;
  9614. + }
  9615. + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
  9616. + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
  9617. + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
  9618. + pkg_vec_insert(installed_conflicts, pkg_scout);
  9619. + }
  9620. + }
  9621. + }
  9622. + }
  9623. + }
  9624. + conflicts++;
  9625. + }
  9626. +
  9627. + if (installed_conflicts->len)
  9628. + return installed_conflicts;
  9629. + pkg_vec_free(installed_conflicts);
  9630. + return (pkg_vec_t *)NULL;
  9631. +}
  9632. +
  9633. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
  9634. +{
  9635. + pkg_t * temp;
  9636. + int comparison;
  9637. +
  9638. + if(depends->constraint == NONE)
  9639. + return 1;
  9640. +
  9641. + temp = pkg_new();
  9642. +
  9643. + parseVersion(temp, depends->version);
  9644. +
  9645. + comparison = pkg_compare_versions(pkg, temp);
  9646. +
  9647. + free(temp);
  9648. +
  9649. + if((depends->constraint == EARLIER) &&
  9650. + (comparison < 0))
  9651. + return 1;
  9652. + else if((depends->constraint == LATER) &&
  9653. + (comparison > 0))
  9654. + return 1;
  9655. + else if(comparison == 0)
  9656. + return 1;
  9657. + else if((depends->constraint == LATER_EQUAL) &&
  9658. + (comparison >= 0))
  9659. + return 1;
  9660. + else if((depends->constraint == EARLIER_EQUAL) &&
  9661. + (comparison <= 0))
  9662. + return 1;
  9663. +
  9664. + return 0;
  9665. +}
  9666. +
  9667. +int pkg_dependence_satisfiable(depend_t *depend)
  9668. +{
  9669. + abstract_pkg_t *apkg = depend->pkg;
  9670. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9671. + int n_providers = provider_apkgs->len;
  9672. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9673. + pkg_vec_t *pkg_vec;
  9674. + int n_pkgs ;
  9675. + int i;
  9676. + int j;
  9677. +
  9678. + for (i = 0; i < n_providers; i++) {
  9679. + abstract_pkg_t *papkg = apkgs[i];
  9680. + pkg_vec = papkg->pkgs;
  9681. + if (pkg_vec) {
  9682. + n_pkgs = pkg_vec->len;
  9683. + for (j = 0; j < n_pkgs; j++) {
  9684. + pkg_t *pkg = pkg_vec->pkgs[j];
  9685. + if (version_constraints_satisfied(depend, pkg)) {
  9686. + return 1;
  9687. + }
  9688. + }
  9689. + }
  9690. + }
  9691. + return 0;
  9692. +}
  9693. +
  9694. +int pkg_dependence_satisfied(depend_t *depend)
  9695. +{
  9696. + abstract_pkg_t *apkg = depend->pkg;
  9697. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9698. + int n_providers = provider_apkgs->len;
  9699. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9700. + int i;
  9701. + int n_pkgs;
  9702. + int j;
  9703. +
  9704. + for (i = 0; i < n_providers; i++) {
  9705. + abstract_pkg_t *papkg = apkgs[i];
  9706. + pkg_vec_t *pkg_vec = papkg->pkgs;
  9707. + if (pkg_vec) {
  9708. + n_pkgs = pkg_vec->len;
  9709. + for (j = 0; j < n_pkgs; j++) {
  9710. + pkg_t *pkg = pkg_vec->pkgs[j];
  9711. + if (version_constraints_satisfied(depend, pkg)) {
  9712. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
  9713. + return 1;
  9714. + }
  9715. + }
  9716. + }
  9717. + }
  9718. + return 0;
  9719. +}
  9720. +
  9721. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
  9722. +{
  9723. + register int i;
  9724. + pkg_t ** pkgs = vec->pkgs;
  9725. +
  9726. + for(i = 0; i < vec->len; i++)
  9727. + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
  9728. + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
  9729. + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
  9730. + return 1;
  9731. + return 0;
  9732. +}
  9733. +
  9734. +
  9735. +#ifdef DeadCode
  9736. +/**
  9737. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  9738. + * the same abstract package and 0 otherwise.
  9739. + */
  9740. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
  9741. +{
  9742. + abstract_pkg_t **provides = pkg->provides;
  9743. + int provides_count = pkg->provides_count;
  9744. + abstract_pkg_t **replacee_provides = replacee->provides;
  9745. + int replacee_provides_count = replacee->provides_count;
  9746. + int i, j;
  9747. + for (i = 0; i < provides_count; i++) {
  9748. + abstract_pkg_t *apkg = provides[i];
  9749. + for (j = 0; j < replacee_provides_count; j++) {
  9750. + abstract_pkg_t *replacee_apkg = replacee_provides[i];
  9751. + if (apkg == replacee_apkg)
  9752. + return 1;
  9753. + }
  9754. + }
  9755. + return 0;
  9756. +}
  9757. +#endif
  9758. +
  9759. +/**
  9760. + * pkg_provides_abstract returns 1 if pkg->provides contains providee
  9761. + * and 0 otherwise.
  9762. + */
  9763. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
  9764. +{
  9765. + abstract_pkg_t **provides = pkg->provides;
  9766. + int provides_count = pkg->provides_count;
  9767. + int i;
  9768. + for (i = 0; i < provides_count; i++) {
  9769. + if (provides[i] == providee)
  9770. + return 1;
  9771. + }
  9772. + return 0;
  9773. +}
  9774. +
  9775. +/**
  9776. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  9777. + * otherwise.
  9778. + */
  9779. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
  9780. +{
  9781. + abstract_pkg_t **replaces = pkg->replaces;
  9782. + int replaces_count = pkg->replaces_count;
  9783. + /* abstract_pkg_t **replacee_provides = pkg->provides;
  9784. + int replacee_provides_count = pkg->provides_count; */
  9785. + int i, j;
  9786. + for (i = 0; i < replaces_count; i++) {
  9787. + abstract_pkg_t *abstract_replacee = replaces[i];
  9788. + for (j = 0; j < replaces_count; j++) {
  9789. + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
  9790. + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
  9791. + if (replacee->provides[j] == abstract_replacee)
  9792. + return 1;
  9793. + }
  9794. + }
  9795. + return 0;
  9796. +}
  9797. +
  9798. +
  9799. +/**
  9800. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
  9801. + * otherwise.
  9802. + */
  9803. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
  9804. +{
  9805. + compound_depend_t *conflicts = pkg->conflicts;
  9806. + int conflicts_count = pkg->conflicts_count;
  9807. + int i, j;
  9808. + for (i = 0; i < conflicts_count; i++) {
  9809. + int possibility_count = conflicts[i].possibility_count;
  9810. + struct depend **possibilities = conflicts[i].possibilities;
  9811. + for (j = 0; j < possibility_count; j++) {
  9812. + if (possibilities[j]->pkg == conflictee) {
  9813. + return 1;
  9814. + }
  9815. + }
  9816. + }
  9817. + return 0;
  9818. +}
  9819. +
  9820. +/**
  9821. + * pkg_conflicts returns 1 if pkg->conflicts contains one of
  9822. + * conflictee's provides and 0 otherwise.
  9823. + */
  9824. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
  9825. +{
  9826. + compound_depend_t *conflicts = pkg->conflicts;
  9827. + int conflicts_count = pkg->conflicts_count;
  9828. + abstract_pkg_t **conflictee_provides = conflictee->provides;
  9829. + int conflictee_provides_count = conflictee->provides_count;
  9830. + int i, j, k;
  9831. + int possibility_count;
  9832. + struct depend **possibilities;
  9833. + abstract_pkg_t *possibility ;
  9834. +
  9835. + for (i = 0; i < conflicts_count; i++) {
  9836. + possibility_count = conflicts[i].possibility_count;
  9837. + possibilities = conflicts[i].possibilities;
  9838. + for (j = 0; j < possibility_count; j++) {
  9839. + possibility = possibilities[j]->pkg;
  9840. + for (k = 0; k < conflictee_provides_count; k++) {
  9841. + if (possibility == conflictee_provides[k]) {
  9842. + return 1;
  9843. + }
  9844. + }
  9845. + }
  9846. + }
  9847. + return 0;
  9848. +}
  9849. +
  9850. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
  9851. +{
  9852. + int oldlen = 0, newlen = 0;
  9853. + char ** result;
  9854. + register int i, j;
  9855. +
  9856. + if(!newstuff)
  9857. + return oldstuff;
  9858. +
  9859. + while(oldstuff && oldstuff[oldlen]) oldlen++;
  9860. + while(newstuff && newstuff[newlen]) newlen++;
  9861. +
  9862. + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
  9863. + if (result == NULL) {
  9864. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9865. + return NULL;
  9866. + }
  9867. +
  9868. + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
  9869. + *(result + i) = *(newstuff + j);
  9870. +
  9871. + *(result + i) = NULL;
  9872. +
  9873. + return result;
  9874. +}
  9875. +
  9876. +/*
  9877. + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
  9878. + * this is null terminated, no count is carried around
  9879. + */
  9880. +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
  9881. +{
  9882. + int count;
  9883. + char ** resized;
  9884. + char *depend_str = pkg_depend_str(pkg, ref_ndx);
  9885. +
  9886. + count = 0;
  9887. + while(the_lost && the_lost[count]) count++;
  9888. +
  9889. + count++; /* need one to hold the null */
  9890. + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
  9891. + if (resized == NULL) {
  9892. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9893. + return NULL;
  9894. + }
  9895. + resized[count - 1] = strdup(depend_str);
  9896. + resized[count] = NULL;
  9897. +
  9898. + return resized;
  9899. +}
  9900. +
  9901. +void printDepends(pkg_t * pkg)
  9902. +{
  9903. + register int i, j;
  9904. + compound_depend_t * depend;
  9905. + int count;
  9906. +
  9907. + count = pkg->pre_depends_count + pkg->depends_count;
  9908. +
  9909. + depend = pkg->depends;
  9910. + if(!depend){
  9911. + fprintf(stderr, "Depends pointer is NULL\n");
  9912. + return;
  9913. + }
  9914. + for(i = 0; i < count; i++){
  9915. + fprintf(stderr, "%s has %d possibilities:\n",
  9916. + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
  9917. + depend->possibility_count);
  9918. + for(j = 0; j < depend->possibility_count; j++)
  9919. + fprintf(stderr, "\t%s version %s (%d)\n",
  9920. + depend->possibilities[j]->pkg->name,
  9921. + depend->possibilities[j]->version,
  9922. + depend->possibilities[j]->constraint);
  9923. + depend++;
  9924. + }
  9925. +}
  9926. +
  9927. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  9928. +{
  9929. + register int i, j;
  9930. +
  9931. + /* every pkg provides itself */
  9932. + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
  9933. +
  9934. + if (!pkg->provides_count)
  9935. + return 0;
  9936. +
  9937. + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
  9938. + if (pkg->provides == NULL) {
  9939. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9940. + return -1 ;
  9941. + }
  9942. + pkg->provides[0] = ab_pkg;
  9943. +
  9944. + // if (strcmp(ab_pkg->name, pkg->name))
  9945. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  9946. +
  9947. + for(i = 0; i < pkg->provides_count; i++){
  9948. + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
  9949. +
  9950. + pkg->provides[i+1] = provided_abpkg;
  9951. +
  9952. + j = 0;
  9953. + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
  9954. + }
  9955. + return 0;
  9956. +}
  9957. +
  9958. +/* Abhaya: added conflicts support */
  9959. +int buildConflicts(hash_table_t * hash, pkg_t * pkg)
  9960. +{
  9961. + register int i;
  9962. + compound_depend_t * conflicts;
  9963. +
  9964. + if (!pkg->conflicts_count)
  9965. + return 0;
  9966. +
  9967. + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
  9968. + pkg->conflicts_count);
  9969. + if (conflicts == NULL) {
  9970. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9971. + return -1;
  9972. + }
  9973. + for (i = 0; i < pkg->conflicts_count; i++) {
  9974. + conflicts->type = CONFLICTS;
  9975. + parseDepends(conflicts, hash,
  9976. + pkg->conflicts_str[i]);
  9977. +#if 0
  9978. + for (j = 0; j < conflicts->possibility_count; j++) {
  9979. + depend_t *possibility = conflicts->possibilities[j];
  9980. + abstract_pkg_t *conflicting_apkg = possibility->pkg;
  9981. + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
  9982. + }
  9983. +#endif
  9984. + conflicts++;
  9985. + }
  9986. + return 0;
  9987. +}
  9988. +
  9989. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  9990. +{
  9991. + register int i, j;
  9992. +
  9993. + if (!pkg->replaces_count)
  9994. + return 0;
  9995. +
  9996. + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
  9997. + if (pkg->replaces == NULL) {
  9998. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9999. + return -1;
  10000. + }
  10001. +
  10002. + // if (strcmp(ab_pkg->name, pkg->name))
  10003. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10004. +
  10005. + for(i = 0; i < pkg->replaces_count; i++){
  10006. + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
  10007. +
  10008. + pkg->replaces[i] = old_abpkg;
  10009. +
  10010. + j = 0;
  10011. + if (!old_abpkg->replaced_by)
  10012. + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
  10013. + if ( old_abpkg->replaced_by == NULL ){
  10014. + return -1;
  10015. + }
  10016. + /* if a package pkg both replaces and conflicts old_abpkg,
  10017. + * then add it to the replaced_by vector so that old_abpkg
  10018. + * will be upgraded to ab_pkg automatically */
  10019. + if (pkg_conflicts_abstract(pkg, old_abpkg))
  10020. + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
  10021. + }
  10022. + return 0;
  10023. +}
  10024. +
  10025. +int buildDepends(hash_table_t * hash, pkg_t * pkg)
  10026. +{
  10027. + int count;
  10028. + register int i;
  10029. + compound_depend_t * depends;
  10030. +
  10031. + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
  10032. + return 0;
  10033. +
  10034. + if (0 && pkg->pre_depends_count)
  10035. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10036. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10037. + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
  10038. + if (depends == NULL) {
  10039. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10040. + return -1;
  10041. + }
  10042. +
  10043. +
  10044. + for(i = 0; i < pkg->pre_depends_count; i++){
  10045. + parseDepends(depends, hash, pkg->pre_depends_str[i]);
  10046. + if (0 && pkg->pre_depends_count)
  10047. + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
  10048. + pkg->pre_depends_str[i], depends, depends->possibility_count);
  10049. + depends->type = PREDEPEND;
  10050. + depends++;
  10051. + }
  10052. +
  10053. + for(i = 0; i < pkg->recommends_count; i++){
  10054. + parseDepends(depends, hash, pkg->recommends_str[i]);
  10055. + if (0 && pkg->recommends_count)
  10056. + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
  10057. + pkg->recommends_str[i], depends, depends->possibility_count);
  10058. + depends->type = RECOMMEND;
  10059. + depends++;
  10060. + }
  10061. +
  10062. + for(i = 0; i < pkg->suggests_count; i++){
  10063. + parseDepends(depends, hash, pkg->suggests_str[i]);
  10064. + if (0 && pkg->suggests_count)
  10065. + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
  10066. + pkg->suggests_str[i], depends, depends->possibility_count);
  10067. + depends->type = SUGGEST;
  10068. + depends++;
  10069. + }
  10070. +
  10071. + for(i = 0; i < pkg->depends_count; i++){
  10072. + parseDepends(depends, hash, pkg->depends_str[i]);
  10073. + if (0 && pkg->depends_count)
  10074. + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
  10075. + pkg->depends_str[i], depends, depends->possibility_count);
  10076. + depends++;
  10077. + }
  10078. + return 0;
  10079. +}
  10080. +
  10081. +/*
  10082. + * pkg_depend_string: returns the depends string specified by index_.
  10083. + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
  10084. + * [0,npredepends) -> returns pre_depends_str[index_]
  10085. + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index_]
  10086. + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index_]
  10087. + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index_]
  10088. + */
  10089. +char *pkg_depend_str(pkg_t *pkg, int index_)
  10090. +{
  10091. + if (index_ < pkg->pre_depends_count) {
  10092. + return pkg->pre_depends_str[index_];
  10093. + }
  10094. + index_ -= pkg->pre_depends_count;
  10095. +
  10096. + if (index_ < pkg->recommends_count) {
  10097. + return pkg->recommends_str[index_];
  10098. + }
  10099. + index_ -= pkg->recommends_count;
  10100. +
  10101. + if (index_ < pkg->suggests_count) {
  10102. + return pkg->suggests_str[index_];
  10103. + }
  10104. + index_ -= pkg->suggests_count;
  10105. +
  10106. + if (index_ < pkg->depends_count) {
  10107. + return pkg->depends_str[index_];
  10108. + }
  10109. + fprintf(stderr, "pkg_depend_str: index_ %d out of range for pkg=%s\n", index_, pkg->name);
  10110. + return NULL;
  10111. +}
  10112. +
  10113. +void freeDepends(pkg_t *pkg)
  10114. +{
  10115. + int i;
  10116. +
  10117. + if (pkg == NULL || pkg->depends == NULL) {
  10118. + return;
  10119. + }
  10120. +
  10121. + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
  10122. + for (i=0; i < pkg->depends->possibility_count; i++) {
  10123. + depend_deinit(pkg->depends->possibilities[i]);
  10124. + }
  10125. + free(pkg->depends->possibilities);
  10126. + free(pkg->depends);
  10127. + pkg->depends = NULL;
  10128. +}
  10129. +
  10130. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
  10131. +{
  10132. + compound_depend_t * depends;
  10133. + int count, othercount;
  10134. + register int i, j;
  10135. + abstract_pkg_t * ab_depend;
  10136. + abstract_pkg_t ** temp;
  10137. +
  10138. + count = pkg->pre_depends_count + pkg->depends_count;
  10139. + depends = pkg->depends;
  10140. +
  10141. + if (0 && pkg->pre_depends_count)
  10142. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10143. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10144. + for (i = 0; i < count; i++) {
  10145. + if (0 && pkg->pre_depends_count)
  10146. + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
  10147. + for (j = 0; j < depends->possibility_count; j++){
  10148. + ab_depend = depends->possibilities[j]->pkg;
  10149. + if(!ab_depend->depended_upon_by)
  10150. + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
  10151. +
  10152. + temp = ab_depend->depended_upon_by;
  10153. + othercount = 1;
  10154. + while(*temp){
  10155. + temp++;
  10156. + othercount++;
  10157. + }
  10158. + *temp = ab_pkg;
  10159. +
  10160. + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
  10161. + (othercount + 1) * sizeof(abstract_pkg_t *));
  10162. + /* the array may have moved */
  10163. + temp = ab_depend->depended_upon_by + othercount;
  10164. + *temp = NULL;
  10165. + }
  10166. + depends++;
  10167. + }
  10168. +}
  10169. +
  10170. +static depend_t * depend_init(void)
  10171. +{
  10172. + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
  10173. + if ( d==NULL ){
  10174. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10175. + return NULL;
  10176. + }
  10177. + d->constraint = NONE;
  10178. + d->version = NULL;
  10179. + d->pkg = NULL;
  10180. +
  10181. + return d;
  10182. +}
  10183. +
  10184. +static void depend_deinit(depend_t *d)
  10185. +{
  10186. + free(d);
  10187. +}
  10188. +
  10189. +static int parseDepends(compound_depend_t *compound_depend,
  10190. + hash_table_t * hash, char * depend_str)
  10191. +{
  10192. + char * pkg_name, buffer[2048];
  10193. + int num_of_ors = 0;
  10194. + register int i;
  10195. + register char * src, * dest;
  10196. + depend_t ** possibilities;
  10197. +
  10198. + /* first count the number of ored possibilities for satisfying dependency */
  10199. + src = depend_str;
  10200. + while(*src)
  10201. + if(*src++ == '|')
  10202. + num_of_ors++;
  10203. +
  10204. + compound_depend->type = DEPEND;
  10205. +
  10206. + compound_depend->possibility_count = num_of_ors + 1;
  10207. + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
  10208. + if (!possibilities)
  10209. + return -ENOMEM;
  10210. + compound_depend->possibilities = possibilities;
  10211. +
  10212. + src = depend_str;
  10213. + for(i = 0; i < num_of_ors + 1; i++){
  10214. + possibilities[i] = depend_init();
  10215. + if (!possibilities[i])
  10216. + return -ENOMEM;
  10217. + /* gobble up just the name first */
  10218. + dest = buffer;
  10219. + while(*src &&
  10220. + !isspace(*src) &&
  10221. + (*src != '(') &&
  10222. + (*src != '*') &&
  10223. + (*src != '|'))
  10224. + *dest++ = *src++;
  10225. + *dest = '\0';
  10226. + pkg_name = trim_alloc(buffer);
  10227. + if (pkg_name == NULL )
  10228. + return -ENOMEM;
  10229. +
  10230. + /* now look at possible version info */
  10231. +
  10232. + /* skip to next chars */
  10233. + if(isspace(*src))
  10234. + while(*src && isspace(*src)) src++;
  10235. +
  10236. + /* extract constraint and version */
  10237. + if(*src == '('){
  10238. + src++;
  10239. + if(!strncmp(src, "<<", 2)){
  10240. + possibilities[i]->constraint = EARLIER;
  10241. + src += 2;
  10242. + }
  10243. + else if(!strncmp(src, "<=", 2)){
  10244. + possibilities[i]->constraint = EARLIER_EQUAL;
  10245. + src += 2;
  10246. + }
  10247. + else if(!strncmp(src, ">=", 2)){
  10248. + possibilities[i]->constraint = LATER_EQUAL;
  10249. + src += 2;
  10250. + }
  10251. + else if(!strncmp(src, ">>", 2)){
  10252. + possibilities[i]->constraint = LATER;
  10253. + src += 2;
  10254. + }
  10255. + else if(!strncmp(src, "=", 1)){
  10256. + possibilities[i]->constraint = EQUAL;
  10257. + src++;
  10258. + }
  10259. + /* should these be here to support deprecated designations; dpkg does */
  10260. + else if(!strncmp(src, "<", 1)){
  10261. + possibilities[i]->constraint = EARLIER_EQUAL;
  10262. + src++;
  10263. + }
  10264. + else if(!strncmp(src, ">", 1)){
  10265. + possibilities[i]->constraint = LATER_EQUAL;
  10266. + src++;
  10267. + }
  10268. +
  10269. + /* now we have any constraint, pass space to version string */
  10270. + while(isspace(*src)) src++;
  10271. +
  10272. + /* this would be the version string */
  10273. + dest = buffer;
  10274. + while(*src && *src != ')')
  10275. + *dest++ = *src++;
  10276. + *dest = '\0';
  10277. +
  10278. + possibilities[i]->version = trim_alloc(buffer);
  10279. + /* fprintf(stderr, "let's print the depends version string:");
  10280. + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
  10281. + if (possibilities[i]->version == NULL )
  10282. + return -ENOMEM;
  10283. +
  10284. +
  10285. + }
  10286. + /* hook up the dependency to its abstract pkg */
  10287. + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
  10288. +
  10289. + free(pkg_name);
  10290. +
  10291. + /* now get past the ) and any possible | chars */
  10292. + while(*src &&
  10293. + (isspace(*src) ||
  10294. + (*src == ')') ||
  10295. + (*src == '|')))
  10296. + src++;
  10297. + if (*src == '*')
  10298. + {
  10299. + compound_depend->type = GREEDY_DEPEND;
  10300. + src++;
  10301. + }
  10302. + }
  10303. +
  10304. + return 0;
  10305. +}
  10306. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_depends.h busybox-1.17.0/archival/libipkg/pkg_depends.h
  10307. --- busybox-1.17.0.orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
  10308. +++ busybox-1.17.0/archival/libipkg/pkg_depends.h 2010-07-08 12:01:56.239000923 +0200
  10309. @@ -0,0 +1,105 @@
  10310. +/* pkg_depends.h - the itsy package management system
  10311. +
  10312. + Steven M. Ayer
  10313. +
  10314. + Copyright (C) 2002 Compaq Computer Corporation
  10315. +
  10316. + This program is free software; you can redistribute it and/or
  10317. + modify it under the terms of the GNU General Public License as
  10318. + published by the Free Software Foundation; either version 2, or (at
  10319. + your option) any later version.
  10320. +
  10321. + This program is distributed in the hope that it will be useful, but
  10322. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10323. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10324. + General Public License for more details.
  10325. +*/
  10326. +
  10327. +#ifndef PKG_DEPENDS_H
  10328. +#define PKG_DEPENDS_H
  10329. +
  10330. +#include "pkg.h"
  10331. +#include "pkg_hash.h"
  10332. +
  10333. +enum depend_type {
  10334. + PREDEPEND,
  10335. + DEPEND,
  10336. + CONFLICTS,
  10337. + GREEDY_DEPEND,
  10338. + RECOMMEND,
  10339. + SUGGEST
  10340. +};
  10341. +typedef enum depend_type depend_type_t;
  10342. +
  10343. +enum version_constraint {
  10344. + NONE,
  10345. + EARLIER,
  10346. + EARLIER_EQUAL,
  10347. + EQUAL,
  10348. + LATER_EQUAL,
  10349. + LATER
  10350. +};
  10351. +typedef enum version_constraint version_constraint_t;
  10352. +
  10353. +struct depend{
  10354. + version_constraint_t constraint;
  10355. + char * version;
  10356. + abstract_pkg_t * pkg;
  10357. +};
  10358. +typedef struct depend depend_t;
  10359. +
  10360. +struct compound_depend{
  10361. + depend_type_t type;
  10362. + int possibility_count;
  10363. + struct depend ** possibilities;
  10364. +};
  10365. +typedef struct compound_depend compound_depend_t;
  10366. +
  10367. +#include "hash_table.h"
  10368. +
  10369. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10370. +int buildConflicts(hash_table_t * hash, pkg_t * pkg);
  10371. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10372. +int buildDepends(hash_table_t * hash, pkg_t * pkg);
  10373. +
  10374. +/**
  10375. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10376. + * the same abstract package and 0 otherwise.
  10377. + */
  10378. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
  10379. +
  10380. +/**
  10381. + * pkg_provides returns 1 if pkg->provides contains providee and 0
  10382. + * otherwise.
  10383. + */
  10384. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
  10385. +
  10386. +/**
  10387. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10388. + * otherwise.
  10389. + */
  10390. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
  10391. +
  10392. +/**
  10393. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
  10394. + * otherwise.
  10395. + */
  10396. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
  10397. +
  10398. +/**
  10399. + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
  10400. + * otherwise.
  10401. + */
  10402. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
  10403. +
  10404. +char *pkg_depend_str(pkg_t *pkg, int index_);
  10405. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
  10406. +void freeDepends(pkg_t *pkg);
  10407. +void printDepends(pkg_t * pkg);
  10408. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
  10409. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
  10410. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
  10411. +int pkg_dependence_satisfiable(depend_t *depend);
  10412. +int pkg_dependence_satisfied(depend_t *depend);
  10413. +
  10414. +#endif
  10415. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_dest.c busybox-1.17.0/archival/libipkg/pkg_dest.c
  10416. --- busybox-1.17.0.orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
  10417. +++ busybox-1.17.0/archival/libipkg/pkg_dest.c 2010-07-08 12:01:56.239000923 +0200
  10418. @@ -0,0 +1,92 @@
  10419. +/* pkg_dest.c - the itsy package management system
  10420. +
  10421. + Carl D. Worth
  10422. +
  10423. + Copyright (C) 2001 University of Southern California
  10424. +
  10425. + This program is free software; you can redistribute it and/or
  10426. + modify it under the terms of the GNU General Public License as
  10427. + published by the Free Software Foundation; either version 2, or (at
  10428. + your option) any later version.
  10429. +
  10430. + This program is distributed in the hope that it will be useful, but
  10431. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10432. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10433. + General Public License for more details.
  10434. +*/
  10435. +
  10436. +#include "ipkg.h"
  10437. +
  10438. +#include "pkg_dest.h"
  10439. +#include "file_util.h"
  10440. +#include "str_util.h"
  10441. +#include "sprintf_alloc.h"
  10442. +
  10443. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
  10444. +{
  10445. + dest->name = strdup(name);
  10446. +
  10447. + /* Guarantee that dest->root_dir ends with a '/' */
  10448. + if (str_ends_with(root_dir, "/")) {
  10449. + dest->root_dir = strdup(root_dir);
  10450. + } else {
  10451. + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
  10452. + }
  10453. + file_mkdir_hier(dest->root_dir, 0755);
  10454. +
  10455. + sprintf_alloc(&dest->ipkg_dir, "%s%s",
  10456. + dest->root_dir, IPKG_STATE_DIR_PREFIX);
  10457. + file_mkdir_hier(dest->ipkg_dir, 0755);
  10458. +
  10459. + if (str_starts_with (lists_dir, "/"))
  10460. + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
  10461. + else
  10462. + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
  10463. +
  10464. + file_mkdir_hier(dest->lists_dir, 0755);
  10465. +
  10466. + sprintf_alloc(&dest->info_dir, "%s/%s",
  10467. + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
  10468. + file_mkdir_hier(dest->info_dir, 0755);
  10469. +
  10470. + sprintf_alloc(&dest->status_file_name, "%s/%s",
  10471. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10472. +
  10473. + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
  10474. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10475. +
  10476. + dest->status_file = NULL;
  10477. +
  10478. + return 0;
  10479. +}
  10480. +
  10481. +void pkg_dest_deinit(pkg_dest_t *dest)
  10482. +{
  10483. + free(dest->name);
  10484. + dest->name = NULL;
  10485. +
  10486. + free(dest->root_dir);
  10487. + dest->root_dir = NULL;
  10488. +
  10489. + free(dest->ipkg_dir);
  10490. + dest->ipkg_dir = NULL;
  10491. +
  10492. + free(dest->lists_dir);
  10493. + dest->lists_dir = NULL;
  10494. +
  10495. + free(dest->info_dir);
  10496. + dest->info_dir = NULL;
  10497. +
  10498. + free(dest->status_file_name);
  10499. + dest->status_file_name = NULL;
  10500. +
  10501. + free(dest->status_file_tmp_name);
  10502. + dest->status_file_tmp_name = NULL;
  10503. +
  10504. + if (dest->status_file) {
  10505. + fclose(dest->status_file);
  10506. + }
  10507. + dest->status_file = NULL;
  10508. +
  10509. + dest->root_dir = NULL;
  10510. +}
  10511. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_dest.h busybox-1.17.0/archival/libipkg/pkg_dest.h
  10512. --- busybox-1.17.0.orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
  10513. +++ busybox-1.17.0/archival/libipkg/pkg_dest.h 2010-07-08 12:01:56.239000923 +0200
  10514. @@ -0,0 +1,38 @@
  10515. +/* pkg_dest.h - the itsy package management system
  10516. +
  10517. + Carl D. Worth
  10518. +
  10519. + Copyright (C) 2001 University of Southern California
  10520. +
  10521. + This program is free software; you can redistribute it and/or
  10522. + modify it under the terms of the GNU General Public License as
  10523. + published by the Free Software Foundation; either version 2, or (at
  10524. + your option) any later version.
  10525. +
  10526. + This program is distributed in the hope that it will be useful, but
  10527. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10528. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10529. + General Public License for more details.
  10530. +*/
  10531. +
  10532. +#ifndef PKG_DEST_H
  10533. +#define PKG_DEST_H
  10534. +
  10535. +typedef struct pkg_dest pkg_dest_t;
  10536. +struct pkg_dest
  10537. +{
  10538. + char *name;
  10539. + char *root_dir;
  10540. + char *ipkg_dir;
  10541. + char *lists_dir;
  10542. + char *info_dir;
  10543. + char *status_file_name;
  10544. + char *status_file_tmp_name;
  10545. + FILE *status_file;
  10546. +};
  10547. +
  10548. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
  10549. +void pkg_dest_deinit(pkg_dest_t *dest);
  10550. +
  10551. +#endif
  10552. +
  10553. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_dest_list.c busybox-1.17.0/archival/libipkg/pkg_dest_list.c
  10554. --- busybox-1.17.0.orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
  10555. +++ busybox-1.17.0/archival/libipkg/pkg_dest_list.c 2010-07-08 12:01:56.243001712 +0200
  10556. @@ -0,0 +1,85 @@
  10557. +/* pkg_dest_list.c - the itsy package management system
  10558. +
  10559. + Carl D. Worth
  10560. +
  10561. + Copyright (C) 2001 University of Southern California
  10562. +
  10563. + This program is free software; you can redistribute it and/or
  10564. + modify it under the terms of the GNU General Public License as
  10565. + published by the Free Software Foundation; either version 2, or (at
  10566. + your option) any later version.
  10567. +
  10568. + This program is distributed in the hope that it will be useful, but
  10569. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10570. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10571. + General Public License for more details.
  10572. +*/
  10573. +
  10574. +#include "ipkg.h"
  10575. +
  10576. +#include "pkg_dest.h"
  10577. +#include "void_list.h"
  10578. +#include "pkg_dest_list.h"
  10579. +
  10580. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
  10581. +{
  10582. + return void_list_elt_init((void_list_elt_t *) elt, data);
  10583. +}
  10584. +
  10585. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
  10586. +{
  10587. + void_list_elt_deinit((void_list_elt_t *) elt);
  10588. +}
  10589. +
  10590. +int pkg_dest_list_init(pkg_dest_list_t *list)
  10591. +{
  10592. + return void_list_init((void_list_t *) list);
  10593. +}
  10594. +
  10595. +void pkg_dest_list_deinit(pkg_dest_list_t *list)
  10596. +{
  10597. + pkg_dest_list_elt_t *iter;
  10598. + pkg_dest_t *pkg_dest;
  10599. +
  10600. + for (iter = list->head; iter; iter = iter->next) {
  10601. + pkg_dest = iter->data;
  10602. + pkg_dest_deinit(pkg_dest);
  10603. +
  10604. + /* malloced in pkg_dest_list_append */
  10605. + free(pkg_dest);
  10606. + iter->data = NULL;
  10607. + }
  10608. + void_list_deinit((void_list_t *) list);
  10609. +}
  10610. +
  10611. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10612. + const char *root_dir,const char *lists_dir)
  10613. +{
  10614. + int err;
  10615. + pkg_dest_t *pkg_dest;
  10616. +
  10617. + /* freed in plg_dest_list_deinit */
  10618. + pkg_dest = malloc(sizeof(pkg_dest_t));
  10619. + if (pkg_dest == NULL) {
  10620. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10621. + return NULL;
  10622. + }
  10623. +
  10624. + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
  10625. + err = void_list_append((void_list_t *) list, pkg_dest);
  10626. + if (err) {
  10627. + return NULL;
  10628. + }
  10629. +
  10630. + return pkg_dest;
  10631. +}
  10632. +
  10633. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
  10634. +{
  10635. + return void_list_push((void_list_t *) list, data);
  10636. +}
  10637. +
  10638. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
  10639. +{
  10640. + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
  10641. +}
  10642. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_dest_list.h busybox-1.17.0/archival/libipkg/pkg_dest_list.h
  10643. --- busybox-1.17.0.orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
  10644. +++ busybox-1.17.0/archival/libipkg/pkg_dest_list.h 2010-07-08 12:01:56.243001712 +0200
  10645. @@ -0,0 +1,50 @@
  10646. +/* pkg_dest_list.h - the itsy package management system
  10647. +
  10648. + Carl D. Worth
  10649. +
  10650. + Copyright (C) 2001 University of Southern California
  10651. +
  10652. + This program is free software; you can redistribute it and/or
  10653. + modify it under the terms of the GNU General Public License as
  10654. + published by the Free Software Foundation; either version 2, or (at
  10655. + your option) any later version.
  10656. +
  10657. + This program is distributed in the hope that it will be useful, but
  10658. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10659. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10660. + General Public License for more details.
  10661. +*/
  10662. +
  10663. +#ifndef PKG_DEST_LIST_H
  10664. +#define PKG_DEST_LIST_H
  10665. +
  10666. +#include "pkg_dest.h"
  10667. +
  10668. +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
  10669. +struct pkg_dest_list_elt
  10670. +{
  10671. + pkg_dest_list_elt_t *next;
  10672. + pkg_dest_t *data;
  10673. +};
  10674. +
  10675. +typedef struct pkg_dest_list pkg_dest_list_t;
  10676. +struct pkg_dest_list
  10677. +{
  10678. + pkg_dest_list_elt_t pre_head;
  10679. + pkg_dest_list_elt_t *head;
  10680. + pkg_dest_list_elt_t *tail;
  10681. +};
  10682. +
  10683. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
  10684. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
  10685. +
  10686. +int pkg_dest_list_init(pkg_dest_list_t *list);
  10687. +void pkg_dest_list_deinit(pkg_dest_list_t *list);
  10688. +
  10689. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10690. + const char *root_dir,const char* lists_dir);
  10691. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
  10692. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
  10693. +
  10694. +#endif
  10695. +
  10696. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_extract.c busybox-1.17.0/archival/libipkg/pkg_extract.c
  10697. --- busybox-1.17.0.orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
  10698. +++ busybox-1.17.0/archival/libipkg/pkg_extract.c 2010-07-08 12:01:56.243001712 +0200
  10699. @@ -0,0 +1,255 @@
  10700. +/* pkg_extract.c - the itsy package management system
  10701. +
  10702. + Carl D. Worth
  10703. +
  10704. + Copyright (C) 2001 University of Southern California
  10705. +
  10706. + This program is free software; you can redistribute it and/or
  10707. + modify it under the terms of the GNU General Public License as
  10708. + published by the Free Software Foundation; either version 2, or (at
  10709. + your option) any later version.
  10710. +
  10711. + This program is distributed in the hope that it will be useful, but
  10712. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10713. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10714. + General Public License for more details.
  10715. +*/
  10716. +
  10717. +#include "ipkg.h"
  10718. +#include <errno.h>
  10719. +#include <fcntl.h>
  10720. +#include <stdio.h>
  10721. +
  10722. +#include "pkg_extract.h"
  10723. +
  10724. +#include "libbb.h"
  10725. +#include "file_util.h"
  10726. +#include "sprintf_alloc.h"
  10727. +#include "unarchive.h"
  10728. +
  10729. +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
  10730. +#define IPKG_DATA_ARCHIVE "data.tar.gz"
  10731. +#define IPKG_CONTROL_FILE "control"
  10732. +
  10733. +static void FAST_FUNC ipkg_data_extract_all_prefix(archive_handle_t *archive_handle)
  10734. +{
  10735. + char *name_ptr = archive_handle->file_header->name;
  10736. +
  10737. + /* Skip all leading "/" */
  10738. + while (*name_ptr == '/')
  10739. + name_ptr++;
  10740. + /* Skip all leading "./" and "../" */
  10741. + while (name_ptr[0] == '.') {
  10742. + if (name_ptr[1] == '.' && name_ptr[2] == '/')
  10743. + name_ptr++;
  10744. + if (name_ptr[1] != '/')
  10745. + break;
  10746. + name_ptr += 2;
  10747. + }
  10748. +
  10749. + if (name_ptr[0] != '\0') {
  10750. + archive_handle->file_header->name = xasprintf("%s%s", archive_handle->dpkg__buffer, name_ptr);
  10751. + data_extract_all(archive_handle);
  10752. + }
  10753. +}
  10754. +
  10755. +static void FAST_FUNC ipkg_data_extract_to_buffer(archive_handle_t *archive_handle)
  10756. +{
  10757. + unsigned size = archive_handle->file_header->size;
  10758. +
  10759. + archive_handle->dpkg__buffer = xzalloc(size + 1);
  10760. + xread(archive_handle->src_fd, archive_handle->dpkg__buffer, size);
  10761. +}
  10762. +
  10763. +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
  10764. +{
  10765. + archive_handle_t *archive;
  10766. + char *path;
  10767. +
  10768. + sprintf_alloc(&path, "%s/", dir);
  10769. + archive = init_handle();
  10770. + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
  10771. + archive->filter = filter_accept_list;
  10772. + llist_add_to(&(archive->accept), (char *)filename);
  10773. + archive->dpkg__buffer = path;
  10774. + archive->action_data = ipkg_data_extract_all_prefix;
  10775. + archive->ah_flags |= ARCHIVE_UNLINK_OLD;
  10776. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10777. + close(archive->src_fd);
  10778. + free(archive->accept);
  10779. + free(archive);
  10780. + free(path);
  10781. +}
  10782. +
  10783. +static void FAST_FUNC data_extract_file_name_to_buffer(archive_handle_t *archive)
  10784. +{
  10785. + unsigned int size = strlen(archive->file_header->name) + 2;
  10786. +
  10787. + if (archive->dpkg__buffer == NULL) {
  10788. + archive->dpkg__buffer = xmalloc(size);
  10789. + strcpy(archive->dpkg__buffer, archive->file_header->name);
  10790. + } else {
  10791. + size += strlen(archive->dpkg__buffer);
  10792. + archive->dpkg__buffer = xrealloc(archive->dpkg__buffer, size);
  10793. + strcat(archive->dpkg__buffer, archive->file_header->name);
  10794. + }
  10795. + strcat(archive->dpkg__buffer, "\n");
  10796. + data_skip(archive);
  10797. +}
  10798. +
  10799. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
  10800. +{
  10801. + archive_handle_t *archive;
  10802. + char *name;
  10803. + const char *filename = "./" IPKG_CONTROL_FILE;
  10804. +
  10805. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10806. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10807. + archive = init_handle();
  10808. + archive->src_fd = xopen(name, O_RDONLY);
  10809. + archive->filter = filter_accept_list;
  10810. + llist_add_to(&(archive->accept), (char *)filename);
  10811. + archive->action_data = ipkg_data_extract_to_buffer;
  10812. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10813. + close(archive->src_fd);
  10814. + fputs(archive->dpkg__buffer, stream);
  10815. + free(archive->dpkg__buffer);
  10816. + free(archive->accept);
  10817. + free(archive);
  10818. + free(name);
  10819. +
  10820. + return 0;
  10821. +}
  10822. +
  10823. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
  10824. +{
  10825. + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
  10826. +}
  10827. +
  10828. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
  10829. +{
  10830. + archive_handle_t *archive;
  10831. + char *name;
  10832. + char *path;
  10833. +
  10834. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10835. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10836. + sprintf_alloc(&path, "%s/%s", dir, prefix);
  10837. + archive = init_handle();
  10838. + archive->src_fd = xopen(name, O_RDONLY);
  10839. + archive->filter = filter_accept_all;
  10840. + archive->dpkg__buffer = path;
  10841. + archive->action_data = ipkg_data_extract_all_prefix;
  10842. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  10843. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10844. + close(archive->src_fd);
  10845. + free(archive);
  10846. + free(path);
  10847. + free(name);
  10848. +
  10849. + return 0;
  10850. +}
  10851. +
  10852. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
  10853. +{
  10854. + archive_handle_t *archive;
  10855. + char *name;
  10856. + char *path;
  10857. +
  10858. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  10859. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  10860. + sprintf_alloc(&path, "%s/", dir);
  10861. + archive = init_handle();
  10862. + archive->src_fd = xopen(name, O_RDONLY);
  10863. + archive->filter = filter_accept_all;
  10864. + archive->dpkg__buffer = path;
  10865. + archive->action_data = ipkg_data_extract_all_prefix;
  10866. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  10867. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10868. + close(archive->src_fd);
  10869. + free(archive);
  10870. + free(path);
  10871. + free(name);
  10872. +
  10873. + return 0;
  10874. +}
  10875. +
  10876. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
  10877. +{
  10878. + int err=0;
  10879. + char *line, *data_file;
  10880. + FILE *file;
  10881. + FILE *tmp;
  10882. +
  10883. + file = fopen(file_name, "w");
  10884. + if (file == NULL) {
  10885. + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
  10886. + __FUNCTION__, file_name);
  10887. + return EINVAL;
  10888. + }
  10889. +
  10890. + tmp = tmpfile();
  10891. + if (pkg->installed_files) {
  10892. + str_list_elt_t *elt;
  10893. + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
  10894. + fprintf(file, "%s\n", elt->data);
  10895. + }
  10896. + } else {
  10897. + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
  10898. + if (err) {
  10899. + fclose(file);
  10900. + fclose(tmp);
  10901. + return err;
  10902. + }
  10903. +
  10904. + /* Fixup data file names by removing the initial '.' */
  10905. + rewind(tmp);
  10906. + while (1) {
  10907. + line = file_read_line_alloc(tmp);
  10908. + if (line == NULL) {
  10909. + break;
  10910. + }
  10911. +
  10912. + data_file = line;
  10913. + if (*data_file == '.') {
  10914. + data_file++;
  10915. + }
  10916. +
  10917. + if (*data_file != '/') {
  10918. + fputs("/", file);
  10919. + }
  10920. +
  10921. + /* I have no idea why, but this is what dpkg does */
  10922. + if (strcmp(data_file, "/\n") == 0) {
  10923. + fputs("/.\n", file);
  10924. + } else {
  10925. + fputs(data_file, file);
  10926. + }
  10927. + }
  10928. + }
  10929. + fclose(tmp);
  10930. + fclose(file);
  10931. +
  10932. + return err;
  10933. +}
  10934. +
  10935. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
  10936. +{
  10937. + archive_handle_t *archive;
  10938. + char *name;
  10939. +
  10940. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  10941. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  10942. + archive = init_handle();
  10943. + archive->src_fd = xopen(name, O_RDONLY);
  10944. + archive->filter = filter_accept_all;
  10945. + archive->action_data = data_extract_file_name_to_buffer;
  10946. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10947. + close(archive->src_fd);
  10948. + fputs(archive->dpkg__buffer, file);
  10949. + free(archive->dpkg__buffer);
  10950. + free(archive);
  10951. + free(name);
  10952. +
  10953. + return 0;
  10954. +}
  10955. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_extract.h busybox-1.17.0/archival/libipkg/pkg_extract.h
  10956. --- busybox-1.17.0.orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
  10957. +++ busybox-1.17.0/archival/libipkg/pkg_extract.h 2010-07-08 12:01:56.243001712 +0200
  10958. @@ -0,0 +1,32 @@
  10959. +/* pkg_extract.c - the itsy package management system
  10960. +
  10961. + Carl D. Worth
  10962. +
  10963. + Copyright (C) 2001 University of Southern California
  10964. +
  10965. + This program is free software; you can redistribute it and/or
  10966. + modify it under the terms of the GNU General Public License as
  10967. + published by the Free Software Foundation; either version 2, or (at
  10968. + your option) any later version.
  10969. +
  10970. + This program is distributed in the hope that it will be useful, but
  10971. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10972. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10973. + General Public License for more details.
  10974. +*/
  10975. +
  10976. +#ifndef PKG_EXTRACT_H
  10977. +#define PKG_EXTRACT_H
  10978. +
  10979. +#include "pkg.h"
  10980. +
  10981. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
  10982. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
  10983. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
  10984. + const char *dir,
  10985. + const char *prefix);
  10986. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
  10987. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
  10988. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
  10989. +
  10990. +#endif
  10991. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg.h busybox-1.17.0/archival/libipkg/pkg.h
  10992. --- busybox-1.17.0.orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
  10993. +++ busybox-1.17.0/archival/libipkg/pkg.h 2010-07-08 12:01:56.243001712 +0200
  10994. @@ -0,0 +1,229 @@
  10995. +/* pkg.h - the itsy package management system
  10996. +
  10997. + Carl D. Worth
  10998. +
  10999. + Copyright (C) 2001 University of Southern California
  11000. +
  11001. + This program is free software; you can redistribute it and/or
  11002. + modify it under the terms of the GNU General Public License as
  11003. + published by the Free Software Foundation; either version 2, or (at
  11004. + your option) any later version.
  11005. +
  11006. + This program is distributed in the hope that it will be useful, but
  11007. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11008. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11009. + General Public License for more details.
  11010. +*/
  11011. +
  11012. +#ifndef PKG_H
  11013. +#define PKG_H
  11014. +
  11015. +#include <sys/types.h>
  11016. +#include <sys/stat.h>
  11017. +#include <unistd.h>
  11018. +
  11019. +#include "pkg_vec.h"
  11020. +#include "str_list.h"
  11021. +#include "pkg_src.h"
  11022. +#include "pkg_dest.h"
  11023. +#include "ipkg_conf.h"
  11024. +#include "conffile_list.h"
  11025. +
  11026. +struct ipkg_conf;
  11027. +
  11028. +/* I think "Size" is currently the shortest field name */
  11029. +#define PKG_MINIMUM_FIELD_NAME_LEN 4
  11030. +
  11031. +enum pkg_state_want
  11032. +{
  11033. + SW_UNKNOWN = 1,
  11034. + SW_INSTALL,
  11035. + SW_DEINSTALL,
  11036. + SW_PURGE,
  11037. + SW_LAST_STATE_WANT
  11038. +};
  11039. +typedef enum pkg_state_want pkg_state_want_t;
  11040. +
  11041. +enum pkg_state_flag
  11042. +{
  11043. + SF_OK = 0,
  11044. + SF_REINSTREQ = 1,
  11045. + SF_HOLD = 2, /* do not upgrade version */
  11046. + SF_REPLACE = 4, /* replace this package */
  11047. + SF_NOPRUNE = 8, /* do not remove obsolete files */
  11048. + SF_PREFER = 16, /* prefer this version */
  11049. + SF_OBSOLETE = 32, /* old package in upgrade pair */
  11050. + SF_MARKED = 64, /* temporary mark */
  11051. + SF_FILELIST_CHANGED = 128, /* needs filelist written */
  11052. + SF_USER = 256,
  11053. + SF_LAST_STATE_FLAG
  11054. +};
  11055. +typedef enum pkg_state_flag pkg_state_flag_t;
  11056. +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
  11057. +
  11058. +enum pkg_state_status
  11059. +{
  11060. + SS_NOT_INSTALLED = 1,
  11061. + SS_UNPACKED,
  11062. + SS_HALF_CONFIGURED,
  11063. + SS_INSTALLED,
  11064. + SS_HALF_INSTALLED,
  11065. + SS_CONFIG_FILES,
  11066. + SS_POST_INST_FAILED,
  11067. + SS_REMOVAL_FAILED,
  11068. + SS_LAST_STATE_STATUS
  11069. +};
  11070. +typedef enum pkg_state_status pkg_state_status_t;
  11071. +
  11072. +struct abstract_pkg{
  11073. + char * name;
  11074. + int dependencies_checked;
  11075. + pkg_vec_t * pkgs;
  11076. + pkg_state_status_t state_status;
  11077. + pkg_state_flag_t state_flag;
  11078. + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
  11079. + abstract_pkg_vec_t * provided_by;
  11080. + abstract_pkg_vec_t * replaced_by;
  11081. +};
  11082. +
  11083. +#include "pkg_depends.h"
  11084. +
  11085. +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
  11086. +
  11087. + The 3 version fields should go into a single version struct. (This
  11088. + is especially important since, currently, pkg->version can easily
  11089. + be mistaken for pkg_verson_str_alloc(pkg) although they are very
  11090. + distinct. This has been the source of multiple bugs.
  11091. +
  11092. + The 3 state fields could possibly also go into their own struct.
  11093. +
  11094. + All fields which deal with lists of packages, (Depends,
  11095. + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
  11096. + be handled by a single struct in pkg_t
  11097. +
  11098. + All string fields for which there is a small set of possible
  11099. + values, (section, maintainer, architecture, maybe version?), that
  11100. + are reused among different packages -- for all such packages we
  11101. + should move from "char *"s to some atom datatype to share data
  11102. + storage and use less memory. We might even do reference counting,
  11103. + but probably not since most often we only create new pkg_t structs,
  11104. + we don't often free them. */
  11105. +struct pkg
  11106. +{
  11107. + char *name;
  11108. + unsigned long epoch;
  11109. + char *version;
  11110. + char *revision;
  11111. + char *familiar_revision;
  11112. + pkg_src_t *src;
  11113. + pkg_dest_t *dest;
  11114. + char *architecture;
  11115. + char *section;
  11116. + char *maintainer;
  11117. + char *description;
  11118. + pkg_state_want_t state_want;
  11119. + pkg_state_flag_t state_flag;
  11120. + pkg_state_status_t state_status;
  11121. + char **depends_str;
  11122. + int depends_count;
  11123. + char **pre_depends_str;
  11124. + int pre_depends_count;
  11125. + char **recommends_str;
  11126. + int recommends_count;
  11127. + char **suggests_str;
  11128. + int suggests_count;
  11129. + compound_depend_t * depends;
  11130. +
  11131. + /* Abhaya: new conflicts */
  11132. + char **conflicts_str;
  11133. + compound_depend_t * conflicts;
  11134. + int conflicts_count;
  11135. +
  11136. + char **replaces_str;
  11137. + int replaces_count;
  11138. + abstract_pkg_t ** replaces;
  11139. +
  11140. + char **provides_str;
  11141. + int provides_count;
  11142. + abstract_pkg_t ** provides;
  11143. +
  11144. + abstract_pkg_t *parent;
  11145. +
  11146. + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
  11147. +
  11148. + char *filename;
  11149. + char *local_filename;
  11150. + char *url;
  11151. + char *tmp_unpack_dir;
  11152. + char *md5sum;
  11153. + char *size;
  11154. + char *installed_size;
  11155. + char *priority;
  11156. + char *source;
  11157. + conffile_list_t conffiles;
  11158. + time_t installed_time;
  11159. + /* As pointer for lazy evaluation */
  11160. + str_list_t *installed_files;
  11161. + /* XXX: CLEANUP: I'd like to perhaps come up with a better
  11162. + mechanism to avoid the problem here, (which is that the
  11163. + installed_files list was being freed from an inner loop while
  11164. + still being used within an outer loop. */
  11165. + int installed_files_ref_cnt;
  11166. + int essential;
  11167. + int arch_priority;
  11168. +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
  11169. + int provided_by_hand;
  11170. +};
  11171. +
  11172. +pkg_t *pkg_new(void);
  11173. +int pkg_init(pkg_t *pkg);
  11174. +void pkg_deinit(pkg_t *pkg);
  11175. +int pkg_init_from_file(pkg_t *pkg, const char *filename);
  11176. +abstract_pkg_t *abstract_pkg_new(void);
  11177. +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
  11178. +
  11179. +/*
  11180. + * merges fields from newpkg into oldpkg.
  11181. + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
  11182. + */
  11183. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
  11184. +
  11185. +char *pkg_version_str_alloc(pkg_t *pkg);
  11186. +
  11187. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
  11188. +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
  11189. +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
  11190. +
  11191. +char * pkg_formatted_info(pkg_t *pkg );
  11192. +char * pkg_formatted_field(pkg_t *pkg, const char *field );
  11193. +
  11194. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
  11195. +
  11196. +void pkg_print_info(pkg_t *pkg, FILE *file);
  11197. +void pkg_print_status(pkg_t * pkg, FILE * file);
  11198. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
  11199. +str_list_t *pkg_get_installed_files(pkg_t *pkg);
  11200. +int pkg_free_installed_files(pkg_t *pkg);
  11201. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
  11202. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
  11203. +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
  11204. + const char *script, const char *args);
  11205. +
  11206. +/* enum mappings */
  11207. +char *pkg_state_want_to_str(pkg_state_want_t sw);
  11208. +pkg_state_want_t pkg_state_want_from_str(char *str);
  11209. +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
  11210. +pkg_state_flag_t pkg_state_flag_from_str(char *str);
  11211. +char *pkg_state_status_to_str(pkg_state_status_t ss);
  11212. +pkg_state_status_t pkg_state_status_from_str(char *str);
  11213. +
  11214. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
  11215. +
  11216. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
  11217. +int pkg_info_preinstall_check(ipkg_conf_t *conf);
  11218. +int pkg_free_installed_files(pkg_t *pkg);
  11219. +
  11220. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
  11221. +int pkg_write_changed_filelists(ipkg_conf_t *conf);
  11222. +
  11223. +#endif
  11224. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_hash.c busybox-1.17.0/archival/libipkg/pkg_hash.c
  11225. --- busybox-1.17.0.orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
  11226. +++ busybox-1.17.0/archival/libipkg/pkg_hash.c 2010-07-08 12:01:56.243001712 +0200
  11227. @@ -0,0 +1,623 @@
  11228. +/* ipkg_hash.c - the itsy package management system
  11229. +
  11230. + Steven M. Ayer
  11231. +
  11232. + Copyright (C) 2002 Compaq Computer Corporation
  11233. +
  11234. + This program is free software; you can redistribute it and/or
  11235. + modify it under the terms of the GNU General Public License as
  11236. + published by the Free Software Foundation; either version 2, or (at
  11237. + your option) any later version.
  11238. +
  11239. + This program is distributed in the hope that it will be useful, but
  11240. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11241. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11242. + General Public License for more details.
  11243. +*/
  11244. +
  11245. +#include "ipkg.h"
  11246. +#include <errno.h>
  11247. +#include <ctype.h>
  11248. +#include <stdlib.h>
  11249. +#include <string.h>
  11250. +
  11251. +#include "hash_table.h"
  11252. +#include "pkg.h"
  11253. +#include "ipkg_message.h"
  11254. +#include "pkg_vec.h"
  11255. +#include "pkg_hash.h"
  11256. +#include "pkg_parse.h"
  11257. +#include "ipkg_utils.h"
  11258. +
  11259. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11260. +
  11261. +/*
  11262. + * this will talk to both feeds-lists files and installed status files
  11263. + * example api:
  11264. + *
  11265. + * hash_table_t hash;
  11266. + * pkg_hash_init(name, &hash, 1000);
  11267. + * pkg_hash_add_from_file(<feed filename>);
  11268. + *
  11269. + * the query function is just there as a shell to prove to me that this
  11270. + * sort of works, but isn't far from doing something useful
  11271. + *
  11272. + * -sma, 12/21/01
  11273. + * modified: CDW 3 Jan. 2002
  11274. + */
  11275. +
  11276. +
  11277. +
  11278. +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
  11279. +{
  11280. + return hash_table_init(name, hash, len);
  11281. +}
  11282. +
  11283. +void pkg_hash_deinit(hash_table_t *hash)
  11284. +{
  11285. + hash_table_deinit(hash);
  11286. +}
  11287. +
  11288. +
  11289. +/* Find the default arch for a given package status file if none is given. */
  11290. +static char *pkg_get_default_arch(ipkg_conf_t *conf)
  11291. +{
  11292. + nv_pair_list_elt_t *l;
  11293. + const char *def_arch = HOST_CPU_STR; /* Default arch */
  11294. + int def_prio = 0; /* Other archs override this */
  11295. +
  11296. + l = conf->arch_list.head;
  11297. +
  11298. + while (l) {
  11299. + nv_pair_t *nv = l->data;
  11300. + int priority = strtol(nv->value, NULL, 0);
  11301. +
  11302. + /* Check if this arch has higher priority, and is valid */
  11303. + if ((priority > def_prio) &&
  11304. + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
  11305. + /* Our new default */
  11306. + def_prio = priority;
  11307. + def_arch = nv->name;
  11308. + }
  11309. + l = l->next;
  11310. + }
  11311. +
  11312. + return strdup(def_arch);
  11313. +}
  11314. +
  11315. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11316. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
  11317. +{
  11318. + hash_table_t *hash = &conf->pkg_hash;
  11319. + char **raw;
  11320. + char **raw_start;
  11321. + pkg_t *pkg;
  11322. +
  11323. + raw = raw_start = read_raw_pkgs_from_file(file_name);
  11324. + if (!raw)
  11325. + return -ENOMEM;
  11326. +
  11327. + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
  11328. + pkg = pkg_new();
  11329. + if (!pkg)
  11330. + return -ENOMEM;
  11331. +
  11332. + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
  11333. + if (!pkg->architecture) {
  11334. + char *version_str = pkg_version_str_alloc(pkg);
  11335. + pkg->architecture = pkg_get_default_arch(conf);
  11336. + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
  11337. + pkg->name, version_str, pkg->architecture);
  11338. + free(version_str);
  11339. + }
  11340. + hash_insert_pkg(hash, pkg, is_status_file,conf);
  11341. + } else {
  11342. + free(pkg);
  11343. + }
  11344. + }
  11345. +
  11346. + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
  11347. + memory after read_raw_pkgs_from_file */
  11348. + raw = raw_start;
  11349. + while (*raw) {
  11350. + free(*raw++);
  11351. + }
  11352. + free(raw_start);
  11353. + return 0;
  11354. +}
  11355. +
  11356. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
  11357. +{
  11358. + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
  11359. +}
  11360. +
  11361. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
  11362. +{
  11363. + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
  11364. + if (apkg)
  11365. + return NULL;
  11366. + return apkg->provided_by;
  11367. +}
  11368. +
  11369. +
  11370. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11371. + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
  11372. +{
  11373. + int i;
  11374. + int nprovides = 0;
  11375. + int nmatching = 0;
  11376. + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
  11377. + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
  11378. + abstract_pkg_vec_t *provided_apkg_vec;
  11379. + abstract_pkg_t **provided_apkgs;
  11380. + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
  11381. + pkg_t *latest_installed_parent = NULL;
  11382. + pkg_t *latest_matching = NULL;
  11383. + pkg_t *held_pkg = NULL;
  11384. + pkg_t *good_pkg_by_name = NULL;
  11385. +
  11386. + if (matching_apkgs == NULL || providers == NULL ||
  11387. + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
  11388. + return NULL;
  11389. +
  11390. + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
  11391. +
  11392. + provided_apkg_vec = apkg->provided_by;
  11393. + nprovides = provided_apkg_vec->len;
  11394. + provided_apkgs = provided_apkg_vec->pkgs;
  11395. + if (nprovides > 1)
  11396. + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
  11397. +
  11398. + /* accumulate all the providers */
  11399. + for (i = 0; i < nprovides; i++) {
  11400. + abstract_pkg_t *provider_apkg = provided_apkgs[i];
  11401. + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
  11402. + abstract_pkg_vec_insert(providers, provider_apkg);
  11403. + }
  11404. + nprovides = providers->len;
  11405. +
  11406. + for (i = 0; i < nprovides; i++) {
  11407. + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
  11408. + abstract_pkg_t *replacement_apkg = NULL;
  11409. + pkg_vec_t *vec;
  11410. +
  11411. + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
  11412. + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
  11413. + if (provider_apkg->replaced_by->len > 1) {
  11414. + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
  11415. + provider_apkg->name, replacement_apkg->name);
  11416. + }
  11417. + }
  11418. +
  11419. + if (replacement_apkg)
  11420. + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
  11421. + replacement_apkg->name, provider_apkg->name);
  11422. +
  11423. + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
  11424. + if (abstract_pkg_vec_contains(providers, replacement_apkg))
  11425. + continue;
  11426. + else
  11427. + provider_apkg = replacement_apkg;
  11428. + }
  11429. +
  11430. + if (!(vec = provider_apkg->pkgs)) {
  11431. + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
  11432. + continue;
  11433. + }
  11434. +
  11435. +
  11436. + /* now check for supported architecture */
  11437. + {
  11438. + int max_count = 0;
  11439. + int j;
  11440. +
  11441. + /* count packages matching max arch priority and keep track of last one */
  11442. + for (j = 0; j < vec->len; j++) {
  11443. + pkg_t *maybe = vec->pkgs[j];
  11444. + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
  11445. + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
  11446. + if (maybe->arch_priority > 0) {
  11447. + max_count++;
  11448. + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
  11449. + pkg_vec_insert(matching_pkgs, maybe);
  11450. + }
  11451. + }
  11452. + }
  11453. + }
  11454. +
  11455. + if (matching_pkgs->len > 1)
  11456. + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
  11457. + if (matching_apkgs->len > 1)
  11458. + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
  11459. +
  11460. +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
  11461. + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
  11462. +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
  11463. + Until now I always got the latest, but that breaks the downgrade option.
  11464. + If I stop at the first one, I would probably miss the new ones
  11465. + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
  11466. + or from a Packages feed.
  11467. + 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*/
  11468. +/*Pigi*/
  11469. +
  11470. + for (i = 0; i < matching_pkgs->len; i++) {
  11471. + pkg_t *matching = matching_pkgs->pkgs[i];
  11472. + if (constraint_fcn(matching, cdata)) { /* We found it */
  11473. + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
  11474. + good_pkg_by_name = matching;
  11475. + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
  11476. + break;
  11477. + }
  11478. + }
  11479. +
  11480. +
  11481. + for (i = 0; i < matching_pkgs->len; i++) {
  11482. + pkg_t *matching = matching_pkgs->pkgs[i];
  11483. + latest_matching = matching;
  11484. + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
  11485. + latest_installed_parent = matching;
  11486. + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
  11487. + if (held_pkg)
  11488. + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
  11489. + held_pkg->name, matching->name);
  11490. + held_pkg = matching;
  11491. + }
  11492. + }
  11493. +
  11494. + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
  11495. + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
  11496. + apkg->name, matching_apkgs->len);
  11497. + for (i = 0; i < matching_apkgs->len; i++) {
  11498. + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
  11499. + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
  11500. + }
  11501. + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
  11502. + }
  11503. +
  11504. + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
  11505. + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
  11506. + __FUNCTION__, apkg->name, matching_pkgs->len);
  11507. + for (i = 0; i < matching_pkgs->len; i++) {
  11508. + pkg_t *matching = matching_pkgs->pkgs[i];
  11509. + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
  11510. + matching->name, matching->version, matching->architecture);
  11511. + }
  11512. + }
  11513. +
  11514. + nmatching = matching_apkgs->len;
  11515. +
  11516. + pkg_vec_free(matching_pkgs);
  11517. + abstract_pkg_vec_free(matching_apkgs);
  11518. + abstract_pkg_vec_free(providers);
  11519. +
  11520. + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
  11521. + return good_pkg_by_name;
  11522. + }
  11523. + if (held_pkg) {
  11524. + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
  11525. + return held_pkg;
  11526. + }
  11527. + if (latest_installed_parent) {
  11528. + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
  11529. + return latest_installed_parent;
  11530. + }
  11531. + if (nmatching > 1) {
  11532. + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
  11533. + return NULL;
  11534. + }
  11535. + if (latest_matching) {
  11536. + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
  11537. + latest_matching->name, latest_matching->version, latest_matching->architecture);
  11538. + return latest_matching;
  11539. + }
  11540. + return NULL;
  11541. +}
  11542. +
  11543. +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
  11544. +{
  11545. + const char *name = (const char *)cdata;
  11546. + if (strcmp(pkg->name, name) == 0)
  11547. + return 1;
  11548. + else
  11549. + return 0;
  11550. +}
  11551. +
  11552. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
  11553. +{
  11554. + hash_table_t *hash = &conf->pkg_hash;
  11555. + abstract_pkg_t *apkg = NULL;
  11556. +
  11557. + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
  11558. + return NULL;
  11559. +
  11560. + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
  11561. +}
  11562. +
  11563. +
  11564. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11565. + const char *pkg_name,
  11566. + const char * version)
  11567. +{
  11568. + pkg_vec_t * vec;
  11569. + register int i;
  11570. + char *version_str = NULL;
  11571. +
  11572. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
  11573. + return NULL;
  11574. +
  11575. + for(i = 0; i < vec->len; i++) {
  11576. + version_str = pkg_version_str_alloc(vec->pkgs[i]);
  11577. + if(!strcmp(version_str, version)) {
  11578. + free(version_str);
  11579. + break;
  11580. + }
  11581. + free(version_str);
  11582. + }
  11583. +
  11584. + if(i == vec->len)
  11585. + return NULL;
  11586. +
  11587. + return vec->pkgs[i];
  11588. +}
  11589. +
  11590. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11591. + const char *pkg_name,
  11592. + pkg_dest_t *dest)
  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) && vec->pkgs[i]->dest == dest) {
  11603. + return vec->pkgs[i];
  11604. + }
  11605. + return NULL;
  11606. +}
  11607. +
  11608. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11609. + const char *pkg_name)
  11610. +{
  11611. + pkg_vec_t * vec;
  11612. + register int i;
  11613. +
  11614. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
  11615. + return NULL;
  11616. + }
  11617. +
  11618. + for(i = 0; i < vec->len; i++)
  11619. + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
  11620. + return vec->pkgs[i];
  11621. + }
  11622. +
  11623. + return NULL;
  11624. +}
  11625. +
  11626. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
  11627. +{
  11628. + abstract_pkg_t * ab_pkg;
  11629. +
  11630. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
  11631. + return NULL;
  11632. + }
  11633. +
  11634. + if (ab_pkg->pkgs) {
  11635. + return ab_pkg->pkgs;
  11636. + } else if (ab_pkg->provided_by) {
  11637. + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
  11638. + if (abpkg != NULL){
  11639. + return abpkg->pkgs;
  11640. + } else {
  11641. + return ab_pkg->pkgs;
  11642. + }
  11643. + } else {
  11644. + return NULL;
  11645. + }
  11646. +}
  11647. +
  11648. +static int pkg_compare_names(const void *p1, const void *p2)
  11649. +{
  11650. + const pkg_t *pkg1 = *(const pkg_t **)p1;
  11651. + const pkg_t *pkg2 = *(const pkg_t **)p2;
  11652. + if (pkg1->name == NULL)
  11653. + return 1;
  11654. + if (pkg2->name == NULL)
  11655. + return -1;
  11656. + return(strcmp(pkg1->name, pkg2->name));
  11657. +}
  11658. +
  11659. +
  11660. +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
  11661. +{
  11662. + int j;
  11663. + const char *name;
  11664. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11665. + pkg_vec_t *all = (pkg_vec_t *)data;
  11666. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11667. + name = pkg_name;
  11668. + if (pkg_vec) {
  11669. + for (j = 0; j < pkg_vec->len; j++) {
  11670. + pkg_t *pkg = pkg_vec->pkgs[j];
  11671. + pkg_vec_insert(all, pkg);
  11672. + }
  11673. + }
  11674. +}
  11675. +
  11676. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
  11677. +{
  11678. + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
  11679. + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
  11680. +}
  11681. +
  11682. +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
  11683. +{
  11684. + const char *name;
  11685. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11686. + pkg_vec_t *all = (pkg_vec_t *)data;
  11687. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11688. + int j;
  11689. + name = pkg_name;
  11690. + if (pkg_vec) {
  11691. + for (j = 0; j < pkg_vec->len; j++) {
  11692. + pkg_t *pkg = pkg_vec->pkgs[j];
  11693. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  11694. + pkg_vec_insert(all, pkg);
  11695. + }
  11696. + }
  11697. + }
  11698. +}
  11699. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
  11700. +{
  11701. + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
  11702. + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
  11703. +}
  11704. +
  11705. +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
  11706. +{
  11707. + int i;
  11708. + pkg_t *pkg;
  11709. + const char *name;
  11710. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11711. + ipkg_conf_t *conf = (ipkg_conf_t *)data;
  11712. + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
  11713. + name = pkg_name;
  11714. + fprintf(stdout, "%s\n", ab_pkg->name);
  11715. + i = 0;
  11716. + if (dependents != NULL)
  11717. + while (dependents [i] != NULL)
  11718. + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
  11719. + dependents = ab_pkg->provided_by->pkgs;
  11720. + i = 0;
  11721. + if (dependents != NULL)
  11722. + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
  11723. + printf ("\tprovided by - %s\n", dependents [i ++]->name);
  11724. + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
  11725. + if (pkg) {
  11726. + i = 0;
  11727. + while (i < pkg->depends_count)
  11728. + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
  11729. + }
  11730. +}
  11731. +void pkg_hash_dump(hash_table_t *hash, void *data)
  11732. +{
  11733. +
  11734. + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
  11735. + hash_table_foreach(hash, pkg_hash_dump_helper, data);
  11736. + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
  11737. +}
  11738. +
  11739. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11740. +{
  11741. + abstract_pkg_t * ab_pkg;
  11742. +
  11743. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
  11744. + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
  11745. +
  11746. + return ab_pkg;
  11747. +}
  11748. +
  11749. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  11750. +{
  11751. + abstract_pkg_t * ab_pkg;
  11752. + int arch_priority;
  11753. +
  11754. + if(!pkg)
  11755. + return pkg;
  11756. +
  11757. + arch_priority = pkg->arch_priority;
  11758. +
  11759. + if (buildDepends(hash, pkg)<0){
  11760. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11761. + return NULL;
  11762. + }
  11763. + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
  11764. +
  11765. + if (set_status) {
  11766. + if (pkg->state_status == SS_INSTALLED) {
  11767. + ab_pkg->state_status = SS_INSTALLED;
  11768. + } else if (pkg->state_status == SS_UNPACKED) {
  11769. + ab_pkg->state_status = SS_UNPACKED;
  11770. + }
  11771. + }
  11772. +
  11773. + if(!ab_pkg->pkgs)
  11774. + ab_pkg->pkgs = pkg_vec_alloc();
  11775. +
  11776. + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
  11777. + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
  11778. + pkg->parent = ab_pkg;
  11779. +
  11780. + if (buildProvides(hash, ab_pkg, pkg)<0){
  11781. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11782. + return NULL;
  11783. + }
  11784. + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
  11785. + if (buildConflicts(hash, pkg)<0){
  11786. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11787. + return NULL;
  11788. + }
  11789. + if (buildReplaces(hash, ab_pkg, pkg)<0) {
  11790. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11791. + return NULL;
  11792. + }
  11793. +
  11794. + buildDependedUponBy(pkg, ab_pkg);
  11795. + return pkg;
  11796. +}
  11797. +
  11798. +/*
  11799. + * this will assume that we've already determined that
  11800. + * the abstract pkg doesn't exist, 'cause we should know these things...
  11801. + */
  11802. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11803. +{
  11804. + abstract_pkg_t * ab_pkg;
  11805. +
  11806. + ab_pkg = abstract_pkg_new();
  11807. + if (ab_pkg == NULL) { return NULL; }
  11808. +
  11809. + ab_pkg->name = strdup(pkg_name);
  11810. + hash_table_insert(hash, pkg_name, ab_pkg);
  11811. +
  11812. + return ab_pkg;
  11813. +}
  11814. +
  11815. +
  11816. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
  11817. +{
  11818. + hash_table_t *file_hash = &conf->file_hash;
  11819. +
  11820. + return hash_table_get(file_hash, file_name);
  11821. +}
  11822. +
  11823. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
  11824. +{
  11825. + hash_table_t *file_hash = &conf->file_hash;
  11826. + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
  11827. + int file_name_len = strlen(file_name);
  11828. +
  11829. + if (file_name[file_name_len -1] == '/')
  11830. + return 0;
  11831. +
  11832. + if (conf->offline_root) {
  11833. + int len = strlen(conf->offline_root);
  11834. + if (strncmp(file_name, conf->offline_root, len) == 0) {
  11835. + file_name += len;
  11836. + }
  11837. + }
  11838. +
  11839. + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
  11840. + hash_table_insert(file_hash, file_name, owning_pkg);
  11841. + if (old_owning_pkg) {
  11842. + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
  11843. + /* mark this package to have its filelist written */
  11844. + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11845. + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11846. + }
  11847. + return 0;
  11848. +}
  11849. +
  11850. +
  11851. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_hash.h busybox-1.17.0/archival/libipkg/pkg_hash.h
  11852. --- busybox-1.17.0.orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
  11853. +++ busybox-1.17.0/archival/libipkg/pkg_hash.h 2010-07-08 12:01:56.327000396 +0200
  11854. @@ -0,0 +1,61 @@
  11855. +/* pkg_hash.h - the itsy package management system
  11856. +
  11857. + Steven M. Ayer
  11858. +
  11859. + Copyright (C) 2002 Compaq Computer Corporation
  11860. +
  11861. + This program is free software; you can redistribute it and/or
  11862. + modify it under the terms of the GNU General Public License as
  11863. + published by the Free Software Foundation; either version 2, or (at
  11864. + your option) any later version.
  11865. +
  11866. + This program is distributed in the hope that it will be useful, but
  11867. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11868. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11869. + General Public License for more details.
  11870. +*/
  11871. +
  11872. +#ifndef PKG_HASH_H
  11873. +#define PKG_HASH_H
  11874. +
  11875. +#include "pkg.h"
  11876. +#include "pkg_vec.h"
  11877. +#include "hash_table.h"
  11878. +
  11879. +
  11880. +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
  11881. +void pkg_hash_deinit(hash_table_t *hash);
  11882. +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
  11883. +
  11884. +void pkg_hash_dump(hash_table_t *hash, void *data);
  11885. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
  11886. +
  11887. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11888. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
  11889. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
  11890. +
  11891. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11892. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
  11893. +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11894. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
  11895. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11896. + const char *pkg_name,
  11897. + const char * version);
  11898. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
  11899. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11900. + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
  11901. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
  11902. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11903. + const char *pkg_name);
  11904. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11905. + const char *pkg_name,
  11906. + pkg_dest_t *dest);
  11907. +
  11908. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
  11909. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
  11910. +
  11911. +/* XXX: shouldn't this go in pkg_vec.[ch]? */
  11912. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11913. +
  11914. +#endif
  11915. +
  11916. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_parse.c busybox-1.17.0/archival/libipkg/pkg_parse.c
  11917. --- busybox-1.17.0.orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
  11918. +++ busybox-1.17.0/archival/libipkg/pkg_parse.c 2010-07-08 12:01:56.343005785 +0200
  11919. @@ -0,0 +1,368 @@
  11920. +/* pkg_parse.c - the itsy package management system
  11921. +
  11922. + Steven M. Ayer
  11923. +
  11924. + Copyright (C) 2002 Compaq Computer Corporation
  11925. +
  11926. + This program is free software; you can redistribute it and/or
  11927. + modify it under the terms of the GNU General Public License as
  11928. + published by the Free Software Foundation; either version 2, or (at
  11929. + your option) any later version.
  11930. +
  11931. + This program is distributed in the hope that it will be useful, but
  11932. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11933. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11934. + General Public License for more details.
  11935. +*/
  11936. +
  11937. +#include "ipkg.h"
  11938. +#include <errno.h>
  11939. +#include <ctype.h>
  11940. +
  11941. +#include "pkg.h"
  11942. +#include "ipkg_utils.h"
  11943. +#include "pkg_parse.h"
  11944. +
  11945. +int alterProvidesLine(char *raw, char *temp);
  11946. +
  11947. +int isGenericFieldType(char * type, char * line)
  11948. +{
  11949. + if(!strncmp(line, type, strlen(type)))
  11950. + return 1;
  11951. + return 0;
  11952. +}
  11953. +
  11954. +char * parseGenericFieldType(char * type, char * raw)
  11955. +{
  11956. + char * field_value = raw + (strlen(type) + 1);
  11957. + return trim_alloc(field_value);
  11958. +}
  11959. +
  11960. +void parseStatus(pkg_t *pkg, char * raw)
  11961. +{
  11962. + char sw_str[64], sf_str[64], ss_str[64];
  11963. +
  11964. + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
  11965. + pkg->state_want = pkg_state_want_from_str(sw_str);
  11966. + pkg->state_flag = pkg_state_flag_from_str(sf_str);
  11967. + pkg->state_status = pkg_state_status_from_str(ss_str);
  11968. +}
  11969. +
  11970. +char ** parseDependsString(char * raw, int * depends_count)
  11971. +{
  11972. + char ** depends = NULL;
  11973. + int line_count = 0;
  11974. + char buff[2048], * dest;
  11975. +
  11976. + while(raw && *raw && !isspace(*raw)) {
  11977. + raw++;
  11978. + }
  11979. +
  11980. + if(line_is_blank(raw)){
  11981. + *depends_count = line_count;
  11982. + return NULL;
  11983. + }
  11984. + while(raw && *raw){
  11985. + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
  11986. +
  11987. + while(isspace(*raw)) raw++;
  11988. +
  11989. + dest = buff;
  11990. + while((*raw != ',') && *raw)
  11991. + *dest++ = *raw++;
  11992. +
  11993. + *dest = '\0';
  11994. + depends[line_count] = trim_alloc(buff);
  11995. + if(depends[line_count] ==NULL)
  11996. + return NULL;
  11997. + line_count++;
  11998. + if(*raw == ',')
  11999. + raw++;
  12000. + }
  12001. + *depends_count = line_count;
  12002. + return depends;
  12003. +}
  12004. +
  12005. +void parseConffiles(pkg_t * pkg, char * raw)
  12006. +{
  12007. + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
  12008. +
  12009. + if(!strncmp(raw, "Conffiles:", 10))
  12010. + raw += strlen("Conffiles:");
  12011. +
  12012. + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
  12013. + conffile_list_append(&pkg->conffiles, file_name, md5sum);
  12014. + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
  12015. + while (*raw && isspace(*raw)) {
  12016. + raw++;
  12017. + }
  12018. + raw += strlen(file_name);
  12019. + while (*raw && isspace(*raw)) {
  12020. + raw++;
  12021. + }
  12022. + raw += strlen(md5sum);
  12023. + }
  12024. +}
  12025. +
  12026. +int parseVersion(pkg_t *pkg, char *raw)
  12027. +{
  12028. + char *colon, *eepochcolon;
  12029. +#ifdef USE_DEBVERSION
  12030. + char *hyphen;
  12031. +#endif
  12032. + unsigned long epoch;
  12033. +
  12034. + if (!*raw) {
  12035. + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
  12036. + return EINVAL;
  12037. + }
  12038. +
  12039. + if (strncmp(raw, "Version:", 8) == 0) {
  12040. + raw += 8;
  12041. + }
  12042. + while (*raw && isspace(*raw)) {
  12043. + raw++;
  12044. + }
  12045. +
  12046. + colon= strchr(raw,':');
  12047. + if (colon) {
  12048. + epoch= strtoul(raw,&eepochcolon,10);
  12049. + if (colon != eepochcolon) {
  12050. + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
  12051. + return EINVAL;
  12052. + }
  12053. + if (!*++colon) {
  12054. + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
  12055. + return EINVAL;
  12056. + }
  12057. + raw= colon;
  12058. + pkg->epoch= epoch;
  12059. + } else {
  12060. + pkg->epoch= 0;
  12061. + }
  12062. +
  12063. + pkg->revision = (char *)"";
  12064. + pkg->familiar_revision = (char *)"";
  12065. +
  12066. + pkg->version= malloc(strlen(raw)+1);
  12067. + if ( pkg->version == NULL ) {
  12068. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12069. + return ENOMEM;
  12070. + }
  12071. + strcpy(pkg->version, raw);
  12072. +
  12073. +#ifdef USE_DEBVERSION
  12074. + hyphen= strrchr(pkg->version,'-');
  12075. +
  12076. + if (hyphen) {
  12077. + *hyphen++= 0;
  12078. + if (strncmp("fam", hyphen, 3) == 0) {
  12079. + pkg->familiar_revision=hyphen+3;
  12080. + hyphen= strrchr(pkg->version,'-');
  12081. + if (hyphen) {
  12082. + *hyphen++= 0;
  12083. + pkg->revision = hyphen;
  12084. + }
  12085. + } else {
  12086. + pkg->revision = hyphen;
  12087. + }
  12088. + }
  12089. +#endif
  12090. +
  12091. +/*
  12092. + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
  12093. + pkg->epoch,
  12094. + pkg->version,
  12095. + pkg->revision,
  12096. + pkg->familiar_revision);
  12097. +*/
  12098. +
  12099. + return 0;
  12100. +}
  12101. +
  12102. +
  12103. +/* This code is needed to insert in first position the keyword for the aligning bug */
  12104. +
  12105. +int alterProvidesLine(char *raw, char *temp)
  12106. +{
  12107. +
  12108. +
  12109. + if (!*raw) {
  12110. + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
  12111. + return -EINVAL;
  12112. + }
  12113. +
  12114. + if ( temp == NULL ) {
  12115. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12116. + return -ENOMEM;
  12117. + }
  12118. +
  12119. + if (strncmp(raw, "Provides:", 9) == 0) {
  12120. + raw += 9;
  12121. + }
  12122. + while (*raw && isspace(*raw)) {
  12123. + raw++;
  12124. + }
  12125. +
  12126. + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
  12127. + while (*raw) {
  12128. + strncat( temp, raw++, 1);
  12129. + }
  12130. + return 0;
  12131. +
  12132. +}
  12133. +
  12134. +/* Some random thoughts from Carl:
  12135. +
  12136. + This function could be considerably simplified if we just kept
  12137. + an array of all the generic string-valued field names, and looped
  12138. + through those looking for a match. Also, these fields could perhaps
  12139. + be stored in the package as an array as well, (or, probably better,
  12140. + as an nv_pair_list_t).
  12141. +
  12142. + Fields which require special parsing or storage, (such as Depends:
  12143. + and Status:) could be handled as they are now.
  12144. +*/
  12145. +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
  12146. + to a dependency list. And, since we already have
  12147. + Depends/Pre-Depends and need to add Conflicts, Recommends, and
  12148. + Enhances, perhaps we could generalize all of these and save some
  12149. + code duplication.
  12150. +*/
  12151. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
  12152. +{
  12153. + int reading_conffiles, reading_description;
  12154. + int pkg_false_provides=1;
  12155. + char ** lines;
  12156. + char * provide=NULL;
  12157. +
  12158. + pkg->src = src;
  12159. + pkg->dest = dest;
  12160. +
  12161. + reading_conffiles = reading_description = 0;
  12162. +
  12163. + for (lines = *raw; *lines; lines++) {
  12164. + /* fprintf(stderr, "PARSING %s\n", *lines);*/
  12165. + if(isGenericFieldType((char *)"Package:", *lines))
  12166. + pkg->name = parseGenericFieldType((char *)"Package", *lines);
  12167. + else if(isGenericFieldType((char *)"Architecture:", *lines))
  12168. + pkg->architecture = parseGenericFieldType((char *)"Architecture", *lines);
  12169. + else if(isGenericFieldType((char *)"Filename:", *lines))
  12170. + pkg->filename = parseGenericFieldType((char *)"Filename", *lines);
  12171. + else if(isGenericFieldType((char *)"Section:", *lines))
  12172. + pkg->section = parseGenericFieldType((char *)"Section", *lines);
  12173. + else if(isGenericFieldType((char *)"MD5sum:", *lines))
  12174. + pkg->md5sum = parseGenericFieldType((char *)"MD5sum", *lines);
  12175. + /* The old ipkg wrote out status files with the wrong case for MD5sum,
  12176. + let's parse it either way */
  12177. + else if(isGenericFieldType((char *)"MD5Sum:", *lines))
  12178. + pkg->md5sum = parseGenericFieldType((char *)"MD5Sum", *lines);
  12179. + else if(isGenericFieldType((char *)"Size:", *lines))
  12180. + pkg->size = parseGenericFieldType((char *)"Size", *lines);
  12181. + else if(isGenericFieldType((char *)"Source:", *lines))
  12182. + pkg->source = parseGenericFieldType((char *)"Source", *lines);
  12183. + else if(isGenericFieldType((char *)"Installed-Size:", *lines))
  12184. + pkg->installed_size = parseGenericFieldType((char *)"Installed-Size", *lines);
  12185. + else if(isGenericFieldType((char *)"Installed-Time:", *lines)) {
  12186. + char *time_str = parseGenericFieldType((char *)"Installed-Time", *lines);
  12187. + pkg->installed_time = strtoul(time_str, NULL, 0);
  12188. + } else if(isGenericFieldType((char *)"Priority:", *lines))
  12189. + pkg->priority = parseGenericFieldType((char *)"Priority", *lines);
  12190. + else if(isGenericFieldType((char *)"Essential:", *lines)) {
  12191. + char *essential_value;
  12192. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12193. + if (strcmp(essential_value, "yes") == 0) {
  12194. + pkg->essential = 1;
  12195. + }
  12196. + free(essential_value);
  12197. + }
  12198. + else if(isGenericFieldType((char *)"Status", *lines))
  12199. + parseStatus(pkg, *lines);
  12200. + else if(isGenericFieldType((char *)"Version", *lines))
  12201. + parseVersion(pkg, *lines);
  12202. + else if(isGenericFieldType((char *)"Maintainer", *lines))
  12203. + pkg->maintainer = parseGenericFieldType((char *)"Maintainer", *lines);
  12204. + else if(isGenericFieldType((char *)"Conffiles", *lines)){
  12205. + parseConffiles(pkg, *lines);
  12206. + reading_conffiles = 1;
  12207. + }
  12208. + else if(isGenericFieldType((char *)"Description", *lines)) {
  12209. + pkg->description = parseGenericFieldType((char *)"Description", *lines);
  12210. + reading_conffiles = 0;
  12211. + reading_description = 1;
  12212. + }
  12213. +
  12214. + else if(isGenericFieldType((char *)"Provides", *lines)){
  12215. +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
  12216. + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
  12217. + if ( alterProvidesLine(*lines,provide) ){
  12218. + return EINVAL;
  12219. + }
  12220. + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
  12221. +/* Let's try to hack a bit here.
  12222. + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
  12223. + in alot of other places. We will remove it before writing down the status database */
  12224. + pkg_false_provides=0;
  12225. + free(provide);
  12226. + }
  12227. +
  12228. + else if(isGenericFieldType((char *)"Depends", *lines))
  12229. + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
  12230. + else if(isGenericFieldType((char *)"Pre-Depends", *lines))
  12231. + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
  12232. + else if(isGenericFieldType((char *)"Recommends", *lines))
  12233. + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
  12234. + else if(isGenericFieldType((char *)"Suggests", *lines))
  12235. + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
  12236. + /* Abhaya: support for conflicts */
  12237. + else if(isGenericFieldType((char *)"Conflicts", *lines))
  12238. + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
  12239. + else if(isGenericFieldType((char *)"Replaces", *lines))
  12240. + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
  12241. + else if(line_is_blank(*lines)) {
  12242. + lines++;
  12243. + break;
  12244. + }
  12245. + else if(**lines == ' '){
  12246. + if(reading_description) {
  12247. + /* we already know it's not blank, so the rest of description */
  12248. + pkg->description = realloc(pkg->description,
  12249. + strlen(pkg->description)
  12250. + + 1 + strlen(*lines) + 1);
  12251. + strcat(pkg->description, "\n");
  12252. + strcat(pkg->description, (*lines));
  12253. + }
  12254. + else if(reading_conffiles)
  12255. + parseConffiles(pkg, *lines);
  12256. + }
  12257. + }
  12258. + *raw = lines;
  12259. +/* If the ipk has not a Provides line, we insert our false line */
  12260. + if ( pkg_false_provides==1)
  12261. + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
  12262. +
  12263. + if (pkg->name) {
  12264. + return 0;
  12265. + } else {
  12266. + return EINVAL;
  12267. + }
  12268. +}
  12269. +
  12270. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
  12271. +{
  12272. + char ** lines;
  12273. +
  12274. + for (lines = *raw; *lines; lines++) {
  12275. + if(isGenericFieldType((char *)"Essential:", *lines)) {
  12276. + char *essential_value;
  12277. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12278. + if (strcmp(essential_value, "yes") == 0) {
  12279. + pkg->essential = 1;
  12280. + }
  12281. + free(essential_value);
  12282. + }
  12283. + }
  12284. + *raw = lines;
  12285. +
  12286. + return 0;
  12287. +}
  12288. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_parse.h busybox-1.17.0/archival/libipkg/pkg_parse.h
  12289. --- busybox-1.17.0.orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
  12290. +++ busybox-1.17.0/archival/libipkg/pkg_parse.h 2010-07-08 12:01:56.343005785 +0200
  12291. @@ -0,0 +1,31 @@
  12292. +/* pkg_parse.h - the itsy package management system
  12293. +
  12294. + Steven M. Ayer
  12295. +
  12296. + Copyright (C) 2002 Compaq Computer Corporation
  12297. +
  12298. + This program is free software; you can redistribute it and/or
  12299. + modify it under the terms of the GNU General Public License as
  12300. + published by the Free Software Foundation; either version 2, or (at
  12301. + your option) any later version.
  12302. +
  12303. + This program is distributed in the hope that it will be useful, but
  12304. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12305. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12306. + General Public License for more details.
  12307. +*/
  12308. +
  12309. +#ifndef PKG_PARSE_H
  12310. +#define PKG_PARSE_H
  12311. +
  12312. +int isGenericFieldType(char * type, char * line);
  12313. +char * parseGenericFieldType(char * type, char * raw);
  12314. +void parseStatus(pkg_t *pkg, char * raw);
  12315. +int parseVersion(pkg_t *pkg, char *raw);
  12316. +char ** parseDependsString(char * raw, int * depends_count);
  12317. +int parseVersion(pkg_t *pkg, char *raw);
  12318. +void parseConffiles(pkg_t * pkg, char * raw);
  12319. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
  12320. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
  12321. +
  12322. +#endif
  12323. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_src.c busybox-1.17.0/archival/libipkg/pkg_src.c
  12324. --- busybox-1.17.0.orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
  12325. +++ busybox-1.17.0/archival/libipkg/pkg_src.c 2010-07-08 12:01:56.343005785 +0200
  12326. @@ -0,0 +1,43 @@
  12327. +/* pkg_src.c - the itsy package management system
  12328. +
  12329. + Carl D. Worth
  12330. +
  12331. + Copyright (C) 2001 University of Southern California
  12332. +
  12333. + This program is free software; you can redistribute it and/or
  12334. + modify it under the terms of the GNU General Public License as
  12335. + published by the Free Software Foundation; either version 2, or (at
  12336. + your option) any later version.
  12337. +
  12338. + This program is distributed in the hope that it will be useful, but
  12339. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12340. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12341. + General Public License for more details.
  12342. +*/
  12343. +
  12344. +#include "ipkg.h"
  12345. +
  12346. +#include "pkg_src.h"
  12347. +#include "str_util.h"
  12348. +
  12349. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
  12350. +{
  12351. + src->gzip = gzip;
  12352. + src->name = str_dup_safe (name);
  12353. + src->value = str_dup_safe (base_url);
  12354. + if (extra_data)
  12355. + src->extra_data = str_dup_safe (extra_data);
  12356. + else
  12357. + src->extra_data = NULL;
  12358. + return 0;
  12359. +}
  12360. +
  12361. +void pkg_src_deinit(pkg_src_t *src)
  12362. +{
  12363. + free (src->name);
  12364. + free (src->value);
  12365. + if (src->extra_data)
  12366. + free (src->extra_data);
  12367. +}
  12368. +
  12369. +
  12370. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_src.h busybox-1.17.0/archival/libipkg/pkg_src.h
  12371. --- busybox-1.17.0.orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
  12372. +++ busybox-1.17.0/archival/libipkg/pkg_src.h 2010-07-08 12:01:56.343005785 +0200
  12373. @@ -0,0 +1,34 @@
  12374. +/* pkg_src.h - the itsy package management system
  12375. +
  12376. + Carl D. Worth
  12377. +
  12378. + Copyright (C) 2001 University of Southern California
  12379. +
  12380. + This program is free software; you can redistribute it and/or
  12381. + modify it under the terms of the GNU General Public License as
  12382. + published by the Free Software Foundation; either version 2, or (at
  12383. + your option) any later version.
  12384. +
  12385. + This program is distributed in the hope that it will be useful, but
  12386. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12387. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12388. + General Public License for more details.
  12389. +*/
  12390. +
  12391. +#ifndef PKG_SRC_H
  12392. +#define PKG_SRC_H
  12393. +
  12394. +#include "nv_pair.h"
  12395. +
  12396. +typedef struct
  12397. +{
  12398. + char *name;
  12399. + char *value;
  12400. + char *extra_data;
  12401. + int gzip;
  12402. +} pkg_src_t;
  12403. +
  12404. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
  12405. +void pkg_src_deinit(pkg_src_t *src);
  12406. +
  12407. +#endif
  12408. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_src_list.c busybox-1.17.0/archival/libipkg/pkg_src_list.c
  12409. --- busybox-1.17.0.orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
  12410. +++ busybox-1.17.0/archival/libipkg/pkg_src_list.c 2010-07-08 12:01:56.359001397 +0200
  12411. @@ -0,0 +1,75 @@
  12412. +/* pkg_src_list.c - the itsy package management system
  12413. +
  12414. + Carl D. Worth
  12415. +
  12416. + Copyright (C) 2001 University of Southern California
  12417. +
  12418. + This program is free software; you can redistribute it and/or
  12419. + modify it under the terms of the GNU General Public License as
  12420. + published by the Free Software Foundation; either version 2, or (at
  12421. + your option) any later version.
  12422. +
  12423. + This program is distributed in the hope that it will be useful, but
  12424. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12425. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12426. + General Public License for more details.
  12427. +*/
  12428. +
  12429. +#include "ipkg.h"
  12430. +
  12431. +#include "pkg_src_list.h"
  12432. +#include "void_list.h"
  12433. +
  12434. +int pkg_src_list_init(pkg_src_list_t *list)
  12435. +{
  12436. + return void_list_init((void_list_t *) list);
  12437. +}
  12438. +
  12439. +void pkg_src_list_deinit(pkg_src_list_t *list)
  12440. +{
  12441. + pkg_src_list_elt_t *iter;
  12442. + pkg_src_t *pkg_src;
  12443. +
  12444. + for (iter = list->head; iter; iter = iter->next) {
  12445. + pkg_src = iter->data;
  12446. + pkg_src_deinit(pkg_src);
  12447. +
  12448. + /* malloced in pkg_src_list_append */
  12449. + free(pkg_src);
  12450. + iter->data = NULL;
  12451. + }
  12452. + void_list_deinit((void_list_t *) list);
  12453. +}
  12454. +
  12455. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
  12456. + const char *name, const char *base_url, const char *extra_data,
  12457. + int gzip)
  12458. +{
  12459. + int err;
  12460. +
  12461. + /* freed in pkg_src_list_deinit */
  12462. + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
  12463. +
  12464. + if (pkg_src == NULL) {
  12465. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12466. + return NULL;
  12467. + }
  12468. + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
  12469. +
  12470. + err = void_list_append((void_list_t *) list, pkg_src);
  12471. + if (err) {
  12472. + return NULL;
  12473. + }
  12474. +
  12475. + return pkg_src;
  12476. +}
  12477. +
  12478. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
  12479. +{
  12480. + return void_list_push((void_list_t *) list, data);
  12481. +}
  12482. +
  12483. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
  12484. +{
  12485. + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
  12486. +}
  12487. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_src_list.h busybox-1.17.0/archival/libipkg/pkg_src_list.h
  12488. --- busybox-1.17.0.orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
  12489. +++ busybox-1.17.0/archival/libipkg/pkg_src_list.h 2010-07-08 12:01:56.359001397 +0200
  12490. @@ -0,0 +1,57 @@
  12491. +/* pkg_src_list.h - the itsy package management system
  12492. +
  12493. + Carl D. Worth
  12494. +
  12495. + Copyright (C) 2001 University of Southern California
  12496. +
  12497. + This program is free software; you can redistribute it and/or
  12498. + modify it under the terms of the GNU General Public License as
  12499. + published by the Free Software Foundation; either version 2, or (at
  12500. + your option) any later version.
  12501. +
  12502. + This program is distributed in the hope that it will be useful, but
  12503. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12504. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12505. + General Public License for more details.
  12506. +*/
  12507. +
  12508. +#ifndef PKG_SRC_LIST_H
  12509. +#define PKG_SRC_LIST_H
  12510. +
  12511. +#include "pkg_src.h"
  12512. +
  12513. +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
  12514. +struct pkg_src_list_elt
  12515. +{
  12516. + pkg_src_list_elt_t *next;
  12517. + pkg_src_t *data;
  12518. +};
  12519. +
  12520. +typedef struct pkg_src_list pkg_src_list_t;
  12521. +struct pkg_src_list
  12522. +{
  12523. + pkg_src_list_elt_t pre_head;
  12524. + pkg_src_list_elt_t *head;
  12525. + pkg_src_list_elt_t *tail;
  12526. +};
  12527. +
  12528. +static inline int pkg_src_list_empty(pkg_src_list_t *list)
  12529. +{
  12530. + if (list->head == NULL)
  12531. + return 1;
  12532. + else
  12533. + return 0;
  12534. +}
  12535. +
  12536. +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
  12537. +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
  12538. +
  12539. +int pkg_src_list_init(pkg_src_list_t *list);
  12540. +void pkg_src_list_deinit(pkg_src_list_t *list);
  12541. +
  12542. +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);
  12543. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
  12544. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
  12545. +
  12546. +#endif
  12547. +
  12548. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_vec.c busybox-1.17.0/archival/libipkg/pkg_vec.c
  12549. --- busybox-1.17.0.orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
  12550. +++ busybox-1.17.0/archival/libipkg/pkg_vec.c 2010-07-08 12:01:56.367001298 +0200
  12551. @@ -0,0 +1,231 @@
  12552. +/* pkg_vec.c - the itsy package management system
  12553. +
  12554. + Steven M. Ayer
  12555. +
  12556. + Copyright (C) 2002 Compaq Computer Corporation
  12557. +
  12558. + This program is free software; you can redistribute it and/or
  12559. + modify it under the terms of the GNU General Public License as
  12560. + published by the Free Software Foundation; either version 2, or (at
  12561. + your option) any later version.
  12562. +
  12563. + This program is distributed in the hope that it will be useful, but
  12564. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12565. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12566. + General Public License for more details.
  12567. +*/
  12568. +
  12569. +#include <stdlib.h>
  12570. +#include <fnmatch.h>
  12571. +#include "libbb.h"
  12572. +#include "xregex.h"
  12573. +#include "ipkg.h"
  12574. +#include "pkg.h"
  12575. +
  12576. +pkg_vec_t * pkg_vec_alloc(void)
  12577. +{
  12578. + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
  12579. + if (!vec) {
  12580. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12581. + return NULL;
  12582. + }
  12583. + vec->pkgs = NULL;
  12584. + vec->len = 0;
  12585. +
  12586. + return vec;
  12587. +}
  12588. +
  12589. +void pkg_vec_free(pkg_vec_t *vec)
  12590. +{
  12591. + free(vec->pkgs);
  12592. + free(vec);
  12593. +}
  12594. +
  12595. +/*
  12596. + * assumption: all names in a vector are identical
  12597. + * assumption: all version strings are trimmed,
  12598. + * so identical versions have identical version strings,
  12599. + * implying identical packages; let's marry these
  12600. + */
  12601. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  12602. +{
  12603. + int i;
  12604. + int found = 0;
  12605. +
  12606. + /* look for a duplicate pkg by name, version, and architecture */
  12607. + for (i = 0; i < vec->len; i++){
  12608. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
  12609. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
  12610. + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
  12611. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12612. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12613. + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
  12614. + found = 1;
  12615. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
  12616. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12617. + break;
  12618. + }
  12619. + }
  12620. +
  12621. + /* we didn't find one, add it */
  12622. + if (!found){
  12623. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
  12624. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12625. +
  12626. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12627. + vec->pkgs[vec->len] = pkg;
  12628. + vec->len++;
  12629. + return pkg;
  12630. + }
  12631. + /* update the one that we have */
  12632. + else {
  12633. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
  12634. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12635. + if (set_status) {
  12636. + /* this is from the status file, so need to merge with existing database */
  12637. + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
  12638. + pkg_merge(vec->pkgs[i], pkg, set_status);
  12639. + /* XXX: CLEANUP: It's not so polite to free something here
  12640. + that was passed in from above. */
  12641. + pkg_deinit(pkg);
  12642. + free(pkg);
  12643. + } else {
  12644. + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
  12645. + /* just overwrite the old one */
  12646. + pkg_deinit(vec->pkgs[i]);
  12647. + free(vec->pkgs[i]);
  12648. + vec->pkgs[i] = pkg;
  12649. + }
  12650. + return vec->pkgs[i];
  12651. + }
  12652. +}
  12653. +
  12654. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
  12655. +{
  12656. + int i;
  12657. + int found = 0;
  12658. +
  12659. + /* look for a duplicate pkg by name, version, and architecture */
  12660. + for (i = 0; i < vec->len; i++)
  12661. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12662. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12663. + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
  12664. + found = 1;
  12665. + break;
  12666. + }
  12667. +
  12668. + /* we didn't find one, add it */
  12669. + if(!found){
  12670. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12671. + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
  12672. + vec->len++;
  12673. + }
  12674. +}
  12675. +
  12676. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
  12677. +{
  12678. + int i;
  12679. + for (i = 0; i < vec->len; i++)
  12680. + if (vec->pkgs[i] == apkg)
  12681. + return 1;
  12682. + return 0;
  12683. +}
  12684. +
  12685. +typedef int (*compare_fcn_t)(const void *, const void *);
  12686. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
  12687. +{
  12688. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12689. +}
  12690. +
  12691. +int pkg_vec_clear_marks(pkg_vec_t *vec)
  12692. +{
  12693. + int npkgs = vec->len;
  12694. + int i;
  12695. + for (i = 0; i < npkgs; i++) {
  12696. + pkg_t *pkg = vec->pkgs[i];
  12697. + pkg->state_flag &= ~SF_MARKED;
  12698. + }
  12699. + return 0;
  12700. +}
  12701. +
  12702. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
  12703. +{
  12704. + int matching_count = 0;
  12705. + pkg_t **pkgs = vec->pkgs;
  12706. + int npkgs = vec->len;
  12707. + int i;
  12708. + for (i = 0; i < npkgs; i++) {
  12709. + pkg_t *pkg = pkgs[i];
  12710. + if (fnmatch(pattern, pkg->name, 0)==0) {
  12711. + pkg->state_flag |= SF_MARKED;
  12712. + matching_count++;
  12713. + }
  12714. + }
  12715. + return matching_count;
  12716. +}
  12717. +
  12718. +
  12719. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
  12720. +{
  12721. + abstract_pkg_vec_t * vec ;
  12722. + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
  12723. + if (!vec) {
  12724. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12725. + return NULL;
  12726. + }
  12727. + vec->pkgs = NULL;
  12728. + vec->len = 0;
  12729. +
  12730. + return vec;
  12731. +}
  12732. +
  12733. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
  12734. +{
  12735. + free(vec->pkgs);
  12736. + free(vec);
  12737. +}
  12738. +
  12739. +/*
  12740. + * assumption: all names in a vector are unique
  12741. + */
  12742. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
  12743. +{
  12744. + int i;
  12745. +
  12746. + /* look for a duplicate pkg by name */
  12747. + for(i = 0; i < vec->len; i++)
  12748. + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12749. + break;
  12750. +
  12751. + /* we didn't find one, add it */
  12752. + if(i == vec->len){
  12753. + vec->pkgs =
  12754. + (abstract_pkg_t **)
  12755. + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
  12756. + vec->pkgs[vec->len] = pkg;
  12757. + vec->len++;
  12758. + }
  12759. +}
  12760. +
  12761. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
  12762. +{
  12763. + if (vec->len > i)
  12764. + return vec->pkgs[i];
  12765. + else
  12766. + return NULL;
  12767. +}
  12768. +
  12769. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
  12770. +{
  12771. + int i;
  12772. + for (i = 0; i < vec->len; i++)
  12773. + if (vec->pkgs[i] == apkg)
  12774. + return 1;
  12775. + return 0;
  12776. +}
  12777. +
  12778. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
  12779. +{
  12780. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12781. +}
  12782. +
  12783. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_vec.h busybox-1.17.0/archival/libipkg/pkg_vec.h
  12784. --- busybox-1.17.0.orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
  12785. +++ busybox-1.17.0/archival/libipkg/pkg_vec.h 2010-07-08 12:01:56.367001298 +0200
  12786. @@ -0,0 +1,62 @@
  12787. +/* pkg_vec.h - the itsy package management system
  12788. +
  12789. + Steven M. Ayer
  12790. +
  12791. + Copyright (C) 2002 Compaq Computer Corporation
  12792. +
  12793. + This program is free software; you can redistribute it and/or
  12794. + modify it under the terms of the GNU General Public License as
  12795. + published by the Free Software Foundation; either version 2, or (at
  12796. + your option) any later version.
  12797. +
  12798. + This program is distributed in the hope that it will be useful, but
  12799. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12800. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12801. + General Public License for more details.
  12802. +*/
  12803. +
  12804. +#ifndef PKG_VEC_H
  12805. +#define PKG_VEC_H
  12806. +
  12807. +typedef struct pkg pkg_t;
  12808. +typedef struct abstract_pkg abstract_pkg_t;
  12809. +
  12810. +struct pkg_vec
  12811. +{
  12812. + pkg_t **pkgs;
  12813. + int len;
  12814. +};
  12815. +typedef struct pkg_vec pkg_vec_t;
  12816. +
  12817. +struct abstract_pkg_vec
  12818. +{
  12819. + abstract_pkg_t **pkgs;
  12820. + int len;
  12821. +};
  12822. +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
  12823. +
  12824. +
  12825. +pkg_vec_t * pkg_vec_alloc(void);
  12826. +void pkg_vec_free(pkg_vec_t *vec);
  12827. +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
  12828. +
  12829. +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
  12830. +/* pkg_vec_insert_merge: might munge pkg.
  12831. +* returns the pkg that is in the pkg graph */
  12832. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
  12833. +/* this one never munges pkg */
  12834. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
  12835. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
  12836. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
  12837. +
  12838. +int pkg_vec_clear_marks(pkg_vec_t *vec);
  12839. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
  12840. +
  12841. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
  12842. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
  12843. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
  12844. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
  12845. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
  12846. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
  12847. +#endif
  12848. +
  12849. diff -Nur busybox-1.17.0.orig/archival/libipkg/sprintf_alloc.h busybox-1.17.0/archival/libipkg/sprintf_alloc.h
  12850. --- busybox-1.17.0.orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
  12851. +++ busybox-1.17.0/archival/libipkg/sprintf_alloc.h 2010-07-08 12:01:56.375003713 +0200
  12852. @@ -0,0 +1,25 @@
  12853. +/* sprintf_alloca.c -- like sprintf with memory allocation
  12854. +
  12855. + Carl D. Worth
  12856. +
  12857. + Copyright (C) 2001 University of Southern California
  12858. +
  12859. + This program is free software; you can redistribute it and/or modify
  12860. + it under the terms of the GNU General Public License as published by
  12861. + the Free Software Foundation; either version 2, or (at your option)
  12862. + any later version.
  12863. +
  12864. + This program is distributed in the hope that it will be useful,
  12865. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  12866. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12867. + GNU General Public License for more details.
  12868. +*/
  12869. +
  12870. +#ifndef SPRINTF_ALLOC_H
  12871. +#define SPRINTF_ALLOC_H
  12872. +
  12873. +#include "libbb.h"
  12874. +
  12875. +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
  12876. +
  12877. +#endif
  12878. diff -Nur busybox-1.17.0.orig/archival/libipkg/str_list.c busybox-1.17.0/archival/libipkg/str_list.c
  12879. --- busybox-1.17.0.orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
  12880. +++ busybox-1.17.0/archival/libipkg/str_list.c 2010-07-08 12:01:56.375003713 +0200
  12881. @@ -0,0 +1,76 @@
  12882. +/* str_list.c - the itsy package management system
  12883. +
  12884. + Carl D. Worth
  12885. +
  12886. + Copyright (C) 2001 University of Southern California
  12887. +
  12888. + This program is free software; you can redistribute it and/or
  12889. + modify it under the terms of the GNU General Public License as
  12890. + published by the Free Software Foundation; either version 2, or (at
  12891. + your option) any later version.
  12892. +
  12893. + This program is distributed in the hope that it will be useful, but
  12894. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12895. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12896. + General Public License for more details.
  12897. +*/
  12898. +
  12899. +#include "ipkg.h"
  12900. +
  12901. +#include "str_list.h"
  12902. +
  12903. +int str_list_elt_init(str_list_elt_t *elt, char *data)
  12904. +{
  12905. + return void_list_elt_init((void_list_elt_t *) elt, data);
  12906. +}
  12907. +
  12908. +void str_list_elt_deinit(str_list_elt_t *elt)
  12909. +{
  12910. + void_list_elt_deinit((void_list_elt_t *) elt);
  12911. +}
  12912. +
  12913. +str_list_t *str_list_alloc(void)
  12914. +{
  12915. + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
  12916. + if (list)
  12917. + str_list_init(list);
  12918. + return list;
  12919. +}
  12920. +
  12921. +int str_list_init(str_list_t *list)
  12922. +{
  12923. + return void_list_init((void_list_t *) list);
  12924. +}
  12925. +
  12926. +void str_list_deinit(str_list_t *list)
  12927. +{
  12928. + void_list_deinit((void_list_t *) list);
  12929. +}
  12930. +
  12931. +int str_list_append(str_list_t *list, char *data)
  12932. +{
  12933. + return void_list_append((void_list_t *) list, data);
  12934. +}
  12935. +
  12936. +int str_list_push(str_list_t *list, char *data)
  12937. +{
  12938. + return void_list_push((void_list_t *) list, data);
  12939. +}
  12940. +
  12941. +str_list_elt_t *str_list_pop(str_list_t *list)
  12942. +{
  12943. + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
  12944. +}
  12945. +
  12946. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
  12947. +{
  12948. + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
  12949. + (void_list_elt_t **) iter);
  12950. +}
  12951. +
  12952. +char *str_list_remove_elt(str_list_t *list, const char *target_str)
  12953. +{
  12954. + return (char *)void_list_remove_elt((void_list_t *) list,
  12955. + (void *)target_str,
  12956. + (void_list_cmp_t)strcmp);
  12957. +}
  12958. diff -Nur busybox-1.17.0.orig/archival/libipkg/str_list.h busybox-1.17.0/archival/libipkg/str_list.h
  12959. --- busybox-1.17.0.orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
  12960. +++ busybox-1.17.0/archival/libipkg/str_list.h 2010-07-08 12:01:56.375003713 +0200
  12961. @@ -0,0 +1,51 @@
  12962. +/* str_list.h - the itsy package management system
  12963. +
  12964. + Carl D. Worth
  12965. +
  12966. + Copyright (C) 2001 University of Southern California
  12967. +
  12968. + This program is free software; you can redistribute it and/or
  12969. + modify it under the terms of the GNU General Public License as
  12970. + published by the Free Software Foundation; either version 2, or (at
  12971. + your option) any later version.
  12972. +
  12973. + This program is distributed in the hope that it will be useful, but
  12974. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12975. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12976. + General Public License for more details.
  12977. +*/
  12978. +
  12979. +#ifndef STR_LIST_H
  12980. +#define STR_LIST_H
  12981. +
  12982. +#include "void_list.h"
  12983. +
  12984. +typedef struct str_list_elt str_list_elt_t;
  12985. +struct str_list_elt
  12986. +{
  12987. + str_list_elt_t *next;
  12988. + char *data;
  12989. +};
  12990. +
  12991. +typedef struct xstr_list str_list_t;
  12992. +struct xstr_list
  12993. +{
  12994. + str_list_elt_t pre_head;
  12995. + str_list_elt_t *head;
  12996. + str_list_elt_t *tail;
  12997. +};
  12998. +
  12999. +int str_list_elt_init(str_list_elt_t *elt, char *data);
  13000. +void str_list_elt_deinit(str_list_elt_t *elt);
  13001. +
  13002. +str_list_t *str_list_alloc(void);
  13003. +int str_list_init(str_list_t *list);
  13004. +void str_list_deinit(str_list_t *list);
  13005. +
  13006. +int str_list_append(str_list_t *list, char *data);
  13007. +int str_list_push(str_list_t *list, char *data);
  13008. +str_list_elt_t *str_list_pop(str_list_t *list);
  13009. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
  13010. +char *str_list_remove_elt(str_list_t *list, const char *target_str);
  13011. +
  13012. +#endif
  13013. diff -Nur busybox-1.17.0.orig/archival/libipkg/str_util.c busybox-1.17.0/archival/libipkg/str_util.c
  13014. --- busybox-1.17.0.orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
  13015. +++ busybox-1.17.0/archival/libipkg/str_util.c 2010-07-08 12:01:56.375003713 +0200
  13016. @@ -0,0 +1,69 @@
  13017. +/* str_utils.c - the itsy package management system
  13018. +
  13019. + Carl D. Worth
  13020. +
  13021. + Copyright (C) 2001 University of Southern California
  13022. +
  13023. + This program is free software; you can redistribute it and/or
  13024. + modify it under the terms of the GNU General Public License as
  13025. + published by the Free Software Foundation; either version 2, or (at
  13026. + your option) any later version.
  13027. +
  13028. + This program is distributed in the hope that it will be useful, but
  13029. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13030. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13031. + General Public License for more details.
  13032. +*/
  13033. +
  13034. +#include "ipkg.h"
  13035. +
  13036. +int str_starts_with(const char *str, const char *prefix);
  13037. +int str_ends_with(const char *str, const char *suffix);
  13038. +int str_chomp(char *str);
  13039. +int str_toupper(char *str);
  13040. +char *str_dup_safe(const char *str);
  13041. +
  13042. +int str_starts_with(const char *str, const char *prefix)
  13043. +{
  13044. + return (strncmp(str, prefix, strlen(prefix)) == 0);
  13045. +}
  13046. +
  13047. +int str_ends_with(const char *str, const char *suffix)
  13048. +{
  13049. + int suffix_len;
  13050. + int str_len;
  13051. +
  13052. + str_len = strlen(str);
  13053. + suffix_len = strlen(suffix);
  13054. +
  13055. + if (str_len < suffix_len) {
  13056. + return 0;
  13057. + }
  13058. +
  13059. + return (strcmp(str + str_len - suffix_len, suffix) == 0);
  13060. +}
  13061. +
  13062. +int str_chomp(char *str)
  13063. +{
  13064. + if (str[strlen(str) - 1] == '\n') {
  13065. + str[strlen(str) - 1] = '\0';
  13066. + return 1;
  13067. + }
  13068. + return 0;
  13069. +}
  13070. +
  13071. +int str_toupper(char *str)
  13072. +{
  13073. + while (*str) {
  13074. + *str = toupper(*str);
  13075. + str++;
  13076. + }
  13077. +
  13078. + return 0;
  13079. +}
  13080. +
  13081. +char *str_dup_safe(const char *str)
  13082. +{
  13083. + return str ? strdup(str) : NULL;
  13084. +}
  13085. +
  13086. diff -Nur busybox-1.17.0.orig/archival/libipkg/str_util.h busybox-1.17.0/archival/libipkg/str_util.h
  13087. --- busybox-1.17.0.orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
  13088. +++ busybox-1.17.0/archival/libipkg/str_util.h 2010-07-08 12:01:56.391000442 +0200
  13089. @@ -0,0 +1,27 @@
  13090. +/* str_utils.h - the itsy package management system
  13091. +
  13092. + Carl D. Worth
  13093. +
  13094. + Copyright (C) 2001 University of Southern California
  13095. +
  13096. + This program is free software; you can redistribute it and/or
  13097. + modify it under the terms of the GNU General Public License as
  13098. + published by the Free Software Foundation; either version 2, or (at
  13099. + your option) any later version.
  13100. +
  13101. + This program is distributed in the hope that it will be useful, but
  13102. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13103. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13104. + General Public License for more details.
  13105. +*/
  13106. +
  13107. +#ifndef STR_UTILS_H
  13108. +#define STR_UTILS_H
  13109. +
  13110. +int str_starts_with(const char *str, const char *prefix);
  13111. +int str_ends_with(const char *str, const char *suffix);
  13112. +int str_chomp(char *str);
  13113. +int str_toupper(char *str);
  13114. +char *str_dup_safe(const char *str);
  13115. +
  13116. +#endif
  13117. diff -Nur busybox-1.17.0.orig/archival/libipkg/user.c busybox-1.17.0/archival/libipkg/user.c
  13118. --- busybox-1.17.0.orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
  13119. +++ busybox-1.17.0/archival/libipkg/user.c 2010-07-08 12:01:56.391000442 +0200
  13120. @@ -0,0 +1,49 @@
  13121. +/* user.c - the itsy package management system
  13122. +
  13123. + Jamey Hicks
  13124. +
  13125. + Copyright (C) 2002 Hewlett Packard Company
  13126. + Copyright (C) 2001 University of Southern California
  13127. +
  13128. + This program is free software; you can redistribute it and/or
  13129. + modify it under the terms of the GNU General Public License as
  13130. + published by the Free Software Foundation; either version 2, or (at
  13131. + your option) any later version.
  13132. +
  13133. + This program is distributed in the hope that it will be useful, but
  13134. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13135. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13136. + General Public License for more details.
  13137. +*/
  13138. +
  13139. +#include <stdio.h>
  13140. +#include <stdarg.h>
  13141. +#include "libbb.h"
  13142. +#include "file_util.h"
  13143. +#include "str_util.h"
  13144. +#include "libipkg.h"
  13145. +
  13146. +char *get_user_response(const char *format, ...);
  13147. +static char *question = NULL;
  13148. +static int question_len = 255;
  13149. +
  13150. +char *get_user_response(const char *format, ...)
  13151. +{
  13152. + int len = question_len;
  13153. + va_list ap;
  13154. + char *response;
  13155. + va_start(ap, format);
  13156. +
  13157. + do {
  13158. + if (question == NULL || len > question_len) {
  13159. + question = realloc(question, len + 1);
  13160. + question_len = len;
  13161. + }
  13162. + len = vsnprintf(question,question_len,format,ap);
  13163. + } while (len > question_len);
  13164. + response = strdup(ipkg_cb_response(question));
  13165. + str_chomp(response);
  13166. + str_tolower(response);
  13167. +
  13168. + return response;
  13169. +}
  13170. diff -Nur busybox-1.17.0.orig/archival/libipkg/user.h busybox-1.17.0/archival/libipkg/user.h
  13171. --- busybox-1.17.0.orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
  13172. +++ busybox-1.17.0/archival/libipkg/user.h 2010-07-08 12:01:56.391000442 +0200
  13173. @@ -0,0 +1,23 @@
  13174. +/* user.c - the itsy package management system
  13175. +
  13176. + Jamey Hicks
  13177. +
  13178. + Copyright (C) 2002 Hewlett Packard Company
  13179. + Copyright (C) 2001 University of Southern California
  13180. +
  13181. + This program is free software; you can redistribute it and/or
  13182. + modify it under the terms of the GNU General Public License as
  13183. + published by the Free Software Foundation; either version 2, or (at
  13184. + your option) any later version.
  13185. +
  13186. + This program is distributed in the hope that it will be useful, but
  13187. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13188. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13189. + General Public License for more details.
  13190. +*/
  13191. +
  13192. +#include <stdio.h>
  13193. +#include <stdarg.h>
  13194. +
  13195. +char *get_user_response(const char *format, ...);
  13196. +
  13197. diff -Nur busybox-1.17.0.orig/archival/libipkg/void_list.c busybox-1.17.0/archival/libipkg/void_list.c
  13198. --- busybox-1.17.0.orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
  13199. +++ busybox-1.17.0/archival/libipkg/void_list.c 2010-07-08 12:01:56.407001361 +0200
  13200. @@ -0,0 +1,194 @@
  13201. +/* void_list.c - the itsy package management system
  13202. +
  13203. + Carl D. Worth
  13204. +
  13205. + Copyright (C) 2001 University of Southern California
  13206. +
  13207. + This program is free software; you can redistribute it and/or
  13208. + modify it under the terms of the GNU General Public License as
  13209. + published by the Free Software Foundation; either version 2, or (at
  13210. + your option) any later version.
  13211. +
  13212. + This program is distributed in the hope that it will be useful, but
  13213. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13214. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13215. + General Public License for more details.
  13216. +*/
  13217. +
  13218. +#include "ipkg.h"
  13219. +#include <errno.h>
  13220. +
  13221. +#include "void_list.h"
  13222. +
  13223. +int void_list_elt_init(void_list_elt_t *elt, void *data)
  13224. +{
  13225. + elt->next = NULL;
  13226. + elt->data = data;
  13227. +
  13228. + return 0;
  13229. +}
  13230. +
  13231. +void void_list_elt_deinit(void_list_elt_t *elt)
  13232. +{
  13233. + void_list_elt_init(elt, NULL);
  13234. +}
  13235. +
  13236. +int void_list_init(void_list_t *list)
  13237. +{
  13238. + void_list_elt_init(&list->pre_head, NULL);
  13239. + list->head = NULL;
  13240. + list->pre_head.next = list->head;
  13241. + list->tail = NULL;
  13242. +
  13243. + return 0;
  13244. +}
  13245. +
  13246. +void void_list_deinit(void_list_t *list)
  13247. +{
  13248. + void_list_elt_t *elt;
  13249. +
  13250. + while (list->head) {
  13251. + elt = void_list_pop(list);
  13252. + void_list_elt_deinit(elt);
  13253. + /* malloced in void_list_append */
  13254. + free(elt);
  13255. + }
  13256. +}
  13257. +
  13258. +int void_list_append(void_list_t *list, void *data)
  13259. +{
  13260. + void_list_elt_t *elt;
  13261. +
  13262. + /* freed in void_list_deinit */
  13263. + elt = malloc(sizeof(void_list_elt_t));
  13264. + if (elt == NULL) {
  13265. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13266. + return ENOMEM;
  13267. + }
  13268. +
  13269. + void_list_elt_init(elt, data);
  13270. +
  13271. + if (list->tail) {
  13272. + list->tail->next = elt;
  13273. + list->tail = elt;
  13274. + } else {
  13275. + list->head = elt;
  13276. + list->pre_head.next = list->head;
  13277. + list->tail = elt;
  13278. + }
  13279. +
  13280. + return 0;
  13281. +}
  13282. +
  13283. +int void_list_push(void_list_t *list, void *data)
  13284. +{
  13285. + void_list_elt_t *elt;
  13286. +
  13287. + elt = malloc(sizeof(void_list_elt_t));
  13288. + if (elt == NULL) {
  13289. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13290. + return ENOMEM;
  13291. + }
  13292. +
  13293. + void_list_elt_init(elt, data);
  13294. +
  13295. + elt->next = list->head;
  13296. + list->head->next = elt;
  13297. + if (list->tail == NULL) {
  13298. + list->tail = list->head;
  13299. + }
  13300. +
  13301. + return 0;
  13302. +}
  13303. +
  13304. +void_list_elt_t *void_list_pop(void_list_t *list)
  13305. +{
  13306. + void_list_elt_t *elt;
  13307. +
  13308. + elt = list->head;
  13309. +
  13310. + if (list->head) {
  13311. + list->head = list->head->next;
  13312. + list->pre_head.next = list->head;
  13313. + if (list->head == NULL) {
  13314. + list->tail = NULL;
  13315. + }
  13316. + }
  13317. +
  13318. + return elt;
  13319. +}
  13320. +
  13321. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
  13322. +{
  13323. + void_list_elt_t *prior;
  13324. + void_list_elt_t *old_elt;
  13325. + void *old_data;
  13326. +
  13327. + old_elt = *iter;
  13328. + old_data = old_elt->data;
  13329. +
  13330. + if (old_elt == list->head) {
  13331. + prior = &list->pre_head;
  13332. + void_list_pop(list);
  13333. + } else {
  13334. + for (prior = list->head; prior; prior = prior->next) {
  13335. + if (prior->next == old_elt) {
  13336. + break;
  13337. + }
  13338. + }
  13339. + if (prior == NULL || prior->next != old_elt) {
  13340. + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
  13341. + return NULL;
  13342. + }
  13343. + prior->next = old_elt->next;
  13344. +
  13345. + if (old_elt == list->tail) {
  13346. + list->tail = prior;
  13347. + }
  13348. + }
  13349. +
  13350. + void_list_elt_deinit(old_elt);
  13351. + *iter = prior;
  13352. +
  13353. + return old_data;
  13354. +}
  13355. +
  13356. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13357. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
  13358. +{
  13359. + void_list_elt_t *prior;
  13360. + void_list_elt_t *old_elt = NULL;
  13361. + void *old_data = NULL;
  13362. +
  13363. + /* first element */
  13364. + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
  13365. + old_elt = list->head;
  13366. + old_data = list->head->data;
  13367. + void_list_pop(list);
  13368. + } else {
  13369. + int found = 0;
  13370. + for (prior = list->head; prior && prior->next; prior = prior->next) {
  13371. + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
  13372. + old_elt = prior->next;
  13373. + old_data = old_elt->data;
  13374. + found = 1;
  13375. + break;
  13376. + }
  13377. + }
  13378. + if (!found) {
  13379. + return NULL;
  13380. + }
  13381. + prior->next = old_elt->next;
  13382. +
  13383. + if (old_elt == list->tail) {
  13384. + list->tail = prior;
  13385. + }
  13386. + }
  13387. + if (old_elt)
  13388. + void_list_elt_deinit(old_elt);
  13389. +
  13390. + if (old_data)
  13391. + return old_data;
  13392. + else
  13393. + return NULL;
  13394. +}
  13395. diff -Nur busybox-1.17.0.orig/archival/libipkg/void_list.h busybox-1.17.0/archival/libipkg/void_list.h
  13396. --- busybox-1.17.0.orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
  13397. +++ busybox-1.17.0/archival/libipkg/void_list.h 2010-07-08 12:01:56.407001361 +0200
  13398. @@ -0,0 +1,59 @@
  13399. +/* void_list.h - the itsy package management system
  13400. +
  13401. + Carl D. Worth
  13402. +
  13403. + Copyright (C) 2001 University of Southern California
  13404. +
  13405. + This program is free software; you can redistribute it and/or
  13406. + modify it under the terms of the GNU General Public License as
  13407. + published by the Free Software Foundation; either version 2, or (at
  13408. + your option) any later version.
  13409. +
  13410. + This program is distributed in the hope that it will be useful, but
  13411. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13412. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13413. + General Public License for more details.
  13414. +*/
  13415. +
  13416. +#ifndef VOID_LIST_H
  13417. +#define VOID_LIST_H
  13418. +
  13419. +typedef struct void_list_elt void_list_elt_t;
  13420. +struct void_list_elt
  13421. +{
  13422. + void_list_elt_t *next;
  13423. + void *data;
  13424. +};
  13425. +
  13426. +typedef struct void_list void_list_t;
  13427. +struct void_list
  13428. +{
  13429. + void_list_elt_t pre_head;
  13430. + void_list_elt_t *head;
  13431. + void_list_elt_t *tail;
  13432. +};
  13433. +
  13434. +static inline int void_list_empty(void_list_t *list)
  13435. +{
  13436. + if (list->head == NULL)
  13437. + return 1;
  13438. + else
  13439. + return 0;
  13440. +}
  13441. +
  13442. +int void_list_elt_init(void_list_elt_t *elt, void *data);
  13443. +void void_list_elt_deinit(void_list_elt_t *elt);
  13444. +
  13445. +int void_list_init(void_list_t *list);
  13446. +void void_list_deinit(void_list_t *list);
  13447. +
  13448. +int void_list_append(void_list_t *list, void *data);
  13449. +int void_list_push(void_list_t *list, void *data);
  13450. +void_list_elt_t *void_list_pop(void_list_t *list);
  13451. +
  13452. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
  13453. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13454. +typedef int (*void_list_cmp_t)(const void *, const void *);
  13455. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
  13456. +
  13457. +#endif
  13458. diff -Nur busybox-1.17.0.orig/archival/libipkg/xsystem.c busybox-1.17.0/archival/libipkg/xsystem.c
  13459. --- busybox-1.17.0.orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
  13460. +++ busybox-1.17.0/archival/libipkg/xsystem.c 2010-07-08 12:01:56.407001361 +0200
  13461. @@ -0,0 +1,64 @@
  13462. +/* xsystem.c - system(3) with error messages
  13463. +
  13464. + Carl D. Worth
  13465. +
  13466. + Copyright (C) 2001 University of Southern California
  13467. +
  13468. + This program is free software; you can redistribute it and/or
  13469. + modify it under the terms of the GNU General Public License as
  13470. + published by the Free Software Foundation; either version 2, or (at
  13471. + your option) any later version.
  13472. +
  13473. + This program is distributed in the hope that it will be useful, but
  13474. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13475. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13476. + General Public License for more details.
  13477. +*/
  13478. +
  13479. +#include "ipkg.h"
  13480. +#include <sys/wait.h>
  13481. +
  13482. +#include "xsystem.h"
  13483. +
  13484. +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
  13485. + really need the /bin/sh invocation which takes resources and
  13486. + introduces security problems. I should switch all of this to a sort
  13487. + of execl() or execv() interface/implementation.
  13488. +*/
  13489. +
  13490. +/* Like system(3), but with error messages printed if the fork fails
  13491. + or if the child process dies due to an uncaught signal. Also, the
  13492. + return value is a bit simpler:
  13493. +
  13494. + -1 if there was any problem
  13495. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13496. + as defined in <sys/wait.h>.
  13497. +*/
  13498. +int xsystem(const char *cmd)
  13499. +{
  13500. + int err;
  13501. +
  13502. + err = system(cmd);
  13503. +
  13504. + if (err == -1) {
  13505. + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
  13506. + __FUNCTION__, cmd);
  13507. + return -1;
  13508. + }
  13509. +
  13510. + if (WIFSIGNALED(err)) {
  13511. + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
  13512. + __FUNCTION__, WTERMSIG(err), cmd);
  13513. + return -1;
  13514. + }
  13515. +
  13516. + if (WIFEXITED(err)) {
  13517. + /* Normal child exit */
  13518. + return WEXITSTATUS(err);
  13519. + }
  13520. +
  13521. + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
  13522. + __FUNCTION__, err);
  13523. + return -1;
  13524. +}
  13525. +
  13526. diff -Nur busybox-1.17.0.orig/archival/libipkg/xsystem.h busybox-1.17.0/archival/libipkg/xsystem.h
  13527. --- busybox-1.17.0.orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
  13528. +++ busybox-1.17.0/archival/libipkg/xsystem.h 2010-07-08 12:01:56.407001361 +0200
  13529. @@ -0,0 +1,34 @@
  13530. +/* xsystem.h - system(3) with error messages
  13531. +
  13532. + Carl D. Worth
  13533. +
  13534. + Copyright (C) 2001 University of Southern California
  13535. +
  13536. + This program is free software; you can redistribute it and/or
  13537. + modify it under the terms of the GNU General Public License as
  13538. + published by the Free Software Foundation; either version 2, or (at
  13539. + your option) any later version.
  13540. +
  13541. + This program is distributed in the hope that it will be useful, but
  13542. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13543. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13544. + General Public License for more details.
  13545. +*/
  13546. +
  13547. +#ifndef XSYSTEM_H
  13548. +#define XSYSTEM_H
  13549. +
  13550. +#include <stdlib.h>
  13551. +
  13552. +/* Like system(3), but with error messages printed if the fork fails
  13553. + or if the child process dies due to an uncaught signal. Also, the
  13554. + return value is a bit simpler:
  13555. +
  13556. + -1 if there was any problem
  13557. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13558. + as defined in <sys/wait.h>.
  13559. +*/
  13560. +int xsystem(const char *cmd);
  13561. +
  13562. +#endif
  13563. +
  13564. diff -Nur busybox-1.17.0.orig/archival/libunarchive/Kbuild.src busybox-1.17.0/archival/libunarchive/Kbuild.src
  13565. --- busybox-1.17.0.orig/archival/libunarchive/Kbuild.src 2010-07-06 02:15:46.000000000 +0200
  13566. +++ busybox-1.17.0/archival/libunarchive/Kbuild.src 2010-07-08 12:03:29.499017277 +0200
  13567. @@ -43,6 +43,7 @@
  13568. lib-$(CONFIG_DPKG) += $(DPKG_FILES)
  13569. lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
  13570. lib-$(CONFIG_GUNZIP) += decompress_unzip.o
  13571. +lib-$(CONFIG_IPKG) += open_transformer.o get_header_tar.o get_header_tar_gz.o
  13572. lib-$(CONFIG_RPM2CPIO) += decompress_unzip.o get_header_cpio.o
  13573. lib-$(CONFIG_RPM) += open_transformer.o decompress_unzip.o get_header_cpio.o
  13574. lib-$(CONFIG_TAR) += get_header_tar.o
  13575. diff -Nur busybox-1.17.0.orig/include/applets.src.h busybox-1.17.0/include/applets.src.h
  13576. --- busybox-1.17.0.orig/include/applets.src.h 2010-06-24 04:40:43.000000000 +0200
  13577. +++ busybox-1.17.0/include/applets.src.h 2010-07-08 12:04:57.087012849 +0200
  13578. @@ -209,6 +209,7 @@
  13579. IF_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_DROP))
  13580. IF_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
  13581. IF_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
  13582. +IF_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_DROP))
  13583. IF_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_DROP))
  13584. IF_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_DROP))
  13585. IF_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_DROP))
  13586. diff -Nur busybox-1.17.0.orig/include/unarchive.h busybox-1.17.0/include/unarchive.h
  13587. --- busybox-1.17.0.orig/include/unarchive.h 2010-07-03 13:18:17.000000000 +0200
  13588. +++ busybox-1.17.0/include/unarchive.h 2010-07-08 12:01:56.422999486 +0200
  13589. @@ -76,7 +76,7 @@
  13590. off_t offset;
  13591. /* Archiver specific. Can make it a union if it ever gets big */
  13592. -#if ENABLE_TAR || ENABLE_DPKG || ENABLE_DPKG_DEB
  13593. +#if ENABLE_TAR || ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13594. smallint tar__end;
  13595. # if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
  13596. char* tar__longname;
  13597. @@ -95,7 +95,7 @@
  13598. struct hardlinks_t *cpio__hardlinks_to_create;
  13599. struct hardlinks_t *cpio__created_hardlinks;
  13600. #endif
  13601. -#if ENABLE_DPKG || ENABLE_DPKG_DEB
  13602. +#if ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13603. /* Temporary storage */
  13604. char *dpkg__buffer;
  13605. /* How to process any sub archive, e.g. get_header_tar_gz */
  13606. diff -Nur busybox-1.17.0.orig/include/usage.src.h busybox-1.17.0/include/usage.src.h
  13607. --- busybox-1.17.0.orig/include/usage.src.h 2010-07-03 13:18:17.000000000 +0200
  13608. +++ busybox-1.17.0/include/usage.src.h 2010-07-08 12:07:04.099000968 +0200
  13609. @@ -1556,6 +1556,82 @@
  13610. "$ ls -la /tmp/busybox*\n" \
  13611. "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
  13612. +#define ipkg_trivial_usage \
  13613. + "[options]... sub-command [arguments]..."
  13614. +#define ipkg_full_usage \
  13615. + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
  13616. + "\n" \
  13617. + "Sub-commands:\n" \
  13618. + "\nPackage Manipulation:\n" \
  13619. + "\tupdate Update list of available packages\n" \
  13620. + "\tupgrade Upgrade all installed packages to latest version\n" \
  13621. + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
  13622. + "\tinstall <file.ipk> Install package <file.ipk>\n" \
  13623. + "\tconfigure [<pkg>] Configure unpacked packages\n" \
  13624. + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
  13625. + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
  13626. + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
  13627. + "\n" \
  13628. + "Informational Commands:\n" \
  13629. + "\tlist List available packages and descriptions\n" \
  13630. + "\tlist_installed List all and only the installed packages and description \n" \
  13631. + "\tfiles <pkg> List all files belonging to <pkg>\n" \
  13632. + "\tsearch <file|regexp> Search for a package providing <file>\n" \
  13633. + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
  13634. + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
  13635. + "\tdownload <pkg> Download <pkg> to current directory.\n" \
  13636. + "\tcompare_versions <v1> <op> <v2>\n" \
  13637. + "\t compare versions using <= < > >= = << >>\n" \
  13638. + "\tprint_architecture prints the architecture.\n" \
  13639. + "\tprint_installation_architecture\n" \
  13640. + "\twhatdepends [-A] [pkgname|pat]+\n" \
  13641. + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
  13642. + "\twhatprovides [-A] [pkgname|pat]+\n" \
  13643. + "\twhatconflicts [-A] [pkgname|pat]+\n" \
  13644. + "\twhatreplaces [-A] [pkgname|pat]+\n" \
  13645. + "\t prints the installation architecture.\n" \
  13646. + "\n" \
  13647. + "\nOptions:\n" \
  13648. + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
  13649. + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
  13650. + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
  13651. + "\t 0 errors only\n" \
  13652. + "\t 1 normal messages (default)\n" \
  13653. + "\t 2 informative messages\n" \
  13654. + "\t 3 debug output\n" \
  13655. + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
  13656. + "\t-conf <conf_file> Default configuration file location\n" \
  13657. + " is /etc/ipkg.conf\n" \
  13658. + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
  13659. + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
  13660. + " <dest_name> should be a defined dest name from\n" \
  13661. + " the configuration file, (but can also be a\n" \
  13662. + " directory name in a pinch).\n" \
  13663. + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
  13664. + "\t-offline <offline_root> offline installation of packages.\n" \
  13665. + "\t-verbose_wget more wget messages\n" \
  13666. + "\n" \
  13667. + "Force Options (use when ipkg is too smart for its own good):\n" \
  13668. + "\t-force-depends Make dependency checks warnings instead of errors\n" \
  13669. + "\t Install/remove package in spite of failed dependences\n" \
  13670. + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
  13671. + " (no prompts). Note that this will not prevent\n" \
  13672. + " package installation scripts from prompting.\n" \
  13673. + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
  13674. + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
  13675. + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
  13676. + "\t-force_space Install even if there does not seem to be enough space.\n" \
  13677. + "\t-noaction No action -- test only\n" \
  13678. + "\t-nodeps Do not follow dependences\n" \
  13679. + "\t-force-removal-of-dependent-packages\n" \
  13680. + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
  13681. + "\t-test No action -- test only\n" \
  13682. + "\t-t Specify tmp-dir.\n" \
  13683. + "\t--tmp-dir Specify tmp-dir.\n" \
  13684. + "\n" \
  13685. + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
  13686. + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
  13687. +
  13688. #define halt_trivial_usage \
  13689. "[-d DELAY] [-n] [-f]" IF_FEATURE_WTMP(" [-w]")
  13690. #define halt_full_usage "\n\n" \
  13691. diff -Nur busybox-1.17.0.orig/Makefile busybox-1.17.0/Makefile
  13692. --- busybox-1.17.0.orig/Makefile 2010-07-06 04:16:45.000000000 +0200
  13693. +++ busybox-1.17.0/Makefile 2010-07-08 12:01:56.455000212 +0200
  13694. @@ -459,6 +459,7 @@
  13695. libs-y := \
  13696. archival/ \
  13697. + archival/libipkg/ \
  13698. archival/libunarchive/ \
  13699. console-tools/ \
  13700. coreutils/ \