001-ipkg.patch 424 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762
  1. diff -Nur busybox-1.22.1.orig/Makefile busybox-1.22.1/Makefile
  2. --- busybox-1.22.1.orig/Makefile 2014-01-20 03:39:28.000000000 +0100
  3. +++ busybox-1.22.1/Makefile 2014-05-23 21:12:06.000000000 +0200
  4. @@ -466,6 +466,7 @@
  5. libs-y := \
  6. archival/ \
  7. archival/libarchive/ \
  8. + archival/libipkg/ \
  9. console-tools/ \
  10. coreutils/ \
  11. coreutils/libcoreutils/ \
  12. diff -Nur busybox-1.22.1.orig/archival/ipkg.c busybox-1.22.1/archival/ipkg.c
  13. --- busybox-1.22.1.orig/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
  14. +++ busybox-1.22.1/archival/ipkg.c 2014-05-23 21:19:24.000000000 +0200
  15. @@ -0,0 +1,39 @@
  16. +/* ipkg.c - the itsy package management system
  17. +
  18. + Florina Boor
  19. +
  20. + Copyright (C) 2003 kernel concepts
  21. +
  22. + This program is free software; you can redistribute it and/or
  23. + modify it under the terms of the GNU General Public License as
  24. + published by the Free Software Foundation; either version 2, or (at
  25. + your option) any later version.
  26. +
  27. + This program is distributed in the hope that it will be useful, but
  28. + WITHOUT ANY WARRANTY; without even the implied warranty of
  29. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  30. + General Public License for more details.
  31. +
  32. + ipkg command line frontend using libipkg
  33. +
  34. +*/
  35. +
  36. +//config:config IPKG
  37. +//config: bool "ipkg"
  38. +//config: default n
  39. +//config: help
  40. +//config: ipkg is a tool to install, build, remove and manage
  41. +//config: packages.
  42. +//config:
  43. +
  44. +//applet:IF_IPKG(APPLET(ipkg, BB_DIR_USR_BIN, BB_SUID_DROP))
  45. +//kbuild:lib-$(CONFIG_IPKG) += ipkg.o
  46. +
  47. +#include "libbb.h"
  48. +#include "libipkg/libipkg.h"
  49. +
  50. +int ipkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  51. +int ipkg_main(int argc, char **argv)
  52. +{
  53. + return ipkg_op(argc, argv);
  54. +}
  55. diff -Nur busybox-1.22.1.orig/archival/libarchive/Kbuild.src busybox-1.22.1/archival/libarchive/Kbuild.src
  56. --- busybox-1.22.1.orig/archival/libarchive/Kbuild.src 2014-01-09 19:15:44.000000000 +0100
  57. +++ busybox-1.22.1/archival/libarchive/Kbuild.src 2014-05-23 21:12:06.000000000 +0200
  58. @@ -25,14 +25,14 @@
  59. \
  60. data_align.o \
  61. find_list_entry.o \
  62. + get_header_tar.o \
  63. + get_header_tar_gz.o \
  64. init_handle.o
  65. DPKG_FILES:= \
  66. unpack_ar_archive.o \
  67. filter_accept_list_reassign.o \
  68. get_header_ar.o \
  69. - get_header_tar.o \
  70. - get_header_tar_gz.o \
  71. get_header_tar_bz2.o \
  72. get_header_tar_lzma.o \
  73. diff -Nur busybox-1.22.1.orig/archival/libipkg/Kbuild busybox-1.22.1/archival/libipkg/Kbuild
  74. --- busybox-1.22.1.orig/archival/libipkg/Kbuild 1970-01-01 01:00:00.000000000 +0100
  75. +++ busybox-1.22.1/archival/libipkg/Kbuild 2014-05-23 21:12:06.000000000 +0200
  76. @@ -0,0 +1,60 @@
  77. +# Makefile for busybox
  78. +#
  79. +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  80. +# Copyright (C) 2006 OpenWrt.org
  81. +#
  82. +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  83. +
  84. +LIBIPKG_CORE_OBJS:= \
  85. + args.o \
  86. + libipkg.o \
  87. + user.o \
  88. +
  89. +LIBIPKG_CMD_OBJS:= \
  90. + ipkg_cmd.o \
  91. + ipkg_configure.o \
  92. + ipkg_download.o \
  93. + ipkg_install.o \
  94. + ipkg_remove.o \
  95. + ipkg_upgrade.o \
  96. +
  97. +LIBIPKG_DB_OBJS:= \
  98. + hash_table.o \
  99. + ipkg_conf.o \
  100. + ipkg_utils.o \
  101. + pkg.o \
  102. + pkg_depends.o \
  103. + pkg_extract.o \
  104. + pkg_hash.o \
  105. + pkg_parse.o \
  106. + pkg_vec.o \
  107. +
  108. +LIBIPKG_LIST_OBJS:= \
  109. + conffile.o \
  110. + conffile_list.o \
  111. + nv_pair.o \
  112. + nv_pair_list.o \
  113. + pkg_dest.o \
  114. + pkg_dest_list.o \
  115. + pkg_src.o \
  116. + pkg_src_list.o \
  117. + str_list.o \
  118. + void_list.o \
  119. +
  120. +LIBIPKG_UTIL_OBJS:= \
  121. + file_util.o \
  122. + ipkg_message.o \
  123. + str_util.o \
  124. + xsystem.o \
  125. +
  126. +lib-y :=
  127. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
  128. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
  129. +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
  130. +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
  131. +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
  132. +
  133. +ifeq ($(strip $(IPKG_ARCH)),)
  134. +IPKG_ARCH:=$(TARGET_ARCH)
  135. +endif
  136. +CFLAGS += -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
  137. diff -Nur busybox-1.22.1.orig/archival/libipkg/args.c busybox-1.22.1/archival/libipkg/args.c
  138. --- busybox-1.22.1.orig/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
  139. +++ busybox-1.22.1/archival/libipkg/args.c 2014-05-23 21:12:06.000000000 +0200
  140. @@ -0,0 +1,242 @@
  141. +/* args.c - parse command-line args
  142. +
  143. + Carl D. Worth
  144. +
  145. + Copyright 2001 University of Southern California
  146. +
  147. + This program is free software; you can redistribute it and/or modify
  148. + it under the terms of the GNU General Public License as published by
  149. + the Free Software Foundation; either version 2, or (at your option)
  150. + any later version.
  151. +
  152. + This program is distributed in the hope that it will be useful,
  153. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  154. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  155. + GNU General Public License for more details.
  156. + */
  157. +
  158. +#include <getopt.h>
  159. +#include <stdlib.h>
  160. +#include <string.h>
  161. +#include <unistd.h>
  162. +
  163. +#include "ipkg.h"
  164. +#include "ipkg_message.h"
  165. +
  166. +#include "args.h"
  167. +#include "sprintf_alloc.h"
  168. +
  169. +#include "libbb.h"
  170. +
  171. +
  172. +static void print_version(void);
  173. +
  174. +enum long_args_opt
  175. +{
  176. + ARGS_OPT_FORCE_DEFAULTS = 129,
  177. + ARGS_OPT_FORCE_DEPENDS,
  178. + ARGS_OPT_FORCE_OVERWRITE,
  179. + ARGS_OPT_FORCE_DOWNGRADE,
  180. + ARGS_OPT_FORCE_REINSTALL,
  181. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
  182. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
  183. + ARGS_OPT_FORCE_SPACE,
  184. + ARGS_OPT_NOACTION,
  185. + ARGS_OPT_NODEPS,
  186. + ARGS_OPT_VERBOSE_WGET,
  187. + ARGS_OPT_VERBOSITY,
  188. + ARGS_OPT_MULTIPLE_PROVIDERS
  189. +};
  190. +
  191. +int args_init(args_t *args)
  192. +{
  193. + const char *conf_file_dir;
  194. +
  195. + memset(args, 0, sizeof(args_t));
  196. +
  197. + args->dest = ARGS_DEFAULT_DEST;
  198. +
  199. + conf_file_dir = getenv("IPKG_CONF_DIR");
  200. + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
  201. + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
  202. + }
  203. + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
  204. + ARGS_DEFAULT_CONF_FILE_NAME);
  205. +
  206. + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
  207. + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
  208. + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
  209. + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
  210. + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
  211. + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
  212. + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
  213. + args->noaction = ARGS_DEFAULT_NOACTION;
  214. + args->nodeps = ARGS_DEFAULT_NODEPS;
  215. + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
  216. + args->verbosity = ARGS_DEFAULT_VERBOSITY;
  217. + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
  218. + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
  219. + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
  220. + args->multiple_providers = 0;
  221. + args->nocheckfordirorfile = 0;
  222. + args->noreadfeedsfile = 0;
  223. +
  224. + return 1;
  225. +}
  226. +
  227. +void args_deinit(args_t *args)
  228. +{
  229. + free(args->conf_file);
  230. + args->conf_file = NULL;
  231. +}
  232. +
  233. +int args_parse(args_t *args, int argc, char *argv[])
  234. +{
  235. + int c;
  236. + int option_index = 0;
  237. + int parse_err = 0;
  238. + static struct option long_options[] = {
  239. + {"query-all", 0, 0, 'A'},
  240. + {"conf-file", 1, 0, 'f'},
  241. + {"conf", 1, 0, 'f'},
  242. + {"dest", 1, 0, 'd'},
  243. + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  244. + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  245. + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  246. + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  247. + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  248. + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  249. + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  250. + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  251. + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  252. + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  253. + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
  254. + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
  255. + {"recursive", 0, 0,
  256. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  257. + {"force-removal-of-dependent-packages", 0, 0,
  258. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  259. + {"force_removal_of_dependent_packages", 0, 0,
  260. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  261. + {"force-removal-of-essential-packages", 0, 0,
  262. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  263. + {"force_removal_of_essential_packages", 0, 0,
  264. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  265. + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  266. + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  267. + {"noaction", 0, 0, ARGS_OPT_NOACTION},
  268. + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
  269. + {"offline", 1, 0, 'o'},
  270. + {"offline-root", 1, 0, 'o'},
  271. + {"test", 0, 0, ARGS_OPT_NOACTION},
  272. + {"tmp-dir", 1, 0, 't'},
  273. + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  274. + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  275. + {"verbosity", 2, 0, 'V'},
  276. + {"version", 0, 0, 'v'},
  277. + {0, 0, 0, 0}
  278. + };
  279. +
  280. + while (1) {
  281. + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
  282. + if (c == -1)
  283. + break;
  284. +
  285. + switch (c) {
  286. + case 'A':
  287. + args->query_all = 1;
  288. + break;
  289. + case 'd':
  290. + args->dest = optarg;
  291. + break;
  292. + case 'f':
  293. + free(args->conf_file);
  294. + args->conf_file = strdup(optarg);
  295. + break;
  296. + case 'o':
  297. + args->offline_root = optarg;
  298. + break;
  299. + case 'n':
  300. + args->noaction = 1;
  301. + break;
  302. + case 't':
  303. + args->tmp_dir = strdup(optarg);
  304. + break;
  305. + case 'v':
  306. + print_version();
  307. + exit(0);
  308. + case 'V':
  309. + case ARGS_OPT_VERBOSITY:
  310. + if (optarg)
  311. + args->verbosity = atoi(optarg);
  312. + else
  313. + args->verbosity += 1;
  314. + break;
  315. + case ARGS_OPT_FORCE_DEFAULTS:
  316. + args->force_defaults = 1;
  317. + break;
  318. + case ARGS_OPT_FORCE_DEPENDS:
  319. + args->force_depends = 1;
  320. + break;
  321. + case ARGS_OPT_FORCE_OVERWRITE:
  322. + args->force_overwrite = 1;
  323. + break;
  324. + case ARGS_OPT_FORCE_DOWNGRADE:
  325. + args->force_downgrade = 1;
  326. + break;
  327. + case ARGS_OPT_FORCE_REINSTALL:
  328. + args->force_reinstall = 1;
  329. + break;
  330. + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
  331. + args->force_removal_of_essential_packages = 1;
  332. + break;
  333. + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
  334. + args->force_removal_of_dependent_packages = 1;
  335. + break;
  336. + case ARGS_OPT_FORCE_SPACE:
  337. + args->force_space = 1;
  338. + break;
  339. + case ARGS_OPT_VERBOSE_WGET:
  340. + args->verbose_wget = 1;
  341. + break;
  342. + case ARGS_OPT_MULTIPLE_PROVIDERS:
  343. + args->multiple_providers = 1;
  344. + break;
  345. + case ARGS_OPT_NODEPS:
  346. + args->nodeps = 1;
  347. + break;
  348. + case ARGS_OPT_NOACTION:
  349. + args->noaction = 1;
  350. + break;
  351. + case ':':
  352. + parse_err++;
  353. + break;
  354. + case '?':
  355. + parse_err++;
  356. + break;
  357. + default:
  358. + bb_error_msg("Confusion: getopt_long returned %d\n", c);
  359. + }
  360. + }
  361. +
  362. + if (parse_err) {
  363. + return -parse_err;
  364. + } else {
  365. + return optind;
  366. + }
  367. +}
  368. +
  369. +void args_usage(const char *complaint)
  370. +{
  371. + if (complaint) {
  372. + bb_error_msg("%s\n", complaint);
  373. + }
  374. + print_version();
  375. + bb_show_usage();
  376. + exit(1);
  377. +}
  378. +
  379. +static void print_version(void)
  380. +{
  381. + bb_error_msg("version %s\n", IPKG_VERSION);
  382. +}
  383. diff -Nur busybox-1.22.1.orig/archival/libipkg/args.h busybox-1.22.1/archival/libipkg/args.h
  384. --- busybox-1.22.1.orig/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
  385. +++ busybox-1.22.1/archival/libipkg/args.h 2014-05-23 21:12:06.000000000 +0200
  386. @@ -0,0 +1,72 @@
  387. +/* args.h - parse command-line args
  388. +
  389. + Carl D. Worth
  390. +
  391. + Copyright 2001 University of Southern California
  392. +
  393. + This program is free software; you can redistribute it and/or modify
  394. + it under the terms of the GNU General Public License as published by
  395. + the Free Software Foundation; either version 2, or (at your option)
  396. + any later version.
  397. +
  398. + This program is distributed in the hope that it will be useful,
  399. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  400. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  401. + GNU General Public License for more details.
  402. +*/
  403. +
  404. +#ifndef ARGS_H
  405. +#define ARGS_H
  406. +
  407. +struct args
  408. +{
  409. + char *conf_file;
  410. + char *dest;
  411. + char *tmp_dir;
  412. + int force_defaults;
  413. + int force_depends;
  414. + int force_overwrite;
  415. + int force_downgrade;
  416. + int force_reinstall;
  417. + int force_removal_of_essential_packages;
  418. + int force_removal_of_dependent_packages;
  419. + int force_space;
  420. + int noaction;
  421. + int nodeps;
  422. + int multiple_providers;
  423. + int query_all;
  424. + int verbose_wget;
  425. + int verbosity;
  426. + int nocheckfordirorfile;
  427. + int noreadfeedsfile;
  428. + char *offline_root;
  429. + char *offline_root_pre_script_cmd;
  430. + char *offline_root_post_script_cmd;
  431. +};
  432. +typedef struct args args_t;
  433. +
  434. +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
  435. +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
  436. +#define ARGS_DEFAULT_DEST NULL
  437. +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
  438. +#define ARGS_DEFAULT_FORCE_DEPENDS 0
  439. +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
  440. +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
  441. +#define ARGS_DEFAULT_FORCE_REINSTALL 0
  442. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
  443. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
  444. +#define ARGS_DEFAULT_FORCE_SPACE 0
  445. +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
  446. +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
  447. +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
  448. +#define ARGS_DEFAULT_NOACTION 0
  449. +#define ARGS_DEFAULT_NODEPS 0
  450. +#define ARGS_DEFAULT_VERBOSE_WGET 0
  451. +#define ARGS_DEFAULT_VERBOSITY 1
  452. +
  453. +int args_init(args_t *args);
  454. +void args_deinit(args_t *args);
  455. +int args_parse(args_t *args, int argc, char *argv[]);
  456. +void args_usage(const char *complaint);
  457. +
  458. +#endif
  459. diff -Nur busybox-1.22.1.orig/archival/libipkg/conffile.c busybox-1.22.1/archival/libipkg/conffile.c
  460. --- busybox-1.22.1.orig/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
  461. +++ busybox-1.22.1/archival/libipkg/conffile.c 2014-05-23 21:12:06.000000000 +0200
  462. @@ -0,0 +1,65 @@
  463. +/* conffile.c - the itsy package management system
  464. +
  465. + Carl D. Worth
  466. +
  467. + Copyright (C) 2001 University of Southern California
  468. +
  469. + This program is free software; you can redistribute it and/or
  470. + modify it under the terms of the GNU General Public License as
  471. + published by the Free Software Foundation; either version 2, or (at
  472. + your option) any later version.
  473. +
  474. + This program is distributed in the hope that it will be useful, but
  475. + WITHOUT ANY WARRANTY; without even the implied warranty of
  476. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  477. + General Public License for more details.
  478. +*/
  479. +
  480. +#include <string.h>
  481. +#include <stdlib.h>
  482. +
  483. +#include "libbb.h"
  484. +#include "ipkg.h"
  485. +#include "ipkg_message.h"
  486. +
  487. +#include "conffile.h"
  488. +#include "file_util.h"
  489. +#include "sprintf_alloc.h"
  490. +
  491. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum)
  492. +{
  493. + return nv_pair_init(conffile, file_name, (char *)md5sum);
  494. +}
  495. +
  496. +void conffile_deinit(conffile_t *conffile)
  497. +{
  498. + nv_pair_deinit(conffile);
  499. +}
  500. +
  501. +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
  502. +{
  503. + uint8_t *md5sum;
  504. + char *filename = conffile->name;
  505. + char *root_filename;
  506. + int ret;
  507. +
  508. + if (conffile->value == NULL) {
  509. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
  510. + return 1;
  511. + }
  512. +
  513. + root_filename = root_filename_alloc(conf, filename);
  514. +
  515. + md5sum = file_md5sum_alloc(root_filename);
  516. +
  517. + ret = strcmp((char *)md5sum, conffile->value);
  518. + if (ret) {
  519. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
  520. + conffile->name, md5sum, conffile->value);
  521. + }
  522. +
  523. + free(root_filename);
  524. + free(md5sum);
  525. +
  526. + return ret;
  527. +}
  528. diff -Nur busybox-1.22.1.orig/archival/libipkg/conffile.h busybox-1.22.1/archival/libipkg/conffile.h
  529. --- busybox-1.22.1.orig/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
  530. +++ busybox-1.22.1/archival/libipkg/conffile.h 2014-05-23 21:12:06.000000000 +0200
  531. @@ -0,0 +1,30 @@
  532. +/* conffile.h - the itsy package management system
  533. +
  534. + Carl D. Worth
  535. +
  536. + Copyright (C) 2001 University of Southern California
  537. +
  538. + This program is free software; you can redistribute it and/or
  539. + modify it under the terms of the GNU General Public License as
  540. + published by the Free Software Foundation; either version 2, or (at
  541. + your option) any later version.
  542. +
  543. + This program is distributed in the hope that it will be useful, but
  544. + WITHOUT ANY WARRANTY; without even the implied warranty of
  545. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  546. + General Public License for more details.
  547. +*/
  548. +
  549. +#ifndef CONFFILE_H
  550. +#define CONFFILE_H
  551. +
  552. +#include "nv_pair.h"
  553. +
  554. +typedef struct nv_pair conffile_t;
  555. +
  556. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum);
  557. +void conffile_deinit(conffile_t *conffile);
  558. +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
  559. +
  560. +#endif
  561. +
  562. diff -Nur busybox-1.22.1.orig/archival/libipkg/conffile_list.c busybox-1.22.1/archival/libipkg/conffile_list.c
  563. --- busybox-1.22.1.orig/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
  564. +++ busybox-1.22.1/archival/libipkg/conffile_list.c 2014-05-23 21:12:06.000000000 +0200
  565. @@ -0,0 +1,47 @@
  566. +/* conffile_list.c - the itsy package management system
  567. +
  568. + Carl D. Worth
  569. +
  570. + Copyright (C) 2001 University of Southern California
  571. +
  572. + This program is free software; you can redistribute it and/or
  573. + modify it under the terms of the GNU General Public License as
  574. + published by the Free Software Foundation; either version 2, or (at
  575. + your option) any later version.
  576. +
  577. + This program is distributed in the hope that it will be useful, but
  578. + WITHOUT ANY WARRANTY; without even the implied warranty of
  579. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  580. + General Public License for more details.
  581. +*/
  582. +
  583. +#include "ipkg.h"
  584. +
  585. +#include "conffile_list.h"
  586. +
  587. +int conffile_list_init(conffile_list_t *list)
  588. +{
  589. + return nv_pair_list_init(list);
  590. +}
  591. +
  592. +void conffile_list_deinit(conffile_list_t *list)
  593. +{
  594. + nv_pair_list_deinit(list);
  595. +}
  596. +
  597. +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
  598. + const char *md5sum)
  599. +{
  600. + return nv_pair_list_append(list, file_name, md5sum);
  601. +}
  602. +
  603. +int conffile_list_push(conffile_list_t *list, conffile_t *data)
  604. +{
  605. + return nv_pair_list_push(list, data);
  606. +}
  607. +
  608. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
  609. +{
  610. + return nv_pair_list_pop(list);
  611. +}
  612. +
  613. diff -Nur busybox-1.22.1.orig/archival/libipkg/conffile_list.h busybox-1.22.1/archival/libipkg/conffile_list.h
  614. --- busybox-1.22.1.orig/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
  615. +++ busybox-1.22.1/archival/libipkg/conffile_list.h 2014-05-23 21:12:06.000000000 +0200
  616. @@ -0,0 +1,36 @@
  617. +/* conffile_list.h - the itsy package management system
  618. +
  619. + Carl D. Worth
  620. +
  621. + Copyright (C) 2001 University of Southern California
  622. +
  623. + This program is free software; you can redistribute it and/or
  624. + modify it under the terms of the GNU General Public License as
  625. + published by the Free Software Foundation; either version 2, or (at
  626. + your option) any later version.
  627. +
  628. + This program is distributed in the hope that it will be useful, but
  629. + WITHOUT ANY WARRANTY; without even the implied warranty of
  630. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  631. + General Public License for more details.
  632. +*/
  633. +
  634. +#ifndef CONFFILE_LIST_H
  635. +#define CONFFILE_LIST_H
  636. +
  637. +#include "conffile.h"
  638. +#include "nv_pair_list.h"
  639. +
  640. +typedef struct nv_pair_list_elt conffile_list_elt_t;
  641. +typedef struct nv_pair_list conffile_list_t;
  642. +
  643. +int conffile_list_init(conffile_list_t *list);
  644. +void conffile_list_deinit(conffile_list_t *list);
  645. +
  646. +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
  647. + const char *root_dir);
  648. +int conffile_list_push(conffile_list_t *list, conffile_t *data);
  649. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
  650. +
  651. +#endif
  652. +
  653. diff -Nur busybox-1.22.1.orig/archival/libipkg/file_util.c busybox-1.22.1/archival/libipkg/file_util.c
  654. --- busybox-1.22.1.orig/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
  655. +++ busybox-1.22.1/archival/libipkg/file_util.c 2014-05-23 21:12:06.000000000 +0200
  656. @@ -0,0 +1,186 @@
  657. +/* file_util.c - convenience routines for common stat operations
  658. +
  659. + Carl D. Worth
  660. +
  661. + Copyright (C) 2001 University of Southern California
  662. +
  663. + This program is free software; you can redistribute it and/or
  664. + modify it under the terms of the GNU General Public License as
  665. + published by the Free Software Foundation; either version 2, or (at
  666. + your option) any later version.
  667. +
  668. + This program is distributed in the hope that it will be useful, but
  669. + WITHOUT ANY WARRANTY; without even the implied warranty of
  670. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  671. + General Public License for more details.
  672. +*/
  673. +
  674. +#include "ipkg.h"
  675. +#include <sys/types.h>
  676. +#include <sys/stat.h>
  677. +
  678. +#include "sprintf_alloc.h"
  679. +#include "file_util.h"
  680. +#include "libbb.h"
  681. +#undef strlen
  682. +
  683. +int file_exists(const char *file_name)
  684. +{
  685. + int err;
  686. + struct stat stat_buf;
  687. +
  688. + err = stat(file_name, &stat_buf);
  689. + if (err == 0) {
  690. + return 1;
  691. + } else {
  692. + return 0;
  693. + }
  694. +}
  695. +
  696. +int file_is_dir(const char *file_name)
  697. +{
  698. + int err;
  699. + struct stat stat_buf;
  700. +
  701. + err = stat(file_name, &stat_buf);
  702. + if (err) {
  703. + return 0;
  704. + }
  705. +
  706. + return S_ISDIR(stat_buf.st_mode);
  707. +}
  708. +
  709. +/* read a single line from a file, stopping at a newline or EOF.
  710. + If a newline is read, it will appear in the resulting string.
  711. + Return value is a malloc'ed char * which should be freed at
  712. + some point by the caller.
  713. +
  714. + Return value is NULL if the file is at EOF when called.
  715. +*/
  716. +#define FILE_READ_LINE_BUF_SIZE 1024
  717. +char *file_read_line_alloc(FILE *file)
  718. +{
  719. + char buf[FILE_READ_LINE_BUF_SIZE];
  720. + int buf_len;
  721. + char *line = NULL;
  722. + int line_size = 0;
  723. +
  724. + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
  725. + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
  726. + buf_len = strlen(buf);
  727. + if (line) {
  728. + line_size += buf_len;
  729. + line = realloc(line, line_size);
  730. + if (line == NULL) {
  731. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  732. + break;
  733. + }
  734. + strcat(line, buf);
  735. + } else {
  736. + line_size = buf_len + 1;
  737. + line = strdup(buf);
  738. + }
  739. + if (buf[buf_len - 1] == '\n') {
  740. + break;
  741. + }
  742. + }
  743. +
  744. + return line;
  745. +}
  746. +
  747. +int file_move(const char *src, const char *dest)
  748. +{
  749. + int err;
  750. +
  751. + err = rename(src, dest);
  752. +
  753. + if (err && errno == EXDEV) {
  754. + err = file_copy(src, dest);
  755. + unlink(src);
  756. + } else if (err) {
  757. + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
  758. + __FUNCTION__, src, dest, strerror(errno));
  759. + }
  760. +
  761. + return err;
  762. +}
  763. +
  764. +/* I put these here to keep libbb dependencies from creeping all over
  765. + the ipkg code */
  766. +int file_copy(const char *src, const char *dest)
  767. +{
  768. + int err;
  769. +
  770. + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
  771. + if (err) {
  772. + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
  773. + __FUNCTION__, src, dest);
  774. + }
  775. +
  776. + return err;
  777. +}
  778. +
  779. +int file_mkdir_hier(char *path, long mode)
  780. +{
  781. + return bb_make_directory(path, mode, FILEUTILS_RECUR);
  782. +}
  783. +
  784. +static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
  785. + unsigned hash_length)
  786. +{
  787. + /* xzalloc zero-terminates */
  788. + char *hex_value = xzalloc((hash_length * 2) + 1);
  789. + bin2hex(hex_value, (char*)hash_value, hash_length);
  790. + return (unsigned char *)hex_value;
  791. +}
  792. +
  793. +static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
  794. +{
  795. + int src_fd, hash_len, count;
  796. + union _ctx_ {
  797. + sha1_ctx_t sha1;
  798. + md5_ctx_t md5;
  799. + } context;
  800. + uint8_t *hash_value = NULL;
  801. + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
  802. + void FAST_FUNC (*update)(void*, const void*, size_t);
  803. + void FAST_FUNC (*final)(void*, void*);
  804. +
  805. + src_fd = open_or_warn_stdin(filename);
  806. + if (src_fd < 0) {
  807. + return NULL;
  808. + }
  809. +
  810. + /* figure specific hash algorithims */
  811. + if (ENABLE_MD5SUM && hash_algo == HASH_MD5) {
  812. + md5_begin(&context.md5);
  813. + update = (void*)md5_hash;
  814. + final = (void*)md5_end;
  815. + hash_len = 16;
  816. + } else {
  817. + bb_error_msg_and_die("algorithm not supported");
  818. + }
  819. +
  820. + while ((count = safe_read(src_fd, in_buf, 4096)) > 0) {
  821. + update(&context, in_buf, count);
  822. + }
  823. +
  824. + if (count == 0) {
  825. + final(&context, in_buf);
  826. + hash_value = hash_bin_to_hex(in_buf, hash_len);
  827. + }
  828. +
  829. + RELEASE_CONFIG_BUFFER(in_buf);
  830. +
  831. + if (src_fd != STDIN_FILENO) {
  832. + close(src_fd);
  833. + }
  834. +
  835. + return hash_value;
  836. +}
  837. +
  838. +uint8_t *file_md5sum_alloc(const char *file_name)
  839. +{
  840. + return hash_file(file_name, HASH_MD5);
  841. +}
  842. +
  843. diff -Nur busybox-1.22.1.orig/archival/libipkg/file_util.h busybox-1.22.1/archival/libipkg/file_util.h
  844. --- busybox-1.22.1.orig/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
  845. +++ busybox-1.22.1/archival/libipkg/file_util.h 2014-05-23 21:12:06.000000000 +0200
  846. @@ -0,0 +1,29 @@
  847. +/* file_util.h - convenience routines for common file operations
  848. +
  849. + Carl D. Worth
  850. +
  851. + Copyright (C) 2001 University of Southern California
  852. +
  853. + This program is free software; you can redistribute it and/or
  854. + modify it under the terms of the GNU General Public License as
  855. + published by the Free Software Foundation; either version 2, or (at
  856. + your option) any later version.
  857. +
  858. + This program is distributed in the hope that it will be useful, but
  859. + WITHOUT ANY WARRANTY; without even the implied warranty of
  860. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  861. + General Public License for more details.
  862. +*/
  863. +
  864. +#ifndef FILE_UTIL_H
  865. +#define FILE_UTIL_H
  866. +
  867. +int file_exists(const char *file_name);
  868. +int file_is_dir(const char *file_name);
  869. +char *file_read_line_alloc(FILE *file);
  870. +int file_move(const char *src, const char *dest);
  871. +int file_copy(const char *src, const char *dest);
  872. +int file_mkdir_hier(char *path, long mode);
  873. +uint8_t *file_md5sum_alloc(const char *file_name);
  874. +
  875. +#endif
  876. diff -Nur busybox-1.22.1.orig/archival/libipkg/hash_table.c busybox-1.22.1/archival/libipkg/hash_table.c
  877. --- busybox-1.22.1.orig/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
  878. +++ busybox-1.22.1/archival/libipkg/hash_table.c 2014-05-23 21:12:06.000000000 +0200
  879. @@ -0,0 +1,155 @@
  880. +/* hash.c - hash tables for ipkg
  881. +
  882. + Steven M. Ayer, Jamey Hicks
  883. +
  884. + Copyright (C) 2002 Compaq Computer Corporation
  885. +
  886. + This program is free software; you can redistribute it and/or
  887. + modify it under the terms of the GNU General Public License as
  888. + published by the Free Software Foundation; either version 2, or (at
  889. + your option) any later version.
  890. +
  891. + This program is distributed in the hope that it will be useful, but
  892. + WITHOUT ANY WARRANTY; without even the implied warranty of
  893. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  894. + General Public License for more details.
  895. +*/
  896. +
  897. +#include <errno.h>
  898. +#include <stdio.h>
  899. +#include <stdlib.h>
  900. +#include <string.h>
  901. +#include "hash_table.h"
  902. +#include "ipkg_message.h"
  903. +
  904. +
  905. +static int hash_index(hash_table_t *hash, const char *pkg_name);
  906. +static int rotating(const char *key, int len, int prime);
  907. +
  908. +static int hash_index(hash_table_t *hash, const char *pkg_name)
  909. +{
  910. + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
  911. +}
  912. +
  913. +static int rotating(const char *key, int len, int prime)
  914. +{
  915. + unsigned int hash, i;
  916. + for (hash=len, i=0; i<len; ++i)
  917. + hash = (hash<<4)^(hash>>28)^key[i];
  918. + return (hash % prime);
  919. +}
  920. +
  921. +
  922. +/*
  923. + * this is an open table keyed by strings
  924. + */
  925. +int hash_table_init(const char *name, hash_table_t *hash, int len)
  926. +{
  927. + static int primes_table[] = {
  928. + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
  929. + 19471, 23143, 33961, 46499, 49727, 99529, 0
  930. + };
  931. + int *picker;
  932. +
  933. + if (hash->entries != NULL) {
  934. + /* we have been here already */
  935. + return 0;
  936. + }
  937. +
  938. + hash->name = name;
  939. + hash->entries = NULL;
  940. + hash->n_entries = 0;
  941. + hash->hash_entry_key = NULL;
  942. +
  943. + picker = primes_table;
  944. + while(*picker && (*picker++ < len));
  945. + if(!*picker)
  946. + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
  947. + --picker;
  948. +
  949. + hash->n_entries = *picker;
  950. + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
  951. + if (hash->entries == NULL) {
  952. + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
  953. + return ENOMEM;
  954. + }
  955. + return 0;
  956. +}
  957. +
  958. +void hash_table_deinit(hash_table_t *hash)
  959. +{
  960. + free(hash->entries);
  961. + hash->entries = NULL;
  962. + hash->n_entries = 0;
  963. +}
  964. +
  965. +void *hash_table_get(hash_table_t *hash, const char *key)
  966. +{
  967. + int ndx= hash_index(hash, key);
  968. + hash_entry_t *hash_entry = hash->entries + ndx;
  969. + while (hash_entry)
  970. + {
  971. + if (hash_entry->key)
  972. + {
  973. + if (strcmp(key, hash_entry->key) == 0) {
  974. + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
  975. + return hash_entry->data;
  976. + }
  977. + }
  978. + hash_entry = hash_entry->next;
  979. + }
  980. + return NULL;
  981. +}
  982. +
  983. +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
  984. +{
  985. + int ndx= hash_index(hash, key);
  986. + hash_entry_t *hash_entry = hash->entries + ndx;
  987. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
  988. + if (hash_entry->key) {
  989. + if (strcmp(hash_entry->key, key) == 0) {
  990. + /* alread in table, update the value */
  991. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
  992. + hash_entry->data = value;
  993. + return 0;
  994. + } else {
  995. + /*
  996. + * if this is a collision, we have to go to the end of the ll,
  997. + * then add a new entry
  998. + * before we can hook up the value
  999. + */
  1000. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
  1001. + while (hash_entry->next)
  1002. + hash_entry = hash_entry->next;
  1003. + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
  1004. + if (!hash_entry->next) {
  1005. + return -ENOMEM;
  1006. + }
  1007. + hash_entry = hash_entry->next;
  1008. + hash_entry->next = NULL;
  1009. + }
  1010. + }
  1011. + hash->n_elements++;
  1012. + hash_entry->key = strdup(key);
  1013. + hash_entry->data = value;
  1014. +
  1015. + return 0;
  1016. +}
  1017. +
  1018. +
  1019. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
  1020. +{
  1021. + int i;
  1022. + if (!hash || !f)
  1023. + return;
  1024. +
  1025. + for (i = 0; i < hash->n_entries; i++) {
  1026. + hash_entry_t *hash_entry = (hash->entries + i);
  1027. + do {
  1028. + if(hash_entry->key) {
  1029. + f(hash_entry->key, hash_entry->data, data);
  1030. + }
  1031. + } while((hash_entry = hash_entry->next));
  1032. + }
  1033. +}
  1034. +
  1035. diff -Nur busybox-1.22.1.orig/archival/libipkg/hash_table.h busybox-1.22.1/archival/libipkg/hash_table.h
  1036. --- busybox-1.22.1.orig/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
  1037. +++ busybox-1.22.1/archival/libipkg/hash_table.h 2014-05-23 21:12:06.000000000 +0200
  1038. @@ -0,0 +1,44 @@
  1039. +/* hash.h - hash tables for ipkg
  1040. +
  1041. + Steven M. Ayer, Jamey Hicks
  1042. +
  1043. + Copyright (C) 2002 Compaq Computer Corporation
  1044. +
  1045. + This program is free software; you can redistribute it and/or
  1046. + modify it under the terms of the GNU General Public License as
  1047. + published by the Free Software Foundation; either version 2, or (at
  1048. + your option) any later version.
  1049. +
  1050. + This program is distributed in the hope that it will be useful, but
  1051. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1052. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1053. + General Public License for more details.
  1054. +*/
  1055. +
  1056. +#ifndef _HASH_TABLE_H_
  1057. +#define _HASH_TABLE_H_
  1058. +
  1059. +typedef struct hash_entry hash_entry_t;
  1060. +typedef struct hash_table hash_table_t;
  1061. +
  1062. +struct hash_entry {
  1063. + const char * key;
  1064. + void * data;
  1065. + struct hash_entry * next;
  1066. +};
  1067. +
  1068. +struct hash_table {
  1069. + const char *name;
  1070. + hash_entry_t * entries;
  1071. + int n_entries; /* number of buckets */
  1072. + int n_elements;
  1073. + const char * (*hash_entry_key)(void * data);
  1074. +};
  1075. +
  1076. +int hash_table_init(const char *name, hash_table_t *hash, int len);
  1077. +void hash_table_deinit(hash_table_t *hash);
  1078. +void *hash_table_get(hash_table_t *hash, const char *key);
  1079. +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
  1080. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
  1081. +
  1082. +#endif /* _HASH_TABLE_H_ */
  1083. diff -Nur busybox-1.22.1.orig/archival/libipkg/ipkg.h busybox-1.22.1/archival/libipkg/ipkg.h
  1084. --- busybox-1.22.1.orig/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
  1085. +++ busybox-1.22.1/archival/libipkg/ipkg.h 2014-05-23 21:12:06.000000000 +0200
  1086. @@ -0,0 +1,68 @@
  1087. +/* ipkg.h - the itsy package management system
  1088. +
  1089. + Carl D. Worth
  1090. +
  1091. + Copyright (C) 2001 University of Southern California
  1092. +
  1093. + This program is free software; you can redistribute it and/or
  1094. + modify it under the terms of the GNU General Public License as
  1095. + published by the Free Software Foundation; either version 2, or (at
  1096. + your option) any later version.
  1097. +
  1098. + This program is distributed in the hope that it will be useful, but
  1099. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1100. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1101. + General Public License for more details.
  1102. +*/
  1103. +
  1104. +#ifndef IPKG_H
  1105. +#define IPKG_H
  1106. +
  1107. +#include "libbb.h"
  1108. +
  1109. +#include "ipkg_includes.h"
  1110. +#include "ipkg_conf.h"
  1111. +#include "ipkg_message.h"
  1112. +
  1113. +#define IPKG_PKG_EXTENSION ".ipk"
  1114. +#define DPKG_PKG_EXTENSION ".deb"
  1115. +
  1116. +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
  1117. +#define IPKG_PKG_VERSION_SEP_CHAR '_'
  1118. +
  1119. +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
  1120. +#define IPKG_LISTS_DIR_SUFFIX "lists"
  1121. +#define IPKG_INFO_DIR_SUFFIX "info"
  1122. +#define IPKG_STATUS_FILE_SUFFIX "status"
  1123. +
  1124. +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
  1125. +
  1126. +#define IPKG_LIST_DESCRIPTION_LENGTH 128
  1127. +
  1128. +#define IPKG_VERSION "1.00"
  1129. +
  1130. +
  1131. +enum ipkg_error {
  1132. + IPKG_SUCCESS = 0,
  1133. + IPKG_PKG_DEPS_UNSATISFIED,
  1134. + IPKG_PKG_IS_ESSENTIAL,
  1135. + IPKG_PKG_HAS_DEPENDENTS,
  1136. + IPKG_PKG_HAS_NO_CANDIDATE
  1137. +};
  1138. +typedef enum ipkg_error ipkg_error_t;
  1139. +
  1140. +extern int ipkg_state_changed;
  1141. +
  1142. +
  1143. +struct errlist {
  1144. + char * errmsg;
  1145. + struct errlist * next;
  1146. +} ;
  1147. +
  1148. +extern struct errlist* error_list;
  1149. +
  1150. +extern ipkg_conf_t *global_conf;
  1151. +
  1152. +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
  1153. +
  1154. +#endif
  1155. diff -Nur busybox-1.22.1.orig/archival/libipkg/ipkg_cmd.c busybox-1.22.1/archival/libipkg/ipkg_cmd.c
  1156. --- busybox-1.22.1.orig/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
  1157. +++ busybox-1.22.1/archival/libipkg/ipkg_cmd.c 2014-05-23 21:12:06.000000000 +0200
  1158. @@ -0,0 +1,1367 @@
  1159. +/* ipkg_cmd.c - the itsy package management system
  1160. +
  1161. + Carl D. Worth
  1162. +
  1163. + Copyright (C) 2001 University of Southern California
  1164. +
  1165. + This program is free software; you can redistribute it and/or
  1166. + modify it under the terms of the GNU General Public License as
  1167. + published by the Free Software Foundation; either version 2, or (at
  1168. + your option) any later version.
  1169. +
  1170. + This program is distributed in the hope that it will be useful, but
  1171. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1172. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1173. + General Public License for more details.
  1174. +*/
  1175. +
  1176. +#include <string.h>
  1177. +
  1178. +#include "ipkg.h"
  1179. +#include <libgen.h>
  1180. +#include <glob.h>
  1181. +#include <errno.h>
  1182. +#include <stdlib.h>
  1183. +#include <unistd.h>
  1184. +#include <signal.h>
  1185. +#include <stdio.h>
  1186. +#include <dirent.h>
  1187. +
  1188. +#include "ipkg_conf.h"
  1189. +#include "ipkg_cmd.h"
  1190. +#include "ipkg_message.h"
  1191. +#include "pkg.h"
  1192. +#include "pkg_dest.h"
  1193. +#include "pkg_parse.h"
  1194. +#include "sprintf_alloc.h"
  1195. +#include "pkg.h"
  1196. +#include "file_util.h"
  1197. +#include "str_util.h"
  1198. +#include "bb_archive.h"
  1199. +
  1200. +#include <fnmatch.h>
  1201. +
  1202. +
  1203. +#include "ipkg_download.h"
  1204. +#include "ipkg_install.h"
  1205. +#include "ipkg_upgrade.h"
  1206. +#include "ipkg_remove.h"
  1207. +#include "ipkg_configure.h"
  1208. +#include "ipkg_message.h"
  1209. +
  1210. +#include "libipkg.h"
  1211. +static void *p_userdata = NULL;
  1212. +
  1213. +static int ipkg_update_cmd(ipkg_conf_t *conf);
  1214. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1215. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1216. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1217. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1218. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf);
  1219. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1220. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1221. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1222. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1223. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1224. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1225. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1226. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1227. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1228. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1229. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1230. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1231. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1232. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1233. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1234. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1235. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1236. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf);
  1237. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1238. +
  1239. +/* XXX: CLEANUP: The usage strings should be incorporated into this
  1240. + array for easier maintenance */
  1241. +static ipkg_cmd_t cmds[] = {
  1242. + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
  1243. + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
  1244. + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
  1245. + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
  1246. + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
  1247. + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
  1248. + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
  1249. + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
  1250. + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
  1251. + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
  1252. + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
  1253. + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
  1254. + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
  1255. + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
  1256. + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
  1257. + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1258. + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1259. + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1260. + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1261. + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1262. + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1263. + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
  1264. + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
  1265. + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
  1266. + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
  1267. + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
  1268. + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
  1269. + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
  1270. + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
  1271. +};
  1272. +
  1273. +int ipkg_state_changed;
  1274. +static void write_status_files_if_changed(ipkg_conf_t *conf)
  1275. +{
  1276. + if (ipkg_state_changed && !conf->noaction) {
  1277. + ipkg_message(conf, IPKG_INFO,
  1278. + " writing status file\n");
  1279. + ipkg_conf_write_status_files(conf);
  1280. + pkg_write_changed_filelists(conf);
  1281. + } else {
  1282. + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
  1283. + }
  1284. +}
  1285. +
  1286. +
  1287. +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
  1288. +
  1289. +ipkg_cmd_t *ipkg_cmd_find(const char *name)
  1290. +{
  1291. + int i;
  1292. + ipkg_cmd_t *cmd;
  1293. +
  1294. + for (i=0; i < num_cmds; i++) {
  1295. + cmd = &cmds[i];
  1296. + if (strcmp(name, cmd->name) == 0) {
  1297. + return cmd;
  1298. + }
  1299. + }
  1300. +
  1301. + return NULL;
  1302. +}
  1303. +
  1304. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
  1305. +{
  1306. + int result;
  1307. + p_userdata = userdata;
  1308. +
  1309. +
  1310. + result = (cmd->fun)(conf, argc, argv);
  1311. + if ( result == 0 ) {
  1312. + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
  1313. + } else {
  1314. + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
  1315. +
  1316. + }
  1317. + if ( error_list ) {
  1318. + reverse_error_list(&error_list);
  1319. +
  1320. + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
  1321. + /* Here we print the errors collected and free the list */
  1322. + while (error_list != NULL) {
  1323. + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
  1324. + error_list = error_list->next;
  1325. +
  1326. + }
  1327. + free_error_list(&error_list);
  1328. +
  1329. + }
  1330. +
  1331. + p_userdata = NULL;
  1332. + return result;
  1333. +}
  1334. +
  1335. +static int ipkg_update_cmd(ipkg_conf_t *conf)
  1336. +{
  1337. + int err;
  1338. + int failures;
  1339. + char *lists_dir;
  1340. + pkg_src_list_elt_t *iter;
  1341. + pkg_src_t *src;
  1342. +
  1343. +
  1344. + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
  1345. +
  1346. + if (! file_is_dir(lists_dir)) {
  1347. + if (file_exists(lists_dir)) {
  1348. + ipkg_message(conf, IPKG_ERROR,
  1349. + "%s: ERROR: %s exists, but is not a directory\n",
  1350. + __FUNCTION__, lists_dir);
  1351. + free(lists_dir);
  1352. + return EINVAL;
  1353. + }
  1354. + err = file_mkdir_hier(lists_dir, 0755);
  1355. + if (err) {
  1356. + ipkg_message(conf, IPKG_ERROR,
  1357. + "%s: ERROR: failed to make directory %s: %s\n",
  1358. + __FUNCTION__, lists_dir, strerror(errno));
  1359. + free(lists_dir);
  1360. + return EINVAL;
  1361. + }
  1362. + }
  1363. +
  1364. + failures = 0;
  1365. + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
  1366. + char *url, *list_file_name;
  1367. +
  1368. + src = iter->data;
  1369. +
  1370. + if (src->extra_data) /* debian style? */
  1371. + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
  1372. + src->gzip ? "Packages.gz" : "Packages");
  1373. + else
  1374. + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
  1375. +
  1376. + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
  1377. + if (src->gzip) {
  1378. + char *tmp;
  1379. + char *tmp_file_name;
  1380. + FILE *in, *out;
  1381. +
  1382. + tmp = strdup ("/tmp/ipkg.XXXXXX");
  1383. +
  1384. + if (mkdtemp (tmp) == NULL) {
  1385. + perror ("mkdtemp");
  1386. + failures++;
  1387. + continue;
  1388. + }
  1389. +
  1390. + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
  1391. + err = ipkg_download(conf, url, tmp_file_name);
  1392. + if (err == 0) {
  1393. + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
  1394. + in = fopen (tmp_file_name, "r");
  1395. + out = fopen (list_file_name, "w");
  1396. + if (in && out) {
  1397. + transformer_aux_data_t aux;
  1398. + init_transformer_aux_data(&aux);
  1399. + inflate_unzip (&aux, fileno(in), fileno(out));
  1400. + } else
  1401. + err = 1;
  1402. + if (in)
  1403. + fclose (in);
  1404. + if (out)
  1405. + fclose (out);
  1406. + unlink (tmp_file_name);
  1407. + rmdir (tmp);
  1408. + free (tmp);
  1409. + }
  1410. + } else
  1411. + err = ipkg_download(conf, url, list_file_name);
  1412. + if (err) {
  1413. + failures++;
  1414. + } else {
  1415. + ipkg_message(conf, IPKG_NOTICE,
  1416. + "Updated list of available packages in %s\n",
  1417. + list_file_name);
  1418. + }
  1419. + free(url);
  1420. + free(list_file_name);
  1421. + }
  1422. + free(lists_dir);
  1423. +
  1424. +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
  1425. +#warning here
  1426. + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
  1427. + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
  1428. + * -Jamey 3/1/03
  1429. + */
  1430. + {
  1431. + int i;
  1432. + int changed = 0;
  1433. + pkg_vec_t *available = pkg_vec_alloc();
  1434. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1435. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
  1436. + for (i = 0; i < available->len; i++) {
  1437. + pkg_t *pkg = available->pkgs[i];
  1438. + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
  1439. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
  1440. + pkg->state_want = SW_UNKNOWN;
  1441. + changed = 1;
  1442. + }
  1443. + }
  1444. + pkg_vec_free(available);
  1445. + if (changed) {
  1446. + write_status_files_if_changed(conf);
  1447. + }
  1448. + }
  1449. +#endif
  1450. +
  1451. + return failures;
  1452. +}
  1453. +
  1454. +
  1455. +/* scan the args passed and cache the local filenames of the packages */
  1456. +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
  1457. +{
  1458. + int i;
  1459. + int err;
  1460. +
  1461. + /*
  1462. + * First scan through package names/urls
  1463. + * For any urls, download the packages and install in database.
  1464. + * For any files, install package info in database.
  1465. + */
  1466. + for (i = 0; i < argc; i ++) {
  1467. + char *filename = argv [i];
  1468. + //char *tmp = basename (tmp);
  1469. + //int tmplen = strlen (tmp);
  1470. +
  1471. + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
  1472. + // continue;
  1473. + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
  1474. + // continue;
  1475. +
  1476. + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
  1477. +
  1478. + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
  1479. + if (err)
  1480. + return err;
  1481. + }
  1482. + return 0;
  1483. +}
  1484. +
  1485. +struct ipkg_intercept
  1486. +{
  1487. + char *oldpath;
  1488. + char *statedir;
  1489. +};
  1490. +
  1491. +typedef struct ipkg_intercept *ipkg_intercept_t;
  1492. +ipkg_intercept_t ipkg_prep_intercepts(void);
  1493. +
  1494. +ipkg_intercept_t ipkg_prep_intercepts(void)
  1495. +{
  1496. + ipkg_intercept_t ctx;
  1497. + char *newpath;
  1498. + int gen;
  1499. +
  1500. + ctx = malloc (sizeof (*ctx));
  1501. + ctx->oldpath = strdup (getenv ("PATH"));
  1502. +
  1503. + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
  1504. + setenv ("PATH", newpath, 1);
  1505. + free (newpath);
  1506. +
  1507. + gen = 0;
  1508. + retry:
  1509. + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
  1510. + if (mkdir (ctx->statedir, 0770) < 0) {
  1511. + if (errno == EEXIST) {
  1512. + free (ctx->statedir);
  1513. + gen++;
  1514. + goto retry;
  1515. + }
  1516. + perror (ctx->statedir);
  1517. + return NULL;
  1518. + }
  1519. + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
  1520. + return ctx;
  1521. +}
  1522. +
  1523. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx);
  1524. +
  1525. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
  1526. +{
  1527. + char *cmd;
  1528. + DIR *dir;
  1529. + int err = 0;
  1530. +
  1531. + setenv ("PATH", ctx->oldpath, 1);
  1532. + free (ctx->oldpath);
  1533. +
  1534. + dir = opendir (ctx->statedir);
  1535. + if (dir) {
  1536. + struct dirent *de;
  1537. + while (de = readdir (dir), de != NULL) {
  1538. + char *path;
  1539. +
  1540. + if (de->d_name[0] == '.')
  1541. + continue;
  1542. +
  1543. + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
  1544. + if (access (path, X_OK) == 0) {
  1545. + if (system (path)) {
  1546. + err = errno;
  1547. + perror (de->d_name);
  1548. + }
  1549. + }
  1550. + free (path);
  1551. + }
  1552. + } else
  1553. + perror (ctx->statedir);
  1554. +
  1555. + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
  1556. + system (cmd);
  1557. + free (cmd);
  1558. +
  1559. + free (ctx->statedir);
  1560. + free (ctx);
  1561. +
  1562. + return err;
  1563. +}
  1564. +
  1565. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
  1566. +{
  1567. + pkg_vec_t *all;
  1568. + int i;
  1569. + pkg_t *pkg;
  1570. + ipkg_intercept_t ic;
  1571. + int r, err = 0;
  1572. +
  1573. + ipkg_message(conf, IPKG_INFO,
  1574. + "Configuring unpacked packages\n");
  1575. + fflush( stdout );
  1576. +
  1577. + all = pkg_vec_alloc();
  1578. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  1579. +
  1580. + ic = ipkg_prep_intercepts();
  1581. +
  1582. + for(i = 0; i < all->len; i++) {
  1583. + pkg = all->pkgs[i];
  1584. +
  1585. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1586. + continue;
  1587. +
  1588. + if (pkg->state_status == SS_UNPACKED) {
  1589. + ipkg_message(conf, IPKG_NOTICE,
  1590. + "Configuring %s\n", pkg->name);
  1591. + fflush( stdout );
  1592. + r = ipkg_configure(conf, pkg);
  1593. + if (r == 0) {
  1594. + pkg->state_status = SS_INSTALLED;
  1595. + pkg->parent->state_status = SS_INSTALLED;
  1596. + pkg->state_flag &= ~SF_PREFER;
  1597. + } else {
  1598. + if (!err)
  1599. + err = r;
  1600. + }
  1601. + }
  1602. + }
  1603. +
  1604. + r = ipkg_finalize_intercepts (ic);
  1605. + if (r && !err)
  1606. + err = r;
  1607. +
  1608. + pkg_vec_free(all);
  1609. + return err;
  1610. +}
  1611. +
  1612. +static void sigint_handler(int sig)
  1613. +{
  1614. + signal(sig, SIG_DFL);
  1615. + ipkg_message(NULL, IPKG_NOTICE,
  1616. + "ipkg: interrupted. writing out status database\n");
  1617. + write_status_files_if_changed(global_conf);
  1618. + exit(128 + sig);
  1619. +}
  1620. +
  1621. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1622. +{
  1623. + int i;
  1624. + char *arg;
  1625. + int err=0;
  1626. +
  1627. + global_conf = conf;
  1628. + signal(SIGINT, sigint_handler);
  1629. +
  1630. + /*
  1631. + * Now scan through package names and install
  1632. + */
  1633. + for (i=0; i < argc; i++) {
  1634. + arg = argv[i];
  1635. +
  1636. + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
  1637. + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
  1638. + if (err != EINVAL && err != 0)
  1639. + return err;
  1640. + }
  1641. + pkg_info_preinstall_check(conf);
  1642. +
  1643. + for (i=0; i < argc; i++) {
  1644. + arg = argv[i];
  1645. + if (conf->multiple_providers)
  1646. + err = ipkg_install_multi_by_name(conf, arg);
  1647. + else{
  1648. + err = ipkg_install_by_name(conf, arg);
  1649. + }
  1650. + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
  1651. + ipkg_message(conf, IPKG_ERROR,
  1652. + "Cannot find package %s.\n"
  1653. + "Check the spelling or perhaps run 'ipkg update'\n",
  1654. + arg);
  1655. + }
  1656. + }
  1657. +
  1658. + /* recheck to verify that all dependences are satisfied */
  1659. + if (0) ipkg_satisfy_all_dependences(conf);
  1660. +
  1661. + ipkg_configure_packages(conf, NULL);
  1662. +
  1663. + write_status_files_if_changed(conf);
  1664. +
  1665. + return err;
  1666. +}
  1667. +
  1668. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1669. +{
  1670. + int i;
  1671. + pkg_t *pkg;
  1672. + int err;
  1673. +
  1674. + global_conf = conf;
  1675. + signal(SIGINT, sigint_handler);
  1676. +
  1677. + if (argc) {
  1678. + for (i=0; i < argc; i++) {
  1679. + char *arg = argv[i];
  1680. +
  1681. + err = ipkg_prepare_url_for_install(conf, arg, &arg);
  1682. + if (err != EINVAL && err != 0)
  1683. + return err;
  1684. + }
  1685. + pkg_info_preinstall_check(conf);
  1686. +
  1687. + for (i=0; i < argc; i++) {
  1688. + char *arg = argv[i];
  1689. + if (conf->restrict_to_default_dest) {
  1690. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1691. + argv[i],
  1692. + conf->default_dest);
  1693. + if (pkg == NULL) {
  1694. + ipkg_message(conf, IPKG_NOTICE,
  1695. + "Package %s not installed in %s\n",
  1696. + argv[i], conf->default_dest->name);
  1697. + continue;
  1698. + }
  1699. + } else {
  1700. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  1701. + argv[i]);
  1702. + }
  1703. + if (pkg)
  1704. + ipkg_upgrade_pkg(conf, pkg);
  1705. + else {
  1706. + ipkg_install_by_name(conf, arg);
  1707. + }
  1708. + }
  1709. + } else {
  1710. + pkg_vec_t *installed = pkg_vec_alloc();
  1711. +
  1712. + pkg_info_preinstall_check(conf);
  1713. +
  1714. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  1715. + for (i = 0; i < installed->len; i++) {
  1716. + pkg = installed->pkgs[i];
  1717. + ipkg_upgrade_pkg(conf, pkg);
  1718. + }
  1719. + pkg_vec_free(installed);
  1720. + }
  1721. +
  1722. + /* recheck to verify that all dependences are satisfied */
  1723. + if (0) ipkg_satisfy_all_dependences(conf);
  1724. +
  1725. + ipkg_configure_packages(conf, NULL);
  1726. +
  1727. + write_status_files_if_changed(conf);
  1728. +
  1729. + return 0;
  1730. +}
  1731. +
  1732. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1733. +{
  1734. + int i, err;
  1735. + char *arg;
  1736. + pkg_t *pkg;
  1737. +
  1738. + pkg_info_preinstall_check(conf);
  1739. + for (i = 0; i < argc; i++) {
  1740. + arg = argv[i];
  1741. +
  1742. + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
  1743. + if (pkg == NULL) {
  1744. + ipkg_message(conf, IPKG_ERROR,
  1745. + "Cannot find package %s.\n"
  1746. + "Check the spelling or perhaps run 'ipkg update'\n",
  1747. + arg);
  1748. + continue;
  1749. + }
  1750. +
  1751. + err = ipkg_download_pkg(conf, pkg, ".");
  1752. +
  1753. + if (err) {
  1754. + ipkg_message(conf, IPKG_ERROR,
  1755. + "Failed to download %s\n", pkg->name);
  1756. + } else {
  1757. + ipkg_message(conf, IPKG_NOTICE,
  1758. + "Downloaded %s as %s\n",
  1759. + pkg->name, pkg->local_filename);
  1760. + }
  1761. + }
  1762. +
  1763. + return 0;
  1764. +}
  1765. +
  1766. +
  1767. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1768. +{
  1769. + int i ;
  1770. + pkg_vec_t *available;
  1771. + pkg_t *pkg;
  1772. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1773. + char *newline;
  1774. + char *pkg_name = NULL;
  1775. + char *version_str;
  1776. +
  1777. + if (argc > 0) {
  1778. + pkg_name = argv[0];
  1779. + }
  1780. + available = pkg_vec_alloc();
  1781. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1782. + for (i=0; i < available->len; i++) {
  1783. + pkg = available->pkgs[i];
  1784. + /* if we have package name or pattern and pkg does not match, then skip it */
  1785. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1786. + continue;
  1787. + if (pkg->description) {
  1788. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1789. + } else {
  1790. + desc_short[0] = '\0';
  1791. + }
  1792. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1793. + newline = strchr(desc_short, '\n');
  1794. + if (newline) {
  1795. + *newline = '\0';
  1796. + }
  1797. + if (ipkg_cb_list) {
  1798. + version_str = pkg_version_str_alloc(pkg);
  1799. + ipkg_cb_list(pkg->name,desc_short,
  1800. + version_str,
  1801. + pkg->state_status,
  1802. + p_userdata);
  1803. + free(version_str);
  1804. + }
  1805. + }
  1806. + pkg_vec_free(available);
  1807. +
  1808. + return 0;
  1809. +}
  1810. +
  1811. +
  1812. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1813. +{
  1814. + int i ;
  1815. + pkg_vec_t *available;
  1816. + pkg_t *pkg;
  1817. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1818. + char *newline;
  1819. + char *pkg_name = NULL;
  1820. + char *version_str;
  1821. +
  1822. + if (argc > 0) {
  1823. + pkg_name = argv[0];
  1824. + }
  1825. + available = pkg_vec_alloc();
  1826. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1827. + for (i=0; i < available->len; i++) {
  1828. + pkg = available->pkgs[i];
  1829. + /* if we have package name or pattern and pkg does not match, then skip it */
  1830. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1831. + continue;
  1832. + if (pkg->description) {
  1833. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1834. + } else {
  1835. + desc_short[0] = '\0';
  1836. + }
  1837. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1838. + newline = strchr(desc_short, '\n');
  1839. + if (newline) {
  1840. + *newline = '\0';
  1841. + }
  1842. + if (ipkg_cb_list) {
  1843. + version_str = pkg_version_str_alloc(pkg);
  1844. + ipkg_cb_list(pkg->name,desc_short,
  1845. + version_str,
  1846. + pkg->state_status,
  1847. + p_userdata);
  1848. + free(version_str);
  1849. + }
  1850. + }
  1851. +
  1852. + return 0;
  1853. +}
  1854. +
  1855. +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
  1856. +{
  1857. + int i;
  1858. + pkg_vec_t *available;
  1859. + pkg_t *pkg;
  1860. + char *pkg_name = NULL;
  1861. + char **pkg_fields = NULL;
  1862. + int n_fields = 0;
  1863. + char *buff ; // = (char *)malloc(1);
  1864. +
  1865. + if (argc > 0) {
  1866. + pkg_name = argv[0];
  1867. + }
  1868. + if (argc > 1) {
  1869. + pkg_fields = &argv[1];
  1870. + n_fields = argc - 1;
  1871. + }
  1872. +
  1873. + available = pkg_vec_alloc();
  1874. + if (installed_only)
  1875. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1876. + else
  1877. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1878. + for (i=0; i < available->len; i++) {
  1879. + pkg = available->pkgs[i];
  1880. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1881. + continue;
  1882. + }
  1883. + buff = pkg_formatted_info(pkg);
  1884. + if ( buff ) {
  1885. + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
  1886. + pkg->state_status,
  1887. + buff,
  1888. + p_userdata);
  1889. + free(buff);
  1890. + }
  1891. + if (conf->verbosity > 1) {
  1892. + conffile_list_elt_t *iter;
  1893. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  1894. + conffile_t *cf = iter->data;
  1895. + int modified = conffile_has_been_modified(conf, cf);
  1896. + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
  1897. + cf->name, cf->value, modified);
  1898. + }
  1899. + }
  1900. + }
  1901. + pkg_vec_free(available);
  1902. +
  1903. + return 0;
  1904. +}
  1905. +
  1906. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1907. +{
  1908. + return ipkg_info_status_cmd(conf, argc, argv, 0);
  1909. +}
  1910. +
  1911. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1912. +{
  1913. + return ipkg_info_status_cmd(conf, argc, argv, 1);
  1914. +}
  1915. +
  1916. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1917. +{
  1918. +
  1919. + int err;
  1920. + if (argc > 0) {
  1921. + char *pkg_name = NULL;
  1922. +
  1923. + pkg_name = argv[0];
  1924. +
  1925. + err = ipkg_configure_packages (conf, pkg_name);
  1926. +
  1927. + } else {
  1928. + err = ipkg_configure_packages (conf, NULL);
  1929. + }
  1930. +
  1931. + write_status_files_if_changed(conf);
  1932. +
  1933. + return err;
  1934. +}
  1935. +
  1936. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf)
  1937. +{
  1938. + int i, err;
  1939. + char *globpattern;
  1940. + glob_t globbuf;
  1941. +
  1942. + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
  1943. + err = glob(globpattern, 0, NULL, &globbuf);
  1944. + free(globpattern);
  1945. + if (err) {
  1946. + return 0;
  1947. + }
  1948. +
  1949. + ipkg_message(conf, IPKG_NOTICE,
  1950. + "The following packages in %s will now be installed.\n",
  1951. + conf->pending_dir);
  1952. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1953. + ipkg_message(conf, IPKG_NOTICE,
  1954. + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
  1955. + }
  1956. + ipkg_message(conf, IPKG_NOTICE, "\n");
  1957. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1958. + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
  1959. + if (err == 0) {
  1960. + err = unlink(globbuf.gl_pathv[i]);
  1961. + if (err) {
  1962. + ipkg_message(conf, IPKG_ERROR,
  1963. + "%s: ERROR: failed to unlink %s: %s\n",
  1964. + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
  1965. + return err;
  1966. + }
  1967. + }
  1968. + }
  1969. + globfree(&globbuf);
  1970. +
  1971. + return err;
  1972. +}
  1973. +
  1974. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1975. +{
  1976. + int i,a,done;
  1977. + pkg_t *pkg;
  1978. + pkg_t *pkg_to_remove;
  1979. + pkg_vec_t *available;
  1980. + char *pkg_name = NULL;
  1981. + global_conf = conf;
  1982. + signal(SIGINT, sigint_handler);
  1983. +
  1984. +// ENH: Add the "no pkg removed" just in case.
  1985. +
  1986. + done = 0;
  1987. +
  1988. + available = pkg_vec_alloc();
  1989. + pkg_info_preinstall_check(conf);
  1990. + if ( argc > 0 ) {
  1991. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1992. + for (i=0; i < argc; i++) {
  1993. + pkg_name = malloc(strlen(argv[i])+2);
  1994. + strcpy(pkg_name,argv[i]);
  1995. + for (a=0; a < available->len; a++) {
  1996. + pkg = available->pkgs[a];
  1997. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1998. + continue;
  1999. + }
  2000. + if (conf->restrict_to_default_dest) {
  2001. + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  2002. + pkg->name,
  2003. + conf->default_dest);
  2004. + } else {
  2005. + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
  2006. + }
  2007. +
  2008. + if (pkg == NULL) {
  2009. + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
  2010. + continue;
  2011. + }
  2012. + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
  2013. + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
  2014. + continue;
  2015. + }
  2016. + ipkg_remove_pkg(conf, pkg_to_remove,0);
  2017. + done = 1;
  2018. + }
  2019. + free (pkg_name);
  2020. + }
  2021. + pkg_vec_free(available);
  2022. + } else {
  2023. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  2024. + int flagged_pkg_count = 0;
  2025. + int removed;
  2026. +
  2027. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
  2028. +
  2029. + for (i = 0; i < installed_pkgs->len; i++) {
  2030. + pkg = installed_pkgs->pkgs[i];
  2031. + if (pkg->state_flag & SF_USER) {
  2032. + flagged_pkg_count++;
  2033. + } else {
  2034. + if (!pkg_has_installed_dependents(pkg, NULL))
  2035. + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
  2036. + }
  2037. + }
  2038. + if (!flagged_pkg_count) {
  2039. + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
  2040. + "so refusing to uninstall unflagged non-leaf packages\n");
  2041. + return 0;
  2042. + }
  2043. +
  2044. + /* find packages not flagged SF_USER (i.e., installed to
  2045. + * satisfy a dependence) and not having any dependents, and
  2046. + * remove them */
  2047. + do {
  2048. + removed = 0;
  2049. + for (i = 0; i < installed_pkgs->len; i++) {
  2050. + pkg = installed_pkgs->pkgs[i];
  2051. + if (!(pkg->state_flag & SF_USER)
  2052. + && !pkg_has_installed_dependents(pkg, NULL)) {
  2053. + removed++;
  2054. + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
  2055. + ipkg_remove_pkg(conf, pkg,0);
  2056. + done = 1;
  2057. + }
  2058. + }
  2059. + } while (removed);
  2060. + pkg_vec_free(installed_pkgs);
  2061. + }
  2062. +
  2063. + if ( done == 0 )
  2064. + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
  2065. +
  2066. + write_status_files_if_changed(conf);
  2067. + return 0;
  2068. +}
  2069. +
  2070. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2071. +{
  2072. + int i;
  2073. + pkg_t *pkg;
  2074. +
  2075. + global_conf = conf;
  2076. + signal(SIGINT, sigint_handler);
  2077. +
  2078. + pkg_info_preinstall_check(conf);
  2079. +
  2080. + for (i=0; i < argc; i++) {
  2081. + if (conf->restrict_to_default_dest) {
  2082. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  2083. + argv[i],
  2084. + conf->default_dest);
  2085. + } else {
  2086. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  2087. + }
  2088. +
  2089. + if (pkg == NULL) {
  2090. + ipkg_message(conf, IPKG_ERROR,
  2091. + "Package %s is not installed.\n", argv[i]);
  2092. + continue;
  2093. + }
  2094. + ipkg_purge_pkg(conf, pkg);
  2095. + }
  2096. +
  2097. + write_status_files_if_changed(conf);
  2098. + return 0;
  2099. +}
  2100. +
  2101. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2102. +{
  2103. + int i;
  2104. + pkg_t *pkg;
  2105. + char *flags = argv[0];
  2106. +
  2107. + global_conf = conf;
  2108. + signal(SIGINT, sigint_handler);
  2109. +
  2110. + for (i=1; i < argc; i++) {
  2111. + if (conf->restrict_to_default_dest) {
  2112. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  2113. + argv[i],
  2114. + conf->default_dest);
  2115. + } else {
  2116. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  2117. + }
  2118. +
  2119. + if (pkg == NULL) {
  2120. + ipkg_message(conf, IPKG_ERROR,
  2121. + "Package %s is not installed.\n", argv[i]);
  2122. + continue;
  2123. + }
  2124. + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
  2125. + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
  2126. + pkg->state_flag = pkg_state_flag_from_str(flags);
  2127. + }
  2128. +/* pb_ asked this feature 03292004 */
  2129. +/* Actually I will use only this two, but this is an open for various status */
  2130. + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
  2131. + pkg->state_status = pkg_state_status_from_str(flags);
  2132. + }
  2133. + ipkg_state_changed++;
  2134. + ipkg_message(conf, IPKG_NOTICE,
  2135. + "Setting flags for package %s to %s\n",
  2136. + pkg->name, flags);
  2137. + }
  2138. +
  2139. + write_status_files_if_changed(conf);
  2140. + return 0;
  2141. +}
  2142. +
  2143. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2144. +{
  2145. + pkg_t *pkg;
  2146. + str_list_t *installed_files;
  2147. + str_list_elt_t *iter;
  2148. + char *pkg_version;
  2149. + size_t buff_len = 8192;
  2150. + size_t used_len;
  2151. + char *buff ;
  2152. +
  2153. + buff = (char *)malloc(buff_len);
  2154. + if ( buff == NULL ) {
  2155. + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
  2156. + return ENOMEM;
  2157. + }
  2158. +
  2159. + if (argc < 1) {
  2160. + return EINVAL;
  2161. + }
  2162. +
  2163. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  2164. + argv[0]);
  2165. + if (pkg == NULL) {
  2166. + ipkg_message(conf, IPKG_ERROR,
  2167. + "Package %s not installed.\n", argv[0]);
  2168. + return 0;
  2169. + }
  2170. +
  2171. + installed_files = pkg_get_installed_files(pkg);
  2172. + pkg_version = pkg_version_str_alloc(pkg);
  2173. +
  2174. + printf("Package %s (%s) is installed on %s and has the following files:\n",
  2175. + pkg->name, pkg_version, pkg->dest->name);
  2176. + for (iter = installed_files->head; iter; iter = iter->next) {
  2177. + puts(iter->data);
  2178. + }
  2179. +
  2180. + free(pkg_version);
  2181. + pkg_free_installed_files(pkg);
  2182. +
  2183. + return 0;
  2184. +}
  2185. +
  2186. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2187. +{
  2188. +
  2189. + if (argc > 0) {
  2190. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2191. + const char *rel_str = "depends on";
  2192. + int i;
  2193. +
  2194. + pkg_info_preinstall_check(conf);
  2195. +
  2196. + if (conf->query_all)
  2197. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2198. + else
  2199. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2200. + for (i = 0; i < argc; i++) {
  2201. + const char *target = argv[i];
  2202. + int j;
  2203. +
  2204. + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
  2205. +
  2206. + for (j = 0; j < available_pkgs->len; j++) {
  2207. + pkg_t *pkg = available_pkgs->pkgs[j];
  2208. + if (fnmatch(target, pkg->name, 0) == 0) {
  2209. + int k;
  2210. + int count = pkg->depends_count + pkg->pre_depends_count;
  2211. + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
  2212. + target, pkg->architecture, rel_str);
  2213. + for (k = 0; k < count; k++) {
  2214. + compound_depend_t *cdepend = &pkg->depends[k];
  2215. + int l;
  2216. + for (l = 0; l < cdepend->possibility_count; l++) {
  2217. + depend_t *possibility = cdepend->possibilities[l];
  2218. + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
  2219. + if (conf->verbosity > 0) {
  2220. + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
  2221. + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
  2222. + if (possibility->version) {
  2223. + const char *typestr = NULL;
  2224. + switch (possibility->constraint) {
  2225. + case NONE: typestr = "none"; break;
  2226. + case EARLIER: typestr = "<"; break;
  2227. + case EARLIER_EQUAL: typestr = "<="; break;
  2228. + case EQUAL: typestr = "="; break;
  2229. + case LATER_EQUAL: typestr = ">="; break;
  2230. + case LATER: typestr = ">"; break;
  2231. + }
  2232. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2233. + }
  2234. + // free(ver);
  2235. + }
  2236. + ipkg_message(conf, IPKG_ERROR, "\n");
  2237. + }
  2238. + }
  2239. + }
  2240. + }
  2241. + }
  2242. + pkg_vec_free(available_pkgs);
  2243. + }
  2244. + return 0;
  2245. +}
  2246. +
  2247. +enum what_field_type {
  2248. + WHATDEPENDS,
  2249. + WHATCONFLICTS,
  2250. + WHATPROVIDES,
  2251. + WHATREPLACES,
  2252. + WHATRECOMMENDS,
  2253. + WHATSUGGESTS
  2254. +};
  2255. +
  2256. +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
  2257. +{
  2258. +
  2259. + if (argc > 0) {
  2260. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2261. + const char *rel_str = NULL;
  2262. + int i;
  2263. + int changed;
  2264. +
  2265. + switch (what_field_type) {
  2266. + case WHATDEPENDS: rel_str = "depends on"; break;
  2267. + case WHATCONFLICTS: rel_str = "conflicts with"; break;
  2268. + case WHATSUGGESTS: rel_str = "suggests"; break;
  2269. + case WHATRECOMMENDS: rel_str = "recommends"; break;
  2270. + case WHATPROVIDES: rel_str = "provides"; break;
  2271. + case WHATREPLACES: rel_str = "replaces"; break;
  2272. + }
  2273. +
  2274. + if (conf->query_all)
  2275. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2276. + else
  2277. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2278. +
  2279. + /* mark the root set */
  2280. + pkg_vec_clear_marks(available_pkgs);
  2281. + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
  2282. + for (i = 0; i < argc; i++) {
  2283. + const char *dependee_pattern = argv[i];
  2284. + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
  2285. + }
  2286. + for (i = 0; i < available_pkgs->len; i++) {
  2287. + pkg_t *pkg = available_pkgs->pkgs[i];
  2288. + if (pkg->state_flag & SF_MARKED) {
  2289. + /* mark the parent (abstract) package */
  2290. + pkg_mark_provides(pkg);
  2291. + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
  2292. + }
  2293. + }
  2294. +
  2295. + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
  2296. + do {
  2297. + int j;
  2298. + changed = 0;
  2299. +
  2300. + for (j = 0; j < available_pkgs->len; j++) {
  2301. + pkg_t *pkg = available_pkgs->pkgs[j];
  2302. + int k;
  2303. + int count = ((what_field_type == WHATCONFLICTS)
  2304. + ? pkg->conflicts_count
  2305. + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
  2306. + /* skip this package if it is already marked */
  2307. + if (pkg->parent->state_flag & SF_MARKED) {
  2308. + continue;
  2309. + }
  2310. + for (k = 0; k < count; k++) {
  2311. + compound_depend_t *cdepend =
  2312. + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
  2313. + int l;
  2314. + for (l = 0; l < cdepend->possibility_count; l++) {
  2315. + depend_t *possibility = cdepend->possibilities[l];
  2316. + if (possibility->pkg->state_flag & SF_MARKED) {
  2317. + /* mark the depending package so we won't visit it again */
  2318. + pkg->state_flag |= SF_MARKED;
  2319. + pkg_mark_provides(pkg);
  2320. + changed++;
  2321. +
  2322. + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
  2323. + if (conf->verbosity > 0) {
  2324. + char *ver = pkg_version_str_alloc(pkg);
  2325. + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
  2326. + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
  2327. + if (possibility->version) {
  2328. + const char *typestr = NULL;
  2329. + switch (possibility->constraint) {
  2330. + case NONE: typestr = "none"; break;
  2331. + case EARLIER: typestr = "<"; break;
  2332. + case EARLIER_EQUAL: typestr = "<="; break;
  2333. + case EQUAL: typestr = "="; break;
  2334. + case LATER_EQUAL: typestr = ">="; break;
  2335. + case LATER: typestr = ">"; break;
  2336. + }
  2337. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2338. + }
  2339. + free(ver);
  2340. + if (!pkg_dependence_satisfiable(possibility))
  2341. + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
  2342. + }
  2343. + ipkg_message(conf, IPKG_NOTICE, "\n");
  2344. + goto next_package;
  2345. + }
  2346. + }
  2347. + }
  2348. + next_package:
  2349. + ;
  2350. + }
  2351. + } while (changed && recursive);
  2352. + pkg_vec_free(available_pkgs);
  2353. + }
  2354. +
  2355. + return 0;
  2356. +}
  2357. +
  2358. +int pkg_mark_provides(pkg_t *pkg)
  2359. +{
  2360. + int provides_count = pkg->provides_count;
  2361. + abstract_pkg_t **provides = pkg->provides;
  2362. + int i;
  2363. + pkg->parent->state_flag |= SF_MARKED;
  2364. + for (i = 0; i < provides_count; i++) {
  2365. + provides[i]->state_flag |= SF_MARKED;
  2366. + }
  2367. + return 0;
  2368. +}
  2369. +
  2370. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2371. +{
  2372. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
  2373. +}
  2374. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2375. +{
  2376. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
  2377. +}
  2378. +
  2379. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2380. +{
  2381. + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
  2382. +}
  2383. +
  2384. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2385. +{
  2386. + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
  2387. +}
  2388. +
  2389. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2390. +{
  2391. + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
  2392. +}
  2393. +
  2394. +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
  2395. +{
  2396. +
  2397. + if (argc > 0) {
  2398. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2399. + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
  2400. + int i;
  2401. +
  2402. + pkg_info_preinstall_check(conf);
  2403. +
  2404. + if (conf->query_all)
  2405. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2406. + else
  2407. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2408. + for (i = 0; i < argc; i++) {
  2409. + const char *target = argv[i];
  2410. + int j;
  2411. +
  2412. + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
  2413. + rel_str, target);
  2414. + for (j = 0; j < available_pkgs->len; j++) {
  2415. + pkg_t *pkg = available_pkgs->pkgs[j];
  2416. + int k;
  2417. + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
  2418. + for (k = 0; k < count; k++) {
  2419. + abstract_pkg_t *apkg =
  2420. + ((what_field_type == WHATPROVIDES)
  2421. + ? pkg->provides[k]
  2422. + : pkg->replaces[k]);
  2423. + if (fnmatch(target, apkg->name, 0) == 0) {
  2424. + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
  2425. + if (strcmp(target, apkg->name) != 0)
  2426. + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
  2427. + ipkg_message(conf, IPKG_ERROR, "\n");
  2428. + }
  2429. + }
  2430. + }
  2431. + }
  2432. + pkg_vec_free(available_pkgs);
  2433. + }
  2434. + return 0;
  2435. +}
  2436. +
  2437. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2438. +{
  2439. + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
  2440. +}
  2441. +
  2442. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2443. +{
  2444. + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
  2445. +}
  2446. +
  2447. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2448. +{
  2449. + int i;
  2450. +
  2451. + pkg_vec_t *installed;
  2452. + pkg_t *pkg;
  2453. + str_list_t *installed_files;
  2454. + str_list_elt_t *iter;
  2455. + char *installed_file;
  2456. +
  2457. + if (argc < 1) {
  2458. + return EINVAL;
  2459. + }
  2460. +
  2461. + installed = pkg_vec_alloc();
  2462. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  2463. +
  2464. + for (i=0; i < installed->len; i++) {
  2465. + pkg = installed->pkgs[i];
  2466. +
  2467. + installed_files = pkg_get_installed_files(pkg);
  2468. +
  2469. + for (iter = installed_files->head; iter; iter = iter->next) {
  2470. + installed_file = iter->data;
  2471. + if (fnmatch(argv[0], installed_file, 0)==0) {
  2472. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2473. + installed_file,
  2474. + pkg_version_str_alloc(pkg),
  2475. + pkg->state_status, p_userdata);
  2476. + }
  2477. + }
  2478. +
  2479. + pkg_free_installed_files(pkg);
  2480. + }
  2481. +
  2482. + /* XXX: CLEANUP: It's not obvious from the name of
  2483. + pkg_hash_fetch_all_installed that we need to call
  2484. + pkg_vec_free to avoid a memory leak. */
  2485. + pkg_vec_free(installed);
  2486. +
  2487. + return 0;
  2488. +}
  2489. +
  2490. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2491. +{
  2492. + if (argc == 3) {
  2493. + /* this is a bit gross */
  2494. + struct pkg p1, p2;
  2495. + parseVersion(&p1, argv[0]);
  2496. + parseVersion(&p2, argv[2]);
  2497. + return pkg_version_satisfied(&p1, &p2, argv[1]);
  2498. + } else {
  2499. + ipkg_message(conf, IPKG_ERROR,
  2500. + "ipkg compare_versions <v1> <op> <v2>\n"
  2501. + "<op> is one of <= >= << >> =\n");
  2502. + return -1;
  2503. + }
  2504. +}
  2505. +
  2506. +#ifndef HOST_CPU_STR
  2507. +#define HOST_CPU_STR__(X) #X
  2508. +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
  2509. +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
  2510. +#endif
  2511. +
  2512. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf)
  2513. +{
  2514. + nv_pair_list_elt_t *l;
  2515. +
  2516. + l = conf->arch_list.head;
  2517. + while (l) {
  2518. + nv_pair_t *nv = l->data;
  2519. + printf("arch %s %s\n", nv->name, nv->value);
  2520. + l = l->next;
  2521. + }
  2522. + return 0;
  2523. +}
  2524. +
  2525. +
  2526. diff -Nur busybox-1.22.1.orig/archival/libipkg/ipkg_cmd.h busybox-1.22.1/archival/libipkg/ipkg_cmd.h
  2527. --- busybox-1.22.1.orig/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
  2528. +++ busybox-1.22.1/archival/libipkg/ipkg_cmd.h 2014-05-23 21:12:06.000000000 +0200
  2529. @@ -0,0 +1,41 @@
  2530. +/* ipkg_cmd.h - the itsy package management system
  2531. +
  2532. + Carl D. Worth
  2533. +
  2534. + Copyright (C) 2001 University of Southern California
  2535. +
  2536. + This program is free software; you can redistribute it and/or
  2537. + modify it under the terms of the GNU General Public License as
  2538. + published by the Free Software Foundation; either version 2, or (at
  2539. + your option) any later version.
  2540. +
  2541. + This program is distributed in the hope that it will be useful, but
  2542. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2543. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2544. + General Public License for more details.
  2545. +*/
  2546. +
  2547. +#ifndef IPKG_CMD_H
  2548. +#define IPKG_CMD_H
  2549. +
  2550. +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
  2551. +
  2552. +struct ipkg_cmd
  2553. +{
  2554. + const char *name;
  2555. + int requires_args;
  2556. + ipkg_cmd_fun_t fun;
  2557. +};
  2558. +typedef struct ipkg_cmd ipkg_cmd_t;
  2559. +
  2560. +ipkg_cmd_t *ipkg_cmd_find(const char *name);
  2561. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
  2562. + const char **argv, void *userdata);
  2563. +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
  2564. +/* install any packges with state_want == SW_INSTALL */
  2565. +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
  2566. +/* ensure that all dependences are satisfied */
  2567. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
  2568. +int pkg_mark_provides(pkg_t *pkg);
  2569. +
  2570. +#endif
  2571. diff -Nur busybox-1.22.1.orig/archival/libipkg/ipkg_conf.c busybox-1.22.1/archival/libipkg/ipkg_conf.c
  2572. --- busybox-1.22.1.orig/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
  2573. +++ busybox-1.22.1/archival/libipkg/ipkg_conf.c 2014-05-23 21:12:06.000000000 +0200
  2574. @@ -0,0 +1,739 @@
  2575. +/* ipkg_conf.c - the itsy package management system
  2576. +
  2577. + Carl D. Worth
  2578. +
  2579. + Copyright (C) 2001 University of Southern California
  2580. +
  2581. + This program is free software; you can redistribute it and/or
  2582. + modify it under the terms of the GNU General Public License as
  2583. + published by the Free Software Foundation; either version 2, or (at
  2584. + your option) any later version.
  2585. +
  2586. + This program is distributed in the hope that it will be useful, but
  2587. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2588. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2589. + General Public License for more details.
  2590. +*/
  2591. +
  2592. +#include <glob.h>
  2593. +
  2594. +#include "ipkg.h"
  2595. +#include "ipkg_conf.h"
  2596. +
  2597. +#include "xregex.h"
  2598. +#include "sprintf_alloc.h"
  2599. +#include "ipkg_conf.h"
  2600. +#include "ipkg_message.h"
  2601. +#include "file_util.h"
  2602. +#include "str_util.h"
  2603. +#include "xsystem.h"
  2604. +
  2605. +
  2606. +ipkg_conf_t *global_conf;
  2607. +
  2608. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2609. + pkg_src_list_t *pkg_src_list,
  2610. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2611. + char **tmp_lists_dir);
  2612. +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
  2613. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  2614. + const char *name, const char *value);
  2615. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2616. + const char *default_dest_name);
  2617. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
  2618. + pkg_src_list_t *nv_pair_list);
  2619. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
  2620. + nv_pair_list_t *nv_pair_list, char * lists_dir);
  2621. +
  2622. +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
  2623. +{
  2624. + ipkg_option_t tmp[] = {
  2625. + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
  2626. + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
  2627. + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
  2628. + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
  2629. + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
  2630. + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
  2631. + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
  2632. + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
  2633. + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
  2634. + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
  2635. + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
  2636. + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
  2637. + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
  2638. + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
  2639. + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
  2640. + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
  2641. + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
  2642. + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
  2643. + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
  2644. + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
  2645. + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
  2646. + { NULL }
  2647. + };
  2648. +
  2649. + *options = (ipkg_option_t *)malloc(sizeof(tmp));
  2650. + if ( options == NULL ){
  2651. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  2652. + return -1;
  2653. + }
  2654. +
  2655. + memcpy(*options, tmp, sizeof(tmp));
  2656. + return 0;
  2657. +};
  2658. +
  2659. +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
  2660. +{
  2661. + if (arg_str) {
  2662. + if (*conf_str) {
  2663. + free(*conf_str);
  2664. + }
  2665. + *conf_str = strdup(arg_str);
  2666. + }
  2667. +}
  2668. +
  2669. +static void ipkg_conf_free_string(char **conf_str)
  2670. +{
  2671. + if (*conf_str) {
  2672. + free(*conf_str);
  2673. + *conf_str = NULL;
  2674. + }
  2675. +}
  2676. +
  2677. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
  2678. +{
  2679. + int err;
  2680. + int remountroot;
  2681. + struct mntent *mnt;
  2682. + FILE *f;
  2683. + char *tmp_dir_base;
  2684. + nv_pair_list_t tmp_dest_nv_pair_list;
  2685. + char * lists_dir =NULL;
  2686. + glob_t globbuf;
  2687. + const char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
  2688. + char *pending_dir =NULL;
  2689. +
  2690. + memset(conf, 0, sizeof(ipkg_conf_t));
  2691. +
  2692. + pkg_src_list_init(&conf->pkg_src_list);
  2693. +
  2694. + nv_pair_list_init(&tmp_dest_nv_pair_list);
  2695. + pkg_dest_list_init(&conf->pkg_dest_list);
  2696. +
  2697. + nv_pair_list_init(&conf->arch_list);
  2698. +
  2699. + conf->restrict_to_default_dest = 0;
  2700. + conf->default_dest = NULL;
  2701. +
  2702. +
  2703. + if (args->tmp_dir)
  2704. + tmp_dir_base = args->tmp_dir;
  2705. + else
  2706. + tmp_dir_base = getenv("IPKGTMPDIR");
  2707. + sprintf_alloc(&conf->tmp_dir, "%s/%s",
  2708. + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
  2709. + IPKG_CONF_TMP_DIR_SUFFIX);
  2710. +
  2711. + remountroot = 0;
  2712. + /* check if /dev/root is mounted read-only */
  2713. + if ((f = setmntent("/proc/mounts", "r")) == NULL)
  2714. + fprintf (stderr, "Checking /proc/mounts failed\n");
  2715. + while ((mnt = getmntent(f)) != NULL) {
  2716. + if (strcmp(mnt->mnt_fsname, "/dev/root") == 0 &&
  2717. + hasmntopt(mnt, MNTOPT_RO) != NULL) {
  2718. + remountroot = 1;
  2719. + }
  2720. + }
  2721. + endmntent(f);
  2722. +
  2723. + if (remountroot) {
  2724. + /* mount rootfs read-write */
  2725. + if (mount("","/",0,MS_REMOUNT,0)<0)
  2726. + fprintf (stderr, "Mounting rootfs read-write failed\n");
  2727. + }
  2728. + mkdir(tmp_dir_base, S_IRWXU);
  2729. + conf->tmp_dir = mkdtemp(conf->tmp_dir);
  2730. + if (conf->tmp_dir == NULL) {
  2731. + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
  2732. + __FUNCTION__, conf->tmp_dir, strerror(errno));
  2733. + return errno;
  2734. + }
  2735. + if (remountroot) {
  2736. + sync();
  2737. + /* mount rootfs read-only */
  2738. + if (mount("","/",0,MS_REMOUNT|MS_RDONLY,0)<0)
  2739. + fprintf (stderr, "Mounting rootfs read-only failed\n");
  2740. + }
  2741. +
  2742. + conf->force_depends = 0;
  2743. + conf->force_defaults = 0;
  2744. + conf->force_overwrite = 0;
  2745. + conf->force_downgrade = 0;
  2746. + conf->force_reinstall = 0;
  2747. + conf->force_space = 0;
  2748. + conf->force_removal_of_essential_packages = 0;
  2749. + conf->force_removal_of_dependent_packages = 0;
  2750. + conf->nodeps = 0;
  2751. + conf->verbose_wget = 0;
  2752. + conf->offline_root = NULL;
  2753. + conf->offline_root_pre_script_cmd = NULL;
  2754. + conf->offline_root_post_script_cmd = NULL;
  2755. + conf->multiple_providers = 0;
  2756. + conf->verbosity = 1;
  2757. + conf->noaction = 0;
  2758. +
  2759. + conf->http_proxy = NULL;
  2760. + conf->ftp_proxy = NULL;
  2761. + conf->no_proxy = NULL;
  2762. + conf->proxy_user = NULL;
  2763. + conf->proxy_passwd = NULL;
  2764. +
  2765. + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2766. + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2767. + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2768. + lists_dir=(char *)malloc(1);
  2769. + lists_dir[0]='\0';
  2770. + if (args->conf_file) {
  2771. + struct stat stat_buf;
  2772. + err = stat(args->conf_file, &stat_buf);
  2773. + if (err == 0)
  2774. + if (ipkg_conf_parse_file(conf, args->conf_file,
  2775. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2776. + /* Memory leakage from ipkg_conf_parse-file */
  2777. + return -1;
  2778. + }
  2779. +
  2780. + }
  2781. +
  2782. + /* if (!lists_dir ){*/
  2783. + if (strlen(lists_dir)<=1 ){
  2784. + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
  2785. + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
  2786. + }
  2787. +
  2788. + if (args->offline_root) {
  2789. + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
  2790. + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
  2791. + free(lists_dir);
  2792. + lists_dir = tmp;
  2793. + }
  2794. +
  2795. + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
  2796. + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
  2797. +
  2798. + conf->lists_dir = strdup(lists_dir);
  2799. + conf->pending_dir = strdup(pending_dir);
  2800. +
  2801. + if (args->offline_root)
  2802. + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
  2803. + memset(&globbuf, 0, sizeof(globbuf));
  2804. + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
  2805. + if (!err) {
  2806. + int i;
  2807. + for (i = 0; i < globbuf.gl_pathc; i++) {
  2808. + if (globbuf.gl_pathv[i])
  2809. + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
  2810. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2811. + /* Memory leakage from ipkg_conf_parse-file */
  2812. + return -1;
  2813. + }
  2814. + }
  2815. + }
  2816. + globfree(&globbuf);
  2817. +
  2818. + /* if no architectures were defined, then default all, noarch, and host architecture */
  2819. + if (nv_pair_list_empty(&conf->arch_list)) {
  2820. + nv_pair_list_append(&conf->arch_list, "all", "1");
  2821. + nv_pair_list_append(&conf->arch_list, "noarch", "1");
  2822. + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
  2823. + }
  2824. +
  2825. + /* Even if there is no conf file, we'll need at least one dest. */
  2826. + if (tmp_dest_nv_pair_list.head == NULL) {
  2827. + nv_pair_list_append(&tmp_dest_nv_pair_list,
  2828. + IPKG_CONF_DEFAULT_DEST_NAME,
  2829. + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
  2830. + }
  2831. +
  2832. + /* After parsing the file, set options from command-line, (so that
  2833. + command-line arguments take precedence) */
  2834. + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
  2835. + really needs to be cleaned up. There is so much duplication
  2836. + right now it is ridiculous. Maybe ipkg_conf_t should just save
  2837. + a pointer to args_t (which could then not be freed), rather
  2838. + than duplicating every field here? */
  2839. + if (args->force_depends) {
  2840. + conf->force_depends = 1;
  2841. + }
  2842. + if (args->force_defaults) {
  2843. + conf->force_defaults = 1;
  2844. + }
  2845. + if (args->force_overwrite) {
  2846. + conf->force_overwrite = 1;
  2847. + }
  2848. + if (args->force_downgrade) {
  2849. + conf->force_downgrade = 1;
  2850. + }
  2851. + if (args->force_reinstall) {
  2852. + conf->force_reinstall = 1;
  2853. + }
  2854. + if (args->force_removal_of_dependent_packages) {
  2855. + conf->force_removal_of_dependent_packages = 1;
  2856. + }
  2857. + if (args->force_removal_of_essential_packages) {
  2858. + conf->force_removal_of_essential_packages = 1;
  2859. + }
  2860. + if (args->nodeps) {
  2861. + conf->nodeps = 1;
  2862. + }
  2863. + if (args->noaction) {
  2864. + conf->noaction = 1;
  2865. + }
  2866. + if (args->query_all) {
  2867. + conf->query_all = 1;
  2868. + }
  2869. + if (args->verbose_wget) {
  2870. + conf->verbose_wget = 1;
  2871. + }
  2872. + if (args->multiple_providers) {
  2873. + conf->multiple_providers = 1;
  2874. + }
  2875. + if (args->verbosity != conf->verbosity) {
  2876. + conf->verbosity = args->verbosity;
  2877. + }
  2878. +
  2879. + ipkg_conf_override_string(&conf->offline_root,
  2880. + args->offline_root);
  2881. + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
  2882. + args->offline_root_pre_script_cmd);
  2883. + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
  2884. + args->offline_root_post_script_cmd);
  2885. +
  2886. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  2887. + read anything from there.
  2888. +*/
  2889. + if ( !(args->nocheckfordirorfile)){
  2890. + /* need to run load the source list before dest list -Jamey */
  2891. + if ( !(args->noreadfeedsfile))
  2892. + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
  2893. +
  2894. + /* Now that we have resolved conf->offline_root, we can commit to
  2895. + the directory names for the dests and load in all the package
  2896. + lists. */
  2897. + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
  2898. +
  2899. + if (args->dest) {
  2900. + err = ipkg_conf_set_default_dest(conf, args->dest);
  2901. + if (err) {
  2902. + return err;
  2903. + }
  2904. + }
  2905. + }
  2906. + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
  2907. + free(lists_dir);
  2908. + free(pending_dir);
  2909. +
  2910. + return 0;
  2911. +}
  2912. +
  2913. +void ipkg_conf_deinit(ipkg_conf_t *conf)
  2914. +{
  2915. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  2916. +#error
  2917. + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
  2918. + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  2919. + __FUNCTION__, conf->tmp_dir);
  2920. +#else
  2921. + int err;
  2922. +
  2923. + err = rmdir(conf->tmp_dir);
  2924. + if (err) {
  2925. + if (errno == ENOTEMPTY) {
  2926. + char *cmd;
  2927. + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
  2928. + err = xsystem(cmd);
  2929. + free(cmd);
  2930. + }
  2931. + if (err)
  2932. + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
  2933. + }
  2934. +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
  2935. +
  2936. + free(conf->tmp_dir); /*XXX*/
  2937. +
  2938. + pkg_src_list_deinit(&conf->pkg_src_list);
  2939. + pkg_dest_list_deinit(&conf->pkg_dest_list);
  2940. + nv_pair_list_deinit(&conf->arch_list);
  2941. + if (&conf->pkg_hash)
  2942. + pkg_hash_deinit(&conf->pkg_hash);
  2943. + if (&conf->file_hash)
  2944. + hash_table_deinit(&conf->file_hash);
  2945. + if (&conf->obs_file_hash)
  2946. + hash_table_deinit(&conf->obs_file_hash);
  2947. +
  2948. + ipkg_conf_free_string(&conf->offline_root);
  2949. + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
  2950. + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
  2951. +
  2952. + if (conf->verbosity > 1) {
  2953. + int i;
  2954. + hash_table_t *hashes[] = {
  2955. + &conf->pkg_hash,
  2956. + &conf->file_hash,
  2957. + &conf->obs_file_hash };
  2958. + for (i = 0; i < 3; i++) {
  2959. + hash_table_t *hash = hashes[i];
  2960. + int c = 0;
  2961. + int n_conflicts = 0;
  2962. + int j;
  2963. + for (j = 0; j < hash->n_entries; j++) {
  2964. + int len = 0;
  2965. + hash_entry_t *e = &hash->entries[j];
  2966. + if (e->next)
  2967. + n_conflicts++;
  2968. + while (e && e->key) {
  2969. + len++;
  2970. + e = e->next;
  2971. + }
  2972. + if (len > c)
  2973. + c = len;
  2974. + }
  2975. + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
  2976. + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
  2977. + hash_table_deinit(hash);
  2978. + }
  2979. + }
  2980. +}
  2981. +
  2982. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2983. + const char *default_dest_name)
  2984. +{
  2985. + pkg_dest_list_elt_t *iter;
  2986. + pkg_dest_t *dest;
  2987. +
  2988. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  2989. + dest = iter->data;
  2990. + if (strcmp(dest->name, default_dest_name) == 0) {
  2991. + conf->default_dest = dest;
  2992. + conf->restrict_to_default_dest = 1;
  2993. + return 0;
  2994. + }
  2995. + }
  2996. +
  2997. + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
  2998. +
  2999. + return 1;
  3000. +}
  3001. +
  3002. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
  3003. +{
  3004. + pkg_src_list_elt_t *iter;
  3005. + pkg_src_t *src;
  3006. + char *list_file;
  3007. +
  3008. + for (iter = pkg_src_list->head; iter; iter = iter->next) {
  3009. + src = iter->data;
  3010. + if (src == NULL) {
  3011. + continue;
  3012. + }
  3013. +
  3014. + sprintf_alloc(&list_file, "%s/%s",
  3015. + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
  3016. + src->name);
  3017. +
  3018. + if (file_exists(list_file)) {
  3019. + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
  3020. + }
  3021. + free(list_file);
  3022. + }
  3023. +
  3024. + return 0;
  3025. +}
  3026. +
  3027. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
  3028. +{
  3029. + nv_pair_list_elt_t *iter;
  3030. + nv_pair_t *nv_pair;
  3031. + pkg_dest_t *dest;
  3032. + char *root_dir;
  3033. +
  3034. + for (iter = nv_pair_list->head; iter; iter = iter->next) {
  3035. + nv_pair = iter->data;
  3036. +
  3037. + if (conf->offline_root) {
  3038. + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
  3039. + } else {
  3040. + root_dir = strdup(nv_pair->value);
  3041. + }
  3042. + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
  3043. + free(root_dir);
  3044. + if (dest == NULL) {
  3045. + continue;
  3046. + }
  3047. + if (conf->default_dest == NULL) {
  3048. + conf->default_dest = dest;
  3049. + }
  3050. + if (file_exists(dest->status_file_name)) {
  3051. + pkg_hash_add_from_file(conf, dest->status_file_name,
  3052. + NULL, dest, 1);
  3053. + }
  3054. + }
  3055. +
  3056. + return 0;
  3057. +}
  3058. +
  3059. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  3060. + pkg_src_list_t *pkg_src_list,
  3061. + nv_pair_list_t *tmp_dest_nv_pair_list,
  3062. + char **lists_dir)
  3063. +{
  3064. + ipkg_option_t * options;
  3065. + FILE *file = fopen(filename, "r");
  3066. + regex_t valid_line_re, comment_re;
  3067. +#define regmatch_size 12
  3068. + regmatch_t regmatch[regmatch_size];
  3069. +
  3070. + if (ipkg_init_options_array(conf, &options)<0)
  3071. + return ENOMEM;
  3072. +
  3073. + if (file == NULL) {
  3074. + fprintf(stderr, "%s: failed to open %s: %s\n",
  3075. + __FUNCTION__, filename, strerror(errno));
  3076. + free(options);
  3077. + return errno;
  3078. + }
  3079. + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
  3080. +
  3081. + xregcomp(&comment_re,
  3082. + "^[[:space:]]*(#.*|[[:space:]]*)$",
  3083. + REG_EXTENDED);
  3084. + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
  3085. +
  3086. + while(1) {
  3087. + int line_num = 0;
  3088. + char *line;
  3089. + char *type, *name, *value, *extra;
  3090. +
  3091. + line = file_read_line_alloc(file);
  3092. + line_num++;
  3093. + if (line == NULL) {
  3094. + break;
  3095. + }
  3096. +
  3097. + str_chomp(line);
  3098. +
  3099. + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
  3100. + goto NEXT_LINE;
  3101. + }
  3102. +
  3103. + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
  3104. + str_chomp(line);
  3105. + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
  3106. + filename, line_num, line);
  3107. + goto NEXT_LINE;
  3108. + }
  3109. +
  3110. + /* This has to be so ugly to deal with optional quotation marks */
  3111. + if (regmatch[2].rm_so > 0) {
  3112. + type = strndup(line + regmatch[2].rm_so,
  3113. + regmatch[2].rm_eo - regmatch[2].rm_so);
  3114. + } else {
  3115. + type = strndup(line + regmatch[3].rm_so,
  3116. + regmatch[3].rm_eo - regmatch[3].rm_so);
  3117. + }
  3118. + if (regmatch[5].rm_so > 0) {
  3119. + name = strndup(line + regmatch[5].rm_so,
  3120. + regmatch[5].rm_eo - regmatch[5].rm_so);
  3121. + } else {
  3122. + name = strndup(line + regmatch[6].rm_so,
  3123. + regmatch[6].rm_eo - regmatch[6].rm_so);
  3124. + }
  3125. + if (regmatch[8].rm_so > 0) {
  3126. + value = strndup(line + regmatch[8].rm_so,
  3127. + regmatch[8].rm_eo - regmatch[8].rm_so);
  3128. + } else {
  3129. + value = strndup(line + regmatch[9].rm_so,
  3130. + regmatch[9].rm_eo - regmatch[9].rm_so);
  3131. + }
  3132. + extra = NULL;
  3133. + if (regmatch[11].rm_so > 0) {
  3134. + extra = strndup (line + regmatch[11].rm_so,
  3135. + regmatch[11].rm_eo - regmatch[11].rm_so);
  3136. + }
  3137. +
  3138. + /* We use the tmp_dest_nv_pair_list below instead of
  3139. + conf->pkg_dest_list because we might encounter an
  3140. + offline_root option later and that would invalidate the
  3141. + directories we would have computed in
  3142. + pkg_dest_list_init. (We do a similar thing with
  3143. + tmp_src_nv_pair_list for sake of symmetry.) */
  3144. + if (strcmp(type, "option") == 0) {
  3145. + ipkg_conf_set_option(options, name, value);
  3146. + } else if (strcmp(type, "src") == 0) {
  3147. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3148. + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
  3149. + } else {
  3150. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3151. + name, value);
  3152. + }
  3153. + } else if (strcmp(type, "src/gz") == 0) {
  3154. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3155. + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
  3156. + } else {
  3157. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3158. + name, value);
  3159. + }
  3160. + } else if (strcmp(type, "dest") == 0) {
  3161. + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
  3162. + } else if (strcmp(type, "lists_dir") == 0) {
  3163. + *lists_dir = realloc(*lists_dir,strlen(value)+1);
  3164. + if (*lists_dir == NULL) {
  3165. + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
  3166. + free(options);
  3167. + return EINVAL;
  3168. + }
  3169. + sprintf (*lists_dir,"%s",value);
  3170. + } else if (strcmp(type, "arch") == 0) {
  3171. + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
  3172. + if (!value) {
  3173. + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
  3174. + value = strdup("10");
  3175. + }
  3176. + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
  3177. + } else {
  3178. + fprintf(stderr, "WARNING: Ignoring unknown configuration "
  3179. + "parameter: %s %s %s\n", type, name, value);
  3180. + free(options);
  3181. + return EINVAL;
  3182. + }
  3183. +
  3184. + free(type);
  3185. + free(name);
  3186. + free(value);
  3187. + if (extra)
  3188. + free (extra);
  3189. +
  3190. + NEXT_LINE:
  3191. + free(line);
  3192. + }
  3193. +
  3194. + free(options);
  3195. + regfree(&comment_re);
  3196. + regfree(&valid_line_re);
  3197. + fclose(file);
  3198. +
  3199. + return 0;
  3200. +}
  3201. +
  3202. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  3203. + const char *name, const char *value)
  3204. +{
  3205. + int i = 0;
  3206. + while (options[i].name) {
  3207. + if (strcmp(options[i].name, name) == 0) {
  3208. + switch (options[i].type) {
  3209. + case IPKG_OPT_TYPE_BOOL:
  3210. + *((int *)options[i].value) = 1;
  3211. + return 0;
  3212. + case IPKG_OPT_TYPE_INT:
  3213. + if (value) {
  3214. + *((int *)options[i].value) = atoi(value);
  3215. + return 0;
  3216. + } else {
  3217. + printf("%s: Option %s need an argument\n",
  3218. + __FUNCTION__, name);
  3219. + return EINVAL;
  3220. + }
  3221. + case IPKG_OPT_TYPE_STRING:
  3222. + if (value) {
  3223. + *((char **)options[i].value) = strdup(value);
  3224. + return 0;
  3225. + } else {
  3226. + printf("%s: Option %s need an argument\n",
  3227. + __FUNCTION__, name);
  3228. + return EINVAL;
  3229. + }
  3230. + }
  3231. + }
  3232. + i++;
  3233. + }
  3234. +
  3235. + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
  3236. + __FUNCTION__, name, value);
  3237. + return EINVAL;
  3238. +}
  3239. +
  3240. +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
  3241. +{
  3242. + pkg_dest_list_elt_t *iter;
  3243. + pkg_dest_t *dest;
  3244. + pkg_vec_t *all;
  3245. + pkg_t *pkg;
  3246. + register int i;
  3247. + int err;
  3248. +
  3249. + if (conf->noaction)
  3250. + return 0;
  3251. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3252. + dest = iter->data;
  3253. + dest->status_file = fopen(dest->status_file_tmp_name, "w");
  3254. + if (dest->status_file == NULL) {
  3255. + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
  3256. + __FUNCTION__, dest->status_file_name, strerror(errno));
  3257. + }
  3258. + }
  3259. +
  3260. + all = pkg_vec_alloc();
  3261. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  3262. +
  3263. + for(i = 0; i < all->len; i++) {
  3264. + pkg = all->pkgs[i];
  3265. + /* We don't need most uninstalled packages in the status file */
  3266. + if (pkg->state_status == SS_NOT_INSTALLED
  3267. + && (pkg->state_want == SW_UNKNOWN
  3268. + || pkg->state_want == SW_DEINSTALL
  3269. + || pkg->state_want == SW_PURGE)) {
  3270. + continue;
  3271. + }
  3272. + if (!pkg) {
  3273. + fprintf(stderr, "Null package\n");
  3274. + }
  3275. + if (pkg->dest == NULL) {
  3276. + fprintf(stderr, "%s: ERROR: Can't write status for "
  3277. + "package %s since it has a NULL dest\n",
  3278. + __FUNCTION__, pkg->name);
  3279. + continue;
  3280. + }
  3281. + if (pkg->dest->status_file) {
  3282. + pkg_print_status(pkg, pkg->dest->status_file);
  3283. + }
  3284. + }
  3285. +
  3286. + pkg_vec_free(all);
  3287. +
  3288. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3289. + dest = iter->data;
  3290. + if (dest->status_file) {
  3291. + err = ferror(dest->status_file);
  3292. + fclose(dest->status_file);
  3293. + dest->status_file = NULL;
  3294. + if (!err) {
  3295. + file_move(dest->status_file_tmp_name, dest->status_file_name);
  3296. + } else {
  3297. + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
  3298. + "retaining old %s\n", __FUNCTION__,
  3299. + dest->status_file_tmp_name, dest->status_file_name);
  3300. + }
  3301. + }
  3302. + }
  3303. +
  3304. + return 0;
  3305. +}
  3306. +
  3307. +
  3308. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
  3309. +{
  3310. + char *root_filename;
  3311. + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
  3312. + return root_filename;
  3313. +}
  3314. diff -Nur busybox-1.22.1.orig/archival/libipkg/ipkg_conf.h busybox-1.22.1/archival/libipkg/ipkg_conf.h
  3315. --- busybox-1.22.1.orig/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
  3316. +++ busybox-1.22.1/archival/libipkg/ipkg_conf.h 2014-05-23 21:12:06.000000000 +0200
  3317. @@ -0,0 +1,107 @@
  3318. +/* ipkg_conf.h - the itsy package management system
  3319. +
  3320. + Carl D. Worth
  3321. +
  3322. + Copyright (C) 2001 University of Southern California
  3323. +
  3324. + This program is free software; you can redistribute it and/or
  3325. + modify it under the terms of the GNU General Public License as
  3326. + published by the Free Software Foundation; either version 2, or (at
  3327. + your option) any later version.
  3328. +
  3329. + This program is distributed in the hope that it will be useful, but
  3330. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3331. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3332. + General Public License for more details.
  3333. +*/
  3334. +
  3335. +#ifndef IPKG_CONF_H
  3336. +#define IPKG_CONF_H
  3337. +
  3338. +typedef struct ipkg_conf ipkg_conf_t;
  3339. +
  3340. +#include "hash_table.h"
  3341. +#include "ipkg.h"
  3342. +#include "args.h"
  3343. +#include "pkg.h"
  3344. +#include "pkg_hash.h"
  3345. +#include "pkg_src_list.h"
  3346. +#include "pkg_dest_list.h"
  3347. +#include "nv_pair_list.h"
  3348. +
  3349. +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
  3350. +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
  3351. +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
  3352. +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
  3353. +
  3354. +/* In case the config file defines no dest */
  3355. +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
  3356. +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
  3357. +
  3358. +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
  3359. +
  3360. +struct ipkg_conf
  3361. +{
  3362. + pkg_src_list_t pkg_src_list;
  3363. + pkg_dest_list_t pkg_dest_list;
  3364. + nv_pair_list_t arch_list;
  3365. +
  3366. + int restrict_to_default_dest;
  3367. + pkg_dest_t *default_dest;
  3368. +
  3369. + char *tmp_dir;
  3370. + char *lists_dir;
  3371. + char *pending_dir;
  3372. +
  3373. + /* options */
  3374. + int force_depends;
  3375. + int force_defaults;
  3376. + int force_overwrite;
  3377. + int force_downgrade;
  3378. + int force_reinstall;
  3379. + int force_space;
  3380. + int force_removal_of_dependent_packages;
  3381. + int force_removal_of_essential_packages;
  3382. + int nodeps; /* do not follow dependences */
  3383. + int verbose_wget;
  3384. + int multiple_providers;
  3385. + char *offline_root;
  3386. + char *offline_root_pre_script_cmd;
  3387. + char *offline_root_post_script_cmd;
  3388. + int query_all;
  3389. + int verbosity;
  3390. + int noaction;
  3391. +
  3392. + /* proxy options */
  3393. + char *http_proxy;
  3394. + char *ftp_proxy;
  3395. + char *no_proxy;
  3396. + char *proxy_user;
  3397. + char *proxy_passwd;
  3398. +
  3399. + hash_table_t pkg_hash;
  3400. + hash_table_t file_hash;
  3401. + hash_table_t obs_file_hash;
  3402. +};
  3403. +
  3404. +enum ipkg_option_type {
  3405. + IPKG_OPT_TYPE_BOOL,
  3406. + IPKG_OPT_TYPE_INT,
  3407. + IPKG_OPT_TYPE_STRING
  3408. +};
  3409. +typedef enum ipkg_option_type ipkg_option_type_t;
  3410. +
  3411. +typedef struct ipkg_option ipkg_option_t;
  3412. +struct ipkg_option {
  3413. + const char *name;
  3414. + const ipkg_option_type_t type;
  3415. + const void *value;
  3416. +};
  3417. +
  3418. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
  3419. +void ipkg_conf_deinit(ipkg_conf_t *conf);
  3420. +
  3421. +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
  3422. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
  3423. +
  3424. +#endif
  3425. diff -Nur busybox-1.22.1.orig/archival/libipkg/ipkg_configure.c busybox-1.22.1/archival/libipkg/ipkg_configure.c
  3426. --- busybox-1.22.1.orig/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
  3427. +++ busybox-1.22.1/archival/libipkg/ipkg_configure.c 2014-05-23 21:12:06.000000000 +0200
  3428. @@ -0,0 +1,40 @@
  3429. +/* ipkg_configure.c - the itsy package management system
  3430. +
  3431. + Carl D. Worth
  3432. +
  3433. + Copyright (C) 2001 University of Southern California
  3434. +
  3435. + This program is free software; you can redistribute it and/or
  3436. + modify it under the terms of the GNU General Public License as
  3437. + published by the Free Software Foundation; either version 2, or (at
  3438. + your option) any later version.
  3439. +
  3440. + This program is distributed in the hope that it will be useful, but
  3441. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3442. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3443. + General Public License for more details.
  3444. +*/
  3445. +
  3446. +#include "ipkg.h"
  3447. +
  3448. +#include "ipkg_configure.h"
  3449. +
  3450. +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
  3451. +{
  3452. + int err;
  3453. +
  3454. + /* DPKG_INCOMPATIBILITY:
  3455. + dpkg actually does some conffile handling here, rather than at the
  3456. + end of ipkg_install(). Do we care? */
  3457. + /* DPKG_INCOMPATIBILITY:
  3458. + dpkg actually includes a version number to this script call */
  3459. + err = pkg_run_script(conf, pkg, "postinst", "configure");
  3460. + if (err) {
  3461. + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
  3462. + return err;
  3463. + }
  3464. +
  3465. + ipkg_state_changed++;
  3466. + return 0;
  3467. +}
  3468. +
  3469. diff -Nur busybox-1.22.1.orig/archival/libipkg/ipkg_configure.h busybox-1.22.1/archival/libipkg/ipkg_configure.h
  3470. --- busybox-1.22.1.orig/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
  3471. +++ busybox-1.22.1/archival/libipkg/ipkg_configure.h 2014-05-23 21:12:06.000000000 +0200
  3472. @@ -0,0 +1,25 @@
  3473. +/* ipkg_configure.h - the itsy package management system
  3474. +
  3475. + Carl D. Worth
  3476. +
  3477. + Copyright (C) 2001 University of Southern California
  3478. +
  3479. + This program is free software; you can redistribute it and/or
  3480. + modify it under the terms of the GNU General Public License as
  3481. + published by the Free Software Foundation; either version 2, or (at
  3482. + your option) any later version.
  3483. +
  3484. + This program is distributed in the hope that it will be useful, but
  3485. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3486. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3487. + General Public License for more details.
  3488. +*/
  3489. +
  3490. +#ifndef IPKG_CONFIGURE_H
  3491. +#define IPKG_CONFIGURE_H
  3492. +
  3493. +#include "ipkg_conf.h"
  3494. +
  3495. +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
  3496. +
  3497. +#endif
  3498. diff -Nur busybox-1.22.1.orig/archival/libipkg/ipkg_download.c busybox-1.22.1/archival/libipkg/ipkg_download.c
  3499. --- busybox-1.22.1.orig/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
  3500. +++ busybox-1.22.1/archival/libipkg/ipkg_download.c 2014-05-23 21:12:06.000000000 +0200
  3501. @@ -0,0 +1,195 @@
  3502. +/* ipkg_download.c - the itsy package management system
  3503. +
  3504. + Carl D. Worth
  3505. +
  3506. + Copyright (C) 2001 University of Southern California
  3507. +
  3508. + This program is free software; you can redistribute it and/or
  3509. + modify it under the terms of the GNU General Public License as
  3510. + published by the Free Software Foundation; either version 2, or (at
  3511. + your option) any later version.
  3512. +
  3513. + This program is distributed in the hope that it will be useful, but
  3514. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3515. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3516. + General Public License for more details.
  3517. +*/
  3518. +
  3519. +#include "ipkg.h"
  3520. +#include "ipkg_download.h"
  3521. +#include "ipkg_message.h"
  3522. +
  3523. +#include "sprintf_alloc.h"
  3524. +#include "xsystem.h"
  3525. +#include "file_util.h"
  3526. +#include "str_util.h"
  3527. +
  3528. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
  3529. +{
  3530. + int err = 0;
  3531. +
  3532. + char *src_basec = strdup(src);
  3533. + char *src_base = bb_basename(src_basec);
  3534. + char *tmp_file_location;
  3535. + char *cmd;
  3536. +
  3537. + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
  3538. +
  3539. + fflush(stdout);
  3540. +
  3541. + if (str_starts_with(src, "file:")) {
  3542. + int ret;
  3543. + const char *file_src = src + 5;
  3544. + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
  3545. + ret = file_copy(src + 5, dest_file_name);
  3546. + ipkg_message(conf,IPKG_INFO,"Done.\n");
  3547. + return ret;
  3548. + }
  3549. +
  3550. + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
  3551. + err = unlink(tmp_file_location);
  3552. + if (err && errno != ENOENT) {
  3553. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
  3554. + __FUNCTION__, tmp_file_location, strerror(errno));
  3555. + free(tmp_file_location);
  3556. + return errno;
  3557. + }
  3558. +
  3559. + if (conf->http_proxy) {
  3560. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
  3561. + setenv("http_proxy", conf->http_proxy, 1);
  3562. + }
  3563. + if (conf->ftp_proxy) {
  3564. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
  3565. + setenv("ftp_proxy", conf->ftp_proxy, 1);
  3566. + }
  3567. + if (conf->no_proxy) {
  3568. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
  3569. + setenv("no_proxy", conf->no_proxy, 1);
  3570. + }
  3571. +
  3572. + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
  3573. + sprintf_alloc(&cmd, "wget %s %s%s %s%s %s -P %s %s",
  3574. + (conf->http_proxy || conf->ftp_proxy) ? "-Y on" : "",
  3575. + conf->proxy_user ? "--proxy-user=" : "",
  3576. + conf->proxy_user ? conf->proxy_user : "",
  3577. + conf->proxy_passwd ? "--proxy-passwd=" : "",
  3578. + conf->proxy_passwd ? conf->proxy_passwd : "",
  3579. + conf->verbose_wget ? "" : "-q",
  3580. + conf->tmp_dir,
  3581. + src);
  3582. + err = xsystem(cmd);
  3583. + if (err) {
  3584. + if (err != -1) {
  3585. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
  3586. + __FUNCTION__, err, cmd);
  3587. + }
  3588. + unlink(tmp_file_location);
  3589. + free(tmp_file_location);
  3590. + free(src_basec);
  3591. + free(cmd);
  3592. + return EINVAL;
  3593. + }
  3594. + free(cmd);
  3595. +
  3596. + err = file_move(tmp_file_location, dest_file_name);
  3597. +
  3598. + free(tmp_file_location);
  3599. + free(src_basec);
  3600. +
  3601. + if (err) {
  3602. + return err;
  3603. + }
  3604. +
  3605. + return 0;
  3606. +}
  3607. +
  3608. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
  3609. +{
  3610. + int err;
  3611. + char *url;
  3612. +
  3613. + if (pkg->src == NULL) {
  3614. + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
  3615. + pkg->name, pkg->parent->name);
  3616. + return -1;
  3617. + }
  3618. +
  3619. + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
  3620. +
  3621. + /* XXX: BUG: The pkg->filename might be something like
  3622. + "../../foo.ipk". While this is correct, and exactly what we
  3623. + want to use to construct url above, here we actually need to
  3624. + use just the filename part, without any directory. */
  3625. + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
  3626. +
  3627. + err = ipkg_download(conf, url, pkg->local_filename);
  3628. + free(url);
  3629. +
  3630. + return err;
  3631. +}
  3632. +
  3633. +/*
  3634. + * Downloads file from url, installs in package database, return package name.
  3635. + */
  3636. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
  3637. +{
  3638. + int err = 0;
  3639. + pkg_t *pkg;
  3640. + pkg = pkg_new();
  3641. + if (pkg == NULL)
  3642. + return ENOMEM;
  3643. +
  3644. + if (str_starts_with(url, "http://")
  3645. + || str_starts_with(url, "ftp://")) {
  3646. + char *tmp_file;
  3647. + char *file_basec = strdup(url);
  3648. + char *file_base = bb_basename(file_basec);
  3649. +
  3650. + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
  3651. + err = ipkg_download(conf, url, tmp_file);
  3652. + if (err)
  3653. + return err;
  3654. +
  3655. + err = pkg_init_from_file(pkg, tmp_file);
  3656. + if (err)
  3657. + return err;
  3658. + pkg->local_filename = strdup(tmp_file);
  3659. +
  3660. + free(tmp_file);
  3661. + free(file_basec);
  3662. +
  3663. + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
  3664. + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
  3665. +
  3666. + err = pkg_init_from_file(pkg, url);
  3667. + if (err)
  3668. + return err;
  3669. + pkg->local_filename = strdup(url);
  3670. + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
  3671. + pkg->provided_by_hand = 1;
  3672. +
  3673. + } else {
  3674. + pkg_deinit(pkg);
  3675. + free(pkg);
  3676. + return 0;
  3677. + }
  3678. +
  3679. + if (!pkg->architecture) {
  3680. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3681. + return -EINVAL;
  3682. + }
  3683. +
  3684. + pkg->dest = conf->default_dest;
  3685. + pkg->state_want = SW_INSTALL;
  3686. + pkg->state_flag |= SF_PREFER;
  3687. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3688. + if ( pkg == NULL ){
  3689. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  3690. + return 0;
  3691. + }
  3692. + if (namep) {
  3693. + *namep = strdup(pkg->name);
  3694. + }
  3695. + return 0;
  3696. +}
  3697. diff -Nur busybox-1.22.1.orig/archival/libipkg/ipkg_download.h busybox-1.22.1/archival/libipkg/ipkg_download.h
  3698. --- busybox-1.22.1.orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
  3699. +++ busybox-1.22.1/archival/libipkg/ipkg_download.h 2014-05-23 21:12:06.000000000 +0200
  3700. @@ -0,0 +1,30 @@
  3701. +/* ipkg_download.h - the itsy package management system
  3702. +
  3703. + Carl D. Worth
  3704. +
  3705. + Copyright (C) 2001 University of Southern California
  3706. +
  3707. + This program is free software; you can redistribute it and/or
  3708. + modify it under the terms of the GNU General Public License as
  3709. + published by the Free Software Foundation; either version 2, or (at
  3710. + your option) any later version.
  3711. +
  3712. + This program is distributed in the hope that it will be useful, but
  3713. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3714. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3715. + General Public License for more details.
  3716. +*/
  3717. +
  3718. +#ifndef IPKG_DOWNLOAD_H
  3719. +#define IPKG_DOWNLOAD_H
  3720. +
  3721. +#include "ipkg_conf.h"
  3722. +
  3723. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
  3724. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
  3725. +/*
  3726. + * Downloads file from url, installs in package database, return package name.
  3727. + */
  3728. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
  3729. +
  3730. +#endif
  3731. diff -Nur busybox-1.22.1.orig/archival/libipkg/ipkg_includes.h busybox-1.22.1/archival/libipkg/ipkg_includes.h
  3732. --- busybox-1.22.1.orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
  3733. +++ busybox-1.22.1/archival/libipkg/ipkg_includes.h 2014-05-23 21:12:06.000000000 +0200
  3734. @@ -0,0 +1,82 @@
  3735. +#ifndef IPKG_INCLUDES_H
  3736. +#define IPKG_INCLUDES_H
  3737. +
  3738. +/* Define to 1 if you have the <memory.h> header file. */
  3739. +#define HAVE_MEMORY_H 1
  3740. +
  3741. +/* Define to 1 if you have the <regex.h> header file. */
  3742. +#define HAVE_REGEX_H 1
  3743. +
  3744. +/* Define to 1 if you have the <stdlib.h> header file. */
  3745. +#define HAVE_STDLIB_H 1
  3746. +
  3747. +/* Define to 1 if you have the <strings.h> header file. */
  3748. +#define HAVE_STRINGS_H 1
  3749. +
  3750. +/* Define to 1 if you have the <string.h> header file. */
  3751. +#define HAVE_STRING_H 1
  3752. +
  3753. +/* Define to 1 if you have the <sys/stat.h> header file. */
  3754. +#define HAVE_SYS_STAT_H 1
  3755. +
  3756. +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
  3757. +#define HAVE_SYS_WAIT_H 1
  3758. +
  3759. +/* Define to 1 if you have the <unistd.h> header file. */
  3760. +#define HAVE_UNISTD_H 1
  3761. +
  3762. +/* Define to 1 if you have the ANSI C header files. */
  3763. +#define STDC_HEADERS 1
  3764. +
  3765. +
  3766. +#include <stdio.h>
  3767. +
  3768. +#if STDC_HEADERS
  3769. +# include <stdlib.h>
  3770. +# include <stdarg.h>
  3771. +# include <stddef.h>
  3772. +# include <ctype.h>
  3773. +# include <errno.h>
  3774. +#else
  3775. +# if HAVE_STDLIB_H
  3776. +# include <stdlib.h>
  3777. +# endif
  3778. +#endif
  3779. +
  3780. +#if HAVE_REGEX_H
  3781. +# include <regex.h>
  3782. +#endif
  3783. +
  3784. +#if HAVE_STRING_H
  3785. +# if !STDC_HEADERS && HAVE_MEMORY_H
  3786. +# include <memory.h>
  3787. +# endif
  3788. +/* XXX: What's the right way to pick up GNU's strndup declaration? */
  3789. +# if __GNUC__
  3790. +# define __USE_GNU 1
  3791. +# endif
  3792. +# include <string.h>
  3793. +# undef __USE_GNU
  3794. +#endif
  3795. +
  3796. +#if HAVE_STRINGS_H
  3797. +# include <strings.h>
  3798. +#endif
  3799. +
  3800. +#if HAVE_SYS_STAT_H
  3801. +# include <sys/stat.h>
  3802. +#endif
  3803. +
  3804. +#if HAVE_SYS_WAIT_H
  3805. +# include <sys/wait.h>
  3806. +#endif
  3807. +
  3808. +#if HAVE_UNISTD_H
  3809. +# include <sys/types.h>
  3810. +# include <unistd.h>
  3811. +#endif
  3812. +
  3813. +#include <sys/mount.h>
  3814. +#include <mntent.h>
  3815. +
  3816. +#endif /* IPKG_INCLUDES_H */
  3817. diff -Nur busybox-1.22.1.orig/archival/libipkg/ipkg_install.c busybox-1.22.1/archival/libipkg/ipkg_install.c
  3818. --- busybox-1.22.1.orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
  3819. +++ busybox-1.22.1/archival/libipkg/ipkg_install.c 2014-05-23 21:12:06.000000000 +0200
  3820. @@ -0,0 +1,1982 @@
  3821. +/* ipkg_install.c - the itsy package management system
  3822. +
  3823. + Carl D. Worth
  3824. +
  3825. + Copyright (C) 2001 University of Southern California
  3826. +
  3827. + This program is free software; you can redistribute it and/or
  3828. + modify it under the terms of the GNU General Public License as
  3829. + published by the Free Software Foundation; either version 2, or (at
  3830. + your option) any later version.
  3831. +
  3832. + This program is distributed in the hope that it will be useful, but
  3833. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3834. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3835. + General Public License for more details.
  3836. +*/
  3837. +
  3838. +#include "ipkg.h"
  3839. +#include <errno.h>
  3840. +#include <dirent.h>
  3841. +#include <glob.h>
  3842. +#include <time.h>
  3843. +#include <signal.h>
  3844. +typedef void (*sighandler_t)(int);
  3845. +
  3846. +#include "pkg.h"
  3847. +#include "pkg_hash.h"
  3848. +#include "pkg_extract.h"
  3849. +
  3850. +#include "ipkg_install.h"
  3851. +#include "ipkg_configure.h"
  3852. +#include "ipkg_download.h"
  3853. +#include "ipkg_remove.h"
  3854. +
  3855. +#include "ipkg_utils.h"
  3856. +#include "ipkg_message.h"
  3857. +
  3858. +#include "sprintf_alloc.h"
  3859. +#include "file_util.h"
  3860. +#include "str_util.h"
  3861. +#include "xsystem.h"
  3862. +#include "user.h"
  3863. +
  3864. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  3865. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
  3866. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
  3867. +
  3868. +/*
  3869. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3870. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3871. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3872. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3873. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3874. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3875. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3876. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
  3877. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3878. +*/
  3879. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3880. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3881. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg);
  3882. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3883. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg);
  3884. +
  3885. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3886. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3887. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
  3888. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
  3889. +
  3890. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
  3891. +
  3892. +static int user_prefers_old_conffile(const char *file, const char *backup);
  3893. +
  3894. +static char *backup_filename_alloc(const char *file_name);
  3895. +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
  3896. +static int backup_exists_for(const char *file_name);
  3897. +static int backup_remove(const char *file_name);
  3898. +
  3899. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees);
  3900. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3901. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3902. +
  3903. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
  3904. +{
  3905. + int err, cmp;
  3906. + pkg_t *pkg, *old;
  3907. + char *old_version, *new_version;
  3908. +
  3909. + pkg = pkg_new();
  3910. + if (pkg == NULL) {
  3911. + return ENOMEM;
  3912. + }
  3913. +
  3914. + err = pkg_init_from_file(pkg, filename);
  3915. + if (err) {
  3916. + return err;
  3917. + }
  3918. +
  3919. + if (!pkg->architecture) {
  3920. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3921. + return -EINVAL;
  3922. + }
  3923. +
  3924. + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
  3925. + freeing the pkg that we pass in. It might be nice to clean this up
  3926. + if possible. */
  3927. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3928. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  3929. +
  3930. + pkg->local_filename = strdup(filename);
  3931. +
  3932. + if (old) {
  3933. + old_version = pkg_version_str_alloc(old);
  3934. + new_version = pkg_version_str_alloc(pkg);
  3935. +
  3936. + cmp = pkg_compare_versions(old, pkg);
  3937. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3938. + cmp = -1 ; /* then we force ipkg to downgrade */
  3939. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3940. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3941. + }
  3942. + if (cmp > 0) {
  3943. + ipkg_message(conf, IPKG_NOTICE,
  3944. + "Not downgrading package %s on %s from %s to %s.\n",
  3945. + old->name, old->dest->name, old_version, new_version);
  3946. + pkg->state_want = SW_DEINSTALL;
  3947. + pkg->state_flag |= SF_OBSOLETE;
  3948. + free(old_version);
  3949. + free(new_version);
  3950. + return 0;
  3951. + } else {
  3952. + free(old_version);
  3953. + free(new_version);
  3954. + }
  3955. + }
  3956. +
  3957. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3958. + return ipkg_install_pkg(conf, pkg,0);
  3959. +}
  3960. +
  3961. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3962. +{
  3963. + int cmp;
  3964. + pkg_t *old, *new;
  3965. + char *old_version, *new_version;
  3966. +
  3967. + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
  3968. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  3969. + if ( old )
  3970. + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
  3971. +
  3972. + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
  3973. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  3974. + if ( new )
  3975. + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
  3976. +
  3977. +/* Pigi Basically here is broken the version stuff.
  3978. + What's happening is that nothing provide the version to differents
  3979. + functions, so the returned struct is always the latest.
  3980. + That's why the install by name don't work.
  3981. +*/
  3982. + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
  3983. +
  3984. + if ( old )
  3985. + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
  3986. + if ( new )
  3987. + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
  3988. + ipkg_message(conf, IPKG_DEBUG2, " \n");
  3989. +
  3990. + if (new == NULL) {
  3991. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3992. + }
  3993. +
  3994. + new->state_flag |= SF_USER;
  3995. + if (old) {
  3996. + old_version = pkg_version_str_alloc(old);
  3997. + new_version = pkg_version_str_alloc(new);
  3998. +
  3999. + cmp = pkg_compare_versions(old, new);
  4000. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4001. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
  4002. + cmp = -1 ; /* then we force ipkg to downgrade */
  4003. + /* We need to use a value < 0 because in the 0 case we are asking to */
  4004. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4005. + }
  4006. + ipkg_message(conf, IPKG_DEBUG,
  4007. + "Comparing visible versions of pkg %s:"
  4008. + "\n\t%s is installed "
  4009. + "\n\t%s is available "
  4010. + "\n\t%d was comparison result\n",
  4011. + pkg_name, old_version, new_version, cmp);
  4012. + if (cmp == 0 && !conf->force_reinstall) {
  4013. + ipkg_message(conf, IPKG_NOTICE,
  4014. + "Package %s (%s) installed in %s is up to date.\n",
  4015. + old->name, old_version, old->dest->name);
  4016. + free(old_version);
  4017. + free(new_version);
  4018. + return 0;
  4019. + } else if (cmp > 0) {
  4020. + ipkg_message(conf, IPKG_NOTICE,
  4021. + "Not downgrading package %s on %s from %s to %s.\n",
  4022. + old->name, old->dest->name, old_version, new_version);
  4023. + free(old_version);
  4024. + free(new_version);
  4025. + return 0;
  4026. + } else if (cmp < 0) {
  4027. + new->dest = old->dest;
  4028. + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
  4029. + }
  4030. + }
  4031. +
  4032. + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
  4033. + supposed to be an ipkg_error_t, but ipkg_install_pkg could
  4034. + return any kind of integer, (might be errno from a syscall,
  4035. + etc.). This is a real mess and will need to be cleaned up if
  4036. + anyone ever wants to make a nice libipkg. */
  4037. +
  4038. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4039. + return ipkg_install_pkg(conf, new,0);
  4040. +}
  4041. +
  4042. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
  4043. +{
  4044. + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
  4045. + int i;
  4046. + ipkg_error_t err;
  4047. + abstract_pkg_t *ppkg ;
  4048. +
  4049. + if (providers == NULL)
  4050. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4051. +
  4052. + for (i = 0; i < providers->len; i++) {
  4053. + ppkg = abstract_pkg_vec_get(providers, i);
  4054. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
  4055. + err = ipkg_install_by_name(conf, ppkg->name);
  4056. + if (err)
  4057. + return err;
  4058. +/* XXX Maybe ppkg should be freed ? */
  4059. + }
  4060. + return 0;
  4061. +}
  4062. +
  4063. +/*
  4064. + * Walk dependence graph starting with pkg, collect packages to be
  4065. + * installed into pkgs_needed, in dependence order.
  4066. + */
  4067. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
  4068. +{
  4069. + int i, err;
  4070. + pkg_vec_t *depends = pkg_vec_alloc();
  4071. + char **unresolved = NULL;
  4072. + int ndepends;
  4073. +
  4074. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4075. + pkg, depends,
  4076. + &unresolved);
  4077. +
  4078. + if (unresolved) {
  4079. + ipkg_message(conf, IPKG_ERROR,
  4080. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4081. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4082. + while (*unresolved) {
  4083. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4084. + unresolved++;
  4085. + }
  4086. + ipkg_message(conf, IPKG_ERROR, "\n");
  4087. + if (! conf->force_depends) {
  4088. + ipkg_message(conf, IPKG_INFO,
  4089. + "This could mean that your package list is out of date or that the packages\n"
  4090. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4091. + "of this problem try again with the '-force-depends' option.\n");
  4092. + pkg_vec_free(depends);
  4093. + return IPKG_PKG_DEPS_UNSATISFIED;
  4094. + }
  4095. + }
  4096. +
  4097. + if (ndepends <= 0) {
  4098. + pkg_vec_free(depends);
  4099. + return 0;
  4100. + }
  4101. +
  4102. + for (i = 0; i < depends->len; i++) {
  4103. + pkg_t *dep = depends->pkgs[i];
  4104. + /* The package was uninstalled when we started, but another
  4105. + dep earlier in this loop may have depended on it and pulled
  4106. + it in, so check first. */
  4107. + if ((dep->state_status != SS_INSTALLED)
  4108. + && (dep->state_status != SS_UNPACKED)
  4109. + && (dep->state_want != SW_INSTALL)) {
  4110. +
  4111. + /* Mark packages as to-be-installed */
  4112. + dep->state_want = SW_INSTALL;
  4113. +
  4114. + /* Dependencies should be installed the same place as pkg */
  4115. + if (dep->dest == NULL) {
  4116. + dep->dest = pkg->dest;
  4117. + }
  4118. +
  4119. + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
  4120. + if (err) {
  4121. + pkg_vec_free(depends);
  4122. + return err;
  4123. + }
  4124. + }
  4125. + }
  4126. + if (pkgs_needed)
  4127. + pkg_vec_insert(pkgs_needed, pkg);
  4128. +
  4129. + pkg_vec_free(depends);
  4130. +
  4131. + return 0;
  4132. +}
  4133. +
  4134. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
  4135. +{
  4136. + int cmp;
  4137. + pkg_t *old, *new;
  4138. + char *old_version, *new_version;
  4139. +
  4140. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  4141. +
  4142. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  4143. + if (new == NULL) {
  4144. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4145. + }
  4146. + if (old) {
  4147. + old_version = pkg_version_str_alloc(old);
  4148. + new_version = pkg_version_str_alloc(new);
  4149. +
  4150. + cmp = pkg_compare_versions(old, new);
  4151. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4152. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
  4153. + cmp = -1 ; /* then we force ipkg to downgrade */
  4154. + /* We need to use a value < 0 because in the 0 case we are asking to */
  4155. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4156. + }
  4157. + ipkg_message(conf, IPKG_DEBUG,
  4158. + "comparing visible versions of pkg %s:"
  4159. + "\n\t%s is installed "
  4160. + "\n\t%s is available "
  4161. + "\n\t%d was comparison result\n",
  4162. + pkg_name, old_version, new_version, cmp);
  4163. + if (cmp == 0 && !conf->force_reinstall) {
  4164. + ipkg_message(conf, IPKG_NOTICE,
  4165. + "Package %s (%s) installed in %s is up to date.\n",
  4166. + old->name, old_version, old->dest->name);
  4167. + free(old_version);
  4168. + free(new_version);
  4169. + return 0;
  4170. + } else if (cmp > 0) {
  4171. + ipkg_message(conf, IPKG_NOTICE,
  4172. + "Not downgrading package %s on %s from %s to %s.\n",
  4173. + old->name, old->dest->name, old_version, new_version);
  4174. + free(old_version);
  4175. + free(new_version);
  4176. + return 0;
  4177. + } else if (cmp < 0) {
  4178. + new->dest = old->dest;
  4179. + old->state_want = SW_DEINSTALL;
  4180. + old->state_flag |= SF_OBSOLETE;
  4181. + }
  4182. + }
  4183. + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
  4184. +}
  4185. +
  4186. +
  4187. +
  4188. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
  4189. +{
  4190. + int i, err;
  4191. + pkg_vec_t *depends = pkg_vec_alloc();
  4192. + pkg_t *dep;
  4193. + char **unresolved = NULL;
  4194. + int ndepends;
  4195. +
  4196. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4197. + pkg, depends,
  4198. + &unresolved);
  4199. +
  4200. + if (unresolved) {
  4201. + ipkg_message(conf, IPKG_ERROR,
  4202. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4203. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4204. + while (*unresolved) {
  4205. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4206. + unresolved++;
  4207. + }
  4208. + ipkg_message(conf, IPKG_ERROR, "\n");
  4209. + if (! conf->force_depends) {
  4210. + ipkg_message(conf, IPKG_INFO,
  4211. + "This could mean that your package list is out of date or that the packages\n"
  4212. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4213. + "of this problem try again with the '-force-depends' option.\n");
  4214. + pkg_vec_free(depends);
  4215. + return IPKG_PKG_DEPS_UNSATISFIED;
  4216. + }
  4217. + }
  4218. +
  4219. + if (ndepends <= 0) {
  4220. + return 0;
  4221. + }
  4222. +
  4223. + /* Mark packages as to-be-installed */
  4224. + for (i=0; i < depends->len; i++) {
  4225. + /* Dependencies should be installed the same place as pkg */
  4226. + if (depends->pkgs[i]->dest == NULL) {
  4227. + depends->pkgs[i]->dest = pkg->dest;
  4228. + }
  4229. + depends->pkgs[i]->state_want = SW_INSTALL;
  4230. + }
  4231. +
  4232. + for (i = 0; i < depends->len; i++) {
  4233. + dep = depends->pkgs[i];
  4234. + /* The package was uninstalled when we started, but another
  4235. + dep earlier in this loop may have depended on it and pulled
  4236. + it in, so check first. */
  4237. + if ((dep->state_status != SS_INSTALLED)
  4238. + && (dep->state_status != SS_UNPACKED)) {
  4239. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4240. + err = ipkg_install_pkg(conf, dep,0);
  4241. + if (err) {
  4242. + pkg_vec_free(depends);
  4243. + return err;
  4244. + }
  4245. + }
  4246. + }
  4247. +
  4248. + pkg_vec_free(depends);
  4249. +
  4250. + return 0;
  4251. +}
  4252. +
  4253. +
  4254. +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
  4255. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
  4256. +{
  4257. + if (conf->nodeps == 0) {
  4258. + int i;
  4259. + pkg_vec_t *installed = pkg_vec_alloc();
  4260. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  4261. + for (i = 0; i < installed->len; i++) {
  4262. + pkg_t *pkg = installed->pkgs[i];
  4263. + satisfy_dependencies_for(conf, pkg);
  4264. + }
  4265. + pkg_vec_free(installed);
  4266. + }
  4267. + return 0;
  4268. +}
  4269. +
  4270. +
  4271. +
  4272. +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
  4273. +{
  4274. + int i;
  4275. + pkg_vec_t *conflicts = NULL;
  4276. + int level;
  4277. + const char *prefix;
  4278. + if (conf->force_depends) {
  4279. + level = IPKG_NOTICE;
  4280. + prefix = "Warning";
  4281. + } else {
  4282. + level = IPKG_ERROR;
  4283. + prefix = "ERROR";
  4284. + }
  4285. +
  4286. + if (!conf->force_depends)
  4287. + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(pkg);
  4288. +
  4289. + if (conflicts) {
  4290. + ipkg_message(conf, level,
  4291. + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
  4292. + i = 0;
  4293. + while (i < conflicts->len)
  4294. + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
  4295. + ipkg_message(conf, level, "\n");
  4296. + pkg_vec_free(conflicts);
  4297. + return IPKG_PKG_DEPS_UNSATISFIED;
  4298. + }
  4299. + return 0;
  4300. +}
  4301. +
  4302. +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
  4303. +{
  4304. + str_list_t *new_list = pkg_get_installed_files(new_pkg);
  4305. + str_list_elt_t *iter;
  4306. +
  4307. + for (iter = new_list->head; iter; iter = iter->next) {
  4308. + char *new_file = iter->data;
  4309. + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
  4310. + if (!new_file)
  4311. + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
  4312. + if (!owner || (owner == old_pkg))
  4313. + file_hash_set_file_owner(conf, new_file, new_pkg);
  4314. + }
  4315. + if (old_pkg) {
  4316. + str_list_t *old_list = pkg_get_installed_files(old_pkg);
  4317. + for (iter = old_list->head; iter; iter = iter->next) {
  4318. + char *old_file = iter->data;
  4319. + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
  4320. + if (owner == old_pkg) {
  4321. + /* obsolete */
  4322. + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
  4323. + }
  4324. + }
  4325. + }
  4326. + return 0;
  4327. +}
  4328. +
  4329. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
  4330. +{
  4331. + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
  4332. +
  4333. + /* sma 6.20.02: yup; here's the first bit */
  4334. + /*
  4335. + * XXX: BUG easy for cworth
  4336. + * 1) please point the call below to the correct current root destination
  4337. + * 2) we need to resolve how to check the required space for a pending pkg,
  4338. + * my diddling with the .ipk file size below isn't going to cut it.
  4339. + * 3) return a proper error code instead of 1
  4340. + */
  4341. + int comp_size, blocks_available;
  4342. +
  4343. + if (!conf->force_space && pkg->installed_size != NULL) {
  4344. + blocks_available = get_available_blocks(conf->default_dest->root_dir);
  4345. +
  4346. + comp_size = strtoul(pkg->installed_size, NULL, 0);
  4347. + /* round up a blocks count without doing fancy-but-slow casting jazz */
  4348. + comp_size = (int)((comp_size + 1023) / 1024);
  4349. +
  4350. + if (comp_size >= blocks_available) {
  4351. + ipkg_message(conf, IPKG_ERROR,
  4352. + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
  4353. + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
  4354. + return ENOSPC;
  4355. + }
  4356. + }
  4357. + return 0;
  4358. +}
  4359. +
  4360. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
  4361. +{
  4362. + int err;
  4363. + char *conffiles_file_name;
  4364. + char *root_dir;
  4365. + FILE *conffiles_file;
  4366. +
  4367. + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
  4368. +
  4369. + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
  4370. + if (pkg->tmp_unpack_dir == NULL) {
  4371. + ipkg_message(conf, IPKG_ERROR,
  4372. + "%s: Failed to create temporary directory '%s': %s\n",
  4373. + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
  4374. + return errno;
  4375. + }
  4376. +
  4377. + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
  4378. + if (err) {
  4379. + return err;
  4380. + }
  4381. +
  4382. + /* XXX: CLEANUP: There might be a cleaner place to read in the
  4383. + conffiles. Seems like I should be able to get everything to go
  4384. + through pkg_init_from_file. If so, maybe it would make sense to
  4385. + move all of unpack_pkg_control_files to that function. */
  4386. +
  4387. + /* Don't need to re-read conffiles if we already have it */
  4388. + if (pkg->conffiles.head) {
  4389. + return 0;
  4390. + }
  4391. +
  4392. + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
  4393. + if (! file_exists(conffiles_file_name)) {
  4394. + free(conffiles_file_name);
  4395. + return 0;
  4396. + }
  4397. +
  4398. + conffiles_file = fopen(conffiles_file_name, "r");
  4399. + if (conffiles_file == NULL) {
  4400. + fprintf(stderr, "%s: failed to open %s: %s\n",
  4401. + __FUNCTION__, conffiles_file_name, strerror(errno));
  4402. + free(conffiles_file_name);
  4403. + return errno;
  4404. + }
  4405. + free(conffiles_file_name);
  4406. +
  4407. + while (1) {
  4408. + char *cf_name;
  4409. + char *cf_name_in_dest;
  4410. +
  4411. + cf_name = file_read_line_alloc(conffiles_file);
  4412. + if (cf_name == NULL) {
  4413. + break;
  4414. + }
  4415. + str_chomp(cf_name);
  4416. + if (cf_name[0] == '\0') {
  4417. + continue;
  4418. + }
  4419. +
  4420. + /* Prepend dest->root_dir to conffile name.
  4421. + Take pains to avoid multiple slashes. */
  4422. + root_dir = pkg->dest->root_dir;
  4423. + if (conf->offline_root)
  4424. + /* skip the offline_root prefix */
  4425. + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
  4426. + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
  4427. + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
  4428. +
  4429. + /* Can't get an md5sum now, (file isn't extracted yet).
  4430. + We'll wait until resolve_conffiles */
  4431. + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
  4432. +
  4433. + free(cf_name);
  4434. + free(cf_name_in_dest);
  4435. + }
  4436. +
  4437. + fclose(conffiles_file);
  4438. +
  4439. + return 0;
  4440. +}
  4441. +
  4442. +/* returns number of installed replacees */
  4443. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees)
  4444. +{
  4445. + abstract_pkg_t **replaces = pkg->replaces;
  4446. + int replaces_count = pkg->replaces_count;
  4447. + int i, j;
  4448. + for (i = 0; i < replaces_count; i++) {
  4449. + abstract_pkg_t *ab_pkg = replaces[i];
  4450. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  4451. + if (pkg_vec) {
  4452. + for (j = 0; j < pkg_vec->len; j++) {
  4453. + pkg_t *replacee = pkg_vec->pkgs[j];
  4454. + if (!pkg_conflicts(pkg, replacee))
  4455. + continue;
  4456. + if (replacee->state_status == SS_INSTALLED) {
  4457. + pkg_vec_insert(installed_replacees, replacee);
  4458. + }
  4459. + }
  4460. + }
  4461. + }
  4462. + return installed_replacees->len;
  4463. +}
  4464. +
  4465. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4466. +{
  4467. + int i;
  4468. + int replaces_count = replacees->len;
  4469. + for (i = 0; i < replaces_count; i++) {
  4470. + pkg_t *replacee = replacees->pkgs[i];
  4471. + int err;
  4472. + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
  4473. + err = ipkg_remove_pkg(conf, replacee,0);
  4474. + if (err)
  4475. + return err;
  4476. + }
  4477. + return 0;
  4478. +}
  4479. +
  4480. +/* to unwind the removal: make sure they are installed */
  4481. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4482. +{
  4483. + int i, err;
  4484. + int replaces_count = replacees->len;
  4485. + for (i = 0; i < replaces_count; i++) {
  4486. + pkg_t *replacee = replacees->pkgs[i];
  4487. + if (replacee->state_status != SS_INSTALLED) {
  4488. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4489. + err = ipkg_install_pkg(conf, replacee,0);
  4490. + if (err)
  4491. + return err;
  4492. + }
  4493. + }
  4494. + return 0;
  4495. +}
  4496. +
  4497. +int caught_sigint = 0;
  4498. +static void ipkg_install_pkg_sigint_handler(int sig)
  4499. +{
  4500. + caught_sigint = sig;
  4501. +}
  4502. +
  4503. +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
  4504. +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
  4505. +{
  4506. + if (old_pkg) {
  4507. + char message_out[15];
  4508. + char *old_version = pkg_version_str_alloc(old_pkg);
  4509. + char *new_version = pkg_version_str_alloc(pkg);
  4510. + int cmp = pkg_compare_versions(old_pkg, pkg);
  4511. + int rc = 0;
  4512. +
  4513. + memset(message_out,'\x0',15);
  4514. + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
  4515. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4516. + cmp = -1 ; /* then we force ipkg to downgrade */
  4517. + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
  4518. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4519. + }
  4520. +
  4521. + if (cmp > 0) {
  4522. + ipkg_message(conf, IPKG_NOTICE,
  4523. + "Not downgrading package %s on %s from %s to %s.\n",
  4524. + old_pkg->name, old_pkg->dest->name, old_version, new_version);
  4525. + rc = 1;
  4526. + } else if (cmp < 0) {
  4527. + ipkg_message(conf, IPKG_NOTICE,
  4528. + "%s%s on %s from %s to %s...\n",
  4529. + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
  4530. + pkg->dest = old_pkg->dest;
  4531. + rc = 0;
  4532. + } else /* cmp == 0 */ {
  4533. + if (conf->force_reinstall) {
  4534. + ipkg_message(conf, IPKG_NOTICE,
  4535. + "Reinstalling %s (%s) on %s...\n",
  4536. + pkg->name, new_version, old_pkg->dest->name);
  4537. + pkg->dest = old_pkg->dest;
  4538. + rc = 0;
  4539. + } else {
  4540. + ipkg_message(conf, IPKG_NOTICE,
  4541. + "Not installing %s (%s) on %s -- already installed.\n",
  4542. + pkg->name, new_version, old_pkg->dest->name);
  4543. + rc = 1;
  4544. + }
  4545. + }
  4546. + free(old_version);
  4547. + free(new_version);
  4548. + return rc;
  4549. + } else {
  4550. + char message_out[15], *version ;
  4551. + memset(message_out,'\x0',15);
  4552. + if ( message )
  4553. + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
  4554. + else
  4555. + strncpy( message_out,"Installing ",strlen("Installing ") );
  4556. + version = pkg_version_str_alloc(pkg);
  4557. +
  4558. + ipkg_message(conf, IPKG_NOTICE,
  4559. + "%s%s (%s) to %s...\n", message_out,
  4560. + pkg->name, version, pkg->dest->name);
  4561. + free(version);
  4562. + return 0;
  4563. + }
  4564. +}
  4565. +
  4566. +/* and now the meat... */
  4567. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
  4568. +{
  4569. + int err = 0;
  4570. + int message = 0;
  4571. + pkg_t *old_pkg = NULL;
  4572. + pkg_vec_t *replacees;
  4573. + abstract_pkg_t *ab_pkg = NULL;
  4574. + int old_state_flag;
  4575. + uint8_t *file_md5;
  4576. +
  4577. +
  4578. + if ( from_upgrade )
  4579. + message = 1; /* Coming from an upgrade, and should change the output message */
  4580. +
  4581. + if (!pkg) {
  4582. + ipkg_message(conf, IPKG_ERROR,
  4583. + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
  4584. + return -EINVAL;
  4585. + }
  4586. +
  4587. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
  4588. +
  4589. + if (!pkg_arch_supported(conf, pkg)) {
  4590. + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
  4591. + pkg->architecture, pkg->name);
  4592. + return -EINVAL;
  4593. + }
  4594. + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
  4595. + err = satisfy_dependencies_for(conf, pkg);
  4596. + if (err) { return err; }
  4597. +
  4598. + ipkg_message(conf, IPKG_NOTICE,
  4599. + "Package %s is already installed in %s.\n",
  4600. + pkg->name, pkg->dest->name);
  4601. + return 0;
  4602. + }
  4603. +
  4604. + if (pkg->dest == NULL) {
  4605. + pkg->dest = conf->default_dest;
  4606. + }
  4607. +
  4608. + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  4609. +
  4610. + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
  4611. + if (err) { return err; }
  4612. +
  4613. + pkg->state_want = SW_INSTALL;
  4614. + if (old_pkg){
  4615. + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
  4616. + }
  4617. +
  4618. +
  4619. + /* Abhaya: conflicts check */
  4620. + err = check_conflicts_for(conf, pkg);
  4621. + if (err) { return err; }
  4622. +
  4623. + /* this setup is to remove the upgrade scenario in the end when
  4624. + installing pkg A, A deps B & B deps on A. So both B and A are
  4625. + installed. Then A's installation is started resulting in an
  4626. + uncecessary upgrade */
  4627. + if (pkg->state_status == SS_INSTALLED
  4628. + && conf->force_reinstall == 0) return 0;
  4629. +
  4630. + err = verify_pkg_installable(conf, pkg);
  4631. + if (err) { return err; }
  4632. +
  4633. + if (pkg->local_filename == NULL) {
  4634. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  4635. + if (err) {
  4636. + ipkg_message(conf, IPKG_ERROR,
  4637. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  4638. + pkg->name);
  4639. + return err;
  4640. + }
  4641. + }
  4642. +
  4643. +/* Check for md5 values */
  4644. + if (pkg->md5sum)
  4645. + {
  4646. + file_md5 = file_md5sum_alloc(pkg->local_filename);
  4647. + if (strcmp((char *)file_md5, pkg->md5sum))
  4648. + {
  4649. + ipkg_message(conf, IPKG_ERROR,
  4650. + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
  4651. + pkg->name);
  4652. + free(file_md5);
  4653. + return err;
  4654. + }
  4655. + free(file_md5);
  4656. + }
  4657. +
  4658. + if (pkg->tmp_unpack_dir == NULL) {
  4659. + unpack_pkg_control_files(conf, pkg);
  4660. + }
  4661. +
  4662. + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
  4663. +/* Pigi: check if it will pass from here when replacing. It seems to fail */
  4664. +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
  4665. + err = update_file_ownership(conf, pkg, old_pkg);
  4666. + if (err) { return err; }
  4667. +
  4668. + if (conf->nodeps == 0) {
  4669. + err = satisfy_dependencies_for(conf, pkg);
  4670. + if (err) { return err; }
  4671. + }
  4672. +
  4673. + replacees = pkg_vec_alloc();
  4674. + pkg_get_installed_replacees(pkg, replacees);
  4675. +
  4676. + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
  4677. + {
  4678. + sigset_t newset, oldset;
  4679. + sighandler_t old_handler = NULL;
  4680. + int use_signal = 0;
  4681. + caught_sigint = 0;
  4682. + if (use_signal) {
  4683. + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
  4684. + } else {
  4685. + sigemptyset(&newset);
  4686. + sigaddset(&newset, SIGINT);
  4687. + sigprocmask(SIG_BLOCK, &newset, &oldset);
  4688. + }
  4689. +
  4690. + ipkg_state_changed++;
  4691. + pkg->state_flag |= SF_FILELIST_CHANGED;
  4692. +
  4693. + /* XXX: BUG: we really should treat replacement more like an upgrade
  4694. + * Instead, we're going to remove the replacees
  4695. + */
  4696. + err = pkg_remove_installed_replacees(conf, replacees);
  4697. + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
  4698. +
  4699. + /*
  4700. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  4701. + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
  4702. +
  4703. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  4704. + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
  4705. + */
  4706. +
  4707. + err = preinst_configure(conf, pkg, old_pkg);
  4708. + /*
  4709. + if (err) goto UNWIND_PREINST_CONFIGURE;
  4710. + */
  4711. +
  4712. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  4713. + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
  4714. +
  4715. + err = check_data_file_clashes(conf, pkg, old_pkg);
  4716. + /*
  4717. + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
  4718. +
  4719. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  4720. + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
  4721. + */
  4722. +
  4723. + if (conf->noaction) return 0;
  4724. +
  4725. + /* point of no return: no unwinding after this */
  4726. + if (old_pkg && !conf->force_reinstall) {
  4727. + old_pkg->state_want = SW_DEINSTALL;
  4728. +
  4729. + if (old_pkg->state_flag & SF_NOPRUNE) {
  4730. + ipkg_message(conf, IPKG_INFO,
  4731. + " not removing obsolesced files because package marked noprune\n");
  4732. + } else {
  4733. + ipkg_message(conf, IPKG_INFO,
  4734. + " removing obsolesced files\n");
  4735. + remove_obsolesced_files(conf, pkg, old_pkg);
  4736. + }
  4737. + /* removing files from old package, to avoid ghost files */
  4738. + remove_data_files_and_list(conf, old_pkg);
  4739. +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
  4740. + remove_maintainer_scripts_except_postrm(conf, old_pkg);
  4741. + remove_postrm(conf, old_pkg);
  4742. +/* Pigi */
  4743. +
  4744. + }
  4745. +
  4746. +
  4747. + ipkg_message(conf, IPKG_INFO,
  4748. + " installing maintainer scripts\n");
  4749. + install_maintainer_scripts(conf, pkg, old_pkg);
  4750. +
  4751. + /* the following just returns 0
  4752. + remove_disappeared(conf, pkg);
  4753. + */
  4754. +
  4755. + ipkg_message(conf, IPKG_INFO,
  4756. + " installing data files\n");
  4757. + install_data_files(conf, pkg);
  4758. +
  4759. +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
  4760. + err = check_data_file_clashes_change(conf, pkg);
  4761. +
  4762. + ipkg_message(conf, IPKG_INFO,
  4763. + " resolving conf files\n");
  4764. + resolve_conffiles(conf, pkg);
  4765. +
  4766. + pkg->state_status = SS_UNPACKED;
  4767. + old_state_flag = pkg->state_flag;
  4768. + pkg->state_flag &= ~SF_PREFER;
  4769. + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
  4770. +
  4771. + if (old_pkg && !conf->force_reinstall) {
  4772. + old_pkg->state_status = SS_NOT_INSTALLED;
  4773. + }
  4774. +
  4775. + time(&pkg->installed_time);
  4776. +
  4777. + ipkg_message(conf, IPKG_INFO,
  4778. + " cleanup temp files\n");
  4779. + cleanup_temporary_files(conf, pkg);
  4780. +
  4781. + ab_pkg = pkg->parent;
  4782. + if (ab_pkg)
  4783. + ab_pkg->state_status = pkg->state_status;
  4784. +
  4785. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  4786. +
  4787. + if (use_signal)
  4788. + signal(SIGINT, old_handler);
  4789. + else
  4790. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4791. +
  4792. + return 0;
  4793. +
  4794. +
  4795. + /*
  4796. + UNWIND_POSTRM_UPGRADE_OLD_PKG:
  4797. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4798. + UNWIND_CHECK_DATA_FILE_CLASHES:
  4799. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  4800. + */
  4801. + UNWIND_BACKUP_MODIFIED_CONFFILES:
  4802. + backup_modified_conffiles_unwind(pkg, old_pkg);
  4803. + /*
  4804. + UNWIND_PREINST_CONFIGURE:
  4805. + preinst_configure_unwind(conf, pkg, old_pkg);
  4806. + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
  4807. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  4808. + UNWIND_PRERM_UPGRADE_OLD_PKG:
  4809. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4810. + */
  4811. + UNWIND_REMOVE_INSTALLED_REPLACEES:
  4812. + pkg_remove_installed_replacees_unwind(conf, replacees);
  4813. +
  4814. + ipkg_message(conf, IPKG_INFO,
  4815. + " cleanup temp files\n");
  4816. + cleanup_temporary_files(conf, pkg);
  4817. +
  4818. + ipkg_message(conf, IPKG_INFO,
  4819. + "Failed.\n");
  4820. + if (use_signal)
  4821. + signal(SIGINT, old_handler);
  4822. + else
  4823. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4824. +
  4825. + return err;
  4826. + }
  4827. +}
  4828. +
  4829. +/*
  4830. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4831. +{
  4832. + DPKG_INCOMPATIBILITY:
  4833. + dpkg does some things here that we don't do yet. Do we care?
  4834. +
  4835. + 1. If a version of the package is already installed, call
  4836. + old-prerm upgrade new-version
  4837. + 2. If the script runs but exits with a non-zero exit status
  4838. + new-prerm failed-upgrade old-version
  4839. + Error unwind, for both the above cases:
  4840. + old-postinst abort-upgrade new-version
  4841. + return 0;
  4842. +}
  4843. +*/
  4844. +
  4845. +/*
  4846. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4847. +{
  4848. + DPKG_INCOMPATIBILITY:
  4849. + dpkg does some things here that we don't do yet. Do we care?
  4850. + (See prerm_upgrade_old_package for details)
  4851. +
  4852. + return 0;
  4853. +}
  4854. +*/
  4855. +
  4856. +/*
  4857. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4858. +{
  4859. + DPKG_INCOMPATIBILITY:
  4860. + dpkg does some things here that we don't do yet. Do we care?
  4861. + 2. If a 'conflicting' package is being removed at the same time:
  4862. + 1. If any packages depended on that conflicting package and
  4863. + --auto-deconfigure is specified, call, for each such package:
  4864. + deconfigured's-prerm deconfigure \
  4865. + in-favour package-being-installed version \
  4866. + removing conflicting-package version
  4867. + Error unwind:
  4868. + deconfigured's-postinst abort-deconfigure \
  4869. + in-favour package-being-installed-but-failed version \
  4870. + removing conflicting-package version
  4871. +
  4872. + The deconfigured packages are marked as requiring
  4873. + configuration, so that if --install is used they will be
  4874. + configured again if possible.
  4875. + 2. To prepare for removal of the conflicting package, call:
  4876. + conflictor's-prerm remove in-favour package new-version
  4877. + Error unwind:
  4878. + conflictor's-postinst abort-remove in-favour package new-version
  4879. + return 0;
  4880. +}
  4881. +*/
  4882. +
  4883. +/*
  4884. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4885. +{
  4886. + DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
  4887. + do yet. Do we care? (See prerm_deconfigure_conflictors for
  4888. + details)
  4889. + return 0;
  4890. +}
  4891. +*/
  4892. +
  4893. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4894. +{
  4895. + int err;
  4896. + char *preinst_args;
  4897. +
  4898. + if (old_pkg) {
  4899. + char *old_version = pkg_version_str_alloc(old_pkg);
  4900. + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
  4901. + free(old_version);
  4902. + } else if (pkg->state_status == SS_CONFIG_FILES) {
  4903. + char *pkg_version = pkg_version_str_alloc(pkg);
  4904. + sprintf_alloc(&preinst_args, "install %s", pkg_version);
  4905. + free(pkg_version);
  4906. + } else {
  4907. + preinst_args = strdup("install");
  4908. + }
  4909. +
  4910. + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
  4911. + if (err) {
  4912. + ipkg_message(conf, IPKG_ERROR,
  4913. + "Aborting installation of %s\n", pkg->name);
  4914. + return 1;
  4915. + }
  4916. +
  4917. + free(preinst_args);
  4918. +
  4919. + return 0;
  4920. +}
  4921. +
  4922. +/*
  4923. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4924. +{
  4925. + DPKG_INCOMPATIBILITY:
  4926. + dpkg does the following error unwind, should we?
  4927. + pkg->postrm abort-upgrade old-version
  4928. + OR pkg->postrm abort-install old-version
  4929. + OR pkg->postrm abort-install
  4930. + return 0;
  4931. +}
  4932. +*/
  4933. +
  4934. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4935. +{
  4936. + int err;
  4937. + conffile_list_elt_t *iter;
  4938. + conffile_t *cf;
  4939. +
  4940. + if (conf->noaction) return 0;
  4941. +
  4942. + /* Backup all modified conffiles */
  4943. + if (old_pkg) {
  4944. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4945. + char *cf_name;
  4946. +
  4947. + cf = iter->data;
  4948. + cf_name = root_filename_alloc(conf, cf->name);
  4949. +
  4950. + /* Don't worry if the conffile is just plain gone */
  4951. + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
  4952. + err = backup_make_backup(conf, cf_name);
  4953. + if (err) {
  4954. + return err;
  4955. + }
  4956. + }
  4957. + free(cf_name);
  4958. + }
  4959. + }
  4960. +
  4961. + /* Backup all conffiles that were not conffiles in old_pkg */
  4962. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4963. + char *cf_name;
  4964. + cf = iter->data;
  4965. + cf_name = root_filename_alloc(conf, cf->name);
  4966. + /* Ignore if this was a conffile in old_pkg as well */
  4967. + if (pkg_get_conffile(old_pkg, cf->name)) {
  4968. + continue;
  4969. + }
  4970. +
  4971. + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
  4972. + err = backup_make_backup(conf, cf_name);
  4973. + if (err) {
  4974. + return err;
  4975. + }
  4976. + }
  4977. + free(cf_name);
  4978. + }
  4979. +
  4980. + return 0;
  4981. +}
  4982. +
  4983. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg)
  4984. +{
  4985. + conffile_list_elt_t *iter;
  4986. +
  4987. + if (old_pkg) {
  4988. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4989. + backup_remove(iter->data->name);
  4990. + }
  4991. + }
  4992. +
  4993. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4994. + backup_remove(iter->data->name);
  4995. + }
  4996. +
  4997. + return 0;
  4998. +}
  4999. +
  5000. +
  5001. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5002. +{
  5003. + /* DPKG_INCOMPATIBILITY:
  5004. + ipkg takes a slightly different approach than dpkg at this
  5005. + point. dpkg installs each file in the new package while
  5006. + creating a backup for any file that is replaced, (so that it
  5007. + can unwind if necessary). To avoid complexity and redundant
  5008. + storage, ipkg doesn't do any installation until later, (at the
  5009. + point at which dpkg removes the backups.
  5010. +
  5011. + But, we do have to check for data file clashes, since after
  5012. + installing a package with a file clash, removing either of the
  5013. + packages involved in the clash has the potential to break the
  5014. + other package.
  5015. + */
  5016. + str_list_t *files_list;
  5017. + str_list_elt_t *iter;
  5018. +
  5019. + int clashes = 0;
  5020. +
  5021. + files_list = pkg_get_installed_files(pkg);
  5022. + for (iter = files_list->head; iter; iter = iter->next) {
  5023. + char *root_filename;
  5024. + char *filename = iter->data;
  5025. + root_filename = root_filename_alloc(conf, filename);
  5026. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5027. + pkg_t *owner;
  5028. + pkg_t *obs;
  5029. + /* Pre-existing conffiles are OK */
  5030. + /* @@@@ should have way to check that it is a conffile -Jamey */
  5031. + if (backup_exists_for(root_filename)) {
  5032. + continue;
  5033. + }
  5034. +
  5035. + /* Pre-existing files are OK if force-overwrite was asserted. */
  5036. + if (conf->force_overwrite) {
  5037. + /* but we need to change who owns this file */
  5038. + file_hash_set_file_owner(conf, filename, pkg);
  5039. + continue;
  5040. + }
  5041. +
  5042. + owner = file_hash_get_file_owner(conf, filename);
  5043. +
  5044. + /* Pre-existing files are OK if owned by the pkg being upgraded. */
  5045. + if (owner && old_pkg) {
  5046. + if (strcmp(owner->name, old_pkg->name) == 0) {
  5047. + continue;
  5048. + }
  5049. + }
  5050. +
  5051. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5052. + if (owner) {
  5053. + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
  5054. + if (pkg_replaces(pkg, owner)) {
  5055. + continue;
  5056. + }
  5057. +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
  5058. + then it's ok to overwrite. */
  5059. + if (strcmp(owner->name,pkg->name)==0){
  5060. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5061. + continue;
  5062. + }
  5063. + }
  5064. +
  5065. + /* Pre-existing files are OK if they are obsolete */
  5066. + obs = hash_table_get(&conf->obs_file_hash, filename);
  5067. + if (obs) {
  5068. + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
  5069. + continue;
  5070. + }
  5071. +
  5072. + /* We have found a clash. */
  5073. + ipkg_message(conf, IPKG_ERROR,
  5074. + "Package %s wants to install file %s\n"
  5075. + "\tBut that file is already provided by package ",
  5076. + pkg->name, filename);
  5077. + if (owner) {
  5078. + ipkg_message(conf, IPKG_ERROR,
  5079. + "%s\n", owner->name);
  5080. + } else {
  5081. + ipkg_message(conf, IPKG_ERROR,
  5082. + "<no package>\nPlease move this file out of the way and try again.\n");
  5083. + }
  5084. + clashes++;
  5085. + }
  5086. + free(root_filename);
  5087. + }
  5088. + pkg_free_installed_files(pkg);
  5089. +
  5090. + return clashes;
  5091. +}
  5092. +
  5093. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg)
  5094. +{
  5095. + /* Basically that's the worst hack I could do to be able to change ownership of
  5096. + file list, but, being that we have no way to unwind the mods, due to structure
  5097. + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
  5098. + What we do here is change the ownership of file in hash if a replace ( or similar events
  5099. + happens )
  5100. + Only the action that are needed to change name should be considered.
  5101. + @@@ To change after 1.0 release.
  5102. + */
  5103. + str_list_t *files_list;
  5104. + str_list_elt_t *iter;
  5105. +
  5106. + int clashes = 0;
  5107. +
  5108. + files_list = pkg_get_installed_files(pkg);
  5109. + for (iter = files_list->head; iter; iter = iter->next) {
  5110. + char *root_filename;
  5111. + char *filename = iter->data;
  5112. + root_filename = root_filename_alloc(conf, filename);
  5113. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5114. + pkg_t *owner;
  5115. +
  5116. + if (conf->force_overwrite) {
  5117. + /* but we need to change who owns this file */
  5118. + file_hash_set_file_owner(conf, filename, pkg);
  5119. + continue;
  5120. + }
  5121. +
  5122. + owner = file_hash_get_file_owner(conf, filename);
  5123. +
  5124. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5125. + if (owner) {
  5126. + if (pkg_replaces(pkg, owner)) {
  5127. +/* It's now time to change the owner of that file.
  5128. + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
  5129. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5130. + file_hash_set_file_owner(conf, filename, pkg);
  5131. + continue;
  5132. + }
  5133. + }
  5134. +
  5135. + }
  5136. + free(root_filename);
  5137. + }
  5138. + pkg_free_installed_files(pkg);
  5139. +
  5140. + return clashes;
  5141. +}
  5142. +
  5143. +/*
  5144. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5145. +{
  5146. + Nothing to do since check_data_file_clashes doesn't change state
  5147. + return 0;
  5148. +}
  5149. +*/
  5150. +
  5151. +/*
  5152. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5153. +{
  5154. + DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
  5155. + 1. If the package is being upgraded, call
  5156. + old-postrm upgrade new-version
  5157. + 2. If this fails, attempt:
  5158. + new-postrm failed-upgrade old-version
  5159. + Error unwind, for both cases:
  5160. + old-preinst abort-upgrade new-version
  5161. + return 0;
  5162. +}
  5163. +*/
  5164. +
  5165. +/*
  5166. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5167. +{
  5168. + DPKG_INCOMPATIBILITY:
  5169. + dpkg does some things here that we don't do yet. Do we care?
  5170. + (See postrm_upgrade_old_pkg for details)
  5171. + return 0;
  5172. +}
  5173. +*/
  5174. +
  5175. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5176. +{
  5177. + int err;
  5178. + str_list_t *old_files;
  5179. + str_list_elt_t *of;
  5180. + str_list_t *new_files;
  5181. + str_list_elt_t *nf;
  5182. +
  5183. + if (old_pkg == NULL) {
  5184. + return 0;
  5185. + }
  5186. +
  5187. + old_files = pkg_get_installed_files(old_pkg);
  5188. + new_files = pkg_get_installed_files(pkg);
  5189. +
  5190. + for (of = old_files->head; of; of = of->next) {
  5191. + pkg_t *owner;
  5192. + char *old, *new;
  5193. + old = of->data;
  5194. + for (nf = new_files->head; nf; nf = nf->next) {
  5195. + new = nf->data;
  5196. + if (strcmp(old, new) == 0) {
  5197. + goto NOT_OBSOLETE;
  5198. + }
  5199. + }
  5200. + if (file_is_dir(old)) {
  5201. + continue;
  5202. + }
  5203. + owner = file_hash_get_file_owner(conf, old);
  5204. + if (owner != old_pkg) {
  5205. + /* in case obsolete file no longer belongs to old_pkg */
  5206. + continue;
  5207. + }
  5208. +
  5209. + /* old file is obsolete */
  5210. + ipkg_message(conf, IPKG_INFO,
  5211. + " removing obsolete file %s\n", old);
  5212. + if (!conf->noaction) {
  5213. + err = unlink(old);
  5214. + if (err) {
  5215. + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
  5216. + strerror(errno));
  5217. + }
  5218. + }
  5219. +
  5220. + NOT_OBSOLETE:
  5221. + ;
  5222. + }
  5223. +
  5224. + pkg_free_installed_files(old_pkg);
  5225. + pkg_free_installed_files(pkg);
  5226. +
  5227. + return 0;
  5228. +}
  5229. +
  5230. +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5231. +{
  5232. + int i;
  5233. + int err = 0;
  5234. + char *globpattern;
  5235. + glob_t globbuf;
  5236. + if (0) {
  5237. + if (!pkg->dest) {
  5238. + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
  5239. + return -1;
  5240. + }
  5241. + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
  5242. + err = glob(globpattern, 0, NULL, &globbuf);
  5243. + free(globpattern);
  5244. + if (err) {
  5245. + return err;
  5246. + }
  5247. + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
  5248. + for (i = 0; i < globbuf.gl_pathc; i++) {
  5249. + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
  5250. + globbuf.gl_pathv[i], old_pkg->name);
  5251. + if (!conf->noaction)
  5252. + unlink(globbuf.gl_pathv[i]);
  5253. + }
  5254. + globfree(&globbuf);
  5255. + }
  5256. + return err;
  5257. +}
  5258. +
  5259. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5260. +{
  5261. + int ret;
  5262. + char *prefix;
  5263. +
  5264. + if (old_pkg)
  5265. + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
  5266. + sprintf_alloc(&prefix, "%s.", pkg->name);
  5267. + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
  5268. + pkg->dest->info_dir,
  5269. + prefix);
  5270. + free(prefix);
  5271. + return ret;
  5272. +}
  5273. +
  5274. +/*
  5275. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
  5276. +{
  5277. + DPKG_INCOMPATIBILITY:
  5278. + This is a fairly sophisticated dpkg operation. Shall we
  5279. + skip it?
  5280. +
  5281. + Any packages all of whose files have been overwritten during the
  5282. + installation, and which aren't required for dependencies, are
  5283. + considered to have been removed. For each such package
  5284. + 1. disappearer's-postrm disappear overwriter overwriter-version
  5285. + 2. The package's maintainer scripts are removed
  5286. + 3. It is noted in the status database as being in a sane state,
  5287. + namely not installed (any conffiles it may have are ignored,
  5288. + rather than being removed by dpkg). Note that disappearing
  5289. + packages do not have their prerm called, because dpkg doesn't
  5290. + know in advance that the package is going to vanish.
  5291. +
  5292. +
  5293. + return 0;
  5294. +}
  5295. +*/
  5296. +
  5297. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
  5298. +{
  5299. + int err;
  5300. +
  5301. + /* ipkg takes a slightly different approach to data file backups
  5302. + than dpkg. Rather than removing backups at this point, we
  5303. + actually do the data file installation now. See comments in
  5304. + check_data_file_clashes() for more details. */
  5305. +
  5306. + ipkg_message(conf, IPKG_INFO,
  5307. + " extracting data files to %s\n", pkg->dest->root_dir);
  5308. + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
  5309. + if (err) {
  5310. + return err;
  5311. + }
  5312. +
  5313. + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
  5314. + so we can't save ourself from removing important packages
  5315. + At this point we (should) have extracted the .control file, so it
  5316. + would be a good idea to reload the data in it, and set the Essential
  5317. + state in *pkg. From now on the Essential is back in status file and
  5318. + we can protect again.
  5319. + We should operate this way:
  5320. + fopen the file ( pkg->dest->root_dir/pkg->name.control )
  5321. + check for "Essential" in it
  5322. + set the value in pkg->essential.
  5323. + This new routine could be useful also for every other flag
  5324. + Pigi: 16/03/2004 */
  5325. + set_flags_from_control(conf, pkg) ;
  5326. +
  5327. + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
  5328. + err = pkg_write_filelist(conf, pkg);
  5329. + if (err)
  5330. + return err;
  5331. +
  5332. + /* XXX: FEATURE: ipkg should identify any files which existed
  5333. + before installation and which were overwritten, (see
  5334. + check_data_file_clashes()). What it must do is remove any such
  5335. + files from the filelist of the old package which provided the
  5336. + file. Otherwise, if the old package were removed at some point
  5337. + it would break the new package. Removing the new package will
  5338. + also break the old one, but this cannot be helped since the old
  5339. + package's file has already been deleted. This is the importance
  5340. + of check_data_file_clashes(), and only allowing ipkg to install
  5341. + a clashing package with a user force. */
  5342. +
  5343. + return 0;
  5344. +}
  5345. +
  5346. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
  5347. +{
  5348. + conffile_list_elt_t *iter;
  5349. + conffile_t *cf;
  5350. + char *cf_backup;
  5351. + uint8_t *md5sum;
  5352. +
  5353. +
  5354. + if (conf->noaction) return 0;
  5355. +
  5356. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  5357. + char *root_filename;
  5358. + cf = iter->data;
  5359. + root_filename = root_filename_alloc(conf, cf->name);
  5360. +
  5361. + /* Might need to initialize the md5sum for each conffile */
  5362. + if (cf->value == NULL) {
  5363. + cf->value = (char *)file_md5sum_alloc(root_filename);
  5364. + }
  5365. +
  5366. + if (!file_exists(root_filename)) {
  5367. + free(root_filename);
  5368. + continue;
  5369. + }
  5370. +
  5371. + cf_backup = backup_filename_alloc(root_filename);
  5372. +
  5373. +
  5374. + if (file_exists(cf_backup)) {
  5375. + /* Let's compute md5 to test if files are changed */
  5376. + md5sum = file_md5sum_alloc(cf_backup);
  5377. + if (strcmp( cf->value, (char *)md5sum) != 0 ) {
  5378. + if (conf->force_defaults
  5379. + || user_prefers_old_conffile(cf->name, cf_backup) ) {
  5380. + rename(cf_backup, root_filename);
  5381. + }
  5382. + }
  5383. + unlink(cf_backup);
  5384. + free(md5sum);
  5385. + }
  5386. +
  5387. + free(cf_backup);
  5388. + free(root_filename);
  5389. + }
  5390. +
  5391. + return 0;
  5392. +}
  5393. +
  5394. +static int user_prefers_old_conffile(const char *file_name, const char *backup)
  5395. +{
  5396. + char *response;
  5397. + const char *short_file_name;
  5398. +
  5399. + short_file_name = strrchr(file_name, '/');
  5400. + if (short_file_name) {
  5401. + short_file_name++;
  5402. + } else {
  5403. + short_file_name = file_name;
  5404. + }
  5405. +
  5406. + while (1) {
  5407. + response = get_user_response(" Configuration file '%s'\n"
  5408. + " ==> File on system created by you or by a script.\n"
  5409. + " ==> File also in package provided by package maintainer.\n"
  5410. + " What would you like to do about it ? Your options are:\n"
  5411. + " Y or I : install the package maintainer's version\n"
  5412. + " N or O : keep your currently-installed version\n"
  5413. +#ifdef CONFIG_DIFF
  5414. + " D : show the differences between the versions\n"
  5415. +#endif
  5416. + " The default action is to keep your current version.\n"
  5417. + " *** %s (Y/I/N/O"
  5418. +#ifdef CONFIG_DIFF
  5419. + "/D"
  5420. +#endif
  5421. + ") [default=N] ? ", file_name, short_file_name);
  5422. + if (strcmp(response, "y") == 0
  5423. + || strcmp(response, "i") == 0
  5424. + || strcmp(response, "yes") == 0) {
  5425. + free(response);
  5426. + return 0;
  5427. + }
  5428. +
  5429. +#ifdef CONFIG_DIFF
  5430. + if (strcmp(response, "d") == 0) {
  5431. + char *cmd;
  5432. +
  5433. + free(response);
  5434. + /* XXX: BUG rewrite to use exec or busybox's internal diff */
  5435. + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
  5436. + xsystem(cmd);
  5437. + free(cmd);
  5438. + printf(" [Press ENTER to continue]\n");
  5439. + response = file_read_line_alloc(stdin);
  5440. + free(response);
  5441. + continue;
  5442. + }
  5443. +#endif
  5444. +
  5445. + free(response);
  5446. + return 1;
  5447. + }
  5448. +}
  5449. +
  5450. +/* XXX: CLEANUP: I'd like to move all of the code for
  5451. + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
  5452. + it would make sense to cleanup pkg->tmp_unpack_dir directly from
  5453. + pkg_deinit for example). */
  5454. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
  5455. +{
  5456. + DIR *tmp_dir;
  5457. + struct dirent *dirent;
  5458. + char *tmp_file;
  5459. +
  5460. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  5461. +#error
  5462. + ipkg_message(conf, IPKG_DEBUG,
  5463. + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  5464. + __FUNCTION__, pkg->tmp_unpack_dir);
  5465. + return 0;
  5466. +#endif
  5467. +
  5468. + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
  5469. + tmp_dir = opendir(pkg->tmp_unpack_dir);
  5470. + if (tmp_dir) {
  5471. + while (1) {
  5472. + dirent = readdir(tmp_dir);
  5473. + if (dirent == NULL) {
  5474. + break;
  5475. + }
  5476. + sprintf_alloc(&tmp_file, "%s/%s",
  5477. + pkg->tmp_unpack_dir, dirent->d_name);
  5478. + if (! file_is_dir(tmp_file)) {
  5479. + unlink(tmp_file);
  5480. + }
  5481. + free(tmp_file);
  5482. + }
  5483. + closedir(tmp_dir);
  5484. + rmdir(pkg->tmp_unpack_dir);
  5485. + free(pkg->tmp_unpack_dir);
  5486. + pkg->tmp_unpack_dir = NULL;
  5487. + }
  5488. + }
  5489. +
  5490. + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
  5491. + pkg->name, pkg->local_filename, conf->tmp_dir);
  5492. + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
  5493. + unlink(pkg->local_filename);
  5494. + free(pkg->local_filename);
  5495. + pkg->local_filename = NULL;
  5496. + }
  5497. +
  5498. + return 0;
  5499. +}
  5500. +
  5501. +static char *backup_filename_alloc(const char *file_name)
  5502. +{
  5503. + char *backup;
  5504. +
  5505. + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
  5506. +
  5507. + return backup;
  5508. +}
  5509. +
  5510. +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
  5511. +{
  5512. + int err;
  5513. + char *backup;
  5514. +
  5515. + backup = backup_filename_alloc(file_name);
  5516. + err = file_copy(file_name, backup);
  5517. + if (err) {
  5518. + ipkg_message(conf, IPKG_ERROR,
  5519. + "%s: Failed to copy %s to %s\n",
  5520. + __FUNCTION__, file_name, backup);
  5521. + }
  5522. +
  5523. + free(backup);
  5524. +
  5525. + return err;
  5526. +}
  5527. +
  5528. +static int backup_exists_for(const char *file_name)
  5529. +{
  5530. + int ret;
  5531. + char *backup;
  5532. +
  5533. + backup = backup_filename_alloc(file_name);
  5534. +
  5535. + ret = file_exists(backup);
  5536. +
  5537. + free(backup);
  5538. +
  5539. + return ret;
  5540. +}
  5541. +
  5542. +static int backup_remove(const char *file_name)
  5543. +{
  5544. + char *backup;
  5545. +
  5546. + backup = backup_filename_alloc(file_name);
  5547. + unlink(backup);
  5548. + free(backup);
  5549. +
  5550. + return 0;
  5551. +}
  5552. +
  5553. +
  5554. +
  5555. +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
  5556. +
  5557. +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
  5558. +{
  5559. + /* first, remove the packages that need removing */
  5560. + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
  5561. + pkg_t *pkg = pkgs_to_remove->pkgs[i];
  5562. + err = ipkg_remove_pkg(conf, pkg,0);
  5563. + if (err) return err;
  5564. + }
  5565. + return 0;
  5566. +}
  5567. +
  5568. +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)
  5569. +{
  5570. + int i;
  5571. + /* now one more pass checking on the ones that need to be installed */
  5572. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5573. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5574. + if (pkg->dest == NULL)
  5575. + pkg->dest = conf->default_dest;
  5576. +
  5577. + pkg->state_want = SW_INSTALL;
  5578. +
  5579. + /* Abhaya: conflicts check */
  5580. + err = check_conflicts_for(conf, pkg);
  5581. + if (err) { return err; }
  5582. + }
  5583. + return 0;
  5584. +}
  5585. +
  5586. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5587. +{
  5588. + int i;
  5589. + /* now one more pass checking on the ones that need to be installed */
  5590. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5591. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5592. +
  5593. + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
  5594. + pkg_vec_t *replacees = pkg_vec_alloc();
  5595. + pkg_get_installed_replacees(pkg, replacees);
  5596. +
  5597. + /* XXX: BUG: we really should treat replacement more like an upgrade
  5598. + * Instead, we're going to remove the replacees
  5599. + */
  5600. + err = pkg_remove_installed_replacees(conf, replacees);
  5601. + if (err) return err;
  5602. + pkg->state_flag |= SF_REMOVED_REPLACEES;
  5603. + }
  5604. + return 0;
  5605. +}
  5606. +
  5607. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5608. +{
  5609. + int i;
  5610. + /* now one more pass checking on the ones that need to be installed */
  5611. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5612. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5613. + if (pkg->local_filename == NULL) {
  5614. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  5615. + if (err) {
  5616. + ipkg_message(conf, IPKG_ERROR,
  5617. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  5618. + pkg->name);
  5619. + return err;
  5620. + }
  5621. + }
  5622. + if (pkg->tmp_unpack_dir == NULL) {
  5623. + err = unpack_pkg_control_files(conf, pkg);
  5624. + if (err) return err;
  5625. + }
  5626. + }
  5627. + return 0;
  5628. +}
  5629. +
  5630. +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5631. +{
  5632. + int i;
  5633. + /* now one more pass checking on the ones that need to be installed */
  5634. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5635. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5636. + pkg_t *old_pkg = pkg->old_pkg;
  5637. +
  5638. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  5639. + if (err) return err;
  5640. +
  5641. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  5642. + if (err) return err;
  5643. +
  5644. + err = preinst_configure(conf, pkg, old_pkg);
  5645. + if (err) return err;
  5646. +
  5647. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  5648. + if (err) return err;
  5649. +
  5650. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  5651. + if (err) return err;
  5652. + }
  5653. + return 0;
  5654. +}
  5655. +
  5656. +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5657. +{
  5658. + int i;
  5659. + /* now one more pass checking on the ones that need to be installed */
  5660. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5661. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5662. + pkg_t *old_pkg = pkg->old_pkg;
  5663. +
  5664. + if (old_pkg) {
  5665. + old_pkg->state_want = SW_DEINSTALL;
  5666. +
  5667. + if (old_pkg->state_flag & SF_NOPRUNE) {
  5668. + ipkg_message(conf, IPKG_INFO,
  5669. + " not removing obsolesced files because package marked noprune\n");
  5670. + } else {
  5671. + ipkg_message(conf, IPKG_INFO,
  5672. + " removing obsolesced files\n");
  5673. + remove_obsolesced_files(conf, pkg, old_pkg);
  5674. + }
  5675. + }
  5676. +
  5677. + ipkg_message(conf, IPKG_INFO,
  5678. + " installing maintainer scripts\n");
  5679. + install_maintainer_scripts(conf, pkg, old_pkg);
  5680. +
  5681. + /* the following just returns 0 */
  5682. + remove_disappeared(conf, pkg);
  5683. +
  5684. + ipkg_message(conf, IPKG_INFO,
  5685. + " installing data files\n");
  5686. + install_data_files(conf, pkg);
  5687. +
  5688. + ipkg_message(conf, IPKG_INFO,
  5689. + " resolving conf files\n");
  5690. + resolve_conffiles(conf, pkg);
  5691. +
  5692. + pkg->state_status = SS_UNPACKED;
  5693. +
  5694. + if (old_pkg) {
  5695. + old_pkg->state_status = SS_NOT_INSTALLED;
  5696. + }
  5697. +
  5698. + time(&pkg->installed_time);
  5699. +
  5700. + ipkg_message(conf, IPKG_INFO,
  5701. + " cleanup temp files\n");
  5702. + cleanup_temporary_files(conf, pkg);
  5703. +
  5704. + if (pkg->parent)
  5705. + pkg->parent->state_status = pkg->state_status;
  5706. + }
  5707. + return 0;
  5708. +}
  5709. +
  5710. +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5711. +{
  5712. + int i;
  5713. + /* now one more pass checking on the ones that need to be installed */
  5714. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5715. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5716. + pkg_t *old_pkg = pkg->old_pkg;
  5717. +
  5718. + if (old_pkg) {
  5719. + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
  5720. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5721. + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
  5722. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  5723. + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
  5724. + backup_modified_conffiles_unwind(pkg, old_pkg);
  5725. + */
  5726. + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
  5727. + preinst_configure_unwind(conf, pkg, old_pkg);
  5728. + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
  5729. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  5730. + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
  5731. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5732. + */
  5733. +
  5734. + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
  5735. + remove_installed_replacees_unwind(conf, pkg, old_pkg);
  5736. +
  5737. + }
  5738. + }
  5739. + return 0;
  5740. +}
  5741. +
  5742. +/*
  5743. + * Perform all the actions.
  5744. + *
  5745. + * pkgs_to_remove are packages marked for removal.
  5746. + * pkgs_superseded are the old packages being replaced by upgrades.
  5747. + *
  5748. + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
  5749. + */
  5750. +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)
  5751. +{
  5752. + int err;
  5753. + int i;
  5754. +
  5755. + err = ipkg_remove_packages(conf, pkgs_to_remove);
  5756. + if (err) return err;
  5757. +
  5758. + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
  5759. + if (err) return err;
  5760. +
  5761. + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
  5762. + if (err) goto UNWIND;
  5763. +
  5764. + /* @@@@ look at ipkg_install_pkg for handling replacements */
  5765. + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
  5766. + if (err) goto UNWIND;
  5767. +
  5768. + /*
  5769. + * Now that we have the packages unpacked, we can look for data
  5770. + * file clashes. First, we mark the files from the superseded
  5771. + * packages as obsolete. Then we scan the files in
  5772. + * pkgs_to_install, and only complain about clashes with
  5773. + * non-obsolete files.
  5774. + */
  5775. +
  5776. + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
  5777. + if (err) goto UNWIND;
  5778. +
  5779. + /* this was before checking data file clashes */
  5780. + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
  5781. + if (err) goto UNWIND;
  5782. +
  5783. + /* point of no return: no unwinding after this */
  5784. + err = ipkg_process_actions_install(conf, pkgs_to_install);
  5785. + if (err) return err;
  5786. +
  5787. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  5788. + return 0;
  5789. +
  5790. + UNWIND:
  5791. + ipkg_process_actions_unwind(conf, pkgs_to_install);
  5792. +
  5793. + ipkg_message(conf, IPKG_INFO,
  5794. + " cleanup temp files\n");
  5795. + cleanup_temporary_files(conf, pkg);
  5796. +
  5797. + ipkg_message(conf, IPKG_INFO,
  5798. + "Failed.\n");
  5799. + return err;
  5800. +}
  5801. +
  5802. +#endif
  5803. diff -Nur busybox-1.22.1.orig/archival/libipkg/ipkg_install.h busybox-1.22.1/archival/libipkg/ipkg_install.h
  5804. --- busybox-1.22.1.orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
  5805. +++ busybox-1.22.1/archival/libipkg/ipkg_install.h 2014-05-23 21:12:06.000000000 +0200
  5806. @@ -0,0 +1,35 @@
  5807. +/* ipkg_install.h - the itsy package management system
  5808. +
  5809. + Carl D. Worth
  5810. +
  5811. + Copyright (C) 2001 University of Southern California
  5812. +
  5813. + This program is free software; you can redistribute it and/or
  5814. + modify it under the terms of the GNU General Public License as
  5815. + published by the Free Software Foundation; either version 2, or (at
  5816. + your option) any later version.
  5817. +
  5818. + This program is distributed in the hope that it will be useful, but
  5819. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5820. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5821. + General Public License for more details.
  5822. +*/
  5823. +
  5824. +#ifndef IPKG_INSTALL_H
  5825. +#define IPKG_INSTALL_H
  5826. +
  5827. +#include "pkg.h"
  5828. +#include "ipkg_conf.h"
  5829. +
  5830. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5831. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5832. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
  5833. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
  5834. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  5835. +
  5836. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
  5837. +
  5838. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
  5839. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
  5840. +
  5841. +#endif
  5842. diff -Nur busybox-1.22.1.orig/archival/libipkg/ipkg_message.c busybox-1.22.1/archival/libipkg/ipkg_message.c
  5843. --- busybox-1.22.1.orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
  5844. +++ busybox-1.22.1/archival/libipkg/ipkg_message.c 2014-05-23 21:12:06.000000000 +0200
  5845. @@ -0,0 +1,35 @@
  5846. +/* ipkg_message.c - the itsy package management system
  5847. +
  5848. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5849. +
  5850. + This program is free software; you can redistribute it and/or
  5851. + modify it under the terms of the GNU General Public License as
  5852. + published by the Free Software Foundation; either version 2, or (at
  5853. + your option) any later version.
  5854. +
  5855. + This program is distributed in the hope that it will be useful, but
  5856. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5857. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5858. + General Public License for more details.
  5859. +*/
  5860. +
  5861. +
  5862. +#include "ipkg.h"
  5863. +#include "ipkg_conf.h"
  5864. +#include "ipkg_message.h"
  5865. +#include "libipkg.h"
  5866. +
  5867. +void
  5868. +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
  5869. +{
  5870. + va_list ap;
  5871. + char ts[256];
  5872. +
  5873. + if (ipkg_cb_message)
  5874. + {
  5875. + va_start (ap, fmt);
  5876. + vsnprintf (ts,256,fmt, ap);
  5877. + va_end (ap);
  5878. + ipkg_cb_message(conf,level,ts);
  5879. + }
  5880. +}
  5881. diff -Nur busybox-1.22.1.orig/archival/libipkg/ipkg_message.h busybox-1.22.1/archival/libipkg/ipkg_message.h
  5882. --- busybox-1.22.1.orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
  5883. +++ busybox-1.22.1/archival/libipkg/ipkg_message.h 2014-05-23 21:12:06.000000000 +0200
  5884. @@ -0,0 +1,32 @@
  5885. +/* ipkg_message.h - the itsy package management system
  5886. +
  5887. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5888. +
  5889. + This program is free software; you can redistribute it and/or
  5890. + modify it under the terms of the GNU General Public License as
  5891. + published by the Free Software Foundation; either version 2, or (at
  5892. + your option) any later version.
  5893. +
  5894. + This program is distributed in the hope that it will be useful, but
  5895. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5896. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5897. + General Public License for more details.
  5898. +*/
  5899. +
  5900. +#ifndef _IPKG_MESSAGE_H_
  5901. +#define _IPKG_MESSAGE_H_
  5902. +
  5903. +#include "ipkg.h"
  5904. +#include "ipkg_conf.h"
  5905. +
  5906. +typedef enum {
  5907. + IPKG_ERROR, /* error conditions */
  5908. + IPKG_NOTICE, /* normal but significant condition */
  5909. + IPKG_INFO, /* informational message */
  5910. + IPKG_DEBUG, /* debug level message */
  5911. + IPKG_DEBUG2, /* more debug level message */
  5912. +} message_level_t;
  5913. +
  5914. +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
  5915. +
  5916. +#endif /* _IPKG_MESSAGE_H_ */
  5917. diff -Nur busybox-1.22.1.orig/archival/libipkg/ipkg_remove.c busybox-1.22.1/archival/libipkg/ipkg_remove.c
  5918. --- busybox-1.22.1.orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
  5919. +++ busybox-1.22.1/archival/libipkg/ipkg_remove.c 2014-05-23 21:12:06.000000000 +0200
  5920. @@ -0,0 +1,385 @@
  5921. +/* ipkg_remove.c - the itsy package management system
  5922. +
  5923. + Carl D. Worth
  5924. +
  5925. + Copyright (C) 2001 University of Southern California
  5926. +
  5927. + This program is free software; you can redistribute it and/or
  5928. + modify it under the terms of the GNU General Public License as
  5929. + published by the Free Software Foundation; either version 2, or (at
  5930. + your option) any later version.
  5931. +
  5932. + This program is distributed in the hope that it will be useful, but
  5933. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5934. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5935. + General Public License for more details.
  5936. +*/
  5937. +
  5938. +#include "ipkg.h"
  5939. +#include "ipkg_message.h"
  5940. +
  5941. +#include <glob.h>
  5942. +
  5943. +#include "ipkg_remove.h"
  5944. +
  5945. +#include "file_util.h"
  5946. +#include "sprintf_alloc.h"
  5947. +#include "str_util.h"
  5948. +
  5949. +#include "ipkg_cmd.h"
  5950. +
  5951. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents);
  5952. +
  5953. +/*
  5954. + * Returns number of the number of packages depending on the packages provided by this package.
  5955. + * Every package implicitly provides itself.
  5956. + */
  5957. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents)
  5958. +{
  5959. + int nprovides = pkg->provides_count;
  5960. + abstract_pkg_t **provides = pkg->provides;
  5961. + int n_installed_dependents = 0;
  5962. + int i;
  5963. + for (i = 0; i <= nprovides; i++) {
  5964. + abstract_pkg_t *providee = provides[i];
  5965. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5966. + abstract_pkg_t *dep_ab_pkg;
  5967. + if (dependers == NULL)
  5968. + continue;
  5969. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5970. + if (dep_ab_pkg->state_status == SS_INSTALLED){
  5971. + n_installed_dependents++;
  5972. + }
  5973. + }
  5974. +
  5975. + }
  5976. + /* if caller requested the set of installed dependents */
  5977. + if (pdependents) {
  5978. + int p = 0;
  5979. + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
  5980. +
  5981. + if ( dependents == NULL ){
  5982. + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
  5983. + return -1;
  5984. + }
  5985. +
  5986. + *pdependents = dependents;
  5987. + for (i = 0; i <= nprovides; i++) {
  5988. + abstract_pkg_t *providee = provides[i];
  5989. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5990. + abstract_pkg_t *dep_ab_pkg;
  5991. + if (dependers == NULL)
  5992. + continue;
  5993. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5994. + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
  5995. + dependents[p++] = dep_ab_pkg;
  5996. + dep_ab_pkg->state_flag |= SF_MARKED;
  5997. + }
  5998. + }
  5999. + }
  6000. + dependents[p] = NULL;
  6001. + /* now clear the marks */
  6002. + for (i = 0; i < p; i++) {
  6003. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  6004. + dep_ab_pkg->state_flag &= ~SF_MARKED;
  6005. + }
  6006. + }
  6007. + return n_installed_dependents;
  6008. +}
  6009. +
  6010. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  6011. +{
  6012. + int i;
  6013. + int a;
  6014. + int count;
  6015. + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
  6016. + abstract_pkg_t * ab_pkg;
  6017. +
  6018. + if((ab_pkg = pkg->parent) == NULL){
  6019. + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
  6020. + __FUNCTION__, pkg->name);
  6021. + return 0;
  6022. + }
  6023. +
  6024. + if (dependents == NULL)
  6025. + return 0;
  6026. +
  6027. + // here i am using the dependencies_checked
  6028. + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
  6029. + return 0; // has already been encountered in the process
  6030. + // of marking packages for removal - Karthik
  6031. + ab_pkg->dependencies_checked = 2;
  6032. +
  6033. + i = 0;
  6034. + count = 1;
  6035. + while (dependents [i] != NULL) {
  6036. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  6037. +
  6038. + if (dep_ab_pkg->dependencies_checked == 2){
  6039. + i++;
  6040. + continue;
  6041. + }
  6042. + if (dep_ab_pkg->state_status == SS_INSTALLED) {
  6043. + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
  6044. + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
  6045. + if (dep_pkg->state_status == SS_INSTALLED) {
  6046. + pkg_vec_insert(dependent_pkgs, dep_pkg);
  6047. + count++;
  6048. + }
  6049. + }
  6050. + }
  6051. + i++;
  6052. + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
  6053. + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
  6054. + }
  6055. +
  6056. + if (count == 1)
  6057. + return 0;
  6058. +
  6059. +
  6060. + for (i = 0; i < dependent_pkgs->len; i++) {
  6061. + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
  6062. + if (err)
  6063. + return err;
  6064. + }
  6065. + return 0;
  6066. +}
  6067. +
  6068. +static int user_prefers_removing_dependents(ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  6069. +{
  6070. + abstract_pkg_t *dep_ab_pkg;
  6071. + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
  6072. + while ((dep_ab_pkg = *dependents++) != NULL) {
  6073. + if (dep_ab_pkg->state_status == SS_INSTALLED)
  6074. + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
  6075. + }
  6076. + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
  6077. + ipkg_message(conf, IPKG_ERROR, "");
  6078. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
  6079. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
  6080. + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
  6081. + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
  6082. + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
  6083. + return 0;
  6084. +}
  6085. +
  6086. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
  6087. +{
  6088. +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
  6089. + thus I wan't check for essential, as I'm upgrading.
  6090. + I hope it won't break anything :)
  6091. +*/
  6092. + int err;
  6093. + abstract_pkg_t *parent_pkg = NULL;
  6094. +
  6095. + if (pkg->essential && !message) {
  6096. + if (conf->force_removal_of_essential_packages) {
  6097. + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
  6098. + "\tIf your system breaks, you get to keep both pieces\n",
  6099. + pkg->name);
  6100. + } else {
  6101. + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
  6102. + "\tRemoving an essential package may lead to an unusable system, but if\n"
  6103. + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
  6104. + "\tits will with the option: -force-removal-of-essential-packages\n",
  6105. + pkg->name);
  6106. + return IPKG_PKG_IS_ESSENTIAL;
  6107. + }
  6108. + }
  6109. +
  6110. + if ((parent_pkg = pkg->parent) == NULL)
  6111. + return 0;
  6112. +
  6113. + /* only attempt to remove dependent installed packages if
  6114. + * force_depends is not specified or the package is being
  6115. + * replaced.
  6116. + */
  6117. + if (!conf->force_depends
  6118. + && !(pkg->state_flag & SF_REPLACE)) {
  6119. + abstract_pkg_t **dependents;
  6120. + int has_installed_dependents =
  6121. + pkg_has_installed_dependents(pkg, &dependents);
  6122. +
  6123. + if (has_installed_dependents) {
  6124. + /*
  6125. + * if this package is depended up by others, then either we should
  6126. + * not remove it or we should remove it and all of its dependents
  6127. + */
  6128. +
  6129. + if (!conf->force_removal_of_dependent_packages
  6130. + && !user_prefers_removing_dependents(conf, pkg, dependents)) {
  6131. + return IPKG_PKG_HAS_DEPENDENTS;
  6132. + }
  6133. +
  6134. + /* remove packages depending on this package - Karthik */
  6135. + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
  6136. + free(dependents);
  6137. + if (err) return err;
  6138. + }
  6139. + }
  6140. +
  6141. + if ( message==0 ){
  6142. + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
  6143. + fflush(stdout);
  6144. + }
  6145. + pkg->state_flag |= SF_FILELIST_CHANGED;
  6146. +
  6147. + pkg->state_want = SW_DEINSTALL;
  6148. + ipkg_state_changed++;
  6149. +
  6150. + pkg_run_script(conf, pkg, "prerm", "remove");
  6151. +
  6152. + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
  6153. + maintains an empty filelist rather than deleting it. That seems
  6154. + like a big pain, and I don't see that that should make a big
  6155. + difference, but for anyone who wants tighter compatibility,
  6156. + feel free to fix this. */
  6157. + remove_data_files_and_list(conf, pkg);
  6158. +
  6159. + pkg_run_script(conf, pkg, "postrm", "remove");
  6160. +
  6161. + remove_maintainer_scripts_except_postrm(conf, pkg);
  6162. +
  6163. + /* Aman Gupta - Since ipkg is made for handheld devices with limited
  6164. + * space, it doesn't make sense to leave extra configurations, files,
  6165. + * and maintainer scripts left around. So, we make remove like purge,
  6166. + * and take out all the crap :) */
  6167. +
  6168. + remove_postrm(conf, pkg);
  6169. + pkg->state_status = SS_NOT_INSTALLED;
  6170. +
  6171. + if (parent_pkg)
  6172. + parent_pkg->state_status = SS_NOT_INSTALLED;
  6173. +
  6174. + return 0;
  6175. +}
  6176. +
  6177. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
  6178. +{
  6179. + ipkg_remove_pkg(conf, pkg,0);
  6180. + return 0;
  6181. +}
  6182. +
  6183. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
  6184. +{
  6185. + str_list_t installed_dirs;
  6186. + str_list_t *installed_files;
  6187. + str_list_elt_t *iter;
  6188. + char *file_name;
  6189. + conffile_t *conffile;
  6190. + int removed_a_dir;
  6191. + pkg_t *owner;
  6192. +
  6193. + str_list_init(&installed_dirs);
  6194. + installed_files = pkg_get_installed_files(pkg);
  6195. +
  6196. + for (iter = installed_files->head; iter; iter = iter->next) {
  6197. + file_name = iter->data;
  6198. +
  6199. + if (file_is_dir(file_name)) {
  6200. + str_list_append(&installed_dirs, strdup(file_name));
  6201. + continue;
  6202. + }
  6203. +
  6204. + conffile = pkg_get_conffile(pkg, file_name);
  6205. + if (conffile) {
  6206. + /* XXX: QUESTION: Is this right? I figure we only need to
  6207. + save the conffile if it has been modified. Is that what
  6208. + dpkg does? Or does dpkg preserve all conffiles? If so,
  6209. + this seems like a better thing to do to conserve
  6210. + space. */
  6211. + if (conffile_has_been_modified(conf, conffile)) {
  6212. + printf(" not deleting modified conffile %s\n", file_name);
  6213. + fflush(stdout);
  6214. + continue;
  6215. + }
  6216. + }
  6217. +
  6218. + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
  6219. + if (!conf->noaction)
  6220. + unlink(file_name);
  6221. + }
  6222. +
  6223. + if (!conf->noaction) {
  6224. + do {
  6225. + removed_a_dir = 0;
  6226. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6227. + file_name = iter->data;
  6228. +
  6229. + if (rmdir(file_name) == 0) {
  6230. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
  6231. + removed_a_dir = 1;
  6232. + str_list_remove(&installed_dirs, &iter);
  6233. + }
  6234. + }
  6235. + } while (removed_a_dir);
  6236. + }
  6237. +
  6238. + pkg_free_installed_files(pkg);
  6239. + /* We have to remove the file list now, so that
  6240. + find_pkg_owning_file does not always just report this package */
  6241. + pkg_remove_installed_files_list(conf, pkg);
  6242. +
  6243. + /* Don't print warning for dirs that are provided by other packages */
  6244. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6245. + file_name = iter->data;
  6246. +
  6247. + owner = file_hash_get_file_owner(conf, file_name);
  6248. + if (owner) {
  6249. + free(iter->data);
  6250. + iter->data = NULL;
  6251. + str_list_remove(&installed_dirs, &iter);
  6252. + }
  6253. + }
  6254. +
  6255. + /* cleanup */
  6256. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6257. + free(iter->data);
  6258. + iter->data = NULL;
  6259. + }
  6260. + str_list_deinit(&installed_dirs);
  6261. +
  6262. + return 0;
  6263. +}
  6264. +
  6265. +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6266. +{
  6267. + int i, err;
  6268. + char *globpattern;
  6269. + glob_t globbuf;
  6270. +
  6271. + if (conf->noaction) return 0;
  6272. +
  6273. + sprintf_alloc(&globpattern, "%s/%s.*",
  6274. + pkg->dest->info_dir, pkg->name);
  6275. + err = glob(globpattern, 0, NULL, &globbuf);
  6276. + free(globpattern);
  6277. + if (err) {
  6278. + return 0;
  6279. + }
  6280. +
  6281. + for (i = 0; i < globbuf.gl_pathc; i++) {
  6282. + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
  6283. + continue;
  6284. + }
  6285. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
  6286. + unlink(globbuf.gl_pathv[i]);
  6287. + }
  6288. + globfree(&globbuf);
  6289. +
  6290. + return 0;
  6291. +}
  6292. +
  6293. +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6294. +{
  6295. + char *postrm_file_name;
  6296. +
  6297. + if (conf->noaction) return 0;
  6298. +
  6299. + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
  6300. + pkg->dest->info_dir, pkg->name);
  6301. + unlink(postrm_file_name);
  6302. + free(postrm_file_name);
  6303. +
  6304. + return 0;
  6305. +}
  6306. diff -Nur busybox-1.22.1.orig/archival/libipkg/ipkg_remove.h busybox-1.22.1/archival/libipkg/ipkg_remove.h
  6307. --- busybox-1.22.1.orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
  6308. +++ busybox-1.22.1/archival/libipkg/ipkg_remove.h 2014-05-23 21:12:06.000000000 +0200
  6309. @@ -0,0 +1,33 @@
  6310. +/* ipkg_remove.h - the itsy package management system
  6311. +
  6312. + Carl D. Worth
  6313. +
  6314. + Copyright (C) 2001 University of Southern California
  6315. +
  6316. + This program is free software; you can redistribute it and/or
  6317. + modify it under the terms of the GNU General Public License as
  6318. + published by the Free Software Foundation; either version 2, or (at
  6319. + your option) any later version.
  6320. +
  6321. + This program is distributed in the hope that it will be useful, but
  6322. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6323. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6324. + General Public License for more details.
  6325. +*/
  6326. +
  6327. +#ifndef IPKG_REMOVE_H
  6328. +#define IPKG_REMOVE_H
  6329. +
  6330. +#include "pkg.h"
  6331. +#include "ipkg_conf.h"
  6332. +
  6333. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
  6334. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
  6335. +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
  6336. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents);
  6337. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
  6338. +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6339. +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6340. +
  6341. +
  6342. +#endif
  6343. diff -Nur busybox-1.22.1.orig/archival/libipkg/ipkg_upgrade.c busybox-1.22.1/archival/libipkg/ipkg_upgrade.c
  6344. --- busybox-1.22.1.orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
  6345. +++ busybox-1.22.1/archival/libipkg/ipkg_upgrade.c 2014-05-23 21:12:06.000000000 +0200
  6346. @@ -0,0 +1,79 @@
  6347. +/* ipkg_upgrade.c - the itsy package management system
  6348. +
  6349. + Carl D. Worth
  6350. + Copyright (C) 2001 University of Southern California
  6351. +
  6352. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6353. +
  6354. + This program is free software; you can redistribute it and/or
  6355. + modify it under the terms of the GNU General Public License as
  6356. + published by the Free Software Foundation; either version 2, or (at
  6357. + your option) any later version.
  6358. +
  6359. + This program is distributed in the hope that it will be useful, but
  6360. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6361. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6362. + General Public License for more details.
  6363. +*/
  6364. +
  6365. +#include "ipkg.h"
  6366. +#include "ipkg_install.h"
  6367. +#include "ipkg_message.h"
  6368. +
  6369. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6370. +
  6371. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
  6372. +{
  6373. + pkg_t *new;
  6374. + int cmp;
  6375. + char *old_version, *new_version;
  6376. +
  6377. + if (old->state_flag & SF_HOLD) {
  6378. + ipkg_message(conf, IPKG_NOTICE,
  6379. + "Not upgrading package %s which is marked "
  6380. + "hold (flags=%#x)\n", old->name, old->state_flag);
  6381. + return 0;
  6382. + }
  6383. +
  6384. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
  6385. + if (new == NULL) {
  6386. + old_version = pkg_version_str_alloc(old);
  6387. + ipkg_message(conf, IPKG_NOTICE,
  6388. + "Assuming locally installed package %s (%s) "
  6389. + "is up to date.\n", old->name, old_version);
  6390. + free(old_version);
  6391. + return 0;
  6392. + }
  6393. +
  6394. + old_version = pkg_version_str_alloc(old);
  6395. + new_version = pkg_version_str_alloc(new);
  6396. +
  6397. + cmp = pkg_compare_versions(old, new);
  6398. + ipkg_message(conf, IPKG_DEBUG,
  6399. + "comparing visible versions of pkg %s:"
  6400. + "\n\t%s is installed "
  6401. + "\n\t%s is available "
  6402. + "\n\t%d was comparison result\n",
  6403. + old->name, old_version, new_version, cmp);
  6404. + if (cmp == 0) {
  6405. + ipkg_message(conf, IPKG_INFO,
  6406. + "Package %s (%s) installed in %s is up to date.\n",
  6407. + old->name, old_version, old->dest->name);
  6408. + free(old_version);
  6409. + free(new_version);
  6410. + return 0;
  6411. + } else if (cmp > 0) {
  6412. + ipkg_message(conf, IPKG_NOTICE,
  6413. + "Not downgrading package %s on %s from %s to %s.\n",
  6414. + old->name, old->dest->name, old_version, new_version);
  6415. + free(old_version);
  6416. + free(new_version);
  6417. + return 0;
  6418. + } else if (cmp < 0) {
  6419. + new->dest = old->dest;
  6420. + old->state_want = SW_DEINSTALL;
  6421. + }
  6422. +
  6423. + new->state_flag |= SF_USER;
  6424. + return ipkg_install_pkg(conf, new,1);
  6425. +}
  6426. diff -Nur busybox-1.22.1.orig/archival/libipkg/ipkg_upgrade.h busybox-1.22.1/archival/libipkg/ipkg_upgrade.h
  6427. --- busybox-1.22.1.orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
  6428. +++ busybox-1.22.1/archival/libipkg/ipkg_upgrade.h 2014-05-23 21:12:06.000000000 +0200
  6429. @@ -0,0 +1,18 @@
  6430. +/* ipkg_upgrade.c - the itsy package management system
  6431. +
  6432. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6433. +
  6434. + This program is free software; you can redistribute it and/or
  6435. + modify it under the terms of the GNU General Public License as
  6436. + published by the Free Software Foundation; either version 2, or (at
  6437. + your option) any later version.
  6438. +
  6439. + This program is distributed in the hope that it will be useful, but
  6440. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6441. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6442. + General Public License for more details.
  6443. +*/
  6444. +
  6445. +#include "ipkg.h"
  6446. +
  6447. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6448. diff -Nur busybox-1.22.1.orig/archival/libipkg/ipkg_utils.c busybox-1.22.1/archival/libipkg/ipkg_utils.c
  6449. --- busybox-1.22.1.orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
  6450. +++ busybox-1.22.1/archival/libipkg/ipkg_utils.c 2014-05-23 21:12:06.000000000 +0200
  6451. @@ -0,0 +1,185 @@
  6452. +/* ipkg_utils.c - the itsy package management system
  6453. +
  6454. + Steven M. Ayer
  6455. +
  6456. + Copyright (C) 2002 Compaq Computer Corporation
  6457. +
  6458. + This program is free software; you can redistribute it and/or
  6459. + modify it under the terms of the GNU General Public License as
  6460. + published by the Free Software Foundation; either version 2, or (at
  6461. + your option) any later version.
  6462. +
  6463. + This program is distributed in the hope that it will be useful, but
  6464. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6465. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6466. + General Public License for more details.
  6467. +*/
  6468. +
  6469. +#include "ipkg.h"
  6470. +#include <errno.h>
  6471. +#include <ctype.h>
  6472. +#include <sys/vfs.h>
  6473. +
  6474. +#include "ipkg_utils.h"
  6475. +#include "pkg.h"
  6476. +#include "pkg_hash.h"
  6477. +
  6478. +void push_error_list(struct errlist ** errors, char * msg);
  6479. +void reverse_error_list(struct errlist **errors);
  6480. +void free_error_list(struct errlist **errors);
  6481. +
  6482. +struct errlist* error_list;
  6483. +
  6484. +int get_available_blocks(char * filesystem)
  6485. +{
  6486. + struct statfs sfs;
  6487. +
  6488. + if(statfs(filesystem, &sfs)){
  6489. + fprintf(stderr, "bad statfs\n");
  6490. + return 0;
  6491. + }
  6492. + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
  6493. + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
  6494. +}
  6495. +
  6496. +char **read_raw_pkgs_from_file(const char *file_name)
  6497. +{
  6498. + FILE *fp;
  6499. + char **ret;
  6500. +
  6501. + if(!(fp = fopen(file_name, "r"))){
  6502. + fprintf(stderr, "can't get %s open for read\n", file_name);
  6503. + return NULL;
  6504. + }
  6505. +
  6506. + ret = read_raw_pkgs_from_stream(fp);
  6507. +
  6508. + fclose(fp);
  6509. +
  6510. + return ret;
  6511. +}
  6512. +
  6513. +char **read_raw_pkgs_from_stream(FILE *fp)
  6514. +{
  6515. + char **raw = NULL, *buf, *scout;
  6516. + int count = 0;
  6517. + size_t size = 512;
  6518. +
  6519. + buf = malloc (size);
  6520. +
  6521. + while (fgets(buf, size, fp)) {
  6522. + while (strlen (buf) == (size - 1)
  6523. + && buf[size-2] != '\n') {
  6524. + size_t o = size - 1;
  6525. + size *= 2;
  6526. + buf = realloc (buf, size);
  6527. + if (fgets (buf + o, size - o, fp) == NULL)
  6528. + break;
  6529. + }
  6530. +
  6531. + if(!(count % 50))
  6532. + raw = realloc(raw, (count + 50) * sizeof(char *));
  6533. +
  6534. + if((scout = strchr(buf, '\n')))
  6535. + *scout = '\0';
  6536. +
  6537. + raw[count++] = strdup(buf);
  6538. + }
  6539. +
  6540. + raw = realloc(raw, (count + 1) * sizeof(char *));
  6541. + raw[count] = NULL;
  6542. +
  6543. + free (buf);
  6544. +
  6545. + return raw;
  6546. +}
  6547. +
  6548. +/* something to remove whitespace, a hash pooper */
  6549. +char *trim_alloc(char *line)
  6550. +{
  6551. + char *new;
  6552. + char *dest, *src, *end;
  6553. +
  6554. + new = malloc(strlen(line) + 1);
  6555. + if ( new == NULL ){
  6556. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  6557. + return NULL;
  6558. + }
  6559. + dest = new, src = line, end = line + (strlen(line) - 1);
  6560. +
  6561. + /* remove it from the front */
  6562. + while(src &&
  6563. + isspace(*src) &&
  6564. + *src)
  6565. + src++;
  6566. + /* and now from the back */
  6567. + while((end > src) &&
  6568. + isspace(*end))
  6569. + end--;
  6570. + end++;
  6571. + *end = '\0';
  6572. + strcpy(new, src);
  6573. + /* this does from the first space
  6574. + * blasting away any versions stuff in depends
  6575. + while(src &&
  6576. + !isspace(*src) &&
  6577. + *src)
  6578. + *dest++ = *src++;
  6579. + *dest = '\0';
  6580. + */
  6581. +
  6582. + return new;
  6583. +}
  6584. +
  6585. +int line_is_blank(const char *line)
  6586. +{
  6587. + const char *s;
  6588. +
  6589. + for (s = line; *s; s++) {
  6590. + if (!isspace(*s))
  6591. + return 0;
  6592. + }
  6593. + return 1;
  6594. +}
  6595. +
  6596. +void push_error_list(struct errlist ** errors, char * msg){
  6597. + struct errlist *err_lst_tmp;
  6598. +
  6599. +
  6600. + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
  6601. + err_lst_tmp->errmsg=strdup(msg) ;
  6602. + err_lst_tmp->next = *errors;
  6603. + *errors = err_lst_tmp;
  6604. +}
  6605. +
  6606. +
  6607. +void reverse_error_list(struct errlist **errors){
  6608. + struct errlist *result=NULL;
  6609. + struct errlist *current= *errors;
  6610. + struct errlist *next;
  6611. +
  6612. + while ( current != NULL ) {
  6613. + next = current->next;
  6614. + current->next=result;
  6615. + result=current;
  6616. + current=next;
  6617. + }
  6618. + *errors=result;
  6619. +
  6620. +}
  6621. +
  6622. +
  6623. +void free_error_list(struct errlist **errors){
  6624. + struct errlist *current = *errors;
  6625. +
  6626. + while (current != NULL) {
  6627. + free(current->errmsg);
  6628. + current = (*errors)->next;
  6629. + free(*errors);
  6630. + *errors = current;
  6631. + }
  6632. +
  6633. +
  6634. +}
  6635. +
  6636. +
  6637. diff -Nur busybox-1.22.1.orig/archival/libipkg/ipkg_utils.h busybox-1.22.1/archival/libipkg/ipkg_utils.h
  6638. --- busybox-1.22.1.orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
  6639. +++ busybox-1.22.1/archival/libipkg/ipkg_utils.h 2014-05-23 21:12:06.000000000 +0200
  6640. @@ -0,0 +1,29 @@
  6641. +/* ipkg_utils.h - the itsy package management system
  6642. +
  6643. + Steven M. Ayer
  6644. +
  6645. + Copyright (C) 2002 Compaq Computer Corporation
  6646. +
  6647. + This program is free software; you can redistribute it and/or
  6648. + modify it under the terms of the GNU General Public License as
  6649. + published by the Free Software Foundation; either version 2, or (at
  6650. + your option) any later version.
  6651. +
  6652. + This program is distributed in the hope that it will be useful, but
  6653. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6654. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6655. + General Public License for more details.
  6656. +*/
  6657. +
  6658. +#ifndef IPKG_UTILS_H
  6659. +#define IPKG_UTILS_H
  6660. +
  6661. +#include "pkg.h"
  6662. +
  6663. +int get_available_blocks(char * filesystem);
  6664. +char **read_raw_pkgs_from_file(const char *file_name);
  6665. +char **read_raw_pkgs_from_stream(FILE *fp);
  6666. +char *trim_alloc(char * line);
  6667. +int line_is_blank(const char *line);
  6668. +
  6669. +#endif
  6670. diff -Nur busybox-1.22.1.orig/archival/libipkg/libipkg.c busybox-1.22.1/archival/libipkg/libipkg.c
  6671. --- busybox-1.22.1.orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
  6672. +++ busybox-1.22.1/archival/libipkg/libipkg.c 2014-05-23 21:12:06.000000000 +0200
  6673. @@ -0,0 +1,583 @@
  6674. +/* ipkglib.c - the itsy package management system
  6675. +
  6676. + Florina Boor
  6677. +
  6678. + Copyright (C) 2003 kernel concepts
  6679. +
  6680. + This program is free software; you can redistribute it and/or
  6681. + modify it under the terms of the GNU General Public License as
  6682. + published by the Free Software Foundation; either version 2, or (at
  6683. + your option) any later version.
  6684. +
  6685. + This program is distributed in the hope that it will be useful, but
  6686. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6687. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6688. + General Public License for more details.
  6689. +*/
  6690. +
  6691. +#include "ipkg.h"
  6692. +#include "ipkg_includes.h"
  6693. +#include "libipkg.h"
  6694. +
  6695. +#include "args.h"
  6696. +#include "ipkg_conf.h"
  6697. +#include "ipkg_cmd.h"
  6698. +#include "file_util.h"
  6699. +
  6700. +int ipkg_file_what(args_t *args, const char *file, const char* command);
  6701. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  6702. + char *msg);
  6703. +int default_ipkg_list_callback(char *name, char *desc, char *version);
  6704. +int default_ipkg_files_callback(char *desc);
  6705. +int default_ipkg_status_callback(char *desc);
  6706. +char* default_ipkg_response_callback(char *question);
  6707. +
  6708. +
  6709. +ipkg_message_callback ipkg_cb_message = NULL;
  6710. +ipkg_response_callback ipkg_cb_response = NULL;
  6711. +ipkg_status_callback ipkg_cb_status = NULL;
  6712. +ipkg_list_callback ipkg_cb_list = NULL;
  6713. +
  6714. +
  6715. +int
  6716. +ipkg_init (ipkg_message_callback mcall,
  6717. + ipkg_response_callback rcall,
  6718. + args_t * args)
  6719. +{
  6720. + ipkg_cb_message = mcall;
  6721. + ipkg_cb_response = rcall;
  6722. +
  6723. + args_init (args);
  6724. +
  6725. + return 0;
  6726. +}
  6727. +
  6728. +
  6729. +int
  6730. +ipkg_deinit (args_t * args)
  6731. +{
  6732. + args_deinit (args);
  6733. + ipkg_cb_message = NULL;
  6734. + ipkg_cb_response = NULL;
  6735. +
  6736. + /* place other cleanup stuff here */
  6737. +
  6738. + return 0;
  6739. +}
  6740. +
  6741. +
  6742. +int
  6743. +ipkg_packages_list(args_t *args,
  6744. + const char *packages,
  6745. + ipkg_list_callback cblist,
  6746. + void *userdata)
  6747. +{
  6748. + ipkg_cmd_t *cmd;
  6749. + ipkg_conf_t ipkg_conf;
  6750. + int err;
  6751. +
  6752. + err = ipkg_conf_init (&ipkg_conf, args);
  6753. + if (err)
  6754. + {
  6755. + return err;
  6756. + }
  6757. +
  6758. + ipkg_cb_list = cblist;
  6759. + /* we need to do this because of static declarations,
  6760. + * maybe a good idea to change */
  6761. + cmd = ipkg_cmd_find ("list");
  6762. + if (packages)
  6763. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6764. + else
  6765. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6766. + ipkg_cb_list = NULL;
  6767. + ipkg_conf_deinit (&ipkg_conf);
  6768. + return (err);
  6769. +}
  6770. +
  6771. +
  6772. +int
  6773. +ipkg_packages_status(args_t *args,
  6774. + const char *packages,
  6775. + ipkg_status_callback cbstatus,
  6776. + void *userdata)
  6777. +{
  6778. + ipkg_cmd_t *cmd;
  6779. + ipkg_conf_t ipkg_conf;
  6780. + int err;
  6781. +
  6782. + err = ipkg_conf_init (&ipkg_conf, args);
  6783. + if (err)
  6784. + {
  6785. + return err;
  6786. + }
  6787. +
  6788. + ipkg_cb_status = cbstatus;
  6789. +
  6790. + /* we need to do this because of static declarations,
  6791. + * maybe a good idea to change */
  6792. + cmd = ipkg_cmd_find ("status");
  6793. + if (packages)
  6794. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6795. + else
  6796. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6797. +
  6798. + ipkg_cb_status = NULL;
  6799. + ipkg_conf_deinit (&ipkg_conf);
  6800. + return (err);
  6801. +}
  6802. +
  6803. +
  6804. +int
  6805. +ipkg_packages_info(args_t *args,
  6806. + const char *packages,
  6807. + ipkg_status_callback cbstatus,
  6808. + void *userdata)
  6809. +{
  6810. + ipkg_cmd_t *cmd;
  6811. + ipkg_conf_t ipkg_conf;
  6812. + int err;
  6813. +
  6814. + err = ipkg_conf_init (&ipkg_conf, args);
  6815. + if (err)
  6816. + {
  6817. + return err;
  6818. + }
  6819. +
  6820. + ipkg_cb_status = cbstatus;
  6821. +
  6822. + /* we need to do this because of static declarations,
  6823. + * maybe a good idea to change */
  6824. + cmd = ipkg_cmd_find ("info");
  6825. + if (packages)
  6826. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6827. + else
  6828. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6829. +
  6830. + ipkg_cb_status = NULL;
  6831. + ipkg_conf_deinit (&ipkg_conf);
  6832. + return (err);
  6833. +}
  6834. +
  6835. +
  6836. +int
  6837. +ipkg_packages_install (args_t * args, const char *name)
  6838. +{
  6839. + ipkg_cmd_t *cmd;
  6840. + ipkg_conf_t ipkg_conf;
  6841. + int err;
  6842. +
  6843. + /* this error should be handled in application */
  6844. + if (!name || !strlen (name))
  6845. + return (-1);
  6846. +
  6847. + err = ipkg_conf_init (&ipkg_conf, args);
  6848. + if (err)
  6849. + {
  6850. + return err;
  6851. + }
  6852. +
  6853. + /* we need to do this because of static declarations,
  6854. + * maybe a good idea to change */
  6855. + cmd = ipkg_cmd_find ("install");
  6856. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6857. +
  6858. + ipkg_conf_deinit(&ipkg_conf);
  6859. + return (err);
  6860. +}
  6861. +
  6862. +
  6863. +int
  6864. +ipkg_packages_remove(args_t *args, const char *name, int purge)
  6865. +{
  6866. + ipkg_cmd_t *cmd;
  6867. + ipkg_conf_t ipkg_conf;
  6868. + int err;
  6869. +
  6870. + /* this error should be handled in application */
  6871. + if (!name || !strlen (name))
  6872. + return (-1);
  6873. +
  6874. + err = ipkg_conf_init (&ipkg_conf, args);
  6875. + if (err)
  6876. + {
  6877. + return err;
  6878. + }
  6879. +
  6880. + /* we need to do this because of static declarations,
  6881. + * maybe a good idea to change */
  6882. + if (purge)
  6883. + cmd = ipkg_cmd_find ("purge");
  6884. + else
  6885. + cmd = ipkg_cmd_find ("remove");
  6886. +
  6887. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6888. +
  6889. + ipkg_conf_deinit(&ipkg_conf);
  6890. + return (err);
  6891. +}
  6892. +
  6893. +
  6894. +int
  6895. +ipkg_lists_update(args_t *args)
  6896. +{
  6897. + ipkg_cmd_t *cmd;
  6898. + ipkg_conf_t ipkg_conf;
  6899. + int err;
  6900. +
  6901. + err = ipkg_conf_init (&ipkg_conf, args);
  6902. + if (err)
  6903. + {
  6904. + return err;
  6905. + }
  6906. +
  6907. + /* we need to do this because of static declarations,
  6908. + * maybe a good idea to change */
  6909. + cmd = ipkg_cmd_find ("update");
  6910. +
  6911. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6912. +
  6913. + ipkg_conf_deinit(&ipkg_conf);
  6914. + return (err);
  6915. +}
  6916. +
  6917. +
  6918. +int
  6919. +ipkg_packages_upgrade(args_t *args)
  6920. +{
  6921. + ipkg_cmd_t *cmd;
  6922. + ipkg_conf_t ipkg_conf;
  6923. + int err;
  6924. +
  6925. + err = ipkg_conf_init (&ipkg_conf, args);
  6926. + if (err)
  6927. + {
  6928. + return err;
  6929. + }
  6930. +
  6931. + /* we need to do this because of static declarations,
  6932. + * maybe a good idea to change */
  6933. + cmd = ipkg_cmd_find ("upgrade");
  6934. +
  6935. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6936. +
  6937. + ipkg_conf_deinit(&ipkg_conf);
  6938. + return (err);
  6939. +}
  6940. +
  6941. +
  6942. +int
  6943. +ipkg_packages_download (args_t * args, const char *name)
  6944. +{
  6945. + ipkg_cmd_t *cmd;
  6946. + ipkg_conf_t ipkg_conf;
  6947. + int err;
  6948. +
  6949. + /* this error should be handled in application */
  6950. + if (!name || !strlen (name))
  6951. + return (-1);
  6952. +
  6953. + err = ipkg_conf_init (&ipkg_conf, args);
  6954. + if (err)
  6955. + {
  6956. + return err;
  6957. + }
  6958. +
  6959. + /* we need to do this because of static declarations,
  6960. + * maybe a good idea to change */
  6961. + cmd = ipkg_cmd_find ("download");
  6962. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6963. +
  6964. + ipkg_conf_deinit(&ipkg_conf);
  6965. + return (err);
  6966. +}
  6967. +
  6968. +
  6969. +int
  6970. +ipkg_package_files(args_t *args,
  6971. + const char *name,
  6972. + ipkg_list_callback cblist,
  6973. + void *userdata)
  6974. +{
  6975. + ipkg_cmd_t *cmd;
  6976. + ipkg_conf_t ipkg_conf;
  6977. + int err;
  6978. +
  6979. + /* this error should be handled in application */
  6980. + if (!name || !strlen (name))
  6981. + return (-1);
  6982. +
  6983. + err = ipkg_conf_init (&ipkg_conf, args);
  6984. + if (err)
  6985. + {
  6986. + return err;
  6987. + }
  6988. +
  6989. + ipkg_cb_list = cblist;
  6990. +
  6991. + /* we need to do this because of static declarations,
  6992. + * maybe a good idea to change */
  6993. + cmd = ipkg_cmd_find ("files");
  6994. +
  6995. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
  6996. +
  6997. + ipkg_cb_list = NULL;
  6998. + ipkg_conf_deinit(&ipkg_conf);
  6999. + return (err);
  7000. +}
  7001. +
  7002. +
  7003. +int
  7004. +ipkg_file_search(args_t *args,
  7005. + const char *file,
  7006. + ipkg_list_callback cblist,
  7007. + void *userdata)
  7008. +{
  7009. + ipkg_cmd_t *cmd;
  7010. + ipkg_conf_t ipkg_conf;
  7011. + int err;
  7012. +
  7013. + /* this error should be handled in application */
  7014. + if (!file || !strlen (file))
  7015. + return (-1);
  7016. +
  7017. + err = ipkg_conf_init (&ipkg_conf, args);
  7018. + if (err)
  7019. + {
  7020. + return err;
  7021. + }
  7022. +
  7023. + ipkg_cb_list = cblist;
  7024. +
  7025. + /* we need to do this because of static declarations,
  7026. + * maybe a good idea to change */
  7027. + cmd = ipkg_cmd_find ("search");
  7028. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
  7029. +
  7030. + ipkg_cb_list = NULL;
  7031. + ipkg_conf_deinit(&ipkg_conf);
  7032. + return(err);
  7033. +}
  7034. +
  7035. +
  7036. +int
  7037. +ipkg_file_what(args_t *args, const char *file, const char* command)
  7038. +{
  7039. + ipkg_cmd_t *cmd;
  7040. + ipkg_conf_t ipkg_conf;
  7041. + int err;
  7042. +
  7043. + /* this error should be handled in application */
  7044. + if (!file || !strlen (file))
  7045. + return (-1);
  7046. +
  7047. + err = ipkg_conf_init (&ipkg_conf, args);
  7048. + if (err)
  7049. + {
  7050. + return err;
  7051. + }
  7052. +
  7053. + /* we need to do this because of static declarations,
  7054. + * maybe a good idea to change */
  7055. + cmd = ipkg_cmd_find (command);
  7056. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
  7057. +
  7058. + ipkg_conf_deinit(&ipkg_conf);
  7059. + return(err);
  7060. +}
  7061. +
  7062. +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
  7063. +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
  7064. +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
  7065. +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
  7066. +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
  7067. +
  7068. +
  7069. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  7070. + char *msg)
  7071. +{
  7072. + if (conf && (conf->verbosity < level)) {
  7073. + return 0;
  7074. + } else {
  7075. + if ( level == IPKG_ERROR )
  7076. + push_error_list(&error_list, msg);
  7077. + else
  7078. + printf(msg);
  7079. + }
  7080. + return 0;
  7081. +}
  7082. +
  7083. +int default_ipkg_list_callback(char *name, char *desc, char *version)
  7084. +{
  7085. + if (desc)
  7086. + printf("%s - %s - %s\n", name, version, desc);
  7087. + else
  7088. + printf("%s - %s\n", name, version);
  7089. + return 0;
  7090. +}
  7091. +
  7092. +int default_ipkg_files_callback(char *desc)
  7093. +{
  7094. + if (desc)
  7095. + printf("%s\n", desc);
  7096. + return 0;
  7097. +}
  7098. +
  7099. +int default_ipkg_status_callback(char *desc)
  7100. +{
  7101. + printf("%s\n", desc);
  7102. + return 0;
  7103. +}
  7104. +
  7105. +char* default_ipkg_response_callback(char *question)
  7106. +{
  7107. + char *response = NULL;
  7108. + printf(question);
  7109. + fflush(stdout);
  7110. + do {
  7111. + response = (char *)file_read_line_alloc(stdin);
  7112. + } while (response == NULL);
  7113. + return response;
  7114. +}
  7115. +
  7116. +/* This is used for backward compatibility */
  7117. +int
  7118. +ipkg_op (int argc, char *argv[])
  7119. +{
  7120. + int err, optind_;
  7121. + args_t args;
  7122. + char *cmd_name;
  7123. + ipkg_cmd_t *cmd;
  7124. + ipkg_conf_t ipkg_conf;
  7125. + const char *message = "ipkg must have one sub-command argument";
  7126. + FILE *f;
  7127. + struct mntent *mnt;
  7128. + int remountroot;
  7129. +
  7130. + args_init (&args);
  7131. +
  7132. + optind_ = args_parse (&args, argc, argv);
  7133. + if (optind_ == argc || optind_ < 0)
  7134. + {
  7135. + args_usage(message);
  7136. + }
  7137. +
  7138. + cmd_name = argv[optind_++];
  7139. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  7140. + read anything from there.
  7141. +*/
  7142. + if ( !strcmp(cmd_name,"print-architecture") ||
  7143. + !strcmp(cmd_name,"print_architecture") ||
  7144. + !strcmp(cmd_name,"print-installation-architecture") ||
  7145. + !strcmp(cmd_name,"print_installation_architecture") )
  7146. + args.nocheckfordirorfile = 1;
  7147. +
  7148. +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
  7149. + read anything from there.
  7150. +*/
  7151. + if ( !strcmp(cmd_name,"flag") ||
  7152. + !strcmp(cmd_name,"configure") ||
  7153. + !strcmp(cmd_name,"remove") ||
  7154. + !strcmp(cmd_name,"files") ||
  7155. + !strcmp(cmd_name,"search") ||
  7156. + !strcmp(cmd_name,"compare_versions") ||
  7157. + !strcmp(cmd_name,"compare-versions") ||
  7158. + !strcmp(cmd_name,"list_installed") ||
  7159. + !strcmp(cmd_name,"list-installed") ||
  7160. + !strcmp(cmd_name,"status") )
  7161. + args.noreadfeedsfile = 1;
  7162. +
  7163. +
  7164. +
  7165. +
  7166. + err = ipkg_conf_init (&ipkg_conf, &args);
  7167. + if (err)
  7168. + {
  7169. + return err;
  7170. + }
  7171. +
  7172. + args_deinit (&args);
  7173. +
  7174. + ipkg_cb_message = default_ipkg_message_callback;
  7175. + ipkg_cb_response = default_ipkg_response_callback;
  7176. + ipkg_cb_status = (ipkg_status_callback)default_ipkg_status_callback;
  7177. + if ( strcmp(cmd_name, "files")==0)
  7178. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_files_callback;
  7179. + else
  7180. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_list_callback;
  7181. +
  7182. + cmd = ipkg_cmd_find (cmd_name);
  7183. + if (cmd == NULL)
  7184. + {
  7185. + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
  7186. + cmd_name);
  7187. + args_usage (NULL);
  7188. + }
  7189. +
  7190. + if (cmd->requires_args && optind_ == argc)
  7191. + {
  7192. + fprintf (stderr,
  7193. + "%s: the ``%s'' command requires at least one argument\n",
  7194. + __FUNCTION__, cmd_name);
  7195. + args_usage (NULL);
  7196. + }
  7197. +
  7198. + remountroot = 0;
  7199. + /* check if /dev/root is mounted read-only */
  7200. + if ((f = setmntent("/proc/mounts", "r")) == NULL)
  7201. + fprintf (stderr, "Checking /proc/mounts failed\n");
  7202. +
  7203. + while ((mnt = getmntent(f)) != NULL) {
  7204. + if (strcmp(mnt->mnt_fsname, "/dev/root") == 0 &&
  7205. + hasmntopt(mnt, MNTOPT_RO) != NULL) {
  7206. + remountroot = 1;
  7207. + }
  7208. + }
  7209. +
  7210. + endmntent(f);
  7211. +
  7212. + if (remountroot) {
  7213. + if ( !strcmp(cmd_name,"install") ||
  7214. + !strcmp(cmd_name,"update") ||
  7215. + !strcmp(cmd_name,"upgrade") ||
  7216. + !strcmp(cmd_name,"flag") ||
  7217. + !strcmp(cmd_name,"configure") ||
  7218. + !strcmp(cmd_name,"remove") ) {
  7219. + /* mount rootfs read-write */
  7220. + if (mount("","/",0,MS_REMOUNT,0)<0)
  7221. + fprintf (stderr, "Mounting rootfs read-write failed\n");
  7222. + }
  7223. + }
  7224. +
  7225. + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind_, (const char **) (argv + optind_), NULL);
  7226. +
  7227. + ipkg_conf_deinit (&ipkg_conf);
  7228. +
  7229. + if (remountroot) {
  7230. + if ( !strcmp(cmd_name,"install") ||
  7231. + !strcmp(cmd_name,"update") ||
  7232. + !strcmp(cmd_name,"upgrade") ||
  7233. + !strcmp(cmd_name,"flag") ||
  7234. + !strcmp(cmd_name,"configure") ||
  7235. + !strcmp(cmd_name,"remove") ) {
  7236. + sync();
  7237. + /* mount rootfs read-only */
  7238. + if (mount("","/",0,MS_REMOUNT|MS_RDONLY,0)<0)
  7239. + fprintf (stderr, "Mounting rootfs read-only failed\n");
  7240. + }
  7241. + }
  7242. +
  7243. + /* check if cfgfs exists */
  7244. + if (access("/sbin/cfgfs", X_OK) == 0) {
  7245. + if ( !strcmp(cmd_name,"install") ||
  7246. + !strcmp(cmd_name,"update") ||
  7247. + !strcmp(cmd_name,"upgrade")) {
  7248. + if (system("cfgfs status -q") != 0) {
  7249. + fprintf (stdout, "Updates in /etc, please review changes\n");
  7250. + fprintf (stdout, "You can check via cfgfs status\n");
  7251. + }
  7252. + }
  7253. + }
  7254. +
  7255. + return err;
  7256. +}
  7257. diff -Nur busybox-1.22.1.orig/archival/libipkg/libipkg.h busybox-1.22.1/archival/libipkg/libipkg.h
  7258. --- busybox-1.22.1.orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
  7259. +++ busybox-1.22.1/archival/libipkg/libipkg.h 2014-05-23 21:12:06.000000000 +0200
  7260. @@ -0,0 +1,78 @@
  7261. +/* ipkglib.h - the itsy package management system
  7262. +
  7263. + Florian Boor <florian.boor@kernelconcepts.de>
  7264. +
  7265. + This program is free software; you can redistribute it and/or
  7266. + modify it under the terms of the GNU General Public License as
  7267. + published by the Free Software Foundation; either version 2, or (at
  7268. + your option) any later version.
  7269. +
  7270. + This program is distributed in the hope that it will be useful, but
  7271. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7272. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7273. + General Public License for more details.
  7274. +*/
  7275. +
  7276. +#ifndef IPKGLIB_H
  7277. +#define IPKGLIB_H
  7278. +
  7279. +#include "ipkg_conf.h"
  7280. +#include "ipkg_message.h"
  7281. +
  7282. +#include "args.h"
  7283. +#include "pkg.h"
  7284. +
  7285. +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
  7286. + char *msg);
  7287. +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
  7288. + pkg_state_status_t status, void *userdata);
  7289. +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
  7290. + void *userdata);
  7291. +typedef char* (*ipkg_response_callback)(char *question);
  7292. +
  7293. +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
  7294. +extern int ipkg_init (ipkg_message_callback mcall,
  7295. + ipkg_response_callback rcall,
  7296. + args_t * args);
  7297. +
  7298. +extern int ipkg_deinit (args_t *args);
  7299. +extern int ipkg_packages_list(args_t *args,
  7300. + const char *packages,
  7301. + ipkg_list_callback cblist,
  7302. + void *userdata);
  7303. +extern int ipkg_packages_status(args_t *args,
  7304. + const char *packages,
  7305. + ipkg_status_callback cbstatus,
  7306. + void *userdata);
  7307. +extern int ipkg_packages_info(args_t *args,
  7308. + const char *packages,
  7309. + ipkg_status_callback cbstatus,
  7310. + void *userdata);
  7311. +extern int ipkg_packages_install(args_t *args, const char *name);
  7312. +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
  7313. +extern int ipkg_lists_update(args_t *args);
  7314. +extern int ipkg_packages_upgrade(args_t *args);
  7315. +extern int ipkg_packages_download(args_t *args, const char *name);
  7316. +extern int ipkg_package_files(args_t *args,
  7317. + const char *name,
  7318. + ipkg_list_callback cblist,
  7319. + void *userdata);
  7320. +extern int ipkg_file_search(args_t *args,
  7321. + const char *file,
  7322. + ipkg_list_callback cblist,
  7323. + void *userdata);
  7324. +extern int ipkg_package_whatdepends(args_t *args, const char *file);
  7325. +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
  7326. +extern int ipkg_package_whatprovides(args_t *args, const char *file);
  7327. +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
  7328. +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
  7329. +
  7330. +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
  7331. +extern ipkg_response_callback ipkg_cb_response;
  7332. +extern ipkg_status_callback ipkg_cb_status;
  7333. +extern ipkg_list_callback ipkg_cb_list;
  7334. +extern void push_error_list(struct errlist **errors,char * msg);
  7335. +extern void reverse_error_list(struct errlist **errors);
  7336. +extern void free_error_list(struct errlist **errors);
  7337. +
  7338. +#endif
  7339. diff -Nur busybox-1.22.1.orig/archival/libipkg/nv_pair.c busybox-1.22.1/archival/libipkg/nv_pair.c
  7340. --- busybox-1.22.1.orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
  7341. +++ busybox-1.22.1/archival/libipkg/nv_pair.c 2014-05-23 21:12:06.000000000 +0200
  7342. @@ -0,0 +1,40 @@
  7343. +/* nv_pair.c - the itsy package management system
  7344. +
  7345. + Carl D. Worth
  7346. +
  7347. + Copyright (C) 2001 University of Southern California
  7348. +
  7349. + This program is free software; you can redistribute it and/or
  7350. + modify it under the terms of the GNU General Public License as
  7351. + published by the Free Software Foundation; either version 2, or (at
  7352. + your option) any later version.
  7353. +
  7354. + This program is distributed in the hope that it will be useful, but
  7355. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7356. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7357. + General Public License for more details.
  7358. +*/
  7359. +
  7360. +#include "ipkg.h"
  7361. +
  7362. +#include "nv_pair.h"
  7363. +#include "str_util.h"
  7364. +
  7365. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
  7366. +{
  7367. + nv_pair->name = str_dup_safe(name);
  7368. + nv_pair->value = str_dup_safe(value);
  7369. +
  7370. + return 0;
  7371. +}
  7372. +
  7373. +void nv_pair_deinit(nv_pair_t *nv_pair)
  7374. +{
  7375. + free(nv_pair->name);
  7376. + nv_pair->name = NULL;
  7377. +
  7378. + free(nv_pair->value);
  7379. + nv_pair->value = NULL;
  7380. +}
  7381. +
  7382. +
  7383. diff -Nur busybox-1.22.1.orig/archival/libipkg/nv_pair.h busybox-1.22.1/archival/libipkg/nv_pair.h
  7384. --- busybox-1.22.1.orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
  7385. +++ busybox-1.22.1/archival/libipkg/nv_pair.h 2014-05-23 21:12:06.000000000 +0200
  7386. @@ -0,0 +1,32 @@
  7387. +/* nv_pair.h - the itsy package management system
  7388. +
  7389. + Carl D. Worth
  7390. +
  7391. + Copyright (C) 2001 University of Southern California
  7392. +
  7393. + This program is free software; you can redistribute it and/or
  7394. + modify it under the terms of the GNU General Public License as
  7395. + published by the Free Software Foundation; either version 2, or (at
  7396. + your option) any later version.
  7397. +
  7398. + This program is distributed in the hope that it will be useful, but
  7399. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7400. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7401. + General Public License for more details.
  7402. +*/
  7403. +
  7404. +#ifndef NV_PAIR_H
  7405. +#define NV_PAIR_H
  7406. +
  7407. +typedef struct nv_pair nv_pair_t;
  7408. +struct nv_pair
  7409. +{
  7410. + char *name;
  7411. + char *value;
  7412. +};
  7413. +
  7414. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
  7415. +void nv_pair_deinit(nv_pair_t *nv_pair);
  7416. +
  7417. +#endif
  7418. +
  7419. diff -Nur busybox-1.22.1.orig/archival/libipkg/nv_pair_list.c busybox-1.22.1/archival/libipkg/nv_pair_list.c
  7420. --- busybox-1.22.1.orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
  7421. +++ busybox-1.22.1/archival/libipkg/nv_pair_list.c 2014-05-23 21:12:06.000000000 +0200
  7422. @@ -0,0 +1,98 @@
  7423. +/* nv_pair_list.c - the itsy package management system
  7424. +
  7425. + Carl D. Worth
  7426. +
  7427. + Copyright (C) 2001 University of Southern California
  7428. +
  7429. + This program is free software; you can redistribute it and/or
  7430. + modify it under the terms of the GNU General Public License as
  7431. + published by the Free Software Foundation; either version 2, or (at
  7432. + your option) any later version.
  7433. +
  7434. + This program is distributed in the hope that it will be useful, but
  7435. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7436. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7437. + General Public License for more details.
  7438. +*/
  7439. +
  7440. +#include "ipkg.h"
  7441. +
  7442. +#include "nv_pair.h"
  7443. +#include "void_list.h"
  7444. +#include "nv_pair_list.h"
  7445. +
  7446. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
  7447. +{
  7448. + return void_list_elt_init((void_list_elt_t *) elt, data);
  7449. +}
  7450. +
  7451. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
  7452. +{
  7453. + void_list_elt_deinit((void_list_elt_t *) elt);
  7454. +}
  7455. +
  7456. +int nv_pair_list_init(nv_pair_list_t *list)
  7457. +{
  7458. + return void_list_init((void_list_t *) list);
  7459. +}
  7460. +
  7461. +void nv_pair_list_deinit(nv_pair_list_t *list)
  7462. +{
  7463. + nv_pair_list_elt_t *iter;
  7464. + nv_pair_t *nv_pair;
  7465. +
  7466. + for (iter = list->head; iter; iter = iter->next) {
  7467. + nv_pair = iter->data;
  7468. + nv_pair_deinit(nv_pair);
  7469. +
  7470. + /* malloced in nv_pair_list_append */
  7471. + free(nv_pair);
  7472. + iter->data = NULL;
  7473. + }
  7474. + void_list_deinit((void_list_t *) list);
  7475. +}
  7476. +
  7477. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
  7478. +{
  7479. + int err;
  7480. +
  7481. + /* freed in nv_pair_list_deinit */
  7482. + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
  7483. +
  7484. + if (nv_pair == NULL) {
  7485. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7486. + return NULL;
  7487. + }
  7488. + nv_pair_init(nv_pair, name, value);
  7489. +
  7490. + err = void_list_append((void_list_t *) list, nv_pair);
  7491. + if (err) {
  7492. + return NULL;
  7493. + }
  7494. +
  7495. + return nv_pair;
  7496. +}
  7497. +
  7498. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
  7499. +{
  7500. + return void_list_push((void_list_t *) list, data);
  7501. +}
  7502. +
  7503. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
  7504. +{
  7505. + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
  7506. +}
  7507. +
  7508. +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
  7509. +{
  7510. + nv_pair_list_elt_t *iter;
  7511. + nv_pair_t *nv_pair;
  7512. +
  7513. + for (iter = list->head; iter; iter = iter->next) {
  7514. + nv_pair = iter->data;
  7515. + if (strcmp(nv_pair->name, name) == 0) {
  7516. + return nv_pair->value;
  7517. + }
  7518. + }
  7519. + return NULL;
  7520. +}
  7521. diff -Nur busybox-1.22.1.orig/archival/libipkg/nv_pair_list.h busybox-1.22.1/archival/libipkg/nv_pair_list.h
  7522. --- busybox-1.22.1.orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
  7523. +++ busybox-1.22.1/archival/libipkg/nv_pair_list.h 2014-05-23 21:12:06.000000000 +0200
  7524. @@ -0,0 +1,60 @@
  7525. +/* nv_pair_list.h - the itsy package management system
  7526. +
  7527. + Carl D. Worth
  7528. +
  7529. + Copyright (C) 2001 University of Southern California
  7530. +
  7531. + This program is free software; you can redistribute it and/or
  7532. + modify it under the terms of the GNU General Public License as
  7533. + published by the Free Software Foundation; either version 2, or (at
  7534. + your option) any later version.
  7535. +
  7536. + This program is distributed in the hope that it will be useful, but
  7537. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7538. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7539. + General Public License for more details.
  7540. +*/
  7541. +
  7542. +#ifndef NV_PAIR_LIST_H
  7543. +#define NV_PAIR_LIST_H
  7544. +
  7545. +#include "nv_pair.h"
  7546. +#include "void_list.h"
  7547. +
  7548. +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
  7549. +struct nv_pair_list_elt
  7550. +{
  7551. + nv_pair_list_elt_t *next;
  7552. + nv_pair_t *data;
  7553. +};
  7554. +
  7555. +typedef struct nv_pair_list nv_pair_list_t;
  7556. +struct nv_pair_list
  7557. +{
  7558. + nv_pair_list_elt_t pre_head;
  7559. + nv_pair_list_elt_t *head;
  7560. + nv_pair_list_elt_t *tail;
  7561. +};
  7562. +
  7563. +static inline int nv_pair_list_empty(nv_pair_list_t *list)
  7564. +{
  7565. + if (list->head == NULL)
  7566. + return 1;
  7567. + else
  7568. + return 0;
  7569. +}
  7570. +
  7571. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
  7572. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
  7573. +
  7574. +int nv_pair_list_init(nv_pair_list_t *list);
  7575. +void nv_pair_list_deinit(nv_pair_list_t *list);
  7576. +
  7577. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
  7578. + const char *name, const char *value);
  7579. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
  7580. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
  7581. +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
  7582. +
  7583. +#endif
  7584. +
  7585. diff -Nur busybox-1.22.1.orig/archival/libipkg/pkg.c busybox-1.22.1/archival/libipkg/pkg.c
  7586. --- busybox-1.22.1.orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
  7587. +++ busybox-1.22.1/archival/libipkg/pkg.c 2014-05-23 21:12:06.000000000 +0200
  7588. @@ -0,0 +1,1757 @@
  7589. +/* pkg.c - the itsy package management system
  7590. +
  7591. + Carl D. Worth
  7592. +
  7593. + Copyright (C) 2001 University of Southern California
  7594. +
  7595. + This program is free software; you can redistribute it and/or
  7596. + modify it under the terms of the GNU General Public License as
  7597. + published by the Free Software Foundation; either version 2, or (at
  7598. + your option) any later version.
  7599. +
  7600. + This program is distributed in the hope that it will be useful, but
  7601. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7602. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7603. + General Public License for more details.
  7604. +*/
  7605. +
  7606. +#include "ipkg.h"
  7607. +#include <ctype.h>
  7608. +#include <string.h>
  7609. +#include <errno.h>
  7610. +
  7611. +#include "pkg.h"
  7612. +
  7613. +#include "pkg_parse.h"
  7614. +#include "pkg_extract.h"
  7615. +#include "ipkg_message.h"
  7616. +#include "ipkg_utils.h"
  7617. +
  7618. +#include "sprintf_alloc.h"
  7619. +#include "file_util.h"
  7620. +#include "str_util.h"
  7621. +#include "xsystem.h"
  7622. +#include "ipkg_conf.h"
  7623. +
  7624. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname);
  7625. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_);
  7626. +
  7627. +typedef struct enum_map enum_map_t;
  7628. +struct enum_map
  7629. +{
  7630. + int value;
  7631. + const char *str;
  7632. +};
  7633. +
  7634. +static const enum_map_t pkg_state_want_map[] = {
  7635. + { SW_UNKNOWN, "unknown"},
  7636. + { SW_INSTALL, "install"},
  7637. + { SW_DEINSTALL, "deinstall"},
  7638. + { SW_PURGE, "purge"}
  7639. +};
  7640. +
  7641. +static const enum_map_t pkg_state_flag_map[] = {
  7642. + { SF_OK, "ok"},
  7643. + { SF_REINSTREQ, "reinstreq"},
  7644. + { SF_HOLD, "hold"},
  7645. + { SF_REPLACE, "replace"},
  7646. + { SF_NOPRUNE, "noprune"},
  7647. + { SF_PREFER, "prefer"},
  7648. + { SF_OBSOLETE, "obsolete"},
  7649. + { SF_USER, "user"},
  7650. +};
  7651. +
  7652. +static const enum_map_t pkg_state_status_map[] = {
  7653. + { SS_NOT_INSTALLED, "not-installed" },
  7654. + { SS_UNPACKED, "unpacked" },
  7655. + { SS_HALF_CONFIGURED, "half-configured" },
  7656. + { SS_INSTALLED, "installed" },
  7657. + { SS_HALF_INSTALLED, "half-installed" },
  7658. + { SS_CONFIG_FILES, "config-files" },
  7659. + { SS_POST_INST_FAILED, "post-inst-failed" },
  7660. + { SS_REMOVAL_FAILED, "removal-failed" }
  7661. +};
  7662. +
  7663. +static int verrevcmp(const char *val, const char *ref);
  7664. +
  7665. +
  7666. +pkg_t *pkg_new(void)
  7667. +{
  7668. + pkg_t *pkg;
  7669. +
  7670. + pkg = malloc(sizeof(pkg_t));
  7671. + if (pkg == NULL) {
  7672. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7673. + return NULL;
  7674. + }
  7675. +
  7676. + pkg_init(pkg);
  7677. +
  7678. + return pkg;
  7679. +}
  7680. +
  7681. +int pkg_init(pkg_t *pkg)
  7682. +{
  7683. + memset(pkg, 0, sizeof(pkg_t));
  7684. + pkg->name = NULL;
  7685. + pkg->epoch = 0;
  7686. + pkg->version = NULL;
  7687. + pkg->revision = NULL;
  7688. + pkg->familiar_revision = NULL;
  7689. + pkg->dest = NULL;
  7690. + pkg->src = NULL;
  7691. + pkg->architecture = NULL;
  7692. + pkg->maintainer = NULL;
  7693. + pkg->section = NULL;
  7694. + pkg->description = NULL;
  7695. + pkg->state_want = SW_UNKNOWN;
  7696. + pkg->state_flag = SF_OK;
  7697. + pkg->state_status = SS_NOT_INSTALLED;
  7698. + pkg->depends_str = NULL;
  7699. + pkg->provides_str = NULL;
  7700. + pkg->depends_count = 0;
  7701. + pkg->depends = NULL;
  7702. + pkg->suggests_str = NULL;
  7703. + pkg->recommends_str = NULL;
  7704. + pkg->suggests_count = 0;
  7705. + pkg->recommends_count = 0;
  7706. +
  7707. + /* Abhaya: added init for conflicts fields */
  7708. + pkg->conflicts = NULL;
  7709. + pkg->conflicts_count = 0;
  7710. +
  7711. + /* added for replaces. Jamey 7/23/2002 */
  7712. + pkg->replaces = NULL;
  7713. + pkg->replaces_count = 0;
  7714. +
  7715. + pkg->pre_depends_count = 0;
  7716. + pkg->pre_depends_str = NULL;
  7717. + pkg->provides_count = 0;
  7718. + pkg->provides = NULL;
  7719. + pkg->filename = NULL;
  7720. + pkg->local_filename = NULL;
  7721. + pkg->tmp_unpack_dir = NULL;
  7722. + pkg->md5sum = NULL;
  7723. + pkg->size = NULL;
  7724. + pkg->installed_size = NULL;
  7725. + pkg->priority = NULL;
  7726. + pkg->source = NULL;
  7727. + conffile_list_init(&pkg->conffiles);
  7728. + pkg->installed_files = NULL;
  7729. + pkg->installed_files_ref_cnt = 0;
  7730. + pkg->essential = 0;
  7731. + pkg->provided_by_hand = 0;
  7732. +
  7733. + return 0;
  7734. +}
  7735. +
  7736. +void pkg_deinit(pkg_t *pkg)
  7737. +{
  7738. + free(pkg->name);
  7739. + pkg->name = NULL;
  7740. + pkg->epoch = 0;
  7741. + free(pkg->version);
  7742. + pkg->version = NULL;
  7743. + /* revision and familiar_revision share storage with version, so
  7744. + don't free */
  7745. + pkg->revision = NULL;
  7746. + pkg->familiar_revision = NULL;
  7747. + /* owned by ipkg_conf_t */
  7748. + pkg->dest = NULL;
  7749. + /* owned by ipkg_conf_t */
  7750. + pkg->src = NULL;
  7751. + free(pkg->architecture);
  7752. + pkg->architecture = NULL;
  7753. + free(pkg->maintainer);
  7754. + pkg->maintainer = NULL;
  7755. + free(pkg->section);
  7756. + pkg->section = NULL;
  7757. + free(pkg->description);
  7758. + pkg->description = NULL;
  7759. + pkg->state_want = SW_UNKNOWN;
  7760. + pkg->state_flag = SF_OK;
  7761. + pkg->state_status = SS_NOT_INSTALLED;
  7762. + free(pkg->depends_str);
  7763. + pkg->depends_str = NULL;
  7764. + free(pkg->provides_str);
  7765. + pkg->provides_str = NULL;
  7766. + pkg->depends_count = 0;
  7767. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
  7768. + pkg->pre_depends_count = 0;
  7769. + free(pkg->pre_depends_str);
  7770. + pkg->pre_depends_str = NULL;
  7771. + pkg->provides_count = 0;
  7772. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
  7773. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
  7774. + free(pkg->filename);
  7775. + pkg->filename = NULL;
  7776. + free(pkg->local_filename);
  7777. + pkg->local_filename = NULL;
  7778. + /* CLEANUP: It'd be nice to pullin the cleanup function from
  7779. + ipkg_install.c here. See comment in
  7780. + ipkg_install.c:cleanup_temporary_files */
  7781. + free(pkg->tmp_unpack_dir);
  7782. + pkg->tmp_unpack_dir = NULL;
  7783. + free(pkg->md5sum);
  7784. + pkg->md5sum = NULL;
  7785. + free(pkg->size);
  7786. + pkg->size = NULL;
  7787. + free(pkg->installed_size);
  7788. + pkg->installed_size = NULL;
  7789. + free(pkg->priority);
  7790. + pkg->priority = NULL;
  7791. + free(pkg->source);
  7792. + pkg->source = NULL;
  7793. + conffile_list_deinit(&pkg->conffiles);
  7794. + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
  7795. + since if they are calling deinit, they should know. Maybe do an
  7796. + assertion here instead? */
  7797. + pkg->installed_files_ref_cnt = 1;
  7798. + pkg_free_installed_files(pkg);
  7799. + pkg->essential = 0;
  7800. +}
  7801. +
  7802. +int pkg_init_from_file(pkg_t *pkg, const char *filename)
  7803. +{
  7804. + int err;
  7805. + char **raw;
  7806. + FILE *control_file;
  7807. +
  7808. + err = pkg_init(pkg);
  7809. + if (err) { return err; }
  7810. +
  7811. + pkg->local_filename = strdup(filename);
  7812. +
  7813. + control_file = tmpfile();
  7814. + err = pkg_extract_control_file_to_stream(pkg, control_file);
  7815. + if (err) { return err; }
  7816. +
  7817. + rewind(control_file);
  7818. + raw = read_raw_pkgs_from_stream(control_file);
  7819. + pkg_parse_raw(pkg, &raw, NULL, NULL);
  7820. +
  7821. + fclose(control_file);
  7822. +
  7823. + return 0;
  7824. +}
  7825. +
  7826. +/* Merge any new information in newpkg into oldpkg */
  7827. +/* XXX: CLEANUP: This function shouldn't actually modify anything in
  7828. + newpkg, but should leave it usable. This rework is so that
  7829. + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
  7830. +/*
  7831. + * uh, i thought that i had originally written this so that it took
  7832. + * two pkgs and returned a new one? we can do that again... -sma
  7833. + */
  7834. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
  7835. +{
  7836. + if (oldpkg == newpkg) {
  7837. + return 0;
  7838. + }
  7839. +
  7840. + if (!oldpkg->src)
  7841. + oldpkg->src = newpkg->src;
  7842. + if (!oldpkg->dest)
  7843. + oldpkg->dest = newpkg->dest;
  7844. + if (!oldpkg->architecture)
  7845. + oldpkg->architecture = str_dup_safe(newpkg->architecture);
  7846. + if (!oldpkg->arch_priority)
  7847. + oldpkg->arch_priority = newpkg->arch_priority;
  7848. + if (!oldpkg->section)
  7849. + oldpkg->section = str_dup_safe(newpkg->section);
  7850. + if(!oldpkg->maintainer)
  7851. + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
  7852. + if(!oldpkg->description)
  7853. + oldpkg->description = str_dup_safe(newpkg->description);
  7854. + if (set_status) {
  7855. + /* merge the state_flags from the new package */
  7856. + oldpkg->state_want = newpkg->state_want;
  7857. + oldpkg->state_status = newpkg->state_status;
  7858. + oldpkg->state_flag = newpkg->state_flag;
  7859. + } else {
  7860. + if (oldpkg->state_want == SW_UNKNOWN)
  7861. + oldpkg->state_want = newpkg->state_want;
  7862. + if (oldpkg->state_status == SS_NOT_INSTALLED)
  7863. + oldpkg->state_status = newpkg->state_status;
  7864. + oldpkg->state_flag |= newpkg->state_flag;
  7865. + }
  7866. +
  7867. + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
  7868. + oldpkg->depends_str = newpkg->depends_str;
  7869. + newpkg->depends_str = NULL;
  7870. + oldpkg->depends_count = newpkg->depends_count;
  7871. + newpkg->depends_count = 0;
  7872. +
  7873. + oldpkg->depends = newpkg->depends;
  7874. + newpkg->depends = NULL;
  7875. +
  7876. + oldpkg->pre_depends_str = newpkg->pre_depends_str;
  7877. + newpkg->pre_depends_str = NULL;
  7878. + oldpkg->pre_depends_count = newpkg->pre_depends_count;
  7879. + newpkg->pre_depends_count = 0;
  7880. +
  7881. + oldpkg->recommends_str = newpkg->recommends_str;
  7882. + newpkg->recommends_str = NULL;
  7883. + oldpkg->recommends_count = newpkg->recommends_count;
  7884. + newpkg->recommends_count = 0;
  7885. +
  7886. + oldpkg->suggests_str = newpkg->suggests_str;
  7887. + newpkg->suggests_str = NULL;
  7888. + oldpkg->suggests_count = newpkg->suggests_count;
  7889. + newpkg->suggests_count = 0;
  7890. + }
  7891. +
  7892. + if (!oldpkg->provides_str) {
  7893. + oldpkg->provides_str = newpkg->provides_str;
  7894. + newpkg->provides_str = NULL;
  7895. + oldpkg->provides_count = newpkg->provides_count;
  7896. + newpkg->provides_count = 0;
  7897. +
  7898. + oldpkg->provides = newpkg->provides;
  7899. + newpkg->provides = NULL;
  7900. + }
  7901. +
  7902. + if (!oldpkg->conflicts_str) {
  7903. + oldpkg->conflicts_str = newpkg->conflicts_str;
  7904. + newpkg->conflicts_str = NULL;
  7905. + oldpkg->conflicts_count = newpkg->conflicts_count;
  7906. + newpkg->conflicts_count = 0;
  7907. +
  7908. + oldpkg->conflicts = newpkg->conflicts;
  7909. + newpkg->conflicts = NULL;
  7910. + }
  7911. +
  7912. + if (!oldpkg->replaces_str) {
  7913. + oldpkg->replaces_str = newpkg->replaces_str;
  7914. + newpkg->replaces_str = NULL;
  7915. + oldpkg->replaces_count = newpkg->replaces_count;
  7916. + newpkg->replaces_count = 0;
  7917. +
  7918. + oldpkg->replaces = newpkg->replaces;
  7919. + newpkg->replaces = NULL;
  7920. + }
  7921. +
  7922. + if (!oldpkg->filename)
  7923. + oldpkg->filename = str_dup_safe(newpkg->filename);
  7924. + if (0)
  7925. + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
  7926. + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
  7927. + if (!oldpkg->local_filename)
  7928. + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
  7929. + if (!oldpkg->tmp_unpack_dir)
  7930. + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
  7931. + if (!oldpkg->md5sum)
  7932. + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
  7933. + if (!oldpkg->size)
  7934. + oldpkg->size = str_dup_safe(newpkg->size);
  7935. + if (!oldpkg->installed_size)
  7936. + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
  7937. + if (!oldpkg->priority)
  7938. + oldpkg->priority = str_dup_safe(newpkg->priority);
  7939. + if (!oldpkg->source)
  7940. + oldpkg->source = str_dup_safe(newpkg->source);
  7941. + if (oldpkg->conffiles.head == NULL){
  7942. + oldpkg->conffiles = newpkg->conffiles;
  7943. + conffile_list_init(&newpkg->conffiles);
  7944. + }
  7945. + if (!oldpkg->installed_files){
  7946. + oldpkg->installed_files = newpkg->installed_files;
  7947. + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
  7948. + newpkg->installed_files = NULL;
  7949. + }
  7950. + if (!oldpkg->essential)
  7951. + oldpkg->essential = newpkg->essential;
  7952. +
  7953. + return 0;
  7954. +}
  7955. +
  7956. +abstract_pkg_t *abstract_pkg_new(void)
  7957. +{
  7958. + abstract_pkg_t * ab_pkg;
  7959. +
  7960. + ab_pkg = malloc(sizeof(abstract_pkg_t));
  7961. +
  7962. + if (ab_pkg == NULL) {
  7963. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7964. + return NULL;
  7965. + }
  7966. +
  7967. + if ( abstract_pkg_init(ab_pkg) < 0 )
  7968. + return NULL;
  7969. +
  7970. + return ab_pkg;
  7971. +}
  7972. +
  7973. +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
  7974. +{
  7975. + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
  7976. +
  7977. + ab_pkg->provided_by = abstract_pkg_vec_alloc();
  7978. + if (ab_pkg->provided_by==NULL){
  7979. + return -1;
  7980. + }
  7981. + ab_pkg->dependencies_checked = 0;
  7982. + ab_pkg->state_status = SS_NOT_INSTALLED;
  7983. +
  7984. + return 0;
  7985. +}
  7986. +
  7987. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
  7988. + char * temp_str;
  7989. + char **raw =NULL;
  7990. + char **raw_start=NULL;
  7991. +
  7992. + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
  7993. + if (temp_str == NULL ){
  7994. + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
  7995. + return;
  7996. + }
  7997. + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
  7998. +
  7999. + raw = raw_start = read_raw_pkgs_from_file(temp_str);
  8000. + if (raw == NULL ){
  8001. + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
  8002. + return;
  8003. + }
  8004. +
  8005. + while(*raw){
  8006. + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
  8007. + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
  8008. + }
  8009. + }
  8010. + raw = raw_start;
  8011. + while (*raw) {
  8012. + if (raw!=NULL)
  8013. + free(*raw++);
  8014. + }
  8015. +
  8016. + free(raw_start);
  8017. + free(temp_str);
  8018. +
  8019. + return ;
  8020. +
  8021. +}
  8022. +
  8023. +char * pkg_formatted_info(pkg_t *pkg )
  8024. +{
  8025. + char *line;
  8026. + char * buff;
  8027. +
  8028. + buff = malloc(8192);
  8029. + if (buff == NULL) {
  8030. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8031. + return NULL;
  8032. + }
  8033. +
  8034. + buff[0] = '\0';
  8035. +
  8036. + line = pkg_formatted_field(pkg, "Package");
  8037. + strncat(buff ,line, strlen(line));
  8038. + free(line);
  8039. +
  8040. + line = pkg_formatted_field(pkg, "Version");
  8041. + strncat(buff ,line, strlen(line));
  8042. + free(line);
  8043. +
  8044. + line = pkg_formatted_field(pkg, "Depends");
  8045. + strncat(buff ,line, strlen(line));
  8046. + free(line);
  8047. +
  8048. + line = pkg_formatted_field(pkg, "Recommends");
  8049. + strncat(buff ,line, strlen(line));
  8050. + free(line);
  8051. +
  8052. + line = pkg_formatted_field(pkg, "Suggests");
  8053. + strncat(buff ,line, strlen(line));
  8054. + free(line);
  8055. +
  8056. + line = pkg_formatted_field(pkg, "Provides");
  8057. + strncat(buff ,line, strlen(line));
  8058. + free(line);
  8059. +
  8060. + line = pkg_formatted_field(pkg, "Replaces");
  8061. + strncat(buff ,line, strlen(line));
  8062. + free(line);
  8063. +
  8064. + line = pkg_formatted_field(pkg, "Conflicts");
  8065. + strncat(buff ,line, strlen(line));
  8066. + free(line);
  8067. +
  8068. + line = pkg_formatted_field(pkg, "Status");
  8069. + strncat(buff ,line, strlen(line));
  8070. + free(line);
  8071. +
  8072. + line = pkg_formatted_field(pkg, "Section");
  8073. + strncat(buff ,line, strlen(line));
  8074. + free(line);
  8075. +
  8076. + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
  8077. + strncat(buff ,line, strlen(line));
  8078. + free(line);
  8079. +
  8080. + line = pkg_formatted_field(pkg, "Architecture");
  8081. + strncat(buff ,line, strlen(line));
  8082. + free(line);
  8083. +
  8084. + line = pkg_formatted_field(pkg, "Maintainer");
  8085. + strncat(buff ,line, strlen(line));
  8086. + free(line);
  8087. +
  8088. + line = pkg_formatted_field(pkg, "MD5sum");
  8089. + strncat(buff ,line, strlen(line));
  8090. + free(line);
  8091. +
  8092. + line = pkg_formatted_field(pkg, "Size");
  8093. + strncat(buff ,line, strlen(line));
  8094. + free(line);
  8095. +
  8096. + line = pkg_formatted_field(pkg, "Filename");
  8097. + strncat(buff ,line, strlen(line));
  8098. + free(line);
  8099. +
  8100. + line = pkg_formatted_field(pkg, "Conffiles");
  8101. + strncat(buff ,line, strlen(line));
  8102. + free(line);
  8103. +
  8104. + line = pkg_formatted_field(pkg, "Source");
  8105. + strncat(buff ,line, strlen(line));
  8106. + free(line);
  8107. +
  8108. + line = pkg_formatted_field(pkg, "Description");
  8109. + strncat(buff ,line, strlen(line));
  8110. + free(line);
  8111. +
  8112. + line = pkg_formatted_field(pkg, "Installed-Time");
  8113. + strncat(buff ,line, strlen(line));
  8114. + free(line);
  8115. +
  8116. + return buff;
  8117. +}
  8118. +
  8119. +char * pkg_formatted_field(pkg_t *pkg, const char *field )
  8120. +{
  8121. + static size_t LINE_LEN = 128;
  8122. + char * temp = (char *)malloc(1);
  8123. + int len = 0;
  8124. + int flag_provide_false = 0;
  8125. +
  8126. +/*
  8127. + Pigi: After some discussion with Florian we decided to modify the full procedure in
  8128. + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
  8129. +*/
  8130. +
  8131. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8132. + goto UNKNOWN_FMT_FIELD;
  8133. + }
  8134. +
  8135. + temp[0]='\0';
  8136. +
  8137. + switch (field[0])
  8138. + {
  8139. + case 'a':
  8140. + case 'A':
  8141. + if (strcasecmp(field, "Architecture") == 0) {
  8142. + /* Architecture */
  8143. + if (pkg->architecture) {
  8144. + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
  8145. + if ( temp == NULL ){
  8146. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8147. + return NULL;
  8148. + }
  8149. + temp[0]='\0';
  8150. + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
  8151. + }
  8152. + } else {
  8153. + goto UNKNOWN_FMT_FIELD;
  8154. + }
  8155. + break;
  8156. + case 'c':
  8157. + case 'C':
  8158. + if (strcasecmp(field, "Conffiles") == 0) {
  8159. + /* Conffiles */
  8160. + conffile_list_elt_t *iter;
  8161. + char confstr_[LINE_LEN];
  8162. +
  8163. + if (pkg->conffiles.head == NULL) {
  8164. + return temp;
  8165. + }
  8166. +
  8167. + len = 14 ;
  8168. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8169. + if (iter->data->name && iter->data->value) {
  8170. + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
  8171. + }
  8172. + }
  8173. + temp = (char *)realloc(temp,len);
  8174. + if ( temp == NULL ){
  8175. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8176. + return NULL;
  8177. + }
  8178. + temp[0]='\0';
  8179. + strncpy(temp, "Conffiles:\n", 12);
  8180. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8181. + if (iter->data->name && iter->data->value) {
  8182. + snprintf(confstr_, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
  8183. + strncat(temp, confstr_, strlen(confstr_));
  8184. + }
  8185. + }
  8186. + } else if (strcasecmp(field, "Conflicts") == 0) {
  8187. + int i;
  8188. +
  8189. + if (pkg->conflicts_count) {
  8190. + char conflictstr[LINE_LEN];
  8191. + len = 14 ;
  8192. + for(i = 0; i < pkg->conflicts_count; i++) {
  8193. + len = len + (strlen(pkg->conflicts_str[i])+5);
  8194. + }
  8195. + temp = (char *)realloc(temp,len);
  8196. + if ( temp == NULL ){
  8197. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8198. + return NULL;
  8199. + }
  8200. + temp[0]='\0';
  8201. + strncpy(temp, "Conflicts:", 11);
  8202. + for(i = 0; i < pkg->conflicts_count; i++) {
  8203. + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
  8204. + strncat(temp, conflictstr, strlen(conflictstr));
  8205. + }
  8206. + strncat(temp, "\n", strlen("\n"));
  8207. + }
  8208. + } else {
  8209. + goto UNKNOWN_FMT_FIELD;
  8210. + }
  8211. + break;
  8212. + case 'd':
  8213. + case 'D':
  8214. + if (strcasecmp(field, "Depends") == 0) {
  8215. + /* Depends */
  8216. + int i;
  8217. +
  8218. + if (pkg->depends_count) {
  8219. + char depstr[LINE_LEN];
  8220. + len = 14 ;
  8221. + for(i = 0; i < pkg->depends_count; i++) {
  8222. + len = len + (strlen(pkg->depends_str[i])+4);
  8223. + }
  8224. + temp = (char *)realloc(temp,len);
  8225. + if ( temp == NULL ){
  8226. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8227. + return NULL;
  8228. + }
  8229. + temp[0]='\0';
  8230. + strncpy(temp, "Depends:", 10);
  8231. + for(i = 0; i < pkg->depends_count; i++) {
  8232. + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
  8233. + strncat(temp, depstr, strlen(depstr));
  8234. + }
  8235. + strncat(temp, "\n", strlen("\n"));
  8236. + }
  8237. + } else if (strcasecmp(field, "Description") == 0) {
  8238. + /* Description */
  8239. + if (pkg->description) {
  8240. + temp = (char *)realloc(temp,strlen(pkg->description)+16);
  8241. + if ( temp == NULL ){
  8242. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8243. + return NULL;
  8244. + }
  8245. + temp[0]='\0';
  8246. + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
  8247. + }
  8248. + } else {
  8249. + goto UNKNOWN_FMT_FIELD;
  8250. + }
  8251. + break;
  8252. + case 'e':
  8253. + case 'E': {
  8254. + /* Essential */
  8255. + if (pkg->essential) {
  8256. + temp = (char *)realloc(temp,16);
  8257. + if ( temp == NULL ){
  8258. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8259. + return NULL;
  8260. + }
  8261. + temp[0]='\0';
  8262. + snprintf(temp, (16), "Essential: yes\n");
  8263. + }
  8264. + }
  8265. + break;
  8266. + case 'f':
  8267. + case 'F': {
  8268. + /* Filename */
  8269. + if (pkg->filename) {
  8270. + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
  8271. + if ( temp == NULL ){
  8272. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8273. + return NULL;
  8274. + }
  8275. + temp[0]='\0';
  8276. + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
  8277. + }
  8278. + }
  8279. + break;
  8280. + case 'i':
  8281. + case 'I': {
  8282. + if (strcasecmp(field, "Installed-Size") == 0) {
  8283. + /* Installed-Size */
  8284. + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
  8285. + if ( temp == NULL ){
  8286. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8287. + return NULL;
  8288. + }
  8289. + temp[0]='\0';
  8290. + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
  8291. + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
  8292. + temp = (char *)realloc(temp,29);
  8293. + if ( temp == NULL ){
  8294. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8295. + return NULL;
  8296. + }
  8297. + temp[0]='\0';
  8298. + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
  8299. + }
  8300. + }
  8301. + break;
  8302. + case 'm':
  8303. + case 'M': {
  8304. + /* Maintainer | MD5sum */
  8305. + if (strcasecmp(field, "Maintainer") == 0) {
  8306. + /* Maintainer */
  8307. + if (pkg->maintainer) {
  8308. + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
  8309. + if ( temp == NULL ){
  8310. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8311. + return NULL;
  8312. + }
  8313. + temp[0]='\0';
  8314. + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
  8315. + }
  8316. + } else if (strcasecmp(field, "MD5sum") == 0) {
  8317. + /* MD5sum */
  8318. + if (pkg->md5sum) {
  8319. + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
  8320. + if ( temp == NULL ){
  8321. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8322. + return NULL;
  8323. + }
  8324. + temp[0]='\0';
  8325. + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
  8326. + }
  8327. + } else {
  8328. + goto UNKNOWN_FMT_FIELD;
  8329. + }
  8330. + }
  8331. + break;
  8332. + case 'p':
  8333. + case 'P': {
  8334. + if (strcasecmp(field, "Package") == 0) {
  8335. + /* Package */
  8336. + temp = (char *)realloc(temp,strlen(pkg->name)+11);
  8337. + if ( temp == NULL ){
  8338. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8339. + return NULL;
  8340. + }
  8341. + temp[0]='\0';
  8342. + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
  8343. + } else if (strcasecmp(field, "Priority") == 0) {
  8344. + /* Priority */
  8345. + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
  8346. + if ( temp == NULL ){
  8347. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8348. + return NULL;
  8349. + }
  8350. + temp[0]='\0';
  8351. + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
  8352. + } else if (strcasecmp(field, "Provides") == 0) {
  8353. + /* Provides */
  8354. + int i;
  8355. +
  8356. + if (pkg->provides_count) {
  8357. + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
  8358. + for ( i=0; i < pkg->provides_count; i++ ){
  8359. + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
  8360. + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
  8361. + flag_provide_false = 1;
  8362. + }
  8363. + }
  8364. + if ( !flag_provide_false || /* Pigi there is not my trick flag */
  8365. + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
  8366. + char provstr[LINE_LEN];
  8367. + len = 15;
  8368. + for(i = 0; i < pkg->provides_count; i++) {
  8369. + len = len + (strlen(pkg->provides_str[i])+5);
  8370. + }
  8371. + temp = (char *)realloc(temp,len);
  8372. + if ( temp == NULL ){
  8373. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8374. + return NULL;
  8375. + }
  8376. + temp[0]='\0';
  8377. + strncpy(temp, "Provides:", 12);
  8378. + for(i = 0; i < pkg->provides_count; i++) {
  8379. + if (strlen(pkg->provides_str[i])>0){;
  8380. + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
  8381. + strncat(temp, provstr, strlen(provstr));
  8382. + }
  8383. + }
  8384. + strncat(temp, "\n", strlen("\n"));
  8385. + }
  8386. + }
  8387. + } else {
  8388. + goto UNKNOWN_FMT_FIELD;
  8389. + }
  8390. + }
  8391. + break;
  8392. + case 'r':
  8393. + case 'R': {
  8394. + int i;
  8395. + /* Replaces | Recommends*/
  8396. + if (strcasecmp (field, "Replaces") == 0) {
  8397. + if (pkg->replaces_count) {
  8398. + char replstr[LINE_LEN];
  8399. + len = 14;
  8400. + for (i = 0; i < pkg->replaces_count; i++) {
  8401. + len = len + (strlen(pkg->replaces_str[i])+5);
  8402. + }
  8403. + temp = (char *)realloc(temp,len);
  8404. + if ( temp == NULL ){
  8405. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8406. + return NULL;
  8407. + }
  8408. + temp[0]='\0';
  8409. + strncpy(temp, "Replaces:", 12);
  8410. + for (i = 0; i < pkg->replaces_count; i++) {
  8411. + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
  8412. + strncat(temp, replstr, strlen(replstr));
  8413. + }
  8414. + strncat(temp, "\n", strlen("\n"));
  8415. + }
  8416. + } else if (strcasecmp (field, "Recommends") == 0) {
  8417. + if (pkg->recommends_count) {
  8418. + char recstr[LINE_LEN];
  8419. + len = 15;
  8420. + for(i = 0; i < pkg->recommends_count; i++) {
  8421. + len = len + (strlen( pkg->recommends_str[i])+5);
  8422. + }
  8423. + temp = (char *)realloc(temp,len);
  8424. + if ( temp == NULL ){
  8425. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8426. + return NULL;
  8427. + }
  8428. + temp[0]='\0';
  8429. + strncpy(temp, "Recommends:", 13);
  8430. + for(i = 0; i < pkg->recommends_count; i++) {
  8431. + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
  8432. + strncat(temp, recstr, strlen(recstr));
  8433. + }
  8434. + strncat(temp, "\n", strlen("\n"));
  8435. + }
  8436. + } else {
  8437. + goto UNKNOWN_FMT_FIELD;
  8438. + }
  8439. + }
  8440. + break;
  8441. + case 's':
  8442. + case 'S': {
  8443. + /* Section | Size | Source | Status | Suggests */
  8444. + if (strcasecmp(field, "Section") == 0) {
  8445. + /* Section */
  8446. + if (pkg->section) {
  8447. + temp = (char *)realloc(temp,strlen(pkg->section)+11);
  8448. + if ( temp == NULL ){
  8449. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8450. + return NULL;
  8451. + }
  8452. + temp[0]='\0';
  8453. + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
  8454. + }
  8455. + } else if (strcasecmp(field, "Size") == 0) {
  8456. + /* Size */
  8457. + if (pkg->size) {
  8458. + temp = (char *)realloc(temp,strlen(pkg->size)+8);
  8459. + if ( temp == NULL ){
  8460. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8461. + return NULL;
  8462. + }
  8463. + temp[0]='\0';
  8464. + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
  8465. + }
  8466. + } else if (strcasecmp(field, "Source") == 0) {
  8467. + /* Source */
  8468. + if (pkg->source) {
  8469. + temp = (char *)realloc(temp,strlen(pkg->source)+10);
  8470. + if ( temp == NULL ){
  8471. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8472. + return NULL;
  8473. + }
  8474. + temp[0]='\0';
  8475. + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
  8476. + }
  8477. + } else if (strcasecmp(field, "Status") == 0) {
  8478. + /* Status */
  8479. + /* Benjamin Pineau note: we should avoid direct usage of
  8480. + * strlen(arg) without keeping "arg" for later free()
  8481. + */
  8482. + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
  8483. + char *pstat=pkg_state_status_to_str(pkg->state_status);
  8484. + char *pwant=pkg_state_want_to_str(pkg->state_want);
  8485. +
  8486. + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
  8487. + temp = (char *)realloc(temp,sum_of_sizes);
  8488. + if ( temp == NULL ){
  8489. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8490. + return NULL;
  8491. + }
  8492. + temp[0]='\0';
  8493. + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
  8494. + free(pflag);
  8495. + free(pwant);
  8496. + if(pstat) /* pfstat can be NULL if ENOMEM */
  8497. + free(pstat);
  8498. + } else if (strcasecmp(field, "Suggests") == 0) {
  8499. + if (pkg->suggests_count) {
  8500. + int i;
  8501. + char sugstr[LINE_LEN];
  8502. + len = 13;
  8503. + for(i = 0; i < pkg->suggests_count; i++) {
  8504. + len = len + (strlen(pkg->suggests_str[i])+5);
  8505. + }
  8506. + temp = (char *)realloc(temp,len);
  8507. + if ( temp == NULL ){
  8508. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8509. + return NULL;
  8510. + }
  8511. + temp[0]='\0';
  8512. + strncpy(temp, "Suggests:", 10);
  8513. + for(i = 0; i < pkg->suggests_count; i++) {
  8514. + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
  8515. + strncat(temp, sugstr, strlen(sugstr));
  8516. + }
  8517. + strncat(temp, "\n", strlen("\n"));
  8518. + }
  8519. + } else {
  8520. + goto UNKNOWN_FMT_FIELD;
  8521. + }
  8522. + }
  8523. + break;
  8524. + case 'v':
  8525. + case 'V': {
  8526. + /* Version */
  8527. + char *version = pkg_version_str_alloc(pkg);
  8528. + temp = (char *)realloc(temp,strlen(version)+14);
  8529. + if ( temp == NULL ){
  8530. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8531. + return NULL;
  8532. + }
  8533. + temp[0]='\0';
  8534. + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
  8535. + free(version);
  8536. + }
  8537. + break;
  8538. + default:
  8539. + goto UNKNOWN_FMT_FIELD;
  8540. + }
  8541. +
  8542. + if ( strlen(temp)<2 ) {
  8543. + temp[0]='\0';
  8544. + }
  8545. + return temp;
  8546. +
  8547. + UNKNOWN_FMT_FIELD:
  8548. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
  8549. + if ( strlen(temp)<2 ) {
  8550. + temp[0]='\0';
  8551. + }
  8552. +
  8553. + return temp;
  8554. +}
  8555. +
  8556. +void pkg_print_info(pkg_t *pkg, FILE *file)
  8557. +{
  8558. + char * buff;
  8559. + if (pkg == NULL) {
  8560. + return;
  8561. + }
  8562. +
  8563. + buff = pkg_formatted_info(pkg);
  8564. + if ( buff == NULL )
  8565. + return;
  8566. + if (strlen(buff)>2){
  8567. + fwrite(buff, 1, strlen(buff), file);
  8568. + }
  8569. + free(buff);
  8570. +}
  8571. +
  8572. +void pkg_print_status(pkg_t * pkg, FILE * file)
  8573. +{
  8574. + if (pkg == NULL) {
  8575. + return;
  8576. + }
  8577. +
  8578. + /* XXX: QUESTION: Do we actually want more fields here? The
  8579. + original idea was to save space by installing only what was
  8580. + needed for actual computation, (package, version, status,
  8581. + essential, conffiles). The assumption is that all other fields
  8582. + can be found in th available file.
  8583. +
  8584. + But, someone proposed the idea to make it possible to
  8585. + reconstruct a .ipk from an installed package, (ie. for beaming
  8586. + from one handheld to another). So, maybe we actually want a few
  8587. + more fields here, (depends, suggests, etc.), so that that would
  8588. + be guaranteed to work even in the absence of more information
  8589. + from the available file.
  8590. +
  8591. + 28-MAR-03: kergoth and I discussed this yesterday. We think
  8592. + the essential info needs to be here for all installed packages
  8593. + because they may not appear in the Packages files on various
  8594. + feeds. Furthermore, one should be able to install from URL or
  8595. + local storage without requiring a Packages file from any feed.
  8596. + -Jamey
  8597. + */
  8598. + pkg_print_field(pkg, file, "Package");
  8599. + pkg_print_field(pkg, file, "Version");
  8600. + pkg_print_field(pkg, file, "Depends");
  8601. + pkg_print_field(pkg, file, "Recommends");
  8602. + pkg_print_field(pkg, file, "Suggests");
  8603. + pkg_print_field(pkg, file, "Provides");
  8604. + pkg_print_field(pkg, file, "Replaces");
  8605. + pkg_print_field(pkg, file, "Conflicts");
  8606. + pkg_print_field(pkg, file, "Status");
  8607. + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
  8608. + pkg_print_field(pkg, file, "Architecture");
  8609. + pkg_print_field(pkg, file, "Conffiles");
  8610. + pkg_print_field(pkg, file, "Installed-Time");
  8611. + fputs("\n", file);
  8612. +}
  8613. +
  8614. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
  8615. +{
  8616. + char *buff;
  8617. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8618. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
  8619. + __FUNCTION__, field);
  8620. + }
  8621. + buff = pkg_formatted_field(pkg, field);
  8622. + if (strlen(buff)>2) {
  8623. + fprintf(file, "%s", buff);
  8624. + fflush(file);
  8625. + }
  8626. + free(buff);
  8627. + return;
  8628. +}
  8629. +
  8630. +/*
  8631. + * libdpkg - Debian packaging suite library routines
  8632. + * vercmp.c - comparison of version numbers
  8633. + *
  8634. + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  8635. + */
  8636. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
  8637. +{
  8638. + int r;
  8639. +
  8640. + if (pkg->epoch > ref_pkg->epoch) {
  8641. + return 1;
  8642. + }
  8643. +
  8644. + if (pkg->epoch < ref_pkg->epoch) {
  8645. + return -1;
  8646. + }
  8647. +
  8648. + r = verrevcmp(pkg->version, ref_pkg->version);
  8649. + if (r) {
  8650. + return r;
  8651. + }
  8652. +
  8653. +#ifdef USE_DEBVERSION
  8654. + r = verrevcmp(pkg->revision, ref_pkg->revision);
  8655. + if (r) {
  8656. + return r;
  8657. + }
  8658. +
  8659. + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
  8660. +#endif
  8661. +
  8662. + return r;
  8663. +}
  8664. +
  8665. +int verrevcmp(const char *val, const char *ref)
  8666. +{
  8667. + int vc, rc;
  8668. + long vl, rl;
  8669. + const char *vp, *rp;
  8670. + const char *vsep, *rsep;
  8671. +
  8672. + if (!val) val= "";
  8673. + if (!ref) ref= "";
  8674. + for (;;) {
  8675. + vp= val; while (*vp && !isdigit(*vp)) vp++;
  8676. + rp= ref; while (*rp && !isdigit(*rp)) rp++;
  8677. + for (;;) {
  8678. + vc= (val == vp) ? 0 : *val++;
  8679. + rc= (ref == rp) ? 0 : *ref++;
  8680. + if (!rc && !vc) break;
  8681. + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
  8682. + if (rc && !isalpha(rc)) rc += 256;
  8683. + if (vc != rc) return vc - rc;
  8684. + }
  8685. + val= vp;
  8686. + ref= rp;
  8687. + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
  8688. + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
  8689. + if (vl != rl) return vl - rl;
  8690. +
  8691. + vc = *val;
  8692. + rc = *ref;
  8693. + vsep = strchr(".-", vc);
  8694. + rsep = strchr(".-", rc);
  8695. + if (vsep && !rsep) return -1;
  8696. + if (!vsep && rsep) return +1;
  8697. +
  8698. + if (!*val && !*ref) return 0;
  8699. + if (!*val) return -1;
  8700. + if (!*ref) return +1;
  8701. + }
  8702. +}
  8703. +
  8704. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
  8705. +{
  8706. + int r;
  8707. +
  8708. + r = pkg_compare_versions(it, ref);
  8709. +
  8710. + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
  8711. + return r <= 0;
  8712. + }
  8713. +
  8714. + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
  8715. + return r >= 0;
  8716. + }
  8717. +
  8718. + if (strcmp(op, "<<") == 0) {
  8719. + return r < 0;
  8720. + }
  8721. +
  8722. + if (strcmp(op, ">>") == 0) {
  8723. + return r > 0;
  8724. + }
  8725. +
  8726. + if (strcmp(op, "=") == 0) {
  8727. + return r == 0;
  8728. + }
  8729. +
  8730. + fprintf(stderr, "unknown operator: %s", op);
  8731. + return 0;
  8732. +}
  8733. +
  8734. +int pkg_name_version_and_architecture_compare(pkg_t *p1, pkg_t *p2)
  8735. +{
  8736. + const pkg_t *a = *(const pkg_t **)p1;
  8737. + const pkg_t *b = *(const pkg_t **)p2;
  8738. + int namecmp;
  8739. + int vercmp;
  8740. + if (!a->name || !b->name) {
  8741. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8742. + a, a->name, b, b->name);
  8743. + return 0;
  8744. + }
  8745. +
  8746. + namecmp = strcmp(a->name, b->name);
  8747. + if (namecmp)
  8748. + return namecmp;
  8749. + vercmp = pkg_compare_versions(a, b);
  8750. + if (vercmp)
  8751. + return vercmp;
  8752. + if (!a->arch_priority || !b->arch_priority) {
  8753. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
  8754. + a, a->arch_priority, b, b->arch_priority);
  8755. + return 0;
  8756. + }
  8757. + if (a->arch_priority > b->arch_priority)
  8758. + return 1;
  8759. + if (a->arch_priority < b->arch_priority)
  8760. + return -1;
  8761. + return 0;
  8762. +}
  8763. +
  8764. +int abstract_pkg_name_compare(abstract_pkg_t *p1, abstract_pkg_t *p2)
  8765. +{
  8766. + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
  8767. + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
  8768. + if (!a->name || !b->name) {
  8769. + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8770. + a, a->name, b, b->name);
  8771. + return 0;
  8772. + }
  8773. + return strcmp(a->name, b->name);
  8774. +}
  8775. +
  8776. +
  8777. +char *pkg_version_str_alloc(pkg_t *pkg)
  8778. +{
  8779. + char *complete_version;
  8780. + char *epoch_str;
  8781. +#ifdef USE_DEBVERSION
  8782. + char *revision_str;
  8783. + char *familiar_revision_str;
  8784. +#endif
  8785. +
  8786. + if (pkg->epoch) {
  8787. + sprintf_alloc(&epoch_str, "%lu:", (unsigned long)pkg->epoch);
  8788. + } else {
  8789. + epoch_str = strdup("");
  8790. + }
  8791. +
  8792. +#ifdef USE_DEBVERSION
  8793. + if (pkg->revision && strlen(pkg->revision)) {
  8794. + sprintf_alloc(&revision_str, "-%s", pkg->revision);
  8795. + } else {
  8796. + revision_str = strdup("");
  8797. + }
  8798. +
  8799. + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
  8800. + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
  8801. + } else {
  8802. + familiar_revision_str = strdup("");
  8803. + }
  8804. +#endif
  8805. +
  8806. +#ifdef USE_DEBVERSION
  8807. + sprintf_alloc(&complete_version, "%s%s%s%s",
  8808. + epoch_str, pkg->version, revision_str, familiar_revision_str);
  8809. +#else
  8810. + sprintf_alloc(&complete_version, "%s%s",
  8811. + epoch_str, pkg->version);
  8812. +#endif
  8813. +
  8814. + free(epoch_str);
  8815. +#ifdef USE_DEBVERSION
  8816. + free(revision_str);
  8817. + free(familiar_revision_str);
  8818. +#endif
  8819. +
  8820. + return complete_version;
  8821. +}
  8822. +
  8823. +str_list_t *pkg_get_installed_files(pkg_t *pkg)
  8824. +{
  8825. + int err;
  8826. + char *list_file_name = NULL;
  8827. + FILE *list_file = NULL;
  8828. + char *line;
  8829. + char *installed_file_name;
  8830. + int rootdirlen;
  8831. +
  8832. + pkg->installed_files_ref_cnt++;
  8833. +
  8834. + if (pkg->installed_files) {
  8835. + return pkg->installed_files;
  8836. + }
  8837. +
  8838. + pkg->installed_files = str_list_alloc();
  8839. + if (pkg->installed_files == NULL) {
  8840. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8841. + return NULL;
  8842. + }
  8843. +
  8844. + /* For uninstalled packages, get the file list firectly from the package.
  8845. + For installed packages, look at the package.list file in the database.
  8846. + */
  8847. + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
  8848. + if (pkg->local_filename == NULL) {
  8849. + return pkg->installed_files;
  8850. + }
  8851. + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
  8852. + file. In other words, change deb_extract so that it can
  8853. + simply return the file list as a char *[] rather than
  8854. + insisting on writing in to a FILE * as it does now. */
  8855. + list_file = tmpfile();
  8856. + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
  8857. + if (err) {
  8858. + fclose(list_file);
  8859. + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
  8860. + __FUNCTION__, pkg->local_filename, strerror(err));
  8861. + return pkg->installed_files;
  8862. + }
  8863. + rewind(list_file);
  8864. + } else {
  8865. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8866. + pkg->dest->info_dir, pkg->name);
  8867. + if (! file_exists(list_file_name)) {
  8868. + free(list_file_name);
  8869. + return pkg->installed_files;
  8870. + }
  8871. +
  8872. + list_file = fopen(list_file_name, "r");
  8873. + if (list_file == NULL) {
  8874. + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
  8875. + list_file_name, strerror(errno));
  8876. + free(list_file_name);
  8877. + return pkg->installed_files;
  8878. + }
  8879. + free(list_file_name);
  8880. + }
  8881. +
  8882. + rootdirlen = strlen( pkg->dest->root_dir );
  8883. + while (1) {
  8884. + char *file_name;
  8885. +
  8886. + line = file_read_line_alloc(list_file);
  8887. + if (line == NULL) {
  8888. + break;
  8889. + }
  8890. + str_chomp(line);
  8891. + file_name = line;
  8892. +
  8893. + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
  8894. + if( strncmp( pkg->dest->root_dir,
  8895. + file_name,
  8896. + rootdirlen ) ) {
  8897. + if (*file_name == '.') {
  8898. + file_name++;
  8899. + }
  8900. + if (*file_name == '/') {
  8901. + file_name++;
  8902. + }
  8903. +
  8904. + /* Freed in pkg_free_installed_files */
  8905. + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
  8906. + } else {
  8907. + // already contains root_dir as header -> ABSOLUTE
  8908. + sprintf_alloc(&installed_file_name, "%s", file_name);
  8909. + }
  8910. + str_list_append(pkg->installed_files, installed_file_name);
  8911. + free(line);
  8912. + }
  8913. +
  8914. + fclose(list_file);
  8915. +
  8916. + return pkg->installed_files;
  8917. +}
  8918. +
  8919. +/* XXX: CLEANUP: This function and it's counterpart,
  8920. + (pkg_get_installed_files), do not match our init/deinit naming
  8921. + convention. Nor the alloc/free convention. But, then again, neither
  8922. + of these conventions currrently fit the way these two functions
  8923. + work. */
  8924. +int pkg_free_installed_files(pkg_t *pkg)
  8925. +{
  8926. + str_list_elt_t *iter;
  8927. +
  8928. + pkg->installed_files_ref_cnt--;
  8929. + if (pkg->installed_files_ref_cnt > 0) {
  8930. + return 0;
  8931. + }
  8932. +
  8933. + if (pkg->installed_files) {
  8934. +
  8935. + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
  8936. + /* malloced in pkg_get_installed_files */
  8937. + free (iter->data);
  8938. + iter->data = NULL;
  8939. + }
  8940. +
  8941. + str_list_deinit(pkg->installed_files);
  8942. + }
  8943. +
  8944. + pkg->installed_files = NULL;
  8945. +
  8946. + return 0;
  8947. +}
  8948. +
  8949. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
  8950. +{
  8951. + int err;
  8952. + char *list_file_name;
  8953. +
  8954. + //I don't think pkg_free_installed_files should be called here. Jamey
  8955. + //pkg_free_installed_files(pkg);
  8956. +
  8957. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8958. + pkg->dest->info_dir, pkg->name);
  8959. + if (!conf->noaction) {
  8960. + err = unlink(list_file_name);
  8961. + free(list_file_name);
  8962. +
  8963. + if (err) {
  8964. + return errno;
  8965. + }
  8966. + }
  8967. + return 0;
  8968. +}
  8969. +
  8970. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
  8971. +{
  8972. + conffile_list_elt_t *iter;
  8973. + conffile_t *conffile;
  8974. +
  8975. + if (pkg == NULL) {
  8976. + return NULL;
  8977. + }
  8978. +
  8979. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8980. + conffile = iter->data;
  8981. +
  8982. + if (strcmp(conffile->name, file_name) == 0) {
  8983. + return conffile;
  8984. + }
  8985. + }
  8986. +
  8987. + return NULL;
  8988. +}
  8989. +
  8990. +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
  8991. + const char *script, const char *args)
  8992. +{
  8993. + int err;
  8994. + char *path;
  8995. + char *cmd;
  8996. +
  8997. + /* XXX: FEATURE: When conf->offline_root is set, we should run the
  8998. + maintainer script within a chroot environment. */
  8999. +
  9000. + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
  9001. + have scripts in pkg->tmp_unpack_dir. */
  9002. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  9003. + if (pkg->dest == NULL) {
  9004. + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
  9005. + __FUNCTION__, pkg->name);
  9006. + return EINVAL;
  9007. + }
  9008. + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
  9009. + } else {
  9010. + if (pkg->tmp_unpack_dir == NULL) {
  9011. + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
  9012. + __FUNCTION__, pkg->name);
  9013. + return EINVAL;
  9014. + }
  9015. + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
  9016. + }
  9017. +
  9018. + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
  9019. + if (conf->noaction) return 0;
  9020. +
  9021. + /* XXX: CLEANUP: There must be a better way to handle maintainer
  9022. + scripts when running with offline_root mode and/or a dest other
  9023. + than '/'. I've been playing around with some clever chroot
  9024. + tricks and I might come up with something workable. */
  9025. + if (conf->offline_root) {
  9026. + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
  9027. + }
  9028. +
  9029. + setenv("PKG_ROOT",
  9030. + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
  9031. +
  9032. + if (! file_exists(path)) {
  9033. + free(path);
  9034. + return 0;
  9035. + }
  9036. +
  9037. + if (conf->offline_root) {
  9038. + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
  9039. + free(path);
  9040. + return 0;
  9041. + }
  9042. +
  9043. + sprintf_alloc(&cmd, "%s %s", path, args);
  9044. + free(path);
  9045. +
  9046. + err = xsystem(cmd);
  9047. + free(cmd);
  9048. +
  9049. + if (err) {
  9050. + fprintf(stderr, "%s script returned status %d\n", script, err);
  9051. + return err;
  9052. + }
  9053. +
  9054. + return 0;
  9055. +}
  9056. +
  9057. +char *pkg_state_want_to_str(pkg_state_want_t sw)
  9058. +{
  9059. + int i;
  9060. +
  9061. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9062. + if (pkg_state_want_map[i].value == sw) {
  9063. + return strdup(pkg_state_want_map[i].str);
  9064. + }
  9065. + }
  9066. +
  9067. + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
  9068. + __FUNCTION__, sw);
  9069. + return strdup("<STATE_WANT_UNKNOWN>");
  9070. +}
  9071. +
  9072. +pkg_state_want_t pkg_state_want_from_str(char *str)
  9073. +{
  9074. + int i;
  9075. +
  9076. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9077. + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
  9078. + return pkg_state_want_map[i].value;
  9079. + }
  9080. + }
  9081. +
  9082. + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
  9083. + __FUNCTION__, str);
  9084. + return SW_UNKNOWN;
  9085. +}
  9086. +
  9087. +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
  9088. +{
  9089. + int i;
  9090. + int len = 3; /* ok\000 is minimum */
  9091. + char *str = NULL;
  9092. +
  9093. + /* clear the temporary flags before converting to string */
  9094. + sf &= SF_NONVOLATILE_FLAGS;
  9095. +
  9096. + if (sf == 0) {
  9097. + return strdup("ok");
  9098. + } else {
  9099. +
  9100. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9101. + if (sf & pkg_state_flag_map[i].value) {
  9102. + len += strlen(pkg_state_flag_map[i].str) + 1;
  9103. + }
  9104. + }
  9105. + str = malloc(len);
  9106. + if ( str == NULL ) {
  9107. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9108. + return NULL;
  9109. + }
  9110. + str[0] = 0;
  9111. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9112. + if (sf & pkg_state_flag_map[i].value) {
  9113. + strcat(str, pkg_state_flag_map[i].str);
  9114. + strcat(str, ",");
  9115. + }
  9116. + }
  9117. + len = strlen(str);
  9118. + str[len-1] = 0; /* squash last comma */
  9119. + return str;
  9120. + }
  9121. +}
  9122. +
  9123. +pkg_state_flag_t pkg_state_flag_from_str(char *str)
  9124. +{
  9125. + int i;
  9126. + int sf = SF_OK;
  9127. +
  9128. + if (strcmp(str, "ok") == 0) {
  9129. + return SF_OK;
  9130. + }
  9131. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9132. + const char *sfname = pkg_state_flag_map[i].str;
  9133. + int sfname_len = strlen(sfname);
  9134. + if (strncmp(str, sfname, sfname_len) == 0) {
  9135. + sf |= pkg_state_flag_map[i].value;
  9136. + str += sfname_len;
  9137. + if (str[0] == ',') {
  9138. + str++;
  9139. + } else {
  9140. + break;
  9141. + }
  9142. + }
  9143. + }
  9144. +
  9145. + return sf;
  9146. +}
  9147. +
  9148. +char *pkg_state_status_to_str(pkg_state_status_t ss)
  9149. +{
  9150. + int i;
  9151. +
  9152. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9153. + if (pkg_state_status_map[i].value == ss) {
  9154. + return strdup(pkg_state_status_map[i].str);
  9155. + }
  9156. + }
  9157. +
  9158. + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
  9159. + __FUNCTION__, ss);
  9160. + return strdup("<STATE_STATUS_UNKNOWN>");
  9161. +}
  9162. +
  9163. +pkg_state_status_t pkg_state_status_from_str(char *str)
  9164. +{
  9165. + int i;
  9166. +
  9167. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9168. + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
  9169. + return pkg_state_status_map[i].value;
  9170. + }
  9171. + }
  9172. +
  9173. + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
  9174. + __FUNCTION__, str);
  9175. + return SS_NOT_INSTALLED;
  9176. +}
  9177. +
  9178. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
  9179. +{
  9180. + nv_pair_list_elt_t *l;
  9181. +
  9182. + if (!pkg->architecture)
  9183. + return 1;
  9184. +
  9185. + l = conf->arch_list.head;
  9186. +
  9187. + while (l) {
  9188. + nv_pair_t *nv = l->data;
  9189. + if (strcmp(nv->name, pkg->architecture) == 0) {
  9190. + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
  9191. + return 1;
  9192. + }
  9193. + l = l->next;
  9194. + }
  9195. +
  9196. + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
  9197. + return 0;
  9198. +}
  9199. +
  9200. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
  9201. +{
  9202. + nv_pair_list_elt_t *l;
  9203. +
  9204. + l = conf->arch_list.head;
  9205. +
  9206. + while (l) {
  9207. + nv_pair_t *nv = l->data;
  9208. + if (strcmp(nv->name, archname) == 0) {
  9209. + int priority = strtol(nv->value, NULL, 0);
  9210. + return priority;
  9211. + }
  9212. + l = l->next;
  9213. + }
  9214. + return 0;
  9215. +}
  9216. +
  9217. +int pkg_info_preinstall_check(ipkg_conf_t *conf)
  9218. +{
  9219. + int i;
  9220. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9221. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  9222. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9223. +
  9224. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
  9225. + pkg_hash_fetch_available(pkg_hash, available_pkgs);
  9226. + /* update arch_priority for each package */
  9227. + for (i = 0; i < available_pkgs->len; i++) {
  9228. + pkg_t *pkg = available_pkgs->pkgs[i];
  9229. + int arch_priority = 1;
  9230. + if (!pkg)
  9231. + continue;
  9232. + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
  9233. + if (pkg->architecture)
  9234. + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
  9235. + else
  9236. + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
  9237. + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
  9238. + pkg->arch_priority = arch_priority;
  9239. + }
  9240. +
  9241. + for (i = 0; i < available_pkgs->len; i++) {
  9242. + pkg_t *pkg = available_pkgs->pkgs[i];
  9243. + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
  9244. + /* clear flags and want for any uninstallable package */
  9245. + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
  9246. + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
  9247. + pkg->state_want = SW_UNKNOWN;
  9248. + pkg->state_flag = 0;
  9249. + }
  9250. + }
  9251. + pkg_vec_free(available_pkgs);
  9252. +
  9253. + /* update the file owner data structure */
  9254. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
  9255. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9256. + for (i = 0; i < installed_pkgs->len; i++) {
  9257. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9258. + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
  9259. + str_list_elt_t *iter;
  9260. + if (installed_files == NULL) {
  9261. + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
  9262. + break;
  9263. + }
  9264. + for (iter = installed_files->head; iter; iter = iter->next) {
  9265. + char *installed_file = iter->data;
  9266. + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
  9267. + file_hash_set_file_owner(conf, installed_file, pkg);
  9268. + }
  9269. + }
  9270. + pkg_vec_free(installed_pkgs);
  9271. +
  9272. + return 0;
  9273. +}
  9274. +
  9275. +struct pkg_write_filelist_data {
  9276. + ipkg_conf_t *conf;
  9277. + pkg_t *pkg;
  9278. + FILE *stream;
  9279. +};
  9280. +
  9281. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
  9282. +{
  9283. + struct pkg_write_filelist_data *data = data_;
  9284. + pkg_t *entry = entry_;
  9285. + if (entry == data->pkg) {
  9286. + fprintf(data->stream, "%s\n", key);
  9287. + }
  9288. +}
  9289. +
  9290. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
  9291. +{
  9292. + struct pkg_write_filelist_data data;
  9293. + char *list_file_name = NULL;
  9294. + int err = 0;
  9295. +
  9296. + if (!pkg) {
  9297. + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
  9298. + return -EINVAL;
  9299. + }
  9300. + ipkg_message(conf, IPKG_INFO,
  9301. + " creating %s.list file\n", pkg->name);
  9302. + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
  9303. + if (!list_file_name) {
  9304. + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
  9305. + return -ENOMEM;
  9306. + }
  9307. + ipkg_message(conf, IPKG_INFO,
  9308. + " creating %s file for pkg %s\n", list_file_name, pkg->name);
  9309. + data.stream = fopen(list_file_name, "w");
  9310. + if (!data.stream) {
  9311. + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
  9312. + list_file_name, strerror(errno));
  9313. + return errno;
  9314. + }
  9315. + data.pkg = pkg;
  9316. + data.conf = conf;
  9317. + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
  9318. + fclose(data.stream);
  9319. + free(list_file_name);
  9320. +
  9321. + return err;
  9322. +}
  9323. +
  9324. +int pkg_write_changed_filelists(ipkg_conf_t *conf)
  9325. +{
  9326. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9327. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9328. + int i;
  9329. + int err;
  9330. + if (conf->noaction)
  9331. + return 0;
  9332. +
  9333. + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
  9334. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9335. + for (i = 0; i < installed_pkgs->len; i++) {
  9336. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9337. + if (pkg->state_flag & SF_FILELIST_CHANGED) {
  9338. + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
  9339. + err = pkg_write_filelist(conf, pkg);
  9340. + if (err)
  9341. + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
  9342. + }
  9343. + }
  9344. + return 0;
  9345. +}
  9346. diff -Nur busybox-1.22.1.orig/archival/libipkg/pkg.h busybox-1.22.1/archival/libipkg/pkg.h
  9347. --- busybox-1.22.1.orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
  9348. +++ busybox-1.22.1/archival/libipkg/pkg.h 2014-05-23 21:12:06.000000000 +0200
  9349. @@ -0,0 +1,229 @@
  9350. +/* pkg.h - the itsy package management system
  9351. +
  9352. + Carl D. Worth
  9353. +
  9354. + Copyright (C) 2001 University of Southern California
  9355. +
  9356. + This program is free software; you can redistribute it and/or
  9357. + modify it under the terms of the GNU General Public License as
  9358. + published by the Free Software Foundation; either version 2, or (at
  9359. + your option) any later version.
  9360. +
  9361. + This program is distributed in the hope that it will be useful, but
  9362. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9363. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9364. + General Public License for more details.
  9365. +*/
  9366. +
  9367. +#ifndef PKG_H
  9368. +#define PKG_H
  9369. +
  9370. +#include <sys/types.h>
  9371. +#include <sys/stat.h>
  9372. +#include <unistd.h>
  9373. +
  9374. +#include "pkg_vec.h"
  9375. +#include "str_list.h"
  9376. +#include "pkg_src.h"
  9377. +#include "pkg_dest.h"
  9378. +#include "ipkg_conf.h"
  9379. +#include "conffile_list.h"
  9380. +
  9381. +struct ipkg_conf;
  9382. +
  9383. +/* I think "Size" is currently the shortest field name */
  9384. +#define PKG_MINIMUM_FIELD_NAME_LEN 4
  9385. +
  9386. +enum pkg_state_want
  9387. +{
  9388. + SW_UNKNOWN = 1,
  9389. + SW_INSTALL,
  9390. + SW_DEINSTALL,
  9391. + SW_PURGE,
  9392. + SW_LAST_STATE_WANT
  9393. +};
  9394. +typedef enum pkg_state_want pkg_state_want_t;
  9395. +
  9396. +enum pkg_state_flag
  9397. +{
  9398. + SF_OK = 0,
  9399. + SF_REINSTREQ = 1,
  9400. + SF_HOLD = 2, /* do not upgrade version */
  9401. + SF_REPLACE = 4, /* replace this package */
  9402. + SF_NOPRUNE = 8, /* do not remove obsolete files */
  9403. + SF_PREFER = 16, /* prefer this version */
  9404. + SF_OBSOLETE = 32, /* old package in upgrade pair */
  9405. + SF_MARKED = 64, /* temporary mark */
  9406. + SF_FILELIST_CHANGED = 128, /* needs filelist written */
  9407. + SF_USER = 256,
  9408. + SF_LAST_STATE_FLAG
  9409. +};
  9410. +typedef enum pkg_state_flag pkg_state_flag_t;
  9411. +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
  9412. +
  9413. +enum pkg_state_status
  9414. +{
  9415. + SS_NOT_INSTALLED = 1,
  9416. + SS_UNPACKED,
  9417. + SS_HALF_CONFIGURED,
  9418. + SS_INSTALLED,
  9419. + SS_HALF_INSTALLED,
  9420. + SS_CONFIG_FILES,
  9421. + SS_POST_INST_FAILED,
  9422. + SS_REMOVAL_FAILED,
  9423. + SS_LAST_STATE_STATUS
  9424. +};
  9425. +typedef enum pkg_state_status pkg_state_status_t;
  9426. +
  9427. +struct abstract_pkg{
  9428. + char * name;
  9429. + int dependencies_checked;
  9430. + pkg_vec_t * pkgs;
  9431. + pkg_state_status_t state_status;
  9432. + pkg_state_flag_t state_flag;
  9433. + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
  9434. + abstract_pkg_vec_t * provided_by;
  9435. + abstract_pkg_vec_t * replaced_by;
  9436. +};
  9437. +
  9438. +#include "pkg_depends.h"
  9439. +
  9440. +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
  9441. +
  9442. + The 3 version fields should go into a single version struct. (This
  9443. + is especially important since, currently, pkg->version can easily
  9444. + be mistaken for pkg_verson_str_alloc(pkg) although they are very
  9445. + distinct. This has been the source of multiple bugs.
  9446. +
  9447. + The 3 state fields could possibly also go into their own struct.
  9448. +
  9449. + All fields which deal with lists of packages, (Depends,
  9450. + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
  9451. + be handled by a single struct in pkg_t
  9452. +
  9453. + All string fields for which there is a small set of possible
  9454. + values, (section, maintainer, architecture, maybe version?), that
  9455. + are reused among different packages -- for all such packages we
  9456. + should move from "char *"s to some atom datatype to share data
  9457. + storage and use less memory. We might even do reference counting,
  9458. + but probably not since most often we only create new pkg_t structs,
  9459. + we don't often free them. */
  9460. +struct pkg
  9461. +{
  9462. + char *name;
  9463. + unsigned long epoch;
  9464. + char *version;
  9465. + char *revision;
  9466. + char *familiar_revision;
  9467. + pkg_src_t *src;
  9468. + pkg_dest_t *dest;
  9469. + char *architecture;
  9470. + char *section;
  9471. + char *maintainer;
  9472. + char *description;
  9473. + pkg_state_want_t state_want;
  9474. + pkg_state_flag_t state_flag;
  9475. + pkg_state_status_t state_status;
  9476. + char **depends_str;
  9477. + int depends_count;
  9478. + char **pre_depends_str;
  9479. + int pre_depends_count;
  9480. + char **recommends_str;
  9481. + int recommends_count;
  9482. + char **suggests_str;
  9483. + int suggests_count;
  9484. + compound_depend_t * depends;
  9485. +
  9486. + /* Abhaya: new conflicts */
  9487. + char **conflicts_str;
  9488. + compound_depend_t * conflicts;
  9489. + int conflicts_count;
  9490. +
  9491. + char **replaces_str;
  9492. + int replaces_count;
  9493. + abstract_pkg_t ** replaces;
  9494. +
  9495. + char **provides_str;
  9496. + int provides_count;
  9497. + abstract_pkg_t ** provides;
  9498. +
  9499. + abstract_pkg_t *parent;
  9500. +
  9501. + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
  9502. +
  9503. + char *filename;
  9504. + char *local_filename;
  9505. + char *url;
  9506. + char *tmp_unpack_dir;
  9507. + char *md5sum;
  9508. + char *size;
  9509. + char *installed_size;
  9510. + char *priority;
  9511. + char *source;
  9512. + conffile_list_t conffiles;
  9513. + time_t installed_time;
  9514. + /* As pointer for lazy evaluation */
  9515. + str_list_t *installed_files;
  9516. + /* XXX: CLEANUP: I'd like to perhaps come up with a better
  9517. + mechanism to avoid the problem here, (which is that the
  9518. + installed_files list was being freed from an inner loop while
  9519. + still being used within an outer loop. */
  9520. + int installed_files_ref_cnt;
  9521. + int essential;
  9522. + int arch_priority;
  9523. +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
  9524. + int provided_by_hand;
  9525. +};
  9526. +
  9527. +pkg_t *pkg_new(void);
  9528. +int pkg_init(pkg_t *pkg);
  9529. +void pkg_deinit(pkg_t *pkg);
  9530. +int pkg_init_from_file(pkg_t *pkg, const char *filename);
  9531. +abstract_pkg_t *abstract_pkg_new(void);
  9532. +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
  9533. +
  9534. +/*
  9535. + * merges fields from newpkg into oldpkg.
  9536. + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
  9537. + */
  9538. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
  9539. +
  9540. +char *pkg_version_str_alloc(pkg_t *pkg);
  9541. +
  9542. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
  9543. +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
  9544. +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
  9545. +
  9546. +char * pkg_formatted_info(pkg_t *pkg );
  9547. +char * pkg_formatted_field(pkg_t *pkg, const char *field );
  9548. +
  9549. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
  9550. +
  9551. +void pkg_print_info(pkg_t *pkg, FILE *file);
  9552. +void pkg_print_status(pkg_t * pkg, FILE * file);
  9553. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
  9554. +str_list_t *pkg_get_installed_files(pkg_t *pkg);
  9555. +int pkg_free_installed_files(pkg_t *pkg);
  9556. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
  9557. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
  9558. +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
  9559. + const char *script, const char *args);
  9560. +
  9561. +/* enum mappings */
  9562. +char *pkg_state_want_to_str(pkg_state_want_t sw);
  9563. +pkg_state_want_t pkg_state_want_from_str(char *str);
  9564. +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
  9565. +pkg_state_flag_t pkg_state_flag_from_str(char *str);
  9566. +char *pkg_state_status_to_str(pkg_state_status_t ss);
  9567. +pkg_state_status_t pkg_state_status_from_str(char *str);
  9568. +
  9569. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
  9570. +
  9571. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
  9572. +int pkg_info_preinstall_check(ipkg_conf_t *conf);
  9573. +int pkg_free_installed_files(pkg_t *pkg);
  9574. +
  9575. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
  9576. +int pkg_write_changed_filelists(ipkg_conf_t *conf);
  9577. +
  9578. +#endif
  9579. diff -Nur busybox-1.22.1.orig/archival/libipkg/pkg_depends.c busybox-1.22.1/archival/libipkg/pkg_depends.c
  9580. --- busybox-1.22.1.orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
  9581. +++ busybox-1.22.1/archival/libipkg/pkg_depends.c 2014-05-23 21:12:06.000000000 +0200
  9582. @@ -0,0 +1,1032 @@
  9583. +/* pkg_depends.c - the itsy package management system
  9584. +
  9585. + Steven M. Ayer
  9586. +
  9587. + Copyright (C) 2002 Compaq Computer Corporation
  9588. +
  9589. + This program is free software; you can redistribute it and/or
  9590. + modify it under the terms of the GNU General Public License as
  9591. + published by the Free Software Foundation; either version 2, or (at
  9592. + your option) any later version.
  9593. +
  9594. + This program is distributed in the hope that it will be useful, but
  9595. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9596. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9597. + General Public License for more details.
  9598. +*/
  9599. +
  9600. +#include "ipkg.h"
  9601. +#include <errno.h>
  9602. +#include <ctype.h>
  9603. +
  9604. +#include "pkg.h"
  9605. +#include "ipkg_utils.h"
  9606. +#include "pkg_hash.h"
  9607. +#include "ipkg_message.h"
  9608. +#include "pkg_parse.h"
  9609. +#include "hash_table.h"
  9610. +
  9611. +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
  9612. +static depend_t * depend_init(void);
  9613. +static void depend_deinit(depend_t *d);
  9614. +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
  9615. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
  9616. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
  9617. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg);
  9618. +
  9619. +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
  9620. +{
  9621. + depend_t *depend = (depend_t *)cdata;
  9622. + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
  9623. + return 1;
  9624. + else
  9625. + return 0;
  9626. +}
  9627. +
  9628. +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
  9629. +{
  9630. + depend_t *depend = (depend_t *)cdata;
  9631. +#if 0
  9632. + pkg_t * temp = pkg_new();
  9633. + int comparison;
  9634. + parseVersion(temp, depend->version);
  9635. + comparison = pkg_compare_versions(pkg, temp);
  9636. + free(temp);
  9637. +
  9638. + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
  9639. + __FUNCTION__, pkg->name, pkg->version,
  9640. + depend, depend->constraint, depend->version,
  9641. + comparison, version_constraints_satisfied(depend, pkg));
  9642. +#endif
  9643. + if (version_constraints_satisfied(depend, pkg))
  9644. + return 1;
  9645. + else
  9646. + return 0;
  9647. +}
  9648. +
  9649. +/* returns ndependences or negative error value */
  9650. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
  9651. + pkg_vec_t *unsatisfied, char *** unresolved)
  9652. +{
  9653. + pkg_t * satisfier_entry_pkg;
  9654. + register int i, j, k, l;
  9655. + int count, found;
  9656. + char ** the_lost;
  9657. + abstract_pkg_t * ab_pkg;
  9658. +
  9659. + /*
  9660. + * this is a setup to check for redundant/cyclic dependency checks,
  9661. + * which are marked at the abstract_pkg level
  9662. + */
  9663. + if (!(ab_pkg = pkg->parent)) {
  9664. + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
  9665. + *unresolved = NULL;
  9666. + return 0;
  9667. + }
  9668. + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
  9669. + *unresolved = NULL;
  9670. + return 0;
  9671. + } else {
  9672. + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
  9673. + }
  9674. + /**/
  9675. +
  9676. + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
  9677. + if (!count){
  9678. + *unresolved = NULL;
  9679. + return 0;
  9680. + }
  9681. +
  9682. + the_lost = NULL;
  9683. +
  9684. + /* foreach dependency */
  9685. + for (i = 0; i < count; i++) {
  9686. + compound_depend_t * compound_depend = &pkg->depends[i];
  9687. + depend_t ** possible_satisfiers = compound_depend->possibilities;;
  9688. + found = 0;
  9689. + satisfier_entry_pkg = NULL;
  9690. +
  9691. + if (compound_depend->type == GREEDY_DEPEND) {
  9692. + /* foreach possible satisfier */
  9693. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9694. + /* foreach provided_by, which includes the abstract_pkg itself */
  9695. + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
  9696. + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
  9697. + int nposs = ab_provider_vec->len;
  9698. + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
  9699. + for (l = 0; l < nposs; l++) {
  9700. + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
  9701. + /* if no depends on this one, try the first package that Provides this one */
  9702. + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
  9703. + continue;
  9704. + }
  9705. +
  9706. + /* cruise this possiblity's pkg_vec looking for an installed version */
  9707. + for (k = 0; k < test_vec->len; k++) {
  9708. + pkg_t *pkg_scout = test_vec->pkgs[k];
  9709. + /* not installed, and not already known about? */
  9710. + if ((pkg_scout->state_want != SW_INSTALL)
  9711. + && !pkg_scout->parent->dependencies_checked
  9712. + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
  9713. + char ** newstuff = NULL;
  9714. + int rc;
  9715. + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
  9716. + /* check for not-already-installed dependencies */
  9717. + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
  9718. + pkg_scout,
  9719. + tmp_vec,
  9720. + &newstuff);
  9721. + if (newstuff == NULL) {
  9722. + int ok = 1;
  9723. + for (i = 0; i < rc; i++) {
  9724. + pkg_t *p = tmp_vec->pkgs[i];
  9725. + if (p->state_want == SW_INSTALL)
  9726. + continue;
  9727. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
  9728. + ok = 0;
  9729. + break;
  9730. + }
  9731. + pkg_vec_free (tmp_vec);
  9732. + if (ok) {
  9733. + /* mark this one for installation */
  9734. + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
  9735. + pkg_vec_insert(unsatisfied, pkg_scout);
  9736. + }
  9737. + } else {
  9738. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
  9739. + free (newstuff);
  9740. + }
  9741. + }
  9742. + }
  9743. + }
  9744. + }
  9745. +
  9746. + continue;
  9747. + }
  9748. +
  9749. + /* foreach possible satisfier, look for installed package */
  9750. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9751. + /* foreach provided_by, which includes the abstract_pkg itself */
  9752. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9753. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9754. + pkg_t *satisfying_pkg =
  9755. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9756. + pkg_installed_and_constraint_satisfied,
  9757. + dependence_to_satisfy, 1);
  9758. + /* Being that I can't test constraing in pkg_hash, I will test it here */
  9759. + if (satisfying_pkg != NULL) {
  9760. + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9761. + satisfying_pkg = NULL;
  9762. + }
  9763. + }
  9764. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
  9765. + if (satisfying_pkg != NULL) {
  9766. + found = 1;
  9767. + break;
  9768. + }
  9769. +
  9770. + }
  9771. + /* if nothing installed matches, then look for uninstalled satisfier */
  9772. + if (!found) {
  9773. + /* foreach possible satisfier, look for installed package */
  9774. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9775. + /* foreach provided_by, which includes the abstract_pkg itself */
  9776. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9777. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9778. + pkg_t *satisfying_pkg =
  9779. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9780. + pkg_constraint_satisfied,
  9781. + dependence_to_satisfy, 1);
  9782. + /* Being that I can't test constraing in pkg_hash, I will test it here too */
  9783. + if (satisfying_pkg != NULL) {
  9784. + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9785. + satisfying_pkg = NULL;
  9786. + }
  9787. + }
  9788. +
  9789. + /* user request overrides package recommendation */
  9790. + if (satisfying_pkg != NULL
  9791. + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
  9792. + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
  9793. + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
  9794. + pkg->name, satisfying_pkg->name);
  9795. + continue;
  9796. + }
  9797. +
  9798. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
  9799. + if (satisfying_pkg != NULL) {
  9800. + satisfier_entry_pkg = satisfying_pkg;
  9801. + break;
  9802. + }
  9803. + }
  9804. + }
  9805. +
  9806. + /* we didn't find one, add something to the unsatisfied vector */
  9807. + if (!found) {
  9808. + if (!satisfier_entry_pkg) {
  9809. + /* failure to meet recommendations is not an error */
  9810. + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
  9811. + the_lost = add_unresolved_dep(pkg, the_lost, i);
  9812. + else
  9813. + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
  9814. + pkg->name, compound_depend->possibilities[0]->pkg->name);
  9815. + }
  9816. + else {
  9817. + if (compound_depend->type == SUGGEST) {
  9818. + /* just mention it politely */
  9819. + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
  9820. + pkg->name, satisfier_entry_pkg->name);
  9821. + } else {
  9822. + char ** newstuff = NULL;
  9823. +
  9824. + if (satisfier_entry_pkg != pkg &&
  9825. + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
  9826. + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
  9827. + pkg_hash_fetch_unsatisfied_dependencies(conf,
  9828. + satisfier_entry_pkg,
  9829. + unsatisfied,
  9830. + &newstuff);
  9831. + the_lost = merge_unresolved(the_lost, newstuff);
  9832. + }
  9833. + }
  9834. + }
  9835. + }
  9836. + }
  9837. + *unresolved = the_lost;
  9838. +
  9839. + return unsatisfied->len;
  9840. +}
  9841. +
  9842. +/*checking for conflicts !in replaces
  9843. + If a packages conflicts with another but is also replacing it, I should not consider it a
  9844. + really conflicts
  9845. + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
  9846. +*/
  9847. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
  9848. +{
  9849. + int i ;
  9850. + int replaces_count = pkg->replaces_count;
  9851. + abstract_pkg_t **replaces;
  9852. +
  9853. + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
  9854. + return 0;
  9855. +
  9856. + replaces = pkg->replaces;
  9857. +
  9858. + for (i = 0; i < replaces_count; i++) {
  9859. + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
  9860. + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
  9861. + return 1;
  9862. + }
  9863. + }
  9864. + return 0;
  9865. +
  9866. +}
  9867. +
  9868. +
  9869. +/* Abhaya: added support for conflicts */
  9870. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg)
  9871. +{
  9872. + pkg_vec_t * installed_conflicts, * test_vec;
  9873. + compound_depend_t * conflicts;
  9874. + depend_t ** possible_satisfiers;
  9875. + depend_t * possible_satisfier;
  9876. + register int i, j, k;
  9877. + int count;
  9878. + abstract_pkg_t * ab_pkg;
  9879. + pkg_t **pkg_scouts;
  9880. + pkg_t *pkg_scout;
  9881. +
  9882. + /*
  9883. + * this is a setup to check for redundant/cyclic dependency checks,
  9884. + * which are marked at the abstract_pkg level
  9885. + */
  9886. + if(!(ab_pkg = pkg->parent)){
  9887. + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
  9888. + return (pkg_vec_t *)NULL;
  9889. + }
  9890. +
  9891. + conflicts = pkg->conflicts;
  9892. + if(!conflicts){
  9893. + return (pkg_vec_t *)NULL;
  9894. + }
  9895. + installed_conflicts = pkg_vec_alloc();
  9896. +
  9897. + count = pkg->conflicts_count;
  9898. +
  9899. +
  9900. +
  9901. + /* foreach conflict */
  9902. + for(i = 0; i < pkg->conflicts_count; i++){
  9903. +
  9904. + possible_satisfiers = conflicts->possibilities;
  9905. +
  9906. + /* foreach possible satisfier */
  9907. + for(j = 0; j < conflicts->possibility_count; j++){
  9908. + possible_satisfier = possible_satisfiers[j];
  9909. + if (!possible_satisfier)
  9910. + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
  9911. + if (!possible_satisfier->pkg)
  9912. + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
  9913. + test_vec = possible_satisfier->pkg->pkgs;
  9914. + if (test_vec) {
  9915. + /* pkg_vec found, it is an actual package conflict
  9916. + * cruise this possiblity's pkg_vec looking for an installed version */
  9917. + pkg_scouts = test_vec->pkgs;
  9918. + for(k = 0; k < test_vec->len; k++){
  9919. + pkg_scout = pkg_scouts[k];
  9920. + if (!pkg_scout) {
  9921. + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
  9922. + continue;
  9923. + }
  9924. + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
  9925. + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
  9926. + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
  9927. + pkg_vec_insert(installed_conflicts, pkg_scout);
  9928. + }
  9929. + }
  9930. + }
  9931. + }
  9932. + }
  9933. + conflicts++;
  9934. + }
  9935. +
  9936. + if (installed_conflicts->len)
  9937. + return installed_conflicts;
  9938. + pkg_vec_free(installed_conflicts);
  9939. + return (pkg_vec_t *)NULL;
  9940. +}
  9941. +
  9942. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
  9943. +{
  9944. + pkg_t * temp;
  9945. + int comparison;
  9946. +
  9947. + if(depends->constraint == NONE)
  9948. + return 1;
  9949. +
  9950. + temp = pkg_new();
  9951. +
  9952. + parseVersion(temp, depends->version);
  9953. +
  9954. + comparison = pkg_compare_versions(pkg, temp);
  9955. +
  9956. + free(temp);
  9957. +
  9958. + if((depends->constraint == EARLIER) &&
  9959. + (comparison < 0))
  9960. + return 1;
  9961. + else if((depends->constraint == LATER) &&
  9962. + (comparison > 0))
  9963. + return 1;
  9964. + else if(comparison == 0)
  9965. + return 1;
  9966. + else if((depends->constraint == LATER_EQUAL) &&
  9967. + (comparison >= 0))
  9968. + return 1;
  9969. + else if((depends->constraint == EARLIER_EQUAL) &&
  9970. + (comparison <= 0))
  9971. + return 1;
  9972. +
  9973. + return 0;
  9974. +}
  9975. +
  9976. +int pkg_dependence_satisfiable(depend_t *depend)
  9977. +{
  9978. + abstract_pkg_t *apkg = depend->pkg;
  9979. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9980. + int n_providers = provider_apkgs->len;
  9981. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9982. + pkg_vec_t *pkg_vec;
  9983. + int n_pkgs ;
  9984. + int i;
  9985. + int j;
  9986. +
  9987. + for (i = 0; i < n_providers; i++) {
  9988. + abstract_pkg_t *papkg = apkgs[i];
  9989. + pkg_vec = papkg->pkgs;
  9990. + if (pkg_vec) {
  9991. + n_pkgs = pkg_vec->len;
  9992. + for (j = 0; j < n_pkgs; j++) {
  9993. + pkg_t *pkg = pkg_vec->pkgs[j];
  9994. + if (version_constraints_satisfied(depend, pkg)) {
  9995. + return 1;
  9996. + }
  9997. + }
  9998. + }
  9999. + }
  10000. + return 0;
  10001. +}
  10002. +
  10003. +int pkg_dependence_satisfied(depend_t *depend)
  10004. +{
  10005. + abstract_pkg_t *apkg = depend->pkg;
  10006. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  10007. + int n_providers = provider_apkgs->len;
  10008. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  10009. + int i;
  10010. + int n_pkgs;
  10011. + int j;
  10012. +
  10013. + for (i = 0; i < n_providers; i++) {
  10014. + abstract_pkg_t *papkg = apkgs[i];
  10015. + pkg_vec_t *pkg_vec = papkg->pkgs;
  10016. + if (pkg_vec) {
  10017. + n_pkgs = pkg_vec->len;
  10018. + for (j = 0; j < n_pkgs; j++) {
  10019. + pkg_t *pkg = pkg_vec->pkgs[j];
  10020. + if (version_constraints_satisfied(depend, pkg)) {
  10021. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
  10022. + return 1;
  10023. + }
  10024. + }
  10025. + }
  10026. + }
  10027. + return 0;
  10028. +}
  10029. +
  10030. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
  10031. +{
  10032. + register int i;
  10033. + pkg_t ** pkgs = vec->pkgs;
  10034. +
  10035. + for(i = 0; i < vec->len; i++)
  10036. + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
  10037. + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
  10038. + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
  10039. + return 1;
  10040. + return 0;
  10041. +}
  10042. +
  10043. +
  10044. +#ifdef DeadCode
  10045. +/**
  10046. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10047. + * the same abstract package and 0 otherwise.
  10048. + */
  10049. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
  10050. +{
  10051. + abstract_pkg_t **provides = pkg->provides;
  10052. + int provides_count = pkg->provides_count;
  10053. + abstract_pkg_t **replacee_provides = replacee->provides;
  10054. + int replacee_provides_count = replacee->provides_count;
  10055. + int i, j;
  10056. + for (i = 0; i < provides_count; i++) {
  10057. + abstract_pkg_t *apkg = provides[i];
  10058. + for (j = 0; j < replacee_provides_count; j++) {
  10059. + abstract_pkg_t *replacee_apkg = replacee_provides[i];
  10060. + if (apkg == replacee_apkg)
  10061. + return 1;
  10062. + }
  10063. + }
  10064. + return 0;
  10065. +}
  10066. +#endif
  10067. +
  10068. +/**
  10069. + * pkg_provides_abstract returns 1 if pkg->provides contains providee
  10070. + * and 0 otherwise.
  10071. + */
  10072. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
  10073. +{
  10074. + abstract_pkg_t **provides = pkg->provides;
  10075. + int provides_count = pkg->provides_count;
  10076. + int i;
  10077. + for (i = 0; i < provides_count; i++) {
  10078. + if (provides[i] == providee)
  10079. + return 1;
  10080. + }
  10081. + return 0;
  10082. +}
  10083. +
  10084. +/**
  10085. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10086. + * otherwise.
  10087. + */
  10088. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
  10089. +{
  10090. + abstract_pkg_t **replaces = pkg->replaces;
  10091. + int replaces_count = pkg->replaces_count;
  10092. + /* abstract_pkg_t **replacee_provides = pkg->provides;
  10093. + int replacee_provides_count = pkg->provides_count; */
  10094. + int i, j;
  10095. + for (i = 0; i < replaces_count; i++) {
  10096. + abstract_pkg_t *abstract_replacee = replaces[i];
  10097. + for (j = 0; j < replaces_count; j++) {
  10098. + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
  10099. + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
  10100. + if (replacee->provides[j] == abstract_replacee)
  10101. + return 1;
  10102. + }
  10103. + }
  10104. + return 0;
  10105. +}
  10106. +
  10107. +
  10108. +/**
  10109. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
  10110. + * otherwise.
  10111. + */
  10112. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
  10113. +{
  10114. + compound_depend_t *conflicts = pkg->conflicts;
  10115. + int conflicts_count = pkg->conflicts_count;
  10116. + int i, j;
  10117. + for (i = 0; i < conflicts_count; i++) {
  10118. + int possibility_count = conflicts[i].possibility_count;
  10119. + struct depend **possibilities = conflicts[i].possibilities;
  10120. + for (j = 0; j < possibility_count; j++) {
  10121. + if (possibilities[j]->pkg == conflictee) {
  10122. + return 1;
  10123. + }
  10124. + }
  10125. + }
  10126. + return 0;
  10127. +}
  10128. +
  10129. +/**
  10130. + * pkg_conflicts returns 1 if pkg->conflicts contains one of
  10131. + * conflictee's provides and 0 otherwise.
  10132. + */
  10133. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
  10134. +{
  10135. + compound_depend_t *conflicts = pkg->conflicts;
  10136. + int conflicts_count = pkg->conflicts_count;
  10137. + abstract_pkg_t **conflictee_provides = conflictee->provides;
  10138. + int conflictee_provides_count = conflictee->provides_count;
  10139. + int i, j, k;
  10140. + int possibility_count;
  10141. + struct depend **possibilities;
  10142. + abstract_pkg_t *possibility ;
  10143. +
  10144. + for (i = 0; i < conflicts_count; i++) {
  10145. + possibility_count = conflicts[i].possibility_count;
  10146. + possibilities = conflicts[i].possibilities;
  10147. + for (j = 0; j < possibility_count; j++) {
  10148. + possibility = possibilities[j]->pkg;
  10149. + for (k = 0; k < conflictee_provides_count; k++) {
  10150. + if (possibility == conflictee_provides[k]) {
  10151. + return 1;
  10152. + }
  10153. + }
  10154. + }
  10155. + }
  10156. + return 0;
  10157. +}
  10158. +
  10159. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
  10160. +{
  10161. + int oldlen = 0, newlen = 0;
  10162. + char ** result;
  10163. + register int i, j;
  10164. +
  10165. + if(!newstuff)
  10166. + return oldstuff;
  10167. +
  10168. + while(oldstuff && oldstuff[oldlen]) oldlen++;
  10169. + while(newstuff && newstuff[newlen]) newlen++;
  10170. +
  10171. + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
  10172. + if (result == NULL) {
  10173. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10174. + return NULL;
  10175. + }
  10176. +
  10177. + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
  10178. + *(result + i) = *(newstuff + j);
  10179. +
  10180. + *(result + i) = NULL;
  10181. +
  10182. + return result;
  10183. +}
  10184. +
  10185. +/*
  10186. + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
  10187. + * this is null terminated, no count is carried around
  10188. + */
  10189. +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
  10190. +{
  10191. + int count;
  10192. + char ** resized;
  10193. + char *depend_str = pkg_depend_str(pkg, ref_ndx);
  10194. +
  10195. + count = 0;
  10196. + while(the_lost && the_lost[count]) count++;
  10197. +
  10198. + count++; /* need one to hold the null */
  10199. + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
  10200. + if (resized == NULL) {
  10201. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10202. + return NULL;
  10203. + }
  10204. + resized[count - 1] = strdup(depend_str);
  10205. + resized[count] = NULL;
  10206. +
  10207. + return resized;
  10208. +}
  10209. +
  10210. +void printDepends(pkg_t * pkg)
  10211. +{
  10212. + register int i, j;
  10213. + compound_depend_t * depend;
  10214. + int count;
  10215. +
  10216. + count = pkg->pre_depends_count + pkg->depends_count;
  10217. +
  10218. + depend = pkg->depends;
  10219. + if(!depend){
  10220. + fprintf(stderr, "Depends pointer is NULL\n");
  10221. + return;
  10222. + }
  10223. + for(i = 0; i < count; i++){
  10224. + fprintf(stderr, "%s has %d possibilities:\n",
  10225. + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
  10226. + depend->possibility_count);
  10227. + for(j = 0; j < depend->possibility_count; j++)
  10228. + fprintf(stderr, "\t%s version %s (%d)\n",
  10229. + depend->possibilities[j]->pkg->name,
  10230. + depend->possibilities[j]->version,
  10231. + depend->possibilities[j]->constraint);
  10232. + depend++;
  10233. + }
  10234. +}
  10235. +
  10236. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10237. +{
  10238. + register int i, j;
  10239. +
  10240. + /* every pkg provides itself */
  10241. + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
  10242. +
  10243. + if (!pkg->provides_count)
  10244. + return 0;
  10245. +
  10246. + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
  10247. + if (pkg->provides == NULL) {
  10248. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10249. + return -1 ;
  10250. + }
  10251. + pkg->provides[0] = ab_pkg;
  10252. +
  10253. + // if (strcmp(ab_pkg->name, pkg->name))
  10254. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10255. +
  10256. + for(i = 0; i < pkg->provides_count; i++){
  10257. + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
  10258. +
  10259. + pkg->provides[i+1] = provided_abpkg;
  10260. +
  10261. + j = 0;
  10262. + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
  10263. + }
  10264. + return 0;
  10265. +}
  10266. +
  10267. +/* Abhaya: added conflicts support */
  10268. +int buildConflicts(hash_table_t * hash, pkg_t * pkg)
  10269. +{
  10270. + register int i;
  10271. + compound_depend_t * conflicts;
  10272. +
  10273. + if (!pkg->conflicts_count)
  10274. + return 0;
  10275. +
  10276. + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
  10277. + pkg->conflicts_count);
  10278. + if (conflicts == NULL) {
  10279. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10280. + return -1;
  10281. + }
  10282. + for (i = 0; i < pkg->conflicts_count; i++) {
  10283. + conflicts->type = CONFLICTS;
  10284. + parseDepends(conflicts, hash,
  10285. + pkg->conflicts_str[i]);
  10286. +#if 0
  10287. + for (j = 0; j < conflicts->possibility_count; j++) {
  10288. + depend_t *possibility = conflicts->possibilities[j];
  10289. + abstract_pkg_t *conflicting_apkg = possibility->pkg;
  10290. + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
  10291. + }
  10292. +#endif
  10293. + conflicts++;
  10294. + }
  10295. + return 0;
  10296. +}
  10297. +
  10298. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10299. +{
  10300. + register int i, j;
  10301. +
  10302. + if (!pkg->replaces_count)
  10303. + return 0;
  10304. +
  10305. + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
  10306. + if (pkg->replaces == NULL) {
  10307. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10308. + return -1;
  10309. + }
  10310. +
  10311. + // if (strcmp(ab_pkg->name, pkg->name))
  10312. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10313. +
  10314. + for(i = 0; i < pkg->replaces_count; i++){
  10315. + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
  10316. +
  10317. + pkg->replaces[i] = old_abpkg;
  10318. +
  10319. + j = 0;
  10320. + if (!old_abpkg->replaced_by)
  10321. + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
  10322. + if ( old_abpkg->replaced_by == NULL ){
  10323. + return -1;
  10324. + }
  10325. + /* if a package pkg both replaces and conflicts old_abpkg,
  10326. + * then add it to the replaced_by vector so that old_abpkg
  10327. + * will be upgraded to ab_pkg automatically */
  10328. + if (pkg_conflicts_abstract(pkg, old_abpkg))
  10329. + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
  10330. + }
  10331. + return 0;
  10332. +}
  10333. +
  10334. +int buildDepends(hash_table_t * hash, pkg_t * pkg)
  10335. +{
  10336. + int count;
  10337. + register int i;
  10338. + compound_depend_t * depends;
  10339. +
  10340. + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
  10341. + return 0;
  10342. +
  10343. + if (0 && pkg->pre_depends_count)
  10344. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10345. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10346. + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
  10347. + if (depends == NULL) {
  10348. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10349. + return -1;
  10350. + }
  10351. +
  10352. +
  10353. + for(i = 0; i < pkg->pre_depends_count; i++){
  10354. + parseDepends(depends, hash, pkg->pre_depends_str[i]);
  10355. + if (0 && pkg->pre_depends_count)
  10356. + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
  10357. + pkg->pre_depends_str[i], depends, depends->possibility_count);
  10358. + depends->type = PREDEPEND;
  10359. + depends++;
  10360. + }
  10361. +
  10362. + for(i = 0; i < pkg->recommends_count; i++){
  10363. + parseDepends(depends, hash, pkg->recommends_str[i]);
  10364. + if (0 && pkg->recommends_count)
  10365. + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
  10366. + pkg->recommends_str[i], depends, depends->possibility_count);
  10367. + depends->type = RECOMMEND;
  10368. + depends++;
  10369. + }
  10370. +
  10371. + for(i = 0; i < pkg->suggests_count; i++){
  10372. + parseDepends(depends, hash, pkg->suggests_str[i]);
  10373. + if (0 && pkg->suggests_count)
  10374. + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
  10375. + pkg->suggests_str[i], depends, depends->possibility_count);
  10376. + depends->type = SUGGEST;
  10377. + depends++;
  10378. + }
  10379. +
  10380. + for(i = 0; i < pkg->depends_count; i++){
  10381. + parseDepends(depends, hash, pkg->depends_str[i]);
  10382. + if (0 && pkg->depends_count)
  10383. + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
  10384. + pkg->depends_str[i], depends, depends->possibility_count);
  10385. + depends++;
  10386. + }
  10387. + return 0;
  10388. +}
  10389. +
  10390. +/*
  10391. + * pkg_depend_string: returns the depends string specified by index_.
  10392. + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
  10393. + * [0,npredepends) -> returns pre_depends_str[index_]
  10394. + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index_]
  10395. + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index_]
  10396. + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index_]
  10397. + */
  10398. +char *pkg_depend_str(pkg_t *pkg, int index_)
  10399. +{
  10400. + if (index_ < pkg->pre_depends_count) {
  10401. + return pkg->pre_depends_str[index_];
  10402. + }
  10403. + index_ -= pkg->pre_depends_count;
  10404. +
  10405. + if (index_ < pkg->recommends_count) {
  10406. + return pkg->recommends_str[index_];
  10407. + }
  10408. + index_ -= pkg->recommends_count;
  10409. +
  10410. + if (index_ < pkg->suggests_count) {
  10411. + return pkg->suggests_str[index_];
  10412. + }
  10413. + index_ -= pkg->suggests_count;
  10414. +
  10415. + if (index_ < pkg->depends_count) {
  10416. + return pkg->depends_str[index_];
  10417. + }
  10418. + fprintf(stderr, "pkg_depend_str: index_ %d out of range for pkg=%s\n", index_, pkg->name);
  10419. + return NULL;
  10420. +}
  10421. +
  10422. +void freeDepends(pkg_t *pkg)
  10423. +{
  10424. + int i;
  10425. +
  10426. + if (pkg == NULL || pkg->depends == NULL) {
  10427. + return;
  10428. + }
  10429. +
  10430. + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
  10431. + for (i=0; i < pkg->depends->possibility_count; i++) {
  10432. + depend_deinit(pkg->depends->possibilities[i]);
  10433. + }
  10434. + free(pkg->depends->possibilities);
  10435. + free(pkg->depends);
  10436. + pkg->depends = NULL;
  10437. +}
  10438. +
  10439. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
  10440. +{
  10441. + compound_depend_t * depends;
  10442. + int count, othercount;
  10443. + register int i, j;
  10444. + abstract_pkg_t * ab_depend;
  10445. + abstract_pkg_t ** temp;
  10446. +
  10447. + count = pkg->pre_depends_count + pkg->depends_count;
  10448. + depends = pkg->depends;
  10449. +
  10450. + if (0 && pkg->pre_depends_count)
  10451. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10452. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10453. + for (i = 0; i < count; i++) {
  10454. + if (0 && pkg->pre_depends_count)
  10455. + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
  10456. + for (j = 0; j < depends->possibility_count; j++){
  10457. + ab_depend = depends->possibilities[j]->pkg;
  10458. + if(!ab_depend->depended_upon_by)
  10459. + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
  10460. +
  10461. + temp = ab_depend->depended_upon_by;
  10462. + othercount = 1;
  10463. + while(*temp){
  10464. + temp++;
  10465. + othercount++;
  10466. + }
  10467. + *temp = ab_pkg;
  10468. +
  10469. + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
  10470. + (othercount + 1) * sizeof(abstract_pkg_t *));
  10471. + /* the array may have moved */
  10472. + temp = ab_depend->depended_upon_by + othercount;
  10473. + *temp = NULL;
  10474. + }
  10475. + depends++;
  10476. + }
  10477. +}
  10478. +
  10479. +static depend_t * depend_init(void)
  10480. +{
  10481. + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
  10482. + if ( d==NULL ){
  10483. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10484. + return NULL;
  10485. + }
  10486. + d->constraint = NONE;
  10487. + d->version = NULL;
  10488. + d->pkg = NULL;
  10489. +
  10490. + return d;
  10491. +}
  10492. +
  10493. +static void depend_deinit(depend_t *d)
  10494. +{
  10495. + free(d);
  10496. +}
  10497. +
  10498. +static int parseDepends(compound_depend_t *compound_depend,
  10499. + hash_table_t * hash, char * depend_str)
  10500. +{
  10501. + char * pkg_name, buffer[2048];
  10502. + int num_of_ors = 0;
  10503. + register int i;
  10504. + register char * src, * dest;
  10505. + depend_t ** possibilities;
  10506. +
  10507. + /* first count the number of ored possibilities for satisfying dependency */
  10508. + src = depend_str;
  10509. + while(*src)
  10510. + if(*src++ == '|')
  10511. + num_of_ors++;
  10512. +
  10513. + compound_depend->type = DEPEND;
  10514. +
  10515. + compound_depend->possibility_count = num_of_ors + 1;
  10516. + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
  10517. + if (!possibilities)
  10518. + return -ENOMEM;
  10519. + compound_depend->possibilities = possibilities;
  10520. +
  10521. + src = depend_str;
  10522. + for(i = 0; i < num_of_ors + 1; i++){
  10523. + possibilities[i] = depend_init();
  10524. + if (!possibilities[i])
  10525. + return -ENOMEM;
  10526. + /* gobble up just the name first */
  10527. + dest = buffer;
  10528. + while(*src &&
  10529. + !isspace(*src) &&
  10530. + (*src != '(') &&
  10531. + (*src != '*') &&
  10532. + (*src != '|'))
  10533. + *dest++ = *src++;
  10534. + *dest = '\0';
  10535. + pkg_name = trim_alloc(buffer);
  10536. + if (pkg_name == NULL )
  10537. + return -ENOMEM;
  10538. +
  10539. + /* now look at possible version info */
  10540. +
  10541. + /* skip to next chars */
  10542. + if(isspace(*src))
  10543. + while(*src && isspace(*src)) src++;
  10544. +
  10545. + /* extract constraint and version */
  10546. + if(*src == '('){
  10547. + src++;
  10548. + if(!strncmp(src, "<<", 2)){
  10549. + possibilities[i]->constraint = EARLIER;
  10550. + src += 2;
  10551. + }
  10552. + else if(!strncmp(src, "<=", 2)){
  10553. + possibilities[i]->constraint = EARLIER_EQUAL;
  10554. + src += 2;
  10555. + }
  10556. + else if(!strncmp(src, ">=", 2)){
  10557. + possibilities[i]->constraint = LATER_EQUAL;
  10558. + src += 2;
  10559. + }
  10560. + else if(!strncmp(src, ">>", 2)){
  10561. + possibilities[i]->constraint = LATER;
  10562. + src += 2;
  10563. + }
  10564. + else if(!strncmp(src, "=", 1)){
  10565. + possibilities[i]->constraint = EQUAL;
  10566. + src++;
  10567. + }
  10568. + /* should these be here to support deprecated designations; dpkg does */
  10569. + else if(!strncmp(src, "<", 1)){
  10570. + possibilities[i]->constraint = EARLIER_EQUAL;
  10571. + src++;
  10572. + }
  10573. + else if(!strncmp(src, ">", 1)){
  10574. + possibilities[i]->constraint = LATER_EQUAL;
  10575. + src++;
  10576. + }
  10577. +
  10578. + /* now we have any constraint, pass space to version string */
  10579. + while(isspace(*src)) src++;
  10580. +
  10581. + /* this would be the version string */
  10582. + dest = buffer;
  10583. + while(*src && *src != ')')
  10584. + *dest++ = *src++;
  10585. + *dest = '\0';
  10586. +
  10587. + possibilities[i]->version = trim_alloc(buffer);
  10588. + /* fprintf(stderr, "let's print the depends version string:");
  10589. + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
  10590. + if (possibilities[i]->version == NULL )
  10591. + return -ENOMEM;
  10592. +
  10593. +
  10594. + }
  10595. + /* hook up the dependency to its abstract pkg */
  10596. + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
  10597. +
  10598. + free(pkg_name);
  10599. +
  10600. + /* now get past the ) and any possible | chars */
  10601. + while(*src &&
  10602. + (isspace(*src) ||
  10603. + (*src == ')') ||
  10604. + (*src == '|')))
  10605. + src++;
  10606. + if (*src == '*')
  10607. + {
  10608. + compound_depend->type = GREEDY_DEPEND;
  10609. + src++;
  10610. + }
  10611. + }
  10612. +
  10613. + return 0;
  10614. +}
  10615. diff -Nur busybox-1.22.1.orig/archival/libipkg/pkg_depends.h busybox-1.22.1/archival/libipkg/pkg_depends.h
  10616. --- busybox-1.22.1.orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
  10617. +++ busybox-1.22.1/archival/libipkg/pkg_depends.h 2014-05-23 21:12:06.000000000 +0200
  10618. @@ -0,0 +1,105 @@
  10619. +/* pkg_depends.h - the itsy package management system
  10620. +
  10621. + Steven M. Ayer
  10622. +
  10623. + Copyright (C) 2002 Compaq Computer Corporation
  10624. +
  10625. + This program is free software; you can redistribute it and/or
  10626. + modify it under the terms of the GNU General Public License as
  10627. + published by the Free Software Foundation; either version 2, or (at
  10628. + your option) any later version.
  10629. +
  10630. + This program is distributed in the hope that it will be useful, but
  10631. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10632. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10633. + General Public License for more details.
  10634. +*/
  10635. +
  10636. +#ifndef PKG_DEPENDS_H
  10637. +#define PKG_DEPENDS_H
  10638. +
  10639. +#include "pkg.h"
  10640. +#include "pkg_hash.h"
  10641. +
  10642. +enum depend_type {
  10643. + PREDEPEND,
  10644. + DEPEND,
  10645. + CONFLICTS,
  10646. + GREEDY_DEPEND,
  10647. + RECOMMEND,
  10648. + SUGGEST
  10649. +};
  10650. +typedef enum depend_type depend_type_t;
  10651. +
  10652. +enum version_constraint {
  10653. + NONE,
  10654. + EARLIER,
  10655. + EARLIER_EQUAL,
  10656. + EQUAL,
  10657. + LATER_EQUAL,
  10658. + LATER
  10659. +};
  10660. +typedef enum version_constraint version_constraint_t;
  10661. +
  10662. +struct depend{
  10663. + version_constraint_t constraint;
  10664. + char * version;
  10665. + abstract_pkg_t * pkg;
  10666. +};
  10667. +typedef struct depend depend_t;
  10668. +
  10669. +struct compound_depend{
  10670. + depend_type_t type;
  10671. + int possibility_count;
  10672. + struct depend ** possibilities;
  10673. +};
  10674. +typedef struct compound_depend compound_depend_t;
  10675. +
  10676. +#include "hash_table.h"
  10677. +
  10678. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10679. +int buildConflicts(hash_table_t * hash, pkg_t * pkg);
  10680. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10681. +int buildDepends(hash_table_t * hash, pkg_t * pkg);
  10682. +
  10683. +/**
  10684. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10685. + * the same abstract package and 0 otherwise.
  10686. + */
  10687. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
  10688. +
  10689. +/**
  10690. + * pkg_provides returns 1 if pkg->provides contains providee and 0
  10691. + * otherwise.
  10692. + */
  10693. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
  10694. +
  10695. +/**
  10696. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10697. + * otherwise.
  10698. + */
  10699. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
  10700. +
  10701. +/**
  10702. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
  10703. + * otherwise.
  10704. + */
  10705. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
  10706. +
  10707. +/**
  10708. + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
  10709. + * otherwise.
  10710. + */
  10711. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
  10712. +
  10713. +char *pkg_depend_str(pkg_t *pkg, int index_);
  10714. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
  10715. +void freeDepends(pkg_t *pkg);
  10716. +void printDepends(pkg_t * pkg);
  10717. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
  10718. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
  10719. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
  10720. +int pkg_dependence_satisfiable(depend_t *depend);
  10721. +int pkg_dependence_satisfied(depend_t *depend);
  10722. +
  10723. +#endif
  10724. diff -Nur busybox-1.22.1.orig/archival/libipkg/pkg_dest.c busybox-1.22.1/archival/libipkg/pkg_dest.c
  10725. --- busybox-1.22.1.orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
  10726. +++ busybox-1.22.1/archival/libipkg/pkg_dest.c 2014-05-23 21:12:06.000000000 +0200
  10727. @@ -0,0 +1,92 @@
  10728. +/* pkg_dest.c - the itsy package management system
  10729. +
  10730. + Carl D. Worth
  10731. +
  10732. + Copyright (C) 2001 University of Southern California
  10733. +
  10734. + This program is free software; you can redistribute it and/or
  10735. + modify it under the terms of the GNU General Public License as
  10736. + published by the Free Software Foundation; either version 2, or (at
  10737. + your option) any later version.
  10738. +
  10739. + This program is distributed in the hope that it will be useful, but
  10740. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10741. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10742. + General Public License for more details.
  10743. +*/
  10744. +
  10745. +#include "ipkg.h"
  10746. +
  10747. +#include "pkg_dest.h"
  10748. +#include "file_util.h"
  10749. +#include "str_util.h"
  10750. +#include "sprintf_alloc.h"
  10751. +
  10752. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
  10753. +{
  10754. + dest->name = strdup(name);
  10755. +
  10756. + /* Guarantee that dest->root_dir ends with a '/' */
  10757. + if (str_ends_with(root_dir, "/")) {
  10758. + dest->root_dir = strdup(root_dir);
  10759. + } else {
  10760. + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
  10761. + }
  10762. + file_mkdir_hier(dest->root_dir, 0755);
  10763. +
  10764. + sprintf_alloc(&dest->ipkg_dir, "%s%s",
  10765. + dest->root_dir, IPKG_STATE_DIR_PREFIX);
  10766. + file_mkdir_hier(dest->ipkg_dir, 0755);
  10767. +
  10768. + if (str_starts_with (lists_dir, "/"))
  10769. + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
  10770. + else
  10771. + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
  10772. +
  10773. + file_mkdir_hier(dest->lists_dir, 0755);
  10774. +
  10775. + sprintf_alloc(&dest->info_dir, "%s/%s",
  10776. + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
  10777. + file_mkdir_hier(dest->info_dir, 0755);
  10778. +
  10779. + sprintf_alloc(&dest->status_file_name, "%s/%s",
  10780. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10781. +
  10782. + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
  10783. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10784. +
  10785. + dest->status_file = NULL;
  10786. +
  10787. + return 0;
  10788. +}
  10789. +
  10790. +void pkg_dest_deinit(pkg_dest_t *dest)
  10791. +{
  10792. + free(dest->name);
  10793. + dest->name = NULL;
  10794. +
  10795. + free(dest->root_dir);
  10796. + dest->root_dir = NULL;
  10797. +
  10798. + free(dest->ipkg_dir);
  10799. + dest->ipkg_dir = NULL;
  10800. +
  10801. + free(dest->lists_dir);
  10802. + dest->lists_dir = NULL;
  10803. +
  10804. + free(dest->info_dir);
  10805. + dest->info_dir = NULL;
  10806. +
  10807. + free(dest->status_file_name);
  10808. + dest->status_file_name = NULL;
  10809. +
  10810. + free(dest->status_file_tmp_name);
  10811. + dest->status_file_tmp_name = NULL;
  10812. +
  10813. + if (dest->status_file) {
  10814. + fclose(dest->status_file);
  10815. + }
  10816. + dest->status_file = NULL;
  10817. +
  10818. + dest->root_dir = NULL;
  10819. +}
  10820. diff -Nur busybox-1.22.1.orig/archival/libipkg/pkg_dest.h busybox-1.22.1/archival/libipkg/pkg_dest.h
  10821. --- busybox-1.22.1.orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
  10822. +++ busybox-1.22.1/archival/libipkg/pkg_dest.h 2014-05-23 21:12:06.000000000 +0200
  10823. @@ -0,0 +1,38 @@
  10824. +/* pkg_dest.h - the itsy package management system
  10825. +
  10826. + Carl D. Worth
  10827. +
  10828. + Copyright (C) 2001 University of Southern California
  10829. +
  10830. + This program is free software; you can redistribute it and/or
  10831. + modify it under the terms of the GNU General Public License as
  10832. + published by the Free Software Foundation; either version 2, or (at
  10833. + your option) any later version.
  10834. +
  10835. + This program is distributed in the hope that it will be useful, but
  10836. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10837. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10838. + General Public License for more details.
  10839. +*/
  10840. +
  10841. +#ifndef PKG_DEST_H
  10842. +#define PKG_DEST_H
  10843. +
  10844. +typedef struct pkg_dest pkg_dest_t;
  10845. +struct pkg_dest
  10846. +{
  10847. + char *name;
  10848. + char *root_dir;
  10849. + char *ipkg_dir;
  10850. + char *lists_dir;
  10851. + char *info_dir;
  10852. + char *status_file_name;
  10853. + char *status_file_tmp_name;
  10854. + FILE *status_file;
  10855. +};
  10856. +
  10857. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
  10858. +void pkg_dest_deinit(pkg_dest_t *dest);
  10859. +
  10860. +#endif
  10861. +
  10862. diff -Nur busybox-1.22.1.orig/archival/libipkg/pkg_dest_list.c busybox-1.22.1/archival/libipkg/pkg_dest_list.c
  10863. --- busybox-1.22.1.orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
  10864. +++ busybox-1.22.1/archival/libipkg/pkg_dest_list.c 2014-05-23 21:12:06.000000000 +0200
  10865. @@ -0,0 +1,85 @@
  10866. +/* pkg_dest_list.c - the itsy package management system
  10867. +
  10868. + Carl D. Worth
  10869. +
  10870. + Copyright (C) 2001 University of Southern California
  10871. +
  10872. + This program is free software; you can redistribute it and/or
  10873. + modify it under the terms of the GNU General Public License as
  10874. + published by the Free Software Foundation; either version 2, or (at
  10875. + your option) any later version.
  10876. +
  10877. + This program is distributed in the hope that it will be useful, but
  10878. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10879. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10880. + General Public License for more details.
  10881. +*/
  10882. +
  10883. +#include "ipkg.h"
  10884. +
  10885. +#include "pkg_dest.h"
  10886. +#include "void_list.h"
  10887. +#include "pkg_dest_list.h"
  10888. +
  10889. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
  10890. +{
  10891. + return void_list_elt_init((void_list_elt_t *) elt, data);
  10892. +}
  10893. +
  10894. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
  10895. +{
  10896. + void_list_elt_deinit((void_list_elt_t *) elt);
  10897. +}
  10898. +
  10899. +int pkg_dest_list_init(pkg_dest_list_t *list)
  10900. +{
  10901. + return void_list_init((void_list_t *) list);
  10902. +}
  10903. +
  10904. +void pkg_dest_list_deinit(pkg_dest_list_t *list)
  10905. +{
  10906. + pkg_dest_list_elt_t *iter;
  10907. + pkg_dest_t *pkg_dest;
  10908. +
  10909. + for (iter = list->head; iter; iter = iter->next) {
  10910. + pkg_dest = iter->data;
  10911. + pkg_dest_deinit(pkg_dest);
  10912. +
  10913. + /* malloced in pkg_dest_list_append */
  10914. + free(pkg_dest);
  10915. + iter->data = NULL;
  10916. + }
  10917. + void_list_deinit((void_list_t *) list);
  10918. +}
  10919. +
  10920. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10921. + const char *root_dir,const char *lists_dir)
  10922. +{
  10923. + int err;
  10924. + pkg_dest_t *pkg_dest;
  10925. +
  10926. + /* freed in plg_dest_list_deinit */
  10927. + pkg_dest = malloc(sizeof(pkg_dest_t));
  10928. + if (pkg_dest == NULL) {
  10929. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10930. + return NULL;
  10931. + }
  10932. +
  10933. + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
  10934. + err = void_list_append((void_list_t *) list, pkg_dest);
  10935. + if (err) {
  10936. + return NULL;
  10937. + }
  10938. +
  10939. + return pkg_dest;
  10940. +}
  10941. +
  10942. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
  10943. +{
  10944. + return void_list_push((void_list_t *) list, data);
  10945. +}
  10946. +
  10947. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
  10948. +{
  10949. + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
  10950. +}
  10951. diff -Nur busybox-1.22.1.orig/archival/libipkg/pkg_dest_list.h busybox-1.22.1/archival/libipkg/pkg_dest_list.h
  10952. --- busybox-1.22.1.orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
  10953. +++ busybox-1.22.1/archival/libipkg/pkg_dest_list.h 2014-05-23 21:12:06.000000000 +0200
  10954. @@ -0,0 +1,50 @@
  10955. +/* pkg_dest_list.h - the itsy package management system
  10956. +
  10957. + Carl D. Worth
  10958. +
  10959. + Copyright (C) 2001 University of Southern California
  10960. +
  10961. + This program is free software; you can redistribute it and/or
  10962. + modify it under the terms of the GNU General Public License as
  10963. + published by the Free Software Foundation; either version 2, or (at
  10964. + your option) any later version.
  10965. +
  10966. + This program is distributed in the hope that it will be useful, but
  10967. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10968. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10969. + General Public License for more details.
  10970. +*/
  10971. +
  10972. +#ifndef PKG_DEST_LIST_H
  10973. +#define PKG_DEST_LIST_H
  10974. +
  10975. +#include "pkg_dest.h"
  10976. +
  10977. +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
  10978. +struct pkg_dest_list_elt
  10979. +{
  10980. + pkg_dest_list_elt_t *next;
  10981. + pkg_dest_t *data;
  10982. +};
  10983. +
  10984. +typedef struct pkg_dest_list pkg_dest_list_t;
  10985. +struct pkg_dest_list
  10986. +{
  10987. + pkg_dest_list_elt_t pre_head;
  10988. + pkg_dest_list_elt_t *head;
  10989. + pkg_dest_list_elt_t *tail;
  10990. +};
  10991. +
  10992. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
  10993. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
  10994. +
  10995. +int pkg_dest_list_init(pkg_dest_list_t *list);
  10996. +void pkg_dest_list_deinit(pkg_dest_list_t *list);
  10997. +
  10998. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10999. + const char *root_dir,const char* lists_dir);
  11000. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
  11001. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
  11002. +
  11003. +#endif
  11004. +
  11005. diff -Nur busybox-1.22.1.orig/archival/libipkg/pkg_extract.c busybox-1.22.1/archival/libipkg/pkg_extract.c
  11006. --- busybox-1.22.1.orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
  11007. +++ busybox-1.22.1/archival/libipkg/pkg_extract.c 2014-05-23 21:12:06.000000000 +0200
  11008. @@ -0,0 +1,255 @@
  11009. +/* pkg_extract.c - the itsy package management system
  11010. +
  11011. + Carl D. Worth
  11012. +
  11013. + Copyright (C) 2001 University of Southern California
  11014. +
  11015. + This program is free software; you can redistribute it and/or
  11016. + modify it under the terms of the GNU General Public License as
  11017. + published by the Free Software Foundation; either version 2, or (at
  11018. + your option) any later version.
  11019. +
  11020. + This program is distributed in the hope that it will be useful, but
  11021. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11022. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11023. + General Public License for more details.
  11024. +*/
  11025. +
  11026. +#include "ipkg.h"
  11027. +#include <errno.h>
  11028. +#include <fcntl.h>
  11029. +#include <stdio.h>
  11030. +
  11031. +#include "pkg_extract.h"
  11032. +
  11033. +#include "libbb.h"
  11034. +#include "file_util.h"
  11035. +#include "sprintf_alloc.h"
  11036. +#include "bb_archive.h"
  11037. +
  11038. +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
  11039. +#define IPKG_DATA_ARCHIVE "data.tar.gz"
  11040. +#define IPKG_CONTROL_FILE "control"
  11041. +
  11042. +static void FAST_FUNC ipkg_data_extract_all_prefix(archive_handle_t *archive_handle)
  11043. +{
  11044. + char *name_ptr = archive_handle->file_header->name;
  11045. +
  11046. + /* Skip all leading "/" */
  11047. + while (*name_ptr == '/')
  11048. + name_ptr++;
  11049. + /* Skip all leading "./" and "../" */
  11050. + while (name_ptr[0] == '.') {
  11051. + if (name_ptr[1] == '.' && name_ptr[2] == '/')
  11052. + name_ptr++;
  11053. + if (name_ptr[1] != '/')
  11054. + break;
  11055. + name_ptr += 2;
  11056. + }
  11057. +
  11058. + if (name_ptr[0] != '\0') {
  11059. + archive_handle->file_header->name = xasprintf("%s%s", archive_handle->dpkg__buffer, name_ptr);
  11060. + data_extract_all(archive_handle);
  11061. + }
  11062. +}
  11063. +
  11064. +static void FAST_FUNC ipkg_data_extract_to_buffer(archive_handle_t *archive_handle)
  11065. +{
  11066. + unsigned size = archive_handle->file_header->size;
  11067. +
  11068. + archive_handle->dpkg__buffer = xzalloc(size + 1);
  11069. + xread(archive_handle->src_fd, archive_handle->dpkg__buffer, size);
  11070. +}
  11071. +
  11072. +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
  11073. +{
  11074. + archive_handle_t *archive;
  11075. + char *path;
  11076. +
  11077. + sprintf_alloc(&path, "%s/", dir);
  11078. + archive = init_handle();
  11079. + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
  11080. + archive->filter = filter_accept_list;
  11081. + llist_add_to(&(archive->accept), (char *)filename);
  11082. + archive->dpkg__buffer = path;
  11083. + archive->action_data = ipkg_data_extract_all_prefix;
  11084. + archive->ah_flags |= ARCHIVE_UNLINK_OLD;
  11085. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11086. + close(archive->src_fd);
  11087. + free(archive->accept);
  11088. + free(archive);
  11089. + free(path);
  11090. +}
  11091. +
  11092. +static void FAST_FUNC data_extract_file_name_to_buffer(archive_handle_t *archive)
  11093. +{
  11094. + unsigned int size = strlen(archive->file_header->name) + 2;
  11095. +
  11096. + if (archive->dpkg__buffer == NULL) {
  11097. + archive->dpkg__buffer = xmalloc(size);
  11098. + strcpy(archive->dpkg__buffer, archive->file_header->name);
  11099. + } else {
  11100. + size += strlen(archive->dpkg__buffer);
  11101. + archive->dpkg__buffer = xrealloc(archive->dpkg__buffer, size);
  11102. + strcat(archive->dpkg__buffer, archive->file_header->name);
  11103. + }
  11104. + strcat(archive->dpkg__buffer, "\n");
  11105. + data_skip(archive);
  11106. +}
  11107. +
  11108. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
  11109. +{
  11110. + archive_handle_t *archive;
  11111. + char *name;
  11112. + const char *filename = IPKG_CONTROL_FILE;
  11113. +
  11114. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  11115. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  11116. + archive = init_handle();
  11117. + archive->src_fd = xopen(name, O_RDONLY);
  11118. + archive->filter = filter_accept_list;
  11119. + llist_add_to(&(archive->accept), (char *)filename);
  11120. + archive->action_data = ipkg_data_extract_to_buffer;
  11121. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11122. + close(archive->src_fd);
  11123. + fputs(archive->dpkg__buffer, stream);
  11124. + free(archive->dpkg__buffer);
  11125. + free(archive->accept);
  11126. + free(archive);
  11127. + free(name);
  11128. +
  11129. + return 0;
  11130. +}
  11131. +
  11132. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
  11133. +{
  11134. + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
  11135. +}
  11136. +
  11137. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
  11138. +{
  11139. + archive_handle_t *archive;
  11140. + char *name;
  11141. + char *path;
  11142. +
  11143. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  11144. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  11145. + sprintf_alloc(&path, "%s/%s", dir, prefix);
  11146. + archive = init_handle();
  11147. + archive->src_fd = xopen(name, O_RDONLY);
  11148. + archive->filter = filter_accept_all;
  11149. + archive->dpkg__buffer = path;
  11150. + archive->action_data = ipkg_data_extract_all_prefix;
  11151. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  11152. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11153. + close(archive->src_fd);
  11154. + free(archive);
  11155. + free(path);
  11156. + free(name);
  11157. +
  11158. + return 0;
  11159. +}
  11160. +
  11161. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
  11162. +{
  11163. + archive_handle_t *archive;
  11164. + char *name;
  11165. + char *path;
  11166. +
  11167. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  11168. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  11169. + sprintf_alloc(&path, "%s/", dir);
  11170. + archive = init_handle();
  11171. + archive->src_fd = xopen(name, O_RDONLY);
  11172. + archive->filter = filter_accept_all;
  11173. + archive->dpkg__buffer = path;
  11174. + archive->action_data = ipkg_data_extract_all_prefix;
  11175. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  11176. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11177. + close(archive->src_fd);
  11178. + free(archive);
  11179. + free(path);
  11180. + free(name);
  11181. +
  11182. + return 0;
  11183. +}
  11184. +
  11185. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
  11186. +{
  11187. + int err=0;
  11188. + char *line, *data_file;
  11189. + FILE *file;
  11190. + FILE *tmp;
  11191. +
  11192. + file = fopen(file_name, "w");
  11193. + if (file == NULL) {
  11194. + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
  11195. + __FUNCTION__, file_name);
  11196. + return EINVAL;
  11197. + }
  11198. +
  11199. + tmp = tmpfile();
  11200. + if (pkg->installed_files) {
  11201. + str_list_elt_t *elt;
  11202. + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
  11203. + fprintf(file, "%s\n", elt->data);
  11204. + }
  11205. + } else {
  11206. + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
  11207. + if (err) {
  11208. + fclose(file);
  11209. + fclose(tmp);
  11210. + return err;
  11211. + }
  11212. +
  11213. + /* Fixup data file names by removing the initial '.' */
  11214. + rewind(tmp);
  11215. + while (1) {
  11216. + line = file_read_line_alloc(tmp);
  11217. + if (line == NULL) {
  11218. + break;
  11219. + }
  11220. +
  11221. + data_file = line;
  11222. + if (*data_file == '.') {
  11223. + data_file++;
  11224. + }
  11225. +
  11226. + if (*data_file != '/') {
  11227. + fputs("/", file);
  11228. + }
  11229. +
  11230. + /* I have no idea why, but this is what dpkg does */
  11231. + if (strcmp(data_file, "/\n") == 0) {
  11232. + fputs("/.\n", file);
  11233. + } else {
  11234. + fputs(data_file, file);
  11235. + }
  11236. + }
  11237. + }
  11238. + fclose(tmp);
  11239. + fclose(file);
  11240. +
  11241. + return err;
  11242. +}
  11243. +
  11244. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
  11245. +{
  11246. + archive_handle_t *archive;
  11247. + char *name;
  11248. +
  11249. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  11250. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  11251. + archive = init_handle();
  11252. + archive->src_fd = xopen(name, O_RDONLY);
  11253. + archive->filter = filter_accept_all;
  11254. + archive->action_data = data_extract_file_name_to_buffer;
  11255. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11256. + close(archive->src_fd);
  11257. + fputs(archive->dpkg__buffer, file);
  11258. + free(archive->dpkg__buffer);
  11259. + free(archive);
  11260. + free(name);
  11261. +
  11262. + return 0;
  11263. +}
  11264. diff -Nur busybox-1.22.1.orig/archival/libipkg/pkg_extract.h busybox-1.22.1/archival/libipkg/pkg_extract.h
  11265. --- busybox-1.22.1.orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
  11266. +++ busybox-1.22.1/archival/libipkg/pkg_extract.h 2014-05-23 21:12:06.000000000 +0200
  11267. @@ -0,0 +1,32 @@
  11268. +/* pkg_extract.c - the itsy package management system
  11269. +
  11270. + Carl D. Worth
  11271. +
  11272. + Copyright (C) 2001 University of Southern California
  11273. +
  11274. + This program is free software; you can redistribute it and/or
  11275. + modify it under the terms of the GNU General Public License as
  11276. + published by the Free Software Foundation; either version 2, or (at
  11277. + your option) any later version.
  11278. +
  11279. + This program is distributed in the hope that it will be useful, but
  11280. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11281. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11282. + General Public License for more details.
  11283. +*/
  11284. +
  11285. +#ifndef PKG_EXTRACT_H
  11286. +#define PKG_EXTRACT_H
  11287. +
  11288. +#include "pkg.h"
  11289. +
  11290. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
  11291. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
  11292. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
  11293. + const char *dir,
  11294. + const char *prefix);
  11295. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
  11296. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
  11297. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
  11298. +
  11299. +#endif
  11300. diff -Nur busybox-1.22.1.orig/archival/libipkg/pkg_hash.c busybox-1.22.1/archival/libipkg/pkg_hash.c
  11301. --- busybox-1.22.1.orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
  11302. +++ busybox-1.22.1/archival/libipkg/pkg_hash.c 2014-05-23 21:12:06.000000000 +0200
  11303. @@ -0,0 +1,623 @@
  11304. +/* ipkg_hash.c - the itsy package management system
  11305. +
  11306. + Steven M. Ayer
  11307. +
  11308. + Copyright (C) 2002 Compaq Computer Corporation
  11309. +
  11310. + This program is free software; you can redistribute it and/or
  11311. + modify it under the terms of the GNU General Public License as
  11312. + published by the Free Software Foundation; either version 2, or (at
  11313. + your option) any later version.
  11314. +
  11315. + This program is distributed in the hope that it will be useful, but
  11316. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11317. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11318. + General Public License for more details.
  11319. +*/
  11320. +
  11321. +#include "ipkg.h"
  11322. +#include <errno.h>
  11323. +#include <ctype.h>
  11324. +#include <stdlib.h>
  11325. +#include <string.h>
  11326. +
  11327. +#include "hash_table.h"
  11328. +#include "pkg.h"
  11329. +#include "ipkg_message.h"
  11330. +#include "pkg_vec.h"
  11331. +#include "pkg_hash.h"
  11332. +#include "pkg_parse.h"
  11333. +#include "ipkg_utils.h"
  11334. +
  11335. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11336. +
  11337. +/*
  11338. + * this will talk to both feeds-lists files and installed status files
  11339. + * example api:
  11340. + *
  11341. + * hash_table_t hash;
  11342. + * pkg_hash_init(name, &hash, 1000);
  11343. + * pkg_hash_add_from_file(<feed filename>);
  11344. + *
  11345. + * the query function is just there as a shell to prove to me that this
  11346. + * sort of works, but isn't far from doing something useful
  11347. + *
  11348. + * -sma, 12/21/01
  11349. + * modified: CDW 3 Jan. 2002
  11350. + */
  11351. +
  11352. +
  11353. +
  11354. +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
  11355. +{
  11356. + return hash_table_init(name, hash, len);
  11357. +}
  11358. +
  11359. +void pkg_hash_deinit(hash_table_t *hash)
  11360. +{
  11361. + hash_table_deinit(hash);
  11362. +}
  11363. +
  11364. +
  11365. +/* Find the default arch for a given package status file if none is given. */
  11366. +static char *pkg_get_default_arch(ipkg_conf_t *conf)
  11367. +{
  11368. + nv_pair_list_elt_t *l;
  11369. + const char *def_arch = HOST_CPU_STR; /* Default arch */
  11370. + int def_prio = 0; /* Other archs override this */
  11371. +
  11372. + l = conf->arch_list.head;
  11373. +
  11374. + while (l) {
  11375. + nv_pair_t *nv = l->data;
  11376. + int priority = strtol(nv->value, NULL, 0);
  11377. +
  11378. + /* Check if this arch has higher priority, and is valid */
  11379. + if ((priority > def_prio) &&
  11380. + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
  11381. + /* Our new default */
  11382. + def_prio = priority;
  11383. + def_arch = nv->name;
  11384. + }
  11385. + l = l->next;
  11386. + }
  11387. +
  11388. + return strdup(def_arch);
  11389. +}
  11390. +
  11391. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11392. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
  11393. +{
  11394. + hash_table_t *hash = &conf->pkg_hash;
  11395. + char **raw;
  11396. + char **raw_start;
  11397. + pkg_t *pkg;
  11398. +
  11399. + raw = raw_start = read_raw_pkgs_from_file(file_name);
  11400. + if (!raw)
  11401. + return -ENOMEM;
  11402. +
  11403. + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
  11404. + pkg = pkg_new();
  11405. + if (!pkg)
  11406. + return -ENOMEM;
  11407. +
  11408. + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
  11409. + if (!pkg->architecture) {
  11410. + char *version_str = pkg_version_str_alloc(pkg);
  11411. + pkg->architecture = pkg_get_default_arch(conf);
  11412. + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
  11413. + pkg->name, version_str, pkg->architecture);
  11414. + free(version_str);
  11415. + }
  11416. + hash_insert_pkg(hash, pkg, is_status_file,conf);
  11417. + } else {
  11418. + free(pkg);
  11419. + }
  11420. + }
  11421. +
  11422. + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
  11423. + memory after read_raw_pkgs_from_file */
  11424. + raw = raw_start;
  11425. + while (*raw) {
  11426. + free(*raw++);
  11427. + }
  11428. + free(raw_start);
  11429. + return 0;
  11430. +}
  11431. +
  11432. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
  11433. +{
  11434. + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
  11435. +}
  11436. +
  11437. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
  11438. +{
  11439. + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
  11440. + if (apkg)
  11441. + return NULL;
  11442. + return apkg->provided_by;
  11443. +}
  11444. +
  11445. +
  11446. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11447. + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
  11448. +{
  11449. + int i;
  11450. + int nprovides = 0;
  11451. + int nmatching = 0;
  11452. + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
  11453. + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
  11454. + abstract_pkg_vec_t *provided_apkg_vec;
  11455. + abstract_pkg_t **provided_apkgs;
  11456. + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
  11457. + pkg_t *latest_installed_parent = NULL;
  11458. + pkg_t *latest_matching = NULL;
  11459. + pkg_t *held_pkg = NULL;
  11460. + pkg_t *good_pkg_by_name = NULL;
  11461. +
  11462. + if (matching_apkgs == NULL || providers == NULL ||
  11463. + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
  11464. + return NULL;
  11465. +
  11466. + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
  11467. +
  11468. + provided_apkg_vec = apkg->provided_by;
  11469. + nprovides = provided_apkg_vec->len;
  11470. + provided_apkgs = provided_apkg_vec->pkgs;
  11471. + if (nprovides > 1)
  11472. + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
  11473. +
  11474. + /* accumulate all the providers */
  11475. + for (i = 0; i < nprovides; i++) {
  11476. + abstract_pkg_t *provider_apkg = provided_apkgs[i];
  11477. + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
  11478. + abstract_pkg_vec_insert(providers, provider_apkg);
  11479. + }
  11480. + nprovides = providers->len;
  11481. +
  11482. + for (i = 0; i < nprovides; i++) {
  11483. + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
  11484. + abstract_pkg_t *replacement_apkg = NULL;
  11485. + pkg_vec_t *vec;
  11486. +
  11487. + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
  11488. + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
  11489. + if (provider_apkg->replaced_by->len > 1) {
  11490. + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
  11491. + provider_apkg->name, replacement_apkg->name);
  11492. + }
  11493. + }
  11494. +
  11495. + if (replacement_apkg)
  11496. + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
  11497. + replacement_apkg->name, provider_apkg->name);
  11498. +
  11499. + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
  11500. + if (abstract_pkg_vec_contains(providers, replacement_apkg))
  11501. + continue;
  11502. + else
  11503. + provider_apkg = replacement_apkg;
  11504. + }
  11505. +
  11506. + if (!(vec = provider_apkg->pkgs)) {
  11507. + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
  11508. + continue;
  11509. + }
  11510. +
  11511. +
  11512. + /* now check for supported architecture */
  11513. + {
  11514. + int max_count = 0;
  11515. + int j;
  11516. +
  11517. + /* count packages matching max arch priority and keep track of last one */
  11518. + for (j = 0; j < vec->len; j++) {
  11519. + pkg_t *maybe = vec->pkgs[j];
  11520. + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
  11521. + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
  11522. + if (maybe->arch_priority > 0) {
  11523. + max_count++;
  11524. + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
  11525. + pkg_vec_insert(matching_pkgs, maybe);
  11526. + }
  11527. + }
  11528. + }
  11529. + }
  11530. +
  11531. + if (matching_pkgs->len > 1)
  11532. + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
  11533. + if (matching_apkgs->len > 1)
  11534. + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
  11535. +
  11536. +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
  11537. + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
  11538. +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
  11539. + Until now I always got the latest, but that breaks the downgrade option.
  11540. + If I stop at the first one, I would probably miss the new ones
  11541. + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
  11542. + or from a Packages feed.
  11543. + 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*/
  11544. +/*Pigi*/
  11545. +
  11546. + for (i = 0; i < matching_pkgs->len; i++) {
  11547. + pkg_t *matching = matching_pkgs->pkgs[i];
  11548. + if (constraint_fcn(matching, cdata)) { /* We found it */
  11549. + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
  11550. + good_pkg_by_name = matching;
  11551. + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
  11552. + break;
  11553. + }
  11554. + }
  11555. +
  11556. +
  11557. + for (i = 0; i < matching_pkgs->len; i++) {
  11558. + pkg_t *matching = matching_pkgs->pkgs[i];
  11559. + latest_matching = matching;
  11560. + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
  11561. + latest_installed_parent = matching;
  11562. + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
  11563. + if (held_pkg)
  11564. + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
  11565. + held_pkg->name, matching->name);
  11566. + held_pkg = matching;
  11567. + }
  11568. + }
  11569. +
  11570. + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
  11571. + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
  11572. + apkg->name, matching_apkgs->len);
  11573. + for (i = 0; i < matching_apkgs->len; i++) {
  11574. + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
  11575. + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
  11576. + }
  11577. + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
  11578. + }
  11579. +
  11580. + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
  11581. + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
  11582. + __FUNCTION__, apkg->name, matching_pkgs->len);
  11583. + for (i = 0; i < matching_pkgs->len; i++) {
  11584. + pkg_t *matching = matching_pkgs->pkgs[i];
  11585. + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
  11586. + matching->name, matching->version, matching->architecture);
  11587. + }
  11588. + }
  11589. +
  11590. + nmatching = matching_apkgs->len;
  11591. +
  11592. + pkg_vec_free(matching_pkgs);
  11593. + abstract_pkg_vec_free(matching_apkgs);
  11594. + abstract_pkg_vec_free(providers);
  11595. +
  11596. + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
  11597. + return good_pkg_by_name;
  11598. + }
  11599. + if (held_pkg) {
  11600. + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
  11601. + return held_pkg;
  11602. + }
  11603. + if (latest_installed_parent) {
  11604. + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
  11605. + return latest_installed_parent;
  11606. + }
  11607. + if (nmatching > 1) {
  11608. + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
  11609. + return NULL;
  11610. + }
  11611. + if (latest_matching) {
  11612. + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
  11613. + latest_matching->name, latest_matching->version, latest_matching->architecture);
  11614. + return latest_matching;
  11615. + }
  11616. + return NULL;
  11617. +}
  11618. +
  11619. +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
  11620. +{
  11621. + const char *name = (const char *)cdata;
  11622. + if (strcmp(pkg->name, name) == 0)
  11623. + return 1;
  11624. + else
  11625. + return 0;
  11626. +}
  11627. +
  11628. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
  11629. +{
  11630. + hash_table_t *hash = &conf->pkg_hash;
  11631. + abstract_pkg_t *apkg = NULL;
  11632. +
  11633. + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
  11634. + return NULL;
  11635. +
  11636. + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
  11637. +}
  11638. +
  11639. +
  11640. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11641. + const char *pkg_name,
  11642. + const char * version)
  11643. +{
  11644. + pkg_vec_t * vec;
  11645. + register int i;
  11646. + char *version_str = NULL;
  11647. +
  11648. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
  11649. + return NULL;
  11650. +
  11651. + for(i = 0; i < vec->len; i++) {
  11652. + version_str = pkg_version_str_alloc(vec->pkgs[i]);
  11653. + if(!strcmp(version_str, version)) {
  11654. + free(version_str);
  11655. + break;
  11656. + }
  11657. + free(version_str);
  11658. + }
  11659. +
  11660. + if(i == vec->len)
  11661. + return NULL;
  11662. +
  11663. + return vec->pkgs[i];
  11664. +}
  11665. +
  11666. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11667. + const char *pkg_name,
  11668. + pkg_dest_t *dest)
  11669. +{
  11670. + pkg_vec_t * vec;
  11671. + register int i;
  11672. +
  11673. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
  11674. + return NULL;
  11675. + }
  11676. +
  11677. + for(i = 0; i < vec->len; i++)
  11678. + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
  11679. + return vec->pkgs[i];
  11680. + }
  11681. + return NULL;
  11682. +}
  11683. +
  11684. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11685. + const char *pkg_name)
  11686. +{
  11687. + pkg_vec_t * vec;
  11688. + register int i;
  11689. +
  11690. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
  11691. + return NULL;
  11692. + }
  11693. +
  11694. + for(i = 0; i < vec->len; i++)
  11695. + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
  11696. + return vec->pkgs[i];
  11697. + }
  11698. +
  11699. + return NULL;
  11700. +}
  11701. +
  11702. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
  11703. +{
  11704. + abstract_pkg_t * ab_pkg;
  11705. +
  11706. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
  11707. + return NULL;
  11708. + }
  11709. +
  11710. + if (ab_pkg->pkgs) {
  11711. + return ab_pkg->pkgs;
  11712. + } else if (ab_pkg->provided_by) {
  11713. + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
  11714. + if (abpkg != NULL){
  11715. + return abpkg->pkgs;
  11716. + } else {
  11717. + return ab_pkg->pkgs;
  11718. + }
  11719. + } else {
  11720. + return NULL;
  11721. + }
  11722. +}
  11723. +
  11724. +static int pkg_compare_names(const void *p1, const void *p2)
  11725. +{
  11726. + const pkg_t *pkg1 = *(const pkg_t **)p1;
  11727. + const pkg_t *pkg2 = *(const pkg_t **)p2;
  11728. + if (pkg1->name == NULL)
  11729. + return 1;
  11730. + if (pkg2->name == NULL)
  11731. + return -1;
  11732. + return(strcmp(pkg1->name, pkg2->name));
  11733. +}
  11734. +
  11735. +
  11736. +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
  11737. +{
  11738. + int j;
  11739. + const char *name;
  11740. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11741. + pkg_vec_t *all = (pkg_vec_t *)data;
  11742. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11743. + name = pkg_name;
  11744. + if (pkg_vec) {
  11745. + for (j = 0; j < pkg_vec->len; j++) {
  11746. + pkg_t *pkg = pkg_vec->pkgs[j];
  11747. + pkg_vec_insert(all, pkg);
  11748. + }
  11749. + }
  11750. +}
  11751. +
  11752. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
  11753. +{
  11754. + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
  11755. + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
  11756. +}
  11757. +
  11758. +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
  11759. +{
  11760. + const char *name;
  11761. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11762. + pkg_vec_t *all = (pkg_vec_t *)data;
  11763. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11764. + int j;
  11765. + name = pkg_name;
  11766. + if (pkg_vec) {
  11767. + for (j = 0; j < pkg_vec->len; j++) {
  11768. + pkg_t *pkg = pkg_vec->pkgs[j];
  11769. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  11770. + pkg_vec_insert(all, pkg);
  11771. + }
  11772. + }
  11773. + }
  11774. +}
  11775. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
  11776. +{
  11777. + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
  11778. + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
  11779. +}
  11780. +
  11781. +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
  11782. +{
  11783. + int i;
  11784. + pkg_t *pkg;
  11785. + const char *name;
  11786. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11787. + ipkg_conf_t *conf = (ipkg_conf_t *)data;
  11788. + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
  11789. + name = pkg_name;
  11790. + fprintf(stdout, "%s\n", ab_pkg->name);
  11791. + i = 0;
  11792. + if (dependents != NULL)
  11793. + while (dependents [i] != NULL)
  11794. + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
  11795. + dependents = ab_pkg->provided_by->pkgs;
  11796. + i = 0;
  11797. + if (dependents != NULL)
  11798. + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
  11799. + printf ("\tprovided by - %s\n", dependents [i ++]->name);
  11800. + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
  11801. + if (pkg) {
  11802. + i = 0;
  11803. + while (i < pkg->depends_count)
  11804. + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
  11805. + }
  11806. +}
  11807. +void pkg_hash_dump(hash_table_t *hash, void *data)
  11808. +{
  11809. +
  11810. + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
  11811. + hash_table_foreach(hash, pkg_hash_dump_helper, data);
  11812. + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
  11813. +}
  11814. +
  11815. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11816. +{
  11817. + abstract_pkg_t * ab_pkg;
  11818. +
  11819. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
  11820. + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
  11821. +
  11822. + return ab_pkg;
  11823. +}
  11824. +
  11825. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  11826. +{
  11827. + abstract_pkg_t * ab_pkg;
  11828. + int arch_priority;
  11829. +
  11830. + if(!pkg)
  11831. + return pkg;
  11832. +
  11833. + arch_priority = pkg->arch_priority;
  11834. +
  11835. + if (buildDepends(hash, pkg)<0){
  11836. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11837. + return NULL;
  11838. + }
  11839. + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
  11840. +
  11841. + if (set_status) {
  11842. + if (pkg->state_status == SS_INSTALLED) {
  11843. + ab_pkg->state_status = SS_INSTALLED;
  11844. + } else if (pkg->state_status == SS_UNPACKED) {
  11845. + ab_pkg->state_status = SS_UNPACKED;
  11846. + }
  11847. + }
  11848. +
  11849. + if(!ab_pkg->pkgs)
  11850. + ab_pkg->pkgs = pkg_vec_alloc();
  11851. +
  11852. + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
  11853. + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
  11854. + pkg->parent = ab_pkg;
  11855. +
  11856. + if (buildProvides(hash, ab_pkg, pkg)<0){
  11857. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11858. + return NULL;
  11859. + }
  11860. + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
  11861. + if (buildConflicts(hash, pkg)<0){
  11862. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11863. + return NULL;
  11864. + }
  11865. + if (buildReplaces(hash, ab_pkg, pkg)<0) {
  11866. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11867. + return NULL;
  11868. + }
  11869. +
  11870. + buildDependedUponBy(pkg, ab_pkg);
  11871. + return pkg;
  11872. +}
  11873. +
  11874. +/*
  11875. + * this will assume that we've already determined that
  11876. + * the abstract pkg doesn't exist, 'cause we should know these things...
  11877. + */
  11878. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11879. +{
  11880. + abstract_pkg_t * ab_pkg;
  11881. +
  11882. + ab_pkg = abstract_pkg_new();
  11883. + if (ab_pkg == NULL) { return NULL; }
  11884. +
  11885. + ab_pkg->name = strdup(pkg_name);
  11886. + hash_table_insert(hash, pkg_name, ab_pkg);
  11887. +
  11888. + return ab_pkg;
  11889. +}
  11890. +
  11891. +
  11892. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
  11893. +{
  11894. + hash_table_t *file_hash = &conf->file_hash;
  11895. +
  11896. + return hash_table_get(file_hash, file_name);
  11897. +}
  11898. +
  11899. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
  11900. +{
  11901. + hash_table_t *file_hash = &conf->file_hash;
  11902. + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
  11903. + int file_name_len = strlen(file_name);
  11904. +
  11905. + if (file_name[file_name_len -1] == '/')
  11906. + return 0;
  11907. +
  11908. + if (conf->offline_root) {
  11909. + int len = strlen(conf->offline_root);
  11910. + if (strncmp(file_name, conf->offline_root, len) == 0) {
  11911. + file_name += len;
  11912. + }
  11913. + }
  11914. +
  11915. + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
  11916. + hash_table_insert(file_hash, file_name, owning_pkg);
  11917. + if (old_owning_pkg) {
  11918. + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
  11919. + /* mark this package to have its filelist written */
  11920. + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11921. + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11922. + }
  11923. + return 0;
  11924. +}
  11925. +
  11926. +
  11927. diff -Nur busybox-1.22.1.orig/archival/libipkg/pkg_hash.h busybox-1.22.1/archival/libipkg/pkg_hash.h
  11928. --- busybox-1.22.1.orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
  11929. +++ busybox-1.22.1/archival/libipkg/pkg_hash.h 2014-05-23 21:12:06.000000000 +0200
  11930. @@ -0,0 +1,61 @@
  11931. +/* pkg_hash.h - the itsy package management system
  11932. +
  11933. + Steven M. Ayer
  11934. +
  11935. + Copyright (C) 2002 Compaq Computer Corporation
  11936. +
  11937. + This program is free software; you can redistribute it and/or
  11938. + modify it under the terms of the GNU General Public License as
  11939. + published by the Free Software Foundation; either version 2, or (at
  11940. + your option) any later version.
  11941. +
  11942. + This program is distributed in the hope that it will be useful, but
  11943. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11944. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11945. + General Public License for more details.
  11946. +*/
  11947. +
  11948. +#ifndef PKG_HASH_H
  11949. +#define PKG_HASH_H
  11950. +
  11951. +#include "pkg.h"
  11952. +#include "pkg_vec.h"
  11953. +#include "hash_table.h"
  11954. +
  11955. +
  11956. +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
  11957. +void pkg_hash_deinit(hash_table_t *hash);
  11958. +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
  11959. +
  11960. +void pkg_hash_dump(hash_table_t *hash, void *data);
  11961. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
  11962. +
  11963. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11964. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
  11965. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
  11966. +
  11967. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11968. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
  11969. +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11970. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
  11971. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11972. + const char *pkg_name,
  11973. + const char * version);
  11974. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
  11975. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11976. + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
  11977. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
  11978. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11979. + const char *pkg_name);
  11980. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11981. + const char *pkg_name,
  11982. + pkg_dest_t *dest);
  11983. +
  11984. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
  11985. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
  11986. +
  11987. +/* XXX: shouldn't this go in pkg_vec.[ch]? */
  11988. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11989. +
  11990. +#endif
  11991. +
  11992. diff -Nur busybox-1.22.1.orig/archival/libipkg/pkg_parse.c busybox-1.22.1/archival/libipkg/pkg_parse.c
  11993. --- busybox-1.22.1.orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
  11994. +++ busybox-1.22.1/archival/libipkg/pkg_parse.c 2014-05-23 21:12:06.000000000 +0200
  11995. @@ -0,0 +1,368 @@
  11996. +/* pkg_parse.c - the itsy package management system
  11997. +
  11998. + Steven M. Ayer
  11999. +
  12000. + Copyright (C) 2002 Compaq Computer Corporation
  12001. +
  12002. + This program is free software; you can redistribute it and/or
  12003. + modify it under the terms of the GNU General Public License as
  12004. + published by the Free Software Foundation; either version 2, or (at
  12005. + your option) any later version.
  12006. +
  12007. + This program is distributed in the hope that it will be useful, but
  12008. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12009. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12010. + General Public License for more details.
  12011. +*/
  12012. +
  12013. +#include "ipkg.h"
  12014. +#include <errno.h>
  12015. +#include <ctype.h>
  12016. +
  12017. +#include "pkg.h"
  12018. +#include "ipkg_utils.h"
  12019. +#include "pkg_parse.h"
  12020. +
  12021. +int alterProvidesLine(char *raw, char *temp);
  12022. +
  12023. +int isGenericFieldType(char * type, char * line)
  12024. +{
  12025. + if(!strncmp(line, type, strlen(type)))
  12026. + return 1;
  12027. + return 0;
  12028. +}
  12029. +
  12030. +char * parseGenericFieldType(char * type, char * raw)
  12031. +{
  12032. + char * field_value = raw + (strlen(type) + 1);
  12033. + return trim_alloc(field_value);
  12034. +}
  12035. +
  12036. +void parseStatus(pkg_t *pkg, char * raw)
  12037. +{
  12038. + char sw_str[64], sf_str[64], ss_str[64];
  12039. +
  12040. + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
  12041. + pkg->state_want = pkg_state_want_from_str(sw_str);
  12042. + pkg->state_flag = pkg_state_flag_from_str(sf_str);
  12043. + pkg->state_status = pkg_state_status_from_str(ss_str);
  12044. +}
  12045. +
  12046. +char ** parseDependsString(char * raw, int * depends_count)
  12047. +{
  12048. + char ** depends = NULL;
  12049. + int line_count = 0;
  12050. + char buff[2048], * dest;
  12051. +
  12052. + while(raw && *raw && !isspace(*raw)) {
  12053. + raw++;
  12054. + }
  12055. +
  12056. + if(line_is_blank(raw)){
  12057. + *depends_count = line_count;
  12058. + return NULL;
  12059. + }
  12060. + while(raw && *raw){
  12061. + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
  12062. +
  12063. + while(isspace(*raw)) raw++;
  12064. +
  12065. + dest = buff;
  12066. + while((*raw != ',') && *raw)
  12067. + *dest++ = *raw++;
  12068. +
  12069. + *dest = '\0';
  12070. + depends[line_count] = trim_alloc(buff);
  12071. + if(depends[line_count] ==NULL)
  12072. + return NULL;
  12073. + line_count++;
  12074. + if(*raw == ',')
  12075. + raw++;
  12076. + }
  12077. + *depends_count = line_count;
  12078. + return depends;
  12079. +}
  12080. +
  12081. +void parseConffiles(pkg_t * pkg, char * raw)
  12082. +{
  12083. + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
  12084. +
  12085. + if(!strncmp(raw, "Conffiles:", 10))
  12086. + raw += strlen("Conffiles:");
  12087. +
  12088. + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
  12089. + conffile_list_append(&pkg->conffiles, file_name, md5sum);
  12090. + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
  12091. + while (*raw && isspace(*raw)) {
  12092. + raw++;
  12093. + }
  12094. + raw += strlen(file_name);
  12095. + while (*raw && isspace(*raw)) {
  12096. + raw++;
  12097. + }
  12098. + raw += strlen(md5sum);
  12099. + }
  12100. +}
  12101. +
  12102. +int parseVersion(pkg_t *pkg, char *raw)
  12103. +{
  12104. + char *colon, *eepochcolon;
  12105. +#ifdef USE_DEBVERSION
  12106. + char *hyphen;
  12107. +#endif
  12108. + unsigned long epoch;
  12109. +
  12110. + if (!*raw) {
  12111. + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
  12112. + return EINVAL;
  12113. + }
  12114. +
  12115. + if (strncmp(raw, "Version:", 8) == 0) {
  12116. + raw += 8;
  12117. + }
  12118. + while (*raw && isspace(*raw)) {
  12119. + raw++;
  12120. + }
  12121. +
  12122. + colon= strchr(raw,':');
  12123. + if (colon) {
  12124. + epoch= strtoul(raw,&eepochcolon,10);
  12125. + if (colon != eepochcolon) {
  12126. + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
  12127. + return EINVAL;
  12128. + }
  12129. + if (!*++colon) {
  12130. + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
  12131. + return EINVAL;
  12132. + }
  12133. + raw= colon;
  12134. + pkg->epoch= epoch;
  12135. + } else {
  12136. + pkg->epoch= 0;
  12137. + }
  12138. +
  12139. + pkg->revision = (char *)"";
  12140. + pkg->familiar_revision = (char *)"";
  12141. +
  12142. + pkg->version= malloc(strlen(raw)+1);
  12143. + if ( pkg->version == NULL ) {
  12144. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12145. + return ENOMEM;
  12146. + }
  12147. + strcpy(pkg->version, raw);
  12148. +
  12149. +#ifdef USE_DEBVERSION
  12150. + hyphen= strrchr(pkg->version,'-');
  12151. +
  12152. + if (hyphen) {
  12153. + *hyphen++= 0;
  12154. + if (strncmp("fam", hyphen, 3) == 0) {
  12155. + pkg->familiar_revision=hyphen+3;
  12156. + hyphen= strrchr(pkg->version,'-');
  12157. + if (hyphen) {
  12158. + *hyphen++= 0;
  12159. + pkg->revision = hyphen;
  12160. + }
  12161. + } else {
  12162. + pkg->revision = hyphen;
  12163. + }
  12164. + }
  12165. +#endif
  12166. +
  12167. +/*
  12168. + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
  12169. + pkg->epoch,
  12170. + pkg->version,
  12171. + pkg->revision,
  12172. + pkg->familiar_revision);
  12173. +*/
  12174. +
  12175. + return 0;
  12176. +}
  12177. +
  12178. +
  12179. +/* This code is needed to insert in first position the keyword for the aligning bug */
  12180. +
  12181. +int alterProvidesLine(char *raw, char *temp)
  12182. +{
  12183. +
  12184. +
  12185. + if (!*raw) {
  12186. + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
  12187. + return -EINVAL;
  12188. + }
  12189. +
  12190. + if ( temp == NULL ) {
  12191. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12192. + return -ENOMEM;
  12193. + }
  12194. +
  12195. + if (strncmp(raw, "Provides:", 9) == 0) {
  12196. + raw += 9;
  12197. + }
  12198. + while (*raw && isspace(*raw)) {
  12199. + raw++;
  12200. + }
  12201. +
  12202. + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
  12203. + while (*raw) {
  12204. + strncat( temp, raw++, 1);
  12205. + }
  12206. + return 0;
  12207. +
  12208. +}
  12209. +
  12210. +/* Some random thoughts from Carl:
  12211. +
  12212. + This function could be considerably simplified if we just kept
  12213. + an array of all the generic string-valued field names, and looped
  12214. + through those looking for a match. Also, these fields could perhaps
  12215. + be stored in the package as an array as well, (or, probably better,
  12216. + as an nv_pair_list_t).
  12217. +
  12218. + Fields which require special parsing or storage, (such as Depends:
  12219. + and Status:) could be handled as they are now.
  12220. +*/
  12221. +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
  12222. + to a dependency list. And, since we already have
  12223. + Depends/Pre-Depends and need to add Conflicts, Recommends, and
  12224. + Enhances, perhaps we could generalize all of these and save some
  12225. + code duplication.
  12226. +*/
  12227. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
  12228. +{
  12229. + int reading_conffiles, reading_description;
  12230. + int pkg_false_provides=1;
  12231. + char ** lines;
  12232. + char * provide=NULL;
  12233. +
  12234. + pkg->src = src;
  12235. + pkg->dest = dest;
  12236. +
  12237. + reading_conffiles = reading_description = 0;
  12238. +
  12239. + for (lines = *raw; *lines; lines++) {
  12240. + /* fprintf(stderr, "PARSING %s\n", *lines);*/
  12241. + if(isGenericFieldType((char *)"Package:", *lines))
  12242. + pkg->name = parseGenericFieldType((char *)"Package", *lines);
  12243. + else if(isGenericFieldType((char *)"Architecture:", *lines))
  12244. + pkg->architecture = parseGenericFieldType((char *)"Architecture", *lines);
  12245. + else if(isGenericFieldType((char *)"Filename:", *lines))
  12246. + pkg->filename = parseGenericFieldType((char *)"Filename", *lines);
  12247. + else if(isGenericFieldType((char *)"Section:", *lines))
  12248. + pkg->section = parseGenericFieldType((char *)"Section", *lines);
  12249. + else if(isGenericFieldType((char *)"MD5sum:", *lines))
  12250. + pkg->md5sum = parseGenericFieldType((char *)"MD5sum", *lines);
  12251. + /* The old ipkg wrote out status files with the wrong case for MD5sum,
  12252. + let's parse it either way */
  12253. + else if(isGenericFieldType((char *)"MD5Sum:", *lines))
  12254. + pkg->md5sum = parseGenericFieldType((char *)"MD5Sum", *lines);
  12255. + else if(isGenericFieldType((char *)"Size:", *lines))
  12256. + pkg->size = parseGenericFieldType((char *)"Size", *lines);
  12257. + else if(isGenericFieldType((char *)"Source:", *lines))
  12258. + pkg->source = parseGenericFieldType((char *)"Source", *lines);
  12259. + else if(isGenericFieldType((char *)"Installed-Size:", *lines))
  12260. + pkg->installed_size = parseGenericFieldType((char *)"Installed-Size", *lines);
  12261. + else if(isGenericFieldType((char *)"Installed-Time:", *lines)) {
  12262. + char *time_str = parseGenericFieldType((char *)"Installed-Time", *lines);
  12263. + pkg->installed_time = strtoul(time_str, NULL, 0);
  12264. + } else if(isGenericFieldType((char *)"Priority:", *lines))
  12265. + pkg->priority = parseGenericFieldType((char *)"Priority", *lines);
  12266. + else if(isGenericFieldType((char *)"Essential:", *lines)) {
  12267. + char *essential_value;
  12268. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12269. + if (strcmp(essential_value, "yes") == 0) {
  12270. + pkg->essential = 1;
  12271. + }
  12272. + free(essential_value);
  12273. + }
  12274. + else if(isGenericFieldType((char *)"Status", *lines))
  12275. + parseStatus(pkg, *lines);
  12276. + else if(isGenericFieldType((char *)"Version", *lines))
  12277. + parseVersion(pkg, *lines);
  12278. + else if(isGenericFieldType((char *)"Maintainer", *lines))
  12279. + pkg->maintainer = parseGenericFieldType((char *)"Maintainer", *lines);
  12280. + else if(isGenericFieldType((char *)"Conffiles", *lines)){
  12281. + parseConffiles(pkg, *lines);
  12282. + reading_conffiles = 1;
  12283. + }
  12284. + else if(isGenericFieldType((char *)"Description", *lines)) {
  12285. + pkg->description = parseGenericFieldType((char *)"Description", *lines);
  12286. + reading_conffiles = 0;
  12287. + reading_description = 1;
  12288. + }
  12289. +
  12290. + else if(isGenericFieldType((char *)"Provides", *lines)){
  12291. +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
  12292. + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
  12293. + if ( alterProvidesLine(*lines,provide) ){
  12294. + return EINVAL;
  12295. + }
  12296. + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
  12297. +/* Let's try to hack a bit here.
  12298. + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
  12299. + in alot of other places. We will remove it before writing down the status database */
  12300. + pkg_false_provides=0;
  12301. + free(provide);
  12302. + }
  12303. +
  12304. + else if(isGenericFieldType((char *)"Depends", *lines))
  12305. + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
  12306. + else if(isGenericFieldType((char *)"Pre-Depends", *lines))
  12307. + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
  12308. + else if(isGenericFieldType((char *)"Recommends", *lines))
  12309. + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
  12310. + else if(isGenericFieldType((char *)"Suggests", *lines))
  12311. + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
  12312. + /* Abhaya: support for conflicts */
  12313. + else if(isGenericFieldType((char *)"Conflicts", *lines))
  12314. + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
  12315. + else if(isGenericFieldType((char *)"Replaces", *lines))
  12316. + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
  12317. + else if(line_is_blank(*lines)) {
  12318. + lines++;
  12319. + break;
  12320. + }
  12321. + else if(**lines == ' '){
  12322. + if(reading_description) {
  12323. + /* we already know it's not blank, so the rest of description */
  12324. + pkg->description = realloc(pkg->description,
  12325. + strlen(pkg->description)
  12326. + + 1 + strlen(*lines) + 1);
  12327. + strcat(pkg->description, "\n");
  12328. + strcat(pkg->description, (*lines));
  12329. + }
  12330. + else if(reading_conffiles)
  12331. + parseConffiles(pkg, *lines);
  12332. + }
  12333. + }
  12334. + *raw = lines;
  12335. +/* If the ipk has not a Provides line, we insert our false line */
  12336. + if ( pkg_false_provides==1)
  12337. + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
  12338. +
  12339. + if (pkg->name) {
  12340. + return 0;
  12341. + } else {
  12342. + return EINVAL;
  12343. + }
  12344. +}
  12345. +
  12346. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
  12347. +{
  12348. + char ** lines;
  12349. +
  12350. + for (lines = *raw; *lines; lines++) {
  12351. + if(isGenericFieldType((char *)"Essential:", *lines)) {
  12352. + char *essential_value;
  12353. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12354. + if (strcmp(essential_value, "yes") == 0) {
  12355. + pkg->essential = 1;
  12356. + }
  12357. + free(essential_value);
  12358. + }
  12359. + }
  12360. + *raw = lines;
  12361. +
  12362. + return 0;
  12363. +}
  12364. diff -Nur busybox-1.22.1.orig/archival/libipkg/pkg_parse.h busybox-1.22.1/archival/libipkg/pkg_parse.h
  12365. --- busybox-1.22.1.orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
  12366. +++ busybox-1.22.1/archival/libipkg/pkg_parse.h 2014-05-23 21:12:06.000000000 +0200
  12367. @@ -0,0 +1,31 @@
  12368. +/* pkg_parse.h - the itsy package management system
  12369. +
  12370. + Steven M. Ayer
  12371. +
  12372. + Copyright (C) 2002 Compaq Computer Corporation
  12373. +
  12374. + This program is free software; you can redistribute it and/or
  12375. + modify it under the terms of the GNU General Public License as
  12376. + published by the Free Software Foundation; either version 2, or (at
  12377. + your option) any later version.
  12378. +
  12379. + This program is distributed in the hope that it will be useful, but
  12380. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12381. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12382. + General Public License for more details.
  12383. +*/
  12384. +
  12385. +#ifndef PKG_PARSE_H
  12386. +#define PKG_PARSE_H
  12387. +
  12388. +int isGenericFieldType(char * type, char * line);
  12389. +char * parseGenericFieldType(char * type, char * raw);
  12390. +void parseStatus(pkg_t *pkg, char * raw);
  12391. +int parseVersion(pkg_t *pkg, char *raw);
  12392. +char ** parseDependsString(char * raw, int * depends_count);
  12393. +int parseVersion(pkg_t *pkg, char *raw);
  12394. +void parseConffiles(pkg_t * pkg, char * raw);
  12395. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
  12396. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
  12397. +
  12398. +#endif
  12399. diff -Nur busybox-1.22.1.orig/archival/libipkg/pkg_src.c busybox-1.22.1/archival/libipkg/pkg_src.c
  12400. --- busybox-1.22.1.orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
  12401. +++ busybox-1.22.1/archival/libipkg/pkg_src.c 2014-05-23 21:12:06.000000000 +0200
  12402. @@ -0,0 +1,43 @@
  12403. +/* pkg_src.c - the itsy package management system
  12404. +
  12405. + Carl D. Worth
  12406. +
  12407. + Copyright (C) 2001 University of Southern California
  12408. +
  12409. + This program is free software; you can redistribute it and/or
  12410. + modify it under the terms of the GNU General Public License as
  12411. + published by the Free Software Foundation; either version 2, or (at
  12412. + your option) any later version.
  12413. +
  12414. + This program is distributed in the hope that it will be useful, but
  12415. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12416. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12417. + General Public License for more details.
  12418. +*/
  12419. +
  12420. +#include "ipkg.h"
  12421. +
  12422. +#include "pkg_src.h"
  12423. +#include "str_util.h"
  12424. +
  12425. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
  12426. +{
  12427. + src->gzip = gzip;
  12428. + src->name = str_dup_safe (name);
  12429. + src->value = str_dup_safe (base_url);
  12430. + if (extra_data)
  12431. + src->extra_data = str_dup_safe (extra_data);
  12432. + else
  12433. + src->extra_data = NULL;
  12434. + return 0;
  12435. +}
  12436. +
  12437. +void pkg_src_deinit(pkg_src_t *src)
  12438. +{
  12439. + free (src->name);
  12440. + free (src->value);
  12441. + if (src->extra_data)
  12442. + free (src->extra_data);
  12443. +}
  12444. +
  12445. +
  12446. diff -Nur busybox-1.22.1.orig/archival/libipkg/pkg_src.h busybox-1.22.1/archival/libipkg/pkg_src.h
  12447. --- busybox-1.22.1.orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
  12448. +++ busybox-1.22.1/archival/libipkg/pkg_src.h 2014-05-23 21:12:06.000000000 +0200
  12449. @@ -0,0 +1,34 @@
  12450. +/* pkg_src.h - the itsy package management system
  12451. +
  12452. + Carl D. Worth
  12453. +
  12454. + Copyright (C) 2001 University of Southern California
  12455. +
  12456. + This program is free software; you can redistribute it and/or
  12457. + modify it under the terms of the GNU General Public License as
  12458. + published by the Free Software Foundation; either version 2, or (at
  12459. + your option) any later version.
  12460. +
  12461. + This program is distributed in the hope that it will be useful, but
  12462. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12463. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12464. + General Public License for more details.
  12465. +*/
  12466. +
  12467. +#ifndef PKG_SRC_H
  12468. +#define PKG_SRC_H
  12469. +
  12470. +#include "nv_pair.h"
  12471. +
  12472. +typedef struct
  12473. +{
  12474. + char *name;
  12475. + char *value;
  12476. + char *extra_data;
  12477. + int gzip;
  12478. +} pkg_src_t;
  12479. +
  12480. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
  12481. +void pkg_src_deinit(pkg_src_t *src);
  12482. +
  12483. +#endif
  12484. diff -Nur busybox-1.22.1.orig/archival/libipkg/pkg_src_list.c busybox-1.22.1/archival/libipkg/pkg_src_list.c
  12485. --- busybox-1.22.1.orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
  12486. +++ busybox-1.22.1/archival/libipkg/pkg_src_list.c 2014-05-23 21:12:06.000000000 +0200
  12487. @@ -0,0 +1,75 @@
  12488. +/* pkg_src_list.c - the itsy package management system
  12489. +
  12490. + Carl D. Worth
  12491. +
  12492. + Copyright (C) 2001 University of Southern California
  12493. +
  12494. + This program is free software; you can redistribute it and/or
  12495. + modify it under the terms of the GNU General Public License as
  12496. + published by the Free Software Foundation; either version 2, or (at
  12497. + your option) any later version.
  12498. +
  12499. + This program is distributed in the hope that it will be useful, but
  12500. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12501. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12502. + General Public License for more details.
  12503. +*/
  12504. +
  12505. +#include "ipkg.h"
  12506. +
  12507. +#include "pkg_src_list.h"
  12508. +#include "void_list.h"
  12509. +
  12510. +int pkg_src_list_init(pkg_src_list_t *list)
  12511. +{
  12512. + return void_list_init((void_list_t *) list);
  12513. +}
  12514. +
  12515. +void pkg_src_list_deinit(pkg_src_list_t *list)
  12516. +{
  12517. + pkg_src_list_elt_t *iter;
  12518. + pkg_src_t *pkg_src;
  12519. +
  12520. + for (iter = list->head; iter; iter = iter->next) {
  12521. + pkg_src = iter->data;
  12522. + pkg_src_deinit(pkg_src);
  12523. +
  12524. + /* malloced in pkg_src_list_append */
  12525. + free(pkg_src);
  12526. + iter->data = NULL;
  12527. + }
  12528. + void_list_deinit((void_list_t *) list);
  12529. +}
  12530. +
  12531. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
  12532. + const char *name, const char *base_url, const char *extra_data,
  12533. + int gzip)
  12534. +{
  12535. + int err;
  12536. +
  12537. + /* freed in pkg_src_list_deinit */
  12538. + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
  12539. +
  12540. + if (pkg_src == NULL) {
  12541. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12542. + return NULL;
  12543. + }
  12544. + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
  12545. +
  12546. + err = void_list_append((void_list_t *) list, pkg_src);
  12547. + if (err) {
  12548. + return NULL;
  12549. + }
  12550. +
  12551. + return pkg_src;
  12552. +}
  12553. +
  12554. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
  12555. +{
  12556. + return void_list_push((void_list_t *) list, data);
  12557. +}
  12558. +
  12559. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
  12560. +{
  12561. + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
  12562. +}
  12563. diff -Nur busybox-1.22.1.orig/archival/libipkg/pkg_src_list.h busybox-1.22.1/archival/libipkg/pkg_src_list.h
  12564. --- busybox-1.22.1.orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
  12565. +++ busybox-1.22.1/archival/libipkg/pkg_src_list.h 2014-05-23 21:12:06.000000000 +0200
  12566. @@ -0,0 +1,57 @@
  12567. +/* pkg_src_list.h - the itsy package management system
  12568. +
  12569. + Carl D. Worth
  12570. +
  12571. + Copyright (C) 2001 University of Southern California
  12572. +
  12573. + This program is free software; you can redistribute it and/or
  12574. + modify it under the terms of the GNU General Public License as
  12575. + published by the Free Software Foundation; either version 2, or (at
  12576. + your option) any later version.
  12577. +
  12578. + This program is distributed in the hope that it will be useful, but
  12579. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12580. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12581. + General Public License for more details.
  12582. +*/
  12583. +
  12584. +#ifndef PKG_SRC_LIST_H
  12585. +#define PKG_SRC_LIST_H
  12586. +
  12587. +#include "pkg_src.h"
  12588. +
  12589. +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
  12590. +struct pkg_src_list_elt
  12591. +{
  12592. + pkg_src_list_elt_t *next;
  12593. + pkg_src_t *data;
  12594. +};
  12595. +
  12596. +typedef struct pkg_src_list pkg_src_list_t;
  12597. +struct pkg_src_list
  12598. +{
  12599. + pkg_src_list_elt_t pre_head;
  12600. + pkg_src_list_elt_t *head;
  12601. + pkg_src_list_elt_t *tail;
  12602. +};
  12603. +
  12604. +static inline int pkg_src_list_empty(pkg_src_list_t *list)
  12605. +{
  12606. + if (list->head == NULL)
  12607. + return 1;
  12608. + else
  12609. + return 0;
  12610. +}
  12611. +
  12612. +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
  12613. +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
  12614. +
  12615. +int pkg_src_list_init(pkg_src_list_t *list);
  12616. +void pkg_src_list_deinit(pkg_src_list_t *list);
  12617. +
  12618. +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);
  12619. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
  12620. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
  12621. +
  12622. +#endif
  12623. +
  12624. diff -Nur busybox-1.22.1.orig/archival/libipkg/pkg_vec.c busybox-1.22.1/archival/libipkg/pkg_vec.c
  12625. --- busybox-1.22.1.orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
  12626. +++ busybox-1.22.1/archival/libipkg/pkg_vec.c 2014-05-23 21:12:06.000000000 +0200
  12627. @@ -0,0 +1,231 @@
  12628. +/* pkg_vec.c - the itsy package management system
  12629. +
  12630. + Steven M. Ayer
  12631. +
  12632. + Copyright (C) 2002 Compaq Computer Corporation
  12633. +
  12634. + This program is free software; you can redistribute it and/or
  12635. + modify it under the terms of the GNU General Public License as
  12636. + published by the Free Software Foundation; either version 2, or (at
  12637. + your option) any later version.
  12638. +
  12639. + This program is distributed in the hope that it will be useful, but
  12640. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12641. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12642. + General Public License for more details.
  12643. +*/
  12644. +
  12645. +#include <stdlib.h>
  12646. +#include <fnmatch.h>
  12647. +#include "libbb.h"
  12648. +#include "xregex.h"
  12649. +#include "ipkg.h"
  12650. +#include "pkg.h"
  12651. +
  12652. +pkg_vec_t * pkg_vec_alloc(void)
  12653. +{
  12654. + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
  12655. + if (!vec) {
  12656. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12657. + return NULL;
  12658. + }
  12659. + vec->pkgs = NULL;
  12660. + vec->len = 0;
  12661. +
  12662. + return vec;
  12663. +}
  12664. +
  12665. +void pkg_vec_free(pkg_vec_t *vec)
  12666. +{
  12667. + free(vec->pkgs);
  12668. + free(vec);
  12669. +}
  12670. +
  12671. +/*
  12672. + * assumption: all names in a vector are identical
  12673. + * assumption: all version strings are trimmed,
  12674. + * so identical versions have identical version strings,
  12675. + * implying identical packages; let's marry these
  12676. + */
  12677. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  12678. +{
  12679. + int i;
  12680. + int found = 0;
  12681. +
  12682. + /* look for a duplicate pkg by name, version, and architecture */
  12683. + for (i = 0; i < vec->len; i++){
  12684. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
  12685. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
  12686. + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
  12687. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12688. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12689. + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
  12690. + found = 1;
  12691. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
  12692. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12693. + break;
  12694. + }
  12695. + }
  12696. +
  12697. + /* we didn't find one, add it */
  12698. + if (!found){
  12699. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
  12700. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12701. +
  12702. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12703. + vec->pkgs[vec->len] = pkg;
  12704. + vec->len++;
  12705. + return pkg;
  12706. + }
  12707. + /* update the one that we have */
  12708. + else {
  12709. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
  12710. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12711. + if (set_status) {
  12712. + /* this is from the status file, so need to merge with existing database */
  12713. + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
  12714. + pkg_merge(vec->pkgs[i], pkg, set_status);
  12715. + /* XXX: CLEANUP: It's not so polite to free something here
  12716. + that was passed in from above. */
  12717. + pkg_deinit(pkg);
  12718. + free(pkg);
  12719. + } else {
  12720. + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
  12721. + /* just overwrite the old one */
  12722. + pkg_deinit(vec->pkgs[i]);
  12723. + free(vec->pkgs[i]);
  12724. + vec->pkgs[i] = pkg;
  12725. + }
  12726. + return vec->pkgs[i];
  12727. + }
  12728. +}
  12729. +
  12730. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
  12731. +{
  12732. + int i;
  12733. + int found = 0;
  12734. +
  12735. + /* look for a duplicate pkg by name, version, and architecture */
  12736. + for (i = 0; i < vec->len; i++)
  12737. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12738. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12739. + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
  12740. + found = 1;
  12741. + break;
  12742. + }
  12743. +
  12744. + /* we didn't find one, add it */
  12745. + if(!found){
  12746. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12747. + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
  12748. + vec->len++;
  12749. + }
  12750. +}
  12751. +
  12752. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
  12753. +{
  12754. + int i;
  12755. + for (i = 0; i < vec->len; i++)
  12756. + if (vec->pkgs[i] == apkg)
  12757. + return 1;
  12758. + return 0;
  12759. +}
  12760. +
  12761. +typedef int (*compare_fcn_t)(const void *, const void *);
  12762. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
  12763. +{
  12764. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12765. +}
  12766. +
  12767. +int pkg_vec_clear_marks(pkg_vec_t *vec)
  12768. +{
  12769. + int npkgs = vec->len;
  12770. + int i;
  12771. + for (i = 0; i < npkgs; i++) {
  12772. + pkg_t *pkg = vec->pkgs[i];
  12773. + pkg->state_flag &= ~SF_MARKED;
  12774. + }
  12775. + return 0;
  12776. +}
  12777. +
  12778. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
  12779. +{
  12780. + int matching_count = 0;
  12781. + pkg_t **pkgs = vec->pkgs;
  12782. + int npkgs = vec->len;
  12783. + int i;
  12784. + for (i = 0; i < npkgs; i++) {
  12785. + pkg_t *pkg = pkgs[i];
  12786. + if (fnmatch(pattern, pkg->name, 0)==0) {
  12787. + pkg->state_flag |= SF_MARKED;
  12788. + matching_count++;
  12789. + }
  12790. + }
  12791. + return matching_count;
  12792. +}
  12793. +
  12794. +
  12795. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
  12796. +{
  12797. + abstract_pkg_vec_t * vec ;
  12798. + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
  12799. + if (!vec) {
  12800. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12801. + return NULL;
  12802. + }
  12803. + vec->pkgs = NULL;
  12804. + vec->len = 0;
  12805. +
  12806. + return vec;
  12807. +}
  12808. +
  12809. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
  12810. +{
  12811. + free(vec->pkgs);
  12812. + free(vec);
  12813. +}
  12814. +
  12815. +/*
  12816. + * assumption: all names in a vector are unique
  12817. + */
  12818. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
  12819. +{
  12820. + int i;
  12821. +
  12822. + /* look for a duplicate pkg by name */
  12823. + for(i = 0; i < vec->len; i++)
  12824. + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12825. + break;
  12826. +
  12827. + /* we didn't find one, add it */
  12828. + if(i == vec->len){
  12829. + vec->pkgs =
  12830. + (abstract_pkg_t **)
  12831. + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
  12832. + vec->pkgs[vec->len] = pkg;
  12833. + vec->len++;
  12834. + }
  12835. +}
  12836. +
  12837. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
  12838. +{
  12839. + if (vec->len > i)
  12840. + return vec->pkgs[i];
  12841. + else
  12842. + return NULL;
  12843. +}
  12844. +
  12845. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
  12846. +{
  12847. + int i;
  12848. + for (i = 0; i < vec->len; i++)
  12849. + if (vec->pkgs[i] == apkg)
  12850. + return 1;
  12851. + return 0;
  12852. +}
  12853. +
  12854. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
  12855. +{
  12856. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12857. +}
  12858. +
  12859. diff -Nur busybox-1.22.1.orig/archival/libipkg/pkg_vec.h busybox-1.22.1/archival/libipkg/pkg_vec.h
  12860. --- busybox-1.22.1.orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
  12861. +++ busybox-1.22.1/archival/libipkg/pkg_vec.h 2014-05-23 21:12:06.000000000 +0200
  12862. @@ -0,0 +1,62 @@
  12863. +/* pkg_vec.h - the itsy package management system
  12864. +
  12865. + Steven M. Ayer
  12866. +
  12867. + Copyright (C) 2002 Compaq Computer Corporation
  12868. +
  12869. + This program is free software; you can redistribute it and/or
  12870. + modify it under the terms of the GNU General Public License as
  12871. + published by the Free Software Foundation; either version 2, or (at
  12872. + your option) any later version.
  12873. +
  12874. + This program is distributed in the hope that it will be useful, but
  12875. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12876. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12877. + General Public License for more details.
  12878. +*/
  12879. +
  12880. +#ifndef PKG_VEC_H
  12881. +#define PKG_VEC_H
  12882. +
  12883. +typedef struct pkg pkg_t;
  12884. +typedef struct abstract_pkg abstract_pkg_t;
  12885. +
  12886. +struct pkg_vec
  12887. +{
  12888. + pkg_t **pkgs;
  12889. + int len;
  12890. +};
  12891. +typedef struct pkg_vec pkg_vec_t;
  12892. +
  12893. +struct abstract_pkg_vec
  12894. +{
  12895. + abstract_pkg_t **pkgs;
  12896. + int len;
  12897. +};
  12898. +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
  12899. +
  12900. +
  12901. +pkg_vec_t * pkg_vec_alloc(void);
  12902. +void pkg_vec_free(pkg_vec_t *vec);
  12903. +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
  12904. +
  12905. +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
  12906. +/* pkg_vec_insert_merge: might munge pkg.
  12907. +* returns the pkg that is in the pkg graph */
  12908. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
  12909. +/* this one never munges pkg */
  12910. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
  12911. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
  12912. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
  12913. +
  12914. +int pkg_vec_clear_marks(pkg_vec_t *vec);
  12915. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
  12916. +
  12917. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
  12918. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
  12919. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
  12920. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
  12921. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
  12922. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
  12923. +#endif
  12924. +
  12925. diff -Nur busybox-1.22.1.orig/archival/libipkg/sprintf_alloc.h busybox-1.22.1/archival/libipkg/sprintf_alloc.h
  12926. --- busybox-1.22.1.orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
  12927. +++ busybox-1.22.1/archival/libipkg/sprintf_alloc.h 2014-05-23 21:12:06.000000000 +0200
  12928. @@ -0,0 +1,25 @@
  12929. +/* sprintf_alloca.c -- like sprintf with memory allocation
  12930. +
  12931. + Carl D. Worth
  12932. +
  12933. + Copyright (C) 2001 University of Southern California
  12934. +
  12935. + This program is free software; you can redistribute it and/or modify
  12936. + it under the terms of the GNU General Public License as published by
  12937. + the Free Software Foundation; either version 2, or (at your option)
  12938. + any later version.
  12939. +
  12940. + This program is distributed in the hope that it will be useful,
  12941. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  12942. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12943. + GNU General Public License for more details.
  12944. +*/
  12945. +
  12946. +#ifndef SPRINTF_ALLOC_H
  12947. +#define SPRINTF_ALLOC_H
  12948. +
  12949. +#include "libbb.h"
  12950. +
  12951. +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
  12952. +
  12953. +#endif
  12954. diff -Nur busybox-1.22.1.orig/archival/libipkg/str_list.c busybox-1.22.1/archival/libipkg/str_list.c
  12955. --- busybox-1.22.1.orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
  12956. +++ busybox-1.22.1/archival/libipkg/str_list.c 2014-05-23 21:12:06.000000000 +0200
  12957. @@ -0,0 +1,76 @@
  12958. +/* str_list.c - the itsy package management system
  12959. +
  12960. + Carl D. Worth
  12961. +
  12962. + Copyright (C) 2001 University of Southern California
  12963. +
  12964. + This program is free software; you can redistribute it and/or
  12965. + modify it under the terms of the GNU General Public License as
  12966. + published by the Free Software Foundation; either version 2, or (at
  12967. + your option) any later version.
  12968. +
  12969. + This program is distributed in the hope that it will be useful, but
  12970. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12971. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12972. + General Public License for more details.
  12973. +*/
  12974. +
  12975. +#include "ipkg.h"
  12976. +
  12977. +#include "str_list.h"
  12978. +
  12979. +int str_list_elt_init(str_list_elt_t *elt, char *data)
  12980. +{
  12981. + return void_list_elt_init((void_list_elt_t *) elt, data);
  12982. +}
  12983. +
  12984. +void str_list_elt_deinit(str_list_elt_t *elt)
  12985. +{
  12986. + void_list_elt_deinit((void_list_elt_t *) elt);
  12987. +}
  12988. +
  12989. +str_list_t *str_list_alloc(void)
  12990. +{
  12991. + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
  12992. + if (list)
  12993. + str_list_init(list);
  12994. + return list;
  12995. +}
  12996. +
  12997. +int str_list_init(str_list_t *list)
  12998. +{
  12999. + return void_list_init((void_list_t *) list);
  13000. +}
  13001. +
  13002. +void str_list_deinit(str_list_t *list)
  13003. +{
  13004. + void_list_deinit((void_list_t *) list);
  13005. +}
  13006. +
  13007. +int str_list_append(str_list_t *list, char *data)
  13008. +{
  13009. + return void_list_append((void_list_t *) list, data);
  13010. +}
  13011. +
  13012. +int str_list_push(str_list_t *list, char *data)
  13013. +{
  13014. + return void_list_push((void_list_t *) list, data);
  13015. +}
  13016. +
  13017. +str_list_elt_t *str_list_pop(str_list_t *list)
  13018. +{
  13019. + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
  13020. +}
  13021. +
  13022. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
  13023. +{
  13024. + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
  13025. + (void_list_elt_t **) iter);
  13026. +}
  13027. +
  13028. +char *str_list_remove_elt(str_list_t *list, const char *target_str)
  13029. +{
  13030. + return (char *)void_list_remove_elt((void_list_t *) list,
  13031. + (void *)target_str,
  13032. + (void_list_cmp_t)strcmp);
  13033. +}
  13034. diff -Nur busybox-1.22.1.orig/archival/libipkg/str_list.h busybox-1.22.1/archival/libipkg/str_list.h
  13035. --- busybox-1.22.1.orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
  13036. +++ busybox-1.22.1/archival/libipkg/str_list.h 2014-05-23 21:12:06.000000000 +0200
  13037. @@ -0,0 +1,51 @@
  13038. +/* str_list.h - the itsy package management system
  13039. +
  13040. + Carl D. Worth
  13041. +
  13042. + Copyright (C) 2001 University of Southern California
  13043. +
  13044. + This program is free software; you can redistribute it and/or
  13045. + modify it under the terms of the GNU General Public License as
  13046. + published by the Free Software Foundation; either version 2, or (at
  13047. + your option) any later version.
  13048. +
  13049. + This program is distributed in the hope that it will be useful, but
  13050. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13051. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13052. + General Public License for more details.
  13053. +*/
  13054. +
  13055. +#ifndef STR_LIST_H
  13056. +#define STR_LIST_H
  13057. +
  13058. +#include "void_list.h"
  13059. +
  13060. +typedef struct str_list_elt str_list_elt_t;
  13061. +struct str_list_elt
  13062. +{
  13063. + str_list_elt_t *next;
  13064. + char *data;
  13065. +};
  13066. +
  13067. +typedef struct xstr_list str_list_t;
  13068. +struct xstr_list
  13069. +{
  13070. + str_list_elt_t pre_head;
  13071. + str_list_elt_t *head;
  13072. + str_list_elt_t *tail;
  13073. +};
  13074. +
  13075. +int str_list_elt_init(str_list_elt_t *elt, char *data);
  13076. +void str_list_elt_deinit(str_list_elt_t *elt);
  13077. +
  13078. +str_list_t *str_list_alloc(void);
  13079. +int str_list_init(str_list_t *list);
  13080. +void str_list_deinit(str_list_t *list);
  13081. +
  13082. +int str_list_append(str_list_t *list, char *data);
  13083. +int str_list_push(str_list_t *list, char *data);
  13084. +str_list_elt_t *str_list_pop(str_list_t *list);
  13085. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
  13086. +char *str_list_remove_elt(str_list_t *list, const char *target_str);
  13087. +
  13088. +#endif
  13089. diff -Nur busybox-1.22.1.orig/archival/libipkg/str_util.c busybox-1.22.1/archival/libipkg/str_util.c
  13090. --- busybox-1.22.1.orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
  13091. +++ busybox-1.22.1/archival/libipkg/str_util.c 2014-05-23 21:12:06.000000000 +0200
  13092. @@ -0,0 +1,69 @@
  13093. +/* str_utils.c - the itsy package management system
  13094. +
  13095. + Carl D. Worth
  13096. +
  13097. + Copyright (C) 2001 University of Southern California
  13098. +
  13099. + This program is free software; you can redistribute it and/or
  13100. + modify it under the terms of the GNU General Public License as
  13101. + published by the Free Software Foundation; either version 2, or (at
  13102. + your option) any later version.
  13103. +
  13104. + This program is distributed in the hope that it will be useful, but
  13105. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13106. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13107. + General Public License for more details.
  13108. +*/
  13109. +
  13110. +#include "ipkg.h"
  13111. +
  13112. +int str_starts_with(const char *str, const char *prefix);
  13113. +int str_ends_with(const char *str, const char *suffix);
  13114. +int str_chomp(char *str);
  13115. +int str_toupper(char *str);
  13116. +char *str_dup_safe(const char *str);
  13117. +
  13118. +int str_starts_with(const char *str, const char *prefix)
  13119. +{
  13120. + return (strncmp(str, prefix, strlen(prefix)) == 0);
  13121. +}
  13122. +
  13123. +int str_ends_with(const char *str, const char *suffix)
  13124. +{
  13125. + int suffix_len;
  13126. + int str_len;
  13127. +
  13128. + str_len = strlen(str);
  13129. + suffix_len = strlen(suffix);
  13130. +
  13131. + if (str_len < suffix_len) {
  13132. + return 0;
  13133. + }
  13134. +
  13135. + return (strcmp(str + str_len - suffix_len, suffix) == 0);
  13136. +}
  13137. +
  13138. +int str_chomp(char *str)
  13139. +{
  13140. + if (str[strlen(str) - 1] == '\n') {
  13141. + str[strlen(str) - 1] = '\0';
  13142. + return 1;
  13143. + }
  13144. + return 0;
  13145. +}
  13146. +
  13147. +int str_toupper(char *str)
  13148. +{
  13149. + while (*str) {
  13150. + *str = toupper(*str);
  13151. + str++;
  13152. + }
  13153. +
  13154. + return 0;
  13155. +}
  13156. +
  13157. +char *str_dup_safe(const char *str)
  13158. +{
  13159. + return str ? strdup(str) : NULL;
  13160. +}
  13161. +
  13162. diff -Nur busybox-1.22.1.orig/archival/libipkg/str_util.h busybox-1.22.1/archival/libipkg/str_util.h
  13163. --- busybox-1.22.1.orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
  13164. +++ busybox-1.22.1/archival/libipkg/str_util.h 2014-05-23 21:12:06.000000000 +0200
  13165. @@ -0,0 +1,27 @@
  13166. +/* str_utils.h - the itsy package management system
  13167. +
  13168. + Carl D. Worth
  13169. +
  13170. + Copyright (C) 2001 University of Southern California
  13171. +
  13172. + This program is free software; you can redistribute it and/or
  13173. + modify it under the terms of the GNU General Public License as
  13174. + published by the Free Software Foundation; either version 2, or (at
  13175. + your option) any later version.
  13176. +
  13177. + This program is distributed in the hope that it will be useful, but
  13178. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13179. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13180. + General Public License for more details.
  13181. +*/
  13182. +
  13183. +#ifndef STR_UTILS_H
  13184. +#define STR_UTILS_H
  13185. +
  13186. +int str_starts_with(const char *str, const char *prefix);
  13187. +int str_ends_with(const char *str, const char *suffix);
  13188. +int str_chomp(char *str);
  13189. +int str_toupper(char *str);
  13190. +char *str_dup_safe(const char *str);
  13191. +
  13192. +#endif
  13193. diff -Nur busybox-1.22.1.orig/archival/libipkg/user.c busybox-1.22.1/archival/libipkg/user.c
  13194. --- busybox-1.22.1.orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
  13195. +++ busybox-1.22.1/archival/libipkg/user.c 2014-05-23 21:12:06.000000000 +0200
  13196. @@ -0,0 +1,49 @@
  13197. +/* user.c - the itsy package management system
  13198. +
  13199. + Jamey Hicks
  13200. +
  13201. + Copyright (C) 2002 Hewlett Packard Company
  13202. + Copyright (C) 2001 University of Southern California
  13203. +
  13204. + This program is free software; you can redistribute it and/or
  13205. + modify it under the terms of the GNU General Public License as
  13206. + published by the Free Software Foundation; either version 2, or (at
  13207. + your option) any later version.
  13208. +
  13209. + This program is distributed in the hope that it will be useful, but
  13210. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13211. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13212. + General Public License for more details.
  13213. +*/
  13214. +
  13215. +#include <stdio.h>
  13216. +#include <stdarg.h>
  13217. +#include "libbb.h"
  13218. +#include "file_util.h"
  13219. +#include "str_util.h"
  13220. +#include "libipkg.h"
  13221. +
  13222. +char *get_user_response(const char *format, ...);
  13223. +static char *question = NULL;
  13224. +static int question_len = 255;
  13225. +
  13226. +char *get_user_response(const char *format, ...)
  13227. +{
  13228. + int len = question_len;
  13229. + va_list ap;
  13230. + char *response;
  13231. + va_start(ap, format);
  13232. +
  13233. + do {
  13234. + if (question == NULL || len > question_len) {
  13235. + question = realloc(question, len + 1);
  13236. + question_len = len;
  13237. + }
  13238. + len = vsnprintf(question,question_len,format,ap);
  13239. + } while (len > question_len);
  13240. + response = strdup(ipkg_cb_response(question));
  13241. + str_chomp(response);
  13242. + str_tolower(response);
  13243. +
  13244. + return response;
  13245. +}
  13246. diff -Nur busybox-1.22.1.orig/archival/libipkg/user.h busybox-1.22.1/archival/libipkg/user.h
  13247. --- busybox-1.22.1.orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
  13248. +++ busybox-1.22.1/archival/libipkg/user.h 2014-05-23 21:12:06.000000000 +0200
  13249. @@ -0,0 +1,23 @@
  13250. +/* user.c - the itsy package management system
  13251. +
  13252. + Jamey Hicks
  13253. +
  13254. + Copyright (C) 2002 Hewlett Packard Company
  13255. + Copyright (C) 2001 University of Southern California
  13256. +
  13257. + This program is free software; you can redistribute it and/or
  13258. + modify it under the terms of the GNU General Public License as
  13259. + published by the Free Software Foundation; either version 2, or (at
  13260. + your option) any later version.
  13261. +
  13262. + This program is distributed in the hope that it will be useful, but
  13263. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13264. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13265. + General Public License for more details.
  13266. +*/
  13267. +
  13268. +#include <stdio.h>
  13269. +#include <stdarg.h>
  13270. +
  13271. +char *get_user_response(const char *format, ...);
  13272. +
  13273. diff -Nur busybox-1.22.1.orig/archival/libipkg/void_list.c busybox-1.22.1/archival/libipkg/void_list.c
  13274. --- busybox-1.22.1.orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
  13275. +++ busybox-1.22.1/archival/libipkg/void_list.c 2014-05-23 21:12:06.000000000 +0200
  13276. @@ -0,0 +1,194 @@
  13277. +/* void_list.c - the itsy package management system
  13278. +
  13279. + Carl D. Worth
  13280. +
  13281. + Copyright (C) 2001 University of Southern California
  13282. +
  13283. + This program is free software; you can redistribute it and/or
  13284. + modify it under the terms of the GNU General Public License as
  13285. + published by the Free Software Foundation; either version 2, or (at
  13286. + your option) any later version.
  13287. +
  13288. + This program is distributed in the hope that it will be useful, but
  13289. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13290. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13291. + General Public License for more details.
  13292. +*/
  13293. +
  13294. +#include "ipkg.h"
  13295. +#include <errno.h>
  13296. +
  13297. +#include "void_list.h"
  13298. +
  13299. +int void_list_elt_init(void_list_elt_t *elt, void *data)
  13300. +{
  13301. + elt->next = NULL;
  13302. + elt->data = data;
  13303. +
  13304. + return 0;
  13305. +}
  13306. +
  13307. +void void_list_elt_deinit(void_list_elt_t *elt)
  13308. +{
  13309. + void_list_elt_init(elt, NULL);
  13310. +}
  13311. +
  13312. +int void_list_init(void_list_t *list)
  13313. +{
  13314. + void_list_elt_init(&list->pre_head, NULL);
  13315. + list->head = NULL;
  13316. + list->pre_head.next = list->head;
  13317. + list->tail = NULL;
  13318. +
  13319. + return 0;
  13320. +}
  13321. +
  13322. +void void_list_deinit(void_list_t *list)
  13323. +{
  13324. + void_list_elt_t *elt;
  13325. +
  13326. + while (list->head) {
  13327. + elt = void_list_pop(list);
  13328. + void_list_elt_deinit(elt);
  13329. + /* malloced in void_list_append */
  13330. + free(elt);
  13331. + }
  13332. +}
  13333. +
  13334. +int void_list_append(void_list_t *list, void *data)
  13335. +{
  13336. + void_list_elt_t *elt;
  13337. +
  13338. + /* freed in void_list_deinit */
  13339. + elt = malloc(sizeof(void_list_elt_t));
  13340. + if (elt == NULL) {
  13341. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13342. + return ENOMEM;
  13343. + }
  13344. +
  13345. + void_list_elt_init(elt, data);
  13346. +
  13347. + if (list->tail) {
  13348. + list->tail->next = elt;
  13349. + list->tail = elt;
  13350. + } else {
  13351. + list->head = elt;
  13352. + list->pre_head.next = list->head;
  13353. + list->tail = elt;
  13354. + }
  13355. +
  13356. + return 0;
  13357. +}
  13358. +
  13359. +int void_list_push(void_list_t *list, void *data)
  13360. +{
  13361. + void_list_elt_t *elt;
  13362. +
  13363. + elt = malloc(sizeof(void_list_elt_t));
  13364. + if (elt == NULL) {
  13365. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13366. + return ENOMEM;
  13367. + }
  13368. +
  13369. + void_list_elt_init(elt, data);
  13370. +
  13371. + elt->next = list->head;
  13372. + list->head->next = elt;
  13373. + if (list->tail == NULL) {
  13374. + list->tail = list->head;
  13375. + }
  13376. +
  13377. + return 0;
  13378. +}
  13379. +
  13380. +void_list_elt_t *void_list_pop(void_list_t *list)
  13381. +{
  13382. + void_list_elt_t *elt;
  13383. +
  13384. + elt = list->head;
  13385. +
  13386. + if (list->head) {
  13387. + list->head = list->head->next;
  13388. + list->pre_head.next = list->head;
  13389. + if (list->head == NULL) {
  13390. + list->tail = NULL;
  13391. + }
  13392. + }
  13393. +
  13394. + return elt;
  13395. +}
  13396. +
  13397. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
  13398. +{
  13399. + void_list_elt_t *prior;
  13400. + void_list_elt_t *old_elt;
  13401. + void *old_data;
  13402. +
  13403. + old_elt = *iter;
  13404. + old_data = old_elt->data;
  13405. +
  13406. + if (old_elt == list->head) {
  13407. + prior = &list->pre_head;
  13408. + void_list_pop(list);
  13409. + } else {
  13410. + for (prior = list->head; prior; prior = prior->next) {
  13411. + if (prior->next == old_elt) {
  13412. + break;
  13413. + }
  13414. + }
  13415. + if (prior == NULL || prior->next != old_elt) {
  13416. + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
  13417. + return NULL;
  13418. + }
  13419. + prior->next = old_elt->next;
  13420. +
  13421. + if (old_elt == list->tail) {
  13422. + list->tail = prior;
  13423. + }
  13424. + }
  13425. +
  13426. + void_list_elt_deinit(old_elt);
  13427. + *iter = prior;
  13428. +
  13429. + return old_data;
  13430. +}
  13431. +
  13432. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13433. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
  13434. +{
  13435. + void_list_elt_t *prior;
  13436. + void_list_elt_t *old_elt = NULL;
  13437. + void *old_data = NULL;
  13438. +
  13439. + /* first element */
  13440. + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
  13441. + old_elt = list->head;
  13442. + old_data = list->head->data;
  13443. + void_list_pop(list);
  13444. + } else {
  13445. + int found = 0;
  13446. + for (prior = list->head; prior && prior->next; prior = prior->next) {
  13447. + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
  13448. + old_elt = prior->next;
  13449. + old_data = old_elt->data;
  13450. + found = 1;
  13451. + break;
  13452. + }
  13453. + }
  13454. + if (!found) {
  13455. + return NULL;
  13456. + }
  13457. + prior->next = old_elt->next;
  13458. +
  13459. + if (old_elt == list->tail) {
  13460. + list->tail = prior;
  13461. + }
  13462. + }
  13463. + if (old_elt)
  13464. + void_list_elt_deinit(old_elt);
  13465. +
  13466. + if (old_data)
  13467. + return old_data;
  13468. + else
  13469. + return NULL;
  13470. +}
  13471. diff -Nur busybox-1.22.1.orig/archival/libipkg/void_list.h busybox-1.22.1/archival/libipkg/void_list.h
  13472. --- busybox-1.22.1.orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
  13473. +++ busybox-1.22.1/archival/libipkg/void_list.h 2014-05-23 21:12:06.000000000 +0200
  13474. @@ -0,0 +1,59 @@
  13475. +/* void_list.h - the itsy package management system
  13476. +
  13477. + Carl D. Worth
  13478. +
  13479. + Copyright (C) 2001 University of Southern California
  13480. +
  13481. + This program is free software; you can redistribute it and/or
  13482. + modify it under the terms of the GNU General Public License as
  13483. + published by the Free Software Foundation; either version 2, or (at
  13484. + your option) any later version.
  13485. +
  13486. + This program is distributed in the hope that it will be useful, but
  13487. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13488. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13489. + General Public License for more details.
  13490. +*/
  13491. +
  13492. +#ifndef VOID_LIST_H
  13493. +#define VOID_LIST_H
  13494. +
  13495. +typedef struct void_list_elt void_list_elt_t;
  13496. +struct void_list_elt
  13497. +{
  13498. + void_list_elt_t *next;
  13499. + void *data;
  13500. +};
  13501. +
  13502. +typedef struct void_list void_list_t;
  13503. +struct void_list
  13504. +{
  13505. + void_list_elt_t pre_head;
  13506. + void_list_elt_t *head;
  13507. + void_list_elt_t *tail;
  13508. +};
  13509. +
  13510. +static inline int void_list_empty(void_list_t *list)
  13511. +{
  13512. + if (list->head == NULL)
  13513. + return 1;
  13514. + else
  13515. + return 0;
  13516. +}
  13517. +
  13518. +int void_list_elt_init(void_list_elt_t *elt, void *data);
  13519. +void void_list_elt_deinit(void_list_elt_t *elt);
  13520. +
  13521. +int void_list_init(void_list_t *list);
  13522. +void void_list_deinit(void_list_t *list);
  13523. +
  13524. +int void_list_append(void_list_t *list, void *data);
  13525. +int void_list_push(void_list_t *list, void *data);
  13526. +void_list_elt_t *void_list_pop(void_list_t *list);
  13527. +
  13528. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
  13529. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13530. +typedef int (*void_list_cmp_t)(const void *, const void *);
  13531. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
  13532. +
  13533. +#endif
  13534. diff -Nur busybox-1.22.1.orig/archival/libipkg/xsystem.c busybox-1.22.1/archival/libipkg/xsystem.c
  13535. --- busybox-1.22.1.orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
  13536. +++ busybox-1.22.1/archival/libipkg/xsystem.c 2014-05-23 21:12:06.000000000 +0200
  13537. @@ -0,0 +1,64 @@
  13538. +/* xsystem.c - system(3) with error messages
  13539. +
  13540. + Carl D. Worth
  13541. +
  13542. + Copyright (C) 2001 University of Southern California
  13543. +
  13544. + This program is free software; you can redistribute it and/or
  13545. + modify it under the terms of the GNU General Public License as
  13546. + published by the Free Software Foundation; either version 2, or (at
  13547. + your option) any later version.
  13548. +
  13549. + This program is distributed in the hope that it will be useful, but
  13550. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13551. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13552. + General Public License for more details.
  13553. +*/
  13554. +
  13555. +#include "ipkg.h"
  13556. +#include <sys/wait.h>
  13557. +
  13558. +#include "xsystem.h"
  13559. +
  13560. +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
  13561. + really need the /bin/sh invocation which takes resources and
  13562. + introduces security problems. I should switch all of this to a sort
  13563. + of execl() or execv() interface/implementation.
  13564. +*/
  13565. +
  13566. +/* Like system(3), but with error messages printed if the fork fails
  13567. + or if the child process dies due to an uncaught signal. Also, the
  13568. + return value is a bit simpler:
  13569. +
  13570. + -1 if there was any problem
  13571. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13572. + as defined in <sys/wait.h>.
  13573. +*/
  13574. +int xsystem(const char *cmd)
  13575. +{
  13576. + int err;
  13577. +
  13578. + err = system(cmd);
  13579. +
  13580. + if (err == -1) {
  13581. + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
  13582. + __FUNCTION__, cmd);
  13583. + return -1;
  13584. + }
  13585. +
  13586. + if (WIFSIGNALED(err)) {
  13587. + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
  13588. + __FUNCTION__, WTERMSIG(err), cmd);
  13589. + return -1;
  13590. + }
  13591. +
  13592. + if (WIFEXITED(err)) {
  13593. + /* Normal child exit */
  13594. + return WEXITSTATUS(err);
  13595. + }
  13596. +
  13597. + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
  13598. + __FUNCTION__, err);
  13599. + return -1;
  13600. +}
  13601. +
  13602. diff -Nur busybox-1.22.1.orig/archival/libipkg/xsystem.h busybox-1.22.1/archival/libipkg/xsystem.h
  13603. --- busybox-1.22.1.orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
  13604. +++ busybox-1.22.1/archival/libipkg/xsystem.h 2014-05-23 21:12:06.000000000 +0200
  13605. @@ -0,0 +1,34 @@
  13606. +/* xsystem.h - system(3) with error messages
  13607. +
  13608. + Carl D. Worth
  13609. +
  13610. + Copyright (C) 2001 University of Southern California
  13611. +
  13612. + This program is free software; you can redistribute it and/or
  13613. + modify it under the terms of the GNU General Public License as
  13614. + published by the Free Software Foundation; either version 2, or (at
  13615. + your option) any later version.
  13616. +
  13617. + This program is distributed in the hope that it will be useful, but
  13618. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13619. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13620. + General Public License for more details.
  13621. +*/
  13622. +
  13623. +#ifndef XSYSTEM_H
  13624. +#define XSYSTEM_H
  13625. +
  13626. +#include <stdlib.h>
  13627. +
  13628. +/* Like system(3), but with error messages printed if the fork fails
  13629. + or if the child process dies due to an uncaught signal. Also, the
  13630. + return value is a bit simpler:
  13631. +
  13632. + -1 if there was any problem
  13633. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13634. + as defined in <sys/wait.h>.
  13635. +*/
  13636. +int xsystem(const char *cmd);
  13637. +
  13638. +#endif
  13639. +
  13640. diff -Nur busybox-1.22.1.orig/include/applets.src.h busybox-1.22.1/include/applets.src.h
  13641. --- busybox-1.22.1.orig/include/applets.src.h 2014-01-09 19:15:44.000000000 +0100
  13642. +++ busybox-1.22.1/include/applets.src.h 2014-05-23 21:12:06.000000000 +0200
  13643. @@ -194,6 +194,7 @@
  13644. IF_IPCALC(APPLET(ipcalc, BB_DIR_BIN, BB_SUID_DROP))
  13645. IF_IPCRM(APPLET(ipcrm, BB_DIR_USR_BIN, BB_SUID_DROP))
  13646. IF_IPCS(APPLET(ipcs, BB_DIR_USR_BIN, BB_SUID_DROP))
  13647. +IF_IPKG(APPLET(ipkg, BB_DIR_USR_BIN, BB_SUID_DROP))
  13648. IF_IPLINK(APPLET(iplink, BB_DIR_SBIN, BB_SUID_DROP))
  13649. IF_IPROUTE(APPLET(iproute, BB_DIR_SBIN, BB_SUID_DROP))
  13650. IF_IPRULE(APPLET(iprule, BB_DIR_SBIN, BB_SUID_DROP))
  13651. diff -Nur busybox-1.22.1.orig/include/bb_archive.h busybox-1.22.1/include/bb_archive.h
  13652. --- busybox-1.22.1.orig/include/bb_archive.h 2014-01-09 19:15:44.000000000 +0100
  13653. +++ busybox-1.22.1/include/bb_archive.h 2014-05-23 21:12:06.000000000 +0200
  13654. @@ -79,7 +79,6 @@
  13655. /* Archiver specific. Can make it a union if it ever gets big */
  13656. #define PAX_NEXT_FILE 0
  13657. #define PAX_GLOBAL 1
  13658. -#if ENABLE_TAR || ENABLE_DPKG || ENABLE_DPKG_DEB
  13659. smallint tar__end;
  13660. # if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
  13661. char* tar__longname;
  13662. @@ -92,13 +91,12 @@
  13663. # if ENABLE_FEATURE_TAR_SELINUX
  13664. char* tar__sctx[2];
  13665. # endif
  13666. -#endif
  13667. #if ENABLE_CPIO || ENABLE_RPM2CPIO || ENABLE_RPM
  13668. uoff_t cpio__blocks;
  13669. struct hardlinks_t *cpio__hardlinks_to_create;
  13670. struct hardlinks_t *cpio__created_hardlinks;
  13671. #endif
  13672. -#if ENABLE_DPKG || ENABLE_DPKG_DEB
  13673. +#if ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13674. /* Temporary storage */
  13675. char *dpkg__buffer;
  13676. /* How to process any sub archive, e.g. get_header_tar_gz */
  13677. diff -Nur busybox-1.22.1.orig/include/usage.src.h busybox-1.22.1/include/usage.src.h
  13678. --- busybox-1.22.1.orig/include/usage.src.h 2014-01-09 19:15:44.000000000 +0100
  13679. +++ busybox-1.22.1/include/usage.src.h 2014-05-23 21:12:06.000000000 +0200
  13680. @@ -19,4 +19,80 @@
  13681. #define busybox_notes_usage \
  13682. "Hello world!\n"
  13683. +#define ipkg_trivial_usage \
  13684. + "[options]... sub-command [arguments]..."
  13685. +#define ipkg_full_usage \
  13686. + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
  13687. + "\n" \
  13688. + "Sub-commands:\n" \
  13689. + "\nPackage Manipulation:\n" \
  13690. + "\tupdate Update list of available packages\n" \
  13691. + "\tupgrade Upgrade all installed packages to latest version\n" \
  13692. + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
  13693. + "\tinstall <file.ipk> Install package <file.ipk>\n" \
  13694. + "\tconfigure [<pkg>] Configure unpacked packages\n" \
  13695. + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
  13696. + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
  13697. + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
  13698. + "\n" \
  13699. + "Informational Commands:\n" \
  13700. + "\tlist List available packages and descriptions\n" \
  13701. + "\tlist_installed List all and only the installed packages and description \n" \
  13702. + "\tfiles <pkg> List all files belonging to <pkg>\n" \
  13703. + "\tsearch <file|regexp> Search for a package providing <file>\n" \
  13704. + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
  13705. + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
  13706. + "\tdownload <pkg> Download <pkg> to current directory.\n" \
  13707. + "\tcompare_versions <v1> <op> <v2>\n" \
  13708. + "\t compare versions using <= < > >= = << >>\n" \
  13709. + "\tprint_architecture prints the architecture.\n" \
  13710. + "\tprint_installation_architecture\n" \
  13711. + "\twhatdepends [-A] [pkgname|pat]+\n" \
  13712. + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
  13713. + "\twhatprovides [-A] [pkgname|pat]+\n" \
  13714. + "\twhatconflicts [-A] [pkgname|pat]+\n" \
  13715. + "\twhatreplaces [-A] [pkgname|pat]+\n" \
  13716. + "\t prints the installation architecture.\n" \
  13717. + "\n" \
  13718. + "\nOptions:\n" \
  13719. + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
  13720. + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
  13721. + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
  13722. + "\t 0 errors only\n" \
  13723. + "\t 1 normal messages (default)\n" \
  13724. + "\t 2 informative messages\n" \
  13725. + "\t 3 debug output\n" \
  13726. + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
  13727. + "\t-conf <conf_file> Default configuration file location\n" \
  13728. + " is /etc/ipkg.conf\n" \
  13729. + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
  13730. + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
  13731. + " <dest_name> should be a defined dest name from\n" \
  13732. + " the configuration file, (but can also be a\n" \
  13733. + " directory name in a pinch).\n" \
  13734. + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
  13735. + "\t-offline <offline_root> offline installation of packages.\n" \
  13736. + "\t-verbose_wget more wget messages\n" \
  13737. + "\n" \
  13738. + "Force Options (use when ipkg is too smart for its own good):\n" \
  13739. + "\t-force-depends Make dependency checks warnings instead of errors\n" \
  13740. + "\t Install/remove package in spite of failed dependences\n" \
  13741. + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
  13742. + " (no prompts). Note that this will not prevent\n" \
  13743. + " package installation scripts from prompting.\n" \
  13744. + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
  13745. + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
  13746. + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
  13747. + "\t-force_space Install even if there does not seem to be enough space.\n" \
  13748. + "\t-noaction No action -- test only\n" \
  13749. + "\t-nodeps Do not follow dependences\n" \
  13750. + "\t-force-removal-of-dependent-packages\n" \
  13751. + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
  13752. + "\t-test No action -- test only\n" \
  13753. + "\t-t Specify tmp-dir.\n" \
  13754. + "\t--tmp-dir Specify tmp-dir.\n" \
  13755. + "\n" \
  13756. + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
  13757. + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
  13758. +
  13759. #endif