001-ipkg.patch 424 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745
  1. diff -Nur busybox-1.20.2.orig//archival/Config.src busybox-1.20.2/archival/Config.src
  2. --- busybox-1.20.2.orig//archival/Config.src 2012-06-26 15:35:45.000000000 +0200
  3. +++ busybox-1.20.2/archival/Config.src 2013-01-31 16:44:31.000000000 +0100
  4. @@ -214,6 +214,12 @@
  5. are actually slower than gzip at equivalent compression ratios
  6. and take up 3.2K of code.
  7. +config IPKG
  8. + bool "ipkg"
  9. + default n
  10. + help
  11. + ipkg is the itsy package management system.
  12. +
  13. config RPM2CPIO
  14. bool "rpm2cpio"
  15. default y
  16. diff -Nur busybox-1.20.2.orig//archival/ipkg.c busybox-1.20.2/archival/ipkg.c
  17. --- busybox-1.20.2.orig//archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
  18. +++ busybox-1.20.2/archival/ipkg.c 2013-01-31 16:44:31.000000000 +0100
  19. @@ -0,0 +1,28 @@
  20. +/* ipkg.c - the itsy package management system
  21. +
  22. + Florina Boor
  23. +
  24. + Copyright (C) 2003 kernel concepts
  25. +
  26. + This program is free software; you can redistribute it and/or
  27. + modify it under the terms of the GNU General Public License as
  28. + published by the Free Software Foundation; either version 2, or (at
  29. + your option) any later version.
  30. +
  31. + This program is distributed in the hope that it will be useful, but
  32. + WITHOUT ANY WARRANTY; without even the implied warranty of
  33. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  34. + General Public License for more details.
  35. +
  36. + ipkg command line frontend using libipkg
  37. +
  38. +*/
  39. +
  40. +#include "libbb.h"
  41. +#include "libipkg/libipkg.h"
  42. +
  43. +int ipkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  44. +int ipkg_main(int argc, char **argv)
  45. +{
  46. + return ipkg_op(argc, argv);
  47. +}
  48. diff -Nur busybox-1.20.2.orig//archival/Kbuild.src busybox-1.20.2/archival/Kbuild.src
  49. --- busybox-1.20.2.orig//archival/Kbuild.src 2012-06-26 15:35:45.000000000 +0200
  50. +++ busybox-1.20.2/archival/Kbuild.src 2013-01-31 16:44:31.000000000 +0100
  51. @@ -22,6 +22,7 @@
  52. lib-$(CONFIG_LZOP) += lzop.o bbunzip.o
  53. lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
  54. lib-$(CONFIG_BZIP2) += bzip2.o bbunzip.o
  55. +lib-$(CONFIG_IPKG) += ipkg.o
  56. lib-$(CONFIG_UNXZ) += bbunzip.o
  57. lib-$(CONFIG_UNLZMA) += bbunzip.o
  58. diff -Nur busybox-1.20.2.orig//archival/libarchive/Kbuild.src busybox-1.20.2/archival/libarchive/Kbuild.src
  59. --- busybox-1.20.2.orig//archival/libarchive/Kbuild.src 2012-06-26 15:35:45.000000000 +0200
  60. +++ busybox-1.20.2/archival/libarchive/Kbuild.src 2013-01-31 16:44:50.000000000 +0100
  61. @@ -25,14 +25,14 @@
  62. \
  63. data_align.o \
  64. find_list_entry.o \
  65. + get_header_tar.o \
  66. + get_header_tar_gz.o \
  67. init_handle.o
  68. DPKG_FILES:= \
  69. unpack_ar_archive.o \
  70. filter_accept_list_reassign.o \
  71. get_header_ar.o \
  72. - get_header_tar.o \
  73. - get_header_tar_gz.o \
  74. get_header_tar_bz2.o \
  75. get_header_tar_lzma.o \
  76. diff -Nur busybox-1.20.2.orig//archival/libipkg/args.c busybox-1.20.2/archival/libipkg/args.c
  77. --- busybox-1.20.2.orig//archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
  78. +++ busybox-1.20.2/archival/libipkg/args.c 2013-01-31 16:44:31.000000000 +0100
  79. @@ -0,0 +1,242 @@
  80. +/* args.c - parse command-line args
  81. +
  82. + Carl D. Worth
  83. +
  84. + Copyright 2001 University of Southern California
  85. +
  86. + This program is free software; you can redistribute it and/or modify
  87. + it under the terms of the GNU General Public License as published by
  88. + the Free Software Foundation; either version 2, or (at your option)
  89. + any later version.
  90. +
  91. + This program is distributed in the hope that it will be useful,
  92. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  93. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  94. + GNU General Public License for more details.
  95. + */
  96. +
  97. +#include <getopt.h>
  98. +#include <stdlib.h>
  99. +#include <string.h>
  100. +#include <unistd.h>
  101. +
  102. +#include "ipkg.h"
  103. +#include "ipkg_message.h"
  104. +
  105. +#include "args.h"
  106. +#include "sprintf_alloc.h"
  107. +
  108. +#include "libbb.h"
  109. +
  110. +
  111. +static void print_version(void);
  112. +
  113. +enum long_args_opt
  114. +{
  115. + ARGS_OPT_FORCE_DEFAULTS = 129,
  116. + ARGS_OPT_FORCE_DEPENDS,
  117. + ARGS_OPT_FORCE_OVERWRITE,
  118. + ARGS_OPT_FORCE_DOWNGRADE,
  119. + ARGS_OPT_FORCE_REINSTALL,
  120. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
  121. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
  122. + ARGS_OPT_FORCE_SPACE,
  123. + ARGS_OPT_NOACTION,
  124. + ARGS_OPT_NODEPS,
  125. + ARGS_OPT_VERBOSE_WGET,
  126. + ARGS_OPT_VERBOSITY,
  127. + ARGS_OPT_MULTIPLE_PROVIDERS
  128. +};
  129. +
  130. +int args_init(args_t *args)
  131. +{
  132. + const char *conf_file_dir;
  133. +
  134. + memset(args, 0, sizeof(args_t));
  135. +
  136. + args->dest = ARGS_DEFAULT_DEST;
  137. +
  138. + conf_file_dir = getenv("IPKG_CONF_DIR");
  139. + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
  140. + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
  141. + }
  142. + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
  143. + ARGS_DEFAULT_CONF_FILE_NAME);
  144. +
  145. + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
  146. + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
  147. + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
  148. + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
  149. + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
  150. + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
  151. + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
  152. + args->noaction = ARGS_DEFAULT_NOACTION;
  153. + args->nodeps = ARGS_DEFAULT_NODEPS;
  154. + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
  155. + args->verbosity = ARGS_DEFAULT_VERBOSITY;
  156. + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
  157. + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
  158. + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
  159. + args->multiple_providers = 0;
  160. + args->nocheckfordirorfile = 0;
  161. + args->noreadfeedsfile = 0;
  162. +
  163. + return 1;
  164. +}
  165. +
  166. +void args_deinit(args_t *args)
  167. +{
  168. + free(args->conf_file);
  169. + args->conf_file = NULL;
  170. +}
  171. +
  172. +int args_parse(args_t *args, int argc, char *argv[])
  173. +{
  174. + int c;
  175. + int option_index = 0;
  176. + int parse_err = 0;
  177. + static struct option long_options[] = {
  178. + {"query-all", 0, 0, 'A'},
  179. + {"conf-file", 1, 0, 'f'},
  180. + {"conf", 1, 0, 'f'},
  181. + {"dest", 1, 0, 'd'},
  182. + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  183. + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  184. + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  185. + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  186. + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  187. + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  188. + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  189. + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  190. + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  191. + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  192. + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
  193. + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
  194. + {"recursive", 0, 0,
  195. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  196. + {"force-removal-of-dependent-packages", 0, 0,
  197. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  198. + {"force_removal_of_dependent_packages", 0, 0,
  199. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  200. + {"force-removal-of-essential-packages", 0, 0,
  201. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  202. + {"force_removal_of_essential_packages", 0, 0,
  203. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  204. + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  205. + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  206. + {"noaction", 0, 0, ARGS_OPT_NOACTION},
  207. + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
  208. + {"offline", 1, 0, 'o'},
  209. + {"offline-root", 1, 0, 'o'},
  210. + {"test", 0, 0, ARGS_OPT_NOACTION},
  211. + {"tmp-dir", 1, 0, 't'},
  212. + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  213. + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  214. + {"verbosity", 2, 0, 'V'},
  215. + {"version", 0, 0, 'v'},
  216. + {0, 0, 0, 0}
  217. + };
  218. +
  219. + while (1) {
  220. + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
  221. + if (c == -1)
  222. + break;
  223. +
  224. + switch (c) {
  225. + case 'A':
  226. + args->query_all = 1;
  227. + break;
  228. + case 'd':
  229. + args->dest = optarg;
  230. + break;
  231. + case 'f':
  232. + free(args->conf_file);
  233. + args->conf_file = strdup(optarg);
  234. + break;
  235. + case 'o':
  236. + args->offline_root = optarg;
  237. + break;
  238. + case 'n':
  239. + args->noaction = 1;
  240. + break;
  241. + case 't':
  242. + args->tmp_dir = strdup(optarg);
  243. + break;
  244. + case 'v':
  245. + print_version();
  246. + exit(0);
  247. + case 'V':
  248. + case ARGS_OPT_VERBOSITY:
  249. + if (optarg)
  250. + args->verbosity = atoi(optarg);
  251. + else
  252. + args->verbosity += 1;
  253. + break;
  254. + case ARGS_OPT_FORCE_DEFAULTS:
  255. + args->force_defaults = 1;
  256. + break;
  257. + case ARGS_OPT_FORCE_DEPENDS:
  258. + args->force_depends = 1;
  259. + break;
  260. + case ARGS_OPT_FORCE_OVERWRITE:
  261. + args->force_overwrite = 1;
  262. + break;
  263. + case ARGS_OPT_FORCE_DOWNGRADE:
  264. + args->force_downgrade = 1;
  265. + break;
  266. + case ARGS_OPT_FORCE_REINSTALL:
  267. + args->force_reinstall = 1;
  268. + break;
  269. + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
  270. + args->force_removal_of_essential_packages = 1;
  271. + break;
  272. + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
  273. + args->force_removal_of_dependent_packages = 1;
  274. + break;
  275. + case ARGS_OPT_FORCE_SPACE:
  276. + args->force_space = 1;
  277. + break;
  278. + case ARGS_OPT_VERBOSE_WGET:
  279. + args->verbose_wget = 1;
  280. + break;
  281. + case ARGS_OPT_MULTIPLE_PROVIDERS:
  282. + args->multiple_providers = 1;
  283. + break;
  284. + case ARGS_OPT_NODEPS:
  285. + args->nodeps = 1;
  286. + break;
  287. + case ARGS_OPT_NOACTION:
  288. + args->noaction = 1;
  289. + break;
  290. + case ':':
  291. + parse_err++;
  292. + break;
  293. + case '?':
  294. + parse_err++;
  295. + break;
  296. + default:
  297. + bb_error_msg("Confusion: getopt_long returned %d\n", c);
  298. + }
  299. + }
  300. +
  301. + if (parse_err) {
  302. + return -parse_err;
  303. + } else {
  304. + return optind;
  305. + }
  306. +}
  307. +
  308. +void args_usage(const char *complaint)
  309. +{
  310. + if (complaint) {
  311. + bb_error_msg("%s\n", complaint);
  312. + }
  313. + print_version();
  314. + bb_show_usage();
  315. + exit(1);
  316. +}
  317. +
  318. +static void print_version(void)
  319. +{
  320. + bb_error_msg("version %s\n", IPKG_VERSION);
  321. +}
  322. diff -Nur busybox-1.20.2.orig//archival/libipkg/args.h busybox-1.20.2/archival/libipkg/args.h
  323. --- busybox-1.20.2.orig//archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
  324. +++ busybox-1.20.2/archival/libipkg/args.h 2013-01-31 16:44:31.000000000 +0100
  325. @@ -0,0 +1,72 @@
  326. +/* args.h - parse command-line args
  327. +
  328. + Carl D. Worth
  329. +
  330. + Copyright 2001 University of Southern California
  331. +
  332. + This program is free software; you can redistribute it and/or modify
  333. + it under the terms of the GNU General Public License as published by
  334. + the Free Software Foundation; either version 2, or (at your option)
  335. + any later version.
  336. +
  337. + This program is distributed in the hope that it will be useful,
  338. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  339. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  340. + GNU General Public License for more details.
  341. +*/
  342. +
  343. +#ifndef ARGS_H
  344. +#define ARGS_H
  345. +
  346. +struct args
  347. +{
  348. + char *conf_file;
  349. + char *dest;
  350. + char *tmp_dir;
  351. + int force_defaults;
  352. + int force_depends;
  353. + int force_overwrite;
  354. + int force_downgrade;
  355. + int force_reinstall;
  356. + int force_removal_of_essential_packages;
  357. + int force_removal_of_dependent_packages;
  358. + int force_space;
  359. + int noaction;
  360. + int nodeps;
  361. + int multiple_providers;
  362. + int query_all;
  363. + int verbose_wget;
  364. + int verbosity;
  365. + int nocheckfordirorfile;
  366. + int noreadfeedsfile;
  367. + char *offline_root;
  368. + char *offline_root_pre_script_cmd;
  369. + char *offline_root_post_script_cmd;
  370. +};
  371. +typedef struct args args_t;
  372. +
  373. +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
  374. +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
  375. +#define ARGS_DEFAULT_DEST NULL
  376. +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
  377. +#define ARGS_DEFAULT_FORCE_DEPENDS 0
  378. +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
  379. +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
  380. +#define ARGS_DEFAULT_FORCE_REINSTALL 0
  381. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
  382. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
  383. +#define ARGS_DEFAULT_FORCE_SPACE 0
  384. +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
  385. +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
  386. +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
  387. +#define ARGS_DEFAULT_NOACTION 0
  388. +#define ARGS_DEFAULT_NODEPS 0
  389. +#define ARGS_DEFAULT_VERBOSE_WGET 0
  390. +#define ARGS_DEFAULT_VERBOSITY 1
  391. +
  392. +int args_init(args_t *args);
  393. +void args_deinit(args_t *args);
  394. +int args_parse(args_t *args, int argc, char *argv[]);
  395. +void args_usage(const char *complaint);
  396. +
  397. +#endif
  398. diff -Nur busybox-1.20.2.orig//archival/libipkg/conffile.c busybox-1.20.2/archival/libipkg/conffile.c
  399. --- busybox-1.20.2.orig//archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
  400. +++ busybox-1.20.2/archival/libipkg/conffile.c 2013-01-31 16:44:31.000000000 +0100
  401. @@ -0,0 +1,65 @@
  402. +/* conffile.c - the itsy package management system
  403. +
  404. + Carl D. Worth
  405. +
  406. + Copyright (C) 2001 University of Southern California
  407. +
  408. + This program is free software; you can redistribute it and/or
  409. + modify it under the terms of the GNU General Public License as
  410. + published by the Free Software Foundation; either version 2, or (at
  411. + your option) any later version.
  412. +
  413. + This program is distributed in the hope that it will be useful, but
  414. + WITHOUT ANY WARRANTY; without even the implied warranty of
  415. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  416. + General Public License for more details.
  417. +*/
  418. +
  419. +#include <string.h>
  420. +#include <stdlib.h>
  421. +
  422. +#include "libbb.h"
  423. +#include "ipkg.h"
  424. +#include "ipkg_message.h"
  425. +
  426. +#include "conffile.h"
  427. +#include "file_util.h"
  428. +#include "sprintf_alloc.h"
  429. +
  430. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum)
  431. +{
  432. + return nv_pair_init(conffile, file_name, (char *)md5sum);
  433. +}
  434. +
  435. +void conffile_deinit(conffile_t *conffile)
  436. +{
  437. + nv_pair_deinit(conffile);
  438. +}
  439. +
  440. +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
  441. +{
  442. + uint8_t *md5sum;
  443. + char *filename = conffile->name;
  444. + char *root_filename;
  445. + int ret;
  446. +
  447. + if (conffile->value == NULL) {
  448. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
  449. + return 1;
  450. + }
  451. +
  452. + root_filename = root_filename_alloc(conf, filename);
  453. +
  454. + md5sum = file_md5sum_alloc(root_filename);
  455. +
  456. + ret = strcmp((char *)md5sum, conffile->value);
  457. + if (ret) {
  458. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
  459. + conffile->name, md5sum, conffile->value);
  460. + }
  461. +
  462. + free(root_filename);
  463. + free(md5sum);
  464. +
  465. + return ret;
  466. +}
  467. diff -Nur busybox-1.20.2.orig//archival/libipkg/conffile.h busybox-1.20.2/archival/libipkg/conffile.h
  468. --- busybox-1.20.2.orig//archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
  469. +++ busybox-1.20.2/archival/libipkg/conffile.h 2013-01-31 16:44:31.000000000 +0100
  470. @@ -0,0 +1,30 @@
  471. +/* conffile.h - the itsy package management system
  472. +
  473. + Carl D. Worth
  474. +
  475. + Copyright (C) 2001 University of Southern California
  476. +
  477. + This program is free software; you can redistribute it and/or
  478. + modify it under the terms of the GNU General Public License as
  479. + published by the Free Software Foundation; either version 2, or (at
  480. + your option) any later version.
  481. +
  482. + This program is distributed in the hope that it will be useful, but
  483. + WITHOUT ANY WARRANTY; without even the implied warranty of
  484. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  485. + General Public License for more details.
  486. +*/
  487. +
  488. +#ifndef CONFFILE_H
  489. +#define CONFFILE_H
  490. +
  491. +#include "nv_pair.h"
  492. +
  493. +typedef struct nv_pair conffile_t;
  494. +
  495. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum);
  496. +void conffile_deinit(conffile_t *conffile);
  497. +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
  498. +
  499. +#endif
  500. +
  501. diff -Nur busybox-1.20.2.orig//archival/libipkg/conffile_list.c busybox-1.20.2/archival/libipkg/conffile_list.c
  502. --- busybox-1.20.2.orig//archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
  503. +++ busybox-1.20.2/archival/libipkg/conffile_list.c 2013-01-31 16:44:31.000000000 +0100
  504. @@ -0,0 +1,47 @@
  505. +/* conffile_list.c - the itsy package management system
  506. +
  507. + Carl D. Worth
  508. +
  509. + Copyright (C) 2001 University of Southern California
  510. +
  511. + This program is free software; you can redistribute it and/or
  512. + modify it under the terms of the GNU General Public License as
  513. + published by the Free Software Foundation; either version 2, or (at
  514. + your option) any later version.
  515. +
  516. + This program is distributed in the hope that it will be useful, but
  517. + WITHOUT ANY WARRANTY; without even the implied warranty of
  518. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  519. + General Public License for more details.
  520. +*/
  521. +
  522. +#include "ipkg.h"
  523. +
  524. +#include "conffile_list.h"
  525. +
  526. +int conffile_list_init(conffile_list_t *list)
  527. +{
  528. + return nv_pair_list_init(list);
  529. +}
  530. +
  531. +void conffile_list_deinit(conffile_list_t *list)
  532. +{
  533. + nv_pair_list_deinit(list);
  534. +}
  535. +
  536. +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
  537. + const char *md5sum)
  538. +{
  539. + return nv_pair_list_append(list, file_name, md5sum);
  540. +}
  541. +
  542. +int conffile_list_push(conffile_list_t *list, conffile_t *data)
  543. +{
  544. + return nv_pair_list_push(list, data);
  545. +}
  546. +
  547. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
  548. +{
  549. + return nv_pair_list_pop(list);
  550. +}
  551. +
  552. diff -Nur busybox-1.20.2.orig//archival/libipkg/conffile_list.h busybox-1.20.2/archival/libipkg/conffile_list.h
  553. --- busybox-1.20.2.orig//archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
  554. +++ busybox-1.20.2/archival/libipkg/conffile_list.h 2013-01-31 16:44:31.000000000 +0100
  555. @@ -0,0 +1,36 @@
  556. +/* conffile_list.h - the itsy package management system
  557. +
  558. + Carl D. Worth
  559. +
  560. + Copyright (C) 2001 University of Southern California
  561. +
  562. + This program is free software; you can redistribute it and/or
  563. + modify it under the terms of the GNU General Public License as
  564. + published by the Free Software Foundation; either version 2, or (at
  565. + your option) any later version.
  566. +
  567. + This program is distributed in the hope that it will be useful, but
  568. + WITHOUT ANY WARRANTY; without even the implied warranty of
  569. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  570. + General Public License for more details.
  571. +*/
  572. +
  573. +#ifndef CONFFILE_LIST_H
  574. +#define CONFFILE_LIST_H
  575. +
  576. +#include "conffile.h"
  577. +#include "nv_pair_list.h"
  578. +
  579. +typedef struct nv_pair_list_elt conffile_list_elt_t;
  580. +typedef struct nv_pair_list conffile_list_t;
  581. +
  582. +int conffile_list_init(conffile_list_t *list);
  583. +void conffile_list_deinit(conffile_list_t *list);
  584. +
  585. +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
  586. + const char *root_dir);
  587. +int conffile_list_push(conffile_list_t *list, conffile_t *data);
  588. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
  589. +
  590. +#endif
  591. +
  592. diff -Nur busybox-1.20.2.orig//archival/libipkg/file_util.c busybox-1.20.2/archival/libipkg/file_util.c
  593. --- busybox-1.20.2.orig//archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
  594. +++ busybox-1.20.2/archival/libipkg/file_util.c 2013-01-31 16:44:31.000000000 +0100
  595. @@ -0,0 +1,186 @@
  596. +/* file_util.c - convenience routines for common stat operations
  597. +
  598. + Carl D. Worth
  599. +
  600. + Copyright (C) 2001 University of Southern California
  601. +
  602. + This program is free software; you can redistribute it and/or
  603. + modify it under the terms of the GNU General Public License as
  604. + published by the Free Software Foundation; either version 2, or (at
  605. + your option) any later version.
  606. +
  607. + This program is distributed in the hope that it will be useful, but
  608. + WITHOUT ANY WARRANTY; without even the implied warranty of
  609. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  610. + General Public License for more details.
  611. +*/
  612. +
  613. +#include "ipkg.h"
  614. +#include <sys/types.h>
  615. +#include <sys/stat.h>
  616. +
  617. +#include "sprintf_alloc.h"
  618. +#include "file_util.h"
  619. +#include "libbb.h"
  620. +#undef strlen
  621. +
  622. +int file_exists(const char *file_name)
  623. +{
  624. + int err;
  625. + struct stat stat_buf;
  626. +
  627. + err = stat(file_name, &stat_buf);
  628. + if (err == 0) {
  629. + return 1;
  630. + } else {
  631. + return 0;
  632. + }
  633. +}
  634. +
  635. +int file_is_dir(const char *file_name)
  636. +{
  637. + int err;
  638. + struct stat stat_buf;
  639. +
  640. + err = stat(file_name, &stat_buf);
  641. + if (err) {
  642. + return 0;
  643. + }
  644. +
  645. + return S_ISDIR(stat_buf.st_mode);
  646. +}
  647. +
  648. +/* read a single line from a file, stopping at a newline or EOF.
  649. + If a newline is read, it will appear in the resulting string.
  650. + Return value is a malloc'ed char * which should be freed at
  651. + some point by the caller.
  652. +
  653. + Return value is NULL if the file is at EOF when called.
  654. +*/
  655. +#define FILE_READ_LINE_BUF_SIZE 1024
  656. +char *file_read_line_alloc(FILE *file)
  657. +{
  658. + char buf[FILE_READ_LINE_BUF_SIZE];
  659. + int buf_len;
  660. + char *line = NULL;
  661. + int line_size = 0;
  662. +
  663. + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
  664. + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
  665. + buf_len = strlen(buf);
  666. + if (line) {
  667. + line_size += buf_len;
  668. + line = realloc(line, line_size);
  669. + if (line == NULL) {
  670. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  671. + break;
  672. + }
  673. + strcat(line, buf);
  674. + } else {
  675. + line_size = buf_len + 1;
  676. + line = strdup(buf);
  677. + }
  678. + if (buf[buf_len - 1] == '\n') {
  679. + break;
  680. + }
  681. + }
  682. +
  683. + return line;
  684. +}
  685. +
  686. +int file_move(const char *src, const char *dest)
  687. +{
  688. + int err;
  689. +
  690. + err = rename(src, dest);
  691. +
  692. + if (err && errno == EXDEV) {
  693. + err = file_copy(src, dest);
  694. + unlink(src);
  695. + } else if (err) {
  696. + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
  697. + __FUNCTION__, src, dest, strerror(errno));
  698. + }
  699. +
  700. + return err;
  701. +}
  702. +
  703. +/* I put these here to keep libbb dependencies from creeping all over
  704. + the ipkg code */
  705. +int file_copy(const char *src, const char *dest)
  706. +{
  707. + int err;
  708. +
  709. + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
  710. + if (err) {
  711. + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
  712. + __FUNCTION__, src, dest);
  713. + }
  714. +
  715. + return err;
  716. +}
  717. +
  718. +int file_mkdir_hier(char *path, long mode)
  719. +{
  720. + return bb_make_directory(path, mode, FILEUTILS_RECUR);
  721. +}
  722. +
  723. +static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
  724. + unsigned hash_length)
  725. +{
  726. + /* xzalloc zero-terminates */
  727. + char *hex_value = xzalloc((hash_length * 2) + 1);
  728. + bin2hex(hex_value, (char*)hash_value, hash_length);
  729. + return (unsigned char *)hex_value;
  730. +}
  731. +
  732. +static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
  733. +{
  734. + int src_fd, hash_len, count;
  735. + union _ctx_ {
  736. + sha1_ctx_t sha1;
  737. + md5_ctx_t md5;
  738. + } context;
  739. + uint8_t *hash_value = NULL;
  740. + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
  741. + void FAST_FUNC (*update)(void*, const void*, size_t);
  742. + void FAST_FUNC (*final)(void*, void*);
  743. +
  744. + src_fd = open_or_warn_stdin(filename);
  745. + if (src_fd < 0) {
  746. + return NULL;
  747. + }
  748. +
  749. + /* figure specific hash algorithims */
  750. + if (ENABLE_MD5SUM && hash_algo == HASH_MD5) {
  751. + md5_begin(&context.md5);
  752. + update = (void*)md5_hash;
  753. + final = (void*)md5_end;
  754. + hash_len = 16;
  755. + } else {
  756. + bb_error_msg_and_die("algorithm not supported");
  757. + }
  758. +
  759. + while ((count = safe_read(src_fd, in_buf, 4096)) > 0) {
  760. + update(&context, in_buf, count);
  761. + }
  762. +
  763. + if (count == 0) {
  764. + final(&context, in_buf);
  765. + hash_value = hash_bin_to_hex(in_buf, hash_len);
  766. + }
  767. +
  768. + RELEASE_CONFIG_BUFFER(in_buf);
  769. +
  770. + if (src_fd != STDIN_FILENO) {
  771. + close(src_fd);
  772. + }
  773. +
  774. + return hash_value;
  775. +}
  776. +
  777. +uint8_t *file_md5sum_alloc(const char *file_name)
  778. +{
  779. + return hash_file(file_name, HASH_MD5);
  780. +}
  781. +
  782. diff -Nur busybox-1.20.2.orig//archival/libipkg/file_util.h busybox-1.20.2/archival/libipkg/file_util.h
  783. --- busybox-1.20.2.orig//archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
  784. +++ busybox-1.20.2/archival/libipkg/file_util.h 2013-01-31 16:44:31.000000000 +0100
  785. @@ -0,0 +1,29 @@
  786. +/* file_util.h - convenience routines for common file operations
  787. +
  788. + Carl D. Worth
  789. +
  790. + Copyright (C) 2001 University of Southern California
  791. +
  792. + This program is free software; you can redistribute it and/or
  793. + modify it under the terms of the GNU General Public License as
  794. + published by the Free Software Foundation; either version 2, or (at
  795. + your option) any later version.
  796. +
  797. + This program is distributed in the hope that it will be useful, but
  798. + WITHOUT ANY WARRANTY; without even the implied warranty of
  799. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  800. + General Public License for more details.
  801. +*/
  802. +
  803. +#ifndef FILE_UTIL_H
  804. +#define FILE_UTIL_H
  805. +
  806. +int file_exists(const char *file_name);
  807. +int file_is_dir(const char *file_name);
  808. +char *file_read_line_alloc(FILE *file);
  809. +int file_move(const char *src, const char *dest);
  810. +int file_copy(const char *src, const char *dest);
  811. +int file_mkdir_hier(char *path, long mode);
  812. +uint8_t *file_md5sum_alloc(const char *file_name);
  813. +
  814. +#endif
  815. diff -Nur busybox-1.20.2.orig//archival/libipkg/hash_table.c busybox-1.20.2/archival/libipkg/hash_table.c
  816. --- busybox-1.20.2.orig//archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
  817. +++ busybox-1.20.2/archival/libipkg/hash_table.c 2013-01-31 16:44:31.000000000 +0100
  818. @@ -0,0 +1,155 @@
  819. +/* hash.c - hash tables for ipkg
  820. +
  821. + Steven M. Ayer, Jamey Hicks
  822. +
  823. + Copyright (C) 2002 Compaq Computer Corporation
  824. +
  825. + This program is free software; you can redistribute it and/or
  826. + modify it under the terms of the GNU General Public License as
  827. + published by the Free Software Foundation; either version 2, or (at
  828. + your option) any later version.
  829. +
  830. + This program is distributed in the hope that it will be useful, but
  831. + WITHOUT ANY WARRANTY; without even the implied warranty of
  832. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  833. + General Public License for more details.
  834. +*/
  835. +
  836. +#include <errno.h>
  837. +#include <stdio.h>
  838. +#include <stdlib.h>
  839. +#include <string.h>
  840. +#include "hash_table.h"
  841. +#include "ipkg_message.h"
  842. +
  843. +
  844. +static int hash_index(hash_table_t *hash, const char *pkg_name);
  845. +static int rotating(const char *key, int len, int prime);
  846. +
  847. +static int hash_index(hash_table_t *hash, const char *pkg_name)
  848. +{
  849. + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
  850. +}
  851. +
  852. +static int rotating(const char *key, int len, int prime)
  853. +{
  854. + unsigned int hash, i;
  855. + for (hash=len, i=0; i<len; ++i)
  856. + hash = (hash<<4)^(hash>>28)^key[i];
  857. + return (hash % prime);
  858. +}
  859. +
  860. +
  861. +/*
  862. + * this is an open table keyed by strings
  863. + */
  864. +int hash_table_init(const char *name, hash_table_t *hash, int len)
  865. +{
  866. + static int primes_table[] = {
  867. + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
  868. + 19471, 23143, 33961, 46499, 49727, 99529, 0
  869. + };
  870. + int *picker;
  871. +
  872. + if (hash->entries != NULL) {
  873. + /* we have been here already */
  874. + return 0;
  875. + }
  876. +
  877. + hash->name = name;
  878. + hash->entries = NULL;
  879. + hash->n_entries = 0;
  880. + hash->hash_entry_key = NULL;
  881. +
  882. + picker = primes_table;
  883. + while(*picker && (*picker++ < len));
  884. + if(!*picker)
  885. + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
  886. + --picker;
  887. +
  888. + hash->n_entries = *picker;
  889. + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
  890. + if (hash->entries == NULL) {
  891. + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
  892. + return ENOMEM;
  893. + }
  894. + return 0;
  895. +}
  896. +
  897. +void hash_table_deinit(hash_table_t *hash)
  898. +{
  899. + free(hash->entries);
  900. + hash->entries = NULL;
  901. + hash->n_entries = 0;
  902. +}
  903. +
  904. +void *hash_table_get(hash_table_t *hash, const char *key)
  905. +{
  906. + int ndx= hash_index(hash, key);
  907. + hash_entry_t *hash_entry = hash->entries + ndx;
  908. + while (hash_entry)
  909. + {
  910. + if (hash_entry->key)
  911. + {
  912. + if (strcmp(key, hash_entry->key) == 0) {
  913. + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
  914. + return hash_entry->data;
  915. + }
  916. + }
  917. + hash_entry = hash_entry->next;
  918. + }
  919. + return NULL;
  920. +}
  921. +
  922. +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
  923. +{
  924. + int ndx= hash_index(hash, key);
  925. + hash_entry_t *hash_entry = hash->entries + ndx;
  926. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
  927. + if (hash_entry->key) {
  928. + if (strcmp(hash_entry->key, key) == 0) {
  929. + /* alread in table, update the value */
  930. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
  931. + hash_entry->data = value;
  932. + return 0;
  933. + } else {
  934. + /*
  935. + * if this is a collision, we have to go to the end of the ll,
  936. + * then add a new entry
  937. + * before we can hook up the value
  938. + */
  939. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
  940. + while (hash_entry->next)
  941. + hash_entry = hash_entry->next;
  942. + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
  943. + if (!hash_entry->next) {
  944. + return -ENOMEM;
  945. + }
  946. + hash_entry = hash_entry->next;
  947. + hash_entry->next = NULL;
  948. + }
  949. + }
  950. + hash->n_elements++;
  951. + hash_entry->key = strdup(key);
  952. + hash_entry->data = value;
  953. +
  954. + return 0;
  955. +}
  956. +
  957. +
  958. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
  959. +{
  960. + int i;
  961. + if (!hash || !f)
  962. + return;
  963. +
  964. + for (i = 0; i < hash->n_entries; i++) {
  965. + hash_entry_t *hash_entry = (hash->entries + i);
  966. + do {
  967. + if(hash_entry->key) {
  968. + f(hash_entry->key, hash_entry->data, data);
  969. + }
  970. + } while((hash_entry = hash_entry->next));
  971. + }
  972. +}
  973. +
  974. diff -Nur busybox-1.20.2.orig//archival/libipkg/hash_table.h busybox-1.20.2/archival/libipkg/hash_table.h
  975. --- busybox-1.20.2.orig//archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
  976. +++ busybox-1.20.2/archival/libipkg/hash_table.h 2013-01-31 16:44:31.000000000 +0100
  977. @@ -0,0 +1,44 @@
  978. +/* hash.h - hash tables for ipkg
  979. +
  980. + Steven M. Ayer, Jamey Hicks
  981. +
  982. + Copyright (C) 2002 Compaq Computer Corporation
  983. +
  984. + This program is free software; you can redistribute it and/or
  985. + modify it under the terms of the GNU General Public License as
  986. + published by the Free Software Foundation; either version 2, or (at
  987. + your option) any later version.
  988. +
  989. + This program is distributed in the hope that it will be useful, but
  990. + WITHOUT ANY WARRANTY; without even the implied warranty of
  991. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  992. + General Public License for more details.
  993. +*/
  994. +
  995. +#ifndef _HASH_TABLE_H_
  996. +#define _HASH_TABLE_H_
  997. +
  998. +typedef struct hash_entry hash_entry_t;
  999. +typedef struct hash_table hash_table_t;
  1000. +
  1001. +struct hash_entry {
  1002. + const char * key;
  1003. + void * data;
  1004. + struct hash_entry * next;
  1005. +};
  1006. +
  1007. +struct hash_table {
  1008. + const char *name;
  1009. + hash_entry_t * entries;
  1010. + int n_entries; /* number of buckets */
  1011. + int n_elements;
  1012. + const char * (*hash_entry_key)(void * data);
  1013. +};
  1014. +
  1015. +int hash_table_init(const char *name, hash_table_t *hash, int len);
  1016. +void hash_table_deinit(hash_table_t *hash);
  1017. +void *hash_table_get(hash_table_t *hash, const char *key);
  1018. +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
  1019. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
  1020. +
  1021. +#endif /* _HASH_TABLE_H_ */
  1022. diff -Nur busybox-1.20.2.orig//archival/libipkg/ipkg_cmd.c busybox-1.20.2/archival/libipkg/ipkg_cmd.c
  1023. --- busybox-1.20.2.orig//archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
  1024. +++ busybox-1.20.2/archival/libipkg/ipkg_cmd.c 2013-01-31 16:44:31.000000000 +0100
  1025. @@ -0,0 +1,1367 @@
  1026. +/* ipkg_cmd.c - the itsy package management system
  1027. +
  1028. + Carl D. Worth
  1029. +
  1030. + Copyright (C) 2001 University of Southern California
  1031. +
  1032. + This program is free software; you can redistribute it and/or
  1033. + modify it under the terms of the GNU General Public License as
  1034. + published by the Free Software Foundation; either version 2, or (at
  1035. + your option) any later version.
  1036. +
  1037. + This program is distributed in the hope that it will be useful, but
  1038. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1039. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1040. + General Public License for more details.
  1041. +*/
  1042. +
  1043. +#include <string.h>
  1044. +
  1045. +#include "ipkg.h"
  1046. +#include <libgen.h>
  1047. +#include <glob.h>
  1048. +#include <errno.h>
  1049. +#include <stdlib.h>
  1050. +#include <unistd.h>
  1051. +#include <signal.h>
  1052. +#include <stdio.h>
  1053. +#include <dirent.h>
  1054. +
  1055. +#include "ipkg_conf.h"
  1056. +#include "ipkg_cmd.h"
  1057. +#include "ipkg_message.h"
  1058. +#include "pkg.h"
  1059. +#include "pkg_dest.h"
  1060. +#include "pkg_parse.h"
  1061. +#include "sprintf_alloc.h"
  1062. +#include "pkg.h"
  1063. +#include "file_util.h"
  1064. +#include "str_util.h"
  1065. +#include "bb_archive.h"
  1066. +
  1067. +#include <fnmatch.h>
  1068. +
  1069. +
  1070. +#include "ipkg_download.h"
  1071. +#include "ipkg_install.h"
  1072. +#include "ipkg_upgrade.h"
  1073. +#include "ipkg_remove.h"
  1074. +#include "ipkg_configure.h"
  1075. +#include "ipkg_message.h"
  1076. +
  1077. +#include "libipkg.h"
  1078. +static void *p_userdata = NULL;
  1079. +
  1080. +static int ipkg_update_cmd(ipkg_conf_t *conf);
  1081. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1082. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1083. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1084. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1085. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf);
  1086. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1087. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1088. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1089. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1090. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1091. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1092. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1093. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1094. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1095. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1096. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1097. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1098. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1099. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1100. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1101. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1102. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1103. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf);
  1104. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1105. +
  1106. +/* XXX: CLEANUP: The usage strings should be incorporated into this
  1107. + array for easier maintenance */
  1108. +static ipkg_cmd_t cmds[] = {
  1109. + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
  1110. + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
  1111. + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
  1112. + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
  1113. + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
  1114. + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
  1115. + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
  1116. + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
  1117. + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
  1118. + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
  1119. + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
  1120. + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
  1121. + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
  1122. + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
  1123. + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
  1124. + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1125. + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1126. + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1127. + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1128. + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1129. + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1130. + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
  1131. + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
  1132. + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
  1133. + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
  1134. + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
  1135. + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
  1136. + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
  1137. + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
  1138. +};
  1139. +
  1140. +int ipkg_state_changed;
  1141. +static void write_status_files_if_changed(ipkg_conf_t *conf)
  1142. +{
  1143. + if (ipkg_state_changed && !conf->noaction) {
  1144. + ipkg_message(conf, IPKG_INFO,
  1145. + " writing status file\n");
  1146. + ipkg_conf_write_status_files(conf);
  1147. + pkg_write_changed_filelists(conf);
  1148. + } else {
  1149. + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
  1150. + }
  1151. +}
  1152. +
  1153. +
  1154. +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
  1155. +
  1156. +ipkg_cmd_t *ipkg_cmd_find(const char *name)
  1157. +{
  1158. + int i;
  1159. + ipkg_cmd_t *cmd;
  1160. +
  1161. + for (i=0; i < num_cmds; i++) {
  1162. + cmd = &cmds[i];
  1163. + if (strcmp(name, cmd->name) == 0) {
  1164. + return cmd;
  1165. + }
  1166. + }
  1167. +
  1168. + return NULL;
  1169. +}
  1170. +
  1171. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
  1172. +{
  1173. + int result;
  1174. + p_userdata = userdata;
  1175. +
  1176. +
  1177. + result = (cmd->fun)(conf, argc, argv);
  1178. + if ( result == 0 ) {
  1179. + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
  1180. + } else {
  1181. + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
  1182. +
  1183. + }
  1184. + if ( error_list ) {
  1185. + reverse_error_list(&error_list);
  1186. +
  1187. + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
  1188. + /* Here we print the errors collected and free the list */
  1189. + while (error_list != NULL) {
  1190. + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
  1191. + error_list = error_list->next;
  1192. +
  1193. + }
  1194. + free_error_list(&error_list);
  1195. +
  1196. + }
  1197. +
  1198. + p_userdata = NULL;
  1199. + return result;
  1200. +}
  1201. +
  1202. +static int ipkg_update_cmd(ipkg_conf_t *conf)
  1203. +{
  1204. + int err;
  1205. + int failures;
  1206. + char *lists_dir;
  1207. + pkg_src_list_elt_t *iter;
  1208. + pkg_src_t *src;
  1209. +
  1210. +
  1211. + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
  1212. +
  1213. + if (! file_is_dir(lists_dir)) {
  1214. + if (file_exists(lists_dir)) {
  1215. + ipkg_message(conf, IPKG_ERROR,
  1216. + "%s: ERROR: %s exists, but is not a directory\n",
  1217. + __FUNCTION__, lists_dir);
  1218. + free(lists_dir);
  1219. + return EINVAL;
  1220. + }
  1221. + err = file_mkdir_hier(lists_dir, 0755);
  1222. + if (err) {
  1223. + ipkg_message(conf, IPKG_ERROR,
  1224. + "%s: ERROR: failed to make directory %s: %s\n",
  1225. + __FUNCTION__, lists_dir, strerror(errno));
  1226. + free(lists_dir);
  1227. + return EINVAL;
  1228. + }
  1229. + }
  1230. +
  1231. + failures = 0;
  1232. + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
  1233. + char *url, *list_file_name;
  1234. +
  1235. + src = iter->data;
  1236. +
  1237. + if (src->extra_data) /* debian style? */
  1238. + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
  1239. + src->gzip ? "Packages.gz" : "Packages");
  1240. + else
  1241. + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
  1242. +
  1243. + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
  1244. + if (src->gzip) {
  1245. + char *tmp;
  1246. + char *tmp_file_name;
  1247. + FILE *in, *out;
  1248. +
  1249. + tmp = strdup ("/tmp/ipkg.XXXXXX");
  1250. +
  1251. + if (mkdtemp (tmp) == NULL) {
  1252. + perror ("mkdtemp");
  1253. + failures++;
  1254. + continue;
  1255. + }
  1256. +
  1257. + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
  1258. + err = ipkg_download(conf, url, tmp_file_name);
  1259. + if (err == 0) {
  1260. + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
  1261. + in = fopen (tmp_file_name, "r");
  1262. + out = fopen (list_file_name, "w");
  1263. + if (in && out) {
  1264. + transformer_aux_data_t aux;
  1265. + init_transformer_aux_data(&aux);
  1266. + inflate_unzip (&aux, fileno(in), fileno(out));
  1267. + } else
  1268. + err = 1;
  1269. + if (in)
  1270. + fclose (in);
  1271. + if (out)
  1272. + fclose (out);
  1273. + unlink (tmp_file_name);
  1274. + rmdir (tmp);
  1275. + free (tmp);
  1276. + }
  1277. + } else
  1278. + err = ipkg_download(conf, url, list_file_name);
  1279. + if (err) {
  1280. + failures++;
  1281. + } else {
  1282. + ipkg_message(conf, IPKG_NOTICE,
  1283. + "Updated list of available packages in %s\n",
  1284. + list_file_name);
  1285. + }
  1286. + free(url);
  1287. + free(list_file_name);
  1288. + }
  1289. + free(lists_dir);
  1290. +
  1291. +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
  1292. +#warning here
  1293. + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
  1294. + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
  1295. + * -Jamey 3/1/03
  1296. + */
  1297. + {
  1298. + int i;
  1299. + int changed = 0;
  1300. + pkg_vec_t *available = pkg_vec_alloc();
  1301. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1302. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
  1303. + for (i = 0; i < available->len; i++) {
  1304. + pkg_t *pkg = available->pkgs[i];
  1305. + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
  1306. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
  1307. + pkg->state_want = SW_UNKNOWN;
  1308. + changed = 1;
  1309. + }
  1310. + }
  1311. + pkg_vec_free(available);
  1312. + if (changed) {
  1313. + write_status_files_if_changed(conf);
  1314. + }
  1315. + }
  1316. +#endif
  1317. +
  1318. + return failures;
  1319. +}
  1320. +
  1321. +
  1322. +/* scan the args passed and cache the local filenames of the packages */
  1323. +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
  1324. +{
  1325. + int i;
  1326. + int err;
  1327. +
  1328. + /*
  1329. + * First scan through package names/urls
  1330. + * For any urls, download the packages and install in database.
  1331. + * For any files, install package info in database.
  1332. + */
  1333. + for (i = 0; i < argc; i ++) {
  1334. + char *filename = argv [i];
  1335. + //char *tmp = basename (tmp);
  1336. + //int tmplen = strlen (tmp);
  1337. +
  1338. + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
  1339. + // continue;
  1340. + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
  1341. + // continue;
  1342. +
  1343. + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
  1344. +
  1345. + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
  1346. + if (err)
  1347. + return err;
  1348. + }
  1349. + return 0;
  1350. +}
  1351. +
  1352. +struct ipkg_intercept
  1353. +{
  1354. + char *oldpath;
  1355. + char *statedir;
  1356. +};
  1357. +
  1358. +typedef struct ipkg_intercept *ipkg_intercept_t;
  1359. +ipkg_intercept_t ipkg_prep_intercepts(void);
  1360. +
  1361. +ipkg_intercept_t ipkg_prep_intercepts(void)
  1362. +{
  1363. + ipkg_intercept_t ctx;
  1364. + char *newpath;
  1365. + int gen;
  1366. +
  1367. + ctx = malloc (sizeof (*ctx));
  1368. + ctx->oldpath = strdup (getenv ("PATH"));
  1369. +
  1370. + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
  1371. + setenv ("PATH", newpath, 1);
  1372. + free (newpath);
  1373. +
  1374. + gen = 0;
  1375. + retry:
  1376. + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
  1377. + if (mkdir (ctx->statedir, 0770) < 0) {
  1378. + if (errno == EEXIST) {
  1379. + free (ctx->statedir);
  1380. + gen++;
  1381. + goto retry;
  1382. + }
  1383. + perror (ctx->statedir);
  1384. + return NULL;
  1385. + }
  1386. + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
  1387. + return ctx;
  1388. +}
  1389. +
  1390. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx);
  1391. +
  1392. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
  1393. +{
  1394. + char *cmd;
  1395. + DIR *dir;
  1396. + int err = 0;
  1397. +
  1398. + setenv ("PATH", ctx->oldpath, 1);
  1399. + free (ctx->oldpath);
  1400. +
  1401. + dir = opendir (ctx->statedir);
  1402. + if (dir) {
  1403. + struct dirent *de;
  1404. + while (de = readdir (dir), de != NULL) {
  1405. + char *path;
  1406. +
  1407. + if (de->d_name[0] == '.')
  1408. + continue;
  1409. +
  1410. + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
  1411. + if (access (path, X_OK) == 0) {
  1412. + if (system (path)) {
  1413. + err = errno;
  1414. + perror (de->d_name);
  1415. + }
  1416. + }
  1417. + free (path);
  1418. + }
  1419. + } else
  1420. + perror (ctx->statedir);
  1421. +
  1422. + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
  1423. + system (cmd);
  1424. + free (cmd);
  1425. +
  1426. + free (ctx->statedir);
  1427. + free (ctx);
  1428. +
  1429. + return err;
  1430. +}
  1431. +
  1432. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
  1433. +{
  1434. + pkg_vec_t *all;
  1435. + int i;
  1436. + pkg_t *pkg;
  1437. + ipkg_intercept_t ic;
  1438. + int r, err = 0;
  1439. +
  1440. + ipkg_message(conf, IPKG_INFO,
  1441. + "Configuring unpacked packages\n");
  1442. + fflush( stdout );
  1443. +
  1444. + all = pkg_vec_alloc();
  1445. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  1446. +
  1447. + ic = ipkg_prep_intercepts();
  1448. +
  1449. + for(i = 0; i < all->len; i++) {
  1450. + pkg = all->pkgs[i];
  1451. +
  1452. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1453. + continue;
  1454. +
  1455. + if (pkg->state_status == SS_UNPACKED) {
  1456. + ipkg_message(conf, IPKG_NOTICE,
  1457. + "Configuring %s\n", pkg->name);
  1458. + fflush( stdout );
  1459. + r = ipkg_configure(conf, pkg);
  1460. + if (r == 0) {
  1461. + pkg->state_status = SS_INSTALLED;
  1462. + pkg->parent->state_status = SS_INSTALLED;
  1463. + pkg->state_flag &= ~SF_PREFER;
  1464. + } else {
  1465. + if (!err)
  1466. + err = r;
  1467. + }
  1468. + }
  1469. + }
  1470. +
  1471. + r = ipkg_finalize_intercepts (ic);
  1472. + if (r && !err)
  1473. + err = r;
  1474. +
  1475. + pkg_vec_free(all);
  1476. + return err;
  1477. +}
  1478. +
  1479. +static void sigint_handler(int sig)
  1480. +{
  1481. + signal(sig, SIG_DFL);
  1482. + ipkg_message(NULL, IPKG_NOTICE,
  1483. + "ipkg: interrupted. writing out status database\n");
  1484. + write_status_files_if_changed(global_conf);
  1485. + exit(128 + sig);
  1486. +}
  1487. +
  1488. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1489. +{
  1490. + int i;
  1491. + char *arg;
  1492. + int err=0;
  1493. +
  1494. + global_conf = conf;
  1495. + signal(SIGINT, sigint_handler);
  1496. +
  1497. + /*
  1498. + * Now scan through package names and install
  1499. + */
  1500. + for (i=0; i < argc; i++) {
  1501. + arg = argv[i];
  1502. +
  1503. + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
  1504. + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
  1505. + if (err != EINVAL && err != 0)
  1506. + return err;
  1507. + }
  1508. + pkg_info_preinstall_check(conf);
  1509. +
  1510. + for (i=0; i < argc; i++) {
  1511. + arg = argv[i];
  1512. + if (conf->multiple_providers)
  1513. + err = ipkg_install_multi_by_name(conf, arg);
  1514. + else{
  1515. + err = ipkg_install_by_name(conf, arg);
  1516. + }
  1517. + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
  1518. + ipkg_message(conf, IPKG_ERROR,
  1519. + "Cannot find package %s.\n"
  1520. + "Check the spelling or perhaps run 'ipkg update'\n",
  1521. + arg);
  1522. + }
  1523. + }
  1524. +
  1525. + /* recheck to verify that all dependences are satisfied */
  1526. + if (0) ipkg_satisfy_all_dependences(conf);
  1527. +
  1528. + ipkg_configure_packages(conf, NULL);
  1529. +
  1530. + write_status_files_if_changed(conf);
  1531. +
  1532. + return err;
  1533. +}
  1534. +
  1535. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1536. +{
  1537. + int i;
  1538. + pkg_t *pkg;
  1539. + int err;
  1540. +
  1541. + global_conf = conf;
  1542. + signal(SIGINT, sigint_handler);
  1543. +
  1544. + if (argc) {
  1545. + for (i=0; i < argc; i++) {
  1546. + char *arg = argv[i];
  1547. +
  1548. + err = ipkg_prepare_url_for_install(conf, arg, &arg);
  1549. + if (err != EINVAL && err != 0)
  1550. + return err;
  1551. + }
  1552. + pkg_info_preinstall_check(conf);
  1553. +
  1554. + for (i=0; i < argc; i++) {
  1555. + char *arg = argv[i];
  1556. + if (conf->restrict_to_default_dest) {
  1557. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1558. + argv[i],
  1559. + conf->default_dest);
  1560. + if (pkg == NULL) {
  1561. + ipkg_message(conf, IPKG_NOTICE,
  1562. + "Package %s not installed in %s\n",
  1563. + argv[i], conf->default_dest->name);
  1564. + continue;
  1565. + }
  1566. + } else {
  1567. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  1568. + argv[i]);
  1569. + }
  1570. + if (pkg)
  1571. + ipkg_upgrade_pkg(conf, pkg);
  1572. + else {
  1573. + ipkg_install_by_name(conf, arg);
  1574. + }
  1575. + }
  1576. + } else {
  1577. + pkg_vec_t *installed = pkg_vec_alloc();
  1578. +
  1579. + pkg_info_preinstall_check(conf);
  1580. +
  1581. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  1582. + for (i = 0; i < installed->len; i++) {
  1583. + pkg = installed->pkgs[i];
  1584. + ipkg_upgrade_pkg(conf, pkg);
  1585. + }
  1586. + pkg_vec_free(installed);
  1587. + }
  1588. +
  1589. + /* recheck to verify that all dependences are satisfied */
  1590. + if (0) ipkg_satisfy_all_dependences(conf);
  1591. +
  1592. + ipkg_configure_packages(conf, NULL);
  1593. +
  1594. + write_status_files_if_changed(conf);
  1595. +
  1596. + return 0;
  1597. +}
  1598. +
  1599. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1600. +{
  1601. + int i, err;
  1602. + char *arg;
  1603. + pkg_t *pkg;
  1604. +
  1605. + pkg_info_preinstall_check(conf);
  1606. + for (i = 0; i < argc; i++) {
  1607. + arg = argv[i];
  1608. +
  1609. + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
  1610. + if (pkg == NULL) {
  1611. + ipkg_message(conf, IPKG_ERROR,
  1612. + "Cannot find package %s.\n"
  1613. + "Check the spelling or perhaps run 'ipkg update'\n",
  1614. + arg);
  1615. + continue;
  1616. + }
  1617. +
  1618. + err = ipkg_download_pkg(conf, pkg, ".");
  1619. +
  1620. + if (err) {
  1621. + ipkg_message(conf, IPKG_ERROR,
  1622. + "Failed to download %s\n", pkg->name);
  1623. + } else {
  1624. + ipkg_message(conf, IPKG_NOTICE,
  1625. + "Downloaded %s as %s\n",
  1626. + pkg->name, pkg->local_filename);
  1627. + }
  1628. + }
  1629. +
  1630. + return 0;
  1631. +}
  1632. +
  1633. +
  1634. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1635. +{
  1636. + int i ;
  1637. + pkg_vec_t *available;
  1638. + pkg_t *pkg;
  1639. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1640. + char *newline;
  1641. + char *pkg_name = NULL;
  1642. + char *version_str;
  1643. +
  1644. + if (argc > 0) {
  1645. + pkg_name = argv[0];
  1646. + }
  1647. + available = pkg_vec_alloc();
  1648. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1649. + for (i=0; i < available->len; i++) {
  1650. + pkg = available->pkgs[i];
  1651. + /* if we have package name or pattern and pkg does not match, then skip it */
  1652. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1653. + continue;
  1654. + if (pkg->description) {
  1655. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1656. + } else {
  1657. + desc_short[0] = '\0';
  1658. + }
  1659. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1660. + newline = strchr(desc_short, '\n');
  1661. + if (newline) {
  1662. + *newline = '\0';
  1663. + }
  1664. + if (ipkg_cb_list) {
  1665. + version_str = pkg_version_str_alloc(pkg);
  1666. + ipkg_cb_list(pkg->name,desc_short,
  1667. + version_str,
  1668. + pkg->state_status,
  1669. + p_userdata);
  1670. + free(version_str);
  1671. + }
  1672. + }
  1673. + pkg_vec_free(available);
  1674. +
  1675. + return 0;
  1676. +}
  1677. +
  1678. +
  1679. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1680. +{
  1681. + int i ;
  1682. + pkg_vec_t *available;
  1683. + pkg_t *pkg;
  1684. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1685. + char *newline;
  1686. + char *pkg_name = NULL;
  1687. + char *version_str;
  1688. +
  1689. + if (argc > 0) {
  1690. + pkg_name = argv[0];
  1691. + }
  1692. + available = pkg_vec_alloc();
  1693. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1694. + for (i=0; i < available->len; i++) {
  1695. + pkg = available->pkgs[i];
  1696. + /* if we have package name or pattern and pkg does not match, then skip it */
  1697. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1698. + continue;
  1699. + if (pkg->description) {
  1700. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1701. + } else {
  1702. + desc_short[0] = '\0';
  1703. + }
  1704. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1705. + newline = strchr(desc_short, '\n');
  1706. + if (newline) {
  1707. + *newline = '\0';
  1708. + }
  1709. + if (ipkg_cb_list) {
  1710. + version_str = pkg_version_str_alloc(pkg);
  1711. + ipkg_cb_list(pkg->name,desc_short,
  1712. + version_str,
  1713. + pkg->state_status,
  1714. + p_userdata);
  1715. + free(version_str);
  1716. + }
  1717. + }
  1718. +
  1719. + return 0;
  1720. +}
  1721. +
  1722. +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
  1723. +{
  1724. + int i;
  1725. + pkg_vec_t *available;
  1726. + pkg_t *pkg;
  1727. + char *pkg_name = NULL;
  1728. + char **pkg_fields = NULL;
  1729. + int n_fields = 0;
  1730. + char *buff ; // = (char *)malloc(1);
  1731. +
  1732. + if (argc > 0) {
  1733. + pkg_name = argv[0];
  1734. + }
  1735. + if (argc > 1) {
  1736. + pkg_fields = &argv[1];
  1737. + n_fields = argc - 1;
  1738. + }
  1739. +
  1740. + available = pkg_vec_alloc();
  1741. + if (installed_only)
  1742. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1743. + else
  1744. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1745. + for (i=0; i < available->len; i++) {
  1746. + pkg = available->pkgs[i];
  1747. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1748. + continue;
  1749. + }
  1750. + buff = pkg_formatted_info(pkg);
  1751. + if ( buff ) {
  1752. + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
  1753. + pkg->state_status,
  1754. + buff,
  1755. + p_userdata);
  1756. + free(buff);
  1757. + }
  1758. + if (conf->verbosity > 1) {
  1759. + conffile_list_elt_t *iter;
  1760. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  1761. + conffile_t *cf = iter->data;
  1762. + int modified = conffile_has_been_modified(conf, cf);
  1763. + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
  1764. + cf->name, cf->value, modified);
  1765. + }
  1766. + }
  1767. + }
  1768. + pkg_vec_free(available);
  1769. +
  1770. + return 0;
  1771. +}
  1772. +
  1773. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1774. +{
  1775. + return ipkg_info_status_cmd(conf, argc, argv, 0);
  1776. +}
  1777. +
  1778. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1779. +{
  1780. + return ipkg_info_status_cmd(conf, argc, argv, 1);
  1781. +}
  1782. +
  1783. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1784. +{
  1785. +
  1786. + int err;
  1787. + if (argc > 0) {
  1788. + char *pkg_name = NULL;
  1789. +
  1790. + pkg_name = argv[0];
  1791. +
  1792. + err = ipkg_configure_packages (conf, pkg_name);
  1793. +
  1794. + } else {
  1795. + err = ipkg_configure_packages (conf, NULL);
  1796. + }
  1797. +
  1798. + write_status_files_if_changed(conf);
  1799. +
  1800. + return err;
  1801. +}
  1802. +
  1803. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf)
  1804. +{
  1805. + int i, err;
  1806. + char *globpattern;
  1807. + glob_t globbuf;
  1808. +
  1809. + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
  1810. + err = glob(globpattern, 0, NULL, &globbuf);
  1811. + free(globpattern);
  1812. + if (err) {
  1813. + return 0;
  1814. + }
  1815. +
  1816. + ipkg_message(conf, IPKG_NOTICE,
  1817. + "The following packages in %s will now be installed.\n",
  1818. + conf->pending_dir);
  1819. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1820. + ipkg_message(conf, IPKG_NOTICE,
  1821. + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
  1822. + }
  1823. + ipkg_message(conf, IPKG_NOTICE, "\n");
  1824. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1825. + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
  1826. + if (err == 0) {
  1827. + err = unlink(globbuf.gl_pathv[i]);
  1828. + if (err) {
  1829. + ipkg_message(conf, IPKG_ERROR,
  1830. + "%s: ERROR: failed to unlink %s: %s\n",
  1831. + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
  1832. + return err;
  1833. + }
  1834. + }
  1835. + }
  1836. + globfree(&globbuf);
  1837. +
  1838. + return err;
  1839. +}
  1840. +
  1841. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1842. +{
  1843. + int i,a,done;
  1844. + pkg_t *pkg;
  1845. + pkg_t *pkg_to_remove;
  1846. + pkg_vec_t *available;
  1847. + char *pkg_name = NULL;
  1848. + global_conf = conf;
  1849. + signal(SIGINT, sigint_handler);
  1850. +
  1851. +// ENH: Add the "no pkg removed" just in case.
  1852. +
  1853. + done = 0;
  1854. +
  1855. + available = pkg_vec_alloc();
  1856. + pkg_info_preinstall_check(conf);
  1857. + if ( argc > 0 ) {
  1858. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1859. + for (i=0; i < argc; i++) {
  1860. + pkg_name = malloc(strlen(argv[i])+2);
  1861. + strcpy(pkg_name,argv[i]);
  1862. + for (a=0; a < available->len; a++) {
  1863. + pkg = available->pkgs[a];
  1864. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1865. + continue;
  1866. + }
  1867. + if (conf->restrict_to_default_dest) {
  1868. + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1869. + pkg->name,
  1870. + conf->default_dest);
  1871. + } else {
  1872. + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
  1873. + }
  1874. +
  1875. + if (pkg == NULL) {
  1876. + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
  1877. + continue;
  1878. + }
  1879. + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
  1880. + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
  1881. + continue;
  1882. + }
  1883. + ipkg_remove_pkg(conf, pkg_to_remove,0);
  1884. + done = 1;
  1885. + }
  1886. + free (pkg_name);
  1887. + }
  1888. + pkg_vec_free(available);
  1889. + } else {
  1890. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  1891. + int flagged_pkg_count = 0;
  1892. + int removed;
  1893. +
  1894. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
  1895. +
  1896. + for (i = 0; i < installed_pkgs->len; i++) {
  1897. + pkg = installed_pkgs->pkgs[i];
  1898. + if (pkg->state_flag & SF_USER) {
  1899. + flagged_pkg_count++;
  1900. + } else {
  1901. + if (!pkg_has_installed_dependents(pkg, NULL))
  1902. + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
  1903. + }
  1904. + }
  1905. + if (!flagged_pkg_count) {
  1906. + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
  1907. + "so refusing to uninstall unflagged non-leaf packages\n");
  1908. + return 0;
  1909. + }
  1910. +
  1911. + /* find packages not flagged SF_USER (i.e., installed to
  1912. + * satisfy a dependence) and not having any dependents, and
  1913. + * remove them */
  1914. + do {
  1915. + removed = 0;
  1916. + for (i = 0; i < installed_pkgs->len; i++) {
  1917. + pkg = installed_pkgs->pkgs[i];
  1918. + if (!(pkg->state_flag & SF_USER)
  1919. + && !pkg_has_installed_dependents(pkg, NULL)) {
  1920. + removed++;
  1921. + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
  1922. + ipkg_remove_pkg(conf, pkg,0);
  1923. + done = 1;
  1924. + }
  1925. + }
  1926. + } while (removed);
  1927. + pkg_vec_free(installed_pkgs);
  1928. + }
  1929. +
  1930. + if ( done == 0 )
  1931. + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
  1932. +
  1933. + write_status_files_if_changed(conf);
  1934. + return 0;
  1935. +}
  1936. +
  1937. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1938. +{
  1939. + int i;
  1940. + pkg_t *pkg;
  1941. +
  1942. + global_conf = conf;
  1943. + signal(SIGINT, sigint_handler);
  1944. +
  1945. + pkg_info_preinstall_check(conf);
  1946. +
  1947. + for (i=0; i < argc; i++) {
  1948. + if (conf->restrict_to_default_dest) {
  1949. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1950. + argv[i],
  1951. + conf->default_dest);
  1952. + } else {
  1953. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1954. + }
  1955. +
  1956. + if (pkg == NULL) {
  1957. + ipkg_message(conf, IPKG_ERROR,
  1958. + "Package %s is not installed.\n", argv[i]);
  1959. + continue;
  1960. + }
  1961. + ipkg_purge_pkg(conf, pkg);
  1962. + }
  1963. +
  1964. + write_status_files_if_changed(conf);
  1965. + return 0;
  1966. +}
  1967. +
  1968. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1969. +{
  1970. + int i;
  1971. + pkg_t *pkg;
  1972. + char *flags = argv[0];
  1973. +
  1974. + global_conf = conf;
  1975. + signal(SIGINT, sigint_handler);
  1976. +
  1977. + for (i=1; i < argc; i++) {
  1978. + if (conf->restrict_to_default_dest) {
  1979. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1980. + argv[i],
  1981. + conf->default_dest);
  1982. + } else {
  1983. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1984. + }
  1985. +
  1986. + if (pkg == NULL) {
  1987. + ipkg_message(conf, IPKG_ERROR,
  1988. + "Package %s is not installed.\n", argv[i]);
  1989. + continue;
  1990. + }
  1991. + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
  1992. + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
  1993. + pkg->state_flag = pkg_state_flag_from_str(flags);
  1994. + }
  1995. +/* pb_ asked this feature 03292004 */
  1996. +/* Actually I will use only this two, but this is an open for various status */
  1997. + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
  1998. + pkg->state_status = pkg_state_status_from_str(flags);
  1999. + }
  2000. + ipkg_state_changed++;
  2001. + ipkg_message(conf, IPKG_NOTICE,
  2002. + "Setting flags for package %s to %s\n",
  2003. + pkg->name, flags);
  2004. + }
  2005. +
  2006. + write_status_files_if_changed(conf);
  2007. + return 0;
  2008. +}
  2009. +
  2010. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2011. +{
  2012. + pkg_t *pkg;
  2013. + str_list_t *installed_files;
  2014. + str_list_elt_t *iter;
  2015. + char *pkg_version;
  2016. + size_t buff_len = 8192;
  2017. + size_t used_len;
  2018. + char *buff ;
  2019. +
  2020. + buff = (char *)malloc(buff_len);
  2021. + if ( buff == NULL ) {
  2022. + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
  2023. + return ENOMEM;
  2024. + }
  2025. +
  2026. + if (argc < 1) {
  2027. + return EINVAL;
  2028. + }
  2029. +
  2030. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  2031. + argv[0]);
  2032. + if (pkg == NULL) {
  2033. + ipkg_message(conf, IPKG_ERROR,
  2034. + "Package %s not installed.\n", argv[0]);
  2035. + return 0;
  2036. + }
  2037. +
  2038. + installed_files = pkg_get_installed_files(pkg);
  2039. + pkg_version = pkg_version_str_alloc(pkg);
  2040. +
  2041. + printf("Package %s (%s) is installed on %s and has the following files:\n",
  2042. + pkg->name, pkg_version, pkg->dest->name);
  2043. + for (iter = installed_files->head; iter; iter = iter->next) {
  2044. + puts(iter->data);
  2045. + }
  2046. +
  2047. + free(pkg_version);
  2048. + pkg_free_installed_files(pkg);
  2049. +
  2050. + return 0;
  2051. +}
  2052. +
  2053. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2054. +{
  2055. +
  2056. + if (argc > 0) {
  2057. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2058. + const char *rel_str = "depends on";
  2059. + int i;
  2060. +
  2061. + pkg_info_preinstall_check(conf);
  2062. +
  2063. + if (conf->query_all)
  2064. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2065. + else
  2066. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2067. + for (i = 0; i < argc; i++) {
  2068. + const char *target = argv[i];
  2069. + int j;
  2070. +
  2071. + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
  2072. +
  2073. + for (j = 0; j < available_pkgs->len; j++) {
  2074. + pkg_t *pkg = available_pkgs->pkgs[j];
  2075. + if (fnmatch(target, pkg->name, 0) == 0) {
  2076. + int k;
  2077. + int count = pkg->depends_count + pkg->pre_depends_count;
  2078. + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
  2079. + target, pkg->architecture, rel_str);
  2080. + for (k = 0; k < count; k++) {
  2081. + compound_depend_t *cdepend = &pkg->depends[k];
  2082. + int l;
  2083. + for (l = 0; l < cdepend->possibility_count; l++) {
  2084. + depend_t *possibility = cdepend->possibilities[l];
  2085. + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
  2086. + if (conf->verbosity > 0) {
  2087. + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
  2088. + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
  2089. + if (possibility->version) {
  2090. + const char *typestr = NULL;
  2091. + switch (possibility->constraint) {
  2092. + case NONE: typestr = "none"; break;
  2093. + case EARLIER: typestr = "<"; break;
  2094. + case EARLIER_EQUAL: typestr = "<="; break;
  2095. + case EQUAL: typestr = "="; break;
  2096. + case LATER_EQUAL: typestr = ">="; break;
  2097. + case LATER: typestr = ">"; break;
  2098. + }
  2099. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2100. + }
  2101. + // free(ver);
  2102. + }
  2103. + ipkg_message(conf, IPKG_ERROR, "\n");
  2104. + }
  2105. + }
  2106. + }
  2107. + }
  2108. + }
  2109. + pkg_vec_free(available_pkgs);
  2110. + }
  2111. + return 0;
  2112. +}
  2113. +
  2114. +enum what_field_type {
  2115. + WHATDEPENDS,
  2116. + WHATCONFLICTS,
  2117. + WHATPROVIDES,
  2118. + WHATREPLACES,
  2119. + WHATRECOMMENDS,
  2120. + WHATSUGGESTS
  2121. +};
  2122. +
  2123. +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
  2124. +{
  2125. +
  2126. + if (argc > 0) {
  2127. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2128. + const char *rel_str = NULL;
  2129. + int i;
  2130. + int changed;
  2131. +
  2132. + switch (what_field_type) {
  2133. + case WHATDEPENDS: rel_str = "depends on"; break;
  2134. + case WHATCONFLICTS: rel_str = "conflicts with"; break;
  2135. + case WHATSUGGESTS: rel_str = "suggests"; break;
  2136. + case WHATRECOMMENDS: rel_str = "recommends"; break;
  2137. + case WHATPROVIDES: rel_str = "provides"; break;
  2138. + case WHATREPLACES: rel_str = "replaces"; break;
  2139. + }
  2140. +
  2141. + if (conf->query_all)
  2142. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2143. + else
  2144. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2145. +
  2146. + /* mark the root set */
  2147. + pkg_vec_clear_marks(available_pkgs);
  2148. + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
  2149. + for (i = 0; i < argc; i++) {
  2150. + const char *dependee_pattern = argv[i];
  2151. + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
  2152. + }
  2153. + for (i = 0; i < available_pkgs->len; i++) {
  2154. + pkg_t *pkg = available_pkgs->pkgs[i];
  2155. + if (pkg->state_flag & SF_MARKED) {
  2156. + /* mark the parent (abstract) package */
  2157. + pkg_mark_provides(pkg);
  2158. + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
  2159. + }
  2160. + }
  2161. +
  2162. + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
  2163. + do {
  2164. + int j;
  2165. + changed = 0;
  2166. +
  2167. + for (j = 0; j < available_pkgs->len; j++) {
  2168. + pkg_t *pkg = available_pkgs->pkgs[j];
  2169. + int k;
  2170. + int count = ((what_field_type == WHATCONFLICTS)
  2171. + ? pkg->conflicts_count
  2172. + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
  2173. + /* skip this package if it is already marked */
  2174. + if (pkg->parent->state_flag & SF_MARKED) {
  2175. + continue;
  2176. + }
  2177. + for (k = 0; k < count; k++) {
  2178. + compound_depend_t *cdepend =
  2179. + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
  2180. + int l;
  2181. + for (l = 0; l < cdepend->possibility_count; l++) {
  2182. + depend_t *possibility = cdepend->possibilities[l];
  2183. + if (possibility->pkg->state_flag & SF_MARKED) {
  2184. + /* mark the depending package so we won't visit it again */
  2185. + pkg->state_flag |= SF_MARKED;
  2186. + pkg_mark_provides(pkg);
  2187. + changed++;
  2188. +
  2189. + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
  2190. + if (conf->verbosity > 0) {
  2191. + char *ver = pkg_version_str_alloc(pkg);
  2192. + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
  2193. + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
  2194. + if (possibility->version) {
  2195. + const char *typestr = NULL;
  2196. + switch (possibility->constraint) {
  2197. + case NONE: typestr = "none"; break;
  2198. + case EARLIER: typestr = "<"; break;
  2199. + case EARLIER_EQUAL: typestr = "<="; break;
  2200. + case EQUAL: typestr = "="; break;
  2201. + case LATER_EQUAL: typestr = ">="; break;
  2202. + case LATER: typestr = ">"; break;
  2203. + }
  2204. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2205. + }
  2206. + free(ver);
  2207. + if (!pkg_dependence_satisfiable(possibility))
  2208. + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
  2209. + }
  2210. + ipkg_message(conf, IPKG_NOTICE, "\n");
  2211. + goto next_package;
  2212. + }
  2213. + }
  2214. + }
  2215. + next_package:
  2216. + ;
  2217. + }
  2218. + } while (changed && recursive);
  2219. + pkg_vec_free(available_pkgs);
  2220. + }
  2221. +
  2222. + return 0;
  2223. +}
  2224. +
  2225. +int pkg_mark_provides(pkg_t *pkg)
  2226. +{
  2227. + int provides_count = pkg->provides_count;
  2228. + abstract_pkg_t **provides = pkg->provides;
  2229. + int i;
  2230. + pkg->parent->state_flag |= SF_MARKED;
  2231. + for (i = 0; i < provides_count; i++) {
  2232. + provides[i]->state_flag |= SF_MARKED;
  2233. + }
  2234. + return 0;
  2235. +}
  2236. +
  2237. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2238. +{
  2239. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
  2240. +}
  2241. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2242. +{
  2243. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
  2244. +}
  2245. +
  2246. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2247. +{
  2248. + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
  2249. +}
  2250. +
  2251. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2252. +{
  2253. + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
  2254. +}
  2255. +
  2256. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2257. +{
  2258. + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
  2259. +}
  2260. +
  2261. +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
  2262. +{
  2263. +
  2264. + if (argc > 0) {
  2265. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2266. + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
  2267. + int i;
  2268. +
  2269. + pkg_info_preinstall_check(conf);
  2270. +
  2271. + if (conf->query_all)
  2272. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2273. + else
  2274. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2275. + for (i = 0; i < argc; i++) {
  2276. + const char *target = argv[i];
  2277. + int j;
  2278. +
  2279. + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
  2280. + rel_str, target);
  2281. + for (j = 0; j < available_pkgs->len; j++) {
  2282. + pkg_t *pkg = available_pkgs->pkgs[j];
  2283. + int k;
  2284. + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
  2285. + for (k = 0; k < count; k++) {
  2286. + abstract_pkg_t *apkg =
  2287. + ((what_field_type == WHATPROVIDES)
  2288. + ? pkg->provides[k]
  2289. + : pkg->replaces[k]);
  2290. + if (fnmatch(target, apkg->name, 0) == 0) {
  2291. + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
  2292. + if (strcmp(target, apkg->name) != 0)
  2293. + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
  2294. + ipkg_message(conf, IPKG_ERROR, "\n");
  2295. + }
  2296. + }
  2297. + }
  2298. + }
  2299. + pkg_vec_free(available_pkgs);
  2300. + }
  2301. + return 0;
  2302. +}
  2303. +
  2304. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2305. +{
  2306. + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
  2307. +}
  2308. +
  2309. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2310. +{
  2311. + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
  2312. +}
  2313. +
  2314. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2315. +{
  2316. + int i;
  2317. +
  2318. + pkg_vec_t *installed;
  2319. + pkg_t *pkg;
  2320. + str_list_t *installed_files;
  2321. + str_list_elt_t *iter;
  2322. + char *installed_file;
  2323. +
  2324. + if (argc < 1) {
  2325. + return EINVAL;
  2326. + }
  2327. +
  2328. + installed = pkg_vec_alloc();
  2329. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  2330. +
  2331. + for (i=0; i < installed->len; i++) {
  2332. + pkg = installed->pkgs[i];
  2333. +
  2334. + installed_files = pkg_get_installed_files(pkg);
  2335. +
  2336. + for (iter = installed_files->head; iter; iter = iter->next) {
  2337. + installed_file = iter->data;
  2338. + if (fnmatch(argv[0], installed_file, 0)==0) {
  2339. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2340. + installed_file,
  2341. + pkg_version_str_alloc(pkg),
  2342. + pkg->state_status, p_userdata);
  2343. + }
  2344. + }
  2345. +
  2346. + pkg_free_installed_files(pkg);
  2347. + }
  2348. +
  2349. + /* XXX: CLEANUP: It's not obvious from the name of
  2350. + pkg_hash_fetch_all_installed that we need to call
  2351. + pkg_vec_free to avoid a memory leak. */
  2352. + pkg_vec_free(installed);
  2353. +
  2354. + return 0;
  2355. +}
  2356. +
  2357. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2358. +{
  2359. + if (argc == 3) {
  2360. + /* this is a bit gross */
  2361. + struct pkg p1, p2;
  2362. + parseVersion(&p1, argv[0]);
  2363. + parseVersion(&p2, argv[2]);
  2364. + return pkg_version_satisfied(&p1, &p2, argv[1]);
  2365. + } else {
  2366. + ipkg_message(conf, IPKG_ERROR,
  2367. + "ipkg compare_versions <v1> <op> <v2>\n"
  2368. + "<op> is one of <= >= << >> =\n");
  2369. + return -1;
  2370. + }
  2371. +}
  2372. +
  2373. +#ifndef HOST_CPU_STR
  2374. +#define HOST_CPU_STR__(X) #X
  2375. +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
  2376. +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
  2377. +#endif
  2378. +
  2379. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf)
  2380. +{
  2381. + nv_pair_list_elt_t *l;
  2382. +
  2383. + l = conf->arch_list.head;
  2384. + while (l) {
  2385. + nv_pair_t *nv = l->data;
  2386. + printf("arch %s %s\n", nv->name, nv->value);
  2387. + l = l->next;
  2388. + }
  2389. + return 0;
  2390. +}
  2391. +
  2392. +
  2393. diff -Nur busybox-1.20.2.orig//archival/libipkg/ipkg_cmd.h busybox-1.20.2/archival/libipkg/ipkg_cmd.h
  2394. --- busybox-1.20.2.orig//archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
  2395. +++ busybox-1.20.2/archival/libipkg/ipkg_cmd.h 2013-01-31 16:44:31.000000000 +0100
  2396. @@ -0,0 +1,41 @@
  2397. +/* ipkg_cmd.h - the itsy package management system
  2398. +
  2399. + Carl D. Worth
  2400. +
  2401. + Copyright (C) 2001 University of Southern California
  2402. +
  2403. + This program is free software; you can redistribute it and/or
  2404. + modify it under the terms of the GNU General Public License as
  2405. + published by the Free Software Foundation; either version 2, or (at
  2406. + your option) any later version.
  2407. +
  2408. + This program is distributed in the hope that it will be useful, but
  2409. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2410. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2411. + General Public License for more details.
  2412. +*/
  2413. +
  2414. +#ifndef IPKG_CMD_H
  2415. +#define IPKG_CMD_H
  2416. +
  2417. +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
  2418. +
  2419. +struct ipkg_cmd
  2420. +{
  2421. + const char *name;
  2422. + int requires_args;
  2423. + ipkg_cmd_fun_t fun;
  2424. +};
  2425. +typedef struct ipkg_cmd ipkg_cmd_t;
  2426. +
  2427. +ipkg_cmd_t *ipkg_cmd_find(const char *name);
  2428. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
  2429. + const char **argv, void *userdata);
  2430. +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
  2431. +/* install any packges with state_want == SW_INSTALL */
  2432. +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
  2433. +/* ensure that all dependences are satisfied */
  2434. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
  2435. +int pkg_mark_provides(pkg_t *pkg);
  2436. +
  2437. +#endif
  2438. diff -Nur busybox-1.20.2.orig//archival/libipkg/ipkg_conf.c busybox-1.20.2/archival/libipkg/ipkg_conf.c
  2439. --- busybox-1.20.2.orig//archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
  2440. +++ busybox-1.20.2/archival/libipkg/ipkg_conf.c 2013-01-31 16:44:31.000000000 +0100
  2441. @@ -0,0 +1,711 @@
  2442. +/* ipkg_conf.c - the itsy package management system
  2443. +
  2444. + Carl D. Worth
  2445. +
  2446. + Copyright (C) 2001 University of Southern California
  2447. +
  2448. + This program is free software; you can redistribute it and/or
  2449. + modify it under the terms of the GNU General Public License as
  2450. + published by the Free Software Foundation; either version 2, or (at
  2451. + your option) any later version.
  2452. +
  2453. + This program is distributed in the hope that it will be useful, but
  2454. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2455. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2456. + General Public License for more details.
  2457. +*/
  2458. +
  2459. +#include <glob.h>
  2460. +
  2461. +#include "ipkg.h"
  2462. +#include "ipkg_conf.h"
  2463. +
  2464. +#include "xregex.h"
  2465. +#include "sprintf_alloc.h"
  2466. +#include "ipkg_conf.h"
  2467. +#include "ipkg_message.h"
  2468. +#include "file_util.h"
  2469. +#include "str_util.h"
  2470. +#include "xsystem.h"
  2471. +
  2472. +
  2473. +ipkg_conf_t *global_conf;
  2474. +
  2475. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2476. + pkg_src_list_t *pkg_src_list,
  2477. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2478. + char **tmp_lists_dir);
  2479. +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
  2480. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  2481. + const char *name, const char *value);
  2482. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2483. + const char *default_dest_name);
  2484. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
  2485. + pkg_src_list_t *nv_pair_list);
  2486. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
  2487. + nv_pair_list_t *nv_pair_list, char * lists_dir);
  2488. +
  2489. +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
  2490. +{
  2491. + ipkg_option_t tmp[] = {
  2492. + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
  2493. + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
  2494. + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
  2495. + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
  2496. + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
  2497. + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
  2498. + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
  2499. + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
  2500. + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
  2501. + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
  2502. + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
  2503. + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
  2504. + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
  2505. + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
  2506. + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
  2507. + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
  2508. + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
  2509. + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
  2510. + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
  2511. + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
  2512. + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
  2513. + { NULL }
  2514. + };
  2515. +
  2516. + *options = (ipkg_option_t *)malloc(sizeof(tmp));
  2517. + if ( options == NULL ){
  2518. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  2519. + return -1;
  2520. + }
  2521. +
  2522. + memcpy(*options, tmp, sizeof(tmp));
  2523. + return 0;
  2524. +};
  2525. +
  2526. +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
  2527. +{
  2528. + if (arg_str) {
  2529. + if (*conf_str) {
  2530. + free(*conf_str);
  2531. + }
  2532. + *conf_str = strdup(arg_str);
  2533. + }
  2534. +}
  2535. +
  2536. +static void ipkg_conf_free_string(char **conf_str)
  2537. +{
  2538. + if (*conf_str) {
  2539. + free(*conf_str);
  2540. + *conf_str = NULL;
  2541. + }
  2542. +}
  2543. +
  2544. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
  2545. +{
  2546. + int err;
  2547. + char *tmp_dir_base;
  2548. + nv_pair_list_t tmp_dest_nv_pair_list;
  2549. + char * lists_dir =NULL;
  2550. + glob_t globbuf;
  2551. + const char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
  2552. + char *pending_dir =NULL;
  2553. +
  2554. + memset(conf, 0, sizeof(ipkg_conf_t));
  2555. +
  2556. + pkg_src_list_init(&conf->pkg_src_list);
  2557. +
  2558. + nv_pair_list_init(&tmp_dest_nv_pair_list);
  2559. + pkg_dest_list_init(&conf->pkg_dest_list);
  2560. +
  2561. + nv_pair_list_init(&conf->arch_list);
  2562. +
  2563. + conf->restrict_to_default_dest = 0;
  2564. + conf->default_dest = NULL;
  2565. +
  2566. +
  2567. + if (args->tmp_dir)
  2568. + tmp_dir_base = args->tmp_dir;
  2569. + else
  2570. + tmp_dir_base = getenv("TMPDIR");
  2571. + sprintf_alloc(&conf->tmp_dir, "%s/%s",
  2572. + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
  2573. + IPKG_CONF_TMP_DIR_SUFFIX);
  2574. + conf->tmp_dir = mkdtemp(conf->tmp_dir);
  2575. + if (conf->tmp_dir == NULL) {
  2576. + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
  2577. + __FUNCTION__, conf->tmp_dir, strerror(errno));
  2578. + return errno;
  2579. + }
  2580. +
  2581. + conf->force_depends = 0;
  2582. + conf->force_defaults = 0;
  2583. + conf->force_overwrite = 0;
  2584. + conf->force_downgrade = 0;
  2585. + conf->force_reinstall = 0;
  2586. + conf->force_space = 0;
  2587. + conf->force_removal_of_essential_packages = 0;
  2588. + conf->force_removal_of_dependent_packages = 0;
  2589. + conf->nodeps = 0;
  2590. + conf->verbose_wget = 0;
  2591. + conf->offline_root = NULL;
  2592. + conf->offline_root_pre_script_cmd = NULL;
  2593. + conf->offline_root_post_script_cmd = NULL;
  2594. + conf->multiple_providers = 0;
  2595. + conf->verbosity = 1;
  2596. + conf->noaction = 0;
  2597. +
  2598. + conf->http_proxy = NULL;
  2599. + conf->ftp_proxy = NULL;
  2600. + conf->no_proxy = NULL;
  2601. + conf->proxy_user = NULL;
  2602. + conf->proxy_passwd = NULL;
  2603. +
  2604. + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2605. + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2606. + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2607. + lists_dir=(char *)malloc(1);
  2608. + lists_dir[0]='\0';
  2609. + if (args->conf_file) {
  2610. + struct stat stat_buf;
  2611. + err = stat(args->conf_file, &stat_buf);
  2612. + if (err == 0)
  2613. + if (ipkg_conf_parse_file(conf, args->conf_file,
  2614. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2615. + /* Memory leakage from ipkg_conf_parse-file */
  2616. + return -1;
  2617. + }
  2618. +
  2619. + }
  2620. +
  2621. + /* if (!lists_dir ){*/
  2622. + if (strlen(lists_dir)<=1 ){
  2623. + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
  2624. + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
  2625. + }
  2626. +
  2627. + if (args->offline_root) {
  2628. + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
  2629. + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
  2630. + free(lists_dir);
  2631. + lists_dir = tmp;
  2632. + }
  2633. +
  2634. + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
  2635. + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
  2636. +
  2637. + conf->lists_dir = strdup(lists_dir);
  2638. + conf->pending_dir = strdup(pending_dir);
  2639. +
  2640. + if (args->offline_root)
  2641. + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
  2642. + memset(&globbuf, 0, sizeof(globbuf));
  2643. + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
  2644. + if (!err) {
  2645. + int i;
  2646. + for (i = 0; i < globbuf.gl_pathc; i++) {
  2647. + if (globbuf.gl_pathv[i])
  2648. + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
  2649. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2650. + /* Memory leakage from ipkg_conf_parse-file */
  2651. + return -1;
  2652. + }
  2653. + }
  2654. + }
  2655. + globfree(&globbuf);
  2656. +
  2657. + /* if no architectures were defined, then default all, noarch, and host architecture */
  2658. + if (nv_pair_list_empty(&conf->arch_list)) {
  2659. + nv_pair_list_append(&conf->arch_list, "all", "1");
  2660. + nv_pair_list_append(&conf->arch_list, "noarch", "1");
  2661. + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
  2662. + }
  2663. +
  2664. + /* Even if there is no conf file, we'll need at least one dest. */
  2665. + if (tmp_dest_nv_pair_list.head == NULL) {
  2666. + nv_pair_list_append(&tmp_dest_nv_pair_list,
  2667. + IPKG_CONF_DEFAULT_DEST_NAME,
  2668. + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
  2669. + }
  2670. +
  2671. + /* After parsing the file, set options from command-line, (so that
  2672. + command-line arguments take precedence) */
  2673. + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
  2674. + really needs to be cleaned up. There is so much duplication
  2675. + right now it is ridiculous. Maybe ipkg_conf_t should just save
  2676. + a pointer to args_t (which could then not be freed), rather
  2677. + than duplicating every field here? */
  2678. + if (args->force_depends) {
  2679. + conf->force_depends = 1;
  2680. + }
  2681. + if (args->force_defaults) {
  2682. + conf->force_defaults = 1;
  2683. + }
  2684. + if (args->force_overwrite) {
  2685. + conf->force_overwrite = 1;
  2686. + }
  2687. + if (args->force_downgrade) {
  2688. + conf->force_downgrade = 1;
  2689. + }
  2690. + if (args->force_reinstall) {
  2691. + conf->force_reinstall = 1;
  2692. + }
  2693. + if (args->force_removal_of_dependent_packages) {
  2694. + conf->force_removal_of_dependent_packages = 1;
  2695. + }
  2696. + if (args->force_removal_of_essential_packages) {
  2697. + conf->force_removal_of_essential_packages = 1;
  2698. + }
  2699. + if (args->nodeps) {
  2700. + conf->nodeps = 1;
  2701. + }
  2702. + if (args->noaction) {
  2703. + conf->noaction = 1;
  2704. + }
  2705. + if (args->query_all) {
  2706. + conf->query_all = 1;
  2707. + }
  2708. + if (args->verbose_wget) {
  2709. + conf->verbose_wget = 1;
  2710. + }
  2711. + if (args->multiple_providers) {
  2712. + conf->multiple_providers = 1;
  2713. + }
  2714. + if (args->verbosity != conf->verbosity) {
  2715. + conf->verbosity = args->verbosity;
  2716. + }
  2717. +
  2718. + ipkg_conf_override_string(&conf->offline_root,
  2719. + args->offline_root);
  2720. + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
  2721. + args->offline_root_pre_script_cmd);
  2722. + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
  2723. + args->offline_root_post_script_cmd);
  2724. +
  2725. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  2726. + read anything from there.
  2727. +*/
  2728. + if ( !(args->nocheckfordirorfile)){
  2729. + /* need to run load the source list before dest list -Jamey */
  2730. + if ( !(args->noreadfeedsfile))
  2731. + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
  2732. +
  2733. + /* Now that we have resolved conf->offline_root, we can commit to
  2734. + the directory names for the dests and load in all the package
  2735. + lists. */
  2736. + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
  2737. +
  2738. + if (args->dest) {
  2739. + err = ipkg_conf_set_default_dest(conf, args->dest);
  2740. + if (err) {
  2741. + return err;
  2742. + }
  2743. + }
  2744. + }
  2745. + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
  2746. + free(lists_dir);
  2747. + free(pending_dir);
  2748. +
  2749. + return 0;
  2750. +}
  2751. +
  2752. +void ipkg_conf_deinit(ipkg_conf_t *conf)
  2753. +{
  2754. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  2755. +#error
  2756. + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
  2757. + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  2758. + __FUNCTION__, conf->tmp_dir);
  2759. +#else
  2760. + int err;
  2761. +
  2762. + err = rmdir(conf->tmp_dir);
  2763. + if (err) {
  2764. + if (errno == ENOTEMPTY) {
  2765. + char *cmd;
  2766. + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
  2767. + err = xsystem(cmd);
  2768. + free(cmd);
  2769. + }
  2770. + if (err)
  2771. + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
  2772. + }
  2773. +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
  2774. +
  2775. + free(conf->tmp_dir); /*XXX*/
  2776. +
  2777. + pkg_src_list_deinit(&conf->pkg_src_list);
  2778. + pkg_dest_list_deinit(&conf->pkg_dest_list);
  2779. + nv_pair_list_deinit(&conf->arch_list);
  2780. + if (&conf->pkg_hash)
  2781. + pkg_hash_deinit(&conf->pkg_hash);
  2782. + if (&conf->file_hash)
  2783. + hash_table_deinit(&conf->file_hash);
  2784. + if (&conf->obs_file_hash)
  2785. + hash_table_deinit(&conf->obs_file_hash);
  2786. +
  2787. + ipkg_conf_free_string(&conf->offline_root);
  2788. + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
  2789. + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
  2790. +
  2791. + if (conf->verbosity > 1) {
  2792. + int i;
  2793. + hash_table_t *hashes[] = {
  2794. + &conf->pkg_hash,
  2795. + &conf->file_hash,
  2796. + &conf->obs_file_hash };
  2797. + for (i = 0; i < 3; i++) {
  2798. + hash_table_t *hash = hashes[i];
  2799. + int c = 0;
  2800. + int n_conflicts = 0;
  2801. + int j;
  2802. + for (j = 0; j < hash->n_entries; j++) {
  2803. + int len = 0;
  2804. + hash_entry_t *e = &hash->entries[j];
  2805. + if (e->next)
  2806. + n_conflicts++;
  2807. + while (e && e->key) {
  2808. + len++;
  2809. + e = e->next;
  2810. + }
  2811. + if (len > c)
  2812. + c = len;
  2813. + }
  2814. + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
  2815. + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
  2816. + hash_table_deinit(hash);
  2817. + }
  2818. + }
  2819. +}
  2820. +
  2821. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2822. + const char *default_dest_name)
  2823. +{
  2824. + pkg_dest_list_elt_t *iter;
  2825. + pkg_dest_t *dest;
  2826. +
  2827. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  2828. + dest = iter->data;
  2829. + if (strcmp(dest->name, default_dest_name) == 0) {
  2830. + conf->default_dest = dest;
  2831. + conf->restrict_to_default_dest = 1;
  2832. + return 0;
  2833. + }
  2834. + }
  2835. +
  2836. + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
  2837. +
  2838. + return 1;
  2839. +}
  2840. +
  2841. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
  2842. +{
  2843. + pkg_src_list_elt_t *iter;
  2844. + pkg_src_t *src;
  2845. + char *list_file;
  2846. +
  2847. + for (iter = pkg_src_list->head; iter; iter = iter->next) {
  2848. + src = iter->data;
  2849. + if (src == NULL) {
  2850. + continue;
  2851. + }
  2852. +
  2853. + sprintf_alloc(&list_file, "%s/%s",
  2854. + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
  2855. + src->name);
  2856. +
  2857. + if (file_exists(list_file)) {
  2858. + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
  2859. + }
  2860. + free(list_file);
  2861. + }
  2862. +
  2863. + return 0;
  2864. +}
  2865. +
  2866. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
  2867. +{
  2868. + nv_pair_list_elt_t *iter;
  2869. + nv_pair_t *nv_pair;
  2870. + pkg_dest_t *dest;
  2871. + char *root_dir;
  2872. +
  2873. + for (iter = nv_pair_list->head; iter; iter = iter->next) {
  2874. + nv_pair = iter->data;
  2875. +
  2876. + if (conf->offline_root) {
  2877. + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
  2878. + } else {
  2879. + root_dir = strdup(nv_pair->value);
  2880. + }
  2881. + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
  2882. + free(root_dir);
  2883. + if (dest == NULL) {
  2884. + continue;
  2885. + }
  2886. + if (conf->default_dest == NULL) {
  2887. + conf->default_dest = dest;
  2888. + }
  2889. + if (file_exists(dest->status_file_name)) {
  2890. + pkg_hash_add_from_file(conf, dest->status_file_name,
  2891. + NULL, dest, 1);
  2892. + }
  2893. + }
  2894. +
  2895. + return 0;
  2896. +}
  2897. +
  2898. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2899. + pkg_src_list_t *pkg_src_list,
  2900. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2901. + char **lists_dir)
  2902. +{
  2903. + ipkg_option_t * options;
  2904. + FILE *file = fopen(filename, "r");
  2905. + regex_t valid_line_re, comment_re;
  2906. +#define regmatch_size 12
  2907. + regmatch_t regmatch[regmatch_size];
  2908. +
  2909. + if (ipkg_init_options_array(conf, &options)<0)
  2910. + return ENOMEM;
  2911. +
  2912. + if (file == NULL) {
  2913. + fprintf(stderr, "%s: failed to open %s: %s\n",
  2914. + __FUNCTION__, filename, strerror(errno));
  2915. + free(options);
  2916. + return errno;
  2917. + }
  2918. + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
  2919. +
  2920. + xregcomp(&comment_re,
  2921. + "^[[:space:]]*(#.*|[[:space:]]*)$",
  2922. + REG_EXTENDED);
  2923. + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
  2924. +
  2925. + while(1) {
  2926. + int line_num = 0;
  2927. + char *line;
  2928. + char *type, *name, *value, *extra;
  2929. +
  2930. + line = file_read_line_alloc(file);
  2931. + line_num++;
  2932. + if (line == NULL) {
  2933. + break;
  2934. + }
  2935. +
  2936. + str_chomp(line);
  2937. +
  2938. + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
  2939. + goto NEXT_LINE;
  2940. + }
  2941. +
  2942. + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
  2943. + str_chomp(line);
  2944. + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
  2945. + filename, line_num, line);
  2946. + goto NEXT_LINE;
  2947. + }
  2948. +
  2949. + /* This has to be so ugly to deal with optional quotation marks */
  2950. + if (regmatch[2].rm_so > 0) {
  2951. + type = strndup(line + regmatch[2].rm_so,
  2952. + regmatch[2].rm_eo - regmatch[2].rm_so);
  2953. + } else {
  2954. + type = strndup(line + regmatch[3].rm_so,
  2955. + regmatch[3].rm_eo - regmatch[3].rm_so);
  2956. + }
  2957. + if (regmatch[5].rm_so > 0) {
  2958. + name = strndup(line + regmatch[5].rm_so,
  2959. + regmatch[5].rm_eo - regmatch[5].rm_so);
  2960. + } else {
  2961. + name = strndup(line + regmatch[6].rm_so,
  2962. + regmatch[6].rm_eo - regmatch[6].rm_so);
  2963. + }
  2964. + if (regmatch[8].rm_so > 0) {
  2965. + value = strndup(line + regmatch[8].rm_so,
  2966. + regmatch[8].rm_eo - regmatch[8].rm_so);
  2967. + } else {
  2968. + value = strndup(line + regmatch[9].rm_so,
  2969. + regmatch[9].rm_eo - regmatch[9].rm_so);
  2970. + }
  2971. + extra = NULL;
  2972. + if (regmatch[11].rm_so > 0) {
  2973. + extra = strndup (line + regmatch[11].rm_so,
  2974. + regmatch[11].rm_eo - regmatch[11].rm_so);
  2975. + }
  2976. +
  2977. + /* We use the tmp_dest_nv_pair_list below instead of
  2978. + conf->pkg_dest_list because we might encounter an
  2979. + offline_root option later and that would invalidate the
  2980. + directories we would have computed in
  2981. + pkg_dest_list_init. (We do a similar thing with
  2982. + tmp_src_nv_pair_list for sake of symmetry.) */
  2983. + if (strcmp(type, "option") == 0) {
  2984. + ipkg_conf_set_option(options, name, value);
  2985. + } else if (strcmp(type, "src") == 0) {
  2986. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  2987. + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
  2988. + } else {
  2989. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  2990. + name, value);
  2991. + }
  2992. + } else if (strcmp(type, "src/gz") == 0) {
  2993. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  2994. + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
  2995. + } else {
  2996. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  2997. + name, value);
  2998. + }
  2999. + } else if (strcmp(type, "dest") == 0) {
  3000. + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
  3001. + } else if (strcmp(type, "lists_dir") == 0) {
  3002. + *lists_dir = realloc(*lists_dir,strlen(value)+1);
  3003. + if (*lists_dir == NULL) {
  3004. + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
  3005. + free(options);
  3006. + return EINVAL;
  3007. + }
  3008. + sprintf (*lists_dir,"%s",value);
  3009. + } else if (strcmp(type, "arch") == 0) {
  3010. + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
  3011. + if (!value) {
  3012. + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
  3013. + value = strdup("10");
  3014. + }
  3015. + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
  3016. + } else {
  3017. + fprintf(stderr, "WARNING: Ignoring unknown configuration "
  3018. + "parameter: %s %s %s\n", type, name, value);
  3019. + free(options);
  3020. + return EINVAL;
  3021. + }
  3022. +
  3023. + free(type);
  3024. + free(name);
  3025. + free(value);
  3026. + if (extra)
  3027. + free (extra);
  3028. +
  3029. + NEXT_LINE:
  3030. + free(line);
  3031. + }
  3032. +
  3033. + free(options);
  3034. + regfree(&comment_re);
  3035. + regfree(&valid_line_re);
  3036. + fclose(file);
  3037. +
  3038. + return 0;
  3039. +}
  3040. +
  3041. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  3042. + const char *name, const char *value)
  3043. +{
  3044. + int i = 0;
  3045. + while (options[i].name) {
  3046. + if (strcmp(options[i].name, name) == 0) {
  3047. + switch (options[i].type) {
  3048. + case IPKG_OPT_TYPE_BOOL:
  3049. + *((int *)options[i].value) = 1;
  3050. + return 0;
  3051. + case IPKG_OPT_TYPE_INT:
  3052. + if (value) {
  3053. + *((int *)options[i].value) = atoi(value);
  3054. + return 0;
  3055. + } else {
  3056. + printf("%s: Option %s need an argument\n",
  3057. + __FUNCTION__, name);
  3058. + return EINVAL;
  3059. + }
  3060. + case IPKG_OPT_TYPE_STRING:
  3061. + if (value) {
  3062. + *((char **)options[i].value) = strdup(value);
  3063. + return 0;
  3064. + } else {
  3065. + printf("%s: Option %s need an argument\n",
  3066. + __FUNCTION__, name);
  3067. + return EINVAL;
  3068. + }
  3069. + }
  3070. + }
  3071. + i++;
  3072. + }
  3073. +
  3074. + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
  3075. + __FUNCTION__, name, value);
  3076. + return EINVAL;
  3077. +}
  3078. +
  3079. +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
  3080. +{
  3081. + pkg_dest_list_elt_t *iter;
  3082. + pkg_dest_t *dest;
  3083. + pkg_vec_t *all;
  3084. + pkg_t *pkg;
  3085. + register int i;
  3086. + int err;
  3087. +
  3088. + if (conf->noaction)
  3089. + return 0;
  3090. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3091. + dest = iter->data;
  3092. + dest->status_file = fopen(dest->status_file_tmp_name, "w");
  3093. + if (dest->status_file == NULL) {
  3094. + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
  3095. + __FUNCTION__, dest->status_file_name, strerror(errno));
  3096. + }
  3097. + }
  3098. +
  3099. + all = pkg_vec_alloc();
  3100. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  3101. +
  3102. + for(i = 0; i < all->len; i++) {
  3103. + pkg = all->pkgs[i];
  3104. + /* We don't need most uninstalled packages in the status file */
  3105. + if (pkg->state_status == SS_NOT_INSTALLED
  3106. + && (pkg->state_want == SW_UNKNOWN
  3107. + || pkg->state_want == SW_DEINSTALL
  3108. + || pkg->state_want == SW_PURGE)) {
  3109. + continue;
  3110. + }
  3111. + if (!pkg) {
  3112. + fprintf(stderr, "Null package\n");
  3113. + }
  3114. + if (pkg->dest == NULL) {
  3115. + fprintf(stderr, "%s: ERROR: Can't write status for "
  3116. + "package %s since it has a NULL dest\n",
  3117. + __FUNCTION__, pkg->name);
  3118. + continue;
  3119. + }
  3120. + if (pkg->dest->status_file) {
  3121. + pkg_print_status(pkg, pkg->dest->status_file);
  3122. + }
  3123. + }
  3124. +
  3125. + pkg_vec_free(all);
  3126. +
  3127. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3128. + dest = iter->data;
  3129. + if (dest->status_file) {
  3130. + err = ferror(dest->status_file);
  3131. + fclose(dest->status_file);
  3132. + dest->status_file = NULL;
  3133. + if (!err) {
  3134. + file_move(dest->status_file_tmp_name, dest->status_file_name);
  3135. + } else {
  3136. + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
  3137. + "retaining old %s\n", __FUNCTION__,
  3138. + dest->status_file_tmp_name, dest->status_file_name);
  3139. + }
  3140. + }
  3141. + }
  3142. +
  3143. + return 0;
  3144. +}
  3145. +
  3146. +
  3147. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
  3148. +{
  3149. + char *root_filename;
  3150. + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
  3151. + return root_filename;
  3152. +}
  3153. diff -Nur busybox-1.20.2.orig//archival/libipkg/ipkg_conf.h busybox-1.20.2/archival/libipkg/ipkg_conf.h
  3154. --- busybox-1.20.2.orig//archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
  3155. +++ busybox-1.20.2/archival/libipkg/ipkg_conf.h 2013-01-31 16:44:31.000000000 +0100
  3156. @@ -0,0 +1,107 @@
  3157. +/* ipkg_conf.h - the itsy package management system
  3158. +
  3159. + Carl D. Worth
  3160. +
  3161. + Copyright (C) 2001 University of Southern California
  3162. +
  3163. + This program is free software; you can redistribute it and/or
  3164. + modify it under the terms of the GNU General Public License as
  3165. + published by the Free Software Foundation; either version 2, or (at
  3166. + your option) any later version.
  3167. +
  3168. + This program is distributed in the hope that it will be useful, but
  3169. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3170. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3171. + General Public License for more details.
  3172. +*/
  3173. +
  3174. +#ifndef IPKG_CONF_H
  3175. +#define IPKG_CONF_H
  3176. +
  3177. +typedef struct ipkg_conf ipkg_conf_t;
  3178. +
  3179. +#include "hash_table.h"
  3180. +#include "ipkg.h"
  3181. +#include "args.h"
  3182. +#include "pkg.h"
  3183. +#include "pkg_hash.h"
  3184. +#include "pkg_src_list.h"
  3185. +#include "pkg_dest_list.h"
  3186. +#include "nv_pair_list.h"
  3187. +
  3188. +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
  3189. +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
  3190. +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
  3191. +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
  3192. +
  3193. +/* In case the config file defines no dest */
  3194. +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
  3195. +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
  3196. +
  3197. +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
  3198. +
  3199. +struct ipkg_conf
  3200. +{
  3201. + pkg_src_list_t pkg_src_list;
  3202. + pkg_dest_list_t pkg_dest_list;
  3203. + nv_pair_list_t arch_list;
  3204. +
  3205. + int restrict_to_default_dest;
  3206. + pkg_dest_t *default_dest;
  3207. +
  3208. + char *tmp_dir;
  3209. + char *lists_dir;
  3210. + char *pending_dir;
  3211. +
  3212. + /* options */
  3213. + int force_depends;
  3214. + int force_defaults;
  3215. + int force_overwrite;
  3216. + int force_downgrade;
  3217. + int force_reinstall;
  3218. + int force_space;
  3219. + int force_removal_of_dependent_packages;
  3220. + int force_removal_of_essential_packages;
  3221. + int nodeps; /* do not follow dependences */
  3222. + int verbose_wget;
  3223. + int multiple_providers;
  3224. + char *offline_root;
  3225. + char *offline_root_pre_script_cmd;
  3226. + char *offline_root_post_script_cmd;
  3227. + int query_all;
  3228. + int verbosity;
  3229. + int noaction;
  3230. +
  3231. + /* proxy options */
  3232. + char *http_proxy;
  3233. + char *ftp_proxy;
  3234. + char *no_proxy;
  3235. + char *proxy_user;
  3236. + char *proxy_passwd;
  3237. +
  3238. + hash_table_t pkg_hash;
  3239. + hash_table_t file_hash;
  3240. + hash_table_t obs_file_hash;
  3241. +};
  3242. +
  3243. +enum ipkg_option_type {
  3244. + IPKG_OPT_TYPE_BOOL,
  3245. + IPKG_OPT_TYPE_INT,
  3246. + IPKG_OPT_TYPE_STRING
  3247. +};
  3248. +typedef enum ipkg_option_type ipkg_option_type_t;
  3249. +
  3250. +typedef struct ipkg_option ipkg_option_t;
  3251. +struct ipkg_option {
  3252. + const char *name;
  3253. + const ipkg_option_type_t type;
  3254. + const void *value;
  3255. +};
  3256. +
  3257. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
  3258. +void ipkg_conf_deinit(ipkg_conf_t *conf);
  3259. +
  3260. +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
  3261. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
  3262. +
  3263. +#endif
  3264. diff -Nur busybox-1.20.2.orig//archival/libipkg/ipkg_configure.c busybox-1.20.2/archival/libipkg/ipkg_configure.c
  3265. --- busybox-1.20.2.orig//archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
  3266. +++ busybox-1.20.2/archival/libipkg/ipkg_configure.c 2013-01-31 16:44:31.000000000 +0100
  3267. @@ -0,0 +1,40 @@
  3268. +/* ipkg_configure.c - the itsy package management system
  3269. +
  3270. + Carl D. Worth
  3271. +
  3272. + Copyright (C) 2001 University of Southern California
  3273. +
  3274. + This program is free software; you can redistribute it and/or
  3275. + modify it under the terms of the GNU General Public License as
  3276. + published by the Free Software Foundation; either version 2, or (at
  3277. + your option) any later version.
  3278. +
  3279. + This program is distributed in the hope that it will be useful, but
  3280. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3281. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3282. + General Public License for more details.
  3283. +*/
  3284. +
  3285. +#include "ipkg.h"
  3286. +
  3287. +#include "ipkg_configure.h"
  3288. +
  3289. +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
  3290. +{
  3291. + int err;
  3292. +
  3293. + /* DPKG_INCOMPATIBILITY:
  3294. + dpkg actually does some conffile handling here, rather than at the
  3295. + end of ipkg_install(). Do we care? */
  3296. + /* DPKG_INCOMPATIBILITY:
  3297. + dpkg actually includes a version number to this script call */
  3298. + err = pkg_run_script(conf, pkg, "postinst", "configure");
  3299. + if (err) {
  3300. + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
  3301. + return err;
  3302. + }
  3303. +
  3304. + ipkg_state_changed++;
  3305. + return 0;
  3306. +}
  3307. +
  3308. diff -Nur busybox-1.20.2.orig//archival/libipkg/ipkg_configure.h busybox-1.20.2/archival/libipkg/ipkg_configure.h
  3309. --- busybox-1.20.2.orig//archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
  3310. +++ busybox-1.20.2/archival/libipkg/ipkg_configure.h 2013-01-31 16:44:31.000000000 +0100
  3311. @@ -0,0 +1,25 @@
  3312. +/* ipkg_configure.h - the itsy package management system
  3313. +
  3314. + Carl D. Worth
  3315. +
  3316. + Copyright (C) 2001 University of Southern California
  3317. +
  3318. + This program is free software; you can redistribute it and/or
  3319. + modify it under the terms of the GNU General Public License as
  3320. + published by the Free Software Foundation; either version 2, or (at
  3321. + your option) any later version.
  3322. +
  3323. + This program is distributed in the hope that it will be useful, but
  3324. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3325. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3326. + General Public License for more details.
  3327. +*/
  3328. +
  3329. +#ifndef IPKG_CONFIGURE_H
  3330. +#define IPKG_CONFIGURE_H
  3331. +
  3332. +#include "ipkg_conf.h"
  3333. +
  3334. +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
  3335. +
  3336. +#endif
  3337. diff -Nur busybox-1.20.2.orig//archival/libipkg/ipkg_download.c busybox-1.20.2/archival/libipkg/ipkg_download.c
  3338. --- busybox-1.20.2.orig//archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
  3339. +++ busybox-1.20.2/archival/libipkg/ipkg_download.c 2013-01-31 16:44:31.000000000 +0100
  3340. @@ -0,0 +1,195 @@
  3341. +/* ipkg_download.c - the itsy package management system
  3342. +
  3343. + Carl D. Worth
  3344. +
  3345. + Copyright (C) 2001 University of Southern California
  3346. +
  3347. + This program is free software; you can redistribute it and/or
  3348. + modify it under the terms of the GNU General Public License as
  3349. + published by the Free Software Foundation; either version 2, or (at
  3350. + your option) any later version.
  3351. +
  3352. + This program is distributed in the hope that it will be useful, but
  3353. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3354. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3355. + General Public License for more details.
  3356. +*/
  3357. +
  3358. +#include "ipkg.h"
  3359. +#include "ipkg_download.h"
  3360. +#include "ipkg_message.h"
  3361. +
  3362. +#include "sprintf_alloc.h"
  3363. +#include "xsystem.h"
  3364. +#include "file_util.h"
  3365. +#include "str_util.h"
  3366. +
  3367. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
  3368. +{
  3369. + int err = 0;
  3370. +
  3371. + char *src_basec = strdup(src);
  3372. + char *src_base = bb_basename(src_basec);
  3373. + char *tmp_file_location;
  3374. + char *cmd;
  3375. +
  3376. + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
  3377. +
  3378. + fflush(stdout);
  3379. +
  3380. + if (str_starts_with(src, "file:")) {
  3381. + int ret;
  3382. + const char *file_src = src + 5;
  3383. + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
  3384. + ret = file_copy(src + 5, dest_file_name);
  3385. + ipkg_message(conf,IPKG_INFO,"Done.\n");
  3386. + return ret;
  3387. + }
  3388. +
  3389. + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
  3390. + err = unlink(tmp_file_location);
  3391. + if (err && errno != ENOENT) {
  3392. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
  3393. + __FUNCTION__, tmp_file_location, strerror(errno));
  3394. + free(tmp_file_location);
  3395. + return errno;
  3396. + }
  3397. +
  3398. + if (conf->http_proxy) {
  3399. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
  3400. + setenv("http_proxy", conf->http_proxy, 1);
  3401. + }
  3402. + if (conf->ftp_proxy) {
  3403. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
  3404. + setenv("ftp_proxy", conf->ftp_proxy, 1);
  3405. + }
  3406. + if (conf->no_proxy) {
  3407. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
  3408. + setenv("no_proxy", conf->no_proxy, 1);
  3409. + }
  3410. +
  3411. + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
  3412. + sprintf_alloc(&cmd, "wget %s %s%s %s%s %s -P %s %s",
  3413. + (conf->http_proxy || conf->ftp_proxy) ? "-Y on" : "",
  3414. + conf->proxy_user ? "--proxy-user=" : "",
  3415. + conf->proxy_user ? conf->proxy_user : "",
  3416. + conf->proxy_passwd ? "--proxy-passwd=" : "",
  3417. + conf->proxy_passwd ? conf->proxy_passwd : "",
  3418. + conf->verbose_wget ? "" : "-q",
  3419. + conf->tmp_dir,
  3420. + src);
  3421. + err = xsystem(cmd);
  3422. + if (err) {
  3423. + if (err != -1) {
  3424. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
  3425. + __FUNCTION__, err, cmd);
  3426. + }
  3427. + unlink(tmp_file_location);
  3428. + free(tmp_file_location);
  3429. + free(src_basec);
  3430. + free(cmd);
  3431. + return EINVAL;
  3432. + }
  3433. + free(cmd);
  3434. +
  3435. + err = file_move(tmp_file_location, dest_file_name);
  3436. +
  3437. + free(tmp_file_location);
  3438. + free(src_basec);
  3439. +
  3440. + if (err) {
  3441. + return err;
  3442. + }
  3443. +
  3444. + return 0;
  3445. +}
  3446. +
  3447. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
  3448. +{
  3449. + int err;
  3450. + char *url;
  3451. +
  3452. + if (pkg->src == NULL) {
  3453. + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
  3454. + pkg->name, pkg->parent->name);
  3455. + return -1;
  3456. + }
  3457. +
  3458. + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
  3459. +
  3460. + /* XXX: BUG: The pkg->filename might be something like
  3461. + "../../foo.ipk". While this is correct, and exactly what we
  3462. + want to use to construct url above, here we actually need to
  3463. + use just the filename part, without any directory. */
  3464. + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
  3465. +
  3466. + err = ipkg_download(conf, url, pkg->local_filename);
  3467. + free(url);
  3468. +
  3469. + return err;
  3470. +}
  3471. +
  3472. +/*
  3473. + * Downloads file from url, installs in package database, return package name.
  3474. + */
  3475. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
  3476. +{
  3477. + int err = 0;
  3478. + pkg_t *pkg;
  3479. + pkg = pkg_new();
  3480. + if (pkg == NULL)
  3481. + return ENOMEM;
  3482. +
  3483. + if (str_starts_with(url, "http://")
  3484. + || str_starts_with(url, "ftp://")) {
  3485. + char *tmp_file;
  3486. + char *file_basec = strdup(url);
  3487. + char *file_base = bb_basename(file_basec);
  3488. +
  3489. + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
  3490. + err = ipkg_download(conf, url, tmp_file);
  3491. + if (err)
  3492. + return err;
  3493. +
  3494. + err = pkg_init_from_file(pkg, tmp_file);
  3495. + if (err)
  3496. + return err;
  3497. + pkg->local_filename = strdup(tmp_file);
  3498. +
  3499. + free(tmp_file);
  3500. + free(file_basec);
  3501. +
  3502. + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
  3503. + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
  3504. +
  3505. + err = pkg_init_from_file(pkg, url);
  3506. + if (err)
  3507. + return err;
  3508. + pkg->local_filename = strdup(url);
  3509. + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
  3510. + pkg->provided_by_hand = 1;
  3511. +
  3512. + } else {
  3513. + pkg_deinit(pkg);
  3514. + free(pkg);
  3515. + return 0;
  3516. + }
  3517. +
  3518. + if (!pkg->architecture) {
  3519. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3520. + return -EINVAL;
  3521. + }
  3522. +
  3523. + pkg->dest = conf->default_dest;
  3524. + pkg->state_want = SW_INSTALL;
  3525. + pkg->state_flag |= SF_PREFER;
  3526. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3527. + if ( pkg == NULL ){
  3528. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  3529. + return 0;
  3530. + }
  3531. + if (namep) {
  3532. + *namep = strdup(pkg->name);
  3533. + }
  3534. + return 0;
  3535. +}
  3536. diff -Nur busybox-1.20.2.orig//archival/libipkg/ipkg_download.h busybox-1.20.2/archival/libipkg/ipkg_download.h
  3537. --- busybox-1.20.2.orig//archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
  3538. +++ busybox-1.20.2/archival/libipkg/ipkg_download.h 2013-01-31 16:44:31.000000000 +0100
  3539. @@ -0,0 +1,30 @@
  3540. +/* ipkg_download.h - the itsy package management system
  3541. +
  3542. + Carl D. Worth
  3543. +
  3544. + Copyright (C) 2001 University of Southern California
  3545. +
  3546. + This program is free software; you can redistribute it and/or
  3547. + modify it under the terms of the GNU General Public License as
  3548. + published by the Free Software Foundation; either version 2, or (at
  3549. + your option) any later version.
  3550. +
  3551. + This program is distributed in the hope that it will be useful, but
  3552. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3553. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3554. + General Public License for more details.
  3555. +*/
  3556. +
  3557. +#ifndef IPKG_DOWNLOAD_H
  3558. +#define IPKG_DOWNLOAD_H
  3559. +
  3560. +#include "ipkg_conf.h"
  3561. +
  3562. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
  3563. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
  3564. +/*
  3565. + * Downloads file from url, installs in package database, return package name.
  3566. + */
  3567. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
  3568. +
  3569. +#endif
  3570. diff -Nur busybox-1.20.2.orig//archival/libipkg/ipkg.h busybox-1.20.2/archival/libipkg/ipkg.h
  3571. --- busybox-1.20.2.orig//archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
  3572. +++ busybox-1.20.2/archival/libipkg/ipkg.h 2013-01-31 16:44:31.000000000 +0100
  3573. @@ -0,0 +1,68 @@
  3574. +/* ipkg.h - the itsy package management system
  3575. +
  3576. + Carl D. Worth
  3577. +
  3578. + Copyright (C) 2001 University of Southern California
  3579. +
  3580. + This program is free software; you can redistribute it and/or
  3581. + modify it under the terms of the GNU General Public License as
  3582. + published by the Free Software Foundation; either version 2, or (at
  3583. + your option) any later version.
  3584. +
  3585. + This program is distributed in the hope that it will be useful, but
  3586. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3587. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3588. + General Public License for more details.
  3589. +*/
  3590. +
  3591. +#ifndef IPKG_H
  3592. +#define IPKG_H
  3593. +
  3594. +#include "libbb.h"
  3595. +
  3596. +#include "ipkg_includes.h"
  3597. +#include "ipkg_conf.h"
  3598. +#include "ipkg_message.h"
  3599. +
  3600. +#define IPKG_PKG_EXTENSION ".ipk"
  3601. +#define DPKG_PKG_EXTENSION ".deb"
  3602. +
  3603. +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
  3604. +#define IPKG_PKG_VERSION_SEP_CHAR '_'
  3605. +
  3606. +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
  3607. +#define IPKG_LISTS_DIR_SUFFIX "lists"
  3608. +#define IPKG_INFO_DIR_SUFFIX "info"
  3609. +#define IPKG_STATUS_FILE_SUFFIX "status"
  3610. +
  3611. +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
  3612. +
  3613. +#define IPKG_LIST_DESCRIPTION_LENGTH 128
  3614. +
  3615. +#define IPKG_VERSION "1.00"
  3616. +
  3617. +
  3618. +enum ipkg_error {
  3619. + IPKG_SUCCESS = 0,
  3620. + IPKG_PKG_DEPS_UNSATISFIED,
  3621. + IPKG_PKG_IS_ESSENTIAL,
  3622. + IPKG_PKG_HAS_DEPENDENTS,
  3623. + IPKG_PKG_HAS_NO_CANDIDATE
  3624. +};
  3625. +typedef enum ipkg_error ipkg_error_t;
  3626. +
  3627. +extern int ipkg_state_changed;
  3628. +
  3629. +
  3630. +struct errlist {
  3631. + char * errmsg;
  3632. + struct errlist * next;
  3633. +} ;
  3634. +
  3635. +extern struct errlist* error_list;
  3636. +
  3637. +extern ipkg_conf_t *global_conf;
  3638. +
  3639. +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
  3640. +
  3641. +#endif
  3642. diff -Nur busybox-1.20.2.orig//archival/libipkg/ipkg_includes.h busybox-1.20.2/archival/libipkg/ipkg_includes.h
  3643. --- busybox-1.20.2.orig//archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
  3644. +++ busybox-1.20.2/archival/libipkg/ipkg_includes.h 2013-01-31 16:44:31.000000000 +0100
  3645. @@ -0,0 +1,82 @@
  3646. +#ifndef IPKG_INCLUDES_H
  3647. +#define IPKG_INCLUDES_H
  3648. +
  3649. +/* Define to 1 if you have the <memory.h> header file. */
  3650. +#define HAVE_MEMORY_H 1
  3651. +
  3652. +/* Define to 1 if you have the <regex.h> header file. */
  3653. +#define HAVE_REGEX_H 1
  3654. +
  3655. +/* Define to 1 if you have the <stdlib.h> header file. */
  3656. +#define HAVE_STDLIB_H 1
  3657. +
  3658. +/* Define to 1 if you have the <strings.h> header file. */
  3659. +#define HAVE_STRINGS_H 1
  3660. +
  3661. +/* Define to 1 if you have the <string.h> header file. */
  3662. +#define HAVE_STRING_H 1
  3663. +
  3664. +/* Define to 1 if you have the <sys/stat.h> header file. */
  3665. +#define HAVE_SYS_STAT_H 1
  3666. +
  3667. +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
  3668. +#define HAVE_SYS_WAIT_H 1
  3669. +
  3670. +/* Define to 1 if you have the <unistd.h> header file. */
  3671. +#define HAVE_UNISTD_H 1
  3672. +
  3673. +/* Define to 1 if you have the ANSI C header files. */
  3674. +#define STDC_HEADERS 1
  3675. +
  3676. +
  3677. +#include <stdio.h>
  3678. +
  3679. +#if STDC_HEADERS
  3680. +# include <stdlib.h>
  3681. +# include <stdarg.h>
  3682. +# include <stddef.h>
  3683. +# include <ctype.h>
  3684. +# include <errno.h>
  3685. +#else
  3686. +# if HAVE_STDLIB_H
  3687. +# include <stdlib.h>
  3688. +# endif
  3689. +#endif
  3690. +
  3691. +#if HAVE_REGEX_H
  3692. +# include <regex.h>
  3693. +#endif
  3694. +
  3695. +#if HAVE_STRING_H
  3696. +# if !STDC_HEADERS && HAVE_MEMORY_H
  3697. +# include <memory.h>
  3698. +# endif
  3699. +/* XXX: What's the right way to pick up GNU's strndup declaration? */
  3700. +# if __GNUC__
  3701. +# define __USE_GNU 1
  3702. +# endif
  3703. +# include <string.h>
  3704. +# undef __USE_GNU
  3705. +#endif
  3706. +
  3707. +#if HAVE_STRINGS_H
  3708. +# include <strings.h>
  3709. +#endif
  3710. +
  3711. +#if HAVE_SYS_STAT_H
  3712. +# include <sys/stat.h>
  3713. +#endif
  3714. +
  3715. +#if HAVE_SYS_WAIT_H
  3716. +# include <sys/wait.h>
  3717. +#endif
  3718. +
  3719. +#if HAVE_UNISTD_H
  3720. +# include <sys/types.h>
  3721. +# include <unistd.h>
  3722. +#endif
  3723. +
  3724. +#include <sys/mount.h>
  3725. +#include <mntent.h>
  3726. +
  3727. +#endif /* IPKG_INCLUDES_H */
  3728. diff -Nur busybox-1.20.2.orig//archival/libipkg/ipkg_install.c busybox-1.20.2/archival/libipkg/ipkg_install.c
  3729. --- busybox-1.20.2.orig//archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
  3730. +++ busybox-1.20.2/archival/libipkg/ipkg_install.c 2013-01-31 16:44:31.000000000 +0100
  3731. @@ -0,0 +1,1982 @@
  3732. +/* ipkg_install.c - the itsy package management system
  3733. +
  3734. + Carl D. Worth
  3735. +
  3736. + Copyright (C) 2001 University of Southern California
  3737. +
  3738. + This program is free software; you can redistribute it and/or
  3739. + modify it under the terms of the GNU General Public License as
  3740. + published by the Free Software Foundation; either version 2, or (at
  3741. + your option) any later version.
  3742. +
  3743. + This program is distributed in the hope that it will be useful, but
  3744. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3745. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3746. + General Public License for more details.
  3747. +*/
  3748. +
  3749. +#include "ipkg.h"
  3750. +#include <errno.h>
  3751. +#include <dirent.h>
  3752. +#include <glob.h>
  3753. +#include <time.h>
  3754. +#include <signal.h>
  3755. +typedef void (*sighandler_t)(int);
  3756. +
  3757. +#include "pkg.h"
  3758. +#include "pkg_hash.h"
  3759. +#include "pkg_extract.h"
  3760. +
  3761. +#include "ipkg_install.h"
  3762. +#include "ipkg_configure.h"
  3763. +#include "ipkg_download.h"
  3764. +#include "ipkg_remove.h"
  3765. +
  3766. +#include "ipkg_utils.h"
  3767. +#include "ipkg_message.h"
  3768. +
  3769. +#include "sprintf_alloc.h"
  3770. +#include "file_util.h"
  3771. +#include "str_util.h"
  3772. +#include "xsystem.h"
  3773. +#include "user.h"
  3774. +
  3775. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  3776. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
  3777. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
  3778. +
  3779. +/*
  3780. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3781. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3782. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3783. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3784. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3785. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3786. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3787. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
  3788. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3789. +*/
  3790. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3791. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3792. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg);
  3793. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3794. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg);
  3795. +
  3796. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3797. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3798. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
  3799. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
  3800. +
  3801. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
  3802. +
  3803. +static int user_prefers_old_conffile(const char *file, const char *backup);
  3804. +
  3805. +static char *backup_filename_alloc(const char *file_name);
  3806. +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
  3807. +static int backup_exists_for(const char *file_name);
  3808. +static int backup_remove(const char *file_name);
  3809. +
  3810. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees);
  3811. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3812. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3813. +
  3814. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
  3815. +{
  3816. + int err, cmp;
  3817. + pkg_t *pkg, *old;
  3818. + char *old_version, *new_version;
  3819. +
  3820. + pkg = pkg_new();
  3821. + if (pkg == NULL) {
  3822. + return ENOMEM;
  3823. + }
  3824. +
  3825. + err = pkg_init_from_file(pkg, filename);
  3826. + if (err) {
  3827. + return err;
  3828. + }
  3829. +
  3830. + if (!pkg->architecture) {
  3831. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3832. + return -EINVAL;
  3833. + }
  3834. +
  3835. + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
  3836. + freeing the pkg that we pass in. It might be nice to clean this up
  3837. + if possible. */
  3838. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3839. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  3840. +
  3841. + pkg->local_filename = strdup(filename);
  3842. +
  3843. + if (old) {
  3844. + old_version = pkg_version_str_alloc(old);
  3845. + new_version = pkg_version_str_alloc(pkg);
  3846. +
  3847. + cmp = pkg_compare_versions(old, pkg);
  3848. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3849. + cmp = -1 ; /* then we force ipkg to downgrade */
  3850. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3851. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3852. + }
  3853. + if (cmp > 0) {
  3854. + ipkg_message(conf, IPKG_NOTICE,
  3855. + "Not downgrading package %s on %s from %s to %s.\n",
  3856. + old->name, old->dest->name, old_version, new_version);
  3857. + pkg->state_want = SW_DEINSTALL;
  3858. + pkg->state_flag |= SF_OBSOLETE;
  3859. + free(old_version);
  3860. + free(new_version);
  3861. + return 0;
  3862. + } else {
  3863. + free(old_version);
  3864. + free(new_version);
  3865. + }
  3866. + }
  3867. +
  3868. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3869. + return ipkg_install_pkg(conf, pkg,0);
  3870. +}
  3871. +
  3872. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3873. +{
  3874. + int cmp;
  3875. + pkg_t *old, *new;
  3876. + char *old_version, *new_version;
  3877. +
  3878. + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
  3879. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  3880. + if ( old )
  3881. + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
  3882. +
  3883. + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
  3884. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  3885. + if ( new )
  3886. + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
  3887. +
  3888. +/* Pigi Basically here is broken the version stuff.
  3889. + What's happening is that nothing provide the version to differents
  3890. + functions, so the returned struct is always the latest.
  3891. + That's why the install by name don't work.
  3892. +*/
  3893. + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
  3894. +
  3895. + if ( old )
  3896. + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
  3897. + if ( new )
  3898. + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
  3899. + ipkg_message(conf, IPKG_DEBUG2, " \n");
  3900. +
  3901. + if (new == NULL) {
  3902. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3903. + }
  3904. +
  3905. + new->state_flag |= SF_USER;
  3906. + if (old) {
  3907. + old_version = pkg_version_str_alloc(old);
  3908. + new_version = pkg_version_str_alloc(new);
  3909. +
  3910. + cmp = pkg_compare_versions(old, new);
  3911. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3912. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
  3913. + cmp = -1 ; /* then we force ipkg to downgrade */
  3914. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3915. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3916. + }
  3917. + ipkg_message(conf, IPKG_DEBUG,
  3918. + "Comparing visible versions of pkg %s:"
  3919. + "\n\t%s is installed "
  3920. + "\n\t%s is available "
  3921. + "\n\t%d was comparison result\n",
  3922. + pkg_name, old_version, new_version, cmp);
  3923. + if (cmp == 0 && !conf->force_reinstall) {
  3924. + ipkg_message(conf, IPKG_NOTICE,
  3925. + "Package %s (%s) installed in %s is up to date.\n",
  3926. + old->name, old_version, old->dest->name);
  3927. + free(old_version);
  3928. + free(new_version);
  3929. + return 0;
  3930. + } else if (cmp > 0) {
  3931. + ipkg_message(conf, IPKG_NOTICE,
  3932. + "Not downgrading package %s on %s from %s to %s.\n",
  3933. + old->name, old->dest->name, old_version, new_version);
  3934. + free(old_version);
  3935. + free(new_version);
  3936. + return 0;
  3937. + } else if (cmp < 0) {
  3938. + new->dest = old->dest;
  3939. + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
  3940. + }
  3941. + }
  3942. +
  3943. + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
  3944. + supposed to be an ipkg_error_t, but ipkg_install_pkg could
  3945. + return any kind of integer, (might be errno from a syscall,
  3946. + etc.). This is a real mess and will need to be cleaned up if
  3947. + anyone ever wants to make a nice libipkg. */
  3948. +
  3949. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3950. + return ipkg_install_pkg(conf, new,0);
  3951. +}
  3952. +
  3953. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3954. +{
  3955. + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
  3956. + int i;
  3957. + ipkg_error_t err;
  3958. + abstract_pkg_t *ppkg ;
  3959. +
  3960. + if (providers == NULL)
  3961. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3962. +
  3963. + for (i = 0; i < providers->len; i++) {
  3964. + ppkg = abstract_pkg_vec_get(providers, i);
  3965. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
  3966. + err = ipkg_install_by_name(conf, ppkg->name);
  3967. + if (err)
  3968. + return err;
  3969. +/* XXX Maybe ppkg should be freed ? */
  3970. + }
  3971. + return 0;
  3972. +}
  3973. +
  3974. +/*
  3975. + * Walk dependence graph starting with pkg, collect packages to be
  3976. + * installed into pkgs_needed, in dependence order.
  3977. + */
  3978. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
  3979. +{
  3980. + int i, err;
  3981. + pkg_vec_t *depends = pkg_vec_alloc();
  3982. + char **unresolved = NULL;
  3983. + int ndepends;
  3984. +
  3985. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  3986. + pkg, depends,
  3987. + &unresolved);
  3988. +
  3989. + if (unresolved) {
  3990. + ipkg_message(conf, IPKG_ERROR,
  3991. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  3992. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  3993. + while (*unresolved) {
  3994. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  3995. + unresolved++;
  3996. + }
  3997. + ipkg_message(conf, IPKG_ERROR, "\n");
  3998. + if (! conf->force_depends) {
  3999. + ipkg_message(conf, IPKG_INFO,
  4000. + "This could mean that your package list is out of date or that the packages\n"
  4001. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4002. + "of this problem try again with the '-force-depends' option.\n");
  4003. + pkg_vec_free(depends);
  4004. + return IPKG_PKG_DEPS_UNSATISFIED;
  4005. + }
  4006. + }
  4007. +
  4008. + if (ndepends <= 0) {
  4009. + pkg_vec_free(depends);
  4010. + return 0;
  4011. + }
  4012. +
  4013. + for (i = 0; i < depends->len; i++) {
  4014. + pkg_t *dep = depends->pkgs[i];
  4015. + /* The package was uninstalled when we started, but another
  4016. + dep earlier in this loop may have depended on it and pulled
  4017. + it in, so check first. */
  4018. + if ((dep->state_status != SS_INSTALLED)
  4019. + && (dep->state_status != SS_UNPACKED)
  4020. + && (dep->state_want != SW_INSTALL)) {
  4021. +
  4022. + /* Mark packages as to-be-installed */
  4023. + dep->state_want = SW_INSTALL;
  4024. +
  4025. + /* Dependencies should be installed the same place as pkg */
  4026. + if (dep->dest == NULL) {
  4027. + dep->dest = pkg->dest;
  4028. + }
  4029. +
  4030. + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
  4031. + if (err) {
  4032. + pkg_vec_free(depends);
  4033. + return err;
  4034. + }
  4035. + }
  4036. + }
  4037. + if (pkgs_needed)
  4038. + pkg_vec_insert(pkgs_needed, pkg);
  4039. +
  4040. + pkg_vec_free(depends);
  4041. +
  4042. + return 0;
  4043. +}
  4044. +
  4045. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
  4046. +{
  4047. + int cmp;
  4048. + pkg_t *old, *new;
  4049. + char *old_version, *new_version;
  4050. +
  4051. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  4052. +
  4053. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  4054. + if (new == NULL) {
  4055. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4056. + }
  4057. + if (old) {
  4058. + old_version = pkg_version_str_alloc(old);
  4059. + new_version = pkg_version_str_alloc(new);
  4060. +
  4061. + cmp = pkg_compare_versions(old, new);
  4062. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4063. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
  4064. + cmp = -1 ; /* then we force ipkg to downgrade */
  4065. + /* We need to use a value < 0 because in the 0 case we are asking to */
  4066. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4067. + }
  4068. + ipkg_message(conf, IPKG_DEBUG,
  4069. + "comparing visible versions of pkg %s:"
  4070. + "\n\t%s is installed "
  4071. + "\n\t%s is available "
  4072. + "\n\t%d was comparison result\n",
  4073. + pkg_name, old_version, new_version, cmp);
  4074. + if (cmp == 0 && !conf->force_reinstall) {
  4075. + ipkg_message(conf, IPKG_NOTICE,
  4076. + "Package %s (%s) installed in %s is up to date.\n",
  4077. + old->name, old_version, old->dest->name);
  4078. + free(old_version);
  4079. + free(new_version);
  4080. + return 0;
  4081. + } else if (cmp > 0) {
  4082. + ipkg_message(conf, IPKG_NOTICE,
  4083. + "Not downgrading package %s on %s from %s to %s.\n",
  4084. + old->name, old->dest->name, old_version, new_version);
  4085. + free(old_version);
  4086. + free(new_version);
  4087. + return 0;
  4088. + } else if (cmp < 0) {
  4089. + new->dest = old->dest;
  4090. + old->state_want = SW_DEINSTALL;
  4091. + old->state_flag |= SF_OBSOLETE;
  4092. + }
  4093. + }
  4094. + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
  4095. +}
  4096. +
  4097. +
  4098. +
  4099. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
  4100. +{
  4101. + int i, err;
  4102. + pkg_vec_t *depends = pkg_vec_alloc();
  4103. + pkg_t *dep;
  4104. + char **unresolved = NULL;
  4105. + int ndepends;
  4106. +
  4107. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4108. + pkg, depends,
  4109. + &unresolved);
  4110. +
  4111. + if (unresolved) {
  4112. + ipkg_message(conf, IPKG_ERROR,
  4113. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4114. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4115. + while (*unresolved) {
  4116. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4117. + unresolved++;
  4118. + }
  4119. + ipkg_message(conf, IPKG_ERROR, "\n");
  4120. + if (! conf->force_depends) {
  4121. + ipkg_message(conf, IPKG_INFO,
  4122. + "This could mean that your package list is out of date or that the packages\n"
  4123. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4124. + "of this problem try again with the '-force-depends' option.\n");
  4125. + pkg_vec_free(depends);
  4126. + return IPKG_PKG_DEPS_UNSATISFIED;
  4127. + }
  4128. + }
  4129. +
  4130. + if (ndepends <= 0) {
  4131. + return 0;
  4132. + }
  4133. +
  4134. + /* Mark packages as to-be-installed */
  4135. + for (i=0; i < depends->len; i++) {
  4136. + /* Dependencies should be installed the same place as pkg */
  4137. + if (depends->pkgs[i]->dest == NULL) {
  4138. + depends->pkgs[i]->dest = pkg->dest;
  4139. + }
  4140. + depends->pkgs[i]->state_want = SW_INSTALL;
  4141. + }
  4142. +
  4143. + for (i = 0; i < depends->len; i++) {
  4144. + dep = depends->pkgs[i];
  4145. + /* The package was uninstalled when we started, but another
  4146. + dep earlier in this loop may have depended on it and pulled
  4147. + it in, so check first. */
  4148. + if ((dep->state_status != SS_INSTALLED)
  4149. + && (dep->state_status != SS_UNPACKED)) {
  4150. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4151. + err = ipkg_install_pkg(conf, dep,0);
  4152. + if (err) {
  4153. + pkg_vec_free(depends);
  4154. + return err;
  4155. + }
  4156. + }
  4157. + }
  4158. +
  4159. + pkg_vec_free(depends);
  4160. +
  4161. + return 0;
  4162. +}
  4163. +
  4164. +
  4165. +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
  4166. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
  4167. +{
  4168. + if (conf->nodeps == 0) {
  4169. + int i;
  4170. + pkg_vec_t *installed = pkg_vec_alloc();
  4171. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  4172. + for (i = 0; i < installed->len; i++) {
  4173. + pkg_t *pkg = installed->pkgs[i];
  4174. + satisfy_dependencies_for(conf, pkg);
  4175. + }
  4176. + pkg_vec_free(installed);
  4177. + }
  4178. + return 0;
  4179. +}
  4180. +
  4181. +
  4182. +
  4183. +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
  4184. +{
  4185. + int i;
  4186. + pkg_vec_t *conflicts = NULL;
  4187. + int level;
  4188. + const char *prefix;
  4189. + if (conf->force_depends) {
  4190. + level = IPKG_NOTICE;
  4191. + prefix = "Warning";
  4192. + } else {
  4193. + level = IPKG_ERROR;
  4194. + prefix = "ERROR";
  4195. + }
  4196. +
  4197. + if (!conf->force_depends)
  4198. + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(pkg);
  4199. +
  4200. + if (conflicts) {
  4201. + ipkg_message(conf, level,
  4202. + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
  4203. + i = 0;
  4204. + while (i < conflicts->len)
  4205. + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
  4206. + ipkg_message(conf, level, "\n");
  4207. + pkg_vec_free(conflicts);
  4208. + return IPKG_PKG_DEPS_UNSATISFIED;
  4209. + }
  4210. + return 0;
  4211. +}
  4212. +
  4213. +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
  4214. +{
  4215. + str_list_t *new_list = pkg_get_installed_files(new_pkg);
  4216. + str_list_elt_t *iter;
  4217. +
  4218. + for (iter = new_list->head; iter; iter = iter->next) {
  4219. + char *new_file = iter->data;
  4220. + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
  4221. + if (!new_file)
  4222. + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
  4223. + if (!owner || (owner == old_pkg))
  4224. + file_hash_set_file_owner(conf, new_file, new_pkg);
  4225. + }
  4226. + if (old_pkg) {
  4227. + str_list_t *old_list = pkg_get_installed_files(old_pkg);
  4228. + for (iter = old_list->head; iter; iter = iter->next) {
  4229. + char *old_file = iter->data;
  4230. + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
  4231. + if (owner == old_pkg) {
  4232. + /* obsolete */
  4233. + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
  4234. + }
  4235. + }
  4236. + }
  4237. + return 0;
  4238. +}
  4239. +
  4240. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
  4241. +{
  4242. + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
  4243. +
  4244. + /* sma 6.20.02: yup; here's the first bit */
  4245. + /*
  4246. + * XXX: BUG easy for cworth
  4247. + * 1) please point the call below to the correct current root destination
  4248. + * 2) we need to resolve how to check the required space for a pending pkg,
  4249. + * my diddling with the .ipk file size below isn't going to cut it.
  4250. + * 3) return a proper error code instead of 1
  4251. + */
  4252. + int comp_size, blocks_available;
  4253. +
  4254. + if (!conf->force_space && pkg->installed_size != NULL) {
  4255. + blocks_available = get_available_blocks(conf->default_dest->root_dir);
  4256. +
  4257. + comp_size = strtoul(pkg->installed_size, NULL, 0);
  4258. + /* round up a blocks count without doing fancy-but-slow casting jazz */
  4259. + comp_size = (int)((comp_size + 1023) / 1024);
  4260. +
  4261. + if (comp_size >= blocks_available) {
  4262. + ipkg_message(conf, IPKG_ERROR,
  4263. + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
  4264. + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
  4265. + return ENOSPC;
  4266. + }
  4267. + }
  4268. + return 0;
  4269. +}
  4270. +
  4271. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
  4272. +{
  4273. + int err;
  4274. + char *conffiles_file_name;
  4275. + char *root_dir;
  4276. + FILE *conffiles_file;
  4277. +
  4278. + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
  4279. +
  4280. + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
  4281. + if (pkg->tmp_unpack_dir == NULL) {
  4282. + ipkg_message(conf, IPKG_ERROR,
  4283. + "%s: Failed to create temporary directory '%s': %s\n",
  4284. + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
  4285. + return errno;
  4286. + }
  4287. +
  4288. + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
  4289. + if (err) {
  4290. + return err;
  4291. + }
  4292. +
  4293. + /* XXX: CLEANUP: There might be a cleaner place to read in the
  4294. + conffiles. Seems like I should be able to get everything to go
  4295. + through pkg_init_from_file. If so, maybe it would make sense to
  4296. + move all of unpack_pkg_control_files to that function. */
  4297. +
  4298. + /* Don't need to re-read conffiles if we already have it */
  4299. + if (pkg->conffiles.head) {
  4300. + return 0;
  4301. + }
  4302. +
  4303. + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
  4304. + if (! file_exists(conffiles_file_name)) {
  4305. + free(conffiles_file_name);
  4306. + return 0;
  4307. + }
  4308. +
  4309. + conffiles_file = fopen(conffiles_file_name, "r");
  4310. + if (conffiles_file == NULL) {
  4311. + fprintf(stderr, "%s: failed to open %s: %s\n",
  4312. + __FUNCTION__, conffiles_file_name, strerror(errno));
  4313. + free(conffiles_file_name);
  4314. + return errno;
  4315. + }
  4316. + free(conffiles_file_name);
  4317. +
  4318. + while (1) {
  4319. + char *cf_name;
  4320. + char *cf_name_in_dest;
  4321. +
  4322. + cf_name = file_read_line_alloc(conffiles_file);
  4323. + if (cf_name == NULL) {
  4324. + break;
  4325. + }
  4326. + str_chomp(cf_name);
  4327. + if (cf_name[0] == '\0') {
  4328. + continue;
  4329. + }
  4330. +
  4331. + /* Prepend dest->root_dir to conffile name.
  4332. + Take pains to avoid multiple slashes. */
  4333. + root_dir = pkg->dest->root_dir;
  4334. + if (conf->offline_root)
  4335. + /* skip the offline_root prefix */
  4336. + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
  4337. + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
  4338. + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
  4339. +
  4340. + /* Can't get an md5sum now, (file isn't extracted yet).
  4341. + We'll wait until resolve_conffiles */
  4342. + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
  4343. +
  4344. + free(cf_name);
  4345. + free(cf_name_in_dest);
  4346. + }
  4347. +
  4348. + fclose(conffiles_file);
  4349. +
  4350. + return 0;
  4351. +}
  4352. +
  4353. +/* returns number of installed replacees */
  4354. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees)
  4355. +{
  4356. + abstract_pkg_t **replaces = pkg->replaces;
  4357. + int replaces_count = pkg->replaces_count;
  4358. + int i, j;
  4359. + for (i = 0; i < replaces_count; i++) {
  4360. + abstract_pkg_t *ab_pkg = replaces[i];
  4361. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  4362. + if (pkg_vec) {
  4363. + for (j = 0; j < pkg_vec->len; j++) {
  4364. + pkg_t *replacee = pkg_vec->pkgs[j];
  4365. + if (!pkg_conflicts(pkg, replacee))
  4366. + continue;
  4367. + if (replacee->state_status == SS_INSTALLED) {
  4368. + pkg_vec_insert(installed_replacees, replacee);
  4369. + }
  4370. + }
  4371. + }
  4372. + }
  4373. + return installed_replacees->len;
  4374. +}
  4375. +
  4376. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4377. +{
  4378. + int i;
  4379. + int replaces_count = replacees->len;
  4380. + for (i = 0; i < replaces_count; i++) {
  4381. + pkg_t *replacee = replacees->pkgs[i];
  4382. + int err;
  4383. + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
  4384. + err = ipkg_remove_pkg(conf, replacee,0);
  4385. + if (err)
  4386. + return err;
  4387. + }
  4388. + return 0;
  4389. +}
  4390. +
  4391. +/* to unwind the removal: make sure they are installed */
  4392. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4393. +{
  4394. + int i, err;
  4395. + int replaces_count = replacees->len;
  4396. + for (i = 0; i < replaces_count; i++) {
  4397. + pkg_t *replacee = replacees->pkgs[i];
  4398. + if (replacee->state_status != SS_INSTALLED) {
  4399. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4400. + err = ipkg_install_pkg(conf, replacee,0);
  4401. + if (err)
  4402. + return err;
  4403. + }
  4404. + }
  4405. + return 0;
  4406. +}
  4407. +
  4408. +int caught_sigint = 0;
  4409. +static void ipkg_install_pkg_sigint_handler(int sig)
  4410. +{
  4411. + caught_sigint = sig;
  4412. +}
  4413. +
  4414. +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
  4415. +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
  4416. +{
  4417. + if (old_pkg) {
  4418. + char message_out[15];
  4419. + char *old_version = pkg_version_str_alloc(old_pkg);
  4420. + char *new_version = pkg_version_str_alloc(pkg);
  4421. + int cmp = pkg_compare_versions(old_pkg, pkg);
  4422. + int rc = 0;
  4423. +
  4424. + memset(message_out,'\x0',15);
  4425. + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
  4426. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4427. + cmp = -1 ; /* then we force ipkg to downgrade */
  4428. + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
  4429. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4430. + }
  4431. +
  4432. + if (cmp > 0) {
  4433. + ipkg_message(conf, IPKG_NOTICE,
  4434. + "Not downgrading package %s on %s from %s to %s.\n",
  4435. + old_pkg->name, old_pkg->dest->name, old_version, new_version);
  4436. + rc = 1;
  4437. + } else if (cmp < 0) {
  4438. + ipkg_message(conf, IPKG_NOTICE,
  4439. + "%s%s on %s from %s to %s...\n",
  4440. + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
  4441. + pkg->dest = old_pkg->dest;
  4442. + rc = 0;
  4443. + } else /* cmp == 0 */ {
  4444. + if (conf->force_reinstall) {
  4445. + ipkg_message(conf, IPKG_NOTICE,
  4446. + "Reinstalling %s (%s) on %s...\n",
  4447. + pkg->name, new_version, old_pkg->dest->name);
  4448. + pkg->dest = old_pkg->dest;
  4449. + rc = 0;
  4450. + } else {
  4451. + ipkg_message(conf, IPKG_NOTICE,
  4452. + "Not installing %s (%s) on %s -- already installed.\n",
  4453. + pkg->name, new_version, old_pkg->dest->name);
  4454. + rc = 1;
  4455. + }
  4456. + }
  4457. + free(old_version);
  4458. + free(new_version);
  4459. + return rc;
  4460. + } else {
  4461. + char message_out[15], *version ;
  4462. + memset(message_out,'\x0',15);
  4463. + if ( message )
  4464. + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
  4465. + else
  4466. + strncpy( message_out,"Installing ",strlen("Installing ") );
  4467. + version = pkg_version_str_alloc(pkg);
  4468. +
  4469. + ipkg_message(conf, IPKG_NOTICE,
  4470. + "%s%s (%s) to %s...\n", message_out,
  4471. + pkg->name, version, pkg->dest->name);
  4472. + free(version);
  4473. + return 0;
  4474. + }
  4475. +}
  4476. +
  4477. +/* and now the meat... */
  4478. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
  4479. +{
  4480. + int err = 0;
  4481. + int message = 0;
  4482. + pkg_t *old_pkg = NULL;
  4483. + pkg_vec_t *replacees;
  4484. + abstract_pkg_t *ab_pkg = NULL;
  4485. + int old_state_flag;
  4486. + uint8_t *file_md5;
  4487. +
  4488. +
  4489. + if ( from_upgrade )
  4490. + message = 1; /* Coming from an upgrade, and should change the output message */
  4491. +
  4492. + if (!pkg) {
  4493. + ipkg_message(conf, IPKG_ERROR,
  4494. + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
  4495. + return -EINVAL;
  4496. + }
  4497. +
  4498. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
  4499. +
  4500. + if (!pkg_arch_supported(conf, pkg)) {
  4501. + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
  4502. + pkg->architecture, pkg->name);
  4503. + return -EINVAL;
  4504. + }
  4505. + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
  4506. + err = satisfy_dependencies_for(conf, pkg);
  4507. + if (err) { return err; }
  4508. +
  4509. + ipkg_message(conf, IPKG_NOTICE,
  4510. + "Package %s is already installed in %s.\n",
  4511. + pkg->name, pkg->dest->name);
  4512. + return 0;
  4513. + }
  4514. +
  4515. + if (pkg->dest == NULL) {
  4516. + pkg->dest = conf->default_dest;
  4517. + }
  4518. +
  4519. + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  4520. +
  4521. + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
  4522. + if (err) { return err; }
  4523. +
  4524. + pkg->state_want = SW_INSTALL;
  4525. + if (old_pkg){
  4526. + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
  4527. + }
  4528. +
  4529. +
  4530. + /* Abhaya: conflicts check */
  4531. + err = check_conflicts_for(conf, pkg);
  4532. + if (err) { return err; }
  4533. +
  4534. + /* this setup is to remove the upgrade scenario in the end when
  4535. + installing pkg A, A deps B & B deps on A. So both B and A are
  4536. + installed. Then A's installation is started resulting in an
  4537. + uncecessary upgrade */
  4538. + if (pkg->state_status == SS_INSTALLED
  4539. + && conf->force_reinstall == 0) return 0;
  4540. +
  4541. + err = verify_pkg_installable(conf, pkg);
  4542. + if (err) { return err; }
  4543. +
  4544. + if (pkg->local_filename == NULL) {
  4545. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  4546. + if (err) {
  4547. + ipkg_message(conf, IPKG_ERROR,
  4548. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  4549. + pkg->name);
  4550. + return err;
  4551. + }
  4552. + }
  4553. +
  4554. +/* Check for md5 values */
  4555. + if (pkg->md5sum)
  4556. + {
  4557. + file_md5 = file_md5sum_alloc(pkg->local_filename);
  4558. + if (strcmp((char *)file_md5, pkg->md5sum))
  4559. + {
  4560. + ipkg_message(conf, IPKG_ERROR,
  4561. + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
  4562. + pkg->name);
  4563. + free(file_md5);
  4564. + return err;
  4565. + }
  4566. + free(file_md5);
  4567. + }
  4568. +
  4569. + if (pkg->tmp_unpack_dir == NULL) {
  4570. + unpack_pkg_control_files(conf, pkg);
  4571. + }
  4572. +
  4573. + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
  4574. +/* Pigi: check if it will pass from here when replacing. It seems to fail */
  4575. +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
  4576. + err = update_file_ownership(conf, pkg, old_pkg);
  4577. + if (err) { return err; }
  4578. +
  4579. + if (conf->nodeps == 0) {
  4580. + err = satisfy_dependencies_for(conf, pkg);
  4581. + if (err) { return err; }
  4582. + }
  4583. +
  4584. + replacees = pkg_vec_alloc();
  4585. + pkg_get_installed_replacees(pkg, replacees);
  4586. +
  4587. + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
  4588. + {
  4589. + sigset_t newset, oldset;
  4590. + sighandler_t old_handler = NULL;
  4591. + int use_signal = 0;
  4592. + caught_sigint = 0;
  4593. + if (use_signal) {
  4594. + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
  4595. + } else {
  4596. + sigemptyset(&newset);
  4597. + sigaddset(&newset, SIGINT);
  4598. + sigprocmask(SIG_BLOCK, &newset, &oldset);
  4599. + }
  4600. +
  4601. + ipkg_state_changed++;
  4602. + pkg->state_flag |= SF_FILELIST_CHANGED;
  4603. +
  4604. + /* XXX: BUG: we really should treat replacement more like an upgrade
  4605. + * Instead, we're going to remove the replacees
  4606. + */
  4607. + err = pkg_remove_installed_replacees(conf, replacees);
  4608. + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
  4609. +
  4610. + /*
  4611. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  4612. + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
  4613. +
  4614. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  4615. + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
  4616. + */
  4617. +
  4618. + err = preinst_configure(conf, pkg, old_pkg);
  4619. + /*
  4620. + if (err) goto UNWIND_PREINST_CONFIGURE;
  4621. + */
  4622. +
  4623. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  4624. + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
  4625. +
  4626. + err = check_data_file_clashes(conf, pkg, old_pkg);
  4627. + /*
  4628. + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
  4629. +
  4630. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  4631. + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
  4632. + */
  4633. +
  4634. + if (conf->noaction) return 0;
  4635. +
  4636. + /* point of no return: no unwinding after this */
  4637. + if (old_pkg && !conf->force_reinstall) {
  4638. + old_pkg->state_want = SW_DEINSTALL;
  4639. +
  4640. + if (old_pkg->state_flag & SF_NOPRUNE) {
  4641. + ipkg_message(conf, IPKG_INFO,
  4642. + " not removing obsolesced files because package marked noprune\n");
  4643. + } else {
  4644. + ipkg_message(conf, IPKG_INFO,
  4645. + " removing obsolesced files\n");
  4646. + remove_obsolesced_files(conf, pkg, old_pkg);
  4647. + }
  4648. + /* removing files from old package, to avoid ghost files */
  4649. + remove_data_files_and_list(conf, old_pkg);
  4650. +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
  4651. + remove_maintainer_scripts_except_postrm(conf, old_pkg);
  4652. + remove_postrm(conf, old_pkg);
  4653. +/* Pigi */
  4654. +
  4655. + }
  4656. +
  4657. +
  4658. + ipkg_message(conf, IPKG_INFO,
  4659. + " installing maintainer scripts\n");
  4660. + install_maintainer_scripts(conf, pkg, old_pkg);
  4661. +
  4662. + /* the following just returns 0
  4663. + remove_disappeared(conf, pkg);
  4664. + */
  4665. +
  4666. + ipkg_message(conf, IPKG_INFO,
  4667. + " installing data files\n");
  4668. + install_data_files(conf, pkg);
  4669. +
  4670. +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
  4671. + err = check_data_file_clashes_change(conf, pkg);
  4672. +
  4673. + ipkg_message(conf, IPKG_INFO,
  4674. + " resolving conf files\n");
  4675. + resolve_conffiles(conf, pkg);
  4676. +
  4677. + pkg->state_status = SS_UNPACKED;
  4678. + old_state_flag = pkg->state_flag;
  4679. + pkg->state_flag &= ~SF_PREFER;
  4680. + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
  4681. +
  4682. + if (old_pkg && !conf->force_reinstall) {
  4683. + old_pkg->state_status = SS_NOT_INSTALLED;
  4684. + }
  4685. +
  4686. + time(&pkg->installed_time);
  4687. +
  4688. + ipkg_message(conf, IPKG_INFO,
  4689. + " cleanup temp files\n");
  4690. + cleanup_temporary_files(conf, pkg);
  4691. +
  4692. + ab_pkg = pkg->parent;
  4693. + if (ab_pkg)
  4694. + ab_pkg->state_status = pkg->state_status;
  4695. +
  4696. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  4697. +
  4698. + if (use_signal)
  4699. + signal(SIGINT, old_handler);
  4700. + else
  4701. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4702. +
  4703. + return 0;
  4704. +
  4705. +
  4706. + /*
  4707. + UNWIND_POSTRM_UPGRADE_OLD_PKG:
  4708. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4709. + UNWIND_CHECK_DATA_FILE_CLASHES:
  4710. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  4711. + */
  4712. + UNWIND_BACKUP_MODIFIED_CONFFILES:
  4713. + backup_modified_conffiles_unwind(pkg, old_pkg);
  4714. + /*
  4715. + UNWIND_PREINST_CONFIGURE:
  4716. + preinst_configure_unwind(conf, pkg, old_pkg);
  4717. + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
  4718. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  4719. + UNWIND_PRERM_UPGRADE_OLD_PKG:
  4720. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4721. + */
  4722. + UNWIND_REMOVE_INSTALLED_REPLACEES:
  4723. + pkg_remove_installed_replacees_unwind(conf, replacees);
  4724. +
  4725. + ipkg_message(conf, IPKG_INFO,
  4726. + " cleanup temp files\n");
  4727. + cleanup_temporary_files(conf, pkg);
  4728. +
  4729. + ipkg_message(conf, IPKG_INFO,
  4730. + "Failed.\n");
  4731. + if (use_signal)
  4732. + signal(SIGINT, old_handler);
  4733. + else
  4734. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4735. +
  4736. + return err;
  4737. + }
  4738. +}
  4739. +
  4740. +/*
  4741. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4742. +{
  4743. + DPKG_INCOMPATIBILITY:
  4744. + dpkg does some things here that we don't do yet. Do we care?
  4745. +
  4746. + 1. If a version of the package is already installed, call
  4747. + old-prerm upgrade new-version
  4748. + 2. If the script runs but exits with a non-zero exit status
  4749. + new-prerm failed-upgrade old-version
  4750. + Error unwind, for both the above cases:
  4751. + old-postinst abort-upgrade new-version
  4752. + return 0;
  4753. +}
  4754. +*/
  4755. +
  4756. +/*
  4757. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4758. +{
  4759. + DPKG_INCOMPATIBILITY:
  4760. + dpkg does some things here that we don't do yet. Do we care?
  4761. + (See prerm_upgrade_old_package for details)
  4762. +
  4763. + return 0;
  4764. +}
  4765. +*/
  4766. +
  4767. +/*
  4768. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4769. +{
  4770. + DPKG_INCOMPATIBILITY:
  4771. + dpkg does some things here that we don't do yet. Do we care?
  4772. + 2. If a 'conflicting' package is being removed at the same time:
  4773. + 1. If any packages depended on that conflicting package and
  4774. + --auto-deconfigure is specified, call, for each such package:
  4775. + deconfigured's-prerm deconfigure \
  4776. + in-favour package-being-installed version \
  4777. + removing conflicting-package version
  4778. + Error unwind:
  4779. + deconfigured's-postinst abort-deconfigure \
  4780. + in-favour package-being-installed-but-failed version \
  4781. + removing conflicting-package version
  4782. +
  4783. + The deconfigured packages are marked as requiring
  4784. + configuration, so that if --install is used they will be
  4785. + configured again if possible.
  4786. + 2. To prepare for removal of the conflicting package, call:
  4787. + conflictor's-prerm remove in-favour package new-version
  4788. + Error unwind:
  4789. + conflictor's-postinst abort-remove in-favour package new-version
  4790. + return 0;
  4791. +}
  4792. +*/
  4793. +
  4794. +/*
  4795. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4796. +{
  4797. + DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
  4798. + do yet. Do we care? (See prerm_deconfigure_conflictors for
  4799. + details)
  4800. + return 0;
  4801. +}
  4802. +*/
  4803. +
  4804. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4805. +{
  4806. + int err;
  4807. + char *preinst_args;
  4808. +
  4809. + if (old_pkg) {
  4810. + char *old_version = pkg_version_str_alloc(old_pkg);
  4811. + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
  4812. + free(old_version);
  4813. + } else if (pkg->state_status == SS_CONFIG_FILES) {
  4814. + char *pkg_version = pkg_version_str_alloc(pkg);
  4815. + sprintf_alloc(&preinst_args, "install %s", pkg_version);
  4816. + free(pkg_version);
  4817. + } else {
  4818. + preinst_args = strdup("install");
  4819. + }
  4820. +
  4821. + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
  4822. + if (err) {
  4823. + ipkg_message(conf, IPKG_ERROR,
  4824. + "Aborting installation of %s\n", pkg->name);
  4825. + return 1;
  4826. + }
  4827. +
  4828. + free(preinst_args);
  4829. +
  4830. + return 0;
  4831. +}
  4832. +
  4833. +/*
  4834. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4835. +{
  4836. + DPKG_INCOMPATIBILITY:
  4837. + dpkg does the following error unwind, should we?
  4838. + pkg->postrm abort-upgrade old-version
  4839. + OR pkg->postrm abort-install old-version
  4840. + OR pkg->postrm abort-install
  4841. + return 0;
  4842. +}
  4843. +*/
  4844. +
  4845. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4846. +{
  4847. + int err;
  4848. + conffile_list_elt_t *iter;
  4849. + conffile_t *cf;
  4850. +
  4851. + if (conf->noaction) return 0;
  4852. +
  4853. + /* Backup all modified conffiles */
  4854. + if (old_pkg) {
  4855. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4856. + char *cf_name;
  4857. +
  4858. + cf = iter->data;
  4859. + cf_name = root_filename_alloc(conf, cf->name);
  4860. +
  4861. + /* Don't worry if the conffile is just plain gone */
  4862. + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
  4863. + err = backup_make_backup(conf, cf_name);
  4864. + if (err) {
  4865. + return err;
  4866. + }
  4867. + }
  4868. + free(cf_name);
  4869. + }
  4870. + }
  4871. +
  4872. + /* Backup all conffiles that were not conffiles in old_pkg */
  4873. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4874. + char *cf_name;
  4875. + cf = iter->data;
  4876. + cf_name = root_filename_alloc(conf, cf->name);
  4877. + /* Ignore if this was a conffile in old_pkg as well */
  4878. + if (pkg_get_conffile(old_pkg, cf->name)) {
  4879. + continue;
  4880. + }
  4881. +
  4882. + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
  4883. + err = backup_make_backup(conf, cf_name);
  4884. + if (err) {
  4885. + return err;
  4886. + }
  4887. + }
  4888. + free(cf_name);
  4889. + }
  4890. +
  4891. + return 0;
  4892. +}
  4893. +
  4894. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg)
  4895. +{
  4896. + conffile_list_elt_t *iter;
  4897. +
  4898. + if (old_pkg) {
  4899. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4900. + backup_remove(iter->data->name);
  4901. + }
  4902. + }
  4903. +
  4904. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4905. + backup_remove(iter->data->name);
  4906. + }
  4907. +
  4908. + return 0;
  4909. +}
  4910. +
  4911. +
  4912. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4913. +{
  4914. + /* DPKG_INCOMPATIBILITY:
  4915. + ipkg takes a slightly different approach than dpkg at this
  4916. + point. dpkg installs each file in the new package while
  4917. + creating a backup for any file that is replaced, (so that it
  4918. + can unwind if necessary). To avoid complexity and redundant
  4919. + storage, ipkg doesn't do any installation until later, (at the
  4920. + point at which dpkg removes the backups.
  4921. +
  4922. + But, we do have to check for data file clashes, since after
  4923. + installing a package with a file clash, removing either of the
  4924. + packages involved in the clash has the potential to break the
  4925. + other package.
  4926. + */
  4927. + str_list_t *files_list;
  4928. + str_list_elt_t *iter;
  4929. +
  4930. + int clashes = 0;
  4931. +
  4932. + files_list = pkg_get_installed_files(pkg);
  4933. + for (iter = files_list->head; iter; iter = iter->next) {
  4934. + char *root_filename;
  4935. + char *filename = iter->data;
  4936. + root_filename = root_filename_alloc(conf, filename);
  4937. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  4938. + pkg_t *owner;
  4939. + pkg_t *obs;
  4940. + /* Pre-existing conffiles are OK */
  4941. + /* @@@@ should have way to check that it is a conffile -Jamey */
  4942. + if (backup_exists_for(root_filename)) {
  4943. + continue;
  4944. + }
  4945. +
  4946. + /* Pre-existing files are OK if force-overwrite was asserted. */
  4947. + if (conf->force_overwrite) {
  4948. + /* but we need to change who owns this file */
  4949. + file_hash_set_file_owner(conf, filename, pkg);
  4950. + continue;
  4951. + }
  4952. +
  4953. + owner = file_hash_get_file_owner(conf, filename);
  4954. +
  4955. + /* Pre-existing files are OK if owned by the pkg being upgraded. */
  4956. + if (owner && old_pkg) {
  4957. + if (strcmp(owner->name, old_pkg->name) == 0) {
  4958. + continue;
  4959. + }
  4960. + }
  4961. +
  4962. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  4963. + if (owner) {
  4964. + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
  4965. + if (pkg_replaces(pkg, owner)) {
  4966. + continue;
  4967. + }
  4968. +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
  4969. + then it's ok to overwrite. */
  4970. + if (strcmp(owner->name,pkg->name)==0){
  4971. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  4972. + continue;
  4973. + }
  4974. + }
  4975. +
  4976. + /* Pre-existing files are OK if they are obsolete */
  4977. + obs = hash_table_get(&conf->obs_file_hash, filename);
  4978. + if (obs) {
  4979. + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
  4980. + continue;
  4981. + }
  4982. +
  4983. + /* We have found a clash. */
  4984. + ipkg_message(conf, IPKG_ERROR,
  4985. + "Package %s wants to install file %s\n"
  4986. + "\tBut that file is already provided by package ",
  4987. + pkg->name, filename);
  4988. + if (owner) {
  4989. + ipkg_message(conf, IPKG_ERROR,
  4990. + "%s\n", owner->name);
  4991. + } else {
  4992. + ipkg_message(conf, IPKG_ERROR,
  4993. + "<no package>\nPlease move this file out of the way and try again.\n");
  4994. + }
  4995. + clashes++;
  4996. + }
  4997. + free(root_filename);
  4998. + }
  4999. + pkg_free_installed_files(pkg);
  5000. +
  5001. + return clashes;
  5002. +}
  5003. +
  5004. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg)
  5005. +{
  5006. + /* Basically that's the worst hack I could do to be able to change ownership of
  5007. + file list, but, being that we have no way to unwind the mods, due to structure
  5008. + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
  5009. + What we do here is change the ownership of file in hash if a replace ( or similar events
  5010. + happens )
  5011. + Only the action that are needed to change name should be considered.
  5012. + @@@ To change after 1.0 release.
  5013. + */
  5014. + str_list_t *files_list;
  5015. + str_list_elt_t *iter;
  5016. +
  5017. + int clashes = 0;
  5018. +
  5019. + files_list = pkg_get_installed_files(pkg);
  5020. + for (iter = files_list->head; iter; iter = iter->next) {
  5021. + char *root_filename;
  5022. + char *filename = iter->data;
  5023. + root_filename = root_filename_alloc(conf, filename);
  5024. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5025. + pkg_t *owner;
  5026. +
  5027. + if (conf->force_overwrite) {
  5028. + /* but we need to change who owns this file */
  5029. + file_hash_set_file_owner(conf, filename, pkg);
  5030. + continue;
  5031. + }
  5032. +
  5033. + owner = file_hash_get_file_owner(conf, filename);
  5034. +
  5035. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5036. + if (owner) {
  5037. + if (pkg_replaces(pkg, owner)) {
  5038. +/* It's now time to change the owner of that file.
  5039. + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
  5040. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5041. + file_hash_set_file_owner(conf, filename, pkg);
  5042. + continue;
  5043. + }
  5044. + }
  5045. +
  5046. + }
  5047. + free(root_filename);
  5048. + }
  5049. + pkg_free_installed_files(pkg);
  5050. +
  5051. + return clashes;
  5052. +}
  5053. +
  5054. +/*
  5055. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5056. +{
  5057. + Nothing to do since check_data_file_clashes doesn't change state
  5058. + return 0;
  5059. +}
  5060. +*/
  5061. +
  5062. +/*
  5063. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5064. +{
  5065. + DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
  5066. + 1. If the package is being upgraded, call
  5067. + old-postrm upgrade new-version
  5068. + 2. If this fails, attempt:
  5069. + new-postrm failed-upgrade old-version
  5070. + Error unwind, for both cases:
  5071. + old-preinst abort-upgrade new-version
  5072. + return 0;
  5073. +}
  5074. +*/
  5075. +
  5076. +/*
  5077. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5078. +{
  5079. + DPKG_INCOMPATIBILITY:
  5080. + dpkg does some things here that we don't do yet. Do we care?
  5081. + (See postrm_upgrade_old_pkg for details)
  5082. + return 0;
  5083. +}
  5084. +*/
  5085. +
  5086. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5087. +{
  5088. + int err;
  5089. + str_list_t *old_files;
  5090. + str_list_elt_t *of;
  5091. + str_list_t *new_files;
  5092. + str_list_elt_t *nf;
  5093. +
  5094. + if (old_pkg == NULL) {
  5095. + return 0;
  5096. + }
  5097. +
  5098. + old_files = pkg_get_installed_files(old_pkg);
  5099. + new_files = pkg_get_installed_files(pkg);
  5100. +
  5101. + for (of = old_files->head; of; of = of->next) {
  5102. + pkg_t *owner;
  5103. + char *old, *new;
  5104. + old = of->data;
  5105. + for (nf = new_files->head; nf; nf = nf->next) {
  5106. + new = nf->data;
  5107. + if (strcmp(old, new) == 0) {
  5108. + goto NOT_OBSOLETE;
  5109. + }
  5110. + }
  5111. + if (file_is_dir(old)) {
  5112. + continue;
  5113. + }
  5114. + owner = file_hash_get_file_owner(conf, old);
  5115. + if (owner != old_pkg) {
  5116. + /* in case obsolete file no longer belongs to old_pkg */
  5117. + continue;
  5118. + }
  5119. +
  5120. + /* old file is obsolete */
  5121. + ipkg_message(conf, IPKG_INFO,
  5122. + " removing obsolete file %s\n", old);
  5123. + if (!conf->noaction) {
  5124. + err = unlink(old);
  5125. + if (err) {
  5126. + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
  5127. + strerror(errno));
  5128. + }
  5129. + }
  5130. +
  5131. + NOT_OBSOLETE:
  5132. + ;
  5133. + }
  5134. +
  5135. + pkg_free_installed_files(old_pkg);
  5136. + pkg_free_installed_files(pkg);
  5137. +
  5138. + return 0;
  5139. +}
  5140. +
  5141. +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5142. +{
  5143. + int i;
  5144. + int err = 0;
  5145. + char *globpattern;
  5146. + glob_t globbuf;
  5147. + if (0) {
  5148. + if (!pkg->dest) {
  5149. + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
  5150. + return -1;
  5151. + }
  5152. + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
  5153. + err = glob(globpattern, 0, NULL, &globbuf);
  5154. + free(globpattern);
  5155. + if (err) {
  5156. + return err;
  5157. + }
  5158. + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
  5159. + for (i = 0; i < globbuf.gl_pathc; i++) {
  5160. + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
  5161. + globbuf.gl_pathv[i], old_pkg->name);
  5162. + if (!conf->noaction)
  5163. + unlink(globbuf.gl_pathv[i]);
  5164. + }
  5165. + globfree(&globbuf);
  5166. + }
  5167. + return err;
  5168. +}
  5169. +
  5170. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5171. +{
  5172. + int ret;
  5173. + char *prefix;
  5174. +
  5175. + if (old_pkg)
  5176. + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
  5177. + sprintf_alloc(&prefix, "%s.", pkg->name);
  5178. + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
  5179. + pkg->dest->info_dir,
  5180. + prefix);
  5181. + free(prefix);
  5182. + return ret;
  5183. +}
  5184. +
  5185. +/*
  5186. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
  5187. +{
  5188. + DPKG_INCOMPATIBILITY:
  5189. + This is a fairly sophisticated dpkg operation. Shall we
  5190. + skip it?
  5191. +
  5192. + Any packages all of whose files have been overwritten during the
  5193. + installation, and which aren't required for dependencies, are
  5194. + considered to have been removed. For each such package
  5195. + 1. disappearer's-postrm disappear overwriter overwriter-version
  5196. + 2. The package's maintainer scripts are removed
  5197. + 3. It is noted in the status database as being in a sane state,
  5198. + namely not installed (any conffiles it may have are ignored,
  5199. + rather than being removed by dpkg). Note that disappearing
  5200. + packages do not have their prerm called, because dpkg doesn't
  5201. + know in advance that the package is going to vanish.
  5202. +
  5203. +
  5204. + return 0;
  5205. +}
  5206. +*/
  5207. +
  5208. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
  5209. +{
  5210. + int err;
  5211. +
  5212. + /* ipkg takes a slightly different approach to data file backups
  5213. + than dpkg. Rather than removing backups at this point, we
  5214. + actually do the data file installation now. See comments in
  5215. + check_data_file_clashes() for more details. */
  5216. +
  5217. + ipkg_message(conf, IPKG_INFO,
  5218. + " extracting data files to %s\n", pkg->dest->root_dir);
  5219. + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
  5220. + if (err) {
  5221. + return err;
  5222. + }
  5223. +
  5224. + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
  5225. + so we can't save ourself from removing important packages
  5226. + At this point we (should) have extracted the .control file, so it
  5227. + would be a good idea to reload the data in it, and set the Essential
  5228. + state in *pkg. From now on the Essential is back in status file and
  5229. + we can protect again.
  5230. + We should operate this way:
  5231. + fopen the file ( pkg->dest->root_dir/pkg->name.control )
  5232. + check for "Essential" in it
  5233. + set the value in pkg->essential.
  5234. + This new routine could be useful also for every other flag
  5235. + Pigi: 16/03/2004 */
  5236. + set_flags_from_control(conf, pkg) ;
  5237. +
  5238. + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
  5239. + err = pkg_write_filelist(conf, pkg);
  5240. + if (err)
  5241. + return err;
  5242. +
  5243. + /* XXX: FEATURE: ipkg should identify any files which existed
  5244. + before installation and which were overwritten, (see
  5245. + check_data_file_clashes()). What it must do is remove any such
  5246. + files from the filelist of the old package which provided the
  5247. + file. Otherwise, if the old package were removed at some point
  5248. + it would break the new package. Removing the new package will
  5249. + also break the old one, but this cannot be helped since the old
  5250. + package's file has already been deleted. This is the importance
  5251. + of check_data_file_clashes(), and only allowing ipkg to install
  5252. + a clashing package with a user force. */
  5253. +
  5254. + return 0;
  5255. +}
  5256. +
  5257. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
  5258. +{
  5259. + conffile_list_elt_t *iter;
  5260. + conffile_t *cf;
  5261. + char *cf_backup;
  5262. + uint8_t *md5sum;
  5263. +
  5264. +
  5265. + if (conf->noaction) return 0;
  5266. +
  5267. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  5268. + char *root_filename;
  5269. + cf = iter->data;
  5270. + root_filename = root_filename_alloc(conf, cf->name);
  5271. +
  5272. + /* Might need to initialize the md5sum for each conffile */
  5273. + if (cf->value == NULL) {
  5274. + cf->value = (char *)file_md5sum_alloc(root_filename);
  5275. + }
  5276. +
  5277. + if (!file_exists(root_filename)) {
  5278. + free(root_filename);
  5279. + continue;
  5280. + }
  5281. +
  5282. + cf_backup = backup_filename_alloc(root_filename);
  5283. +
  5284. +
  5285. + if (file_exists(cf_backup)) {
  5286. + /* Let's compute md5 to test if files are changed */
  5287. + md5sum = file_md5sum_alloc(cf_backup);
  5288. + if (strcmp( cf->value, (char *)md5sum) != 0 ) {
  5289. + if (conf->force_defaults
  5290. + || user_prefers_old_conffile(cf->name, cf_backup) ) {
  5291. + rename(cf_backup, root_filename);
  5292. + }
  5293. + }
  5294. + unlink(cf_backup);
  5295. + free(md5sum);
  5296. + }
  5297. +
  5298. + free(cf_backup);
  5299. + free(root_filename);
  5300. + }
  5301. +
  5302. + return 0;
  5303. +}
  5304. +
  5305. +static int user_prefers_old_conffile(const char *file_name, const char *backup)
  5306. +{
  5307. + char *response;
  5308. + const char *short_file_name;
  5309. +
  5310. + short_file_name = strrchr(file_name, '/');
  5311. + if (short_file_name) {
  5312. + short_file_name++;
  5313. + } else {
  5314. + short_file_name = file_name;
  5315. + }
  5316. +
  5317. + while (1) {
  5318. + response = get_user_response(" Configuration file '%s'\n"
  5319. + " ==> File on system created by you or by a script.\n"
  5320. + " ==> File also in package provided by package maintainer.\n"
  5321. + " What would you like to do about it ? Your options are:\n"
  5322. + " Y or I : install the package maintainer's version\n"
  5323. + " N or O : keep your currently-installed version\n"
  5324. +#ifdef CONFIG_DIFF
  5325. + " D : show the differences between the versions\n"
  5326. +#endif
  5327. + " The default action is to keep your current version.\n"
  5328. + " *** %s (Y/I/N/O"
  5329. +#ifdef CONFIG_DIFF
  5330. + "/D"
  5331. +#endif
  5332. + ") [default=N] ? ", file_name, short_file_name);
  5333. + if (strcmp(response, "y") == 0
  5334. + || strcmp(response, "i") == 0
  5335. + || strcmp(response, "yes") == 0) {
  5336. + free(response);
  5337. + return 0;
  5338. + }
  5339. +
  5340. +#ifdef CONFIG_DIFF
  5341. + if (strcmp(response, "d") == 0) {
  5342. + char *cmd;
  5343. +
  5344. + free(response);
  5345. + /* XXX: BUG rewrite to use exec or busybox's internal diff */
  5346. + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
  5347. + xsystem(cmd);
  5348. + free(cmd);
  5349. + printf(" [Press ENTER to continue]\n");
  5350. + response = file_read_line_alloc(stdin);
  5351. + free(response);
  5352. + continue;
  5353. + }
  5354. +#endif
  5355. +
  5356. + free(response);
  5357. + return 1;
  5358. + }
  5359. +}
  5360. +
  5361. +/* XXX: CLEANUP: I'd like to move all of the code for
  5362. + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
  5363. + it would make sense to cleanup pkg->tmp_unpack_dir directly from
  5364. + pkg_deinit for example). */
  5365. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
  5366. +{
  5367. + DIR *tmp_dir;
  5368. + struct dirent *dirent;
  5369. + char *tmp_file;
  5370. +
  5371. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  5372. +#error
  5373. + ipkg_message(conf, IPKG_DEBUG,
  5374. + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  5375. + __FUNCTION__, pkg->tmp_unpack_dir);
  5376. + return 0;
  5377. +#endif
  5378. +
  5379. + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
  5380. + tmp_dir = opendir(pkg->tmp_unpack_dir);
  5381. + if (tmp_dir) {
  5382. + while (1) {
  5383. + dirent = readdir(tmp_dir);
  5384. + if (dirent == NULL) {
  5385. + break;
  5386. + }
  5387. + sprintf_alloc(&tmp_file, "%s/%s",
  5388. + pkg->tmp_unpack_dir, dirent->d_name);
  5389. + if (! file_is_dir(tmp_file)) {
  5390. + unlink(tmp_file);
  5391. + }
  5392. + free(tmp_file);
  5393. + }
  5394. + closedir(tmp_dir);
  5395. + rmdir(pkg->tmp_unpack_dir);
  5396. + free(pkg->tmp_unpack_dir);
  5397. + pkg->tmp_unpack_dir = NULL;
  5398. + }
  5399. + }
  5400. +
  5401. + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
  5402. + pkg->name, pkg->local_filename, conf->tmp_dir);
  5403. + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
  5404. + unlink(pkg->local_filename);
  5405. + free(pkg->local_filename);
  5406. + pkg->local_filename = NULL;
  5407. + }
  5408. +
  5409. + return 0;
  5410. +}
  5411. +
  5412. +static char *backup_filename_alloc(const char *file_name)
  5413. +{
  5414. + char *backup;
  5415. +
  5416. + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
  5417. +
  5418. + return backup;
  5419. +}
  5420. +
  5421. +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
  5422. +{
  5423. + int err;
  5424. + char *backup;
  5425. +
  5426. + backup = backup_filename_alloc(file_name);
  5427. + err = file_copy(file_name, backup);
  5428. + if (err) {
  5429. + ipkg_message(conf, IPKG_ERROR,
  5430. + "%s: Failed to copy %s to %s\n",
  5431. + __FUNCTION__, file_name, backup);
  5432. + }
  5433. +
  5434. + free(backup);
  5435. +
  5436. + return err;
  5437. +}
  5438. +
  5439. +static int backup_exists_for(const char *file_name)
  5440. +{
  5441. + int ret;
  5442. + char *backup;
  5443. +
  5444. + backup = backup_filename_alloc(file_name);
  5445. +
  5446. + ret = file_exists(backup);
  5447. +
  5448. + free(backup);
  5449. +
  5450. + return ret;
  5451. +}
  5452. +
  5453. +static int backup_remove(const char *file_name)
  5454. +{
  5455. + char *backup;
  5456. +
  5457. + backup = backup_filename_alloc(file_name);
  5458. + unlink(backup);
  5459. + free(backup);
  5460. +
  5461. + return 0;
  5462. +}
  5463. +
  5464. +
  5465. +
  5466. +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
  5467. +
  5468. +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
  5469. +{
  5470. + /* first, remove the packages that need removing */
  5471. + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
  5472. + pkg_t *pkg = pkgs_to_remove->pkgs[i];
  5473. + err = ipkg_remove_pkg(conf, pkg,0);
  5474. + if (err) return err;
  5475. + }
  5476. + return 0;
  5477. +}
  5478. +
  5479. +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)
  5480. +{
  5481. + int i;
  5482. + /* now one more pass checking on the ones that need to be installed */
  5483. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5484. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5485. + if (pkg->dest == NULL)
  5486. + pkg->dest = conf->default_dest;
  5487. +
  5488. + pkg->state_want = SW_INSTALL;
  5489. +
  5490. + /* Abhaya: conflicts check */
  5491. + err = check_conflicts_for(conf, pkg);
  5492. + if (err) { return err; }
  5493. + }
  5494. + return 0;
  5495. +}
  5496. +
  5497. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5498. +{
  5499. + int i;
  5500. + /* now one more pass checking on the ones that need to be installed */
  5501. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5502. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5503. +
  5504. + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
  5505. + pkg_vec_t *replacees = pkg_vec_alloc();
  5506. + pkg_get_installed_replacees(pkg, replacees);
  5507. +
  5508. + /* XXX: BUG: we really should treat replacement more like an upgrade
  5509. + * Instead, we're going to remove the replacees
  5510. + */
  5511. + err = pkg_remove_installed_replacees(conf, replacees);
  5512. + if (err) return err;
  5513. + pkg->state_flag |= SF_REMOVED_REPLACEES;
  5514. + }
  5515. + return 0;
  5516. +}
  5517. +
  5518. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5519. +{
  5520. + int i;
  5521. + /* now one more pass checking on the ones that need to be installed */
  5522. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5523. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5524. + if (pkg->local_filename == NULL) {
  5525. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  5526. + if (err) {
  5527. + ipkg_message(conf, IPKG_ERROR,
  5528. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  5529. + pkg->name);
  5530. + return err;
  5531. + }
  5532. + }
  5533. + if (pkg->tmp_unpack_dir == NULL) {
  5534. + err = unpack_pkg_control_files(conf, pkg);
  5535. + if (err) return err;
  5536. + }
  5537. + }
  5538. + return 0;
  5539. +}
  5540. +
  5541. +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5542. +{
  5543. + int i;
  5544. + /* now one more pass checking on the ones that need to be installed */
  5545. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5546. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5547. + pkg_t *old_pkg = pkg->old_pkg;
  5548. +
  5549. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  5550. + if (err) return err;
  5551. +
  5552. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  5553. + if (err) return err;
  5554. +
  5555. + err = preinst_configure(conf, pkg, old_pkg);
  5556. + if (err) return err;
  5557. +
  5558. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  5559. + if (err) return err;
  5560. +
  5561. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  5562. + if (err) return err;
  5563. + }
  5564. + return 0;
  5565. +}
  5566. +
  5567. +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5568. +{
  5569. + int i;
  5570. + /* now one more pass checking on the ones that need to be installed */
  5571. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5572. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5573. + pkg_t *old_pkg = pkg->old_pkg;
  5574. +
  5575. + if (old_pkg) {
  5576. + old_pkg->state_want = SW_DEINSTALL;
  5577. +
  5578. + if (old_pkg->state_flag & SF_NOPRUNE) {
  5579. + ipkg_message(conf, IPKG_INFO,
  5580. + " not removing obsolesced files because package marked noprune\n");
  5581. + } else {
  5582. + ipkg_message(conf, IPKG_INFO,
  5583. + " removing obsolesced files\n");
  5584. + remove_obsolesced_files(conf, pkg, old_pkg);
  5585. + }
  5586. + }
  5587. +
  5588. + ipkg_message(conf, IPKG_INFO,
  5589. + " installing maintainer scripts\n");
  5590. + install_maintainer_scripts(conf, pkg, old_pkg);
  5591. +
  5592. + /* the following just returns 0 */
  5593. + remove_disappeared(conf, pkg);
  5594. +
  5595. + ipkg_message(conf, IPKG_INFO,
  5596. + " installing data files\n");
  5597. + install_data_files(conf, pkg);
  5598. +
  5599. + ipkg_message(conf, IPKG_INFO,
  5600. + " resolving conf files\n");
  5601. + resolve_conffiles(conf, pkg);
  5602. +
  5603. + pkg->state_status = SS_UNPACKED;
  5604. +
  5605. + if (old_pkg) {
  5606. + old_pkg->state_status = SS_NOT_INSTALLED;
  5607. + }
  5608. +
  5609. + time(&pkg->installed_time);
  5610. +
  5611. + ipkg_message(conf, IPKG_INFO,
  5612. + " cleanup temp files\n");
  5613. + cleanup_temporary_files(conf, pkg);
  5614. +
  5615. + if (pkg->parent)
  5616. + pkg->parent->state_status = pkg->state_status;
  5617. + }
  5618. + return 0;
  5619. +}
  5620. +
  5621. +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5622. +{
  5623. + int i;
  5624. + /* now one more pass checking on the ones that need to be installed */
  5625. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5626. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5627. + pkg_t *old_pkg = pkg->old_pkg;
  5628. +
  5629. + if (old_pkg) {
  5630. + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
  5631. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5632. + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
  5633. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  5634. + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
  5635. + backup_modified_conffiles_unwind(pkg, old_pkg);
  5636. + */
  5637. + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
  5638. + preinst_configure_unwind(conf, pkg, old_pkg);
  5639. + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
  5640. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  5641. + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
  5642. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5643. + */
  5644. +
  5645. + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
  5646. + remove_installed_replacees_unwind(conf, pkg, old_pkg);
  5647. +
  5648. + }
  5649. + }
  5650. + return 0;
  5651. +}
  5652. +
  5653. +/*
  5654. + * Perform all the actions.
  5655. + *
  5656. + * pkgs_to_remove are packages marked for removal.
  5657. + * pkgs_superseded are the old packages being replaced by upgrades.
  5658. + *
  5659. + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
  5660. + */
  5661. +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)
  5662. +{
  5663. + int err;
  5664. + int i;
  5665. +
  5666. + err = ipkg_remove_packages(conf, pkgs_to_remove);
  5667. + if (err) return err;
  5668. +
  5669. + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
  5670. + if (err) return err;
  5671. +
  5672. + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
  5673. + if (err) goto UNWIND;
  5674. +
  5675. + /* @@@@ look at ipkg_install_pkg for handling replacements */
  5676. + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
  5677. + if (err) goto UNWIND;
  5678. +
  5679. + /*
  5680. + * Now that we have the packages unpacked, we can look for data
  5681. + * file clashes. First, we mark the files from the superseded
  5682. + * packages as obsolete. Then we scan the files in
  5683. + * pkgs_to_install, and only complain about clashes with
  5684. + * non-obsolete files.
  5685. + */
  5686. +
  5687. + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
  5688. + if (err) goto UNWIND;
  5689. +
  5690. + /* this was before checking data file clashes */
  5691. + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
  5692. + if (err) goto UNWIND;
  5693. +
  5694. + /* point of no return: no unwinding after this */
  5695. + err = ipkg_process_actions_install(conf, pkgs_to_install);
  5696. + if (err) return err;
  5697. +
  5698. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  5699. + return 0;
  5700. +
  5701. + UNWIND:
  5702. + ipkg_process_actions_unwind(conf, pkgs_to_install);
  5703. +
  5704. + ipkg_message(conf, IPKG_INFO,
  5705. + " cleanup temp files\n");
  5706. + cleanup_temporary_files(conf, pkg);
  5707. +
  5708. + ipkg_message(conf, IPKG_INFO,
  5709. + "Failed.\n");
  5710. + return err;
  5711. +}
  5712. +
  5713. +#endif
  5714. diff -Nur busybox-1.20.2.orig//archival/libipkg/ipkg_install.h busybox-1.20.2/archival/libipkg/ipkg_install.h
  5715. --- busybox-1.20.2.orig//archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
  5716. +++ busybox-1.20.2/archival/libipkg/ipkg_install.h 2013-01-31 16:44:31.000000000 +0100
  5717. @@ -0,0 +1,35 @@
  5718. +/* ipkg_install.h - the itsy package management system
  5719. +
  5720. + Carl D. Worth
  5721. +
  5722. + Copyright (C) 2001 University of Southern California
  5723. +
  5724. + This program is free software; you can redistribute it and/or
  5725. + modify it under the terms of the GNU General Public License as
  5726. + published by the Free Software Foundation; either version 2, or (at
  5727. + your option) any later version.
  5728. +
  5729. + This program is distributed in the hope that it will be useful, but
  5730. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5731. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5732. + General Public License for more details.
  5733. +*/
  5734. +
  5735. +#ifndef IPKG_INSTALL_H
  5736. +#define IPKG_INSTALL_H
  5737. +
  5738. +#include "pkg.h"
  5739. +#include "ipkg_conf.h"
  5740. +
  5741. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5742. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5743. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
  5744. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
  5745. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  5746. +
  5747. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
  5748. +
  5749. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
  5750. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
  5751. +
  5752. +#endif
  5753. diff -Nur busybox-1.20.2.orig//archival/libipkg/ipkg_message.c busybox-1.20.2/archival/libipkg/ipkg_message.c
  5754. --- busybox-1.20.2.orig//archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
  5755. +++ busybox-1.20.2/archival/libipkg/ipkg_message.c 2013-01-31 16:44:31.000000000 +0100
  5756. @@ -0,0 +1,35 @@
  5757. +/* ipkg_message.c - the itsy package management system
  5758. +
  5759. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5760. +
  5761. + This program is free software; you can redistribute it and/or
  5762. + modify it under the terms of the GNU General Public License as
  5763. + published by the Free Software Foundation; either version 2, or (at
  5764. + your option) any later version.
  5765. +
  5766. + This program is distributed in the hope that it will be useful, but
  5767. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5768. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5769. + General Public License for more details.
  5770. +*/
  5771. +
  5772. +
  5773. +#include "ipkg.h"
  5774. +#include "ipkg_conf.h"
  5775. +#include "ipkg_message.h"
  5776. +#include "libipkg.h"
  5777. +
  5778. +void
  5779. +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
  5780. +{
  5781. + va_list ap;
  5782. + char ts[256];
  5783. +
  5784. + if (ipkg_cb_message)
  5785. + {
  5786. + va_start (ap, fmt);
  5787. + vsnprintf (ts,256,fmt, ap);
  5788. + va_end (ap);
  5789. + ipkg_cb_message(conf,level,ts);
  5790. + }
  5791. +}
  5792. diff -Nur busybox-1.20.2.orig//archival/libipkg/ipkg_message.h busybox-1.20.2/archival/libipkg/ipkg_message.h
  5793. --- busybox-1.20.2.orig//archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
  5794. +++ busybox-1.20.2/archival/libipkg/ipkg_message.h 2013-01-31 16:44:31.000000000 +0100
  5795. @@ -0,0 +1,32 @@
  5796. +/* ipkg_message.h - the itsy package management system
  5797. +
  5798. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5799. +
  5800. + This program is free software; you can redistribute it and/or
  5801. + modify it under the terms of the GNU General Public License as
  5802. + published by the Free Software Foundation; either version 2, or (at
  5803. + your option) any later version.
  5804. +
  5805. + This program is distributed in the hope that it will be useful, but
  5806. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5807. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5808. + General Public License for more details.
  5809. +*/
  5810. +
  5811. +#ifndef _IPKG_MESSAGE_H_
  5812. +#define _IPKG_MESSAGE_H_
  5813. +
  5814. +#include "ipkg.h"
  5815. +#include "ipkg_conf.h"
  5816. +
  5817. +typedef enum {
  5818. + IPKG_ERROR, /* error conditions */
  5819. + IPKG_NOTICE, /* normal but significant condition */
  5820. + IPKG_INFO, /* informational message */
  5821. + IPKG_DEBUG, /* debug level message */
  5822. + IPKG_DEBUG2, /* more debug level message */
  5823. +} message_level_t;
  5824. +
  5825. +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
  5826. +
  5827. +#endif /* _IPKG_MESSAGE_H_ */
  5828. diff -Nur busybox-1.20.2.orig//archival/libipkg/ipkg_remove.c busybox-1.20.2/archival/libipkg/ipkg_remove.c
  5829. --- busybox-1.20.2.orig//archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
  5830. +++ busybox-1.20.2/archival/libipkg/ipkg_remove.c 2013-01-31 16:44:31.000000000 +0100
  5831. @@ -0,0 +1,385 @@
  5832. +/* ipkg_remove.c - the itsy package management system
  5833. +
  5834. + Carl D. Worth
  5835. +
  5836. + Copyright (C) 2001 University of Southern California
  5837. +
  5838. + This program is free software; you can redistribute it and/or
  5839. + modify it under the terms of the GNU General Public License as
  5840. + published by the Free Software Foundation; either version 2, or (at
  5841. + your option) any later version.
  5842. +
  5843. + This program is distributed in the hope that it will be useful, but
  5844. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5845. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5846. + General Public License for more details.
  5847. +*/
  5848. +
  5849. +#include "ipkg.h"
  5850. +#include "ipkg_message.h"
  5851. +
  5852. +#include <glob.h>
  5853. +
  5854. +#include "ipkg_remove.h"
  5855. +
  5856. +#include "file_util.h"
  5857. +#include "sprintf_alloc.h"
  5858. +#include "str_util.h"
  5859. +
  5860. +#include "ipkg_cmd.h"
  5861. +
  5862. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents);
  5863. +
  5864. +/*
  5865. + * Returns number of the number of packages depending on the packages provided by this package.
  5866. + * Every package implicitly provides itself.
  5867. + */
  5868. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents)
  5869. +{
  5870. + int nprovides = pkg->provides_count;
  5871. + abstract_pkg_t **provides = pkg->provides;
  5872. + int n_installed_dependents = 0;
  5873. + int i;
  5874. + for (i = 0; i <= nprovides; i++) {
  5875. + abstract_pkg_t *providee = provides[i];
  5876. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5877. + abstract_pkg_t *dep_ab_pkg;
  5878. + if (dependers == NULL)
  5879. + continue;
  5880. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5881. + if (dep_ab_pkg->state_status == SS_INSTALLED){
  5882. + n_installed_dependents++;
  5883. + }
  5884. + }
  5885. +
  5886. + }
  5887. + /* if caller requested the set of installed dependents */
  5888. + if (pdependents) {
  5889. + int p = 0;
  5890. + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
  5891. +
  5892. + if ( dependents == NULL ){
  5893. + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
  5894. + return -1;
  5895. + }
  5896. +
  5897. + *pdependents = dependents;
  5898. + for (i = 0; i <= nprovides; i++) {
  5899. + abstract_pkg_t *providee = provides[i];
  5900. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5901. + abstract_pkg_t *dep_ab_pkg;
  5902. + if (dependers == NULL)
  5903. + continue;
  5904. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5905. + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
  5906. + dependents[p++] = dep_ab_pkg;
  5907. + dep_ab_pkg->state_flag |= SF_MARKED;
  5908. + }
  5909. + }
  5910. + }
  5911. + dependents[p] = NULL;
  5912. + /* now clear the marks */
  5913. + for (i = 0; i < p; i++) {
  5914. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5915. + dep_ab_pkg->state_flag &= ~SF_MARKED;
  5916. + }
  5917. + }
  5918. + return n_installed_dependents;
  5919. +}
  5920. +
  5921. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5922. +{
  5923. + int i;
  5924. + int a;
  5925. + int count;
  5926. + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
  5927. + abstract_pkg_t * ab_pkg;
  5928. +
  5929. + if((ab_pkg = pkg->parent) == NULL){
  5930. + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
  5931. + __FUNCTION__, pkg->name);
  5932. + return 0;
  5933. + }
  5934. +
  5935. + if (dependents == NULL)
  5936. + return 0;
  5937. +
  5938. + // here i am using the dependencies_checked
  5939. + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
  5940. + return 0; // has already been encountered in the process
  5941. + // of marking packages for removal - Karthik
  5942. + ab_pkg->dependencies_checked = 2;
  5943. +
  5944. + i = 0;
  5945. + count = 1;
  5946. + while (dependents [i] != NULL) {
  5947. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5948. +
  5949. + if (dep_ab_pkg->dependencies_checked == 2){
  5950. + i++;
  5951. + continue;
  5952. + }
  5953. + if (dep_ab_pkg->state_status == SS_INSTALLED) {
  5954. + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
  5955. + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
  5956. + if (dep_pkg->state_status == SS_INSTALLED) {
  5957. + pkg_vec_insert(dependent_pkgs, dep_pkg);
  5958. + count++;
  5959. + }
  5960. + }
  5961. + }
  5962. + i++;
  5963. + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
  5964. + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
  5965. + }
  5966. +
  5967. + if (count == 1)
  5968. + return 0;
  5969. +
  5970. +
  5971. + for (i = 0; i < dependent_pkgs->len; i++) {
  5972. + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
  5973. + if (err)
  5974. + return err;
  5975. + }
  5976. + return 0;
  5977. +}
  5978. +
  5979. +static int user_prefers_removing_dependents(ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5980. +{
  5981. + abstract_pkg_t *dep_ab_pkg;
  5982. + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
  5983. + while ((dep_ab_pkg = *dependents++) != NULL) {
  5984. + if (dep_ab_pkg->state_status == SS_INSTALLED)
  5985. + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
  5986. + }
  5987. + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
  5988. + ipkg_message(conf, IPKG_ERROR, "");
  5989. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
  5990. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
  5991. + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
  5992. + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
  5993. + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
  5994. + return 0;
  5995. +}
  5996. +
  5997. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
  5998. +{
  5999. +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
  6000. + thus I wan't check for essential, as I'm upgrading.
  6001. + I hope it won't break anything :)
  6002. +*/
  6003. + int err;
  6004. + abstract_pkg_t *parent_pkg = NULL;
  6005. +
  6006. + if (pkg->essential && !message) {
  6007. + if (conf->force_removal_of_essential_packages) {
  6008. + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
  6009. + "\tIf your system breaks, you get to keep both pieces\n",
  6010. + pkg->name);
  6011. + } else {
  6012. + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
  6013. + "\tRemoving an essential package may lead to an unusable system, but if\n"
  6014. + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
  6015. + "\tits will with the option: -force-removal-of-essential-packages\n",
  6016. + pkg->name);
  6017. + return IPKG_PKG_IS_ESSENTIAL;
  6018. + }
  6019. + }
  6020. +
  6021. + if ((parent_pkg = pkg->parent) == NULL)
  6022. + return 0;
  6023. +
  6024. + /* only attempt to remove dependent installed packages if
  6025. + * force_depends is not specified or the package is being
  6026. + * replaced.
  6027. + */
  6028. + if (!conf->force_depends
  6029. + && !(pkg->state_flag & SF_REPLACE)) {
  6030. + abstract_pkg_t **dependents;
  6031. + int has_installed_dependents =
  6032. + pkg_has_installed_dependents(pkg, &dependents);
  6033. +
  6034. + if (has_installed_dependents) {
  6035. + /*
  6036. + * if this package is depended up by others, then either we should
  6037. + * not remove it or we should remove it and all of its dependents
  6038. + */
  6039. +
  6040. + if (!conf->force_removal_of_dependent_packages
  6041. + && !user_prefers_removing_dependents(conf, pkg, dependents)) {
  6042. + return IPKG_PKG_HAS_DEPENDENTS;
  6043. + }
  6044. +
  6045. + /* remove packages depending on this package - Karthik */
  6046. + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
  6047. + free(dependents);
  6048. + if (err) return err;
  6049. + }
  6050. + }
  6051. +
  6052. + if ( message==0 ){
  6053. + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
  6054. + fflush(stdout);
  6055. + }
  6056. + pkg->state_flag |= SF_FILELIST_CHANGED;
  6057. +
  6058. + pkg->state_want = SW_DEINSTALL;
  6059. + ipkg_state_changed++;
  6060. +
  6061. + pkg_run_script(conf, pkg, "prerm", "remove");
  6062. +
  6063. + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
  6064. + maintains an empty filelist rather than deleting it. That seems
  6065. + like a big pain, and I don't see that that should make a big
  6066. + difference, but for anyone who wants tighter compatibility,
  6067. + feel free to fix this. */
  6068. + remove_data_files_and_list(conf, pkg);
  6069. +
  6070. + pkg_run_script(conf, pkg, "postrm", "remove");
  6071. +
  6072. + remove_maintainer_scripts_except_postrm(conf, pkg);
  6073. +
  6074. + /* Aman Gupta - Since ipkg is made for handheld devices with limited
  6075. + * space, it doesn't make sense to leave extra configurations, files,
  6076. + * and maintainer scripts left around. So, we make remove like purge,
  6077. + * and take out all the crap :) */
  6078. +
  6079. + remove_postrm(conf, pkg);
  6080. + pkg->state_status = SS_NOT_INSTALLED;
  6081. +
  6082. + if (parent_pkg)
  6083. + parent_pkg->state_status = SS_NOT_INSTALLED;
  6084. +
  6085. + return 0;
  6086. +}
  6087. +
  6088. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
  6089. +{
  6090. + ipkg_remove_pkg(conf, pkg,0);
  6091. + return 0;
  6092. +}
  6093. +
  6094. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
  6095. +{
  6096. + str_list_t installed_dirs;
  6097. + str_list_t *installed_files;
  6098. + str_list_elt_t *iter;
  6099. + char *file_name;
  6100. + conffile_t *conffile;
  6101. + int removed_a_dir;
  6102. + pkg_t *owner;
  6103. +
  6104. + str_list_init(&installed_dirs);
  6105. + installed_files = pkg_get_installed_files(pkg);
  6106. +
  6107. + for (iter = installed_files->head; iter; iter = iter->next) {
  6108. + file_name = iter->data;
  6109. +
  6110. + if (file_is_dir(file_name)) {
  6111. + str_list_append(&installed_dirs, strdup(file_name));
  6112. + continue;
  6113. + }
  6114. +
  6115. + conffile = pkg_get_conffile(pkg, file_name);
  6116. + if (conffile) {
  6117. + /* XXX: QUESTION: Is this right? I figure we only need to
  6118. + save the conffile if it has been modified. Is that what
  6119. + dpkg does? Or does dpkg preserve all conffiles? If so,
  6120. + this seems like a better thing to do to conserve
  6121. + space. */
  6122. + if (conffile_has_been_modified(conf, conffile)) {
  6123. + printf(" not deleting modified conffile %s\n", file_name);
  6124. + fflush(stdout);
  6125. + continue;
  6126. + }
  6127. + }
  6128. +
  6129. + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
  6130. + if (!conf->noaction)
  6131. + unlink(file_name);
  6132. + }
  6133. +
  6134. + if (!conf->noaction) {
  6135. + do {
  6136. + removed_a_dir = 0;
  6137. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6138. + file_name = iter->data;
  6139. +
  6140. + if (rmdir(file_name) == 0) {
  6141. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
  6142. + removed_a_dir = 1;
  6143. + str_list_remove(&installed_dirs, &iter);
  6144. + }
  6145. + }
  6146. + } while (removed_a_dir);
  6147. + }
  6148. +
  6149. + pkg_free_installed_files(pkg);
  6150. + /* We have to remove the file list now, so that
  6151. + find_pkg_owning_file does not always just report this package */
  6152. + pkg_remove_installed_files_list(conf, pkg);
  6153. +
  6154. + /* Don't print warning for dirs that are provided by other packages */
  6155. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6156. + file_name = iter->data;
  6157. +
  6158. + owner = file_hash_get_file_owner(conf, file_name);
  6159. + if (owner) {
  6160. + free(iter->data);
  6161. + iter->data = NULL;
  6162. + str_list_remove(&installed_dirs, &iter);
  6163. + }
  6164. + }
  6165. +
  6166. + /* cleanup */
  6167. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6168. + free(iter->data);
  6169. + iter->data = NULL;
  6170. + }
  6171. + str_list_deinit(&installed_dirs);
  6172. +
  6173. + return 0;
  6174. +}
  6175. +
  6176. +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6177. +{
  6178. + int i, err;
  6179. + char *globpattern;
  6180. + glob_t globbuf;
  6181. +
  6182. + if (conf->noaction) return 0;
  6183. +
  6184. + sprintf_alloc(&globpattern, "%s/%s.*",
  6185. + pkg->dest->info_dir, pkg->name);
  6186. + err = glob(globpattern, 0, NULL, &globbuf);
  6187. + free(globpattern);
  6188. + if (err) {
  6189. + return 0;
  6190. + }
  6191. +
  6192. + for (i = 0; i < globbuf.gl_pathc; i++) {
  6193. + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
  6194. + continue;
  6195. + }
  6196. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
  6197. + unlink(globbuf.gl_pathv[i]);
  6198. + }
  6199. + globfree(&globbuf);
  6200. +
  6201. + return 0;
  6202. +}
  6203. +
  6204. +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6205. +{
  6206. + char *postrm_file_name;
  6207. +
  6208. + if (conf->noaction) return 0;
  6209. +
  6210. + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
  6211. + pkg->dest->info_dir, pkg->name);
  6212. + unlink(postrm_file_name);
  6213. + free(postrm_file_name);
  6214. +
  6215. + return 0;
  6216. +}
  6217. diff -Nur busybox-1.20.2.orig//archival/libipkg/ipkg_remove.h busybox-1.20.2/archival/libipkg/ipkg_remove.h
  6218. --- busybox-1.20.2.orig//archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
  6219. +++ busybox-1.20.2/archival/libipkg/ipkg_remove.h 2013-01-31 16:44:31.000000000 +0100
  6220. @@ -0,0 +1,33 @@
  6221. +/* ipkg_remove.h - the itsy package management system
  6222. +
  6223. + Carl D. Worth
  6224. +
  6225. + Copyright (C) 2001 University of Southern California
  6226. +
  6227. + This program is free software; you can redistribute it and/or
  6228. + modify it under the terms of the GNU General Public License as
  6229. + published by the Free Software Foundation; either version 2, or (at
  6230. + your option) any later version.
  6231. +
  6232. + This program is distributed in the hope that it will be useful, but
  6233. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6234. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6235. + General Public License for more details.
  6236. +*/
  6237. +
  6238. +#ifndef IPKG_REMOVE_H
  6239. +#define IPKG_REMOVE_H
  6240. +
  6241. +#include "pkg.h"
  6242. +#include "ipkg_conf.h"
  6243. +
  6244. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
  6245. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
  6246. +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
  6247. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents);
  6248. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
  6249. +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6250. +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6251. +
  6252. +
  6253. +#endif
  6254. diff -Nur busybox-1.20.2.orig//archival/libipkg/ipkg_upgrade.c busybox-1.20.2/archival/libipkg/ipkg_upgrade.c
  6255. --- busybox-1.20.2.orig//archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
  6256. +++ busybox-1.20.2/archival/libipkg/ipkg_upgrade.c 2013-01-31 16:44:31.000000000 +0100
  6257. @@ -0,0 +1,79 @@
  6258. +/* ipkg_upgrade.c - the itsy package management system
  6259. +
  6260. + Carl D. Worth
  6261. + Copyright (C) 2001 University of Southern California
  6262. +
  6263. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6264. +
  6265. + This program is free software; you can redistribute it and/or
  6266. + modify it under the terms of the GNU General Public License as
  6267. + published by the Free Software Foundation; either version 2, or (at
  6268. + your option) any later version.
  6269. +
  6270. + This program is distributed in the hope that it will be useful, but
  6271. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6272. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6273. + General Public License for more details.
  6274. +*/
  6275. +
  6276. +#include "ipkg.h"
  6277. +#include "ipkg_install.h"
  6278. +#include "ipkg_message.h"
  6279. +
  6280. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6281. +
  6282. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
  6283. +{
  6284. + pkg_t *new;
  6285. + int cmp;
  6286. + char *old_version, *new_version;
  6287. +
  6288. + if (old->state_flag & SF_HOLD) {
  6289. + ipkg_message(conf, IPKG_NOTICE,
  6290. + "Not upgrading package %s which is marked "
  6291. + "hold (flags=%#x)\n", old->name, old->state_flag);
  6292. + return 0;
  6293. + }
  6294. +
  6295. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
  6296. + if (new == NULL) {
  6297. + old_version = pkg_version_str_alloc(old);
  6298. + ipkg_message(conf, IPKG_NOTICE,
  6299. + "Assuming locally installed package %s (%s) "
  6300. + "is up to date.\n", old->name, old_version);
  6301. + free(old_version);
  6302. + return 0;
  6303. + }
  6304. +
  6305. + old_version = pkg_version_str_alloc(old);
  6306. + new_version = pkg_version_str_alloc(new);
  6307. +
  6308. + cmp = pkg_compare_versions(old, new);
  6309. + ipkg_message(conf, IPKG_DEBUG,
  6310. + "comparing visible versions of pkg %s:"
  6311. + "\n\t%s is installed "
  6312. + "\n\t%s is available "
  6313. + "\n\t%d was comparison result\n",
  6314. + old->name, old_version, new_version, cmp);
  6315. + if (cmp == 0) {
  6316. + ipkg_message(conf, IPKG_INFO,
  6317. + "Package %s (%s) installed in %s is up to date.\n",
  6318. + old->name, old_version, old->dest->name);
  6319. + free(old_version);
  6320. + free(new_version);
  6321. + return 0;
  6322. + } else if (cmp > 0) {
  6323. + ipkg_message(conf, IPKG_NOTICE,
  6324. + "Not downgrading package %s on %s from %s to %s.\n",
  6325. + old->name, old->dest->name, old_version, new_version);
  6326. + free(old_version);
  6327. + free(new_version);
  6328. + return 0;
  6329. + } else if (cmp < 0) {
  6330. + new->dest = old->dest;
  6331. + old->state_want = SW_DEINSTALL;
  6332. + }
  6333. +
  6334. + new->state_flag |= SF_USER;
  6335. + return ipkg_install_pkg(conf, new,1);
  6336. +}
  6337. diff -Nur busybox-1.20.2.orig//archival/libipkg/ipkg_upgrade.h busybox-1.20.2/archival/libipkg/ipkg_upgrade.h
  6338. --- busybox-1.20.2.orig//archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
  6339. +++ busybox-1.20.2/archival/libipkg/ipkg_upgrade.h 2013-01-31 16:44:31.000000000 +0100
  6340. @@ -0,0 +1,18 @@
  6341. +/* ipkg_upgrade.c - the itsy package management system
  6342. +
  6343. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6344. +
  6345. + This program is free software; you can redistribute it and/or
  6346. + modify it under the terms of the GNU General Public License as
  6347. + published by the Free Software Foundation; either version 2, or (at
  6348. + your option) any later version.
  6349. +
  6350. + This program is distributed in the hope that it will be useful, but
  6351. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6352. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6353. + General Public License for more details.
  6354. +*/
  6355. +
  6356. +#include "ipkg.h"
  6357. +
  6358. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6359. diff -Nur busybox-1.20.2.orig//archival/libipkg/ipkg_utils.c busybox-1.20.2/archival/libipkg/ipkg_utils.c
  6360. --- busybox-1.20.2.orig//archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
  6361. +++ busybox-1.20.2/archival/libipkg/ipkg_utils.c 2013-01-31 16:44:31.000000000 +0100
  6362. @@ -0,0 +1,185 @@
  6363. +/* ipkg_utils.c - the itsy package management system
  6364. +
  6365. + Steven M. Ayer
  6366. +
  6367. + Copyright (C) 2002 Compaq Computer Corporation
  6368. +
  6369. + This program is free software; you can redistribute it and/or
  6370. + modify it under the terms of the GNU General Public License as
  6371. + published by the Free Software Foundation; either version 2, or (at
  6372. + your option) any later version.
  6373. +
  6374. + This program is distributed in the hope that it will be useful, but
  6375. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6376. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6377. + General Public License for more details.
  6378. +*/
  6379. +
  6380. +#include "ipkg.h"
  6381. +#include <errno.h>
  6382. +#include <ctype.h>
  6383. +#include <sys/vfs.h>
  6384. +
  6385. +#include "ipkg_utils.h"
  6386. +#include "pkg.h"
  6387. +#include "pkg_hash.h"
  6388. +
  6389. +void push_error_list(struct errlist ** errors, char * msg);
  6390. +void reverse_error_list(struct errlist **errors);
  6391. +void free_error_list(struct errlist **errors);
  6392. +
  6393. +struct errlist* error_list;
  6394. +
  6395. +int get_available_blocks(char * filesystem)
  6396. +{
  6397. + struct statfs sfs;
  6398. +
  6399. + if(statfs(filesystem, &sfs)){
  6400. + fprintf(stderr, "bad statfs\n");
  6401. + return 0;
  6402. + }
  6403. + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
  6404. + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
  6405. +}
  6406. +
  6407. +char **read_raw_pkgs_from_file(const char *file_name)
  6408. +{
  6409. + FILE *fp;
  6410. + char **ret;
  6411. +
  6412. + if(!(fp = fopen(file_name, "r"))){
  6413. + fprintf(stderr, "can't get %s open for read\n", file_name);
  6414. + return NULL;
  6415. + }
  6416. +
  6417. + ret = read_raw_pkgs_from_stream(fp);
  6418. +
  6419. + fclose(fp);
  6420. +
  6421. + return ret;
  6422. +}
  6423. +
  6424. +char **read_raw_pkgs_from_stream(FILE *fp)
  6425. +{
  6426. + char **raw = NULL, *buf, *scout;
  6427. + int count = 0;
  6428. + size_t size = 512;
  6429. +
  6430. + buf = malloc (size);
  6431. +
  6432. + while (fgets(buf, size, fp)) {
  6433. + while (strlen (buf) == (size - 1)
  6434. + && buf[size-2] != '\n') {
  6435. + size_t o = size - 1;
  6436. + size *= 2;
  6437. + buf = realloc (buf, size);
  6438. + if (fgets (buf + o, size - o, fp) == NULL)
  6439. + break;
  6440. + }
  6441. +
  6442. + if(!(count % 50))
  6443. + raw = realloc(raw, (count + 50) * sizeof(char *));
  6444. +
  6445. + if((scout = strchr(buf, '\n')))
  6446. + *scout = '\0';
  6447. +
  6448. + raw[count++] = strdup(buf);
  6449. + }
  6450. +
  6451. + raw = realloc(raw, (count + 1) * sizeof(char *));
  6452. + raw[count] = NULL;
  6453. +
  6454. + free (buf);
  6455. +
  6456. + return raw;
  6457. +}
  6458. +
  6459. +/* something to remove whitespace, a hash pooper */
  6460. +char *trim_alloc(char *line)
  6461. +{
  6462. + char *new;
  6463. + char *dest, *src, *end;
  6464. +
  6465. + new = malloc(strlen(line) + 1);
  6466. + if ( new == NULL ){
  6467. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  6468. + return NULL;
  6469. + }
  6470. + dest = new, src = line, end = line + (strlen(line) - 1);
  6471. +
  6472. + /* remove it from the front */
  6473. + while(src &&
  6474. + isspace(*src) &&
  6475. + *src)
  6476. + src++;
  6477. + /* and now from the back */
  6478. + while((end > src) &&
  6479. + isspace(*end))
  6480. + end--;
  6481. + end++;
  6482. + *end = '\0';
  6483. + strcpy(new, src);
  6484. + /* this does from the first space
  6485. + * blasting away any versions stuff in depends
  6486. + while(src &&
  6487. + !isspace(*src) &&
  6488. + *src)
  6489. + *dest++ = *src++;
  6490. + *dest = '\0';
  6491. + */
  6492. +
  6493. + return new;
  6494. +}
  6495. +
  6496. +int line_is_blank(const char *line)
  6497. +{
  6498. + const char *s;
  6499. +
  6500. + for (s = line; *s; s++) {
  6501. + if (!isspace(*s))
  6502. + return 0;
  6503. + }
  6504. + return 1;
  6505. +}
  6506. +
  6507. +void push_error_list(struct errlist ** errors, char * msg){
  6508. + struct errlist *err_lst_tmp;
  6509. +
  6510. +
  6511. + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
  6512. + err_lst_tmp->errmsg=strdup(msg) ;
  6513. + err_lst_tmp->next = *errors;
  6514. + *errors = err_lst_tmp;
  6515. +}
  6516. +
  6517. +
  6518. +void reverse_error_list(struct errlist **errors){
  6519. + struct errlist *result=NULL;
  6520. + struct errlist *current= *errors;
  6521. + struct errlist *next;
  6522. +
  6523. + while ( current != NULL ) {
  6524. + next = current->next;
  6525. + current->next=result;
  6526. + result=current;
  6527. + current=next;
  6528. + }
  6529. + *errors=result;
  6530. +
  6531. +}
  6532. +
  6533. +
  6534. +void free_error_list(struct errlist **errors){
  6535. + struct errlist *current = *errors;
  6536. +
  6537. + while (current != NULL) {
  6538. + free(current->errmsg);
  6539. + current = (*errors)->next;
  6540. + free(*errors);
  6541. + *errors = current;
  6542. + }
  6543. +
  6544. +
  6545. +}
  6546. +
  6547. +
  6548. diff -Nur busybox-1.20.2.orig//archival/libipkg/ipkg_utils.h busybox-1.20.2/archival/libipkg/ipkg_utils.h
  6549. --- busybox-1.20.2.orig//archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
  6550. +++ busybox-1.20.2/archival/libipkg/ipkg_utils.h 2013-01-31 16:44:31.000000000 +0100
  6551. @@ -0,0 +1,29 @@
  6552. +/* ipkg_utils.h - the itsy package management system
  6553. +
  6554. + Steven M. Ayer
  6555. +
  6556. + Copyright (C) 2002 Compaq Computer Corporation
  6557. +
  6558. + This program is free software; you can redistribute it and/or
  6559. + modify it under the terms of the GNU General Public License as
  6560. + published by the Free Software Foundation; either version 2, or (at
  6561. + your option) any later version.
  6562. +
  6563. + This program is distributed in the hope that it will be useful, but
  6564. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6565. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6566. + General Public License for more details.
  6567. +*/
  6568. +
  6569. +#ifndef IPKG_UTILS_H
  6570. +#define IPKG_UTILS_H
  6571. +
  6572. +#include "pkg.h"
  6573. +
  6574. +int get_available_blocks(char * filesystem);
  6575. +char **read_raw_pkgs_from_file(const char *file_name);
  6576. +char **read_raw_pkgs_from_stream(FILE *fp);
  6577. +char *trim_alloc(char * line);
  6578. +int line_is_blank(const char *line);
  6579. +
  6580. +#endif
  6581. diff -Nur busybox-1.20.2.orig//archival/libipkg/Kbuild busybox-1.20.2/archival/libipkg/Kbuild
  6582. --- busybox-1.20.2.orig//archival/libipkg/Kbuild 1970-01-01 01:00:00.000000000 +0100
  6583. +++ busybox-1.20.2/archival/libipkg/Kbuild 2013-01-31 16:44:31.000000000 +0100
  6584. @@ -0,0 +1,60 @@
  6585. +# Makefile for busybox
  6586. +#
  6587. +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  6588. +# Copyright (C) 2006 OpenWrt.org
  6589. +#
  6590. +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  6591. +
  6592. +LIBIPKG_CORE_OBJS:= \
  6593. + args.o \
  6594. + libipkg.o \
  6595. + user.o \
  6596. +
  6597. +LIBIPKG_CMD_OBJS:= \
  6598. + ipkg_cmd.o \
  6599. + ipkg_configure.o \
  6600. + ipkg_download.o \
  6601. + ipkg_install.o \
  6602. + ipkg_remove.o \
  6603. + ipkg_upgrade.o \
  6604. +
  6605. +LIBIPKG_DB_OBJS:= \
  6606. + hash_table.o \
  6607. + ipkg_conf.o \
  6608. + ipkg_utils.o \
  6609. + pkg.o \
  6610. + pkg_depends.o \
  6611. + pkg_extract.o \
  6612. + pkg_hash.o \
  6613. + pkg_parse.o \
  6614. + pkg_vec.o \
  6615. +
  6616. +LIBIPKG_LIST_OBJS:= \
  6617. + conffile.o \
  6618. + conffile_list.o \
  6619. + nv_pair.o \
  6620. + nv_pair_list.o \
  6621. + pkg_dest.o \
  6622. + pkg_dest_list.o \
  6623. + pkg_src.o \
  6624. + pkg_src_list.o \
  6625. + str_list.o \
  6626. + void_list.o \
  6627. +
  6628. +LIBIPKG_UTIL_OBJS:= \
  6629. + file_util.o \
  6630. + ipkg_message.o \
  6631. + str_util.o \
  6632. + xsystem.o \
  6633. +
  6634. +lib-y :=
  6635. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
  6636. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
  6637. +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
  6638. +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
  6639. +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
  6640. +
  6641. +ifeq ($(strip $(IPKG_ARCH)),)
  6642. +IPKG_ARCH:=$(TARGET_ARCH)
  6643. +endif
  6644. +CFLAGS += -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
  6645. diff -Nur busybox-1.20.2.orig//archival/libipkg/libipkg.c busybox-1.20.2/archival/libipkg/libipkg.c
  6646. --- busybox-1.20.2.orig//archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
  6647. +++ busybox-1.20.2/archival/libipkg/libipkg.c 2013-01-31 16:44:31.000000000 +0100
  6648. @@ -0,0 +1,583 @@
  6649. +/* ipkglib.c - the itsy package management system
  6650. +
  6651. + Florina Boor
  6652. +
  6653. + Copyright (C) 2003 kernel concepts
  6654. +
  6655. + This program is free software; you can redistribute it and/or
  6656. + modify it under the terms of the GNU General Public License as
  6657. + published by the Free Software Foundation; either version 2, or (at
  6658. + your option) any later version.
  6659. +
  6660. + This program is distributed in the hope that it will be useful, but
  6661. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6662. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6663. + General Public License for more details.
  6664. +*/
  6665. +
  6666. +#include "ipkg.h"
  6667. +#include "ipkg_includes.h"
  6668. +#include "libipkg.h"
  6669. +
  6670. +#include "args.h"
  6671. +#include "ipkg_conf.h"
  6672. +#include "ipkg_cmd.h"
  6673. +#include "file_util.h"
  6674. +
  6675. +int ipkg_file_what(args_t *args, const char *file, const char* command);
  6676. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  6677. + char *msg);
  6678. +int default_ipkg_list_callback(char *name, char *desc, char *version);
  6679. +int default_ipkg_files_callback(char *desc);
  6680. +int default_ipkg_status_callback(char *desc);
  6681. +char* default_ipkg_response_callback(char *question);
  6682. +
  6683. +
  6684. +ipkg_message_callback ipkg_cb_message = NULL;
  6685. +ipkg_response_callback ipkg_cb_response = NULL;
  6686. +ipkg_status_callback ipkg_cb_status = NULL;
  6687. +ipkg_list_callback ipkg_cb_list = NULL;
  6688. +
  6689. +
  6690. +int
  6691. +ipkg_init (ipkg_message_callback mcall,
  6692. + ipkg_response_callback rcall,
  6693. + args_t * args)
  6694. +{
  6695. + ipkg_cb_message = mcall;
  6696. + ipkg_cb_response = rcall;
  6697. +
  6698. + args_init (args);
  6699. +
  6700. + return 0;
  6701. +}
  6702. +
  6703. +
  6704. +int
  6705. +ipkg_deinit (args_t * args)
  6706. +{
  6707. + args_deinit (args);
  6708. + ipkg_cb_message = NULL;
  6709. + ipkg_cb_response = NULL;
  6710. +
  6711. + /* place other cleanup stuff here */
  6712. +
  6713. + return 0;
  6714. +}
  6715. +
  6716. +
  6717. +int
  6718. +ipkg_packages_list(args_t *args,
  6719. + const char *packages,
  6720. + ipkg_list_callback cblist,
  6721. + void *userdata)
  6722. +{
  6723. + ipkg_cmd_t *cmd;
  6724. + ipkg_conf_t ipkg_conf;
  6725. + int err;
  6726. +
  6727. + err = ipkg_conf_init (&ipkg_conf, args);
  6728. + if (err)
  6729. + {
  6730. + return err;
  6731. + }
  6732. +
  6733. + ipkg_cb_list = cblist;
  6734. + /* we need to do this because of static declarations,
  6735. + * maybe a good idea to change */
  6736. + cmd = ipkg_cmd_find ("list");
  6737. + if (packages)
  6738. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6739. + else
  6740. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6741. + ipkg_cb_list = NULL;
  6742. + ipkg_conf_deinit (&ipkg_conf);
  6743. + return (err);
  6744. +}
  6745. +
  6746. +
  6747. +int
  6748. +ipkg_packages_status(args_t *args,
  6749. + const char *packages,
  6750. + ipkg_status_callback cbstatus,
  6751. + void *userdata)
  6752. +{
  6753. + ipkg_cmd_t *cmd;
  6754. + ipkg_conf_t ipkg_conf;
  6755. + int err;
  6756. +
  6757. + err = ipkg_conf_init (&ipkg_conf, args);
  6758. + if (err)
  6759. + {
  6760. + return err;
  6761. + }
  6762. +
  6763. + ipkg_cb_status = cbstatus;
  6764. +
  6765. + /* we need to do this because of static declarations,
  6766. + * maybe a good idea to change */
  6767. + cmd = ipkg_cmd_find ("status");
  6768. + if (packages)
  6769. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6770. + else
  6771. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6772. +
  6773. + ipkg_cb_status = NULL;
  6774. + ipkg_conf_deinit (&ipkg_conf);
  6775. + return (err);
  6776. +}
  6777. +
  6778. +
  6779. +int
  6780. +ipkg_packages_info(args_t *args,
  6781. + const char *packages,
  6782. + ipkg_status_callback cbstatus,
  6783. + void *userdata)
  6784. +{
  6785. + ipkg_cmd_t *cmd;
  6786. + ipkg_conf_t ipkg_conf;
  6787. + int err;
  6788. +
  6789. + err = ipkg_conf_init (&ipkg_conf, args);
  6790. + if (err)
  6791. + {
  6792. + return err;
  6793. + }
  6794. +
  6795. + ipkg_cb_status = cbstatus;
  6796. +
  6797. + /* we need to do this because of static declarations,
  6798. + * maybe a good idea to change */
  6799. + cmd = ipkg_cmd_find ("info");
  6800. + if (packages)
  6801. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6802. + else
  6803. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6804. +
  6805. + ipkg_cb_status = NULL;
  6806. + ipkg_conf_deinit (&ipkg_conf);
  6807. + return (err);
  6808. +}
  6809. +
  6810. +
  6811. +int
  6812. +ipkg_packages_install (args_t * args, const char *name)
  6813. +{
  6814. + ipkg_cmd_t *cmd;
  6815. + ipkg_conf_t ipkg_conf;
  6816. + int err;
  6817. +
  6818. + /* this error should be handled in application */
  6819. + if (!name || !strlen (name))
  6820. + return (-1);
  6821. +
  6822. + err = ipkg_conf_init (&ipkg_conf, args);
  6823. + if (err)
  6824. + {
  6825. + return err;
  6826. + }
  6827. +
  6828. + /* we need to do this because of static declarations,
  6829. + * maybe a good idea to change */
  6830. + cmd = ipkg_cmd_find ("install");
  6831. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6832. +
  6833. + ipkg_conf_deinit(&ipkg_conf);
  6834. + return (err);
  6835. +}
  6836. +
  6837. +
  6838. +int
  6839. +ipkg_packages_remove(args_t *args, const char *name, int purge)
  6840. +{
  6841. + ipkg_cmd_t *cmd;
  6842. + ipkg_conf_t ipkg_conf;
  6843. + int err;
  6844. +
  6845. + /* this error should be handled in application */
  6846. + if (!name || !strlen (name))
  6847. + return (-1);
  6848. +
  6849. + err = ipkg_conf_init (&ipkg_conf, args);
  6850. + if (err)
  6851. + {
  6852. + return err;
  6853. + }
  6854. +
  6855. + /* we need to do this because of static declarations,
  6856. + * maybe a good idea to change */
  6857. + if (purge)
  6858. + cmd = ipkg_cmd_find ("purge");
  6859. + else
  6860. + cmd = ipkg_cmd_find ("remove");
  6861. +
  6862. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6863. +
  6864. + ipkg_conf_deinit(&ipkg_conf);
  6865. + return (err);
  6866. +}
  6867. +
  6868. +
  6869. +int
  6870. +ipkg_lists_update(args_t *args)
  6871. +{
  6872. + ipkg_cmd_t *cmd;
  6873. + ipkg_conf_t ipkg_conf;
  6874. + int err;
  6875. +
  6876. + err = ipkg_conf_init (&ipkg_conf, args);
  6877. + if (err)
  6878. + {
  6879. + return err;
  6880. + }
  6881. +
  6882. + /* we need to do this because of static declarations,
  6883. + * maybe a good idea to change */
  6884. + cmd = ipkg_cmd_find ("update");
  6885. +
  6886. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6887. +
  6888. + ipkg_conf_deinit(&ipkg_conf);
  6889. + return (err);
  6890. +}
  6891. +
  6892. +
  6893. +int
  6894. +ipkg_packages_upgrade(args_t *args)
  6895. +{
  6896. + ipkg_cmd_t *cmd;
  6897. + ipkg_conf_t ipkg_conf;
  6898. + int err;
  6899. +
  6900. + err = ipkg_conf_init (&ipkg_conf, args);
  6901. + if (err)
  6902. + {
  6903. + return err;
  6904. + }
  6905. +
  6906. + /* we need to do this because of static declarations,
  6907. + * maybe a good idea to change */
  6908. + cmd = ipkg_cmd_find ("upgrade");
  6909. +
  6910. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6911. +
  6912. + ipkg_conf_deinit(&ipkg_conf);
  6913. + return (err);
  6914. +}
  6915. +
  6916. +
  6917. +int
  6918. +ipkg_packages_download (args_t * args, const char *name)
  6919. +{
  6920. + ipkg_cmd_t *cmd;
  6921. + ipkg_conf_t ipkg_conf;
  6922. + int err;
  6923. +
  6924. + /* this error should be handled in application */
  6925. + if (!name || !strlen (name))
  6926. + return (-1);
  6927. +
  6928. + err = ipkg_conf_init (&ipkg_conf, args);
  6929. + if (err)
  6930. + {
  6931. + return err;
  6932. + }
  6933. +
  6934. + /* we need to do this because of static declarations,
  6935. + * maybe a good idea to change */
  6936. + cmd = ipkg_cmd_find ("download");
  6937. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6938. +
  6939. + ipkg_conf_deinit(&ipkg_conf);
  6940. + return (err);
  6941. +}
  6942. +
  6943. +
  6944. +int
  6945. +ipkg_package_files(args_t *args,
  6946. + const char *name,
  6947. + ipkg_list_callback cblist,
  6948. + void *userdata)
  6949. +{
  6950. + ipkg_cmd_t *cmd;
  6951. + ipkg_conf_t ipkg_conf;
  6952. + int err;
  6953. +
  6954. + /* this error should be handled in application */
  6955. + if (!name || !strlen (name))
  6956. + return (-1);
  6957. +
  6958. + err = ipkg_conf_init (&ipkg_conf, args);
  6959. + if (err)
  6960. + {
  6961. + return err;
  6962. + }
  6963. +
  6964. + ipkg_cb_list = cblist;
  6965. +
  6966. + /* we need to do this because of static declarations,
  6967. + * maybe a good idea to change */
  6968. + cmd = ipkg_cmd_find ("files");
  6969. +
  6970. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
  6971. +
  6972. + ipkg_cb_list = NULL;
  6973. + ipkg_conf_deinit(&ipkg_conf);
  6974. + return (err);
  6975. +}
  6976. +
  6977. +
  6978. +int
  6979. +ipkg_file_search(args_t *args,
  6980. + const char *file,
  6981. + ipkg_list_callback cblist,
  6982. + void *userdata)
  6983. +{
  6984. + ipkg_cmd_t *cmd;
  6985. + ipkg_conf_t ipkg_conf;
  6986. + int err;
  6987. +
  6988. + /* this error should be handled in application */
  6989. + if (!file || !strlen (file))
  6990. + return (-1);
  6991. +
  6992. + err = ipkg_conf_init (&ipkg_conf, args);
  6993. + if (err)
  6994. + {
  6995. + return err;
  6996. + }
  6997. +
  6998. + ipkg_cb_list = cblist;
  6999. +
  7000. + /* we need to do this because of static declarations,
  7001. + * maybe a good idea to change */
  7002. + cmd = ipkg_cmd_find ("search");
  7003. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
  7004. +
  7005. + ipkg_cb_list = NULL;
  7006. + ipkg_conf_deinit(&ipkg_conf);
  7007. + return(err);
  7008. +}
  7009. +
  7010. +
  7011. +int
  7012. +ipkg_file_what(args_t *args, const char *file, const char* command)
  7013. +{
  7014. + ipkg_cmd_t *cmd;
  7015. + ipkg_conf_t ipkg_conf;
  7016. + int err;
  7017. +
  7018. + /* this error should be handled in application */
  7019. + if (!file || !strlen (file))
  7020. + return (-1);
  7021. +
  7022. + err = ipkg_conf_init (&ipkg_conf, args);
  7023. + if (err)
  7024. + {
  7025. + return err;
  7026. + }
  7027. +
  7028. + /* we need to do this because of static declarations,
  7029. + * maybe a good idea to change */
  7030. + cmd = ipkg_cmd_find (command);
  7031. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
  7032. +
  7033. + ipkg_conf_deinit(&ipkg_conf);
  7034. + return(err);
  7035. +}
  7036. +
  7037. +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
  7038. +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
  7039. +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
  7040. +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
  7041. +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
  7042. +
  7043. +
  7044. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  7045. + char *msg)
  7046. +{
  7047. + if (conf && (conf->verbosity < level)) {
  7048. + return 0;
  7049. + } else {
  7050. + if ( level == IPKG_ERROR )
  7051. + push_error_list(&error_list, msg);
  7052. + else
  7053. + printf(msg);
  7054. + }
  7055. + return 0;
  7056. +}
  7057. +
  7058. +int default_ipkg_list_callback(char *name, char *desc, char *version)
  7059. +{
  7060. + if (desc)
  7061. + printf("%s - %s - %s\n", name, version, desc);
  7062. + else
  7063. + printf("%s - %s\n", name, version);
  7064. + return 0;
  7065. +}
  7066. +
  7067. +int default_ipkg_files_callback(char *desc)
  7068. +{
  7069. + if (desc)
  7070. + printf("%s\n", desc);
  7071. + return 0;
  7072. +}
  7073. +
  7074. +int default_ipkg_status_callback(char *desc)
  7075. +{
  7076. + printf("%s\n", desc);
  7077. + return 0;
  7078. +}
  7079. +
  7080. +char* default_ipkg_response_callback(char *question)
  7081. +{
  7082. + char *response = NULL;
  7083. + printf(question);
  7084. + fflush(stdout);
  7085. + do {
  7086. + response = (char *)file_read_line_alloc(stdin);
  7087. + } while (response == NULL);
  7088. + return response;
  7089. +}
  7090. +
  7091. +/* This is used for backward compatibility */
  7092. +int
  7093. +ipkg_op (int argc, char *argv[])
  7094. +{
  7095. + int err, optind_;
  7096. + args_t args;
  7097. + char *cmd_name;
  7098. + ipkg_cmd_t *cmd;
  7099. + ipkg_conf_t ipkg_conf;
  7100. + const char *message = "ipkg must have one sub-command argument";
  7101. + FILE *f;
  7102. + struct mntent *mnt;
  7103. + int remountroot;
  7104. +
  7105. + args_init (&args);
  7106. +
  7107. + optind_ = args_parse (&args, argc, argv);
  7108. + if (optind_ == argc || optind_ < 0)
  7109. + {
  7110. + args_usage(message);
  7111. + }
  7112. +
  7113. + cmd_name = argv[optind_++];
  7114. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  7115. + read anything from there.
  7116. +*/
  7117. + if ( !strcmp(cmd_name,"print-architecture") ||
  7118. + !strcmp(cmd_name,"print_architecture") ||
  7119. + !strcmp(cmd_name,"print-installation-architecture") ||
  7120. + !strcmp(cmd_name,"print_installation_architecture") )
  7121. + args.nocheckfordirorfile = 1;
  7122. +
  7123. +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
  7124. + read anything from there.
  7125. +*/
  7126. + if ( !strcmp(cmd_name,"flag") ||
  7127. + !strcmp(cmd_name,"configure") ||
  7128. + !strcmp(cmd_name,"remove") ||
  7129. + !strcmp(cmd_name,"files") ||
  7130. + !strcmp(cmd_name,"search") ||
  7131. + !strcmp(cmd_name,"compare_versions") ||
  7132. + !strcmp(cmd_name,"compare-versions") ||
  7133. + !strcmp(cmd_name,"list_installed") ||
  7134. + !strcmp(cmd_name,"list-installed") ||
  7135. + !strcmp(cmd_name,"status") )
  7136. + args.noreadfeedsfile = 1;
  7137. +
  7138. +
  7139. +
  7140. +
  7141. + err = ipkg_conf_init (&ipkg_conf, &args);
  7142. + if (err)
  7143. + {
  7144. + return err;
  7145. + }
  7146. +
  7147. + args_deinit (&args);
  7148. +
  7149. + ipkg_cb_message = default_ipkg_message_callback;
  7150. + ipkg_cb_response = default_ipkg_response_callback;
  7151. + ipkg_cb_status = (ipkg_status_callback)default_ipkg_status_callback;
  7152. + if ( strcmp(cmd_name, "files")==0)
  7153. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_files_callback;
  7154. + else
  7155. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_list_callback;
  7156. +
  7157. + cmd = ipkg_cmd_find (cmd_name);
  7158. + if (cmd == NULL)
  7159. + {
  7160. + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
  7161. + cmd_name);
  7162. + args_usage (NULL);
  7163. + }
  7164. +
  7165. + if (cmd->requires_args && optind_ == argc)
  7166. + {
  7167. + fprintf (stderr,
  7168. + "%s: the ``%s'' command requires at least one argument\n",
  7169. + __FUNCTION__, cmd_name);
  7170. + args_usage (NULL);
  7171. + }
  7172. +
  7173. + remountroot = 0;
  7174. + /* check if /dev/root is mounted read-only */
  7175. + if ((f = setmntent("/proc/mounts", "r")) == NULL)
  7176. + fprintf (stderr, "Checking /proc/mounts failed\n");
  7177. +
  7178. + while ((mnt = getmntent(f)) != NULL) {
  7179. + if (strcmp(mnt->mnt_fsname, "/dev/root") == 0 &&
  7180. + hasmntopt(mnt, MNTOPT_RO) != NULL) {
  7181. + remountroot = 1;
  7182. + }
  7183. + }
  7184. +
  7185. + endmntent(f);
  7186. +
  7187. + if (remountroot) {
  7188. + if ( !strcmp(cmd_name,"install") ||
  7189. + !strcmp(cmd_name,"update") ||
  7190. + !strcmp(cmd_name,"upgrade") ||
  7191. + !strcmp(cmd_name,"flag") ||
  7192. + !strcmp(cmd_name,"configure") ||
  7193. + !strcmp(cmd_name,"remove") ) {
  7194. + /* mount rootfs read-write */
  7195. + if (mount("","/",0,MS_REMOUNT,0)<0)
  7196. + fprintf (stderr, "Mounting rootfs read-write failed\n");
  7197. + }
  7198. + }
  7199. +
  7200. + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind_, (const char **) (argv + optind_), NULL);
  7201. +
  7202. + ipkg_conf_deinit (&ipkg_conf);
  7203. +
  7204. + if (remountroot) {
  7205. + if ( !strcmp(cmd_name,"install") ||
  7206. + !strcmp(cmd_name,"update") ||
  7207. + !strcmp(cmd_name,"upgrade") ||
  7208. + !strcmp(cmd_name,"flag") ||
  7209. + !strcmp(cmd_name,"configure") ||
  7210. + !strcmp(cmd_name,"remove") ) {
  7211. + sync();
  7212. + /* mount rootfs read-only */
  7213. + if (mount("","/",0,MS_REMOUNT|MS_RDONLY,0)<0)
  7214. + fprintf (stderr, "Mounting rootfs read-only failed\n");
  7215. + }
  7216. + }
  7217. +
  7218. + /* check if cfgfs exists */
  7219. + if (access("/sbin/cfgfs", X_OK) == 0) {
  7220. + if ( !strcmp(cmd_name,"install") ||
  7221. + !strcmp(cmd_name,"update") ||
  7222. + !strcmp(cmd_name,"upgrade")) {
  7223. + if (system("cfgfs status -q") != 0) {
  7224. + fprintf (stdout, "Updates in /etc, please review changes\n");
  7225. + fprintf (stdout, "You can check via cfgfs status\n");
  7226. + }
  7227. + }
  7228. + }
  7229. +
  7230. + return err;
  7231. +}
  7232. diff -Nur busybox-1.20.2.orig//archival/libipkg/libipkg.h busybox-1.20.2/archival/libipkg/libipkg.h
  7233. --- busybox-1.20.2.orig//archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
  7234. +++ busybox-1.20.2/archival/libipkg/libipkg.h 2013-01-31 16:44:31.000000000 +0100
  7235. @@ -0,0 +1,78 @@
  7236. +/* ipkglib.h - the itsy package management system
  7237. +
  7238. + Florian Boor <florian.boor@kernelconcepts.de>
  7239. +
  7240. + This program is free software; you can redistribute it and/or
  7241. + modify it under the terms of the GNU General Public License as
  7242. + published by the Free Software Foundation; either version 2, or (at
  7243. + your option) any later version.
  7244. +
  7245. + This program is distributed in the hope that it will be useful, but
  7246. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7247. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7248. + General Public License for more details.
  7249. +*/
  7250. +
  7251. +#ifndef IPKGLIB_H
  7252. +#define IPKGLIB_H
  7253. +
  7254. +#include "ipkg_conf.h"
  7255. +#include "ipkg_message.h"
  7256. +
  7257. +#include "args.h"
  7258. +#include "pkg.h"
  7259. +
  7260. +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
  7261. + char *msg);
  7262. +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
  7263. + pkg_state_status_t status, void *userdata);
  7264. +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
  7265. + void *userdata);
  7266. +typedef char* (*ipkg_response_callback)(char *question);
  7267. +
  7268. +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
  7269. +extern int ipkg_init (ipkg_message_callback mcall,
  7270. + ipkg_response_callback rcall,
  7271. + args_t * args);
  7272. +
  7273. +extern int ipkg_deinit (args_t *args);
  7274. +extern int ipkg_packages_list(args_t *args,
  7275. + const char *packages,
  7276. + ipkg_list_callback cblist,
  7277. + void *userdata);
  7278. +extern int ipkg_packages_status(args_t *args,
  7279. + const char *packages,
  7280. + ipkg_status_callback cbstatus,
  7281. + void *userdata);
  7282. +extern int ipkg_packages_info(args_t *args,
  7283. + const char *packages,
  7284. + ipkg_status_callback cbstatus,
  7285. + void *userdata);
  7286. +extern int ipkg_packages_install(args_t *args, const char *name);
  7287. +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
  7288. +extern int ipkg_lists_update(args_t *args);
  7289. +extern int ipkg_packages_upgrade(args_t *args);
  7290. +extern int ipkg_packages_download(args_t *args, const char *name);
  7291. +extern int ipkg_package_files(args_t *args,
  7292. + const char *name,
  7293. + ipkg_list_callback cblist,
  7294. + void *userdata);
  7295. +extern int ipkg_file_search(args_t *args,
  7296. + const char *file,
  7297. + ipkg_list_callback cblist,
  7298. + void *userdata);
  7299. +extern int ipkg_package_whatdepends(args_t *args, const char *file);
  7300. +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
  7301. +extern int ipkg_package_whatprovides(args_t *args, const char *file);
  7302. +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
  7303. +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
  7304. +
  7305. +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
  7306. +extern ipkg_response_callback ipkg_cb_response;
  7307. +extern ipkg_status_callback ipkg_cb_status;
  7308. +extern ipkg_list_callback ipkg_cb_list;
  7309. +extern void push_error_list(struct errlist **errors,char * msg);
  7310. +extern void reverse_error_list(struct errlist **errors);
  7311. +extern void free_error_list(struct errlist **errors);
  7312. +
  7313. +#endif
  7314. diff -Nur busybox-1.20.2.orig//archival/libipkg/nv_pair.c busybox-1.20.2/archival/libipkg/nv_pair.c
  7315. --- busybox-1.20.2.orig//archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
  7316. +++ busybox-1.20.2/archival/libipkg/nv_pair.c 2013-01-31 16:44:31.000000000 +0100
  7317. @@ -0,0 +1,40 @@
  7318. +/* nv_pair.c - the itsy package management system
  7319. +
  7320. + Carl D. Worth
  7321. +
  7322. + Copyright (C) 2001 University of Southern California
  7323. +
  7324. + This program is free software; you can redistribute it and/or
  7325. + modify it under the terms of the GNU General Public License as
  7326. + published by the Free Software Foundation; either version 2, or (at
  7327. + your option) any later version.
  7328. +
  7329. + This program is distributed in the hope that it will be useful, but
  7330. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7331. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7332. + General Public License for more details.
  7333. +*/
  7334. +
  7335. +#include "ipkg.h"
  7336. +
  7337. +#include "nv_pair.h"
  7338. +#include "str_util.h"
  7339. +
  7340. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
  7341. +{
  7342. + nv_pair->name = str_dup_safe(name);
  7343. + nv_pair->value = str_dup_safe(value);
  7344. +
  7345. + return 0;
  7346. +}
  7347. +
  7348. +void nv_pair_deinit(nv_pair_t *nv_pair)
  7349. +{
  7350. + free(nv_pair->name);
  7351. + nv_pair->name = NULL;
  7352. +
  7353. + free(nv_pair->value);
  7354. + nv_pair->value = NULL;
  7355. +}
  7356. +
  7357. +
  7358. diff -Nur busybox-1.20.2.orig//archival/libipkg/nv_pair.h busybox-1.20.2/archival/libipkg/nv_pair.h
  7359. --- busybox-1.20.2.orig//archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
  7360. +++ busybox-1.20.2/archival/libipkg/nv_pair.h 2013-01-31 16:44:31.000000000 +0100
  7361. @@ -0,0 +1,32 @@
  7362. +/* nv_pair.h - the itsy package management system
  7363. +
  7364. + Carl D. Worth
  7365. +
  7366. + Copyright (C) 2001 University of Southern California
  7367. +
  7368. + This program is free software; you can redistribute it and/or
  7369. + modify it under the terms of the GNU General Public License as
  7370. + published by the Free Software Foundation; either version 2, or (at
  7371. + your option) any later version.
  7372. +
  7373. + This program is distributed in the hope that it will be useful, but
  7374. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7375. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7376. + General Public License for more details.
  7377. +*/
  7378. +
  7379. +#ifndef NV_PAIR_H
  7380. +#define NV_PAIR_H
  7381. +
  7382. +typedef struct nv_pair nv_pair_t;
  7383. +struct nv_pair
  7384. +{
  7385. + char *name;
  7386. + char *value;
  7387. +};
  7388. +
  7389. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
  7390. +void nv_pair_deinit(nv_pair_t *nv_pair);
  7391. +
  7392. +#endif
  7393. +
  7394. diff -Nur busybox-1.20.2.orig//archival/libipkg/nv_pair_list.c busybox-1.20.2/archival/libipkg/nv_pair_list.c
  7395. --- busybox-1.20.2.orig//archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
  7396. +++ busybox-1.20.2/archival/libipkg/nv_pair_list.c 2013-01-31 16:44:31.000000000 +0100
  7397. @@ -0,0 +1,98 @@
  7398. +/* nv_pair_list.c - the itsy package management system
  7399. +
  7400. + Carl D. Worth
  7401. +
  7402. + Copyright (C) 2001 University of Southern California
  7403. +
  7404. + This program is free software; you can redistribute it and/or
  7405. + modify it under the terms of the GNU General Public License as
  7406. + published by the Free Software Foundation; either version 2, or (at
  7407. + your option) any later version.
  7408. +
  7409. + This program is distributed in the hope that it will be useful, but
  7410. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7411. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7412. + General Public License for more details.
  7413. +*/
  7414. +
  7415. +#include "ipkg.h"
  7416. +
  7417. +#include "nv_pair.h"
  7418. +#include "void_list.h"
  7419. +#include "nv_pair_list.h"
  7420. +
  7421. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
  7422. +{
  7423. + return void_list_elt_init((void_list_elt_t *) elt, data);
  7424. +}
  7425. +
  7426. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
  7427. +{
  7428. + void_list_elt_deinit((void_list_elt_t *) elt);
  7429. +}
  7430. +
  7431. +int nv_pair_list_init(nv_pair_list_t *list)
  7432. +{
  7433. + return void_list_init((void_list_t *) list);
  7434. +}
  7435. +
  7436. +void nv_pair_list_deinit(nv_pair_list_t *list)
  7437. +{
  7438. + nv_pair_list_elt_t *iter;
  7439. + nv_pair_t *nv_pair;
  7440. +
  7441. + for (iter = list->head; iter; iter = iter->next) {
  7442. + nv_pair = iter->data;
  7443. + nv_pair_deinit(nv_pair);
  7444. +
  7445. + /* malloced in nv_pair_list_append */
  7446. + free(nv_pair);
  7447. + iter->data = NULL;
  7448. + }
  7449. + void_list_deinit((void_list_t *) list);
  7450. +}
  7451. +
  7452. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
  7453. +{
  7454. + int err;
  7455. +
  7456. + /* freed in nv_pair_list_deinit */
  7457. + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
  7458. +
  7459. + if (nv_pair == NULL) {
  7460. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7461. + return NULL;
  7462. + }
  7463. + nv_pair_init(nv_pair, name, value);
  7464. +
  7465. + err = void_list_append((void_list_t *) list, nv_pair);
  7466. + if (err) {
  7467. + return NULL;
  7468. + }
  7469. +
  7470. + return nv_pair;
  7471. +}
  7472. +
  7473. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
  7474. +{
  7475. + return void_list_push((void_list_t *) list, data);
  7476. +}
  7477. +
  7478. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
  7479. +{
  7480. + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
  7481. +}
  7482. +
  7483. +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
  7484. +{
  7485. + nv_pair_list_elt_t *iter;
  7486. + nv_pair_t *nv_pair;
  7487. +
  7488. + for (iter = list->head; iter; iter = iter->next) {
  7489. + nv_pair = iter->data;
  7490. + if (strcmp(nv_pair->name, name) == 0) {
  7491. + return nv_pair->value;
  7492. + }
  7493. + }
  7494. + return NULL;
  7495. +}
  7496. diff -Nur busybox-1.20.2.orig//archival/libipkg/nv_pair_list.h busybox-1.20.2/archival/libipkg/nv_pair_list.h
  7497. --- busybox-1.20.2.orig//archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
  7498. +++ busybox-1.20.2/archival/libipkg/nv_pair_list.h 2013-01-31 16:44:31.000000000 +0100
  7499. @@ -0,0 +1,60 @@
  7500. +/* nv_pair_list.h - the itsy package management system
  7501. +
  7502. + Carl D. Worth
  7503. +
  7504. + Copyright (C) 2001 University of Southern California
  7505. +
  7506. + This program is free software; you can redistribute it and/or
  7507. + modify it under the terms of the GNU General Public License as
  7508. + published by the Free Software Foundation; either version 2, or (at
  7509. + your option) any later version.
  7510. +
  7511. + This program is distributed in the hope that it will be useful, but
  7512. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7513. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7514. + General Public License for more details.
  7515. +*/
  7516. +
  7517. +#ifndef NV_PAIR_LIST_H
  7518. +#define NV_PAIR_LIST_H
  7519. +
  7520. +#include "nv_pair.h"
  7521. +#include "void_list.h"
  7522. +
  7523. +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
  7524. +struct nv_pair_list_elt
  7525. +{
  7526. + nv_pair_list_elt_t *next;
  7527. + nv_pair_t *data;
  7528. +};
  7529. +
  7530. +typedef struct nv_pair_list nv_pair_list_t;
  7531. +struct nv_pair_list
  7532. +{
  7533. + nv_pair_list_elt_t pre_head;
  7534. + nv_pair_list_elt_t *head;
  7535. + nv_pair_list_elt_t *tail;
  7536. +};
  7537. +
  7538. +static inline int nv_pair_list_empty(nv_pair_list_t *list)
  7539. +{
  7540. + if (list->head == NULL)
  7541. + return 1;
  7542. + else
  7543. + return 0;
  7544. +}
  7545. +
  7546. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
  7547. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
  7548. +
  7549. +int nv_pair_list_init(nv_pair_list_t *list);
  7550. +void nv_pair_list_deinit(nv_pair_list_t *list);
  7551. +
  7552. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
  7553. + const char *name, const char *value);
  7554. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
  7555. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
  7556. +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
  7557. +
  7558. +#endif
  7559. +
  7560. diff -Nur busybox-1.20.2.orig//archival/libipkg/pkg.c busybox-1.20.2/archival/libipkg/pkg.c
  7561. --- busybox-1.20.2.orig//archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
  7562. +++ busybox-1.20.2/archival/libipkg/pkg.c 2013-01-31 16:44:31.000000000 +0100
  7563. @@ -0,0 +1,1757 @@
  7564. +/* pkg.c - the itsy package management system
  7565. +
  7566. + Carl D. Worth
  7567. +
  7568. + Copyright (C) 2001 University of Southern California
  7569. +
  7570. + This program is free software; you can redistribute it and/or
  7571. + modify it under the terms of the GNU General Public License as
  7572. + published by the Free Software Foundation; either version 2, or (at
  7573. + your option) any later version.
  7574. +
  7575. + This program is distributed in the hope that it will be useful, but
  7576. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7577. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7578. + General Public License for more details.
  7579. +*/
  7580. +
  7581. +#include "ipkg.h"
  7582. +#include <ctype.h>
  7583. +#include <string.h>
  7584. +#include <errno.h>
  7585. +
  7586. +#include "pkg.h"
  7587. +
  7588. +#include "pkg_parse.h"
  7589. +#include "pkg_extract.h"
  7590. +#include "ipkg_message.h"
  7591. +#include "ipkg_utils.h"
  7592. +
  7593. +#include "sprintf_alloc.h"
  7594. +#include "file_util.h"
  7595. +#include "str_util.h"
  7596. +#include "xsystem.h"
  7597. +#include "ipkg_conf.h"
  7598. +
  7599. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname);
  7600. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_);
  7601. +
  7602. +typedef struct enum_map enum_map_t;
  7603. +struct enum_map
  7604. +{
  7605. + int value;
  7606. + const char *str;
  7607. +};
  7608. +
  7609. +static const enum_map_t pkg_state_want_map[] = {
  7610. + { SW_UNKNOWN, "unknown"},
  7611. + { SW_INSTALL, "install"},
  7612. + { SW_DEINSTALL, "deinstall"},
  7613. + { SW_PURGE, "purge"}
  7614. +};
  7615. +
  7616. +static const enum_map_t pkg_state_flag_map[] = {
  7617. + { SF_OK, "ok"},
  7618. + { SF_REINSTREQ, "reinstreq"},
  7619. + { SF_HOLD, "hold"},
  7620. + { SF_REPLACE, "replace"},
  7621. + { SF_NOPRUNE, "noprune"},
  7622. + { SF_PREFER, "prefer"},
  7623. + { SF_OBSOLETE, "obsolete"},
  7624. + { SF_USER, "user"},
  7625. +};
  7626. +
  7627. +static const enum_map_t pkg_state_status_map[] = {
  7628. + { SS_NOT_INSTALLED, "not-installed" },
  7629. + { SS_UNPACKED, "unpacked" },
  7630. + { SS_HALF_CONFIGURED, "half-configured" },
  7631. + { SS_INSTALLED, "installed" },
  7632. + { SS_HALF_INSTALLED, "half-installed" },
  7633. + { SS_CONFIG_FILES, "config-files" },
  7634. + { SS_POST_INST_FAILED, "post-inst-failed" },
  7635. + { SS_REMOVAL_FAILED, "removal-failed" }
  7636. +};
  7637. +
  7638. +static int verrevcmp(const char *val, const char *ref);
  7639. +
  7640. +
  7641. +pkg_t *pkg_new(void)
  7642. +{
  7643. + pkg_t *pkg;
  7644. +
  7645. + pkg = malloc(sizeof(pkg_t));
  7646. + if (pkg == NULL) {
  7647. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7648. + return NULL;
  7649. + }
  7650. +
  7651. + pkg_init(pkg);
  7652. +
  7653. + return pkg;
  7654. +}
  7655. +
  7656. +int pkg_init(pkg_t *pkg)
  7657. +{
  7658. + memset(pkg, 0, sizeof(pkg_t));
  7659. + pkg->name = NULL;
  7660. + pkg->epoch = 0;
  7661. + pkg->version = NULL;
  7662. + pkg->revision = NULL;
  7663. + pkg->familiar_revision = NULL;
  7664. + pkg->dest = NULL;
  7665. + pkg->src = NULL;
  7666. + pkg->architecture = NULL;
  7667. + pkg->maintainer = NULL;
  7668. + pkg->section = NULL;
  7669. + pkg->description = NULL;
  7670. + pkg->state_want = SW_UNKNOWN;
  7671. + pkg->state_flag = SF_OK;
  7672. + pkg->state_status = SS_NOT_INSTALLED;
  7673. + pkg->depends_str = NULL;
  7674. + pkg->provides_str = NULL;
  7675. + pkg->depends_count = 0;
  7676. + pkg->depends = NULL;
  7677. + pkg->suggests_str = NULL;
  7678. + pkg->recommends_str = NULL;
  7679. + pkg->suggests_count = 0;
  7680. + pkg->recommends_count = 0;
  7681. +
  7682. + /* Abhaya: added init for conflicts fields */
  7683. + pkg->conflicts = NULL;
  7684. + pkg->conflicts_count = 0;
  7685. +
  7686. + /* added for replaces. Jamey 7/23/2002 */
  7687. + pkg->replaces = NULL;
  7688. + pkg->replaces_count = 0;
  7689. +
  7690. + pkg->pre_depends_count = 0;
  7691. + pkg->pre_depends_str = NULL;
  7692. + pkg->provides_count = 0;
  7693. + pkg->provides = NULL;
  7694. + pkg->filename = NULL;
  7695. + pkg->local_filename = NULL;
  7696. + pkg->tmp_unpack_dir = NULL;
  7697. + pkg->md5sum = NULL;
  7698. + pkg->size = NULL;
  7699. + pkg->installed_size = NULL;
  7700. + pkg->priority = NULL;
  7701. + pkg->source = NULL;
  7702. + conffile_list_init(&pkg->conffiles);
  7703. + pkg->installed_files = NULL;
  7704. + pkg->installed_files_ref_cnt = 0;
  7705. + pkg->essential = 0;
  7706. + pkg->provided_by_hand = 0;
  7707. +
  7708. + return 0;
  7709. +}
  7710. +
  7711. +void pkg_deinit(pkg_t *pkg)
  7712. +{
  7713. + free(pkg->name);
  7714. + pkg->name = NULL;
  7715. + pkg->epoch = 0;
  7716. + free(pkg->version);
  7717. + pkg->version = NULL;
  7718. + /* revision and familiar_revision share storage with version, so
  7719. + don't free */
  7720. + pkg->revision = NULL;
  7721. + pkg->familiar_revision = NULL;
  7722. + /* owned by ipkg_conf_t */
  7723. + pkg->dest = NULL;
  7724. + /* owned by ipkg_conf_t */
  7725. + pkg->src = NULL;
  7726. + free(pkg->architecture);
  7727. + pkg->architecture = NULL;
  7728. + free(pkg->maintainer);
  7729. + pkg->maintainer = NULL;
  7730. + free(pkg->section);
  7731. + pkg->section = NULL;
  7732. + free(pkg->description);
  7733. + pkg->description = NULL;
  7734. + pkg->state_want = SW_UNKNOWN;
  7735. + pkg->state_flag = SF_OK;
  7736. + pkg->state_status = SS_NOT_INSTALLED;
  7737. + free(pkg->depends_str);
  7738. + pkg->depends_str = NULL;
  7739. + free(pkg->provides_str);
  7740. + pkg->provides_str = NULL;
  7741. + pkg->depends_count = 0;
  7742. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
  7743. + pkg->pre_depends_count = 0;
  7744. + free(pkg->pre_depends_str);
  7745. + pkg->pre_depends_str = NULL;
  7746. + pkg->provides_count = 0;
  7747. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
  7748. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
  7749. + free(pkg->filename);
  7750. + pkg->filename = NULL;
  7751. + free(pkg->local_filename);
  7752. + pkg->local_filename = NULL;
  7753. + /* CLEANUP: It'd be nice to pullin the cleanup function from
  7754. + ipkg_install.c here. See comment in
  7755. + ipkg_install.c:cleanup_temporary_files */
  7756. + free(pkg->tmp_unpack_dir);
  7757. + pkg->tmp_unpack_dir = NULL;
  7758. + free(pkg->md5sum);
  7759. + pkg->md5sum = NULL;
  7760. + free(pkg->size);
  7761. + pkg->size = NULL;
  7762. + free(pkg->installed_size);
  7763. + pkg->installed_size = NULL;
  7764. + free(pkg->priority);
  7765. + pkg->priority = NULL;
  7766. + free(pkg->source);
  7767. + pkg->source = NULL;
  7768. + conffile_list_deinit(&pkg->conffiles);
  7769. + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
  7770. + since if they are calling deinit, they should know. Maybe do an
  7771. + assertion here instead? */
  7772. + pkg->installed_files_ref_cnt = 1;
  7773. + pkg_free_installed_files(pkg);
  7774. + pkg->essential = 0;
  7775. +}
  7776. +
  7777. +int pkg_init_from_file(pkg_t *pkg, const char *filename)
  7778. +{
  7779. + int err;
  7780. + char **raw;
  7781. + FILE *control_file;
  7782. +
  7783. + err = pkg_init(pkg);
  7784. + if (err) { return err; }
  7785. +
  7786. + pkg->local_filename = strdup(filename);
  7787. +
  7788. + control_file = tmpfile();
  7789. + err = pkg_extract_control_file_to_stream(pkg, control_file);
  7790. + if (err) { return err; }
  7791. +
  7792. + rewind(control_file);
  7793. + raw = read_raw_pkgs_from_stream(control_file);
  7794. + pkg_parse_raw(pkg, &raw, NULL, NULL);
  7795. +
  7796. + fclose(control_file);
  7797. +
  7798. + return 0;
  7799. +}
  7800. +
  7801. +/* Merge any new information in newpkg into oldpkg */
  7802. +/* XXX: CLEANUP: This function shouldn't actually modify anything in
  7803. + newpkg, but should leave it usable. This rework is so that
  7804. + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
  7805. +/*
  7806. + * uh, i thought that i had originally written this so that it took
  7807. + * two pkgs and returned a new one? we can do that again... -sma
  7808. + */
  7809. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
  7810. +{
  7811. + if (oldpkg == newpkg) {
  7812. + return 0;
  7813. + }
  7814. +
  7815. + if (!oldpkg->src)
  7816. + oldpkg->src = newpkg->src;
  7817. + if (!oldpkg->dest)
  7818. + oldpkg->dest = newpkg->dest;
  7819. + if (!oldpkg->architecture)
  7820. + oldpkg->architecture = str_dup_safe(newpkg->architecture);
  7821. + if (!oldpkg->arch_priority)
  7822. + oldpkg->arch_priority = newpkg->arch_priority;
  7823. + if (!oldpkg->section)
  7824. + oldpkg->section = str_dup_safe(newpkg->section);
  7825. + if(!oldpkg->maintainer)
  7826. + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
  7827. + if(!oldpkg->description)
  7828. + oldpkg->description = str_dup_safe(newpkg->description);
  7829. + if (set_status) {
  7830. + /* merge the state_flags from the new package */
  7831. + oldpkg->state_want = newpkg->state_want;
  7832. + oldpkg->state_status = newpkg->state_status;
  7833. + oldpkg->state_flag = newpkg->state_flag;
  7834. + } else {
  7835. + if (oldpkg->state_want == SW_UNKNOWN)
  7836. + oldpkg->state_want = newpkg->state_want;
  7837. + if (oldpkg->state_status == SS_NOT_INSTALLED)
  7838. + oldpkg->state_status = newpkg->state_status;
  7839. + oldpkg->state_flag |= newpkg->state_flag;
  7840. + }
  7841. +
  7842. + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
  7843. + oldpkg->depends_str = newpkg->depends_str;
  7844. + newpkg->depends_str = NULL;
  7845. + oldpkg->depends_count = newpkg->depends_count;
  7846. + newpkg->depends_count = 0;
  7847. +
  7848. + oldpkg->depends = newpkg->depends;
  7849. + newpkg->depends = NULL;
  7850. +
  7851. + oldpkg->pre_depends_str = newpkg->pre_depends_str;
  7852. + newpkg->pre_depends_str = NULL;
  7853. + oldpkg->pre_depends_count = newpkg->pre_depends_count;
  7854. + newpkg->pre_depends_count = 0;
  7855. +
  7856. + oldpkg->recommends_str = newpkg->recommends_str;
  7857. + newpkg->recommends_str = NULL;
  7858. + oldpkg->recommends_count = newpkg->recommends_count;
  7859. + newpkg->recommends_count = 0;
  7860. +
  7861. + oldpkg->suggests_str = newpkg->suggests_str;
  7862. + newpkg->suggests_str = NULL;
  7863. + oldpkg->suggests_count = newpkg->suggests_count;
  7864. + newpkg->suggests_count = 0;
  7865. + }
  7866. +
  7867. + if (!oldpkg->provides_str) {
  7868. + oldpkg->provides_str = newpkg->provides_str;
  7869. + newpkg->provides_str = NULL;
  7870. + oldpkg->provides_count = newpkg->provides_count;
  7871. + newpkg->provides_count = 0;
  7872. +
  7873. + oldpkg->provides = newpkg->provides;
  7874. + newpkg->provides = NULL;
  7875. + }
  7876. +
  7877. + if (!oldpkg->conflicts_str) {
  7878. + oldpkg->conflicts_str = newpkg->conflicts_str;
  7879. + newpkg->conflicts_str = NULL;
  7880. + oldpkg->conflicts_count = newpkg->conflicts_count;
  7881. + newpkg->conflicts_count = 0;
  7882. +
  7883. + oldpkg->conflicts = newpkg->conflicts;
  7884. + newpkg->conflicts = NULL;
  7885. + }
  7886. +
  7887. + if (!oldpkg->replaces_str) {
  7888. + oldpkg->replaces_str = newpkg->replaces_str;
  7889. + newpkg->replaces_str = NULL;
  7890. + oldpkg->replaces_count = newpkg->replaces_count;
  7891. + newpkg->replaces_count = 0;
  7892. +
  7893. + oldpkg->replaces = newpkg->replaces;
  7894. + newpkg->replaces = NULL;
  7895. + }
  7896. +
  7897. + if (!oldpkg->filename)
  7898. + oldpkg->filename = str_dup_safe(newpkg->filename);
  7899. + if (0)
  7900. + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
  7901. + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
  7902. + if (!oldpkg->local_filename)
  7903. + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
  7904. + if (!oldpkg->tmp_unpack_dir)
  7905. + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
  7906. + if (!oldpkg->md5sum)
  7907. + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
  7908. + if (!oldpkg->size)
  7909. + oldpkg->size = str_dup_safe(newpkg->size);
  7910. + if (!oldpkg->installed_size)
  7911. + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
  7912. + if (!oldpkg->priority)
  7913. + oldpkg->priority = str_dup_safe(newpkg->priority);
  7914. + if (!oldpkg->source)
  7915. + oldpkg->source = str_dup_safe(newpkg->source);
  7916. + if (oldpkg->conffiles.head == NULL){
  7917. + oldpkg->conffiles = newpkg->conffiles;
  7918. + conffile_list_init(&newpkg->conffiles);
  7919. + }
  7920. + if (!oldpkg->installed_files){
  7921. + oldpkg->installed_files = newpkg->installed_files;
  7922. + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
  7923. + newpkg->installed_files = NULL;
  7924. + }
  7925. + if (!oldpkg->essential)
  7926. + oldpkg->essential = newpkg->essential;
  7927. +
  7928. + return 0;
  7929. +}
  7930. +
  7931. +abstract_pkg_t *abstract_pkg_new(void)
  7932. +{
  7933. + abstract_pkg_t * ab_pkg;
  7934. +
  7935. + ab_pkg = malloc(sizeof(abstract_pkg_t));
  7936. +
  7937. + if (ab_pkg == NULL) {
  7938. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7939. + return NULL;
  7940. + }
  7941. +
  7942. + if ( abstract_pkg_init(ab_pkg) < 0 )
  7943. + return NULL;
  7944. +
  7945. + return ab_pkg;
  7946. +}
  7947. +
  7948. +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
  7949. +{
  7950. + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
  7951. +
  7952. + ab_pkg->provided_by = abstract_pkg_vec_alloc();
  7953. + if (ab_pkg->provided_by==NULL){
  7954. + return -1;
  7955. + }
  7956. + ab_pkg->dependencies_checked = 0;
  7957. + ab_pkg->state_status = SS_NOT_INSTALLED;
  7958. +
  7959. + return 0;
  7960. +}
  7961. +
  7962. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
  7963. + char * temp_str;
  7964. + char **raw =NULL;
  7965. + char **raw_start=NULL;
  7966. +
  7967. + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
  7968. + if (temp_str == NULL ){
  7969. + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
  7970. + return;
  7971. + }
  7972. + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
  7973. +
  7974. + raw = raw_start = read_raw_pkgs_from_file(temp_str);
  7975. + if (raw == NULL ){
  7976. + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
  7977. + return;
  7978. + }
  7979. +
  7980. + while(*raw){
  7981. + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
  7982. + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
  7983. + }
  7984. + }
  7985. + raw = raw_start;
  7986. + while (*raw) {
  7987. + if (raw!=NULL)
  7988. + free(*raw++);
  7989. + }
  7990. +
  7991. + free(raw_start);
  7992. + free(temp_str);
  7993. +
  7994. + return ;
  7995. +
  7996. +}
  7997. +
  7998. +char * pkg_formatted_info(pkg_t *pkg )
  7999. +{
  8000. + char *line;
  8001. + char * buff;
  8002. +
  8003. + buff = malloc(8192);
  8004. + if (buff == NULL) {
  8005. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8006. + return NULL;
  8007. + }
  8008. +
  8009. + buff[0] = '\0';
  8010. +
  8011. + line = pkg_formatted_field(pkg, "Package");
  8012. + strncat(buff ,line, strlen(line));
  8013. + free(line);
  8014. +
  8015. + line = pkg_formatted_field(pkg, "Version");
  8016. + strncat(buff ,line, strlen(line));
  8017. + free(line);
  8018. +
  8019. + line = pkg_formatted_field(pkg, "Depends");
  8020. + strncat(buff ,line, strlen(line));
  8021. + free(line);
  8022. +
  8023. + line = pkg_formatted_field(pkg, "Recommends");
  8024. + strncat(buff ,line, strlen(line));
  8025. + free(line);
  8026. +
  8027. + line = pkg_formatted_field(pkg, "Suggests");
  8028. + strncat(buff ,line, strlen(line));
  8029. + free(line);
  8030. +
  8031. + line = pkg_formatted_field(pkg, "Provides");
  8032. + strncat(buff ,line, strlen(line));
  8033. + free(line);
  8034. +
  8035. + line = pkg_formatted_field(pkg, "Replaces");
  8036. + strncat(buff ,line, strlen(line));
  8037. + free(line);
  8038. +
  8039. + line = pkg_formatted_field(pkg, "Conflicts");
  8040. + strncat(buff ,line, strlen(line));
  8041. + free(line);
  8042. +
  8043. + line = pkg_formatted_field(pkg, "Status");
  8044. + strncat(buff ,line, strlen(line));
  8045. + free(line);
  8046. +
  8047. + line = pkg_formatted_field(pkg, "Section");
  8048. + strncat(buff ,line, strlen(line));
  8049. + free(line);
  8050. +
  8051. + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
  8052. + strncat(buff ,line, strlen(line));
  8053. + free(line);
  8054. +
  8055. + line = pkg_formatted_field(pkg, "Architecture");
  8056. + strncat(buff ,line, strlen(line));
  8057. + free(line);
  8058. +
  8059. + line = pkg_formatted_field(pkg, "Maintainer");
  8060. + strncat(buff ,line, strlen(line));
  8061. + free(line);
  8062. +
  8063. + line = pkg_formatted_field(pkg, "MD5sum");
  8064. + strncat(buff ,line, strlen(line));
  8065. + free(line);
  8066. +
  8067. + line = pkg_formatted_field(pkg, "Size");
  8068. + strncat(buff ,line, strlen(line));
  8069. + free(line);
  8070. +
  8071. + line = pkg_formatted_field(pkg, "Filename");
  8072. + strncat(buff ,line, strlen(line));
  8073. + free(line);
  8074. +
  8075. + line = pkg_formatted_field(pkg, "Conffiles");
  8076. + strncat(buff ,line, strlen(line));
  8077. + free(line);
  8078. +
  8079. + line = pkg_formatted_field(pkg, "Source");
  8080. + strncat(buff ,line, strlen(line));
  8081. + free(line);
  8082. +
  8083. + line = pkg_formatted_field(pkg, "Description");
  8084. + strncat(buff ,line, strlen(line));
  8085. + free(line);
  8086. +
  8087. + line = pkg_formatted_field(pkg, "Installed-Time");
  8088. + strncat(buff ,line, strlen(line));
  8089. + free(line);
  8090. +
  8091. + return buff;
  8092. +}
  8093. +
  8094. +char * pkg_formatted_field(pkg_t *pkg, const char *field )
  8095. +{
  8096. + static size_t LINE_LEN = 128;
  8097. + char * temp = (char *)malloc(1);
  8098. + int len = 0;
  8099. + int flag_provide_false = 0;
  8100. +
  8101. +/*
  8102. + Pigi: After some discussion with Florian we decided to modify the full procedure in
  8103. + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
  8104. +*/
  8105. +
  8106. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8107. + goto UNKNOWN_FMT_FIELD;
  8108. + }
  8109. +
  8110. + temp[0]='\0';
  8111. +
  8112. + switch (field[0])
  8113. + {
  8114. + case 'a':
  8115. + case 'A':
  8116. + if (strcasecmp(field, "Architecture") == 0) {
  8117. + /* Architecture */
  8118. + if (pkg->architecture) {
  8119. + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
  8120. + if ( temp == NULL ){
  8121. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8122. + return NULL;
  8123. + }
  8124. + temp[0]='\0';
  8125. + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
  8126. + }
  8127. + } else {
  8128. + goto UNKNOWN_FMT_FIELD;
  8129. + }
  8130. + break;
  8131. + case 'c':
  8132. + case 'C':
  8133. + if (strcasecmp(field, "Conffiles") == 0) {
  8134. + /* Conffiles */
  8135. + conffile_list_elt_t *iter;
  8136. + char confstr_[LINE_LEN];
  8137. +
  8138. + if (pkg->conffiles.head == NULL) {
  8139. + return temp;
  8140. + }
  8141. +
  8142. + len = 14 ;
  8143. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8144. + if (iter->data->name && iter->data->value) {
  8145. + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
  8146. + }
  8147. + }
  8148. + temp = (char *)realloc(temp,len);
  8149. + if ( temp == NULL ){
  8150. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8151. + return NULL;
  8152. + }
  8153. + temp[0]='\0';
  8154. + strncpy(temp, "Conffiles:\n", 12);
  8155. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8156. + if (iter->data->name && iter->data->value) {
  8157. + snprintf(confstr_, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
  8158. + strncat(temp, confstr_, strlen(confstr_));
  8159. + }
  8160. + }
  8161. + } else if (strcasecmp(field, "Conflicts") == 0) {
  8162. + int i;
  8163. +
  8164. + if (pkg->conflicts_count) {
  8165. + char conflictstr[LINE_LEN];
  8166. + len = 14 ;
  8167. + for(i = 0; i < pkg->conflicts_count; i++) {
  8168. + len = len + (strlen(pkg->conflicts_str[i])+5);
  8169. + }
  8170. + temp = (char *)realloc(temp,len);
  8171. + if ( temp == NULL ){
  8172. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8173. + return NULL;
  8174. + }
  8175. + temp[0]='\0';
  8176. + strncpy(temp, "Conflicts:", 11);
  8177. + for(i = 0; i < pkg->conflicts_count; i++) {
  8178. + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
  8179. + strncat(temp, conflictstr, strlen(conflictstr));
  8180. + }
  8181. + strncat(temp, "\n", strlen("\n"));
  8182. + }
  8183. + } else {
  8184. + goto UNKNOWN_FMT_FIELD;
  8185. + }
  8186. + break;
  8187. + case 'd':
  8188. + case 'D':
  8189. + if (strcasecmp(field, "Depends") == 0) {
  8190. + /* Depends */
  8191. + int i;
  8192. +
  8193. + if (pkg->depends_count) {
  8194. + char depstr[LINE_LEN];
  8195. + len = 14 ;
  8196. + for(i = 0; i < pkg->depends_count; i++) {
  8197. + len = len + (strlen(pkg->depends_str[i])+4);
  8198. + }
  8199. + temp = (char *)realloc(temp,len);
  8200. + if ( temp == NULL ){
  8201. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8202. + return NULL;
  8203. + }
  8204. + temp[0]='\0';
  8205. + strncpy(temp, "Depends:", 10);
  8206. + for(i = 0; i < pkg->depends_count; i++) {
  8207. + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
  8208. + strncat(temp, depstr, strlen(depstr));
  8209. + }
  8210. + strncat(temp, "\n", strlen("\n"));
  8211. + }
  8212. + } else if (strcasecmp(field, "Description") == 0) {
  8213. + /* Description */
  8214. + if (pkg->description) {
  8215. + temp = (char *)realloc(temp,strlen(pkg->description)+16);
  8216. + if ( temp == NULL ){
  8217. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8218. + return NULL;
  8219. + }
  8220. + temp[0]='\0';
  8221. + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
  8222. + }
  8223. + } else {
  8224. + goto UNKNOWN_FMT_FIELD;
  8225. + }
  8226. + break;
  8227. + case 'e':
  8228. + case 'E': {
  8229. + /* Essential */
  8230. + if (pkg->essential) {
  8231. + temp = (char *)realloc(temp,16);
  8232. + if ( temp == NULL ){
  8233. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8234. + return NULL;
  8235. + }
  8236. + temp[0]='\0';
  8237. + snprintf(temp, (16), "Essential: yes\n");
  8238. + }
  8239. + }
  8240. + break;
  8241. + case 'f':
  8242. + case 'F': {
  8243. + /* Filename */
  8244. + if (pkg->filename) {
  8245. + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
  8246. + if ( temp == NULL ){
  8247. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8248. + return NULL;
  8249. + }
  8250. + temp[0]='\0';
  8251. + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
  8252. + }
  8253. + }
  8254. + break;
  8255. + case 'i':
  8256. + case 'I': {
  8257. + if (strcasecmp(field, "Installed-Size") == 0) {
  8258. + /* Installed-Size */
  8259. + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
  8260. + if ( temp == NULL ){
  8261. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8262. + return NULL;
  8263. + }
  8264. + temp[0]='\0';
  8265. + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
  8266. + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
  8267. + temp = (char *)realloc(temp,29);
  8268. + if ( temp == NULL ){
  8269. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8270. + return NULL;
  8271. + }
  8272. + temp[0]='\0';
  8273. + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
  8274. + }
  8275. + }
  8276. + break;
  8277. + case 'm':
  8278. + case 'M': {
  8279. + /* Maintainer | MD5sum */
  8280. + if (strcasecmp(field, "Maintainer") == 0) {
  8281. + /* Maintainer */
  8282. + if (pkg->maintainer) {
  8283. + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
  8284. + if ( temp == NULL ){
  8285. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8286. + return NULL;
  8287. + }
  8288. + temp[0]='\0';
  8289. + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
  8290. + }
  8291. + } else if (strcasecmp(field, "MD5sum") == 0) {
  8292. + /* MD5sum */
  8293. + if (pkg->md5sum) {
  8294. + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
  8295. + if ( temp == NULL ){
  8296. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8297. + return NULL;
  8298. + }
  8299. + temp[0]='\0';
  8300. + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
  8301. + }
  8302. + } else {
  8303. + goto UNKNOWN_FMT_FIELD;
  8304. + }
  8305. + }
  8306. + break;
  8307. + case 'p':
  8308. + case 'P': {
  8309. + if (strcasecmp(field, "Package") == 0) {
  8310. + /* Package */
  8311. + temp = (char *)realloc(temp,strlen(pkg->name)+11);
  8312. + if ( temp == NULL ){
  8313. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8314. + return NULL;
  8315. + }
  8316. + temp[0]='\0';
  8317. + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
  8318. + } else if (strcasecmp(field, "Priority") == 0) {
  8319. + /* Priority */
  8320. + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
  8321. + if ( temp == NULL ){
  8322. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8323. + return NULL;
  8324. + }
  8325. + temp[0]='\0';
  8326. + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
  8327. + } else if (strcasecmp(field, "Provides") == 0) {
  8328. + /* Provides */
  8329. + int i;
  8330. +
  8331. + if (pkg->provides_count) {
  8332. + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
  8333. + for ( i=0; i < pkg->provides_count; i++ ){
  8334. + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
  8335. + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
  8336. + flag_provide_false = 1;
  8337. + }
  8338. + }
  8339. + if ( !flag_provide_false || /* Pigi there is not my trick flag */
  8340. + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
  8341. + char provstr[LINE_LEN];
  8342. + len = 15;
  8343. + for(i = 0; i < pkg->provides_count; i++) {
  8344. + len = len + (strlen(pkg->provides_str[i])+5);
  8345. + }
  8346. + temp = (char *)realloc(temp,len);
  8347. + if ( temp == NULL ){
  8348. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8349. + return NULL;
  8350. + }
  8351. + temp[0]='\0';
  8352. + strncpy(temp, "Provides:", 12);
  8353. + for(i = 0; i < pkg->provides_count; i++) {
  8354. + if (strlen(pkg->provides_str[i])>0){;
  8355. + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
  8356. + strncat(temp, provstr, strlen(provstr));
  8357. + }
  8358. + }
  8359. + strncat(temp, "\n", strlen("\n"));
  8360. + }
  8361. + }
  8362. + } else {
  8363. + goto UNKNOWN_FMT_FIELD;
  8364. + }
  8365. + }
  8366. + break;
  8367. + case 'r':
  8368. + case 'R': {
  8369. + int i;
  8370. + /* Replaces | Recommends*/
  8371. + if (strcasecmp (field, "Replaces") == 0) {
  8372. + if (pkg->replaces_count) {
  8373. + char replstr[LINE_LEN];
  8374. + len = 14;
  8375. + for (i = 0; i < pkg->replaces_count; i++) {
  8376. + len = len + (strlen(pkg->replaces_str[i])+5);
  8377. + }
  8378. + temp = (char *)realloc(temp,len);
  8379. + if ( temp == NULL ){
  8380. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8381. + return NULL;
  8382. + }
  8383. + temp[0]='\0';
  8384. + strncpy(temp, "Replaces:", 12);
  8385. + for (i = 0; i < pkg->replaces_count; i++) {
  8386. + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
  8387. + strncat(temp, replstr, strlen(replstr));
  8388. + }
  8389. + strncat(temp, "\n", strlen("\n"));
  8390. + }
  8391. + } else if (strcasecmp (field, "Recommends") == 0) {
  8392. + if (pkg->recommends_count) {
  8393. + char recstr[LINE_LEN];
  8394. + len = 15;
  8395. + for(i = 0; i < pkg->recommends_count; i++) {
  8396. + len = len + (strlen( pkg->recommends_str[i])+5);
  8397. + }
  8398. + temp = (char *)realloc(temp,len);
  8399. + if ( temp == NULL ){
  8400. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8401. + return NULL;
  8402. + }
  8403. + temp[0]='\0';
  8404. + strncpy(temp, "Recommends:", 13);
  8405. + for(i = 0; i < pkg->recommends_count; i++) {
  8406. + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
  8407. + strncat(temp, recstr, strlen(recstr));
  8408. + }
  8409. + strncat(temp, "\n", strlen("\n"));
  8410. + }
  8411. + } else {
  8412. + goto UNKNOWN_FMT_FIELD;
  8413. + }
  8414. + }
  8415. + break;
  8416. + case 's':
  8417. + case 'S': {
  8418. + /* Section | Size | Source | Status | Suggests */
  8419. + if (strcasecmp(field, "Section") == 0) {
  8420. + /* Section */
  8421. + if (pkg->section) {
  8422. + temp = (char *)realloc(temp,strlen(pkg->section)+11);
  8423. + if ( temp == NULL ){
  8424. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8425. + return NULL;
  8426. + }
  8427. + temp[0]='\0';
  8428. + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
  8429. + }
  8430. + } else if (strcasecmp(field, "Size") == 0) {
  8431. + /* Size */
  8432. + if (pkg->size) {
  8433. + temp = (char *)realloc(temp,strlen(pkg->size)+8);
  8434. + if ( temp == NULL ){
  8435. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8436. + return NULL;
  8437. + }
  8438. + temp[0]='\0';
  8439. + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
  8440. + }
  8441. + } else if (strcasecmp(field, "Source") == 0) {
  8442. + /* Source */
  8443. + if (pkg->source) {
  8444. + temp = (char *)realloc(temp,strlen(pkg->source)+10);
  8445. + if ( temp == NULL ){
  8446. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8447. + return NULL;
  8448. + }
  8449. + temp[0]='\0';
  8450. + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
  8451. + }
  8452. + } else if (strcasecmp(field, "Status") == 0) {
  8453. + /* Status */
  8454. + /* Benjamin Pineau note: we should avoid direct usage of
  8455. + * strlen(arg) without keeping "arg" for later free()
  8456. + */
  8457. + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
  8458. + char *pstat=pkg_state_status_to_str(pkg->state_status);
  8459. + char *pwant=pkg_state_want_to_str(pkg->state_want);
  8460. +
  8461. + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
  8462. + temp = (char *)realloc(temp,sum_of_sizes);
  8463. + if ( temp == NULL ){
  8464. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8465. + return NULL;
  8466. + }
  8467. + temp[0]='\0';
  8468. + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
  8469. + free(pflag);
  8470. + free(pwant);
  8471. + if(pstat) /* pfstat can be NULL if ENOMEM */
  8472. + free(pstat);
  8473. + } else if (strcasecmp(field, "Suggests") == 0) {
  8474. + if (pkg->suggests_count) {
  8475. + int i;
  8476. + char sugstr[LINE_LEN];
  8477. + len = 13;
  8478. + for(i = 0; i < pkg->suggests_count; i++) {
  8479. + len = len + (strlen(pkg->suggests_str[i])+5);
  8480. + }
  8481. + temp = (char *)realloc(temp,len);
  8482. + if ( temp == NULL ){
  8483. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8484. + return NULL;
  8485. + }
  8486. + temp[0]='\0';
  8487. + strncpy(temp, "Suggests:", 10);
  8488. + for(i = 0; i < pkg->suggests_count; i++) {
  8489. + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
  8490. + strncat(temp, sugstr, strlen(sugstr));
  8491. + }
  8492. + strncat(temp, "\n", strlen("\n"));
  8493. + }
  8494. + } else {
  8495. + goto UNKNOWN_FMT_FIELD;
  8496. + }
  8497. + }
  8498. + break;
  8499. + case 'v':
  8500. + case 'V': {
  8501. + /* Version */
  8502. + char *version = pkg_version_str_alloc(pkg);
  8503. + temp = (char *)realloc(temp,strlen(version)+14);
  8504. + if ( temp == NULL ){
  8505. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8506. + return NULL;
  8507. + }
  8508. + temp[0]='\0';
  8509. + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
  8510. + free(version);
  8511. + }
  8512. + break;
  8513. + default:
  8514. + goto UNKNOWN_FMT_FIELD;
  8515. + }
  8516. +
  8517. + if ( strlen(temp)<2 ) {
  8518. + temp[0]='\0';
  8519. + }
  8520. + return temp;
  8521. +
  8522. + UNKNOWN_FMT_FIELD:
  8523. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
  8524. + if ( strlen(temp)<2 ) {
  8525. + temp[0]='\0';
  8526. + }
  8527. +
  8528. + return temp;
  8529. +}
  8530. +
  8531. +void pkg_print_info(pkg_t *pkg, FILE *file)
  8532. +{
  8533. + char * buff;
  8534. + if (pkg == NULL) {
  8535. + return;
  8536. + }
  8537. +
  8538. + buff = pkg_formatted_info(pkg);
  8539. + if ( buff == NULL )
  8540. + return;
  8541. + if (strlen(buff)>2){
  8542. + fwrite(buff, 1, strlen(buff), file);
  8543. + }
  8544. + free(buff);
  8545. +}
  8546. +
  8547. +void pkg_print_status(pkg_t * pkg, FILE * file)
  8548. +{
  8549. + if (pkg == NULL) {
  8550. + return;
  8551. + }
  8552. +
  8553. + /* XXX: QUESTION: Do we actually want more fields here? The
  8554. + original idea was to save space by installing only what was
  8555. + needed for actual computation, (package, version, status,
  8556. + essential, conffiles). The assumption is that all other fields
  8557. + can be found in th available file.
  8558. +
  8559. + But, someone proposed the idea to make it possible to
  8560. + reconstruct a .ipk from an installed package, (ie. for beaming
  8561. + from one handheld to another). So, maybe we actually want a few
  8562. + more fields here, (depends, suggests, etc.), so that that would
  8563. + be guaranteed to work even in the absence of more information
  8564. + from the available file.
  8565. +
  8566. + 28-MAR-03: kergoth and I discussed this yesterday. We think
  8567. + the essential info needs to be here for all installed packages
  8568. + because they may not appear in the Packages files on various
  8569. + feeds. Furthermore, one should be able to install from URL or
  8570. + local storage without requiring a Packages file from any feed.
  8571. + -Jamey
  8572. + */
  8573. + pkg_print_field(pkg, file, "Package");
  8574. + pkg_print_field(pkg, file, "Version");
  8575. + pkg_print_field(pkg, file, "Depends");
  8576. + pkg_print_field(pkg, file, "Recommends");
  8577. + pkg_print_field(pkg, file, "Suggests");
  8578. + pkg_print_field(pkg, file, "Provides");
  8579. + pkg_print_field(pkg, file, "Replaces");
  8580. + pkg_print_field(pkg, file, "Conflicts");
  8581. + pkg_print_field(pkg, file, "Status");
  8582. + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
  8583. + pkg_print_field(pkg, file, "Architecture");
  8584. + pkg_print_field(pkg, file, "Conffiles");
  8585. + pkg_print_field(pkg, file, "Installed-Time");
  8586. + fputs("\n", file);
  8587. +}
  8588. +
  8589. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
  8590. +{
  8591. + char *buff;
  8592. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8593. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
  8594. + __FUNCTION__, field);
  8595. + }
  8596. + buff = pkg_formatted_field(pkg, field);
  8597. + if (strlen(buff)>2) {
  8598. + fprintf(file, "%s", buff);
  8599. + fflush(file);
  8600. + }
  8601. + free(buff);
  8602. + return;
  8603. +}
  8604. +
  8605. +/*
  8606. + * libdpkg - Debian packaging suite library routines
  8607. + * vercmp.c - comparison of version numbers
  8608. + *
  8609. + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  8610. + */
  8611. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
  8612. +{
  8613. + int r;
  8614. +
  8615. + if (pkg->epoch > ref_pkg->epoch) {
  8616. + return 1;
  8617. + }
  8618. +
  8619. + if (pkg->epoch < ref_pkg->epoch) {
  8620. + return -1;
  8621. + }
  8622. +
  8623. + r = verrevcmp(pkg->version, ref_pkg->version);
  8624. + if (r) {
  8625. + return r;
  8626. + }
  8627. +
  8628. +#ifdef USE_DEBVERSION
  8629. + r = verrevcmp(pkg->revision, ref_pkg->revision);
  8630. + if (r) {
  8631. + return r;
  8632. + }
  8633. +
  8634. + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
  8635. +#endif
  8636. +
  8637. + return r;
  8638. +}
  8639. +
  8640. +int verrevcmp(const char *val, const char *ref)
  8641. +{
  8642. + int vc, rc;
  8643. + long vl, rl;
  8644. + const char *vp, *rp;
  8645. + const char *vsep, *rsep;
  8646. +
  8647. + if (!val) val= "";
  8648. + if (!ref) ref= "";
  8649. + for (;;) {
  8650. + vp= val; while (*vp && !isdigit(*vp)) vp++;
  8651. + rp= ref; while (*rp && !isdigit(*rp)) rp++;
  8652. + for (;;) {
  8653. + vc= (val == vp) ? 0 : *val++;
  8654. + rc= (ref == rp) ? 0 : *ref++;
  8655. + if (!rc && !vc) break;
  8656. + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
  8657. + if (rc && !isalpha(rc)) rc += 256;
  8658. + if (vc != rc) return vc - rc;
  8659. + }
  8660. + val= vp;
  8661. + ref= rp;
  8662. + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
  8663. + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
  8664. + if (vl != rl) return vl - rl;
  8665. +
  8666. + vc = *val;
  8667. + rc = *ref;
  8668. + vsep = strchr(".-", vc);
  8669. + rsep = strchr(".-", rc);
  8670. + if (vsep && !rsep) return -1;
  8671. + if (!vsep && rsep) return +1;
  8672. +
  8673. + if (!*val && !*ref) return 0;
  8674. + if (!*val) return -1;
  8675. + if (!*ref) return +1;
  8676. + }
  8677. +}
  8678. +
  8679. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
  8680. +{
  8681. + int r;
  8682. +
  8683. + r = pkg_compare_versions(it, ref);
  8684. +
  8685. + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
  8686. + return r <= 0;
  8687. + }
  8688. +
  8689. + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
  8690. + return r >= 0;
  8691. + }
  8692. +
  8693. + if (strcmp(op, "<<") == 0) {
  8694. + return r < 0;
  8695. + }
  8696. +
  8697. + if (strcmp(op, ">>") == 0) {
  8698. + return r > 0;
  8699. + }
  8700. +
  8701. + if (strcmp(op, "=") == 0) {
  8702. + return r == 0;
  8703. + }
  8704. +
  8705. + fprintf(stderr, "unknown operator: %s", op);
  8706. + return 0;
  8707. +}
  8708. +
  8709. +int pkg_name_version_and_architecture_compare(pkg_t *p1, pkg_t *p2)
  8710. +{
  8711. + const pkg_t *a = *(const pkg_t **)p1;
  8712. + const pkg_t *b = *(const pkg_t **)p2;
  8713. + int namecmp;
  8714. + int vercmp;
  8715. + if (!a->name || !b->name) {
  8716. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8717. + a, a->name, b, b->name);
  8718. + return 0;
  8719. + }
  8720. +
  8721. + namecmp = strcmp(a->name, b->name);
  8722. + if (namecmp)
  8723. + return namecmp;
  8724. + vercmp = pkg_compare_versions(a, b);
  8725. + if (vercmp)
  8726. + return vercmp;
  8727. + if (!a->arch_priority || !b->arch_priority) {
  8728. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
  8729. + a, a->arch_priority, b, b->arch_priority);
  8730. + return 0;
  8731. + }
  8732. + if (a->arch_priority > b->arch_priority)
  8733. + return 1;
  8734. + if (a->arch_priority < b->arch_priority)
  8735. + return -1;
  8736. + return 0;
  8737. +}
  8738. +
  8739. +int abstract_pkg_name_compare(abstract_pkg_t *p1, abstract_pkg_t *p2)
  8740. +{
  8741. + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
  8742. + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
  8743. + if (!a->name || !b->name) {
  8744. + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8745. + a, a->name, b, b->name);
  8746. + return 0;
  8747. + }
  8748. + return strcmp(a->name, b->name);
  8749. +}
  8750. +
  8751. +
  8752. +char *pkg_version_str_alloc(pkg_t *pkg)
  8753. +{
  8754. + char *complete_version;
  8755. + char *epoch_str;
  8756. +#ifdef USE_DEBVERSION
  8757. + char *revision_str;
  8758. + char *familiar_revision_str;
  8759. +#endif
  8760. +
  8761. + if (pkg->epoch) {
  8762. + sprintf_alloc(&epoch_str, "%lu:", (unsigned long)pkg->epoch);
  8763. + } else {
  8764. + epoch_str = strdup("");
  8765. + }
  8766. +
  8767. +#ifdef USE_DEBVERSION
  8768. + if (pkg->revision && strlen(pkg->revision)) {
  8769. + sprintf_alloc(&revision_str, "-%s", pkg->revision);
  8770. + } else {
  8771. + revision_str = strdup("");
  8772. + }
  8773. +
  8774. + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
  8775. + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
  8776. + } else {
  8777. + familiar_revision_str = strdup("");
  8778. + }
  8779. +#endif
  8780. +
  8781. +#ifdef USE_DEBVERSION
  8782. + sprintf_alloc(&complete_version, "%s%s%s%s",
  8783. + epoch_str, pkg->version, revision_str, familiar_revision_str);
  8784. +#else
  8785. + sprintf_alloc(&complete_version, "%s%s",
  8786. + epoch_str, pkg->version);
  8787. +#endif
  8788. +
  8789. + free(epoch_str);
  8790. +#ifdef USE_DEBVERSION
  8791. + free(revision_str);
  8792. + free(familiar_revision_str);
  8793. +#endif
  8794. +
  8795. + return complete_version;
  8796. +}
  8797. +
  8798. +str_list_t *pkg_get_installed_files(pkg_t *pkg)
  8799. +{
  8800. + int err;
  8801. + char *list_file_name = NULL;
  8802. + FILE *list_file = NULL;
  8803. + char *line;
  8804. + char *installed_file_name;
  8805. + int rootdirlen;
  8806. +
  8807. + pkg->installed_files_ref_cnt++;
  8808. +
  8809. + if (pkg->installed_files) {
  8810. + return pkg->installed_files;
  8811. + }
  8812. +
  8813. + pkg->installed_files = str_list_alloc();
  8814. + if (pkg->installed_files == NULL) {
  8815. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8816. + return NULL;
  8817. + }
  8818. +
  8819. + /* For uninstalled packages, get the file list firectly from the package.
  8820. + For installed packages, look at the package.list file in the database.
  8821. + */
  8822. + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
  8823. + if (pkg->local_filename == NULL) {
  8824. + return pkg->installed_files;
  8825. + }
  8826. + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
  8827. + file. In other words, change deb_extract so that it can
  8828. + simply return the file list as a char *[] rather than
  8829. + insisting on writing in to a FILE * as it does now. */
  8830. + list_file = tmpfile();
  8831. + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
  8832. + if (err) {
  8833. + fclose(list_file);
  8834. + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
  8835. + __FUNCTION__, pkg->local_filename, strerror(err));
  8836. + return pkg->installed_files;
  8837. + }
  8838. + rewind(list_file);
  8839. + } else {
  8840. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8841. + pkg->dest->info_dir, pkg->name);
  8842. + if (! file_exists(list_file_name)) {
  8843. + free(list_file_name);
  8844. + return pkg->installed_files;
  8845. + }
  8846. +
  8847. + list_file = fopen(list_file_name, "r");
  8848. + if (list_file == NULL) {
  8849. + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
  8850. + list_file_name, strerror(errno));
  8851. + free(list_file_name);
  8852. + return pkg->installed_files;
  8853. + }
  8854. + free(list_file_name);
  8855. + }
  8856. +
  8857. + rootdirlen = strlen( pkg->dest->root_dir );
  8858. + while (1) {
  8859. + char *file_name;
  8860. +
  8861. + line = file_read_line_alloc(list_file);
  8862. + if (line == NULL) {
  8863. + break;
  8864. + }
  8865. + str_chomp(line);
  8866. + file_name = line;
  8867. +
  8868. + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
  8869. + if( strncmp( pkg->dest->root_dir,
  8870. + file_name,
  8871. + rootdirlen ) ) {
  8872. + if (*file_name == '.') {
  8873. + file_name++;
  8874. + }
  8875. + if (*file_name == '/') {
  8876. + file_name++;
  8877. + }
  8878. +
  8879. + /* Freed in pkg_free_installed_files */
  8880. + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
  8881. + } else {
  8882. + // already contains root_dir as header -> ABSOLUTE
  8883. + sprintf_alloc(&installed_file_name, "%s", file_name);
  8884. + }
  8885. + str_list_append(pkg->installed_files, installed_file_name);
  8886. + free(line);
  8887. + }
  8888. +
  8889. + fclose(list_file);
  8890. +
  8891. + return pkg->installed_files;
  8892. +}
  8893. +
  8894. +/* XXX: CLEANUP: This function and it's counterpart,
  8895. + (pkg_get_installed_files), do not match our init/deinit naming
  8896. + convention. Nor the alloc/free convention. But, then again, neither
  8897. + of these conventions currrently fit the way these two functions
  8898. + work. */
  8899. +int pkg_free_installed_files(pkg_t *pkg)
  8900. +{
  8901. + str_list_elt_t *iter;
  8902. +
  8903. + pkg->installed_files_ref_cnt--;
  8904. + if (pkg->installed_files_ref_cnt > 0) {
  8905. + return 0;
  8906. + }
  8907. +
  8908. + if (pkg->installed_files) {
  8909. +
  8910. + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
  8911. + /* malloced in pkg_get_installed_files */
  8912. + free (iter->data);
  8913. + iter->data = NULL;
  8914. + }
  8915. +
  8916. + str_list_deinit(pkg->installed_files);
  8917. + }
  8918. +
  8919. + pkg->installed_files = NULL;
  8920. +
  8921. + return 0;
  8922. +}
  8923. +
  8924. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
  8925. +{
  8926. + int err;
  8927. + char *list_file_name;
  8928. +
  8929. + //I don't think pkg_free_installed_files should be called here. Jamey
  8930. + //pkg_free_installed_files(pkg);
  8931. +
  8932. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8933. + pkg->dest->info_dir, pkg->name);
  8934. + if (!conf->noaction) {
  8935. + err = unlink(list_file_name);
  8936. + free(list_file_name);
  8937. +
  8938. + if (err) {
  8939. + return errno;
  8940. + }
  8941. + }
  8942. + return 0;
  8943. +}
  8944. +
  8945. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
  8946. +{
  8947. + conffile_list_elt_t *iter;
  8948. + conffile_t *conffile;
  8949. +
  8950. + if (pkg == NULL) {
  8951. + return NULL;
  8952. + }
  8953. +
  8954. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8955. + conffile = iter->data;
  8956. +
  8957. + if (strcmp(conffile->name, file_name) == 0) {
  8958. + return conffile;
  8959. + }
  8960. + }
  8961. +
  8962. + return NULL;
  8963. +}
  8964. +
  8965. +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
  8966. + const char *script, const char *args)
  8967. +{
  8968. + int err;
  8969. + char *path;
  8970. + char *cmd;
  8971. +
  8972. + /* XXX: FEATURE: When conf->offline_root is set, we should run the
  8973. + maintainer script within a chroot environment. */
  8974. +
  8975. + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
  8976. + have scripts in pkg->tmp_unpack_dir. */
  8977. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  8978. + if (pkg->dest == NULL) {
  8979. + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
  8980. + __FUNCTION__, pkg->name);
  8981. + return EINVAL;
  8982. + }
  8983. + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
  8984. + } else {
  8985. + if (pkg->tmp_unpack_dir == NULL) {
  8986. + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
  8987. + __FUNCTION__, pkg->name);
  8988. + return EINVAL;
  8989. + }
  8990. + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
  8991. + }
  8992. +
  8993. + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
  8994. + if (conf->noaction) return 0;
  8995. +
  8996. + /* XXX: CLEANUP: There must be a better way to handle maintainer
  8997. + scripts when running with offline_root mode and/or a dest other
  8998. + than '/'. I've been playing around with some clever chroot
  8999. + tricks and I might come up with something workable. */
  9000. + if (conf->offline_root) {
  9001. + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
  9002. + }
  9003. +
  9004. + setenv("PKG_ROOT",
  9005. + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
  9006. +
  9007. + if (! file_exists(path)) {
  9008. + free(path);
  9009. + return 0;
  9010. + }
  9011. +
  9012. + if (conf->offline_root) {
  9013. + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
  9014. + free(path);
  9015. + return 0;
  9016. + }
  9017. +
  9018. + sprintf_alloc(&cmd, "%s %s", path, args);
  9019. + free(path);
  9020. +
  9021. + err = xsystem(cmd);
  9022. + free(cmd);
  9023. +
  9024. + if (err) {
  9025. + fprintf(stderr, "%s script returned status %d\n", script, err);
  9026. + return err;
  9027. + }
  9028. +
  9029. + return 0;
  9030. +}
  9031. +
  9032. +char *pkg_state_want_to_str(pkg_state_want_t sw)
  9033. +{
  9034. + int i;
  9035. +
  9036. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9037. + if (pkg_state_want_map[i].value == sw) {
  9038. + return strdup(pkg_state_want_map[i].str);
  9039. + }
  9040. + }
  9041. +
  9042. + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
  9043. + __FUNCTION__, sw);
  9044. + return strdup("<STATE_WANT_UNKNOWN>");
  9045. +}
  9046. +
  9047. +pkg_state_want_t pkg_state_want_from_str(char *str)
  9048. +{
  9049. + int i;
  9050. +
  9051. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9052. + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
  9053. + return pkg_state_want_map[i].value;
  9054. + }
  9055. + }
  9056. +
  9057. + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
  9058. + __FUNCTION__, str);
  9059. + return SW_UNKNOWN;
  9060. +}
  9061. +
  9062. +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
  9063. +{
  9064. + int i;
  9065. + int len = 3; /* ok\000 is minimum */
  9066. + char *str = NULL;
  9067. +
  9068. + /* clear the temporary flags before converting to string */
  9069. + sf &= SF_NONVOLATILE_FLAGS;
  9070. +
  9071. + if (sf == 0) {
  9072. + return strdup("ok");
  9073. + } else {
  9074. +
  9075. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9076. + if (sf & pkg_state_flag_map[i].value) {
  9077. + len += strlen(pkg_state_flag_map[i].str) + 1;
  9078. + }
  9079. + }
  9080. + str = malloc(len);
  9081. + if ( str == NULL ) {
  9082. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9083. + return NULL;
  9084. + }
  9085. + str[0] = 0;
  9086. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9087. + if (sf & pkg_state_flag_map[i].value) {
  9088. + strcat(str, pkg_state_flag_map[i].str);
  9089. + strcat(str, ",");
  9090. + }
  9091. + }
  9092. + len = strlen(str);
  9093. + str[len-1] = 0; /* squash last comma */
  9094. + return str;
  9095. + }
  9096. +}
  9097. +
  9098. +pkg_state_flag_t pkg_state_flag_from_str(char *str)
  9099. +{
  9100. + int i;
  9101. + int sf = SF_OK;
  9102. +
  9103. + if (strcmp(str, "ok") == 0) {
  9104. + return SF_OK;
  9105. + }
  9106. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9107. + const char *sfname = pkg_state_flag_map[i].str;
  9108. + int sfname_len = strlen(sfname);
  9109. + if (strncmp(str, sfname, sfname_len) == 0) {
  9110. + sf |= pkg_state_flag_map[i].value;
  9111. + str += sfname_len;
  9112. + if (str[0] == ',') {
  9113. + str++;
  9114. + } else {
  9115. + break;
  9116. + }
  9117. + }
  9118. + }
  9119. +
  9120. + return sf;
  9121. +}
  9122. +
  9123. +char *pkg_state_status_to_str(pkg_state_status_t ss)
  9124. +{
  9125. + int i;
  9126. +
  9127. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9128. + if (pkg_state_status_map[i].value == ss) {
  9129. + return strdup(pkg_state_status_map[i].str);
  9130. + }
  9131. + }
  9132. +
  9133. + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
  9134. + __FUNCTION__, ss);
  9135. + return strdup("<STATE_STATUS_UNKNOWN>");
  9136. +}
  9137. +
  9138. +pkg_state_status_t pkg_state_status_from_str(char *str)
  9139. +{
  9140. + int i;
  9141. +
  9142. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9143. + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
  9144. + return pkg_state_status_map[i].value;
  9145. + }
  9146. + }
  9147. +
  9148. + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
  9149. + __FUNCTION__, str);
  9150. + return SS_NOT_INSTALLED;
  9151. +}
  9152. +
  9153. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
  9154. +{
  9155. + nv_pair_list_elt_t *l;
  9156. +
  9157. + if (!pkg->architecture)
  9158. + return 1;
  9159. +
  9160. + l = conf->arch_list.head;
  9161. +
  9162. + while (l) {
  9163. + nv_pair_t *nv = l->data;
  9164. + if (strcmp(nv->name, pkg->architecture) == 0) {
  9165. + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
  9166. + return 1;
  9167. + }
  9168. + l = l->next;
  9169. + }
  9170. +
  9171. + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
  9172. + return 0;
  9173. +}
  9174. +
  9175. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
  9176. +{
  9177. + nv_pair_list_elt_t *l;
  9178. +
  9179. + l = conf->arch_list.head;
  9180. +
  9181. + while (l) {
  9182. + nv_pair_t *nv = l->data;
  9183. + if (strcmp(nv->name, archname) == 0) {
  9184. + int priority = strtol(nv->value, NULL, 0);
  9185. + return priority;
  9186. + }
  9187. + l = l->next;
  9188. + }
  9189. + return 0;
  9190. +}
  9191. +
  9192. +int pkg_info_preinstall_check(ipkg_conf_t *conf)
  9193. +{
  9194. + int i;
  9195. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9196. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  9197. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9198. +
  9199. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
  9200. + pkg_hash_fetch_available(pkg_hash, available_pkgs);
  9201. + /* update arch_priority for each package */
  9202. + for (i = 0; i < available_pkgs->len; i++) {
  9203. + pkg_t *pkg = available_pkgs->pkgs[i];
  9204. + int arch_priority = 1;
  9205. + if (!pkg)
  9206. + continue;
  9207. + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
  9208. + if (pkg->architecture)
  9209. + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
  9210. + else
  9211. + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
  9212. + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
  9213. + pkg->arch_priority = arch_priority;
  9214. + }
  9215. +
  9216. + for (i = 0; i < available_pkgs->len; i++) {
  9217. + pkg_t *pkg = available_pkgs->pkgs[i];
  9218. + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
  9219. + /* clear flags and want for any uninstallable package */
  9220. + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
  9221. + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
  9222. + pkg->state_want = SW_UNKNOWN;
  9223. + pkg->state_flag = 0;
  9224. + }
  9225. + }
  9226. + pkg_vec_free(available_pkgs);
  9227. +
  9228. + /* update the file owner data structure */
  9229. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
  9230. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9231. + for (i = 0; i < installed_pkgs->len; i++) {
  9232. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9233. + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
  9234. + str_list_elt_t *iter;
  9235. + if (installed_files == NULL) {
  9236. + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
  9237. + break;
  9238. + }
  9239. + for (iter = installed_files->head; iter; iter = iter->next) {
  9240. + char *installed_file = iter->data;
  9241. + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
  9242. + file_hash_set_file_owner(conf, installed_file, pkg);
  9243. + }
  9244. + }
  9245. + pkg_vec_free(installed_pkgs);
  9246. +
  9247. + return 0;
  9248. +}
  9249. +
  9250. +struct pkg_write_filelist_data {
  9251. + ipkg_conf_t *conf;
  9252. + pkg_t *pkg;
  9253. + FILE *stream;
  9254. +};
  9255. +
  9256. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
  9257. +{
  9258. + struct pkg_write_filelist_data *data = data_;
  9259. + pkg_t *entry = entry_;
  9260. + if (entry == data->pkg) {
  9261. + fprintf(data->stream, "%s\n", key);
  9262. + }
  9263. +}
  9264. +
  9265. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
  9266. +{
  9267. + struct pkg_write_filelist_data data;
  9268. + char *list_file_name = NULL;
  9269. + int err = 0;
  9270. +
  9271. + if (!pkg) {
  9272. + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
  9273. + return -EINVAL;
  9274. + }
  9275. + ipkg_message(conf, IPKG_INFO,
  9276. + " creating %s.list file\n", pkg->name);
  9277. + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
  9278. + if (!list_file_name) {
  9279. + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
  9280. + return -ENOMEM;
  9281. + }
  9282. + ipkg_message(conf, IPKG_INFO,
  9283. + " creating %s file for pkg %s\n", list_file_name, pkg->name);
  9284. + data.stream = fopen(list_file_name, "w");
  9285. + if (!data.stream) {
  9286. + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
  9287. + list_file_name, strerror(errno));
  9288. + return errno;
  9289. + }
  9290. + data.pkg = pkg;
  9291. + data.conf = conf;
  9292. + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
  9293. + fclose(data.stream);
  9294. + free(list_file_name);
  9295. +
  9296. + return err;
  9297. +}
  9298. +
  9299. +int pkg_write_changed_filelists(ipkg_conf_t *conf)
  9300. +{
  9301. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9302. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9303. + int i;
  9304. + int err;
  9305. + if (conf->noaction)
  9306. + return 0;
  9307. +
  9308. + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
  9309. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9310. + for (i = 0; i < installed_pkgs->len; i++) {
  9311. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9312. + if (pkg->state_flag & SF_FILELIST_CHANGED) {
  9313. + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
  9314. + err = pkg_write_filelist(conf, pkg);
  9315. + if (err)
  9316. + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
  9317. + }
  9318. + }
  9319. + return 0;
  9320. +}
  9321. diff -Nur busybox-1.20.2.orig//archival/libipkg/pkg_depends.c busybox-1.20.2/archival/libipkg/pkg_depends.c
  9322. --- busybox-1.20.2.orig//archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
  9323. +++ busybox-1.20.2/archival/libipkg/pkg_depends.c 2013-01-31 16:44:31.000000000 +0100
  9324. @@ -0,0 +1,1032 @@
  9325. +/* pkg_depends.c - the itsy package management system
  9326. +
  9327. + Steven M. Ayer
  9328. +
  9329. + Copyright (C) 2002 Compaq Computer Corporation
  9330. +
  9331. + This program is free software; you can redistribute it and/or
  9332. + modify it under the terms of the GNU General Public License as
  9333. + published by the Free Software Foundation; either version 2, or (at
  9334. + your option) any later version.
  9335. +
  9336. + This program is distributed in the hope that it will be useful, but
  9337. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9338. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9339. + General Public License for more details.
  9340. +*/
  9341. +
  9342. +#include "ipkg.h"
  9343. +#include <errno.h>
  9344. +#include <ctype.h>
  9345. +
  9346. +#include "pkg.h"
  9347. +#include "ipkg_utils.h"
  9348. +#include "pkg_hash.h"
  9349. +#include "ipkg_message.h"
  9350. +#include "pkg_parse.h"
  9351. +#include "hash_table.h"
  9352. +
  9353. +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
  9354. +static depend_t * depend_init(void);
  9355. +static void depend_deinit(depend_t *d);
  9356. +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
  9357. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
  9358. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
  9359. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg);
  9360. +
  9361. +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
  9362. +{
  9363. + depend_t *depend = (depend_t *)cdata;
  9364. + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
  9365. + return 1;
  9366. + else
  9367. + return 0;
  9368. +}
  9369. +
  9370. +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
  9371. +{
  9372. + depend_t *depend = (depend_t *)cdata;
  9373. +#if 0
  9374. + pkg_t * temp = pkg_new();
  9375. + int comparison;
  9376. + parseVersion(temp, depend->version);
  9377. + comparison = pkg_compare_versions(pkg, temp);
  9378. + free(temp);
  9379. +
  9380. + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
  9381. + __FUNCTION__, pkg->name, pkg->version,
  9382. + depend, depend->constraint, depend->version,
  9383. + comparison, version_constraints_satisfied(depend, pkg));
  9384. +#endif
  9385. + if (version_constraints_satisfied(depend, pkg))
  9386. + return 1;
  9387. + else
  9388. + return 0;
  9389. +}
  9390. +
  9391. +/* returns ndependences or negative error value */
  9392. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
  9393. + pkg_vec_t *unsatisfied, char *** unresolved)
  9394. +{
  9395. + pkg_t * satisfier_entry_pkg;
  9396. + register int i, j, k, l;
  9397. + int count, found;
  9398. + char ** the_lost;
  9399. + abstract_pkg_t * ab_pkg;
  9400. +
  9401. + /*
  9402. + * this is a setup to check for redundant/cyclic dependency checks,
  9403. + * which are marked at the abstract_pkg level
  9404. + */
  9405. + if (!(ab_pkg = pkg->parent)) {
  9406. + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
  9407. + *unresolved = NULL;
  9408. + return 0;
  9409. + }
  9410. + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
  9411. + *unresolved = NULL;
  9412. + return 0;
  9413. + } else {
  9414. + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
  9415. + }
  9416. + /**/
  9417. +
  9418. + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
  9419. + if (!count){
  9420. + *unresolved = NULL;
  9421. + return 0;
  9422. + }
  9423. +
  9424. + the_lost = NULL;
  9425. +
  9426. + /* foreach dependency */
  9427. + for (i = 0; i < count; i++) {
  9428. + compound_depend_t * compound_depend = &pkg->depends[i];
  9429. + depend_t ** possible_satisfiers = compound_depend->possibilities;;
  9430. + found = 0;
  9431. + satisfier_entry_pkg = NULL;
  9432. +
  9433. + if (compound_depend->type == GREEDY_DEPEND) {
  9434. + /* foreach possible satisfier */
  9435. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9436. + /* foreach provided_by, which includes the abstract_pkg itself */
  9437. + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
  9438. + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
  9439. + int nposs = ab_provider_vec->len;
  9440. + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
  9441. + for (l = 0; l < nposs; l++) {
  9442. + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
  9443. + /* if no depends on this one, try the first package that Provides this one */
  9444. + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
  9445. + continue;
  9446. + }
  9447. +
  9448. + /* cruise this possiblity's pkg_vec looking for an installed version */
  9449. + for (k = 0; k < test_vec->len; k++) {
  9450. + pkg_t *pkg_scout = test_vec->pkgs[k];
  9451. + /* not installed, and not already known about? */
  9452. + if ((pkg_scout->state_want != SW_INSTALL)
  9453. + && !pkg_scout->parent->dependencies_checked
  9454. + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
  9455. + char ** newstuff = NULL;
  9456. + int rc;
  9457. + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
  9458. + /* check for not-already-installed dependencies */
  9459. + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
  9460. + pkg_scout,
  9461. + tmp_vec,
  9462. + &newstuff);
  9463. + if (newstuff == NULL) {
  9464. + int ok = 1;
  9465. + for (i = 0; i < rc; i++) {
  9466. + pkg_t *p = tmp_vec->pkgs[i];
  9467. + if (p->state_want == SW_INSTALL)
  9468. + continue;
  9469. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
  9470. + ok = 0;
  9471. + break;
  9472. + }
  9473. + pkg_vec_free (tmp_vec);
  9474. + if (ok) {
  9475. + /* mark this one for installation */
  9476. + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
  9477. + pkg_vec_insert(unsatisfied, pkg_scout);
  9478. + }
  9479. + } else {
  9480. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
  9481. + free (newstuff);
  9482. + }
  9483. + }
  9484. + }
  9485. + }
  9486. + }
  9487. +
  9488. + continue;
  9489. + }
  9490. +
  9491. + /* foreach possible satisfier, look for installed package */
  9492. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9493. + /* foreach provided_by, which includes the abstract_pkg itself */
  9494. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9495. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9496. + pkg_t *satisfying_pkg =
  9497. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9498. + pkg_installed_and_constraint_satisfied,
  9499. + dependence_to_satisfy, 1);
  9500. + /* Being that I can't test constraing in pkg_hash, I will test it here */
  9501. + if (satisfying_pkg != NULL) {
  9502. + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9503. + satisfying_pkg = NULL;
  9504. + }
  9505. + }
  9506. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
  9507. + if (satisfying_pkg != NULL) {
  9508. + found = 1;
  9509. + break;
  9510. + }
  9511. +
  9512. + }
  9513. + /* if nothing installed matches, then look for uninstalled satisfier */
  9514. + if (!found) {
  9515. + /* foreach possible satisfier, look for installed package */
  9516. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9517. + /* foreach provided_by, which includes the abstract_pkg itself */
  9518. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9519. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9520. + pkg_t *satisfying_pkg =
  9521. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9522. + pkg_constraint_satisfied,
  9523. + dependence_to_satisfy, 1);
  9524. + /* Being that I can't test constraing in pkg_hash, I will test it here too */
  9525. + if (satisfying_pkg != NULL) {
  9526. + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9527. + satisfying_pkg = NULL;
  9528. + }
  9529. + }
  9530. +
  9531. + /* user request overrides package recommendation */
  9532. + if (satisfying_pkg != NULL
  9533. + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
  9534. + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
  9535. + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
  9536. + pkg->name, satisfying_pkg->name);
  9537. + continue;
  9538. + }
  9539. +
  9540. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
  9541. + if (satisfying_pkg != NULL) {
  9542. + satisfier_entry_pkg = satisfying_pkg;
  9543. + break;
  9544. + }
  9545. + }
  9546. + }
  9547. +
  9548. + /* we didn't find one, add something to the unsatisfied vector */
  9549. + if (!found) {
  9550. + if (!satisfier_entry_pkg) {
  9551. + /* failure to meet recommendations is not an error */
  9552. + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
  9553. + the_lost = add_unresolved_dep(pkg, the_lost, i);
  9554. + else
  9555. + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
  9556. + pkg->name, compound_depend->possibilities[0]->pkg->name);
  9557. + }
  9558. + else {
  9559. + if (compound_depend->type == SUGGEST) {
  9560. + /* just mention it politely */
  9561. + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
  9562. + pkg->name, satisfier_entry_pkg->name);
  9563. + } else {
  9564. + char ** newstuff = NULL;
  9565. +
  9566. + if (satisfier_entry_pkg != pkg &&
  9567. + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
  9568. + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
  9569. + pkg_hash_fetch_unsatisfied_dependencies(conf,
  9570. + satisfier_entry_pkg,
  9571. + unsatisfied,
  9572. + &newstuff);
  9573. + the_lost = merge_unresolved(the_lost, newstuff);
  9574. + }
  9575. + }
  9576. + }
  9577. + }
  9578. + }
  9579. + *unresolved = the_lost;
  9580. +
  9581. + return unsatisfied->len;
  9582. +}
  9583. +
  9584. +/*checking for conflicts !in replaces
  9585. + If a packages conflicts with another but is also replacing it, I should not consider it a
  9586. + really conflicts
  9587. + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
  9588. +*/
  9589. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
  9590. +{
  9591. + int i ;
  9592. + int replaces_count = pkg->replaces_count;
  9593. + abstract_pkg_t **replaces;
  9594. +
  9595. + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
  9596. + return 0;
  9597. +
  9598. + replaces = pkg->replaces;
  9599. +
  9600. + for (i = 0; i < replaces_count; i++) {
  9601. + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
  9602. + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
  9603. + return 1;
  9604. + }
  9605. + }
  9606. + return 0;
  9607. +
  9608. +}
  9609. +
  9610. +
  9611. +/* Abhaya: added support for conflicts */
  9612. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg)
  9613. +{
  9614. + pkg_vec_t * installed_conflicts, * test_vec;
  9615. + compound_depend_t * conflicts;
  9616. + depend_t ** possible_satisfiers;
  9617. + depend_t * possible_satisfier;
  9618. + register int i, j, k;
  9619. + int count;
  9620. + abstract_pkg_t * ab_pkg;
  9621. + pkg_t **pkg_scouts;
  9622. + pkg_t *pkg_scout;
  9623. +
  9624. + /*
  9625. + * this is a setup to check for redundant/cyclic dependency checks,
  9626. + * which are marked at the abstract_pkg level
  9627. + */
  9628. + if(!(ab_pkg = pkg->parent)){
  9629. + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
  9630. + return (pkg_vec_t *)NULL;
  9631. + }
  9632. +
  9633. + conflicts = pkg->conflicts;
  9634. + if(!conflicts){
  9635. + return (pkg_vec_t *)NULL;
  9636. + }
  9637. + installed_conflicts = pkg_vec_alloc();
  9638. +
  9639. + count = pkg->conflicts_count;
  9640. +
  9641. +
  9642. +
  9643. + /* foreach conflict */
  9644. + for(i = 0; i < pkg->conflicts_count; i++){
  9645. +
  9646. + possible_satisfiers = conflicts->possibilities;
  9647. +
  9648. + /* foreach possible satisfier */
  9649. + for(j = 0; j < conflicts->possibility_count; j++){
  9650. + possible_satisfier = possible_satisfiers[j];
  9651. + if (!possible_satisfier)
  9652. + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
  9653. + if (!possible_satisfier->pkg)
  9654. + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
  9655. + test_vec = possible_satisfier->pkg->pkgs;
  9656. + if (test_vec) {
  9657. + /* pkg_vec found, it is an actual package conflict
  9658. + * cruise this possiblity's pkg_vec looking for an installed version */
  9659. + pkg_scouts = test_vec->pkgs;
  9660. + for(k = 0; k < test_vec->len; k++){
  9661. + pkg_scout = pkg_scouts[k];
  9662. + if (!pkg_scout) {
  9663. + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
  9664. + continue;
  9665. + }
  9666. + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
  9667. + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
  9668. + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
  9669. + pkg_vec_insert(installed_conflicts, pkg_scout);
  9670. + }
  9671. + }
  9672. + }
  9673. + }
  9674. + }
  9675. + conflicts++;
  9676. + }
  9677. +
  9678. + if (installed_conflicts->len)
  9679. + return installed_conflicts;
  9680. + pkg_vec_free(installed_conflicts);
  9681. + return (pkg_vec_t *)NULL;
  9682. +}
  9683. +
  9684. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
  9685. +{
  9686. + pkg_t * temp;
  9687. + int comparison;
  9688. +
  9689. + if(depends->constraint == NONE)
  9690. + return 1;
  9691. +
  9692. + temp = pkg_new();
  9693. +
  9694. + parseVersion(temp, depends->version);
  9695. +
  9696. + comparison = pkg_compare_versions(pkg, temp);
  9697. +
  9698. + free(temp);
  9699. +
  9700. + if((depends->constraint == EARLIER) &&
  9701. + (comparison < 0))
  9702. + return 1;
  9703. + else if((depends->constraint == LATER) &&
  9704. + (comparison > 0))
  9705. + return 1;
  9706. + else if(comparison == 0)
  9707. + return 1;
  9708. + else if((depends->constraint == LATER_EQUAL) &&
  9709. + (comparison >= 0))
  9710. + return 1;
  9711. + else if((depends->constraint == EARLIER_EQUAL) &&
  9712. + (comparison <= 0))
  9713. + return 1;
  9714. +
  9715. + return 0;
  9716. +}
  9717. +
  9718. +int pkg_dependence_satisfiable(depend_t *depend)
  9719. +{
  9720. + abstract_pkg_t *apkg = depend->pkg;
  9721. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9722. + int n_providers = provider_apkgs->len;
  9723. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9724. + pkg_vec_t *pkg_vec;
  9725. + int n_pkgs ;
  9726. + int i;
  9727. + int j;
  9728. +
  9729. + for (i = 0; i < n_providers; i++) {
  9730. + abstract_pkg_t *papkg = apkgs[i];
  9731. + pkg_vec = papkg->pkgs;
  9732. + if (pkg_vec) {
  9733. + n_pkgs = pkg_vec->len;
  9734. + for (j = 0; j < n_pkgs; j++) {
  9735. + pkg_t *pkg = pkg_vec->pkgs[j];
  9736. + if (version_constraints_satisfied(depend, pkg)) {
  9737. + return 1;
  9738. + }
  9739. + }
  9740. + }
  9741. + }
  9742. + return 0;
  9743. +}
  9744. +
  9745. +int pkg_dependence_satisfied(depend_t *depend)
  9746. +{
  9747. + abstract_pkg_t *apkg = depend->pkg;
  9748. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9749. + int n_providers = provider_apkgs->len;
  9750. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9751. + int i;
  9752. + int n_pkgs;
  9753. + int j;
  9754. +
  9755. + for (i = 0; i < n_providers; i++) {
  9756. + abstract_pkg_t *papkg = apkgs[i];
  9757. + pkg_vec_t *pkg_vec = papkg->pkgs;
  9758. + if (pkg_vec) {
  9759. + n_pkgs = pkg_vec->len;
  9760. + for (j = 0; j < n_pkgs; j++) {
  9761. + pkg_t *pkg = pkg_vec->pkgs[j];
  9762. + if (version_constraints_satisfied(depend, pkg)) {
  9763. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
  9764. + return 1;
  9765. + }
  9766. + }
  9767. + }
  9768. + }
  9769. + return 0;
  9770. +}
  9771. +
  9772. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
  9773. +{
  9774. + register int i;
  9775. + pkg_t ** pkgs = vec->pkgs;
  9776. +
  9777. + for(i = 0; i < vec->len; i++)
  9778. + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
  9779. + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
  9780. + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
  9781. + return 1;
  9782. + return 0;
  9783. +}
  9784. +
  9785. +
  9786. +#ifdef DeadCode
  9787. +/**
  9788. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  9789. + * the same abstract package and 0 otherwise.
  9790. + */
  9791. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
  9792. +{
  9793. + abstract_pkg_t **provides = pkg->provides;
  9794. + int provides_count = pkg->provides_count;
  9795. + abstract_pkg_t **replacee_provides = replacee->provides;
  9796. + int replacee_provides_count = replacee->provides_count;
  9797. + int i, j;
  9798. + for (i = 0; i < provides_count; i++) {
  9799. + abstract_pkg_t *apkg = provides[i];
  9800. + for (j = 0; j < replacee_provides_count; j++) {
  9801. + abstract_pkg_t *replacee_apkg = replacee_provides[i];
  9802. + if (apkg == replacee_apkg)
  9803. + return 1;
  9804. + }
  9805. + }
  9806. + return 0;
  9807. +}
  9808. +#endif
  9809. +
  9810. +/**
  9811. + * pkg_provides_abstract returns 1 if pkg->provides contains providee
  9812. + * and 0 otherwise.
  9813. + */
  9814. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
  9815. +{
  9816. + abstract_pkg_t **provides = pkg->provides;
  9817. + int provides_count = pkg->provides_count;
  9818. + int i;
  9819. + for (i = 0; i < provides_count; i++) {
  9820. + if (provides[i] == providee)
  9821. + return 1;
  9822. + }
  9823. + return 0;
  9824. +}
  9825. +
  9826. +/**
  9827. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  9828. + * otherwise.
  9829. + */
  9830. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
  9831. +{
  9832. + abstract_pkg_t **replaces = pkg->replaces;
  9833. + int replaces_count = pkg->replaces_count;
  9834. + /* abstract_pkg_t **replacee_provides = pkg->provides;
  9835. + int replacee_provides_count = pkg->provides_count; */
  9836. + int i, j;
  9837. + for (i = 0; i < replaces_count; i++) {
  9838. + abstract_pkg_t *abstract_replacee = replaces[i];
  9839. + for (j = 0; j < replaces_count; j++) {
  9840. + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
  9841. + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
  9842. + if (replacee->provides[j] == abstract_replacee)
  9843. + return 1;
  9844. + }
  9845. + }
  9846. + return 0;
  9847. +}
  9848. +
  9849. +
  9850. +/**
  9851. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
  9852. + * otherwise.
  9853. + */
  9854. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
  9855. +{
  9856. + compound_depend_t *conflicts = pkg->conflicts;
  9857. + int conflicts_count = pkg->conflicts_count;
  9858. + int i, j;
  9859. + for (i = 0; i < conflicts_count; i++) {
  9860. + int possibility_count = conflicts[i].possibility_count;
  9861. + struct depend **possibilities = conflicts[i].possibilities;
  9862. + for (j = 0; j < possibility_count; j++) {
  9863. + if (possibilities[j]->pkg == conflictee) {
  9864. + return 1;
  9865. + }
  9866. + }
  9867. + }
  9868. + return 0;
  9869. +}
  9870. +
  9871. +/**
  9872. + * pkg_conflicts returns 1 if pkg->conflicts contains one of
  9873. + * conflictee's provides and 0 otherwise.
  9874. + */
  9875. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
  9876. +{
  9877. + compound_depend_t *conflicts = pkg->conflicts;
  9878. + int conflicts_count = pkg->conflicts_count;
  9879. + abstract_pkg_t **conflictee_provides = conflictee->provides;
  9880. + int conflictee_provides_count = conflictee->provides_count;
  9881. + int i, j, k;
  9882. + int possibility_count;
  9883. + struct depend **possibilities;
  9884. + abstract_pkg_t *possibility ;
  9885. +
  9886. + for (i = 0; i < conflicts_count; i++) {
  9887. + possibility_count = conflicts[i].possibility_count;
  9888. + possibilities = conflicts[i].possibilities;
  9889. + for (j = 0; j < possibility_count; j++) {
  9890. + possibility = possibilities[j]->pkg;
  9891. + for (k = 0; k < conflictee_provides_count; k++) {
  9892. + if (possibility == conflictee_provides[k]) {
  9893. + return 1;
  9894. + }
  9895. + }
  9896. + }
  9897. + }
  9898. + return 0;
  9899. +}
  9900. +
  9901. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
  9902. +{
  9903. + int oldlen = 0, newlen = 0;
  9904. + char ** result;
  9905. + register int i, j;
  9906. +
  9907. + if(!newstuff)
  9908. + return oldstuff;
  9909. +
  9910. + while(oldstuff && oldstuff[oldlen]) oldlen++;
  9911. + while(newstuff && newstuff[newlen]) newlen++;
  9912. +
  9913. + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
  9914. + if (result == NULL) {
  9915. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9916. + return NULL;
  9917. + }
  9918. +
  9919. + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
  9920. + *(result + i) = *(newstuff + j);
  9921. +
  9922. + *(result + i) = NULL;
  9923. +
  9924. + return result;
  9925. +}
  9926. +
  9927. +/*
  9928. + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
  9929. + * this is null terminated, no count is carried around
  9930. + */
  9931. +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
  9932. +{
  9933. + int count;
  9934. + char ** resized;
  9935. + char *depend_str = pkg_depend_str(pkg, ref_ndx);
  9936. +
  9937. + count = 0;
  9938. + while(the_lost && the_lost[count]) count++;
  9939. +
  9940. + count++; /* need one to hold the null */
  9941. + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
  9942. + if (resized == NULL) {
  9943. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9944. + return NULL;
  9945. + }
  9946. + resized[count - 1] = strdup(depend_str);
  9947. + resized[count] = NULL;
  9948. +
  9949. + return resized;
  9950. +}
  9951. +
  9952. +void printDepends(pkg_t * pkg)
  9953. +{
  9954. + register int i, j;
  9955. + compound_depend_t * depend;
  9956. + int count;
  9957. +
  9958. + count = pkg->pre_depends_count + pkg->depends_count;
  9959. +
  9960. + depend = pkg->depends;
  9961. + if(!depend){
  9962. + fprintf(stderr, "Depends pointer is NULL\n");
  9963. + return;
  9964. + }
  9965. + for(i = 0; i < count; i++){
  9966. + fprintf(stderr, "%s has %d possibilities:\n",
  9967. + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
  9968. + depend->possibility_count);
  9969. + for(j = 0; j < depend->possibility_count; j++)
  9970. + fprintf(stderr, "\t%s version %s (%d)\n",
  9971. + depend->possibilities[j]->pkg->name,
  9972. + depend->possibilities[j]->version,
  9973. + depend->possibilities[j]->constraint);
  9974. + depend++;
  9975. + }
  9976. +}
  9977. +
  9978. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  9979. +{
  9980. + register int i, j;
  9981. +
  9982. + /* every pkg provides itself */
  9983. + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
  9984. +
  9985. + if (!pkg->provides_count)
  9986. + return 0;
  9987. +
  9988. + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
  9989. + if (pkg->provides == NULL) {
  9990. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9991. + return -1 ;
  9992. + }
  9993. + pkg->provides[0] = ab_pkg;
  9994. +
  9995. + // if (strcmp(ab_pkg->name, pkg->name))
  9996. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  9997. +
  9998. + for(i = 0; i < pkg->provides_count; i++){
  9999. + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
  10000. +
  10001. + pkg->provides[i+1] = provided_abpkg;
  10002. +
  10003. + j = 0;
  10004. + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
  10005. + }
  10006. + return 0;
  10007. +}
  10008. +
  10009. +/* Abhaya: added conflicts support */
  10010. +int buildConflicts(hash_table_t * hash, pkg_t * pkg)
  10011. +{
  10012. + register int i;
  10013. + compound_depend_t * conflicts;
  10014. +
  10015. + if (!pkg->conflicts_count)
  10016. + return 0;
  10017. +
  10018. + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
  10019. + pkg->conflicts_count);
  10020. + if (conflicts == NULL) {
  10021. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10022. + return -1;
  10023. + }
  10024. + for (i = 0; i < pkg->conflicts_count; i++) {
  10025. + conflicts->type = CONFLICTS;
  10026. + parseDepends(conflicts, hash,
  10027. + pkg->conflicts_str[i]);
  10028. +#if 0
  10029. + for (j = 0; j < conflicts->possibility_count; j++) {
  10030. + depend_t *possibility = conflicts->possibilities[j];
  10031. + abstract_pkg_t *conflicting_apkg = possibility->pkg;
  10032. + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
  10033. + }
  10034. +#endif
  10035. + conflicts++;
  10036. + }
  10037. + return 0;
  10038. +}
  10039. +
  10040. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10041. +{
  10042. + register int i, j;
  10043. +
  10044. + if (!pkg->replaces_count)
  10045. + return 0;
  10046. +
  10047. + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
  10048. + if (pkg->replaces == NULL) {
  10049. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10050. + return -1;
  10051. + }
  10052. +
  10053. + // if (strcmp(ab_pkg->name, pkg->name))
  10054. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10055. +
  10056. + for(i = 0; i < pkg->replaces_count; i++){
  10057. + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
  10058. +
  10059. + pkg->replaces[i] = old_abpkg;
  10060. +
  10061. + j = 0;
  10062. + if (!old_abpkg->replaced_by)
  10063. + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
  10064. + if ( old_abpkg->replaced_by == NULL ){
  10065. + return -1;
  10066. + }
  10067. + /* if a package pkg both replaces and conflicts old_abpkg,
  10068. + * then add it to the replaced_by vector so that old_abpkg
  10069. + * will be upgraded to ab_pkg automatically */
  10070. + if (pkg_conflicts_abstract(pkg, old_abpkg))
  10071. + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
  10072. + }
  10073. + return 0;
  10074. +}
  10075. +
  10076. +int buildDepends(hash_table_t * hash, pkg_t * pkg)
  10077. +{
  10078. + int count;
  10079. + register int i;
  10080. + compound_depend_t * depends;
  10081. +
  10082. + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
  10083. + return 0;
  10084. +
  10085. + if (0 && pkg->pre_depends_count)
  10086. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10087. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10088. + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
  10089. + if (depends == NULL) {
  10090. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10091. + return -1;
  10092. + }
  10093. +
  10094. +
  10095. + for(i = 0; i < pkg->pre_depends_count; i++){
  10096. + parseDepends(depends, hash, pkg->pre_depends_str[i]);
  10097. + if (0 && pkg->pre_depends_count)
  10098. + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
  10099. + pkg->pre_depends_str[i], depends, depends->possibility_count);
  10100. + depends->type = PREDEPEND;
  10101. + depends++;
  10102. + }
  10103. +
  10104. + for(i = 0; i < pkg->recommends_count; i++){
  10105. + parseDepends(depends, hash, pkg->recommends_str[i]);
  10106. + if (0 && pkg->recommends_count)
  10107. + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
  10108. + pkg->recommends_str[i], depends, depends->possibility_count);
  10109. + depends->type = RECOMMEND;
  10110. + depends++;
  10111. + }
  10112. +
  10113. + for(i = 0; i < pkg->suggests_count; i++){
  10114. + parseDepends(depends, hash, pkg->suggests_str[i]);
  10115. + if (0 && pkg->suggests_count)
  10116. + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
  10117. + pkg->suggests_str[i], depends, depends->possibility_count);
  10118. + depends->type = SUGGEST;
  10119. + depends++;
  10120. + }
  10121. +
  10122. + for(i = 0; i < pkg->depends_count; i++){
  10123. + parseDepends(depends, hash, pkg->depends_str[i]);
  10124. + if (0 && pkg->depends_count)
  10125. + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
  10126. + pkg->depends_str[i], depends, depends->possibility_count);
  10127. + depends++;
  10128. + }
  10129. + return 0;
  10130. +}
  10131. +
  10132. +/*
  10133. + * pkg_depend_string: returns the depends string specified by index_.
  10134. + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
  10135. + * [0,npredepends) -> returns pre_depends_str[index_]
  10136. + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index_]
  10137. + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index_]
  10138. + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index_]
  10139. + */
  10140. +char *pkg_depend_str(pkg_t *pkg, int index_)
  10141. +{
  10142. + if (index_ < pkg->pre_depends_count) {
  10143. + return pkg->pre_depends_str[index_];
  10144. + }
  10145. + index_ -= pkg->pre_depends_count;
  10146. +
  10147. + if (index_ < pkg->recommends_count) {
  10148. + return pkg->recommends_str[index_];
  10149. + }
  10150. + index_ -= pkg->recommends_count;
  10151. +
  10152. + if (index_ < pkg->suggests_count) {
  10153. + return pkg->suggests_str[index_];
  10154. + }
  10155. + index_ -= pkg->suggests_count;
  10156. +
  10157. + if (index_ < pkg->depends_count) {
  10158. + return pkg->depends_str[index_];
  10159. + }
  10160. + fprintf(stderr, "pkg_depend_str: index_ %d out of range for pkg=%s\n", index_, pkg->name);
  10161. + return NULL;
  10162. +}
  10163. +
  10164. +void freeDepends(pkg_t *pkg)
  10165. +{
  10166. + int i;
  10167. +
  10168. + if (pkg == NULL || pkg->depends == NULL) {
  10169. + return;
  10170. + }
  10171. +
  10172. + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
  10173. + for (i=0; i < pkg->depends->possibility_count; i++) {
  10174. + depend_deinit(pkg->depends->possibilities[i]);
  10175. + }
  10176. + free(pkg->depends->possibilities);
  10177. + free(pkg->depends);
  10178. + pkg->depends = NULL;
  10179. +}
  10180. +
  10181. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
  10182. +{
  10183. + compound_depend_t * depends;
  10184. + int count, othercount;
  10185. + register int i, j;
  10186. + abstract_pkg_t * ab_depend;
  10187. + abstract_pkg_t ** temp;
  10188. +
  10189. + count = pkg->pre_depends_count + pkg->depends_count;
  10190. + depends = pkg->depends;
  10191. +
  10192. + if (0 && pkg->pre_depends_count)
  10193. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10194. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10195. + for (i = 0; i < count; i++) {
  10196. + if (0 && pkg->pre_depends_count)
  10197. + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
  10198. + for (j = 0; j < depends->possibility_count; j++){
  10199. + ab_depend = depends->possibilities[j]->pkg;
  10200. + if(!ab_depend->depended_upon_by)
  10201. + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
  10202. +
  10203. + temp = ab_depend->depended_upon_by;
  10204. + othercount = 1;
  10205. + while(*temp){
  10206. + temp++;
  10207. + othercount++;
  10208. + }
  10209. + *temp = ab_pkg;
  10210. +
  10211. + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
  10212. + (othercount + 1) * sizeof(abstract_pkg_t *));
  10213. + /* the array may have moved */
  10214. + temp = ab_depend->depended_upon_by + othercount;
  10215. + *temp = NULL;
  10216. + }
  10217. + depends++;
  10218. + }
  10219. +}
  10220. +
  10221. +static depend_t * depend_init(void)
  10222. +{
  10223. + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
  10224. + if ( d==NULL ){
  10225. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10226. + return NULL;
  10227. + }
  10228. + d->constraint = NONE;
  10229. + d->version = NULL;
  10230. + d->pkg = NULL;
  10231. +
  10232. + return d;
  10233. +}
  10234. +
  10235. +static void depend_deinit(depend_t *d)
  10236. +{
  10237. + free(d);
  10238. +}
  10239. +
  10240. +static int parseDepends(compound_depend_t *compound_depend,
  10241. + hash_table_t * hash, char * depend_str)
  10242. +{
  10243. + char * pkg_name, buffer[2048];
  10244. + int num_of_ors = 0;
  10245. + register int i;
  10246. + register char * src, * dest;
  10247. + depend_t ** possibilities;
  10248. +
  10249. + /* first count the number of ored possibilities for satisfying dependency */
  10250. + src = depend_str;
  10251. + while(*src)
  10252. + if(*src++ == '|')
  10253. + num_of_ors++;
  10254. +
  10255. + compound_depend->type = DEPEND;
  10256. +
  10257. + compound_depend->possibility_count = num_of_ors + 1;
  10258. + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
  10259. + if (!possibilities)
  10260. + return -ENOMEM;
  10261. + compound_depend->possibilities = possibilities;
  10262. +
  10263. + src = depend_str;
  10264. + for(i = 0; i < num_of_ors + 1; i++){
  10265. + possibilities[i] = depend_init();
  10266. + if (!possibilities[i])
  10267. + return -ENOMEM;
  10268. + /* gobble up just the name first */
  10269. + dest = buffer;
  10270. + while(*src &&
  10271. + !isspace(*src) &&
  10272. + (*src != '(') &&
  10273. + (*src != '*') &&
  10274. + (*src != '|'))
  10275. + *dest++ = *src++;
  10276. + *dest = '\0';
  10277. + pkg_name = trim_alloc(buffer);
  10278. + if (pkg_name == NULL )
  10279. + return -ENOMEM;
  10280. +
  10281. + /* now look at possible version info */
  10282. +
  10283. + /* skip to next chars */
  10284. + if(isspace(*src))
  10285. + while(*src && isspace(*src)) src++;
  10286. +
  10287. + /* extract constraint and version */
  10288. + if(*src == '('){
  10289. + src++;
  10290. + if(!strncmp(src, "<<", 2)){
  10291. + possibilities[i]->constraint = EARLIER;
  10292. + src += 2;
  10293. + }
  10294. + else if(!strncmp(src, "<=", 2)){
  10295. + possibilities[i]->constraint = EARLIER_EQUAL;
  10296. + src += 2;
  10297. + }
  10298. + else if(!strncmp(src, ">=", 2)){
  10299. + possibilities[i]->constraint = LATER_EQUAL;
  10300. + src += 2;
  10301. + }
  10302. + else if(!strncmp(src, ">>", 2)){
  10303. + possibilities[i]->constraint = LATER;
  10304. + src += 2;
  10305. + }
  10306. + else if(!strncmp(src, "=", 1)){
  10307. + possibilities[i]->constraint = EQUAL;
  10308. + src++;
  10309. + }
  10310. + /* should these be here to support deprecated designations; dpkg does */
  10311. + else if(!strncmp(src, "<", 1)){
  10312. + possibilities[i]->constraint = EARLIER_EQUAL;
  10313. + src++;
  10314. + }
  10315. + else if(!strncmp(src, ">", 1)){
  10316. + possibilities[i]->constraint = LATER_EQUAL;
  10317. + src++;
  10318. + }
  10319. +
  10320. + /* now we have any constraint, pass space to version string */
  10321. + while(isspace(*src)) src++;
  10322. +
  10323. + /* this would be the version string */
  10324. + dest = buffer;
  10325. + while(*src && *src != ')')
  10326. + *dest++ = *src++;
  10327. + *dest = '\0';
  10328. +
  10329. + possibilities[i]->version = trim_alloc(buffer);
  10330. + /* fprintf(stderr, "let's print the depends version string:");
  10331. + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
  10332. + if (possibilities[i]->version == NULL )
  10333. + return -ENOMEM;
  10334. +
  10335. +
  10336. + }
  10337. + /* hook up the dependency to its abstract pkg */
  10338. + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
  10339. +
  10340. + free(pkg_name);
  10341. +
  10342. + /* now get past the ) and any possible | chars */
  10343. + while(*src &&
  10344. + (isspace(*src) ||
  10345. + (*src == ')') ||
  10346. + (*src == '|')))
  10347. + src++;
  10348. + if (*src == '*')
  10349. + {
  10350. + compound_depend->type = GREEDY_DEPEND;
  10351. + src++;
  10352. + }
  10353. + }
  10354. +
  10355. + return 0;
  10356. +}
  10357. diff -Nur busybox-1.20.2.orig//archival/libipkg/pkg_depends.h busybox-1.20.2/archival/libipkg/pkg_depends.h
  10358. --- busybox-1.20.2.orig//archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
  10359. +++ busybox-1.20.2/archival/libipkg/pkg_depends.h 2013-01-31 16:44:31.000000000 +0100
  10360. @@ -0,0 +1,105 @@
  10361. +/* pkg_depends.h - the itsy package management system
  10362. +
  10363. + Steven M. Ayer
  10364. +
  10365. + Copyright (C) 2002 Compaq Computer Corporation
  10366. +
  10367. + This program is free software; you can redistribute it and/or
  10368. + modify it under the terms of the GNU General Public License as
  10369. + published by the Free Software Foundation; either version 2, or (at
  10370. + your option) any later version.
  10371. +
  10372. + This program is distributed in the hope that it will be useful, but
  10373. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10374. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10375. + General Public License for more details.
  10376. +*/
  10377. +
  10378. +#ifndef PKG_DEPENDS_H
  10379. +#define PKG_DEPENDS_H
  10380. +
  10381. +#include "pkg.h"
  10382. +#include "pkg_hash.h"
  10383. +
  10384. +enum depend_type {
  10385. + PREDEPEND,
  10386. + DEPEND,
  10387. + CONFLICTS,
  10388. + GREEDY_DEPEND,
  10389. + RECOMMEND,
  10390. + SUGGEST
  10391. +};
  10392. +typedef enum depend_type depend_type_t;
  10393. +
  10394. +enum version_constraint {
  10395. + NONE,
  10396. + EARLIER,
  10397. + EARLIER_EQUAL,
  10398. + EQUAL,
  10399. + LATER_EQUAL,
  10400. + LATER
  10401. +};
  10402. +typedef enum version_constraint version_constraint_t;
  10403. +
  10404. +struct depend{
  10405. + version_constraint_t constraint;
  10406. + char * version;
  10407. + abstract_pkg_t * pkg;
  10408. +};
  10409. +typedef struct depend depend_t;
  10410. +
  10411. +struct compound_depend{
  10412. + depend_type_t type;
  10413. + int possibility_count;
  10414. + struct depend ** possibilities;
  10415. +};
  10416. +typedef struct compound_depend compound_depend_t;
  10417. +
  10418. +#include "hash_table.h"
  10419. +
  10420. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10421. +int buildConflicts(hash_table_t * hash, pkg_t * pkg);
  10422. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10423. +int buildDepends(hash_table_t * hash, pkg_t * pkg);
  10424. +
  10425. +/**
  10426. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10427. + * the same abstract package and 0 otherwise.
  10428. + */
  10429. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
  10430. +
  10431. +/**
  10432. + * pkg_provides returns 1 if pkg->provides contains providee and 0
  10433. + * otherwise.
  10434. + */
  10435. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
  10436. +
  10437. +/**
  10438. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10439. + * otherwise.
  10440. + */
  10441. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
  10442. +
  10443. +/**
  10444. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
  10445. + * otherwise.
  10446. + */
  10447. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
  10448. +
  10449. +/**
  10450. + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
  10451. + * otherwise.
  10452. + */
  10453. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
  10454. +
  10455. +char *pkg_depend_str(pkg_t *pkg, int index_);
  10456. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
  10457. +void freeDepends(pkg_t *pkg);
  10458. +void printDepends(pkg_t * pkg);
  10459. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
  10460. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
  10461. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
  10462. +int pkg_dependence_satisfiable(depend_t *depend);
  10463. +int pkg_dependence_satisfied(depend_t *depend);
  10464. +
  10465. +#endif
  10466. diff -Nur busybox-1.20.2.orig//archival/libipkg/pkg_dest.c busybox-1.20.2/archival/libipkg/pkg_dest.c
  10467. --- busybox-1.20.2.orig//archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
  10468. +++ busybox-1.20.2/archival/libipkg/pkg_dest.c 2013-01-31 16:44:31.000000000 +0100
  10469. @@ -0,0 +1,92 @@
  10470. +/* pkg_dest.c - the itsy package management system
  10471. +
  10472. + Carl D. Worth
  10473. +
  10474. + Copyright (C) 2001 University of Southern California
  10475. +
  10476. + This program is free software; you can redistribute it and/or
  10477. + modify it under the terms of the GNU General Public License as
  10478. + published by the Free Software Foundation; either version 2, or (at
  10479. + your option) any later version.
  10480. +
  10481. + This program is distributed in the hope that it will be useful, but
  10482. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10483. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10484. + General Public License for more details.
  10485. +*/
  10486. +
  10487. +#include "ipkg.h"
  10488. +
  10489. +#include "pkg_dest.h"
  10490. +#include "file_util.h"
  10491. +#include "str_util.h"
  10492. +#include "sprintf_alloc.h"
  10493. +
  10494. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
  10495. +{
  10496. + dest->name = strdup(name);
  10497. +
  10498. + /* Guarantee that dest->root_dir ends with a '/' */
  10499. + if (str_ends_with(root_dir, "/")) {
  10500. + dest->root_dir = strdup(root_dir);
  10501. + } else {
  10502. + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
  10503. + }
  10504. + file_mkdir_hier(dest->root_dir, 0755);
  10505. +
  10506. + sprintf_alloc(&dest->ipkg_dir, "%s%s",
  10507. + dest->root_dir, IPKG_STATE_DIR_PREFIX);
  10508. + file_mkdir_hier(dest->ipkg_dir, 0755);
  10509. +
  10510. + if (str_starts_with (lists_dir, "/"))
  10511. + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
  10512. + else
  10513. + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
  10514. +
  10515. + file_mkdir_hier(dest->lists_dir, 0755);
  10516. +
  10517. + sprintf_alloc(&dest->info_dir, "%s/%s",
  10518. + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
  10519. + file_mkdir_hier(dest->info_dir, 0755);
  10520. +
  10521. + sprintf_alloc(&dest->status_file_name, "%s/%s",
  10522. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10523. +
  10524. + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
  10525. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10526. +
  10527. + dest->status_file = NULL;
  10528. +
  10529. + return 0;
  10530. +}
  10531. +
  10532. +void pkg_dest_deinit(pkg_dest_t *dest)
  10533. +{
  10534. + free(dest->name);
  10535. + dest->name = NULL;
  10536. +
  10537. + free(dest->root_dir);
  10538. + dest->root_dir = NULL;
  10539. +
  10540. + free(dest->ipkg_dir);
  10541. + dest->ipkg_dir = NULL;
  10542. +
  10543. + free(dest->lists_dir);
  10544. + dest->lists_dir = NULL;
  10545. +
  10546. + free(dest->info_dir);
  10547. + dest->info_dir = NULL;
  10548. +
  10549. + free(dest->status_file_name);
  10550. + dest->status_file_name = NULL;
  10551. +
  10552. + free(dest->status_file_tmp_name);
  10553. + dest->status_file_tmp_name = NULL;
  10554. +
  10555. + if (dest->status_file) {
  10556. + fclose(dest->status_file);
  10557. + }
  10558. + dest->status_file = NULL;
  10559. +
  10560. + dest->root_dir = NULL;
  10561. +}
  10562. diff -Nur busybox-1.20.2.orig//archival/libipkg/pkg_dest.h busybox-1.20.2/archival/libipkg/pkg_dest.h
  10563. --- busybox-1.20.2.orig//archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
  10564. +++ busybox-1.20.2/archival/libipkg/pkg_dest.h 2013-01-31 16:44:31.000000000 +0100
  10565. @@ -0,0 +1,38 @@
  10566. +/* pkg_dest.h - the itsy package management system
  10567. +
  10568. + Carl D. Worth
  10569. +
  10570. + Copyright (C) 2001 University of Southern California
  10571. +
  10572. + This program is free software; you can redistribute it and/or
  10573. + modify it under the terms of the GNU General Public License as
  10574. + published by the Free Software Foundation; either version 2, or (at
  10575. + your option) any later version.
  10576. +
  10577. + This program is distributed in the hope that it will be useful, but
  10578. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10579. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10580. + General Public License for more details.
  10581. +*/
  10582. +
  10583. +#ifndef PKG_DEST_H
  10584. +#define PKG_DEST_H
  10585. +
  10586. +typedef struct pkg_dest pkg_dest_t;
  10587. +struct pkg_dest
  10588. +{
  10589. + char *name;
  10590. + char *root_dir;
  10591. + char *ipkg_dir;
  10592. + char *lists_dir;
  10593. + char *info_dir;
  10594. + char *status_file_name;
  10595. + char *status_file_tmp_name;
  10596. + FILE *status_file;
  10597. +};
  10598. +
  10599. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
  10600. +void pkg_dest_deinit(pkg_dest_t *dest);
  10601. +
  10602. +#endif
  10603. +
  10604. diff -Nur busybox-1.20.2.orig//archival/libipkg/pkg_dest_list.c busybox-1.20.2/archival/libipkg/pkg_dest_list.c
  10605. --- busybox-1.20.2.orig//archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
  10606. +++ busybox-1.20.2/archival/libipkg/pkg_dest_list.c 2013-01-31 16:44:31.000000000 +0100
  10607. @@ -0,0 +1,85 @@
  10608. +/* pkg_dest_list.c - the itsy package management system
  10609. +
  10610. + Carl D. Worth
  10611. +
  10612. + Copyright (C) 2001 University of Southern California
  10613. +
  10614. + This program is free software; you can redistribute it and/or
  10615. + modify it under the terms of the GNU General Public License as
  10616. + published by the Free Software Foundation; either version 2, or (at
  10617. + your option) any later version.
  10618. +
  10619. + This program is distributed in the hope that it will be useful, but
  10620. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10621. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10622. + General Public License for more details.
  10623. +*/
  10624. +
  10625. +#include "ipkg.h"
  10626. +
  10627. +#include "pkg_dest.h"
  10628. +#include "void_list.h"
  10629. +#include "pkg_dest_list.h"
  10630. +
  10631. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
  10632. +{
  10633. + return void_list_elt_init((void_list_elt_t *) elt, data);
  10634. +}
  10635. +
  10636. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
  10637. +{
  10638. + void_list_elt_deinit((void_list_elt_t *) elt);
  10639. +}
  10640. +
  10641. +int pkg_dest_list_init(pkg_dest_list_t *list)
  10642. +{
  10643. + return void_list_init((void_list_t *) list);
  10644. +}
  10645. +
  10646. +void pkg_dest_list_deinit(pkg_dest_list_t *list)
  10647. +{
  10648. + pkg_dest_list_elt_t *iter;
  10649. + pkg_dest_t *pkg_dest;
  10650. +
  10651. + for (iter = list->head; iter; iter = iter->next) {
  10652. + pkg_dest = iter->data;
  10653. + pkg_dest_deinit(pkg_dest);
  10654. +
  10655. + /* malloced in pkg_dest_list_append */
  10656. + free(pkg_dest);
  10657. + iter->data = NULL;
  10658. + }
  10659. + void_list_deinit((void_list_t *) list);
  10660. +}
  10661. +
  10662. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10663. + const char *root_dir,const char *lists_dir)
  10664. +{
  10665. + int err;
  10666. + pkg_dest_t *pkg_dest;
  10667. +
  10668. + /* freed in plg_dest_list_deinit */
  10669. + pkg_dest = malloc(sizeof(pkg_dest_t));
  10670. + if (pkg_dest == NULL) {
  10671. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10672. + return NULL;
  10673. + }
  10674. +
  10675. + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
  10676. + err = void_list_append((void_list_t *) list, pkg_dest);
  10677. + if (err) {
  10678. + return NULL;
  10679. + }
  10680. +
  10681. + return pkg_dest;
  10682. +}
  10683. +
  10684. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
  10685. +{
  10686. + return void_list_push((void_list_t *) list, data);
  10687. +}
  10688. +
  10689. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
  10690. +{
  10691. + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
  10692. +}
  10693. diff -Nur busybox-1.20.2.orig//archival/libipkg/pkg_dest_list.h busybox-1.20.2/archival/libipkg/pkg_dest_list.h
  10694. --- busybox-1.20.2.orig//archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
  10695. +++ busybox-1.20.2/archival/libipkg/pkg_dest_list.h 2013-01-31 16:44:31.000000000 +0100
  10696. @@ -0,0 +1,50 @@
  10697. +/* pkg_dest_list.h - the itsy package management system
  10698. +
  10699. + Carl D. Worth
  10700. +
  10701. + Copyright (C) 2001 University of Southern California
  10702. +
  10703. + This program is free software; you can redistribute it and/or
  10704. + modify it under the terms of the GNU General Public License as
  10705. + published by the Free Software Foundation; either version 2, or (at
  10706. + your option) any later version.
  10707. +
  10708. + This program is distributed in the hope that it will be useful, but
  10709. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10710. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10711. + General Public License for more details.
  10712. +*/
  10713. +
  10714. +#ifndef PKG_DEST_LIST_H
  10715. +#define PKG_DEST_LIST_H
  10716. +
  10717. +#include "pkg_dest.h"
  10718. +
  10719. +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
  10720. +struct pkg_dest_list_elt
  10721. +{
  10722. + pkg_dest_list_elt_t *next;
  10723. + pkg_dest_t *data;
  10724. +};
  10725. +
  10726. +typedef struct pkg_dest_list pkg_dest_list_t;
  10727. +struct pkg_dest_list
  10728. +{
  10729. + pkg_dest_list_elt_t pre_head;
  10730. + pkg_dest_list_elt_t *head;
  10731. + pkg_dest_list_elt_t *tail;
  10732. +};
  10733. +
  10734. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
  10735. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
  10736. +
  10737. +int pkg_dest_list_init(pkg_dest_list_t *list);
  10738. +void pkg_dest_list_deinit(pkg_dest_list_t *list);
  10739. +
  10740. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10741. + const char *root_dir,const char* lists_dir);
  10742. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
  10743. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
  10744. +
  10745. +#endif
  10746. +
  10747. diff -Nur busybox-1.20.2.orig//archival/libipkg/pkg_extract.c busybox-1.20.2/archival/libipkg/pkg_extract.c
  10748. --- busybox-1.20.2.orig//archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
  10749. +++ busybox-1.20.2/archival/libipkg/pkg_extract.c 2013-01-31 16:44:31.000000000 +0100
  10750. @@ -0,0 +1,255 @@
  10751. +/* pkg_extract.c - the itsy package management system
  10752. +
  10753. + Carl D. Worth
  10754. +
  10755. + Copyright (C) 2001 University of Southern California
  10756. +
  10757. + This program is free software; you can redistribute it and/or
  10758. + modify it under the terms of the GNU General Public License as
  10759. + published by the Free Software Foundation; either version 2, or (at
  10760. + your option) any later version.
  10761. +
  10762. + This program is distributed in the hope that it will be useful, but
  10763. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10764. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10765. + General Public License for more details.
  10766. +*/
  10767. +
  10768. +#include "ipkg.h"
  10769. +#include <errno.h>
  10770. +#include <fcntl.h>
  10771. +#include <stdio.h>
  10772. +
  10773. +#include "pkg_extract.h"
  10774. +
  10775. +#include "libbb.h"
  10776. +#include "file_util.h"
  10777. +#include "sprintf_alloc.h"
  10778. +#include "bb_archive.h"
  10779. +
  10780. +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
  10781. +#define IPKG_DATA_ARCHIVE "data.tar.gz"
  10782. +#define IPKG_CONTROL_FILE "control"
  10783. +
  10784. +static void FAST_FUNC ipkg_data_extract_all_prefix(archive_handle_t *archive_handle)
  10785. +{
  10786. + char *name_ptr = archive_handle->file_header->name;
  10787. +
  10788. + /* Skip all leading "/" */
  10789. + while (*name_ptr == '/')
  10790. + name_ptr++;
  10791. + /* Skip all leading "./" and "../" */
  10792. + while (name_ptr[0] == '.') {
  10793. + if (name_ptr[1] == '.' && name_ptr[2] == '/')
  10794. + name_ptr++;
  10795. + if (name_ptr[1] != '/')
  10796. + break;
  10797. + name_ptr += 2;
  10798. + }
  10799. +
  10800. + if (name_ptr[0] != '\0') {
  10801. + archive_handle->file_header->name = xasprintf("%s%s", archive_handle->dpkg__buffer, name_ptr);
  10802. + data_extract_all(archive_handle);
  10803. + }
  10804. +}
  10805. +
  10806. +static void FAST_FUNC ipkg_data_extract_to_buffer(archive_handle_t *archive_handle)
  10807. +{
  10808. + unsigned size = archive_handle->file_header->size;
  10809. +
  10810. + archive_handle->dpkg__buffer = xzalloc(size + 1);
  10811. + xread(archive_handle->src_fd, archive_handle->dpkg__buffer, size);
  10812. +}
  10813. +
  10814. +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
  10815. +{
  10816. + archive_handle_t *archive;
  10817. + char *path;
  10818. +
  10819. + sprintf_alloc(&path, "%s/", dir);
  10820. + archive = init_handle();
  10821. + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
  10822. + archive->filter = filter_accept_list;
  10823. + llist_add_to(&(archive->accept), (char *)filename);
  10824. + archive->dpkg__buffer = path;
  10825. + archive->action_data = ipkg_data_extract_all_prefix;
  10826. + archive->ah_flags |= ARCHIVE_UNLINK_OLD;
  10827. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10828. + close(archive->src_fd);
  10829. + free(archive->accept);
  10830. + free(archive);
  10831. + free(path);
  10832. +}
  10833. +
  10834. +static void FAST_FUNC data_extract_file_name_to_buffer(archive_handle_t *archive)
  10835. +{
  10836. + unsigned int size = strlen(archive->file_header->name) + 2;
  10837. +
  10838. + if (archive->dpkg__buffer == NULL) {
  10839. + archive->dpkg__buffer = xmalloc(size);
  10840. + strcpy(archive->dpkg__buffer, archive->file_header->name);
  10841. + } else {
  10842. + size += strlen(archive->dpkg__buffer);
  10843. + archive->dpkg__buffer = xrealloc(archive->dpkg__buffer, size);
  10844. + strcat(archive->dpkg__buffer, archive->file_header->name);
  10845. + }
  10846. + strcat(archive->dpkg__buffer, "\n");
  10847. + data_skip(archive);
  10848. +}
  10849. +
  10850. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
  10851. +{
  10852. + archive_handle_t *archive;
  10853. + char *name;
  10854. + const char *filename = IPKG_CONTROL_FILE;
  10855. +
  10856. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10857. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10858. + archive = init_handle();
  10859. + archive->src_fd = xopen(name, O_RDONLY);
  10860. + archive->filter = filter_accept_list;
  10861. + llist_add_to(&(archive->accept), (char *)filename);
  10862. + archive->action_data = ipkg_data_extract_to_buffer;
  10863. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10864. + close(archive->src_fd);
  10865. + fputs(archive->dpkg__buffer, stream);
  10866. + free(archive->dpkg__buffer);
  10867. + free(archive->accept);
  10868. + free(archive);
  10869. + free(name);
  10870. +
  10871. + return 0;
  10872. +}
  10873. +
  10874. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
  10875. +{
  10876. + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
  10877. +}
  10878. +
  10879. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
  10880. +{
  10881. + archive_handle_t *archive;
  10882. + char *name;
  10883. + char *path;
  10884. +
  10885. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10886. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10887. + sprintf_alloc(&path, "%s/%s", dir, prefix);
  10888. + archive = init_handle();
  10889. + archive->src_fd = xopen(name, O_RDONLY);
  10890. + archive->filter = filter_accept_all;
  10891. + archive->dpkg__buffer = path;
  10892. + archive->action_data = ipkg_data_extract_all_prefix;
  10893. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  10894. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10895. + close(archive->src_fd);
  10896. + free(archive);
  10897. + free(path);
  10898. + free(name);
  10899. +
  10900. + return 0;
  10901. +}
  10902. +
  10903. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
  10904. +{
  10905. + archive_handle_t *archive;
  10906. + char *name;
  10907. + char *path;
  10908. +
  10909. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  10910. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  10911. + sprintf_alloc(&path, "%s/", dir);
  10912. + archive = init_handle();
  10913. + archive->src_fd = xopen(name, O_RDONLY);
  10914. + archive->filter = filter_accept_all;
  10915. + archive->dpkg__buffer = path;
  10916. + archive->action_data = ipkg_data_extract_all_prefix;
  10917. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  10918. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10919. + close(archive->src_fd);
  10920. + free(archive);
  10921. + free(path);
  10922. + free(name);
  10923. +
  10924. + return 0;
  10925. +}
  10926. +
  10927. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
  10928. +{
  10929. + int err=0;
  10930. + char *line, *data_file;
  10931. + FILE *file;
  10932. + FILE *tmp;
  10933. +
  10934. + file = fopen(file_name, "w");
  10935. + if (file == NULL) {
  10936. + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
  10937. + __FUNCTION__, file_name);
  10938. + return EINVAL;
  10939. + }
  10940. +
  10941. + tmp = tmpfile();
  10942. + if (pkg->installed_files) {
  10943. + str_list_elt_t *elt;
  10944. + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
  10945. + fprintf(file, "%s\n", elt->data);
  10946. + }
  10947. + } else {
  10948. + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
  10949. + if (err) {
  10950. + fclose(file);
  10951. + fclose(tmp);
  10952. + return err;
  10953. + }
  10954. +
  10955. + /* Fixup data file names by removing the initial '.' */
  10956. + rewind(tmp);
  10957. + while (1) {
  10958. + line = file_read_line_alloc(tmp);
  10959. + if (line == NULL) {
  10960. + break;
  10961. + }
  10962. +
  10963. + data_file = line;
  10964. + if (*data_file == '.') {
  10965. + data_file++;
  10966. + }
  10967. +
  10968. + if (*data_file != '/') {
  10969. + fputs("/", file);
  10970. + }
  10971. +
  10972. + /* I have no idea why, but this is what dpkg does */
  10973. + if (strcmp(data_file, "/\n") == 0) {
  10974. + fputs("/.\n", file);
  10975. + } else {
  10976. + fputs(data_file, file);
  10977. + }
  10978. + }
  10979. + }
  10980. + fclose(tmp);
  10981. + fclose(file);
  10982. +
  10983. + return err;
  10984. +}
  10985. +
  10986. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
  10987. +{
  10988. + archive_handle_t *archive;
  10989. + char *name;
  10990. +
  10991. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  10992. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  10993. + archive = init_handle();
  10994. + archive->src_fd = xopen(name, O_RDONLY);
  10995. + archive->filter = filter_accept_all;
  10996. + archive->action_data = data_extract_file_name_to_buffer;
  10997. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10998. + close(archive->src_fd);
  10999. + fputs(archive->dpkg__buffer, file);
  11000. + free(archive->dpkg__buffer);
  11001. + free(archive);
  11002. + free(name);
  11003. +
  11004. + return 0;
  11005. +}
  11006. diff -Nur busybox-1.20.2.orig//archival/libipkg/pkg_extract.h busybox-1.20.2/archival/libipkg/pkg_extract.h
  11007. --- busybox-1.20.2.orig//archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
  11008. +++ busybox-1.20.2/archival/libipkg/pkg_extract.h 2013-01-31 16:44:31.000000000 +0100
  11009. @@ -0,0 +1,32 @@
  11010. +/* pkg_extract.c - the itsy package management system
  11011. +
  11012. + Carl D. Worth
  11013. +
  11014. + Copyright (C) 2001 University of Southern California
  11015. +
  11016. + This program is free software; you can redistribute it and/or
  11017. + modify it under the terms of the GNU General Public License as
  11018. + published by the Free Software Foundation; either version 2, or (at
  11019. + your option) any later version.
  11020. +
  11021. + This program is distributed in the hope that it will be useful, but
  11022. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11023. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11024. + General Public License for more details.
  11025. +*/
  11026. +
  11027. +#ifndef PKG_EXTRACT_H
  11028. +#define PKG_EXTRACT_H
  11029. +
  11030. +#include "pkg.h"
  11031. +
  11032. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
  11033. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
  11034. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
  11035. + const char *dir,
  11036. + const char *prefix);
  11037. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
  11038. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
  11039. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
  11040. +
  11041. +#endif
  11042. diff -Nur busybox-1.20.2.orig//archival/libipkg/pkg.h busybox-1.20.2/archival/libipkg/pkg.h
  11043. --- busybox-1.20.2.orig//archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
  11044. +++ busybox-1.20.2/archival/libipkg/pkg.h 2013-01-31 16:44:31.000000000 +0100
  11045. @@ -0,0 +1,229 @@
  11046. +/* pkg.h - the itsy package management system
  11047. +
  11048. + Carl D. Worth
  11049. +
  11050. + Copyright (C) 2001 University of Southern California
  11051. +
  11052. + This program is free software; you can redistribute it and/or
  11053. + modify it under the terms of the GNU General Public License as
  11054. + published by the Free Software Foundation; either version 2, or (at
  11055. + your option) any later version.
  11056. +
  11057. + This program is distributed in the hope that it will be useful, but
  11058. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11059. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11060. + General Public License for more details.
  11061. +*/
  11062. +
  11063. +#ifndef PKG_H
  11064. +#define PKG_H
  11065. +
  11066. +#include <sys/types.h>
  11067. +#include <sys/stat.h>
  11068. +#include <unistd.h>
  11069. +
  11070. +#include "pkg_vec.h"
  11071. +#include "str_list.h"
  11072. +#include "pkg_src.h"
  11073. +#include "pkg_dest.h"
  11074. +#include "ipkg_conf.h"
  11075. +#include "conffile_list.h"
  11076. +
  11077. +struct ipkg_conf;
  11078. +
  11079. +/* I think "Size" is currently the shortest field name */
  11080. +#define PKG_MINIMUM_FIELD_NAME_LEN 4
  11081. +
  11082. +enum pkg_state_want
  11083. +{
  11084. + SW_UNKNOWN = 1,
  11085. + SW_INSTALL,
  11086. + SW_DEINSTALL,
  11087. + SW_PURGE,
  11088. + SW_LAST_STATE_WANT
  11089. +};
  11090. +typedef enum pkg_state_want pkg_state_want_t;
  11091. +
  11092. +enum pkg_state_flag
  11093. +{
  11094. + SF_OK = 0,
  11095. + SF_REINSTREQ = 1,
  11096. + SF_HOLD = 2, /* do not upgrade version */
  11097. + SF_REPLACE = 4, /* replace this package */
  11098. + SF_NOPRUNE = 8, /* do not remove obsolete files */
  11099. + SF_PREFER = 16, /* prefer this version */
  11100. + SF_OBSOLETE = 32, /* old package in upgrade pair */
  11101. + SF_MARKED = 64, /* temporary mark */
  11102. + SF_FILELIST_CHANGED = 128, /* needs filelist written */
  11103. + SF_USER = 256,
  11104. + SF_LAST_STATE_FLAG
  11105. +};
  11106. +typedef enum pkg_state_flag pkg_state_flag_t;
  11107. +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
  11108. +
  11109. +enum pkg_state_status
  11110. +{
  11111. + SS_NOT_INSTALLED = 1,
  11112. + SS_UNPACKED,
  11113. + SS_HALF_CONFIGURED,
  11114. + SS_INSTALLED,
  11115. + SS_HALF_INSTALLED,
  11116. + SS_CONFIG_FILES,
  11117. + SS_POST_INST_FAILED,
  11118. + SS_REMOVAL_FAILED,
  11119. + SS_LAST_STATE_STATUS
  11120. +};
  11121. +typedef enum pkg_state_status pkg_state_status_t;
  11122. +
  11123. +struct abstract_pkg{
  11124. + char * name;
  11125. + int dependencies_checked;
  11126. + pkg_vec_t * pkgs;
  11127. + pkg_state_status_t state_status;
  11128. + pkg_state_flag_t state_flag;
  11129. + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
  11130. + abstract_pkg_vec_t * provided_by;
  11131. + abstract_pkg_vec_t * replaced_by;
  11132. +};
  11133. +
  11134. +#include "pkg_depends.h"
  11135. +
  11136. +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
  11137. +
  11138. + The 3 version fields should go into a single version struct. (This
  11139. + is especially important since, currently, pkg->version can easily
  11140. + be mistaken for pkg_verson_str_alloc(pkg) although they are very
  11141. + distinct. This has been the source of multiple bugs.
  11142. +
  11143. + The 3 state fields could possibly also go into their own struct.
  11144. +
  11145. + All fields which deal with lists of packages, (Depends,
  11146. + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
  11147. + be handled by a single struct in pkg_t
  11148. +
  11149. + All string fields for which there is a small set of possible
  11150. + values, (section, maintainer, architecture, maybe version?), that
  11151. + are reused among different packages -- for all such packages we
  11152. + should move from "char *"s to some atom datatype to share data
  11153. + storage and use less memory. We might even do reference counting,
  11154. + but probably not since most often we only create new pkg_t structs,
  11155. + we don't often free them. */
  11156. +struct pkg
  11157. +{
  11158. + char *name;
  11159. + unsigned long epoch;
  11160. + char *version;
  11161. + char *revision;
  11162. + char *familiar_revision;
  11163. + pkg_src_t *src;
  11164. + pkg_dest_t *dest;
  11165. + char *architecture;
  11166. + char *section;
  11167. + char *maintainer;
  11168. + char *description;
  11169. + pkg_state_want_t state_want;
  11170. + pkg_state_flag_t state_flag;
  11171. + pkg_state_status_t state_status;
  11172. + char **depends_str;
  11173. + int depends_count;
  11174. + char **pre_depends_str;
  11175. + int pre_depends_count;
  11176. + char **recommends_str;
  11177. + int recommends_count;
  11178. + char **suggests_str;
  11179. + int suggests_count;
  11180. + compound_depend_t * depends;
  11181. +
  11182. + /* Abhaya: new conflicts */
  11183. + char **conflicts_str;
  11184. + compound_depend_t * conflicts;
  11185. + int conflicts_count;
  11186. +
  11187. + char **replaces_str;
  11188. + int replaces_count;
  11189. + abstract_pkg_t ** replaces;
  11190. +
  11191. + char **provides_str;
  11192. + int provides_count;
  11193. + abstract_pkg_t ** provides;
  11194. +
  11195. + abstract_pkg_t *parent;
  11196. +
  11197. + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
  11198. +
  11199. + char *filename;
  11200. + char *local_filename;
  11201. + char *url;
  11202. + char *tmp_unpack_dir;
  11203. + char *md5sum;
  11204. + char *size;
  11205. + char *installed_size;
  11206. + char *priority;
  11207. + char *source;
  11208. + conffile_list_t conffiles;
  11209. + time_t installed_time;
  11210. + /* As pointer for lazy evaluation */
  11211. + str_list_t *installed_files;
  11212. + /* XXX: CLEANUP: I'd like to perhaps come up with a better
  11213. + mechanism to avoid the problem here, (which is that the
  11214. + installed_files list was being freed from an inner loop while
  11215. + still being used within an outer loop. */
  11216. + int installed_files_ref_cnt;
  11217. + int essential;
  11218. + int arch_priority;
  11219. +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
  11220. + int provided_by_hand;
  11221. +};
  11222. +
  11223. +pkg_t *pkg_new(void);
  11224. +int pkg_init(pkg_t *pkg);
  11225. +void pkg_deinit(pkg_t *pkg);
  11226. +int pkg_init_from_file(pkg_t *pkg, const char *filename);
  11227. +abstract_pkg_t *abstract_pkg_new(void);
  11228. +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
  11229. +
  11230. +/*
  11231. + * merges fields from newpkg into oldpkg.
  11232. + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
  11233. + */
  11234. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
  11235. +
  11236. +char *pkg_version_str_alloc(pkg_t *pkg);
  11237. +
  11238. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
  11239. +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
  11240. +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
  11241. +
  11242. +char * pkg_formatted_info(pkg_t *pkg );
  11243. +char * pkg_formatted_field(pkg_t *pkg, const char *field );
  11244. +
  11245. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
  11246. +
  11247. +void pkg_print_info(pkg_t *pkg, FILE *file);
  11248. +void pkg_print_status(pkg_t * pkg, FILE * file);
  11249. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
  11250. +str_list_t *pkg_get_installed_files(pkg_t *pkg);
  11251. +int pkg_free_installed_files(pkg_t *pkg);
  11252. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
  11253. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
  11254. +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
  11255. + const char *script, const char *args);
  11256. +
  11257. +/* enum mappings */
  11258. +char *pkg_state_want_to_str(pkg_state_want_t sw);
  11259. +pkg_state_want_t pkg_state_want_from_str(char *str);
  11260. +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
  11261. +pkg_state_flag_t pkg_state_flag_from_str(char *str);
  11262. +char *pkg_state_status_to_str(pkg_state_status_t ss);
  11263. +pkg_state_status_t pkg_state_status_from_str(char *str);
  11264. +
  11265. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
  11266. +
  11267. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
  11268. +int pkg_info_preinstall_check(ipkg_conf_t *conf);
  11269. +int pkg_free_installed_files(pkg_t *pkg);
  11270. +
  11271. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
  11272. +int pkg_write_changed_filelists(ipkg_conf_t *conf);
  11273. +
  11274. +#endif
  11275. diff -Nur busybox-1.20.2.orig//archival/libipkg/pkg_hash.c busybox-1.20.2/archival/libipkg/pkg_hash.c
  11276. --- busybox-1.20.2.orig//archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
  11277. +++ busybox-1.20.2/archival/libipkg/pkg_hash.c 2013-01-31 16:44:31.000000000 +0100
  11278. @@ -0,0 +1,623 @@
  11279. +/* ipkg_hash.c - the itsy package management system
  11280. +
  11281. + Steven M. Ayer
  11282. +
  11283. + Copyright (C) 2002 Compaq Computer Corporation
  11284. +
  11285. + This program is free software; you can redistribute it and/or
  11286. + modify it under the terms of the GNU General Public License as
  11287. + published by the Free Software Foundation; either version 2, or (at
  11288. + your option) any later version.
  11289. +
  11290. + This program is distributed in the hope that it will be useful, but
  11291. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11292. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11293. + General Public License for more details.
  11294. +*/
  11295. +
  11296. +#include "ipkg.h"
  11297. +#include <errno.h>
  11298. +#include <ctype.h>
  11299. +#include <stdlib.h>
  11300. +#include <string.h>
  11301. +
  11302. +#include "hash_table.h"
  11303. +#include "pkg.h"
  11304. +#include "ipkg_message.h"
  11305. +#include "pkg_vec.h"
  11306. +#include "pkg_hash.h"
  11307. +#include "pkg_parse.h"
  11308. +#include "ipkg_utils.h"
  11309. +
  11310. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11311. +
  11312. +/*
  11313. + * this will talk to both feeds-lists files and installed status files
  11314. + * example api:
  11315. + *
  11316. + * hash_table_t hash;
  11317. + * pkg_hash_init(name, &hash, 1000);
  11318. + * pkg_hash_add_from_file(<feed filename>);
  11319. + *
  11320. + * the query function is just there as a shell to prove to me that this
  11321. + * sort of works, but isn't far from doing something useful
  11322. + *
  11323. + * -sma, 12/21/01
  11324. + * modified: CDW 3 Jan. 2002
  11325. + */
  11326. +
  11327. +
  11328. +
  11329. +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
  11330. +{
  11331. + return hash_table_init(name, hash, len);
  11332. +}
  11333. +
  11334. +void pkg_hash_deinit(hash_table_t *hash)
  11335. +{
  11336. + hash_table_deinit(hash);
  11337. +}
  11338. +
  11339. +
  11340. +/* Find the default arch for a given package status file if none is given. */
  11341. +static char *pkg_get_default_arch(ipkg_conf_t *conf)
  11342. +{
  11343. + nv_pair_list_elt_t *l;
  11344. + const char *def_arch = HOST_CPU_STR; /* Default arch */
  11345. + int def_prio = 0; /* Other archs override this */
  11346. +
  11347. + l = conf->arch_list.head;
  11348. +
  11349. + while (l) {
  11350. + nv_pair_t *nv = l->data;
  11351. + int priority = strtol(nv->value, NULL, 0);
  11352. +
  11353. + /* Check if this arch has higher priority, and is valid */
  11354. + if ((priority > def_prio) &&
  11355. + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
  11356. + /* Our new default */
  11357. + def_prio = priority;
  11358. + def_arch = nv->name;
  11359. + }
  11360. + l = l->next;
  11361. + }
  11362. +
  11363. + return strdup(def_arch);
  11364. +}
  11365. +
  11366. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11367. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
  11368. +{
  11369. + hash_table_t *hash = &conf->pkg_hash;
  11370. + char **raw;
  11371. + char **raw_start;
  11372. + pkg_t *pkg;
  11373. +
  11374. + raw = raw_start = read_raw_pkgs_from_file(file_name);
  11375. + if (!raw)
  11376. + return -ENOMEM;
  11377. +
  11378. + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
  11379. + pkg = pkg_new();
  11380. + if (!pkg)
  11381. + return -ENOMEM;
  11382. +
  11383. + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
  11384. + if (!pkg->architecture) {
  11385. + char *version_str = pkg_version_str_alloc(pkg);
  11386. + pkg->architecture = pkg_get_default_arch(conf);
  11387. + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
  11388. + pkg->name, version_str, pkg->architecture);
  11389. + free(version_str);
  11390. + }
  11391. + hash_insert_pkg(hash, pkg, is_status_file,conf);
  11392. + } else {
  11393. + free(pkg);
  11394. + }
  11395. + }
  11396. +
  11397. + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
  11398. + memory after read_raw_pkgs_from_file */
  11399. + raw = raw_start;
  11400. + while (*raw) {
  11401. + free(*raw++);
  11402. + }
  11403. + free(raw_start);
  11404. + return 0;
  11405. +}
  11406. +
  11407. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
  11408. +{
  11409. + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
  11410. +}
  11411. +
  11412. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
  11413. +{
  11414. + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
  11415. + if (apkg)
  11416. + return NULL;
  11417. + return apkg->provided_by;
  11418. +}
  11419. +
  11420. +
  11421. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11422. + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
  11423. +{
  11424. + int i;
  11425. + int nprovides = 0;
  11426. + int nmatching = 0;
  11427. + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
  11428. + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
  11429. + abstract_pkg_vec_t *provided_apkg_vec;
  11430. + abstract_pkg_t **provided_apkgs;
  11431. + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
  11432. + pkg_t *latest_installed_parent = NULL;
  11433. + pkg_t *latest_matching = NULL;
  11434. + pkg_t *held_pkg = NULL;
  11435. + pkg_t *good_pkg_by_name = NULL;
  11436. +
  11437. + if (matching_apkgs == NULL || providers == NULL ||
  11438. + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
  11439. + return NULL;
  11440. +
  11441. + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
  11442. +
  11443. + provided_apkg_vec = apkg->provided_by;
  11444. + nprovides = provided_apkg_vec->len;
  11445. + provided_apkgs = provided_apkg_vec->pkgs;
  11446. + if (nprovides > 1)
  11447. + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
  11448. +
  11449. + /* accumulate all the providers */
  11450. + for (i = 0; i < nprovides; i++) {
  11451. + abstract_pkg_t *provider_apkg = provided_apkgs[i];
  11452. + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
  11453. + abstract_pkg_vec_insert(providers, provider_apkg);
  11454. + }
  11455. + nprovides = providers->len;
  11456. +
  11457. + for (i = 0; i < nprovides; i++) {
  11458. + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
  11459. + abstract_pkg_t *replacement_apkg = NULL;
  11460. + pkg_vec_t *vec;
  11461. +
  11462. + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
  11463. + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
  11464. + if (provider_apkg->replaced_by->len > 1) {
  11465. + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
  11466. + provider_apkg->name, replacement_apkg->name);
  11467. + }
  11468. + }
  11469. +
  11470. + if (replacement_apkg)
  11471. + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
  11472. + replacement_apkg->name, provider_apkg->name);
  11473. +
  11474. + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
  11475. + if (abstract_pkg_vec_contains(providers, replacement_apkg))
  11476. + continue;
  11477. + else
  11478. + provider_apkg = replacement_apkg;
  11479. + }
  11480. +
  11481. + if (!(vec = provider_apkg->pkgs)) {
  11482. + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
  11483. + continue;
  11484. + }
  11485. +
  11486. +
  11487. + /* now check for supported architecture */
  11488. + {
  11489. + int max_count = 0;
  11490. + int j;
  11491. +
  11492. + /* count packages matching max arch priority and keep track of last one */
  11493. + for (j = 0; j < vec->len; j++) {
  11494. + pkg_t *maybe = vec->pkgs[j];
  11495. + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
  11496. + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
  11497. + if (maybe->arch_priority > 0) {
  11498. + max_count++;
  11499. + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
  11500. + pkg_vec_insert(matching_pkgs, maybe);
  11501. + }
  11502. + }
  11503. + }
  11504. + }
  11505. +
  11506. + if (matching_pkgs->len > 1)
  11507. + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
  11508. + if (matching_apkgs->len > 1)
  11509. + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
  11510. +
  11511. +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
  11512. + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
  11513. +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
  11514. + Until now I always got the latest, but that breaks the downgrade option.
  11515. + If I stop at the first one, I would probably miss the new ones
  11516. + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
  11517. + or from a Packages feed.
  11518. + 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*/
  11519. +/*Pigi*/
  11520. +
  11521. + for (i = 0; i < matching_pkgs->len; i++) {
  11522. + pkg_t *matching = matching_pkgs->pkgs[i];
  11523. + if (constraint_fcn(matching, cdata)) { /* We found it */
  11524. + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
  11525. + good_pkg_by_name = matching;
  11526. + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
  11527. + break;
  11528. + }
  11529. + }
  11530. +
  11531. +
  11532. + for (i = 0; i < matching_pkgs->len; i++) {
  11533. + pkg_t *matching = matching_pkgs->pkgs[i];
  11534. + latest_matching = matching;
  11535. + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
  11536. + latest_installed_parent = matching;
  11537. + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
  11538. + if (held_pkg)
  11539. + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
  11540. + held_pkg->name, matching->name);
  11541. + held_pkg = matching;
  11542. + }
  11543. + }
  11544. +
  11545. + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
  11546. + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
  11547. + apkg->name, matching_apkgs->len);
  11548. + for (i = 0; i < matching_apkgs->len; i++) {
  11549. + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
  11550. + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
  11551. + }
  11552. + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
  11553. + }
  11554. +
  11555. + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
  11556. + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
  11557. + __FUNCTION__, apkg->name, matching_pkgs->len);
  11558. + for (i = 0; i < matching_pkgs->len; i++) {
  11559. + pkg_t *matching = matching_pkgs->pkgs[i];
  11560. + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
  11561. + matching->name, matching->version, matching->architecture);
  11562. + }
  11563. + }
  11564. +
  11565. + nmatching = matching_apkgs->len;
  11566. +
  11567. + pkg_vec_free(matching_pkgs);
  11568. + abstract_pkg_vec_free(matching_apkgs);
  11569. + abstract_pkg_vec_free(providers);
  11570. +
  11571. + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
  11572. + return good_pkg_by_name;
  11573. + }
  11574. + if (held_pkg) {
  11575. + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
  11576. + return held_pkg;
  11577. + }
  11578. + if (latest_installed_parent) {
  11579. + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
  11580. + return latest_installed_parent;
  11581. + }
  11582. + if (nmatching > 1) {
  11583. + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
  11584. + return NULL;
  11585. + }
  11586. + if (latest_matching) {
  11587. + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
  11588. + latest_matching->name, latest_matching->version, latest_matching->architecture);
  11589. + return latest_matching;
  11590. + }
  11591. + return NULL;
  11592. +}
  11593. +
  11594. +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
  11595. +{
  11596. + const char *name = (const char *)cdata;
  11597. + if (strcmp(pkg->name, name) == 0)
  11598. + return 1;
  11599. + else
  11600. + return 0;
  11601. +}
  11602. +
  11603. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
  11604. +{
  11605. + hash_table_t *hash = &conf->pkg_hash;
  11606. + abstract_pkg_t *apkg = NULL;
  11607. +
  11608. + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
  11609. + return NULL;
  11610. +
  11611. + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
  11612. +}
  11613. +
  11614. +
  11615. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11616. + const char *pkg_name,
  11617. + const char * version)
  11618. +{
  11619. + pkg_vec_t * vec;
  11620. + register int i;
  11621. + char *version_str = NULL;
  11622. +
  11623. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
  11624. + return NULL;
  11625. +
  11626. + for(i = 0; i < vec->len; i++) {
  11627. + version_str = pkg_version_str_alloc(vec->pkgs[i]);
  11628. + if(!strcmp(version_str, version)) {
  11629. + free(version_str);
  11630. + break;
  11631. + }
  11632. + free(version_str);
  11633. + }
  11634. +
  11635. + if(i == vec->len)
  11636. + return NULL;
  11637. +
  11638. + return vec->pkgs[i];
  11639. +}
  11640. +
  11641. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11642. + const char *pkg_name,
  11643. + pkg_dest_t *dest)
  11644. +{
  11645. + pkg_vec_t * vec;
  11646. + register int i;
  11647. +
  11648. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
  11649. + return NULL;
  11650. + }
  11651. +
  11652. + for(i = 0; i < vec->len; i++)
  11653. + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
  11654. + return vec->pkgs[i];
  11655. + }
  11656. + return NULL;
  11657. +}
  11658. +
  11659. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11660. + const char *pkg_name)
  11661. +{
  11662. + pkg_vec_t * vec;
  11663. + register int i;
  11664. +
  11665. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
  11666. + return NULL;
  11667. + }
  11668. +
  11669. + for(i = 0; i < vec->len; i++)
  11670. + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
  11671. + return vec->pkgs[i];
  11672. + }
  11673. +
  11674. + return NULL;
  11675. +}
  11676. +
  11677. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
  11678. +{
  11679. + abstract_pkg_t * ab_pkg;
  11680. +
  11681. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
  11682. + return NULL;
  11683. + }
  11684. +
  11685. + if (ab_pkg->pkgs) {
  11686. + return ab_pkg->pkgs;
  11687. + } else if (ab_pkg->provided_by) {
  11688. + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
  11689. + if (abpkg != NULL){
  11690. + return abpkg->pkgs;
  11691. + } else {
  11692. + return ab_pkg->pkgs;
  11693. + }
  11694. + } else {
  11695. + return NULL;
  11696. + }
  11697. +}
  11698. +
  11699. +static int pkg_compare_names(const void *p1, const void *p2)
  11700. +{
  11701. + const pkg_t *pkg1 = *(const pkg_t **)p1;
  11702. + const pkg_t *pkg2 = *(const pkg_t **)p2;
  11703. + if (pkg1->name == NULL)
  11704. + return 1;
  11705. + if (pkg2->name == NULL)
  11706. + return -1;
  11707. + return(strcmp(pkg1->name, pkg2->name));
  11708. +}
  11709. +
  11710. +
  11711. +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
  11712. +{
  11713. + int j;
  11714. + const char *name;
  11715. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11716. + pkg_vec_t *all = (pkg_vec_t *)data;
  11717. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11718. + name = pkg_name;
  11719. + if (pkg_vec) {
  11720. + for (j = 0; j < pkg_vec->len; j++) {
  11721. + pkg_t *pkg = pkg_vec->pkgs[j];
  11722. + pkg_vec_insert(all, pkg);
  11723. + }
  11724. + }
  11725. +}
  11726. +
  11727. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
  11728. +{
  11729. + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
  11730. + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
  11731. +}
  11732. +
  11733. +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
  11734. +{
  11735. + const char *name;
  11736. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11737. + pkg_vec_t *all = (pkg_vec_t *)data;
  11738. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11739. + int j;
  11740. + name = pkg_name;
  11741. + if (pkg_vec) {
  11742. + for (j = 0; j < pkg_vec->len; j++) {
  11743. + pkg_t *pkg = pkg_vec->pkgs[j];
  11744. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  11745. + pkg_vec_insert(all, pkg);
  11746. + }
  11747. + }
  11748. + }
  11749. +}
  11750. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
  11751. +{
  11752. + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
  11753. + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
  11754. +}
  11755. +
  11756. +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
  11757. +{
  11758. + int i;
  11759. + pkg_t *pkg;
  11760. + const char *name;
  11761. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11762. + ipkg_conf_t *conf = (ipkg_conf_t *)data;
  11763. + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
  11764. + name = pkg_name;
  11765. + fprintf(stdout, "%s\n", ab_pkg->name);
  11766. + i = 0;
  11767. + if (dependents != NULL)
  11768. + while (dependents [i] != NULL)
  11769. + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
  11770. + dependents = ab_pkg->provided_by->pkgs;
  11771. + i = 0;
  11772. + if (dependents != NULL)
  11773. + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
  11774. + printf ("\tprovided by - %s\n", dependents [i ++]->name);
  11775. + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
  11776. + if (pkg) {
  11777. + i = 0;
  11778. + while (i < pkg->depends_count)
  11779. + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
  11780. + }
  11781. +}
  11782. +void pkg_hash_dump(hash_table_t *hash, void *data)
  11783. +{
  11784. +
  11785. + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
  11786. + hash_table_foreach(hash, pkg_hash_dump_helper, data);
  11787. + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
  11788. +}
  11789. +
  11790. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11791. +{
  11792. + abstract_pkg_t * ab_pkg;
  11793. +
  11794. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
  11795. + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
  11796. +
  11797. + return ab_pkg;
  11798. +}
  11799. +
  11800. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  11801. +{
  11802. + abstract_pkg_t * ab_pkg;
  11803. + int arch_priority;
  11804. +
  11805. + if(!pkg)
  11806. + return pkg;
  11807. +
  11808. + arch_priority = pkg->arch_priority;
  11809. +
  11810. + if (buildDepends(hash, pkg)<0){
  11811. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11812. + return NULL;
  11813. + }
  11814. + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
  11815. +
  11816. + if (set_status) {
  11817. + if (pkg->state_status == SS_INSTALLED) {
  11818. + ab_pkg->state_status = SS_INSTALLED;
  11819. + } else if (pkg->state_status == SS_UNPACKED) {
  11820. + ab_pkg->state_status = SS_UNPACKED;
  11821. + }
  11822. + }
  11823. +
  11824. + if(!ab_pkg->pkgs)
  11825. + ab_pkg->pkgs = pkg_vec_alloc();
  11826. +
  11827. + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
  11828. + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
  11829. + pkg->parent = ab_pkg;
  11830. +
  11831. + if (buildProvides(hash, ab_pkg, pkg)<0){
  11832. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11833. + return NULL;
  11834. + }
  11835. + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
  11836. + if (buildConflicts(hash, pkg)<0){
  11837. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11838. + return NULL;
  11839. + }
  11840. + if (buildReplaces(hash, ab_pkg, pkg)<0) {
  11841. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11842. + return NULL;
  11843. + }
  11844. +
  11845. + buildDependedUponBy(pkg, ab_pkg);
  11846. + return pkg;
  11847. +}
  11848. +
  11849. +/*
  11850. + * this will assume that we've already determined that
  11851. + * the abstract pkg doesn't exist, 'cause we should know these things...
  11852. + */
  11853. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11854. +{
  11855. + abstract_pkg_t * ab_pkg;
  11856. +
  11857. + ab_pkg = abstract_pkg_new();
  11858. + if (ab_pkg == NULL) { return NULL; }
  11859. +
  11860. + ab_pkg->name = strdup(pkg_name);
  11861. + hash_table_insert(hash, pkg_name, ab_pkg);
  11862. +
  11863. + return ab_pkg;
  11864. +}
  11865. +
  11866. +
  11867. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
  11868. +{
  11869. + hash_table_t *file_hash = &conf->file_hash;
  11870. +
  11871. + return hash_table_get(file_hash, file_name);
  11872. +}
  11873. +
  11874. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
  11875. +{
  11876. + hash_table_t *file_hash = &conf->file_hash;
  11877. + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
  11878. + int file_name_len = strlen(file_name);
  11879. +
  11880. + if (file_name[file_name_len -1] == '/')
  11881. + return 0;
  11882. +
  11883. + if (conf->offline_root) {
  11884. + int len = strlen(conf->offline_root);
  11885. + if (strncmp(file_name, conf->offline_root, len) == 0) {
  11886. + file_name += len;
  11887. + }
  11888. + }
  11889. +
  11890. + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
  11891. + hash_table_insert(file_hash, file_name, owning_pkg);
  11892. + if (old_owning_pkg) {
  11893. + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
  11894. + /* mark this package to have its filelist written */
  11895. + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11896. + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11897. + }
  11898. + return 0;
  11899. +}
  11900. +
  11901. +
  11902. diff -Nur busybox-1.20.2.orig//archival/libipkg/pkg_hash.h busybox-1.20.2/archival/libipkg/pkg_hash.h
  11903. --- busybox-1.20.2.orig//archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
  11904. +++ busybox-1.20.2/archival/libipkg/pkg_hash.h 2013-01-31 16:44:31.000000000 +0100
  11905. @@ -0,0 +1,61 @@
  11906. +/* pkg_hash.h - the itsy package management system
  11907. +
  11908. + Steven M. Ayer
  11909. +
  11910. + Copyright (C) 2002 Compaq Computer Corporation
  11911. +
  11912. + This program is free software; you can redistribute it and/or
  11913. + modify it under the terms of the GNU General Public License as
  11914. + published by the Free Software Foundation; either version 2, or (at
  11915. + your option) any later version.
  11916. +
  11917. + This program is distributed in the hope that it will be useful, but
  11918. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11919. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11920. + General Public License for more details.
  11921. +*/
  11922. +
  11923. +#ifndef PKG_HASH_H
  11924. +#define PKG_HASH_H
  11925. +
  11926. +#include "pkg.h"
  11927. +#include "pkg_vec.h"
  11928. +#include "hash_table.h"
  11929. +
  11930. +
  11931. +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
  11932. +void pkg_hash_deinit(hash_table_t *hash);
  11933. +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
  11934. +
  11935. +void pkg_hash_dump(hash_table_t *hash, void *data);
  11936. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
  11937. +
  11938. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11939. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
  11940. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
  11941. +
  11942. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11943. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
  11944. +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11945. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
  11946. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11947. + const char *pkg_name,
  11948. + const char * version);
  11949. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
  11950. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11951. + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
  11952. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
  11953. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11954. + const char *pkg_name);
  11955. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11956. + const char *pkg_name,
  11957. + pkg_dest_t *dest);
  11958. +
  11959. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
  11960. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
  11961. +
  11962. +/* XXX: shouldn't this go in pkg_vec.[ch]? */
  11963. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11964. +
  11965. +#endif
  11966. +
  11967. diff -Nur busybox-1.20.2.orig//archival/libipkg/pkg_parse.c busybox-1.20.2/archival/libipkg/pkg_parse.c
  11968. --- busybox-1.20.2.orig//archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
  11969. +++ busybox-1.20.2/archival/libipkg/pkg_parse.c 2013-01-31 16:44:31.000000000 +0100
  11970. @@ -0,0 +1,368 @@
  11971. +/* pkg_parse.c - the itsy package management system
  11972. +
  11973. + Steven M. Ayer
  11974. +
  11975. + Copyright (C) 2002 Compaq Computer Corporation
  11976. +
  11977. + This program is free software; you can redistribute it and/or
  11978. + modify it under the terms of the GNU General Public License as
  11979. + published by the Free Software Foundation; either version 2, or (at
  11980. + your option) any later version.
  11981. +
  11982. + This program is distributed in the hope that it will be useful, but
  11983. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11984. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11985. + General Public License for more details.
  11986. +*/
  11987. +
  11988. +#include "ipkg.h"
  11989. +#include <errno.h>
  11990. +#include <ctype.h>
  11991. +
  11992. +#include "pkg.h"
  11993. +#include "ipkg_utils.h"
  11994. +#include "pkg_parse.h"
  11995. +
  11996. +int alterProvidesLine(char *raw, char *temp);
  11997. +
  11998. +int isGenericFieldType(char * type, char * line)
  11999. +{
  12000. + if(!strncmp(line, type, strlen(type)))
  12001. + return 1;
  12002. + return 0;
  12003. +}
  12004. +
  12005. +char * parseGenericFieldType(char * type, char * raw)
  12006. +{
  12007. + char * field_value = raw + (strlen(type) + 1);
  12008. + return trim_alloc(field_value);
  12009. +}
  12010. +
  12011. +void parseStatus(pkg_t *pkg, char * raw)
  12012. +{
  12013. + char sw_str[64], sf_str[64], ss_str[64];
  12014. +
  12015. + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
  12016. + pkg->state_want = pkg_state_want_from_str(sw_str);
  12017. + pkg->state_flag = pkg_state_flag_from_str(sf_str);
  12018. + pkg->state_status = pkg_state_status_from_str(ss_str);
  12019. +}
  12020. +
  12021. +char ** parseDependsString(char * raw, int * depends_count)
  12022. +{
  12023. + char ** depends = NULL;
  12024. + int line_count = 0;
  12025. + char buff[2048], * dest;
  12026. +
  12027. + while(raw && *raw && !isspace(*raw)) {
  12028. + raw++;
  12029. + }
  12030. +
  12031. + if(line_is_blank(raw)){
  12032. + *depends_count = line_count;
  12033. + return NULL;
  12034. + }
  12035. + while(raw && *raw){
  12036. + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
  12037. +
  12038. + while(isspace(*raw)) raw++;
  12039. +
  12040. + dest = buff;
  12041. + while((*raw != ',') && *raw)
  12042. + *dest++ = *raw++;
  12043. +
  12044. + *dest = '\0';
  12045. + depends[line_count] = trim_alloc(buff);
  12046. + if(depends[line_count] ==NULL)
  12047. + return NULL;
  12048. + line_count++;
  12049. + if(*raw == ',')
  12050. + raw++;
  12051. + }
  12052. + *depends_count = line_count;
  12053. + return depends;
  12054. +}
  12055. +
  12056. +void parseConffiles(pkg_t * pkg, char * raw)
  12057. +{
  12058. + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
  12059. +
  12060. + if(!strncmp(raw, "Conffiles:", 10))
  12061. + raw += strlen("Conffiles:");
  12062. +
  12063. + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
  12064. + conffile_list_append(&pkg->conffiles, file_name, md5sum);
  12065. + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
  12066. + while (*raw && isspace(*raw)) {
  12067. + raw++;
  12068. + }
  12069. + raw += strlen(file_name);
  12070. + while (*raw && isspace(*raw)) {
  12071. + raw++;
  12072. + }
  12073. + raw += strlen(md5sum);
  12074. + }
  12075. +}
  12076. +
  12077. +int parseVersion(pkg_t *pkg, char *raw)
  12078. +{
  12079. + char *colon, *eepochcolon;
  12080. +#ifdef USE_DEBVERSION
  12081. + char *hyphen;
  12082. +#endif
  12083. + unsigned long epoch;
  12084. +
  12085. + if (!*raw) {
  12086. + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
  12087. + return EINVAL;
  12088. + }
  12089. +
  12090. + if (strncmp(raw, "Version:", 8) == 0) {
  12091. + raw += 8;
  12092. + }
  12093. + while (*raw && isspace(*raw)) {
  12094. + raw++;
  12095. + }
  12096. +
  12097. + colon= strchr(raw,':');
  12098. + if (colon) {
  12099. + epoch= strtoul(raw,&eepochcolon,10);
  12100. + if (colon != eepochcolon) {
  12101. + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
  12102. + return EINVAL;
  12103. + }
  12104. + if (!*++colon) {
  12105. + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
  12106. + return EINVAL;
  12107. + }
  12108. + raw= colon;
  12109. + pkg->epoch= epoch;
  12110. + } else {
  12111. + pkg->epoch= 0;
  12112. + }
  12113. +
  12114. + pkg->revision = (char *)"";
  12115. + pkg->familiar_revision = (char *)"";
  12116. +
  12117. + pkg->version= malloc(strlen(raw)+1);
  12118. + if ( pkg->version == NULL ) {
  12119. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12120. + return ENOMEM;
  12121. + }
  12122. + strcpy(pkg->version, raw);
  12123. +
  12124. +#ifdef USE_DEBVERSION
  12125. + hyphen= strrchr(pkg->version,'-');
  12126. +
  12127. + if (hyphen) {
  12128. + *hyphen++= 0;
  12129. + if (strncmp("fam", hyphen, 3) == 0) {
  12130. + pkg->familiar_revision=hyphen+3;
  12131. + hyphen= strrchr(pkg->version,'-');
  12132. + if (hyphen) {
  12133. + *hyphen++= 0;
  12134. + pkg->revision = hyphen;
  12135. + }
  12136. + } else {
  12137. + pkg->revision = hyphen;
  12138. + }
  12139. + }
  12140. +#endif
  12141. +
  12142. +/*
  12143. + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
  12144. + pkg->epoch,
  12145. + pkg->version,
  12146. + pkg->revision,
  12147. + pkg->familiar_revision);
  12148. +*/
  12149. +
  12150. + return 0;
  12151. +}
  12152. +
  12153. +
  12154. +/* This code is needed to insert in first position the keyword for the aligning bug */
  12155. +
  12156. +int alterProvidesLine(char *raw, char *temp)
  12157. +{
  12158. +
  12159. +
  12160. + if (!*raw) {
  12161. + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
  12162. + return -EINVAL;
  12163. + }
  12164. +
  12165. + if ( temp == NULL ) {
  12166. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12167. + return -ENOMEM;
  12168. + }
  12169. +
  12170. + if (strncmp(raw, "Provides:", 9) == 0) {
  12171. + raw += 9;
  12172. + }
  12173. + while (*raw && isspace(*raw)) {
  12174. + raw++;
  12175. + }
  12176. +
  12177. + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
  12178. + while (*raw) {
  12179. + strncat( temp, raw++, 1);
  12180. + }
  12181. + return 0;
  12182. +
  12183. +}
  12184. +
  12185. +/* Some random thoughts from Carl:
  12186. +
  12187. + This function could be considerably simplified if we just kept
  12188. + an array of all the generic string-valued field names, and looped
  12189. + through those looking for a match. Also, these fields could perhaps
  12190. + be stored in the package as an array as well, (or, probably better,
  12191. + as an nv_pair_list_t).
  12192. +
  12193. + Fields which require special parsing or storage, (such as Depends:
  12194. + and Status:) could be handled as they are now.
  12195. +*/
  12196. +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
  12197. + to a dependency list. And, since we already have
  12198. + Depends/Pre-Depends and need to add Conflicts, Recommends, and
  12199. + Enhances, perhaps we could generalize all of these and save some
  12200. + code duplication.
  12201. +*/
  12202. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
  12203. +{
  12204. + int reading_conffiles, reading_description;
  12205. + int pkg_false_provides=1;
  12206. + char ** lines;
  12207. + char * provide=NULL;
  12208. +
  12209. + pkg->src = src;
  12210. + pkg->dest = dest;
  12211. +
  12212. + reading_conffiles = reading_description = 0;
  12213. +
  12214. + for (lines = *raw; *lines; lines++) {
  12215. + /* fprintf(stderr, "PARSING %s\n", *lines);*/
  12216. + if(isGenericFieldType((char *)"Package:", *lines))
  12217. + pkg->name = parseGenericFieldType((char *)"Package", *lines);
  12218. + else if(isGenericFieldType((char *)"Architecture:", *lines))
  12219. + pkg->architecture = parseGenericFieldType((char *)"Architecture", *lines);
  12220. + else if(isGenericFieldType((char *)"Filename:", *lines))
  12221. + pkg->filename = parseGenericFieldType((char *)"Filename", *lines);
  12222. + else if(isGenericFieldType((char *)"Section:", *lines))
  12223. + pkg->section = parseGenericFieldType((char *)"Section", *lines);
  12224. + else if(isGenericFieldType((char *)"MD5sum:", *lines))
  12225. + pkg->md5sum = parseGenericFieldType((char *)"MD5sum", *lines);
  12226. + /* The old ipkg wrote out status files with the wrong case for MD5sum,
  12227. + let's parse it either way */
  12228. + else if(isGenericFieldType((char *)"MD5Sum:", *lines))
  12229. + pkg->md5sum = parseGenericFieldType((char *)"MD5Sum", *lines);
  12230. + else if(isGenericFieldType((char *)"Size:", *lines))
  12231. + pkg->size = parseGenericFieldType((char *)"Size", *lines);
  12232. + else if(isGenericFieldType((char *)"Source:", *lines))
  12233. + pkg->source = parseGenericFieldType((char *)"Source", *lines);
  12234. + else if(isGenericFieldType((char *)"Installed-Size:", *lines))
  12235. + pkg->installed_size = parseGenericFieldType((char *)"Installed-Size", *lines);
  12236. + else if(isGenericFieldType((char *)"Installed-Time:", *lines)) {
  12237. + char *time_str = parseGenericFieldType((char *)"Installed-Time", *lines);
  12238. + pkg->installed_time = strtoul(time_str, NULL, 0);
  12239. + } else if(isGenericFieldType((char *)"Priority:", *lines))
  12240. + pkg->priority = parseGenericFieldType((char *)"Priority", *lines);
  12241. + else if(isGenericFieldType((char *)"Essential:", *lines)) {
  12242. + char *essential_value;
  12243. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12244. + if (strcmp(essential_value, "yes") == 0) {
  12245. + pkg->essential = 1;
  12246. + }
  12247. + free(essential_value);
  12248. + }
  12249. + else if(isGenericFieldType((char *)"Status", *lines))
  12250. + parseStatus(pkg, *lines);
  12251. + else if(isGenericFieldType((char *)"Version", *lines))
  12252. + parseVersion(pkg, *lines);
  12253. + else if(isGenericFieldType((char *)"Maintainer", *lines))
  12254. + pkg->maintainer = parseGenericFieldType((char *)"Maintainer", *lines);
  12255. + else if(isGenericFieldType((char *)"Conffiles", *lines)){
  12256. + parseConffiles(pkg, *lines);
  12257. + reading_conffiles = 1;
  12258. + }
  12259. + else if(isGenericFieldType((char *)"Description", *lines)) {
  12260. + pkg->description = parseGenericFieldType((char *)"Description", *lines);
  12261. + reading_conffiles = 0;
  12262. + reading_description = 1;
  12263. + }
  12264. +
  12265. + else if(isGenericFieldType((char *)"Provides", *lines)){
  12266. +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
  12267. + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
  12268. + if ( alterProvidesLine(*lines,provide) ){
  12269. + return EINVAL;
  12270. + }
  12271. + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
  12272. +/* Let's try to hack a bit here.
  12273. + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
  12274. + in alot of other places. We will remove it before writing down the status database */
  12275. + pkg_false_provides=0;
  12276. + free(provide);
  12277. + }
  12278. +
  12279. + else if(isGenericFieldType((char *)"Depends", *lines))
  12280. + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
  12281. + else if(isGenericFieldType((char *)"Pre-Depends", *lines))
  12282. + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
  12283. + else if(isGenericFieldType((char *)"Recommends", *lines))
  12284. + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
  12285. + else if(isGenericFieldType((char *)"Suggests", *lines))
  12286. + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
  12287. + /* Abhaya: support for conflicts */
  12288. + else if(isGenericFieldType((char *)"Conflicts", *lines))
  12289. + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
  12290. + else if(isGenericFieldType((char *)"Replaces", *lines))
  12291. + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
  12292. + else if(line_is_blank(*lines)) {
  12293. + lines++;
  12294. + break;
  12295. + }
  12296. + else if(**lines == ' '){
  12297. + if(reading_description) {
  12298. + /* we already know it's not blank, so the rest of description */
  12299. + pkg->description = realloc(pkg->description,
  12300. + strlen(pkg->description)
  12301. + + 1 + strlen(*lines) + 1);
  12302. + strcat(pkg->description, "\n");
  12303. + strcat(pkg->description, (*lines));
  12304. + }
  12305. + else if(reading_conffiles)
  12306. + parseConffiles(pkg, *lines);
  12307. + }
  12308. + }
  12309. + *raw = lines;
  12310. +/* If the ipk has not a Provides line, we insert our false line */
  12311. + if ( pkg_false_provides==1)
  12312. + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
  12313. +
  12314. + if (pkg->name) {
  12315. + return 0;
  12316. + } else {
  12317. + return EINVAL;
  12318. + }
  12319. +}
  12320. +
  12321. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
  12322. +{
  12323. + char ** lines;
  12324. +
  12325. + for (lines = *raw; *lines; lines++) {
  12326. + if(isGenericFieldType((char *)"Essential:", *lines)) {
  12327. + char *essential_value;
  12328. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12329. + if (strcmp(essential_value, "yes") == 0) {
  12330. + pkg->essential = 1;
  12331. + }
  12332. + free(essential_value);
  12333. + }
  12334. + }
  12335. + *raw = lines;
  12336. +
  12337. + return 0;
  12338. +}
  12339. diff -Nur busybox-1.20.2.orig//archival/libipkg/pkg_parse.h busybox-1.20.2/archival/libipkg/pkg_parse.h
  12340. --- busybox-1.20.2.orig//archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
  12341. +++ busybox-1.20.2/archival/libipkg/pkg_parse.h 2013-01-31 16:44:31.000000000 +0100
  12342. @@ -0,0 +1,31 @@
  12343. +/* pkg_parse.h - the itsy package management system
  12344. +
  12345. + Steven M. Ayer
  12346. +
  12347. + Copyright (C) 2002 Compaq Computer Corporation
  12348. +
  12349. + This program is free software; you can redistribute it and/or
  12350. + modify it under the terms of the GNU General Public License as
  12351. + published by the Free Software Foundation; either version 2, or (at
  12352. + your option) any later version.
  12353. +
  12354. + This program is distributed in the hope that it will be useful, but
  12355. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12356. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12357. + General Public License for more details.
  12358. +*/
  12359. +
  12360. +#ifndef PKG_PARSE_H
  12361. +#define PKG_PARSE_H
  12362. +
  12363. +int isGenericFieldType(char * type, char * line);
  12364. +char * parseGenericFieldType(char * type, char * raw);
  12365. +void parseStatus(pkg_t *pkg, char * raw);
  12366. +int parseVersion(pkg_t *pkg, char *raw);
  12367. +char ** parseDependsString(char * raw, int * depends_count);
  12368. +int parseVersion(pkg_t *pkg, char *raw);
  12369. +void parseConffiles(pkg_t * pkg, char * raw);
  12370. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
  12371. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
  12372. +
  12373. +#endif
  12374. diff -Nur busybox-1.20.2.orig//archival/libipkg/pkg_src.c busybox-1.20.2/archival/libipkg/pkg_src.c
  12375. --- busybox-1.20.2.orig//archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
  12376. +++ busybox-1.20.2/archival/libipkg/pkg_src.c 2013-01-31 16:44:31.000000000 +0100
  12377. @@ -0,0 +1,43 @@
  12378. +/* pkg_src.c - the itsy package management system
  12379. +
  12380. + Carl D. Worth
  12381. +
  12382. + Copyright (C) 2001 University of Southern California
  12383. +
  12384. + This program is free software; you can redistribute it and/or
  12385. + modify it under the terms of the GNU General Public License as
  12386. + published by the Free Software Foundation; either version 2, or (at
  12387. + your option) any later version.
  12388. +
  12389. + This program is distributed in the hope that it will be useful, but
  12390. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12391. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12392. + General Public License for more details.
  12393. +*/
  12394. +
  12395. +#include "ipkg.h"
  12396. +
  12397. +#include "pkg_src.h"
  12398. +#include "str_util.h"
  12399. +
  12400. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
  12401. +{
  12402. + src->gzip = gzip;
  12403. + src->name = str_dup_safe (name);
  12404. + src->value = str_dup_safe (base_url);
  12405. + if (extra_data)
  12406. + src->extra_data = str_dup_safe (extra_data);
  12407. + else
  12408. + src->extra_data = NULL;
  12409. + return 0;
  12410. +}
  12411. +
  12412. +void pkg_src_deinit(pkg_src_t *src)
  12413. +{
  12414. + free (src->name);
  12415. + free (src->value);
  12416. + if (src->extra_data)
  12417. + free (src->extra_data);
  12418. +}
  12419. +
  12420. +
  12421. diff -Nur busybox-1.20.2.orig//archival/libipkg/pkg_src.h busybox-1.20.2/archival/libipkg/pkg_src.h
  12422. --- busybox-1.20.2.orig//archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
  12423. +++ busybox-1.20.2/archival/libipkg/pkg_src.h 2013-01-31 16:44:31.000000000 +0100
  12424. @@ -0,0 +1,34 @@
  12425. +/* pkg_src.h - the itsy package management system
  12426. +
  12427. + Carl D. Worth
  12428. +
  12429. + Copyright (C) 2001 University of Southern California
  12430. +
  12431. + This program is free software; you can redistribute it and/or
  12432. + modify it under the terms of the GNU General Public License as
  12433. + published by the Free Software Foundation; either version 2, or (at
  12434. + your option) any later version.
  12435. +
  12436. + This program is distributed in the hope that it will be useful, but
  12437. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12438. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12439. + General Public License for more details.
  12440. +*/
  12441. +
  12442. +#ifndef PKG_SRC_H
  12443. +#define PKG_SRC_H
  12444. +
  12445. +#include "nv_pair.h"
  12446. +
  12447. +typedef struct
  12448. +{
  12449. + char *name;
  12450. + char *value;
  12451. + char *extra_data;
  12452. + int gzip;
  12453. +} pkg_src_t;
  12454. +
  12455. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
  12456. +void pkg_src_deinit(pkg_src_t *src);
  12457. +
  12458. +#endif
  12459. diff -Nur busybox-1.20.2.orig//archival/libipkg/pkg_src_list.c busybox-1.20.2/archival/libipkg/pkg_src_list.c
  12460. --- busybox-1.20.2.orig//archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
  12461. +++ busybox-1.20.2/archival/libipkg/pkg_src_list.c 2013-01-31 16:44:31.000000000 +0100
  12462. @@ -0,0 +1,75 @@
  12463. +/* pkg_src_list.c - the itsy package management system
  12464. +
  12465. + Carl D. Worth
  12466. +
  12467. + Copyright (C) 2001 University of Southern California
  12468. +
  12469. + This program is free software; you can redistribute it and/or
  12470. + modify it under the terms of the GNU General Public License as
  12471. + published by the Free Software Foundation; either version 2, or (at
  12472. + your option) any later version.
  12473. +
  12474. + This program is distributed in the hope that it will be useful, but
  12475. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12476. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12477. + General Public License for more details.
  12478. +*/
  12479. +
  12480. +#include "ipkg.h"
  12481. +
  12482. +#include "pkg_src_list.h"
  12483. +#include "void_list.h"
  12484. +
  12485. +int pkg_src_list_init(pkg_src_list_t *list)
  12486. +{
  12487. + return void_list_init((void_list_t *) list);
  12488. +}
  12489. +
  12490. +void pkg_src_list_deinit(pkg_src_list_t *list)
  12491. +{
  12492. + pkg_src_list_elt_t *iter;
  12493. + pkg_src_t *pkg_src;
  12494. +
  12495. + for (iter = list->head; iter; iter = iter->next) {
  12496. + pkg_src = iter->data;
  12497. + pkg_src_deinit(pkg_src);
  12498. +
  12499. + /* malloced in pkg_src_list_append */
  12500. + free(pkg_src);
  12501. + iter->data = NULL;
  12502. + }
  12503. + void_list_deinit((void_list_t *) list);
  12504. +}
  12505. +
  12506. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
  12507. + const char *name, const char *base_url, const char *extra_data,
  12508. + int gzip)
  12509. +{
  12510. + int err;
  12511. +
  12512. + /* freed in pkg_src_list_deinit */
  12513. + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
  12514. +
  12515. + if (pkg_src == NULL) {
  12516. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12517. + return NULL;
  12518. + }
  12519. + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
  12520. +
  12521. + err = void_list_append((void_list_t *) list, pkg_src);
  12522. + if (err) {
  12523. + return NULL;
  12524. + }
  12525. +
  12526. + return pkg_src;
  12527. +}
  12528. +
  12529. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
  12530. +{
  12531. + return void_list_push((void_list_t *) list, data);
  12532. +}
  12533. +
  12534. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
  12535. +{
  12536. + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
  12537. +}
  12538. diff -Nur busybox-1.20.2.orig//archival/libipkg/pkg_src_list.h busybox-1.20.2/archival/libipkg/pkg_src_list.h
  12539. --- busybox-1.20.2.orig//archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
  12540. +++ busybox-1.20.2/archival/libipkg/pkg_src_list.h 2013-01-31 16:44:31.000000000 +0100
  12541. @@ -0,0 +1,57 @@
  12542. +/* pkg_src_list.h - the itsy package management system
  12543. +
  12544. + Carl D. Worth
  12545. +
  12546. + Copyright (C) 2001 University of Southern California
  12547. +
  12548. + This program is free software; you can redistribute it and/or
  12549. + modify it under the terms of the GNU General Public License as
  12550. + published by the Free Software Foundation; either version 2, or (at
  12551. + your option) any later version.
  12552. +
  12553. + This program is distributed in the hope that it will be useful, but
  12554. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12555. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12556. + General Public License for more details.
  12557. +*/
  12558. +
  12559. +#ifndef PKG_SRC_LIST_H
  12560. +#define PKG_SRC_LIST_H
  12561. +
  12562. +#include "pkg_src.h"
  12563. +
  12564. +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
  12565. +struct pkg_src_list_elt
  12566. +{
  12567. + pkg_src_list_elt_t *next;
  12568. + pkg_src_t *data;
  12569. +};
  12570. +
  12571. +typedef struct pkg_src_list pkg_src_list_t;
  12572. +struct pkg_src_list
  12573. +{
  12574. + pkg_src_list_elt_t pre_head;
  12575. + pkg_src_list_elt_t *head;
  12576. + pkg_src_list_elt_t *tail;
  12577. +};
  12578. +
  12579. +static inline int pkg_src_list_empty(pkg_src_list_t *list)
  12580. +{
  12581. + if (list->head == NULL)
  12582. + return 1;
  12583. + else
  12584. + return 0;
  12585. +}
  12586. +
  12587. +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
  12588. +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
  12589. +
  12590. +int pkg_src_list_init(pkg_src_list_t *list);
  12591. +void pkg_src_list_deinit(pkg_src_list_t *list);
  12592. +
  12593. +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);
  12594. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
  12595. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
  12596. +
  12597. +#endif
  12598. +
  12599. diff -Nur busybox-1.20.2.orig//archival/libipkg/pkg_vec.c busybox-1.20.2/archival/libipkg/pkg_vec.c
  12600. --- busybox-1.20.2.orig//archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
  12601. +++ busybox-1.20.2/archival/libipkg/pkg_vec.c 2013-01-31 16:44:31.000000000 +0100
  12602. @@ -0,0 +1,231 @@
  12603. +/* pkg_vec.c - the itsy package management system
  12604. +
  12605. + Steven M. Ayer
  12606. +
  12607. + Copyright (C) 2002 Compaq Computer Corporation
  12608. +
  12609. + This program is free software; you can redistribute it and/or
  12610. + modify it under the terms of the GNU General Public License as
  12611. + published by the Free Software Foundation; either version 2, or (at
  12612. + your option) any later version.
  12613. +
  12614. + This program is distributed in the hope that it will be useful, but
  12615. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12616. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12617. + General Public License for more details.
  12618. +*/
  12619. +
  12620. +#include <stdlib.h>
  12621. +#include <fnmatch.h>
  12622. +#include "libbb.h"
  12623. +#include "xregex.h"
  12624. +#include "ipkg.h"
  12625. +#include "pkg.h"
  12626. +
  12627. +pkg_vec_t * pkg_vec_alloc(void)
  12628. +{
  12629. + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
  12630. + if (!vec) {
  12631. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12632. + return NULL;
  12633. + }
  12634. + vec->pkgs = NULL;
  12635. + vec->len = 0;
  12636. +
  12637. + return vec;
  12638. +}
  12639. +
  12640. +void pkg_vec_free(pkg_vec_t *vec)
  12641. +{
  12642. + free(vec->pkgs);
  12643. + free(vec);
  12644. +}
  12645. +
  12646. +/*
  12647. + * assumption: all names in a vector are identical
  12648. + * assumption: all version strings are trimmed,
  12649. + * so identical versions have identical version strings,
  12650. + * implying identical packages; let's marry these
  12651. + */
  12652. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  12653. +{
  12654. + int i;
  12655. + int found = 0;
  12656. +
  12657. + /* look for a duplicate pkg by name, version, and architecture */
  12658. + for (i = 0; i < vec->len; i++){
  12659. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
  12660. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
  12661. + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
  12662. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12663. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12664. + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
  12665. + found = 1;
  12666. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
  12667. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12668. + break;
  12669. + }
  12670. + }
  12671. +
  12672. + /* we didn't find one, add it */
  12673. + if (!found){
  12674. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
  12675. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12676. +
  12677. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12678. + vec->pkgs[vec->len] = pkg;
  12679. + vec->len++;
  12680. + return pkg;
  12681. + }
  12682. + /* update the one that we have */
  12683. + else {
  12684. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
  12685. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12686. + if (set_status) {
  12687. + /* this is from the status file, so need to merge with existing database */
  12688. + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
  12689. + pkg_merge(vec->pkgs[i], pkg, set_status);
  12690. + /* XXX: CLEANUP: It's not so polite to free something here
  12691. + that was passed in from above. */
  12692. + pkg_deinit(pkg);
  12693. + free(pkg);
  12694. + } else {
  12695. + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
  12696. + /* just overwrite the old one */
  12697. + pkg_deinit(vec->pkgs[i]);
  12698. + free(vec->pkgs[i]);
  12699. + vec->pkgs[i] = pkg;
  12700. + }
  12701. + return vec->pkgs[i];
  12702. + }
  12703. +}
  12704. +
  12705. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
  12706. +{
  12707. + int i;
  12708. + int found = 0;
  12709. +
  12710. + /* look for a duplicate pkg by name, version, and architecture */
  12711. + for (i = 0; i < vec->len; i++)
  12712. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12713. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12714. + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
  12715. + found = 1;
  12716. + break;
  12717. + }
  12718. +
  12719. + /* we didn't find one, add it */
  12720. + if(!found){
  12721. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12722. + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
  12723. + vec->len++;
  12724. + }
  12725. +}
  12726. +
  12727. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
  12728. +{
  12729. + int i;
  12730. + for (i = 0; i < vec->len; i++)
  12731. + if (vec->pkgs[i] == apkg)
  12732. + return 1;
  12733. + return 0;
  12734. +}
  12735. +
  12736. +typedef int (*compare_fcn_t)(const void *, const void *);
  12737. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
  12738. +{
  12739. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12740. +}
  12741. +
  12742. +int pkg_vec_clear_marks(pkg_vec_t *vec)
  12743. +{
  12744. + int npkgs = vec->len;
  12745. + int i;
  12746. + for (i = 0; i < npkgs; i++) {
  12747. + pkg_t *pkg = vec->pkgs[i];
  12748. + pkg->state_flag &= ~SF_MARKED;
  12749. + }
  12750. + return 0;
  12751. +}
  12752. +
  12753. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
  12754. +{
  12755. + int matching_count = 0;
  12756. + pkg_t **pkgs = vec->pkgs;
  12757. + int npkgs = vec->len;
  12758. + int i;
  12759. + for (i = 0; i < npkgs; i++) {
  12760. + pkg_t *pkg = pkgs[i];
  12761. + if (fnmatch(pattern, pkg->name, 0)==0) {
  12762. + pkg->state_flag |= SF_MARKED;
  12763. + matching_count++;
  12764. + }
  12765. + }
  12766. + return matching_count;
  12767. +}
  12768. +
  12769. +
  12770. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
  12771. +{
  12772. + abstract_pkg_vec_t * vec ;
  12773. + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
  12774. + if (!vec) {
  12775. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12776. + return NULL;
  12777. + }
  12778. + vec->pkgs = NULL;
  12779. + vec->len = 0;
  12780. +
  12781. + return vec;
  12782. +}
  12783. +
  12784. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
  12785. +{
  12786. + free(vec->pkgs);
  12787. + free(vec);
  12788. +}
  12789. +
  12790. +/*
  12791. + * assumption: all names in a vector are unique
  12792. + */
  12793. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
  12794. +{
  12795. + int i;
  12796. +
  12797. + /* look for a duplicate pkg by name */
  12798. + for(i = 0; i < vec->len; i++)
  12799. + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12800. + break;
  12801. +
  12802. + /* we didn't find one, add it */
  12803. + if(i == vec->len){
  12804. + vec->pkgs =
  12805. + (abstract_pkg_t **)
  12806. + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
  12807. + vec->pkgs[vec->len] = pkg;
  12808. + vec->len++;
  12809. + }
  12810. +}
  12811. +
  12812. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
  12813. +{
  12814. + if (vec->len > i)
  12815. + return vec->pkgs[i];
  12816. + else
  12817. + return NULL;
  12818. +}
  12819. +
  12820. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
  12821. +{
  12822. + int i;
  12823. + for (i = 0; i < vec->len; i++)
  12824. + if (vec->pkgs[i] == apkg)
  12825. + return 1;
  12826. + return 0;
  12827. +}
  12828. +
  12829. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
  12830. +{
  12831. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12832. +}
  12833. +
  12834. diff -Nur busybox-1.20.2.orig//archival/libipkg/pkg_vec.h busybox-1.20.2/archival/libipkg/pkg_vec.h
  12835. --- busybox-1.20.2.orig//archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
  12836. +++ busybox-1.20.2/archival/libipkg/pkg_vec.h 2013-01-31 16:44:31.000000000 +0100
  12837. @@ -0,0 +1,62 @@
  12838. +/* pkg_vec.h - the itsy package management system
  12839. +
  12840. + Steven M. Ayer
  12841. +
  12842. + Copyright (C) 2002 Compaq Computer Corporation
  12843. +
  12844. + This program is free software; you can redistribute it and/or
  12845. + modify it under the terms of the GNU General Public License as
  12846. + published by the Free Software Foundation; either version 2, or (at
  12847. + your option) any later version.
  12848. +
  12849. + This program is distributed in the hope that it will be useful, but
  12850. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12851. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12852. + General Public License for more details.
  12853. +*/
  12854. +
  12855. +#ifndef PKG_VEC_H
  12856. +#define PKG_VEC_H
  12857. +
  12858. +typedef struct pkg pkg_t;
  12859. +typedef struct abstract_pkg abstract_pkg_t;
  12860. +
  12861. +struct pkg_vec
  12862. +{
  12863. + pkg_t **pkgs;
  12864. + int len;
  12865. +};
  12866. +typedef struct pkg_vec pkg_vec_t;
  12867. +
  12868. +struct abstract_pkg_vec
  12869. +{
  12870. + abstract_pkg_t **pkgs;
  12871. + int len;
  12872. +};
  12873. +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
  12874. +
  12875. +
  12876. +pkg_vec_t * pkg_vec_alloc(void);
  12877. +void pkg_vec_free(pkg_vec_t *vec);
  12878. +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
  12879. +
  12880. +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
  12881. +/* pkg_vec_insert_merge: might munge pkg.
  12882. +* returns the pkg that is in the pkg graph */
  12883. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
  12884. +/* this one never munges pkg */
  12885. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
  12886. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
  12887. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
  12888. +
  12889. +int pkg_vec_clear_marks(pkg_vec_t *vec);
  12890. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
  12891. +
  12892. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
  12893. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
  12894. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
  12895. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
  12896. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
  12897. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
  12898. +#endif
  12899. +
  12900. diff -Nur busybox-1.20.2.orig//archival/libipkg/sprintf_alloc.h busybox-1.20.2/archival/libipkg/sprintf_alloc.h
  12901. --- busybox-1.20.2.orig//archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
  12902. +++ busybox-1.20.2/archival/libipkg/sprintf_alloc.h 2013-01-31 16:44:31.000000000 +0100
  12903. @@ -0,0 +1,25 @@
  12904. +/* sprintf_alloca.c -- like sprintf with memory allocation
  12905. +
  12906. + Carl D. Worth
  12907. +
  12908. + Copyright (C) 2001 University of Southern California
  12909. +
  12910. + This program is free software; you can redistribute it and/or modify
  12911. + it under the terms of the GNU General Public License as published by
  12912. + the Free Software Foundation; either version 2, or (at your option)
  12913. + any later version.
  12914. +
  12915. + This program is distributed in the hope that it will be useful,
  12916. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  12917. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12918. + GNU General Public License for more details.
  12919. +*/
  12920. +
  12921. +#ifndef SPRINTF_ALLOC_H
  12922. +#define SPRINTF_ALLOC_H
  12923. +
  12924. +#include "libbb.h"
  12925. +
  12926. +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
  12927. +
  12928. +#endif
  12929. diff -Nur busybox-1.20.2.orig//archival/libipkg/str_list.c busybox-1.20.2/archival/libipkg/str_list.c
  12930. --- busybox-1.20.2.orig//archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
  12931. +++ busybox-1.20.2/archival/libipkg/str_list.c 2013-01-31 16:44:31.000000000 +0100
  12932. @@ -0,0 +1,76 @@
  12933. +/* str_list.c - the itsy package management system
  12934. +
  12935. + Carl D. Worth
  12936. +
  12937. + Copyright (C) 2001 University of Southern California
  12938. +
  12939. + This program is free software; you can redistribute it and/or
  12940. + modify it under the terms of the GNU General Public License as
  12941. + published by the Free Software Foundation; either version 2, or (at
  12942. + your option) any later version.
  12943. +
  12944. + This program is distributed in the hope that it will be useful, but
  12945. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12946. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12947. + General Public License for more details.
  12948. +*/
  12949. +
  12950. +#include "ipkg.h"
  12951. +
  12952. +#include "str_list.h"
  12953. +
  12954. +int str_list_elt_init(str_list_elt_t *elt, char *data)
  12955. +{
  12956. + return void_list_elt_init((void_list_elt_t *) elt, data);
  12957. +}
  12958. +
  12959. +void str_list_elt_deinit(str_list_elt_t *elt)
  12960. +{
  12961. + void_list_elt_deinit((void_list_elt_t *) elt);
  12962. +}
  12963. +
  12964. +str_list_t *str_list_alloc(void)
  12965. +{
  12966. + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
  12967. + if (list)
  12968. + str_list_init(list);
  12969. + return list;
  12970. +}
  12971. +
  12972. +int str_list_init(str_list_t *list)
  12973. +{
  12974. + return void_list_init((void_list_t *) list);
  12975. +}
  12976. +
  12977. +void str_list_deinit(str_list_t *list)
  12978. +{
  12979. + void_list_deinit((void_list_t *) list);
  12980. +}
  12981. +
  12982. +int str_list_append(str_list_t *list, char *data)
  12983. +{
  12984. + return void_list_append((void_list_t *) list, data);
  12985. +}
  12986. +
  12987. +int str_list_push(str_list_t *list, char *data)
  12988. +{
  12989. + return void_list_push((void_list_t *) list, data);
  12990. +}
  12991. +
  12992. +str_list_elt_t *str_list_pop(str_list_t *list)
  12993. +{
  12994. + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
  12995. +}
  12996. +
  12997. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
  12998. +{
  12999. + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
  13000. + (void_list_elt_t **) iter);
  13001. +}
  13002. +
  13003. +char *str_list_remove_elt(str_list_t *list, const char *target_str)
  13004. +{
  13005. + return (char *)void_list_remove_elt((void_list_t *) list,
  13006. + (void *)target_str,
  13007. + (void_list_cmp_t)strcmp);
  13008. +}
  13009. diff -Nur busybox-1.20.2.orig//archival/libipkg/str_list.h busybox-1.20.2/archival/libipkg/str_list.h
  13010. --- busybox-1.20.2.orig//archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
  13011. +++ busybox-1.20.2/archival/libipkg/str_list.h 2013-01-31 16:44:31.000000000 +0100
  13012. @@ -0,0 +1,51 @@
  13013. +/* str_list.h - the itsy package management system
  13014. +
  13015. + Carl D. Worth
  13016. +
  13017. + Copyright (C) 2001 University of Southern California
  13018. +
  13019. + This program is free software; you can redistribute it and/or
  13020. + modify it under the terms of the GNU General Public License as
  13021. + published by the Free Software Foundation; either version 2, or (at
  13022. + your option) any later version.
  13023. +
  13024. + This program is distributed in the hope that it will be useful, but
  13025. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13026. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13027. + General Public License for more details.
  13028. +*/
  13029. +
  13030. +#ifndef STR_LIST_H
  13031. +#define STR_LIST_H
  13032. +
  13033. +#include "void_list.h"
  13034. +
  13035. +typedef struct str_list_elt str_list_elt_t;
  13036. +struct str_list_elt
  13037. +{
  13038. + str_list_elt_t *next;
  13039. + char *data;
  13040. +};
  13041. +
  13042. +typedef struct xstr_list str_list_t;
  13043. +struct xstr_list
  13044. +{
  13045. + str_list_elt_t pre_head;
  13046. + str_list_elt_t *head;
  13047. + str_list_elt_t *tail;
  13048. +};
  13049. +
  13050. +int str_list_elt_init(str_list_elt_t *elt, char *data);
  13051. +void str_list_elt_deinit(str_list_elt_t *elt);
  13052. +
  13053. +str_list_t *str_list_alloc(void);
  13054. +int str_list_init(str_list_t *list);
  13055. +void str_list_deinit(str_list_t *list);
  13056. +
  13057. +int str_list_append(str_list_t *list, char *data);
  13058. +int str_list_push(str_list_t *list, char *data);
  13059. +str_list_elt_t *str_list_pop(str_list_t *list);
  13060. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
  13061. +char *str_list_remove_elt(str_list_t *list, const char *target_str);
  13062. +
  13063. +#endif
  13064. diff -Nur busybox-1.20.2.orig//archival/libipkg/str_util.c busybox-1.20.2/archival/libipkg/str_util.c
  13065. --- busybox-1.20.2.orig//archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
  13066. +++ busybox-1.20.2/archival/libipkg/str_util.c 2013-01-31 16:44:31.000000000 +0100
  13067. @@ -0,0 +1,69 @@
  13068. +/* str_utils.c - the itsy package management system
  13069. +
  13070. + Carl D. Worth
  13071. +
  13072. + Copyright (C) 2001 University of Southern California
  13073. +
  13074. + This program is free software; you can redistribute it and/or
  13075. + modify it under the terms of the GNU General Public License as
  13076. + published by the Free Software Foundation; either version 2, or (at
  13077. + your option) any later version.
  13078. +
  13079. + This program is distributed in the hope that it will be useful, but
  13080. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13081. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13082. + General Public License for more details.
  13083. +*/
  13084. +
  13085. +#include "ipkg.h"
  13086. +
  13087. +int str_starts_with(const char *str, const char *prefix);
  13088. +int str_ends_with(const char *str, const char *suffix);
  13089. +int str_chomp(char *str);
  13090. +int str_toupper(char *str);
  13091. +char *str_dup_safe(const char *str);
  13092. +
  13093. +int str_starts_with(const char *str, const char *prefix)
  13094. +{
  13095. + return (strncmp(str, prefix, strlen(prefix)) == 0);
  13096. +}
  13097. +
  13098. +int str_ends_with(const char *str, const char *suffix)
  13099. +{
  13100. + int suffix_len;
  13101. + int str_len;
  13102. +
  13103. + str_len = strlen(str);
  13104. + suffix_len = strlen(suffix);
  13105. +
  13106. + if (str_len < suffix_len) {
  13107. + return 0;
  13108. + }
  13109. +
  13110. + return (strcmp(str + str_len - suffix_len, suffix) == 0);
  13111. +}
  13112. +
  13113. +int str_chomp(char *str)
  13114. +{
  13115. + if (str[strlen(str) - 1] == '\n') {
  13116. + str[strlen(str) - 1] = '\0';
  13117. + return 1;
  13118. + }
  13119. + return 0;
  13120. +}
  13121. +
  13122. +int str_toupper(char *str)
  13123. +{
  13124. + while (*str) {
  13125. + *str = toupper(*str);
  13126. + str++;
  13127. + }
  13128. +
  13129. + return 0;
  13130. +}
  13131. +
  13132. +char *str_dup_safe(const char *str)
  13133. +{
  13134. + return str ? strdup(str) : NULL;
  13135. +}
  13136. +
  13137. diff -Nur busybox-1.20.2.orig//archival/libipkg/str_util.h busybox-1.20.2/archival/libipkg/str_util.h
  13138. --- busybox-1.20.2.orig//archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
  13139. +++ busybox-1.20.2/archival/libipkg/str_util.h 2013-01-31 16:44:31.000000000 +0100
  13140. @@ -0,0 +1,27 @@
  13141. +/* str_utils.h - the itsy package management system
  13142. +
  13143. + Carl D. Worth
  13144. +
  13145. + Copyright (C) 2001 University of Southern California
  13146. +
  13147. + This program is free software; you can redistribute it and/or
  13148. + modify it under the terms of the GNU General Public License as
  13149. + published by the Free Software Foundation; either version 2, or (at
  13150. + your option) any later version.
  13151. +
  13152. + This program is distributed in the hope that it will be useful, but
  13153. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13154. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13155. + General Public License for more details.
  13156. +*/
  13157. +
  13158. +#ifndef STR_UTILS_H
  13159. +#define STR_UTILS_H
  13160. +
  13161. +int str_starts_with(const char *str, const char *prefix);
  13162. +int str_ends_with(const char *str, const char *suffix);
  13163. +int str_chomp(char *str);
  13164. +int str_toupper(char *str);
  13165. +char *str_dup_safe(const char *str);
  13166. +
  13167. +#endif
  13168. diff -Nur busybox-1.20.2.orig//archival/libipkg/user.c busybox-1.20.2/archival/libipkg/user.c
  13169. --- busybox-1.20.2.orig//archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
  13170. +++ busybox-1.20.2/archival/libipkg/user.c 2013-01-31 16:44:31.000000000 +0100
  13171. @@ -0,0 +1,49 @@
  13172. +/* user.c - the itsy package management system
  13173. +
  13174. + Jamey Hicks
  13175. +
  13176. + Copyright (C) 2002 Hewlett Packard Company
  13177. + Copyright (C) 2001 University of Southern California
  13178. +
  13179. + This program is free software; you can redistribute it and/or
  13180. + modify it under the terms of the GNU General Public License as
  13181. + published by the Free Software Foundation; either version 2, or (at
  13182. + your option) any later version.
  13183. +
  13184. + This program is distributed in the hope that it will be useful, but
  13185. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13186. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13187. + General Public License for more details.
  13188. +*/
  13189. +
  13190. +#include <stdio.h>
  13191. +#include <stdarg.h>
  13192. +#include "libbb.h"
  13193. +#include "file_util.h"
  13194. +#include "str_util.h"
  13195. +#include "libipkg.h"
  13196. +
  13197. +char *get_user_response(const char *format, ...);
  13198. +static char *question = NULL;
  13199. +static int question_len = 255;
  13200. +
  13201. +char *get_user_response(const char *format, ...)
  13202. +{
  13203. + int len = question_len;
  13204. + va_list ap;
  13205. + char *response;
  13206. + va_start(ap, format);
  13207. +
  13208. + do {
  13209. + if (question == NULL || len > question_len) {
  13210. + question = realloc(question, len + 1);
  13211. + question_len = len;
  13212. + }
  13213. + len = vsnprintf(question,question_len,format,ap);
  13214. + } while (len > question_len);
  13215. + response = strdup(ipkg_cb_response(question));
  13216. + str_chomp(response);
  13217. + str_tolower(response);
  13218. +
  13219. + return response;
  13220. +}
  13221. diff -Nur busybox-1.20.2.orig//archival/libipkg/user.h busybox-1.20.2/archival/libipkg/user.h
  13222. --- busybox-1.20.2.orig//archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
  13223. +++ busybox-1.20.2/archival/libipkg/user.h 2013-01-31 16:44:31.000000000 +0100
  13224. @@ -0,0 +1,23 @@
  13225. +/* user.c - the itsy package management system
  13226. +
  13227. + Jamey Hicks
  13228. +
  13229. + Copyright (C) 2002 Hewlett Packard Company
  13230. + Copyright (C) 2001 University of Southern California
  13231. +
  13232. + This program is free software; you can redistribute it and/or
  13233. + modify it under the terms of the GNU General Public License as
  13234. + published by the Free Software Foundation; either version 2, or (at
  13235. + your option) any later version.
  13236. +
  13237. + This program is distributed in the hope that it will be useful, but
  13238. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13239. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13240. + General Public License for more details.
  13241. +*/
  13242. +
  13243. +#include <stdio.h>
  13244. +#include <stdarg.h>
  13245. +
  13246. +char *get_user_response(const char *format, ...);
  13247. +
  13248. diff -Nur busybox-1.20.2.orig//archival/libipkg/void_list.c busybox-1.20.2/archival/libipkg/void_list.c
  13249. --- busybox-1.20.2.orig//archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
  13250. +++ busybox-1.20.2/archival/libipkg/void_list.c 2013-01-31 16:44:31.000000000 +0100
  13251. @@ -0,0 +1,194 @@
  13252. +/* void_list.c - the itsy package management system
  13253. +
  13254. + Carl D. Worth
  13255. +
  13256. + Copyright (C) 2001 University of Southern California
  13257. +
  13258. + This program is free software; you can redistribute it and/or
  13259. + modify it under the terms of the GNU General Public License as
  13260. + published by the Free Software Foundation; either version 2, or (at
  13261. + your option) any later version.
  13262. +
  13263. + This program is distributed in the hope that it will be useful, but
  13264. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13265. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13266. + General Public License for more details.
  13267. +*/
  13268. +
  13269. +#include "ipkg.h"
  13270. +#include <errno.h>
  13271. +
  13272. +#include "void_list.h"
  13273. +
  13274. +int void_list_elt_init(void_list_elt_t *elt, void *data)
  13275. +{
  13276. + elt->next = NULL;
  13277. + elt->data = data;
  13278. +
  13279. + return 0;
  13280. +}
  13281. +
  13282. +void void_list_elt_deinit(void_list_elt_t *elt)
  13283. +{
  13284. + void_list_elt_init(elt, NULL);
  13285. +}
  13286. +
  13287. +int void_list_init(void_list_t *list)
  13288. +{
  13289. + void_list_elt_init(&list->pre_head, NULL);
  13290. + list->head = NULL;
  13291. + list->pre_head.next = list->head;
  13292. + list->tail = NULL;
  13293. +
  13294. + return 0;
  13295. +}
  13296. +
  13297. +void void_list_deinit(void_list_t *list)
  13298. +{
  13299. + void_list_elt_t *elt;
  13300. +
  13301. + while (list->head) {
  13302. + elt = void_list_pop(list);
  13303. + void_list_elt_deinit(elt);
  13304. + /* malloced in void_list_append */
  13305. + free(elt);
  13306. + }
  13307. +}
  13308. +
  13309. +int void_list_append(void_list_t *list, void *data)
  13310. +{
  13311. + void_list_elt_t *elt;
  13312. +
  13313. + /* freed in void_list_deinit */
  13314. + elt = malloc(sizeof(void_list_elt_t));
  13315. + if (elt == NULL) {
  13316. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13317. + return ENOMEM;
  13318. + }
  13319. +
  13320. + void_list_elt_init(elt, data);
  13321. +
  13322. + if (list->tail) {
  13323. + list->tail->next = elt;
  13324. + list->tail = elt;
  13325. + } else {
  13326. + list->head = elt;
  13327. + list->pre_head.next = list->head;
  13328. + list->tail = elt;
  13329. + }
  13330. +
  13331. + return 0;
  13332. +}
  13333. +
  13334. +int void_list_push(void_list_t *list, void *data)
  13335. +{
  13336. + void_list_elt_t *elt;
  13337. +
  13338. + elt = malloc(sizeof(void_list_elt_t));
  13339. + if (elt == NULL) {
  13340. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13341. + return ENOMEM;
  13342. + }
  13343. +
  13344. + void_list_elt_init(elt, data);
  13345. +
  13346. + elt->next = list->head;
  13347. + list->head->next = elt;
  13348. + if (list->tail == NULL) {
  13349. + list->tail = list->head;
  13350. + }
  13351. +
  13352. + return 0;
  13353. +}
  13354. +
  13355. +void_list_elt_t *void_list_pop(void_list_t *list)
  13356. +{
  13357. + void_list_elt_t *elt;
  13358. +
  13359. + elt = list->head;
  13360. +
  13361. + if (list->head) {
  13362. + list->head = list->head->next;
  13363. + list->pre_head.next = list->head;
  13364. + if (list->head == NULL) {
  13365. + list->tail = NULL;
  13366. + }
  13367. + }
  13368. +
  13369. + return elt;
  13370. +}
  13371. +
  13372. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
  13373. +{
  13374. + void_list_elt_t *prior;
  13375. + void_list_elt_t *old_elt;
  13376. + void *old_data;
  13377. +
  13378. + old_elt = *iter;
  13379. + old_data = old_elt->data;
  13380. +
  13381. + if (old_elt == list->head) {
  13382. + prior = &list->pre_head;
  13383. + void_list_pop(list);
  13384. + } else {
  13385. + for (prior = list->head; prior; prior = prior->next) {
  13386. + if (prior->next == old_elt) {
  13387. + break;
  13388. + }
  13389. + }
  13390. + if (prior == NULL || prior->next != old_elt) {
  13391. + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
  13392. + return NULL;
  13393. + }
  13394. + prior->next = old_elt->next;
  13395. +
  13396. + if (old_elt == list->tail) {
  13397. + list->tail = prior;
  13398. + }
  13399. + }
  13400. +
  13401. + void_list_elt_deinit(old_elt);
  13402. + *iter = prior;
  13403. +
  13404. + return old_data;
  13405. +}
  13406. +
  13407. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13408. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
  13409. +{
  13410. + void_list_elt_t *prior;
  13411. + void_list_elt_t *old_elt = NULL;
  13412. + void *old_data = NULL;
  13413. +
  13414. + /* first element */
  13415. + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
  13416. + old_elt = list->head;
  13417. + old_data = list->head->data;
  13418. + void_list_pop(list);
  13419. + } else {
  13420. + int found = 0;
  13421. + for (prior = list->head; prior && prior->next; prior = prior->next) {
  13422. + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
  13423. + old_elt = prior->next;
  13424. + old_data = old_elt->data;
  13425. + found = 1;
  13426. + break;
  13427. + }
  13428. + }
  13429. + if (!found) {
  13430. + return NULL;
  13431. + }
  13432. + prior->next = old_elt->next;
  13433. +
  13434. + if (old_elt == list->tail) {
  13435. + list->tail = prior;
  13436. + }
  13437. + }
  13438. + if (old_elt)
  13439. + void_list_elt_deinit(old_elt);
  13440. +
  13441. + if (old_data)
  13442. + return old_data;
  13443. + else
  13444. + return NULL;
  13445. +}
  13446. diff -Nur busybox-1.20.2.orig//archival/libipkg/void_list.h busybox-1.20.2/archival/libipkg/void_list.h
  13447. --- busybox-1.20.2.orig//archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
  13448. +++ busybox-1.20.2/archival/libipkg/void_list.h 2013-01-31 16:44:31.000000000 +0100
  13449. @@ -0,0 +1,59 @@
  13450. +/* void_list.h - the itsy package management system
  13451. +
  13452. + Carl D. Worth
  13453. +
  13454. + Copyright (C) 2001 University of Southern California
  13455. +
  13456. + This program is free software; you can redistribute it and/or
  13457. + modify it under the terms of the GNU General Public License as
  13458. + published by the Free Software Foundation; either version 2, or (at
  13459. + your option) any later version.
  13460. +
  13461. + This program is distributed in the hope that it will be useful, but
  13462. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13463. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13464. + General Public License for more details.
  13465. +*/
  13466. +
  13467. +#ifndef VOID_LIST_H
  13468. +#define VOID_LIST_H
  13469. +
  13470. +typedef struct void_list_elt void_list_elt_t;
  13471. +struct void_list_elt
  13472. +{
  13473. + void_list_elt_t *next;
  13474. + void *data;
  13475. +};
  13476. +
  13477. +typedef struct void_list void_list_t;
  13478. +struct void_list
  13479. +{
  13480. + void_list_elt_t pre_head;
  13481. + void_list_elt_t *head;
  13482. + void_list_elt_t *tail;
  13483. +};
  13484. +
  13485. +static inline int void_list_empty(void_list_t *list)
  13486. +{
  13487. + if (list->head == NULL)
  13488. + return 1;
  13489. + else
  13490. + return 0;
  13491. +}
  13492. +
  13493. +int void_list_elt_init(void_list_elt_t *elt, void *data);
  13494. +void void_list_elt_deinit(void_list_elt_t *elt);
  13495. +
  13496. +int void_list_init(void_list_t *list);
  13497. +void void_list_deinit(void_list_t *list);
  13498. +
  13499. +int void_list_append(void_list_t *list, void *data);
  13500. +int void_list_push(void_list_t *list, void *data);
  13501. +void_list_elt_t *void_list_pop(void_list_t *list);
  13502. +
  13503. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
  13504. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13505. +typedef int (*void_list_cmp_t)(const void *, const void *);
  13506. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
  13507. +
  13508. +#endif
  13509. diff -Nur busybox-1.20.2.orig//archival/libipkg/xsystem.c busybox-1.20.2/archival/libipkg/xsystem.c
  13510. --- busybox-1.20.2.orig//archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
  13511. +++ busybox-1.20.2/archival/libipkg/xsystem.c 2013-01-31 16:44:31.000000000 +0100
  13512. @@ -0,0 +1,64 @@
  13513. +/* xsystem.c - system(3) with error messages
  13514. +
  13515. + Carl D. Worth
  13516. +
  13517. + Copyright (C) 2001 University of Southern California
  13518. +
  13519. + This program is free software; you can redistribute it and/or
  13520. + modify it under the terms of the GNU General Public License as
  13521. + published by the Free Software Foundation; either version 2, or (at
  13522. + your option) any later version.
  13523. +
  13524. + This program is distributed in the hope that it will be useful, but
  13525. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13526. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13527. + General Public License for more details.
  13528. +*/
  13529. +
  13530. +#include "ipkg.h"
  13531. +#include <sys/wait.h>
  13532. +
  13533. +#include "xsystem.h"
  13534. +
  13535. +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
  13536. + really need the /bin/sh invocation which takes resources and
  13537. + introduces security problems. I should switch all of this to a sort
  13538. + of execl() or execv() interface/implementation.
  13539. +*/
  13540. +
  13541. +/* Like system(3), but with error messages printed if the fork fails
  13542. + or if the child process dies due to an uncaught signal. Also, the
  13543. + return value is a bit simpler:
  13544. +
  13545. + -1 if there was any problem
  13546. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13547. + as defined in <sys/wait.h>.
  13548. +*/
  13549. +int xsystem(const char *cmd)
  13550. +{
  13551. + int err;
  13552. +
  13553. + err = system(cmd);
  13554. +
  13555. + if (err == -1) {
  13556. + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
  13557. + __FUNCTION__, cmd);
  13558. + return -1;
  13559. + }
  13560. +
  13561. + if (WIFSIGNALED(err)) {
  13562. + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
  13563. + __FUNCTION__, WTERMSIG(err), cmd);
  13564. + return -1;
  13565. + }
  13566. +
  13567. + if (WIFEXITED(err)) {
  13568. + /* Normal child exit */
  13569. + return WEXITSTATUS(err);
  13570. + }
  13571. +
  13572. + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
  13573. + __FUNCTION__, err);
  13574. + return -1;
  13575. +}
  13576. +
  13577. diff -Nur busybox-1.20.2.orig//archival/libipkg/xsystem.h busybox-1.20.2/archival/libipkg/xsystem.h
  13578. --- busybox-1.20.2.orig//archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
  13579. +++ busybox-1.20.2/archival/libipkg/xsystem.h 2013-01-31 16:44:31.000000000 +0100
  13580. @@ -0,0 +1,34 @@
  13581. +/* xsystem.h - system(3) with error messages
  13582. +
  13583. + Carl D. Worth
  13584. +
  13585. + Copyright (C) 2001 University of Southern California
  13586. +
  13587. + This program is free software; you can redistribute it and/or
  13588. + modify it under the terms of the GNU General Public License as
  13589. + published by the Free Software Foundation; either version 2, or (at
  13590. + your option) any later version.
  13591. +
  13592. + This program is distributed in the hope that it will be useful, but
  13593. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13594. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13595. + General Public License for more details.
  13596. +*/
  13597. +
  13598. +#ifndef XSYSTEM_H
  13599. +#define XSYSTEM_H
  13600. +
  13601. +#include <stdlib.h>
  13602. +
  13603. +/* Like system(3), but with error messages printed if the fork fails
  13604. + or if the child process dies due to an uncaught signal. Also, the
  13605. + return value is a bit simpler:
  13606. +
  13607. + -1 if there was any problem
  13608. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13609. + as defined in <sys/wait.h>.
  13610. +*/
  13611. +int xsystem(const char *cmd);
  13612. +
  13613. +#endif
  13614. +
  13615. diff -Nur busybox-1.20.2.orig//include/applets.src.h busybox-1.20.2/include/applets.src.h
  13616. --- busybox-1.20.2.orig//include/applets.src.h 2012-07-02 16:08:25.000000000 +0200
  13617. +++ busybox-1.20.2/include/applets.src.h 2013-01-31 16:44:31.000000000 +0100
  13618. @@ -199,6 +199,7 @@
  13619. IF_IPCALC(APPLET(ipcalc, BB_DIR_BIN, BB_SUID_DROP))
  13620. IF_IPCRM(APPLET(ipcrm, BB_DIR_USR_BIN, BB_SUID_DROP))
  13621. IF_IPCS(APPLET(ipcs, BB_DIR_USR_BIN, BB_SUID_DROP))
  13622. +IF_IPKG(APPLET(ipkg, BB_DIR_USR_BIN, BB_SUID_DROP))
  13623. IF_IPLINK(APPLET(iplink, BB_DIR_BIN, BB_SUID_DROP))
  13624. IF_IPROUTE(APPLET(iproute, BB_DIR_BIN, BB_SUID_DROP))
  13625. IF_IPRULE(APPLET(iprule, BB_DIR_BIN, BB_SUID_DROP))
  13626. diff -Nur busybox-1.20.2.orig//include/bb_archive.h busybox-1.20.2/include/bb_archive.h
  13627. --- busybox-1.20.2.orig//include/bb_archive.h 2012-07-02 16:08:25.000000000 +0200
  13628. +++ busybox-1.20.2/include/bb_archive.h 2013-01-31 16:49:28.000000000 +0100
  13629. @@ -79,7 +79,7 @@
  13630. /* Archiver specific. Can make it a union if it ever gets big */
  13631. #define PAX_NEXT_FILE 0
  13632. #define PAX_GLOBAL 1
  13633. -#if ENABLE_TAR || ENABLE_DPKG || ENABLE_DPKG_DEB
  13634. +#if ENABLE_TAR || ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13635. smallint tar__end;
  13636. # if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
  13637. char* tar__longname;
  13638. @@ -98,7 +98,7 @@
  13639. struct hardlinks_t *cpio__hardlinks_to_create;
  13640. struct hardlinks_t *cpio__created_hardlinks;
  13641. #endif
  13642. -#if ENABLE_DPKG || ENABLE_DPKG_DEB
  13643. +#if ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13644. /* Temporary storage */
  13645. char *dpkg__buffer;
  13646. /* How to process any sub archive, e.g. get_header_tar_gz */
  13647. diff -Nur busybox-1.20.2.orig//include/usage.src.h busybox-1.20.2/include/usage.src.h
  13648. --- busybox-1.20.2.orig//include/usage.src.h 2012-06-26 15:35:45.000000000 +0200
  13649. +++ busybox-1.20.2/include/usage.src.h 2013-01-31 16:44:31.000000000 +0100
  13650. @@ -19,4 +19,80 @@
  13651. #define busybox_notes_usage \
  13652. "Hello world!\n"
  13653. +#define ipkg_trivial_usage \
  13654. + "[options]... sub-command [arguments]..."
  13655. +#define ipkg_full_usage \
  13656. + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
  13657. + "\n" \
  13658. + "Sub-commands:\n" \
  13659. + "\nPackage Manipulation:\n" \
  13660. + "\tupdate Update list of available packages\n" \
  13661. + "\tupgrade Upgrade all installed packages to latest version\n" \
  13662. + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
  13663. + "\tinstall <file.ipk> Install package <file.ipk>\n" \
  13664. + "\tconfigure [<pkg>] Configure unpacked packages\n" \
  13665. + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
  13666. + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
  13667. + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
  13668. + "\n" \
  13669. + "Informational Commands:\n" \
  13670. + "\tlist List available packages and descriptions\n" \
  13671. + "\tlist_installed List all and only the installed packages and description \n" \
  13672. + "\tfiles <pkg> List all files belonging to <pkg>\n" \
  13673. + "\tsearch <file|regexp> Search for a package providing <file>\n" \
  13674. + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
  13675. + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
  13676. + "\tdownload <pkg> Download <pkg> to current directory.\n" \
  13677. + "\tcompare_versions <v1> <op> <v2>\n" \
  13678. + "\t compare versions using <= < > >= = << >>\n" \
  13679. + "\tprint_architecture prints the architecture.\n" \
  13680. + "\tprint_installation_architecture\n" \
  13681. + "\twhatdepends [-A] [pkgname|pat]+\n" \
  13682. + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
  13683. + "\twhatprovides [-A] [pkgname|pat]+\n" \
  13684. + "\twhatconflicts [-A] [pkgname|pat]+\n" \
  13685. + "\twhatreplaces [-A] [pkgname|pat]+\n" \
  13686. + "\t prints the installation architecture.\n" \
  13687. + "\n" \
  13688. + "\nOptions:\n" \
  13689. + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
  13690. + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
  13691. + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
  13692. + "\t 0 errors only\n" \
  13693. + "\t 1 normal messages (default)\n" \
  13694. + "\t 2 informative messages\n" \
  13695. + "\t 3 debug output\n" \
  13696. + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
  13697. + "\t-conf <conf_file> Default configuration file location\n" \
  13698. + " is /etc/ipkg.conf\n" \
  13699. + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
  13700. + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
  13701. + " <dest_name> should be a defined dest name from\n" \
  13702. + " the configuration file, (but can also be a\n" \
  13703. + " directory name in a pinch).\n" \
  13704. + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
  13705. + "\t-offline <offline_root> offline installation of packages.\n" \
  13706. + "\t-verbose_wget more wget messages\n" \
  13707. + "\n" \
  13708. + "Force Options (use when ipkg is too smart for its own good):\n" \
  13709. + "\t-force-depends Make dependency checks warnings instead of errors\n" \
  13710. + "\t Install/remove package in spite of failed dependences\n" \
  13711. + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
  13712. + " (no prompts). Note that this will not prevent\n" \
  13713. + " package installation scripts from prompting.\n" \
  13714. + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
  13715. + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
  13716. + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
  13717. + "\t-force_space Install even if there does not seem to be enough space.\n" \
  13718. + "\t-noaction No action -- test only\n" \
  13719. + "\t-nodeps Do not follow dependences\n" \
  13720. + "\t-force-removal-of-dependent-packages\n" \
  13721. + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
  13722. + "\t-test No action -- test only\n" \
  13723. + "\t-t Specify tmp-dir.\n" \
  13724. + "\t--tmp-dir Specify tmp-dir.\n" \
  13725. + "\n" \
  13726. + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
  13727. + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
  13728. +
  13729. #endif
  13730. diff -Nur busybox-1.20.2.orig//Makefile busybox-1.20.2/Makefile
  13731. --- busybox-1.20.2.orig//Makefile 2012-07-02 16:20:27.000000000 +0200
  13732. +++ busybox-1.20.2/Makefile 2013-01-31 16:44:31.000000000 +0100
  13733. @@ -465,6 +465,7 @@
  13734. libs-y := \
  13735. archival/ \
  13736. archival/libarchive/ \
  13737. + archival/libipkg/ \
  13738. console-tools/ \
  13739. coreutils/ \
  13740. coreutils/libcoreutils/ \