001-ipkg.patch 424 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724
  1. diff -Nur busybox-1.17.0.orig/archival/Config.src busybox-1.17.0/archival/Config.src
  2. --- busybox-1.17.0.orig/archival/Config.src 2010-06-25 01:32:35.000000000 +0200
  3. +++ busybox-1.17.0/archival/Config.src 2010-07-16 14:45:13.629607777 +0200
  4. @@ -202,6 +202,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.17.0.orig/archival/ipkg.c busybox-1.17.0/archival/ipkg.c
  17. --- busybox-1.17.0.orig/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
  18. +++ busybox-1.17.0/archival/ipkg.c 2010-07-16 14:45:13.649608170 +0200
  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.17.0.orig/archival/Kbuild.src busybox-1.17.0/archival/Kbuild.src
  49. --- busybox-1.17.0.orig/archival/Kbuild.src 2010-06-24 04:40:43.000000000 +0200
  50. +++ busybox-1.17.0/archival/Kbuild.src 2010-07-16 14:45:13.706406936 +0200
  51. @@ -23,6 +23,7 @@
  52. lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.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.17.0.orig/archival/libipkg/args.c busybox-1.17.0/archival/libipkg/args.c
  59. --- busybox-1.17.0.orig/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
  60. +++ busybox-1.17.0/archival/libipkg/args.c 2010-07-16 14:45:13.756293745 +0200
  61. @@ -0,0 +1,242 @@
  62. +/* args.c - parse command-line args
  63. +
  64. + Carl D. Worth
  65. +
  66. + Copyright 2001 University of Southern California
  67. +
  68. + This program is free software; you can redistribute it and/or modify
  69. + it under the terms of the GNU General Public License as published by
  70. + the Free Software Foundation; either version 2, or (at your option)
  71. + any later version.
  72. +
  73. + This program is distributed in the hope that it will be useful,
  74. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  75. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  76. + GNU General Public License for more details.
  77. + */
  78. +
  79. +#include <getopt.h>
  80. +#include <stdlib.h>
  81. +#include <string.h>
  82. +#include <unistd.h>
  83. +
  84. +#include "ipkg.h"
  85. +#include "ipkg_message.h"
  86. +
  87. +#include "args.h"
  88. +#include "sprintf_alloc.h"
  89. +
  90. +#include "libbb.h"
  91. +
  92. +
  93. +static void print_version(void);
  94. +
  95. +enum long_args_opt
  96. +{
  97. + ARGS_OPT_FORCE_DEFAULTS = 129,
  98. + ARGS_OPT_FORCE_DEPENDS,
  99. + ARGS_OPT_FORCE_OVERWRITE,
  100. + ARGS_OPT_FORCE_DOWNGRADE,
  101. + ARGS_OPT_FORCE_REINSTALL,
  102. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
  103. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
  104. + ARGS_OPT_FORCE_SPACE,
  105. + ARGS_OPT_NOACTION,
  106. + ARGS_OPT_NODEPS,
  107. + ARGS_OPT_VERBOSE_WGET,
  108. + ARGS_OPT_VERBOSITY,
  109. + ARGS_OPT_MULTIPLE_PROVIDERS
  110. +};
  111. +
  112. +int args_init(args_t *args)
  113. +{
  114. + const char *conf_file_dir;
  115. +
  116. + memset(args, 0, sizeof(args_t));
  117. +
  118. + args->dest = ARGS_DEFAULT_DEST;
  119. +
  120. + conf_file_dir = getenv("IPKG_CONF_DIR");
  121. + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
  122. + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
  123. + }
  124. + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
  125. + ARGS_DEFAULT_CONF_FILE_NAME);
  126. +
  127. + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
  128. + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
  129. + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
  130. + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
  131. + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
  132. + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
  133. + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
  134. + args->noaction = ARGS_DEFAULT_NOACTION;
  135. + args->nodeps = ARGS_DEFAULT_NODEPS;
  136. + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
  137. + args->verbosity = ARGS_DEFAULT_VERBOSITY;
  138. + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
  139. + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
  140. + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
  141. + args->multiple_providers = 0;
  142. + args->nocheckfordirorfile = 0;
  143. + args->noreadfeedsfile = 0;
  144. +
  145. + return 1;
  146. +}
  147. +
  148. +void args_deinit(args_t *args)
  149. +{
  150. + free(args->conf_file);
  151. + args->conf_file = NULL;
  152. +}
  153. +
  154. +int args_parse(args_t *args, int argc, char *argv[])
  155. +{
  156. + int c;
  157. + int option_index = 0;
  158. + int parse_err = 0;
  159. + static struct option long_options[] = {
  160. + {"query-all", 0, 0, 'A'},
  161. + {"conf-file", 1, 0, 'f'},
  162. + {"conf", 1, 0, 'f'},
  163. + {"dest", 1, 0, 'd'},
  164. + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  165. + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  166. + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  167. + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  168. + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  169. + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  170. + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  171. + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  172. + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  173. + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  174. + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
  175. + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
  176. + {"recursive", 0, 0,
  177. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  178. + {"force-removal-of-dependent-packages", 0, 0,
  179. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  180. + {"force_removal_of_dependent_packages", 0, 0,
  181. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  182. + {"force-removal-of-essential-packages", 0, 0,
  183. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  184. + {"force_removal_of_essential_packages", 0, 0,
  185. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  186. + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  187. + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  188. + {"noaction", 0, 0, ARGS_OPT_NOACTION},
  189. + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
  190. + {"offline", 1, 0, 'o'},
  191. + {"offline-root", 1, 0, 'o'},
  192. + {"test", 0, 0, ARGS_OPT_NOACTION},
  193. + {"tmp-dir", 1, 0, 't'},
  194. + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  195. + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  196. + {"verbosity", 2, 0, 'V'},
  197. + {"version", 0, 0, 'v'},
  198. + {0, 0, 0, 0}
  199. + };
  200. +
  201. + while (1) {
  202. + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
  203. + if (c == -1)
  204. + break;
  205. +
  206. + switch (c) {
  207. + case 'A':
  208. + args->query_all = 1;
  209. + break;
  210. + case 'd':
  211. + args->dest = optarg;
  212. + break;
  213. + case 'f':
  214. + free(args->conf_file);
  215. + args->conf_file = strdup(optarg);
  216. + break;
  217. + case 'o':
  218. + args->offline_root = optarg;
  219. + break;
  220. + case 'n':
  221. + args->noaction = 1;
  222. + break;
  223. + case 't':
  224. + args->tmp_dir = strdup(optarg);
  225. + break;
  226. + case 'v':
  227. + print_version();
  228. + exit(0);
  229. + case 'V':
  230. + case ARGS_OPT_VERBOSITY:
  231. + if (optarg)
  232. + args->verbosity = atoi(optarg);
  233. + else
  234. + args->verbosity += 1;
  235. + break;
  236. + case ARGS_OPT_FORCE_DEFAULTS:
  237. + args->force_defaults = 1;
  238. + break;
  239. + case ARGS_OPT_FORCE_DEPENDS:
  240. + args->force_depends = 1;
  241. + break;
  242. + case ARGS_OPT_FORCE_OVERWRITE:
  243. + args->force_overwrite = 1;
  244. + break;
  245. + case ARGS_OPT_FORCE_DOWNGRADE:
  246. + args->force_downgrade = 1;
  247. + break;
  248. + case ARGS_OPT_FORCE_REINSTALL:
  249. + args->force_reinstall = 1;
  250. + break;
  251. + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
  252. + args->force_removal_of_essential_packages = 1;
  253. + break;
  254. + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
  255. + args->force_removal_of_dependent_packages = 1;
  256. + break;
  257. + case ARGS_OPT_FORCE_SPACE:
  258. + args->force_space = 1;
  259. + break;
  260. + case ARGS_OPT_VERBOSE_WGET:
  261. + args->verbose_wget = 1;
  262. + break;
  263. + case ARGS_OPT_MULTIPLE_PROVIDERS:
  264. + args->multiple_providers = 1;
  265. + break;
  266. + case ARGS_OPT_NODEPS:
  267. + args->nodeps = 1;
  268. + break;
  269. + case ARGS_OPT_NOACTION:
  270. + args->noaction = 1;
  271. + break;
  272. + case ':':
  273. + parse_err++;
  274. + break;
  275. + case '?':
  276. + parse_err++;
  277. + break;
  278. + default:
  279. + bb_error_msg("Confusion: getopt_long returned %d\n", c);
  280. + }
  281. + }
  282. +
  283. + if (parse_err) {
  284. + return -parse_err;
  285. + } else {
  286. + return optind;
  287. + }
  288. +}
  289. +
  290. +void args_usage(const char *complaint)
  291. +{
  292. + if (complaint) {
  293. + bb_error_msg("%s\n", complaint);
  294. + }
  295. + print_version();
  296. + bb_show_usage();
  297. + exit(1);
  298. +}
  299. +
  300. +static void print_version(void)
  301. +{
  302. + bb_error_msg("version %s\n", IPKG_VERSION);
  303. +}
  304. diff -Nur busybox-1.17.0.orig/archival/libipkg/args.h busybox-1.17.0/archival/libipkg/args.h
  305. --- busybox-1.17.0.orig/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
  306. +++ busybox-1.17.0/archival/libipkg/args.h 2010-07-16 14:45:13.816520862 +0200
  307. @@ -0,0 +1,72 @@
  308. +/* args.h - parse command-line args
  309. +
  310. + Carl D. Worth
  311. +
  312. + Copyright 2001 University of Southern California
  313. +
  314. + This program is free software; you can redistribute it and/or modify
  315. + it under the terms of the GNU General Public License as published by
  316. + the Free Software Foundation; either version 2, or (at your option)
  317. + any later version.
  318. +
  319. + This program is distributed in the hope that it will be useful,
  320. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  321. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  322. + GNU General Public License for more details.
  323. +*/
  324. +
  325. +#ifndef ARGS_H
  326. +#define ARGS_H
  327. +
  328. +struct args
  329. +{
  330. + char *conf_file;
  331. + char *dest;
  332. + char *tmp_dir;
  333. + int force_defaults;
  334. + int force_depends;
  335. + int force_overwrite;
  336. + int force_downgrade;
  337. + int force_reinstall;
  338. + int force_removal_of_essential_packages;
  339. + int force_removal_of_dependent_packages;
  340. + int force_space;
  341. + int noaction;
  342. + int nodeps;
  343. + int multiple_providers;
  344. + int query_all;
  345. + int verbose_wget;
  346. + int verbosity;
  347. + int nocheckfordirorfile;
  348. + int noreadfeedsfile;
  349. + char *offline_root;
  350. + char *offline_root_pre_script_cmd;
  351. + char *offline_root_post_script_cmd;
  352. +};
  353. +typedef struct args args_t;
  354. +
  355. +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
  356. +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
  357. +#define ARGS_DEFAULT_DEST NULL
  358. +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
  359. +#define ARGS_DEFAULT_FORCE_DEPENDS 0
  360. +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
  361. +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
  362. +#define ARGS_DEFAULT_FORCE_REINSTALL 0
  363. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
  364. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
  365. +#define ARGS_DEFAULT_FORCE_SPACE 0
  366. +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
  367. +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
  368. +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
  369. +#define ARGS_DEFAULT_NOACTION 0
  370. +#define ARGS_DEFAULT_NODEPS 0
  371. +#define ARGS_DEFAULT_VERBOSE_WGET 0
  372. +#define ARGS_DEFAULT_VERBOSITY 1
  373. +
  374. +int args_init(args_t *args);
  375. +void args_deinit(args_t *args);
  376. +int args_parse(args_t *args, int argc, char *argv[]);
  377. +void args_usage(const char *complaint);
  378. +
  379. +#endif
  380. diff -Nur busybox-1.17.0.orig/archival/libipkg/conffile.c busybox-1.17.0/archival/libipkg/conffile.c
  381. --- busybox-1.17.0.orig/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
  382. +++ busybox-1.17.0/archival/libipkg/conffile.c 2010-07-16 14:45:13.886566803 +0200
  383. @@ -0,0 +1,65 @@
  384. +/* conffile.c - the itsy package management system
  385. +
  386. + Carl D. Worth
  387. +
  388. + Copyright (C) 2001 University of Southern California
  389. +
  390. + This program is free software; you can redistribute it and/or
  391. + modify it under the terms of the GNU General Public License as
  392. + published by the Free Software Foundation; either version 2, or (at
  393. + your option) any later version.
  394. +
  395. + This program is distributed in the hope that it will be useful, but
  396. + WITHOUT ANY WARRANTY; without even the implied warranty of
  397. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  398. + General Public License for more details.
  399. +*/
  400. +
  401. +#include <string.h>
  402. +#include <stdlib.h>
  403. +
  404. +#include "libbb.h"
  405. +#include "ipkg.h"
  406. +#include "ipkg_message.h"
  407. +
  408. +#include "conffile.h"
  409. +#include "file_util.h"
  410. +#include "sprintf_alloc.h"
  411. +
  412. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum)
  413. +{
  414. + return nv_pair_init(conffile, file_name, (char *)md5sum);
  415. +}
  416. +
  417. +void conffile_deinit(conffile_t *conffile)
  418. +{
  419. + nv_pair_deinit(conffile);
  420. +}
  421. +
  422. +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
  423. +{
  424. + uint8_t *md5sum;
  425. + char *filename = conffile->name;
  426. + char *root_filename;
  427. + int ret;
  428. +
  429. + if (conffile->value == NULL) {
  430. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
  431. + return 1;
  432. + }
  433. +
  434. + root_filename = root_filename_alloc(conf, filename);
  435. +
  436. + md5sum = file_md5sum_alloc(root_filename);
  437. +
  438. + ret = strcmp((char *)md5sum, conffile->value);
  439. + if (ret) {
  440. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
  441. + conffile->name, md5sum, conffile->value);
  442. + }
  443. +
  444. + free(root_filename);
  445. + free(md5sum);
  446. +
  447. + return ret;
  448. +}
  449. diff -Nur busybox-1.17.0.orig/archival/libipkg/conffile.h busybox-1.17.0/archival/libipkg/conffile.h
  450. --- busybox-1.17.0.orig/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
  451. +++ busybox-1.17.0/archival/libipkg/conffile.h 2010-07-16 14:45:13.956241799 +0200
  452. @@ -0,0 +1,30 @@
  453. +/* conffile.h - the itsy package management system
  454. +
  455. + Carl D. Worth
  456. +
  457. + Copyright (C) 2001 University of Southern California
  458. +
  459. + This program is free software; you can redistribute it and/or
  460. + modify it under the terms of the GNU General Public License as
  461. + published by the Free Software Foundation; either version 2, or (at
  462. + your option) any later version.
  463. +
  464. + This program is distributed in the hope that it will be useful, but
  465. + WITHOUT ANY WARRANTY; without even the implied warranty of
  466. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  467. + General Public License for more details.
  468. +*/
  469. +
  470. +#ifndef CONFFILE_H
  471. +#define CONFFILE_H
  472. +
  473. +#include "nv_pair.h"
  474. +
  475. +typedef struct nv_pair conffile_t;
  476. +
  477. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum);
  478. +void conffile_deinit(conffile_t *conffile);
  479. +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
  480. +
  481. +#endif
  482. +
  483. diff -Nur busybox-1.17.0.orig/archival/libipkg/conffile_list.c busybox-1.17.0/archival/libipkg/conffile_list.c
  484. --- busybox-1.17.0.orig/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
  485. +++ busybox-1.17.0/archival/libipkg/conffile_list.c 2010-07-16 14:45:14.005935364 +0200
  486. @@ -0,0 +1,47 @@
  487. +/* conffile_list.c - the itsy package management system
  488. +
  489. + Carl D. Worth
  490. +
  491. + Copyright (C) 2001 University of Southern California
  492. +
  493. + This program is free software; you can redistribute it and/or
  494. + modify it under the terms of the GNU General Public License as
  495. + published by the Free Software Foundation; either version 2, or (at
  496. + your option) any later version.
  497. +
  498. + This program is distributed in the hope that it will be useful, but
  499. + WITHOUT ANY WARRANTY; without even the implied warranty of
  500. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  501. + General Public License for more details.
  502. +*/
  503. +
  504. +#include "ipkg.h"
  505. +
  506. +#include "conffile_list.h"
  507. +
  508. +int conffile_list_init(conffile_list_t *list)
  509. +{
  510. + return nv_pair_list_init(list);
  511. +}
  512. +
  513. +void conffile_list_deinit(conffile_list_t *list)
  514. +{
  515. + nv_pair_list_deinit(list);
  516. +}
  517. +
  518. +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
  519. + const char *md5sum)
  520. +{
  521. + return nv_pair_list_append(list, file_name, md5sum);
  522. +}
  523. +
  524. +int conffile_list_push(conffile_list_t *list, conffile_t *data)
  525. +{
  526. + return nv_pair_list_push(list, data);
  527. +}
  528. +
  529. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
  530. +{
  531. + return nv_pair_list_pop(list);
  532. +}
  533. +
  534. diff -Nur busybox-1.17.0.orig/archival/libipkg/conffile_list.h busybox-1.17.0/archival/libipkg/conffile_list.h
  535. --- busybox-1.17.0.orig/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
  536. +++ busybox-1.17.0/archival/libipkg/conffile_list.h 2010-07-16 14:45:14.066487403 +0200
  537. @@ -0,0 +1,36 @@
  538. +/* conffile_list.h - the itsy package management system
  539. +
  540. + Carl D. Worth
  541. +
  542. + Copyright (C) 2001 University of Southern California
  543. +
  544. + This program is free software; you can redistribute it and/or
  545. + modify it under the terms of the GNU General Public License as
  546. + published by the Free Software Foundation; either version 2, or (at
  547. + your option) any later version.
  548. +
  549. + This program is distributed in the hope that it will be useful, but
  550. + WITHOUT ANY WARRANTY; without even the implied warranty of
  551. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  552. + General Public License for more details.
  553. +*/
  554. +
  555. +#ifndef CONFFILE_LIST_H
  556. +#define CONFFILE_LIST_H
  557. +
  558. +#include "conffile.h"
  559. +#include "nv_pair_list.h"
  560. +
  561. +typedef struct nv_pair_list_elt conffile_list_elt_t;
  562. +typedef struct nv_pair_list conffile_list_t;
  563. +
  564. +int conffile_list_init(conffile_list_t *list);
  565. +void conffile_list_deinit(conffile_list_t *list);
  566. +
  567. +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
  568. + const char *root_dir);
  569. +int conffile_list_push(conffile_list_t *list, conffile_t *data);
  570. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
  571. +
  572. +#endif
  573. +
  574. diff -Nur busybox-1.17.0.orig/archival/libipkg/file_util.c busybox-1.17.0/archival/libipkg/file_util.c
  575. --- busybox-1.17.0.orig/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
  576. +++ busybox-1.17.0/archival/libipkg/file_util.c 2010-07-16 14:45:14.116380621 +0200
  577. @@ -0,0 +1,186 @@
  578. +/* file_util.c - convenience routines for common stat operations
  579. +
  580. + Carl D. Worth
  581. +
  582. + Copyright (C) 2001 University of Southern California
  583. +
  584. + This program is free software; you can redistribute it and/or
  585. + modify it under the terms of the GNU General Public License as
  586. + published by the Free Software Foundation; either version 2, or (at
  587. + your option) any later version.
  588. +
  589. + This program is distributed in the hope that it will be useful, but
  590. + WITHOUT ANY WARRANTY; without even the implied warranty of
  591. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  592. + General Public License for more details.
  593. +*/
  594. +
  595. +#include "ipkg.h"
  596. +#include <sys/types.h>
  597. +#include <sys/stat.h>
  598. +
  599. +#include "sprintf_alloc.h"
  600. +#include "file_util.h"
  601. +#include "libbb.h"
  602. +#undef strlen
  603. +
  604. +int file_exists(const char *file_name)
  605. +{
  606. + int err;
  607. + struct stat stat_buf;
  608. +
  609. + err = stat(file_name, &stat_buf);
  610. + if (err == 0) {
  611. + return 1;
  612. + } else {
  613. + return 0;
  614. + }
  615. +}
  616. +
  617. +int file_is_dir(const char *file_name)
  618. +{
  619. + int err;
  620. + struct stat stat_buf;
  621. +
  622. + err = stat(file_name, &stat_buf);
  623. + if (err) {
  624. + return 0;
  625. + }
  626. +
  627. + return S_ISDIR(stat_buf.st_mode);
  628. +}
  629. +
  630. +/* read a single line from a file, stopping at a newline or EOF.
  631. + If a newline is read, it will appear in the resulting string.
  632. + Return value is a malloc'ed char * which should be freed at
  633. + some point by the caller.
  634. +
  635. + Return value is NULL if the file is at EOF when called.
  636. +*/
  637. +#define FILE_READ_LINE_BUF_SIZE 1024
  638. +char *file_read_line_alloc(FILE *file)
  639. +{
  640. + char buf[FILE_READ_LINE_BUF_SIZE];
  641. + int buf_len;
  642. + char *line = NULL;
  643. + int line_size = 0;
  644. +
  645. + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
  646. + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
  647. + buf_len = strlen(buf);
  648. + if (line) {
  649. + line_size += buf_len;
  650. + line = realloc(line, line_size);
  651. + if (line == NULL) {
  652. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  653. + break;
  654. + }
  655. + strcat(line, buf);
  656. + } else {
  657. + line_size = buf_len + 1;
  658. + line = strdup(buf);
  659. + }
  660. + if (buf[buf_len - 1] == '\n') {
  661. + break;
  662. + }
  663. + }
  664. +
  665. + return line;
  666. +}
  667. +
  668. +int file_move(const char *src, const char *dest)
  669. +{
  670. + int err;
  671. +
  672. + err = rename(src, dest);
  673. +
  674. + if (err && errno == EXDEV) {
  675. + err = file_copy(src, dest);
  676. + unlink(src);
  677. + } else if (err) {
  678. + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
  679. + __FUNCTION__, src, dest, strerror(errno));
  680. + }
  681. +
  682. + return err;
  683. +}
  684. +
  685. +/* I put these here to keep libbb dependencies from creeping all over
  686. + the ipkg code */
  687. +int file_copy(const char *src, const char *dest)
  688. +{
  689. + int err;
  690. +
  691. + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
  692. + if (err) {
  693. + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
  694. + __FUNCTION__, src, dest);
  695. + }
  696. +
  697. + return err;
  698. +}
  699. +
  700. +int file_mkdir_hier(char *path, long mode)
  701. +{
  702. + return bb_make_directory(path, mode, FILEUTILS_RECUR);
  703. +}
  704. +
  705. +static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
  706. + unsigned hash_length)
  707. +{
  708. + /* xzalloc zero-terminates */
  709. + char *hex_value = xzalloc((hash_length * 2) + 1);
  710. + bin2hex(hex_value, (char*)hash_value, hash_length);
  711. + return (unsigned char *)hex_value;
  712. +}
  713. +
  714. +static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
  715. +{
  716. + int src_fd, hash_len, count;
  717. + union _ctx_ {
  718. + sha1_ctx_t sha1;
  719. + md5_ctx_t md5;
  720. + } context;
  721. + uint8_t *hash_value = NULL;
  722. + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
  723. + void FAST_FUNC (*update)(const void*, size_t, void*);
  724. + void FAST_FUNC (*final)(void*, void*);
  725. +
  726. + src_fd = open_or_warn_stdin(filename);
  727. + if (src_fd < 0) {
  728. + return NULL;
  729. + }
  730. +
  731. + /* figure specific hash algorithims */
  732. + if (ENABLE_MD5SUM && hash_algo == HASH_MD5) {
  733. + md5_begin(&context.md5);
  734. + update = (void*)md5_hash;
  735. + final = (void*)md5_end;
  736. + hash_len = 16;
  737. + } else {
  738. + bb_error_msg_and_die("algorithm not supported");
  739. + }
  740. +
  741. + while (0 < (count = safe_read(src_fd, in_buf, 4096))) {
  742. + update(in_buf, count, &context);
  743. + }
  744. +
  745. + if (count == 0) {
  746. + final(in_buf, &context);
  747. + hash_value = hash_bin_to_hex(in_buf, hash_len);
  748. + }
  749. +
  750. + RELEASE_CONFIG_BUFFER(in_buf);
  751. +
  752. + if (src_fd != STDIN_FILENO) {
  753. + close(src_fd);
  754. + }
  755. +
  756. + return hash_value;
  757. +}
  758. +
  759. +uint8_t *file_md5sum_alloc(const char *file_name)
  760. +{
  761. + return hash_file(file_name, HASH_MD5);
  762. +}
  763. +
  764. diff -Nur busybox-1.17.0.orig/archival/libipkg/file_util.h busybox-1.17.0/archival/libipkg/file_util.h
  765. --- busybox-1.17.0.orig/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
  766. +++ busybox-1.17.0/archival/libipkg/file_util.h 2010-07-16 14:45:14.166369529 +0200
  767. @@ -0,0 +1,29 @@
  768. +/* file_util.h - convenience routines for common file operations
  769. +
  770. + Carl D. Worth
  771. +
  772. + Copyright (C) 2001 University of Southern California
  773. +
  774. + This program is free software; you can redistribute it and/or
  775. + modify it under the terms of the GNU General Public License as
  776. + published by the Free Software Foundation; either version 2, or (at
  777. + your option) any later version.
  778. +
  779. + This program is distributed in the hope that it will be useful, but
  780. + WITHOUT ANY WARRANTY; without even the implied warranty of
  781. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  782. + General Public License for more details.
  783. +*/
  784. +
  785. +#ifndef FILE_UTIL_H
  786. +#define FILE_UTIL_H
  787. +
  788. +int file_exists(const char *file_name);
  789. +int file_is_dir(const char *file_name);
  790. +char *file_read_line_alloc(FILE *file);
  791. +int file_move(const char *src, const char *dest);
  792. +int file_copy(const char *src, const char *dest);
  793. +int file_mkdir_hier(char *path, long mode);
  794. +uint8_t *file_md5sum_alloc(const char *file_name);
  795. +
  796. +#endif
  797. diff -Nur busybox-1.17.0.orig/archival/libipkg/hash_table.c busybox-1.17.0/archival/libipkg/hash_table.c
  798. --- busybox-1.17.0.orig/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
  799. +++ busybox-1.17.0/archival/libipkg/hash_table.c 2010-07-16 14:45:14.226462120 +0200
  800. @@ -0,0 +1,155 @@
  801. +/* hash.c - hash tables for ipkg
  802. +
  803. + Steven M. Ayer, Jamey Hicks
  804. +
  805. + Copyright (C) 2002 Compaq Computer Corporation
  806. +
  807. + This program is free software; you can redistribute it and/or
  808. + modify it under the terms of the GNU General Public License as
  809. + published by the Free Software Foundation; either version 2, or (at
  810. + your option) any later version.
  811. +
  812. + This program is distributed in the hope that it will be useful, but
  813. + WITHOUT ANY WARRANTY; without even the implied warranty of
  814. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  815. + General Public License for more details.
  816. +*/
  817. +
  818. +#include <errno.h>
  819. +#include <stdio.h>
  820. +#include <stdlib.h>
  821. +#include <string.h>
  822. +#include "hash_table.h"
  823. +#include "ipkg_message.h"
  824. +
  825. +
  826. +static int hash_index(hash_table_t *hash, const char *pkg_name);
  827. +static int rotating(const char *key, int len, int prime);
  828. +
  829. +static int hash_index(hash_table_t *hash, const char *pkg_name)
  830. +{
  831. + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
  832. +}
  833. +
  834. +static int rotating(const char *key, int len, int prime)
  835. +{
  836. + unsigned int hash, i;
  837. + for (hash=len, i=0; i<len; ++i)
  838. + hash = (hash<<4)^(hash>>28)^key[i];
  839. + return (hash % prime);
  840. +}
  841. +
  842. +
  843. +/*
  844. + * this is an open table keyed by strings
  845. + */
  846. +int hash_table_init(const char *name, hash_table_t *hash, int len)
  847. +{
  848. + static int primes_table[] = {
  849. + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
  850. + 19471, 23143, 33961, 46499, 49727, 99529, 0
  851. + };
  852. + int *picker;
  853. +
  854. + if (hash->entries != NULL) {
  855. + /* we have been here already */
  856. + return 0;
  857. + }
  858. +
  859. + hash->name = name;
  860. + hash->entries = NULL;
  861. + hash->n_entries = 0;
  862. + hash->hash_entry_key = NULL;
  863. +
  864. + picker = primes_table;
  865. + while(*picker && (*picker++ < len));
  866. + if(!*picker)
  867. + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
  868. + --picker;
  869. +
  870. + hash->n_entries = *picker;
  871. + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
  872. + if (hash->entries == NULL) {
  873. + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
  874. + return ENOMEM;
  875. + }
  876. + return 0;
  877. +}
  878. +
  879. +void hash_table_deinit(hash_table_t *hash)
  880. +{
  881. + free(hash->entries);
  882. + hash->entries = NULL;
  883. + hash->n_entries = 0;
  884. +}
  885. +
  886. +void *hash_table_get(hash_table_t *hash, const char *key)
  887. +{
  888. + int ndx= hash_index(hash, key);
  889. + hash_entry_t *hash_entry = hash->entries + ndx;
  890. + while (hash_entry)
  891. + {
  892. + if (hash_entry->key)
  893. + {
  894. + if (strcmp(key, hash_entry->key) == 0) {
  895. + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
  896. + return hash_entry->data;
  897. + }
  898. + }
  899. + hash_entry = hash_entry->next;
  900. + }
  901. + return NULL;
  902. +}
  903. +
  904. +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
  905. +{
  906. + int ndx= hash_index(hash, key);
  907. + hash_entry_t *hash_entry = hash->entries + ndx;
  908. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
  909. + if (hash_entry->key) {
  910. + if (strcmp(hash_entry->key, key) == 0) {
  911. + /* alread in table, update the value */
  912. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
  913. + hash_entry->data = value;
  914. + return 0;
  915. + } else {
  916. + /*
  917. + * if this is a collision, we have to go to the end of the ll,
  918. + * then add a new entry
  919. + * before we can hook up the value
  920. + */
  921. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
  922. + while (hash_entry->next)
  923. + hash_entry = hash_entry->next;
  924. + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
  925. + if (!hash_entry->next) {
  926. + return -ENOMEM;
  927. + }
  928. + hash_entry = hash_entry->next;
  929. + hash_entry->next = NULL;
  930. + }
  931. + }
  932. + hash->n_elements++;
  933. + hash_entry->key = strdup(key);
  934. + hash_entry->data = value;
  935. +
  936. + return 0;
  937. +}
  938. +
  939. +
  940. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
  941. +{
  942. + int i;
  943. + if (!hash || !f)
  944. + return;
  945. +
  946. + for (i = 0; i < hash->n_entries; i++) {
  947. + hash_entry_t *hash_entry = (hash->entries + i);
  948. + do {
  949. + if(hash_entry->key) {
  950. + f(hash_entry->key, hash_entry->data, data);
  951. + }
  952. + } while((hash_entry = hash_entry->next));
  953. + }
  954. +}
  955. +
  956. diff -Nur busybox-1.17.0.orig/archival/libipkg/hash_table.h busybox-1.17.0/archival/libipkg/hash_table.h
  957. --- busybox-1.17.0.orig/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
  958. +++ busybox-1.17.0/archival/libipkg/hash_table.h 2010-07-16 14:45:14.296312488 +0200
  959. @@ -0,0 +1,44 @@
  960. +/* hash.h - hash tables for ipkg
  961. +
  962. + Steven M. Ayer, Jamey Hicks
  963. +
  964. + Copyright (C) 2002 Compaq Computer Corporation
  965. +
  966. + This program is free software; you can redistribute it and/or
  967. + modify it under the terms of the GNU General Public License as
  968. + published by the Free Software Foundation; either version 2, or (at
  969. + your option) any later version.
  970. +
  971. + This program is distributed in the hope that it will be useful, but
  972. + WITHOUT ANY WARRANTY; without even the implied warranty of
  973. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  974. + General Public License for more details.
  975. +*/
  976. +
  977. +#ifndef _HASH_TABLE_H_
  978. +#define _HASH_TABLE_H_
  979. +
  980. +typedef struct hash_entry hash_entry_t;
  981. +typedef struct hash_table hash_table_t;
  982. +
  983. +struct hash_entry {
  984. + const char * key;
  985. + void * data;
  986. + struct hash_entry * next;
  987. +};
  988. +
  989. +struct hash_table {
  990. + const char *name;
  991. + hash_entry_t * entries;
  992. + int n_entries; /* number of buckets */
  993. + int n_elements;
  994. + const char * (*hash_entry_key)(void * data);
  995. +};
  996. +
  997. +int hash_table_init(const char *name, hash_table_t *hash, int len);
  998. +void hash_table_deinit(hash_table_t *hash);
  999. +void *hash_table_get(hash_table_t *hash, const char *key);
  1000. +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
  1001. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
  1002. +
  1003. +#endif /* _HASH_TABLE_H_ */
  1004. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_cmd.c busybox-1.17.0/archival/libipkg/ipkg_cmd.c
  1005. --- busybox-1.17.0.orig/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
  1006. +++ busybox-1.17.0/archival/libipkg/ipkg_cmd.c 2010-07-16 14:45:14.346253334 +0200
  1007. @@ -0,0 +1,1366 @@
  1008. +/* ipkg_cmd.c - the itsy package management system
  1009. +
  1010. + Carl D. Worth
  1011. +
  1012. + Copyright (C) 2001 University of Southern California
  1013. +
  1014. + This program is free software; you can redistribute it and/or
  1015. + modify it under the terms of the GNU General Public License as
  1016. + published by the Free Software Foundation; either version 2, or (at
  1017. + your option) any later version.
  1018. +
  1019. + This program is distributed in the hope that it will be useful, but
  1020. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1021. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1022. + General Public License for more details.
  1023. +*/
  1024. +
  1025. +#include <string.h>
  1026. +
  1027. +#include "ipkg.h"
  1028. +#include <libgen.h>
  1029. +#include <glob.h>
  1030. +#include <errno.h>
  1031. +#include <stdlib.h>
  1032. +#include <unistd.h>
  1033. +#include <signal.h>
  1034. +#include <stdio.h>
  1035. +#include <dirent.h>
  1036. +
  1037. +#include "ipkg_conf.h"
  1038. +#include "ipkg_cmd.h"
  1039. +#include "ipkg_message.h"
  1040. +#include "pkg.h"
  1041. +#include "pkg_dest.h"
  1042. +#include "pkg_parse.h"
  1043. +#include "sprintf_alloc.h"
  1044. +#include "pkg.h"
  1045. +#include "file_util.h"
  1046. +#include "str_util.h"
  1047. +#include "unarchive.h"
  1048. +
  1049. +#include <fnmatch.h>
  1050. +
  1051. +
  1052. +#include "ipkg_download.h"
  1053. +#include "ipkg_install.h"
  1054. +#include "ipkg_upgrade.h"
  1055. +#include "ipkg_remove.h"
  1056. +#include "ipkg_configure.h"
  1057. +#include "ipkg_message.h"
  1058. +
  1059. +#include "libipkg.h"
  1060. +static void *p_userdata = NULL;
  1061. +
  1062. +static int ipkg_update_cmd(ipkg_conf_t *conf);
  1063. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1064. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1065. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1066. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1067. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf);
  1068. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1069. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1070. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1071. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1072. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1073. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1074. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1075. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1076. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1077. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1078. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1079. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1080. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1081. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1082. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1083. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1084. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1085. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf);
  1086. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1087. +
  1088. +/* XXX: CLEANUP: The usage strings should be incorporated into this
  1089. + array for easier maintenance */
  1090. +static ipkg_cmd_t cmds[] = {
  1091. + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
  1092. + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
  1093. + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
  1094. + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
  1095. + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
  1096. + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
  1097. + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
  1098. + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
  1099. + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
  1100. + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
  1101. + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
  1102. + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
  1103. + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
  1104. + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
  1105. + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
  1106. + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1107. + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1108. + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1109. + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1110. + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1111. + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1112. + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
  1113. + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
  1114. + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
  1115. + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
  1116. + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
  1117. + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
  1118. + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
  1119. + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
  1120. +};
  1121. +
  1122. +int ipkg_state_changed;
  1123. +static void write_status_files_if_changed(ipkg_conf_t *conf)
  1124. +{
  1125. + if (ipkg_state_changed && !conf->noaction) {
  1126. + ipkg_message(conf, IPKG_INFO,
  1127. + " writing status file\n");
  1128. + ipkg_conf_write_status_files(conf);
  1129. + pkg_write_changed_filelists(conf);
  1130. + } else {
  1131. + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
  1132. + }
  1133. +}
  1134. +
  1135. +
  1136. +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
  1137. +
  1138. +ipkg_cmd_t *ipkg_cmd_find(const char *name)
  1139. +{
  1140. + int i;
  1141. + ipkg_cmd_t *cmd;
  1142. +
  1143. + for (i=0; i < num_cmds; i++) {
  1144. + cmd = &cmds[i];
  1145. + if (strcmp(name, cmd->name) == 0) {
  1146. + return cmd;
  1147. + }
  1148. + }
  1149. +
  1150. + return NULL;
  1151. +}
  1152. +
  1153. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
  1154. +{
  1155. + int result;
  1156. + p_userdata = userdata;
  1157. +
  1158. +
  1159. + result = (cmd->fun)(conf, argc, argv);
  1160. + if ( result == 0 ) {
  1161. + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
  1162. + } else {
  1163. + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
  1164. +
  1165. + }
  1166. + if ( error_list ) {
  1167. + reverse_error_list(&error_list);
  1168. +
  1169. + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
  1170. + /* Here we print the errors collected and free the list */
  1171. + while (error_list != NULL) {
  1172. + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
  1173. + error_list = error_list->next;
  1174. +
  1175. + }
  1176. + free_error_list(&error_list);
  1177. +
  1178. + }
  1179. +
  1180. + p_userdata = NULL;
  1181. + return result;
  1182. +}
  1183. +
  1184. +static int ipkg_update_cmd(ipkg_conf_t *conf)
  1185. +{
  1186. + int err;
  1187. + int failures;
  1188. + char *lists_dir;
  1189. + pkg_src_list_elt_t *iter;
  1190. + pkg_src_t *src;
  1191. +
  1192. +
  1193. + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
  1194. +
  1195. + if (! file_is_dir(lists_dir)) {
  1196. + if (file_exists(lists_dir)) {
  1197. + ipkg_message(conf, IPKG_ERROR,
  1198. + "%s: ERROR: %s exists, but is not a directory\n",
  1199. + __FUNCTION__, lists_dir);
  1200. + free(lists_dir);
  1201. + return EINVAL;
  1202. + }
  1203. + err = file_mkdir_hier(lists_dir, 0755);
  1204. + if (err) {
  1205. + ipkg_message(conf, IPKG_ERROR,
  1206. + "%s: ERROR: failed to make directory %s: %s\n",
  1207. + __FUNCTION__, lists_dir, strerror(errno));
  1208. + free(lists_dir);
  1209. + return EINVAL;
  1210. + }
  1211. + }
  1212. +
  1213. + failures = 0;
  1214. + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
  1215. + char *url, *list_file_name;
  1216. +
  1217. + src = iter->data;
  1218. +
  1219. + if (src->extra_data) /* debian style? */
  1220. + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
  1221. + src->gzip ? "Packages.gz" : "Packages");
  1222. + else
  1223. + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
  1224. +
  1225. + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
  1226. + if (src->gzip) {
  1227. + char *tmp;
  1228. + char *tmp_file_name;
  1229. + FILE *in, *out;
  1230. +
  1231. + tmp = strdup ("/tmp/ipkg.XXXXXX");
  1232. +
  1233. + if (mkdtemp (tmp) == NULL) {
  1234. + perror ("mkdtemp");
  1235. + failures++;
  1236. + continue;
  1237. + }
  1238. +
  1239. + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
  1240. + err = ipkg_download(conf, url, tmp_file_name);
  1241. + if (err == 0) {
  1242. + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
  1243. + in = fopen (tmp_file_name, "r");
  1244. + out = fopen (list_file_name, "w");
  1245. + if (in && out) {
  1246. + inflate_unzip_result res;
  1247. + inflate_unzip (&res, 0x8000, fileno(in), fileno(out));
  1248. + } else
  1249. + err = 1;
  1250. + if (in)
  1251. + fclose (in);
  1252. + if (out)
  1253. + fclose (out);
  1254. + unlink (tmp_file_name);
  1255. + rmdir (tmp);
  1256. + free (tmp);
  1257. + }
  1258. + } else
  1259. + err = ipkg_download(conf, url, list_file_name);
  1260. + if (err) {
  1261. + failures++;
  1262. + } else {
  1263. + ipkg_message(conf, IPKG_NOTICE,
  1264. + "Updated list of available packages in %s\n",
  1265. + list_file_name);
  1266. + }
  1267. + free(url);
  1268. + free(list_file_name);
  1269. + }
  1270. + free(lists_dir);
  1271. +
  1272. +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
  1273. +#warning here
  1274. + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
  1275. + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
  1276. + * -Jamey 3/1/03
  1277. + */
  1278. + {
  1279. + int i;
  1280. + int changed = 0;
  1281. + pkg_vec_t *available = pkg_vec_alloc();
  1282. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1283. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
  1284. + for (i = 0; i < available->len; i++) {
  1285. + pkg_t *pkg = available->pkgs[i];
  1286. + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
  1287. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
  1288. + pkg->state_want = SW_UNKNOWN;
  1289. + changed = 1;
  1290. + }
  1291. + }
  1292. + pkg_vec_free(available);
  1293. + if (changed) {
  1294. + write_status_files_if_changed(conf);
  1295. + }
  1296. + }
  1297. +#endif
  1298. +
  1299. + return failures;
  1300. +}
  1301. +
  1302. +
  1303. +/* scan the args passed and cache the local filenames of the packages */
  1304. +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
  1305. +{
  1306. + int i;
  1307. + int err;
  1308. +
  1309. + /*
  1310. + * First scan through package names/urls
  1311. + * For any urls, download the packages and install in database.
  1312. + * For any files, install package info in database.
  1313. + */
  1314. + for (i = 0; i < argc; i ++) {
  1315. + char *filename = argv [i];
  1316. + //char *tmp = basename (tmp);
  1317. + //int tmplen = strlen (tmp);
  1318. +
  1319. + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
  1320. + // continue;
  1321. + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
  1322. + // continue;
  1323. +
  1324. + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
  1325. +
  1326. + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
  1327. + if (err)
  1328. + return err;
  1329. + }
  1330. + return 0;
  1331. +}
  1332. +
  1333. +struct ipkg_intercept
  1334. +{
  1335. + char *oldpath;
  1336. + char *statedir;
  1337. +};
  1338. +
  1339. +typedef struct ipkg_intercept *ipkg_intercept_t;
  1340. +ipkg_intercept_t ipkg_prep_intercepts(void);
  1341. +
  1342. +ipkg_intercept_t ipkg_prep_intercepts(void)
  1343. +{
  1344. + ipkg_intercept_t ctx;
  1345. + char *newpath;
  1346. + int gen;
  1347. +
  1348. + ctx = malloc (sizeof (*ctx));
  1349. + ctx->oldpath = strdup (getenv ("PATH"));
  1350. +
  1351. + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
  1352. + setenv ("PATH", newpath, 1);
  1353. + free (newpath);
  1354. +
  1355. + gen = 0;
  1356. + retry:
  1357. + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
  1358. + if (mkdir (ctx->statedir, 0770) < 0) {
  1359. + if (errno == EEXIST) {
  1360. + free (ctx->statedir);
  1361. + gen++;
  1362. + goto retry;
  1363. + }
  1364. + perror (ctx->statedir);
  1365. + return NULL;
  1366. + }
  1367. + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
  1368. + return ctx;
  1369. +}
  1370. +
  1371. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx);
  1372. +
  1373. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
  1374. +{
  1375. + char *cmd;
  1376. + DIR *dir;
  1377. + int err = 0;
  1378. +
  1379. + setenv ("PATH", ctx->oldpath, 1);
  1380. + free (ctx->oldpath);
  1381. +
  1382. + dir = opendir (ctx->statedir);
  1383. + if (dir) {
  1384. + struct dirent *de;
  1385. + while (de = readdir (dir), de != NULL) {
  1386. + char *path;
  1387. +
  1388. + if (de->d_name[0] == '.')
  1389. + continue;
  1390. +
  1391. + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
  1392. + if (access (path, X_OK) == 0) {
  1393. + if (system (path)) {
  1394. + err = errno;
  1395. + perror (de->d_name);
  1396. + }
  1397. + }
  1398. + free (path);
  1399. + }
  1400. + } else
  1401. + perror (ctx->statedir);
  1402. +
  1403. + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
  1404. + system (cmd);
  1405. + free (cmd);
  1406. +
  1407. + free (ctx->statedir);
  1408. + free (ctx);
  1409. +
  1410. + return err;
  1411. +}
  1412. +
  1413. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
  1414. +{
  1415. + pkg_vec_t *all;
  1416. + int i;
  1417. + pkg_t *pkg;
  1418. + ipkg_intercept_t ic;
  1419. + int r, err = 0;
  1420. +
  1421. + ipkg_message(conf, IPKG_INFO,
  1422. + "Configuring unpacked packages\n");
  1423. + fflush( stdout );
  1424. +
  1425. + all = pkg_vec_alloc();
  1426. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  1427. +
  1428. + ic = ipkg_prep_intercepts();
  1429. +
  1430. + for(i = 0; i < all->len; i++) {
  1431. + pkg = all->pkgs[i];
  1432. +
  1433. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1434. + continue;
  1435. +
  1436. + if (pkg->state_status == SS_UNPACKED) {
  1437. + ipkg_message(conf, IPKG_NOTICE,
  1438. + "Configuring %s\n", pkg->name);
  1439. + fflush( stdout );
  1440. + r = ipkg_configure(conf, pkg);
  1441. + if (r == 0) {
  1442. + pkg->state_status = SS_INSTALLED;
  1443. + pkg->parent->state_status = SS_INSTALLED;
  1444. + pkg->state_flag &= ~SF_PREFER;
  1445. + } else {
  1446. + if (!err)
  1447. + err = r;
  1448. + }
  1449. + }
  1450. + }
  1451. +
  1452. + r = ipkg_finalize_intercepts (ic);
  1453. + if (r && !err)
  1454. + err = r;
  1455. +
  1456. + pkg_vec_free(all);
  1457. + return err;
  1458. +}
  1459. +
  1460. +static void sigint_handler(int sig)
  1461. +{
  1462. + signal(sig, SIG_DFL);
  1463. + ipkg_message(NULL, IPKG_NOTICE,
  1464. + "ipkg: interrupted. writing out status database\n");
  1465. + write_status_files_if_changed(global_conf);
  1466. + exit(128 + sig);
  1467. +}
  1468. +
  1469. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1470. +{
  1471. + int i;
  1472. + char *arg;
  1473. + int err=0;
  1474. +
  1475. + global_conf = conf;
  1476. + signal(SIGINT, sigint_handler);
  1477. +
  1478. + /*
  1479. + * Now scan through package names and install
  1480. + */
  1481. + for (i=0; i < argc; i++) {
  1482. + arg = argv[i];
  1483. +
  1484. + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
  1485. + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
  1486. + if (err != EINVAL && err != 0)
  1487. + return err;
  1488. + }
  1489. + pkg_info_preinstall_check(conf);
  1490. +
  1491. + for (i=0; i < argc; i++) {
  1492. + arg = argv[i];
  1493. + if (conf->multiple_providers)
  1494. + err = ipkg_install_multi_by_name(conf, arg);
  1495. + else{
  1496. + err = ipkg_install_by_name(conf, arg);
  1497. + }
  1498. + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
  1499. + ipkg_message(conf, IPKG_ERROR,
  1500. + "Cannot find package %s.\n"
  1501. + "Check the spelling or perhaps run 'ipkg update'\n",
  1502. + arg);
  1503. + }
  1504. + }
  1505. +
  1506. + /* recheck to verify that all dependences are satisfied */
  1507. + if (0) ipkg_satisfy_all_dependences(conf);
  1508. +
  1509. + ipkg_configure_packages(conf, NULL);
  1510. +
  1511. + write_status_files_if_changed(conf);
  1512. +
  1513. + return err;
  1514. +}
  1515. +
  1516. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1517. +{
  1518. + int i;
  1519. + pkg_t *pkg;
  1520. + int err;
  1521. +
  1522. + global_conf = conf;
  1523. + signal(SIGINT, sigint_handler);
  1524. +
  1525. + if (argc) {
  1526. + for (i=0; i < argc; i++) {
  1527. + char *arg = argv[i];
  1528. +
  1529. + err = ipkg_prepare_url_for_install(conf, arg, &arg);
  1530. + if (err != EINVAL && err != 0)
  1531. + return err;
  1532. + }
  1533. + pkg_info_preinstall_check(conf);
  1534. +
  1535. + for (i=0; i < argc; i++) {
  1536. + char *arg = argv[i];
  1537. + if (conf->restrict_to_default_dest) {
  1538. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1539. + argv[i],
  1540. + conf->default_dest);
  1541. + if (pkg == NULL) {
  1542. + ipkg_message(conf, IPKG_NOTICE,
  1543. + "Package %s not installed in %s\n",
  1544. + argv[i], conf->default_dest->name);
  1545. + continue;
  1546. + }
  1547. + } else {
  1548. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  1549. + argv[i]);
  1550. + }
  1551. + if (pkg)
  1552. + ipkg_upgrade_pkg(conf, pkg);
  1553. + else {
  1554. + ipkg_install_by_name(conf, arg);
  1555. + }
  1556. + }
  1557. + } else {
  1558. + pkg_vec_t *installed = pkg_vec_alloc();
  1559. +
  1560. + pkg_info_preinstall_check(conf);
  1561. +
  1562. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  1563. + for (i = 0; i < installed->len; i++) {
  1564. + pkg = installed->pkgs[i];
  1565. + ipkg_upgrade_pkg(conf, pkg);
  1566. + }
  1567. + pkg_vec_free(installed);
  1568. + }
  1569. +
  1570. + /* recheck to verify that all dependences are satisfied */
  1571. + if (0) ipkg_satisfy_all_dependences(conf);
  1572. +
  1573. + ipkg_configure_packages(conf, NULL);
  1574. +
  1575. + write_status_files_if_changed(conf);
  1576. +
  1577. + return 0;
  1578. +}
  1579. +
  1580. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1581. +{
  1582. + int i, err;
  1583. + char *arg;
  1584. + pkg_t *pkg;
  1585. +
  1586. + pkg_info_preinstall_check(conf);
  1587. + for (i = 0; i < argc; i++) {
  1588. + arg = argv[i];
  1589. +
  1590. + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
  1591. + if (pkg == NULL) {
  1592. + ipkg_message(conf, IPKG_ERROR,
  1593. + "Cannot find package %s.\n"
  1594. + "Check the spelling or perhaps run 'ipkg update'\n",
  1595. + arg);
  1596. + continue;
  1597. + }
  1598. +
  1599. + err = ipkg_download_pkg(conf, pkg, ".");
  1600. +
  1601. + if (err) {
  1602. + ipkg_message(conf, IPKG_ERROR,
  1603. + "Failed to download %s\n", pkg->name);
  1604. + } else {
  1605. + ipkg_message(conf, IPKG_NOTICE,
  1606. + "Downloaded %s as %s\n",
  1607. + pkg->name, pkg->local_filename);
  1608. + }
  1609. + }
  1610. +
  1611. + return 0;
  1612. +}
  1613. +
  1614. +
  1615. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1616. +{
  1617. + int i ;
  1618. + pkg_vec_t *available;
  1619. + pkg_t *pkg;
  1620. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1621. + char *newline;
  1622. + char *pkg_name = NULL;
  1623. + char *version_str;
  1624. +
  1625. + if (argc > 0) {
  1626. + pkg_name = argv[0];
  1627. + }
  1628. + available = pkg_vec_alloc();
  1629. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1630. + for (i=0; i < available->len; i++) {
  1631. + pkg = available->pkgs[i];
  1632. + /* if we have package name or pattern and pkg does not match, then skip it */
  1633. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1634. + continue;
  1635. + if (pkg->description) {
  1636. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1637. + } else {
  1638. + desc_short[0] = '\0';
  1639. + }
  1640. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1641. + newline = strchr(desc_short, '\n');
  1642. + if (newline) {
  1643. + *newline = '\0';
  1644. + }
  1645. + if (ipkg_cb_list) {
  1646. + version_str = pkg_version_str_alloc(pkg);
  1647. + ipkg_cb_list(pkg->name,desc_short,
  1648. + version_str,
  1649. + pkg->state_status,
  1650. + p_userdata);
  1651. + free(version_str);
  1652. + }
  1653. + }
  1654. + pkg_vec_free(available);
  1655. +
  1656. + return 0;
  1657. +}
  1658. +
  1659. +
  1660. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1661. +{
  1662. + int i ;
  1663. + pkg_vec_t *available;
  1664. + pkg_t *pkg;
  1665. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1666. + char *newline;
  1667. + char *pkg_name = NULL;
  1668. + char *version_str;
  1669. +
  1670. + if (argc > 0) {
  1671. + pkg_name = argv[0];
  1672. + }
  1673. + available = pkg_vec_alloc();
  1674. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1675. + for (i=0; i < available->len; i++) {
  1676. + pkg = available->pkgs[i];
  1677. + /* if we have package name or pattern and pkg does not match, then skip it */
  1678. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1679. + continue;
  1680. + if (pkg->description) {
  1681. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1682. + } else {
  1683. + desc_short[0] = '\0';
  1684. + }
  1685. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1686. + newline = strchr(desc_short, '\n');
  1687. + if (newline) {
  1688. + *newline = '\0';
  1689. + }
  1690. + if (ipkg_cb_list) {
  1691. + version_str = pkg_version_str_alloc(pkg);
  1692. + ipkg_cb_list(pkg->name,desc_short,
  1693. + version_str,
  1694. + pkg->state_status,
  1695. + p_userdata);
  1696. + free(version_str);
  1697. + }
  1698. + }
  1699. +
  1700. + return 0;
  1701. +}
  1702. +
  1703. +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
  1704. +{
  1705. + int i;
  1706. + pkg_vec_t *available;
  1707. + pkg_t *pkg;
  1708. + char *pkg_name = NULL;
  1709. + char **pkg_fields = NULL;
  1710. + int n_fields = 0;
  1711. + char *buff ; // = (char *)malloc(1);
  1712. +
  1713. + if (argc > 0) {
  1714. + pkg_name = argv[0];
  1715. + }
  1716. + if (argc > 1) {
  1717. + pkg_fields = &argv[1];
  1718. + n_fields = argc - 1;
  1719. + }
  1720. +
  1721. + available = pkg_vec_alloc();
  1722. + if (installed_only)
  1723. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1724. + else
  1725. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1726. + for (i=0; i < available->len; i++) {
  1727. + pkg = available->pkgs[i];
  1728. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1729. + continue;
  1730. + }
  1731. + buff = pkg_formatted_info(pkg);
  1732. + if ( buff ) {
  1733. + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
  1734. + pkg->state_status,
  1735. + buff,
  1736. + p_userdata);
  1737. + free(buff);
  1738. + }
  1739. + if (conf->verbosity > 1) {
  1740. + conffile_list_elt_t *iter;
  1741. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  1742. + conffile_t *cf = iter->data;
  1743. + int modified = conffile_has_been_modified(conf, cf);
  1744. + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
  1745. + cf->name, cf->value, modified);
  1746. + }
  1747. + }
  1748. + }
  1749. + pkg_vec_free(available);
  1750. +
  1751. + return 0;
  1752. +}
  1753. +
  1754. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1755. +{
  1756. + return ipkg_info_status_cmd(conf, argc, argv, 0);
  1757. +}
  1758. +
  1759. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1760. +{
  1761. + return ipkg_info_status_cmd(conf, argc, argv, 1);
  1762. +}
  1763. +
  1764. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1765. +{
  1766. +
  1767. + int err;
  1768. + if (argc > 0) {
  1769. + char *pkg_name = NULL;
  1770. +
  1771. + pkg_name = argv[0];
  1772. +
  1773. + err = ipkg_configure_packages (conf, pkg_name);
  1774. +
  1775. + } else {
  1776. + err = ipkg_configure_packages (conf, NULL);
  1777. + }
  1778. +
  1779. + write_status_files_if_changed(conf);
  1780. +
  1781. + return err;
  1782. +}
  1783. +
  1784. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf)
  1785. +{
  1786. + int i, err;
  1787. + char *globpattern;
  1788. + glob_t globbuf;
  1789. +
  1790. + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
  1791. + err = glob(globpattern, 0, NULL, &globbuf);
  1792. + free(globpattern);
  1793. + if (err) {
  1794. + return 0;
  1795. + }
  1796. +
  1797. + ipkg_message(conf, IPKG_NOTICE,
  1798. + "The following packages in %s will now be installed.\n",
  1799. + conf->pending_dir);
  1800. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1801. + ipkg_message(conf, IPKG_NOTICE,
  1802. + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
  1803. + }
  1804. + ipkg_message(conf, IPKG_NOTICE, "\n");
  1805. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1806. + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
  1807. + if (err == 0) {
  1808. + err = unlink(globbuf.gl_pathv[i]);
  1809. + if (err) {
  1810. + ipkg_message(conf, IPKG_ERROR,
  1811. + "%s: ERROR: failed to unlink %s: %s\n",
  1812. + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
  1813. + return err;
  1814. + }
  1815. + }
  1816. + }
  1817. + globfree(&globbuf);
  1818. +
  1819. + return err;
  1820. +}
  1821. +
  1822. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1823. +{
  1824. + int i,a,done;
  1825. + pkg_t *pkg;
  1826. + pkg_t *pkg_to_remove;
  1827. + pkg_vec_t *available;
  1828. + char *pkg_name = NULL;
  1829. + global_conf = conf;
  1830. + signal(SIGINT, sigint_handler);
  1831. +
  1832. +// ENH: Add the "no pkg removed" just in case.
  1833. +
  1834. + done = 0;
  1835. +
  1836. + available = pkg_vec_alloc();
  1837. + pkg_info_preinstall_check(conf);
  1838. + if ( argc > 0 ) {
  1839. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1840. + for (i=0; i < argc; i++) {
  1841. + pkg_name = malloc(strlen(argv[i])+2);
  1842. + strcpy(pkg_name,argv[i]);
  1843. + for (a=0; a < available->len; a++) {
  1844. + pkg = available->pkgs[a];
  1845. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1846. + continue;
  1847. + }
  1848. + if (conf->restrict_to_default_dest) {
  1849. + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1850. + pkg->name,
  1851. + conf->default_dest);
  1852. + } else {
  1853. + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
  1854. + }
  1855. +
  1856. + if (pkg == NULL) {
  1857. + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
  1858. + continue;
  1859. + }
  1860. + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
  1861. + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
  1862. + continue;
  1863. + }
  1864. + ipkg_remove_pkg(conf, pkg_to_remove,0);
  1865. + done = 1;
  1866. + }
  1867. + free (pkg_name);
  1868. + }
  1869. + pkg_vec_free(available);
  1870. + } else {
  1871. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  1872. + int flagged_pkg_count = 0;
  1873. + int removed;
  1874. +
  1875. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
  1876. +
  1877. + for (i = 0; i < installed_pkgs->len; i++) {
  1878. + pkg = installed_pkgs->pkgs[i];
  1879. + if (pkg->state_flag & SF_USER) {
  1880. + flagged_pkg_count++;
  1881. + } else {
  1882. + if (!pkg_has_installed_dependents(pkg, NULL))
  1883. + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
  1884. + }
  1885. + }
  1886. + if (!flagged_pkg_count) {
  1887. + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
  1888. + "so refusing to uninstall unflagged non-leaf packages\n");
  1889. + return 0;
  1890. + }
  1891. +
  1892. + /* find packages not flagged SF_USER (i.e., installed to
  1893. + * satisfy a dependence) and not having any dependents, and
  1894. + * remove them */
  1895. + do {
  1896. + removed = 0;
  1897. + for (i = 0; i < installed_pkgs->len; i++) {
  1898. + pkg = installed_pkgs->pkgs[i];
  1899. + if (!(pkg->state_flag & SF_USER)
  1900. + && !pkg_has_installed_dependents(pkg, NULL)) {
  1901. + removed++;
  1902. + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
  1903. + ipkg_remove_pkg(conf, pkg,0);
  1904. + done = 1;
  1905. + }
  1906. + }
  1907. + } while (removed);
  1908. + pkg_vec_free(installed_pkgs);
  1909. + }
  1910. +
  1911. + if ( done == 0 )
  1912. + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
  1913. +
  1914. + write_status_files_if_changed(conf);
  1915. + return 0;
  1916. +}
  1917. +
  1918. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1919. +{
  1920. + int i;
  1921. + pkg_t *pkg;
  1922. +
  1923. + global_conf = conf;
  1924. + signal(SIGINT, sigint_handler);
  1925. +
  1926. + pkg_info_preinstall_check(conf);
  1927. +
  1928. + for (i=0; i < argc; i++) {
  1929. + if (conf->restrict_to_default_dest) {
  1930. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1931. + argv[i],
  1932. + conf->default_dest);
  1933. + } else {
  1934. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1935. + }
  1936. +
  1937. + if (pkg == NULL) {
  1938. + ipkg_message(conf, IPKG_ERROR,
  1939. + "Package %s is not installed.\n", argv[i]);
  1940. + continue;
  1941. + }
  1942. + ipkg_purge_pkg(conf, pkg);
  1943. + }
  1944. +
  1945. + write_status_files_if_changed(conf);
  1946. + return 0;
  1947. +}
  1948. +
  1949. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1950. +{
  1951. + int i;
  1952. + pkg_t *pkg;
  1953. + char *flags = argv[0];
  1954. +
  1955. + global_conf = conf;
  1956. + signal(SIGINT, sigint_handler);
  1957. +
  1958. + for (i=1; i < argc; i++) {
  1959. + if (conf->restrict_to_default_dest) {
  1960. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1961. + argv[i],
  1962. + conf->default_dest);
  1963. + } else {
  1964. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1965. + }
  1966. +
  1967. + if (pkg == NULL) {
  1968. + ipkg_message(conf, IPKG_ERROR,
  1969. + "Package %s is not installed.\n", argv[i]);
  1970. + continue;
  1971. + }
  1972. + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
  1973. + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
  1974. + pkg->state_flag = pkg_state_flag_from_str(flags);
  1975. + }
  1976. +/* pb_ asked this feature 03292004 */
  1977. +/* Actually I will use only this two, but this is an open for various status */
  1978. + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
  1979. + pkg->state_status = pkg_state_status_from_str(flags);
  1980. + }
  1981. + ipkg_state_changed++;
  1982. + ipkg_message(conf, IPKG_NOTICE,
  1983. + "Setting flags for package %s to %s\n",
  1984. + pkg->name, flags);
  1985. + }
  1986. +
  1987. + write_status_files_if_changed(conf);
  1988. + return 0;
  1989. +}
  1990. +
  1991. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1992. +{
  1993. + pkg_t *pkg;
  1994. + str_list_t *installed_files;
  1995. + str_list_elt_t *iter;
  1996. + char *pkg_version;
  1997. + size_t buff_len = 8192;
  1998. + size_t used_len;
  1999. + char *buff ;
  2000. +
  2001. + buff = (char *)malloc(buff_len);
  2002. + if ( buff == NULL ) {
  2003. + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
  2004. + return ENOMEM;
  2005. + }
  2006. +
  2007. + if (argc < 1) {
  2008. + return EINVAL;
  2009. + }
  2010. +
  2011. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  2012. + argv[0]);
  2013. + if (pkg == NULL) {
  2014. + ipkg_message(conf, IPKG_ERROR,
  2015. + "Package %s not installed.\n", argv[0]);
  2016. + return 0;
  2017. + }
  2018. +
  2019. + installed_files = pkg_get_installed_files(pkg);
  2020. + pkg_version = pkg_version_str_alloc(pkg);
  2021. +
  2022. + printf("Package %s (%s) is installed on %s and has the following files:\n",
  2023. + pkg->name, pkg_version, pkg->dest->name);
  2024. + for (iter = installed_files->head; iter; iter = iter->next) {
  2025. + puts(iter->data);
  2026. + }
  2027. +
  2028. + free(pkg_version);
  2029. + pkg_free_installed_files(pkg);
  2030. +
  2031. + return 0;
  2032. +}
  2033. +
  2034. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2035. +{
  2036. +
  2037. + if (argc > 0) {
  2038. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2039. + const char *rel_str = "depends on";
  2040. + int i;
  2041. +
  2042. + pkg_info_preinstall_check(conf);
  2043. +
  2044. + if (conf->query_all)
  2045. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2046. + else
  2047. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2048. + for (i = 0; i < argc; i++) {
  2049. + const char *target = argv[i];
  2050. + int j;
  2051. +
  2052. + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
  2053. +
  2054. + for (j = 0; j < available_pkgs->len; j++) {
  2055. + pkg_t *pkg = available_pkgs->pkgs[j];
  2056. + if (fnmatch(target, pkg->name, 0) == 0) {
  2057. + int k;
  2058. + int count = pkg->depends_count + pkg->pre_depends_count;
  2059. + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
  2060. + target, pkg->architecture, rel_str);
  2061. + for (k = 0; k < count; k++) {
  2062. + compound_depend_t *cdepend = &pkg->depends[k];
  2063. + int l;
  2064. + for (l = 0; l < cdepend->possibility_count; l++) {
  2065. + depend_t *possibility = cdepend->possibilities[l];
  2066. + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
  2067. + if (conf->verbosity > 0) {
  2068. + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
  2069. + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
  2070. + if (possibility->version) {
  2071. + const char *typestr = NULL;
  2072. + switch (possibility->constraint) {
  2073. + case NONE: typestr = "none"; break;
  2074. + case EARLIER: typestr = "<"; break;
  2075. + case EARLIER_EQUAL: typestr = "<="; break;
  2076. + case EQUAL: typestr = "="; break;
  2077. + case LATER_EQUAL: typestr = ">="; break;
  2078. + case LATER: typestr = ">"; break;
  2079. + }
  2080. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2081. + }
  2082. + // free(ver);
  2083. + }
  2084. + ipkg_message(conf, IPKG_ERROR, "\n");
  2085. + }
  2086. + }
  2087. + }
  2088. + }
  2089. + }
  2090. + pkg_vec_free(available_pkgs);
  2091. + }
  2092. + return 0;
  2093. +}
  2094. +
  2095. +enum what_field_type {
  2096. + WHATDEPENDS,
  2097. + WHATCONFLICTS,
  2098. + WHATPROVIDES,
  2099. + WHATREPLACES,
  2100. + WHATRECOMMENDS,
  2101. + WHATSUGGESTS
  2102. +};
  2103. +
  2104. +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
  2105. +{
  2106. +
  2107. + if (argc > 0) {
  2108. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2109. + const char *rel_str = NULL;
  2110. + int i;
  2111. + int changed;
  2112. +
  2113. + switch (what_field_type) {
  2114. + case WHATDEPENDS: rel_str = "depends on"; break;
  2115. + case WHATCONFLICTS: rel_str = "conflicts with"; break;
  2116. + case WHATSUGGESTS: rel_str = "suggests"; break;
  2117. + case WHATRECOMMENDS: rel_str = "recommends"; break;
  2118. + case WHATPROVIDES: rel_str = "provides"; break;
  2119. + case WHATREPLACES: rel_str = "replaces"; break;
  2120. + }
  2121. +
  2122. + if (conf->query_all)
  2123. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2124. + else
  2125. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2126. +
  2127. + /* mark the root set */
  2128. + pkg_vec_clear_marks(available_pkgs);
  2129. + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
  2130. + for (i = 0; i < argc; i++) {
  2131. + const char *dependee_pattern = argv[i];
  2132. + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
  2133. + }
  2134. + for (i = 0; i < available_pkgs->len; i++) {
  2135. + pkg_t *pkg = available_pkgs->pkgs[i];
  2136. + if (pkg->state_flag & SF_MARKED) {
  2137. + /* mark the parent (abstract) package */
  2138. + pkg_mark_provides(pkg);
  2139. + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
  2140. + }
  2141. + }
  2142. +
  2143. + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
  2144. + do {
  2145. + int j;
  2146. + changed = 0;
  2147. +
  2148. + for (j = 0; j < available_pkgs->len; j++) {
  2149. + pkg_t *pkg = available_pkgs->pkgs[j];
  2150. + int k;
  2151. + int count = ((what_field_type == WHATCONFLICTS)
  2152. + ? pkg->conflicts_count
  2153. + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
  2154. + /* skip this package if it is already marked */
  2155. + if (pkg->parent->state_flag & SF_MARKED) {
  2156. + continue;
  2157. + }
  2158. + for (k = 0; k < count; k++) {
  2159. + compound_depend_t *cdepend =
  2160. + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
  2161. + int l;
  2162. + for (l = 0; l < cdepend->possibility_count; l++) {
  2163. + depend_t *possibility = cdepend->possibilities[l];
  2164. + if (possibility->pkg->state_flag & SF_MARKED) {
  2165. + /* mark the depending package so we won't visit it again */
  2166. + pkg->state_flag |= SF_MARKED;
  2167. + pkg_mark_provides(pkg);
  2168. + changed++;
  2169. +
  2170. + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
  2171. + if (conf->verbosity > 0) {
  2172. + char *ver = pkg_version_str_alloc(pkg);
  2173. + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
  2174. + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
  2175. + if (possibility->version) {
  2176. + const char *typestr = NULL;
  2177. + switch (possibility->constraint) {
  2178. + case NONE: typestr = "none"; break;
  2179. + case EARLIER: typestr = "<"; break;
  2180. + case EARLIER_EQUAL: typestr = "<="; break;
  2181. + case EQUAL: typestr = "="; break;
  2182. + case LATER_EQUAL: typestr = ">="; break;
  2183. + case LATER: typestr = ">"; break;
  2184. + }
  2185. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2186. + }
  2187. + free(ver);
  2188. + if (!pkg_dependence_satisfiable(possibility))
  2189. + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
  2190. + }
  2191. + ipkg_message(conf, IPKG_NOTICE, "\n");
  2192. + goto next_package;
  2193. + }
  2194. + }
  2195. + }
  2196. + next_package:
  2197. + ;
  2198. + }
  2199. + } while (changed && recursive);
  2200. + pkg_vec_free(available_pkgs);
  2201. + }
  2202. +
  2203. + return 0;
  2204. +}
  2205. +
  2206. +int pkg_mark_provides(pkg_t *pkg)
  2207. +{
  2208. + int provides_count = pkg->provides_count;
  2209. + abstract_pkg_t **provides = pkg->provides;
  2210. + int i;
  2211. + pkg->parent->state_flag |= SF_MARKED;
  2212. + for (i = 0; i < provides_count; i++) {
  2213. + provides[i]->state_flag |= SF_MARKED;
  2214. + }
  2215. + return 0;
  2216. +}
  2217. +
  2218. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2219. +{
  2220. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
  2221. +}
  2222. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2223. +{
  2224. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
  2225. +}
  2226. +
  2227. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2228. +{
  2229. + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
  2230. +}
  2231. +
  2232. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2233. +{
  2234. + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
  2235. +}
  2236. +
  2237. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2238. +{
  2239. + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
  2240. +}
  2241. +
  2242. +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
  2243. +{
  2244. +
  2245. + if (argc > 0) {
  2246. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2247. + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
  2248. + int i;
  2249. +
  2250. + pkg_info_preinstall_check(conf);
  2251. +
  2252. + if (conf->query_all)
  2253. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2254. + else
  2255. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2256. + for (i = 0; i < argc; i++) {
  2257. + const char *target = argv[i];
  2258. + int j;
  2259. +
  2260. + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
  2261. + rel_str, target);
  2262. + for (j = 0; j < available_pkgs->len; j++) {
  2263. + pkg_t *pkg = available_pkgs->pkgs[j];
  2264. + int k;
  2265. + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
  2266. + for (k = 0; k < count; k++) {
  2267. + abstract_pkg_t *apkg =
  2268. + ((what_field_type == WHATPROVIDES)
  2269. + ? pkg->provides[k]
  2270. + : pkg->replaces[k]);
  2271. + if (fnmatch(target, apkg->name, 0) == 0) {
  2272. + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
  2273. + if (strcmp(target, apkg->name) != 0)
  2274. + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
  2275. + ipkg_message(conf, IPKG_ERROR, "\n");
  2276. + }
  2277. + }
  2278. + }
  2279. + }
  2280. + pkg_vec_free(available_pkgs);
  2281. + }
  2282. + return 0;
  2283. +}
  2284. +
  2285. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2286. +{
  2287. + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
  2288. +}
  2289. +
  2290. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2291. +{
  2292. + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
  2293. +}
  2294. +
  2295. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2296. +{
  2297. + int i;
  2298. +
  2299. + pkg_vec_t *installed;
  2300. + pkg_t *pkg;
  2301. + str_list_t *installed_files;
  2302. + str_list_elt_t *iter;
  2303. + char *installed_file;
  2304. +
  2305. + if (argc < 1) {
  2306. + return EINVAL;
  2307. + }
  2308. +
  2309. + installed = pkg_vec_alloc();
  2310. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  2311. +
  2312. + for (i=0; i < installed->len; i++) {
  2313. + pkg = installed->pkgs[i];
  2314. +
  2315. + installed_files = pkg_get_installed_files(pkg);
  2316. +
  2317. + for (iter = installed_files->head; iter; iter = iter->next) {
  2318. + installed_file = iter->data;
  2319. + if (fnmatch(argv[0], installed_file, 0)==0) {
  2320. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2321. + installed_file,
  2322. + pkg_version_str_alloc(pkg),
  2323. + pkg->state_status, p_userdata);
  2324. + }
  2325. + }
  2326. +
  2327. + pkg_free_installed_files(pkg);
  2328. + }
  2329. +
  2330. + /* XXX: CLEANUP: It's not obvious from the name of
  2331. + pkg_hash_fetch_all_installed that we need to call
  2332. + pkg_vec_free to avoid a memory leak. */
  2333. + pkg_vec_free(installed);
  2334. +
  2335. + return 0;
  2336. +}
  2337. +
  2338. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2339. +{
  2340. + if (argc == 3) {
  2341. + /* this is a bit gross */
  2342. + struct pkg p1, p2;
  2343. + parseVersion(&p1, argv[0]);
  2344. + parseVersion(&p2, argv[2]);
  2345. + return pkg_version_satisfied(&p1, &p2, argv[1]);
  2346. + } else {
  2347. + ipkg_message(conf, IPKG_ERROR,
  2348. + "ipkg compare_versions <v1> <op> <v2>\n"
  2349. + "<op> is one of <= >= << >> =\n");
  2350. + return -1;
  2351. + }
  2352. +}
  2353. +
  2354. +#ifndef HOST_CPU_STR
  2355. +#define HOST_CPU_STR__(X) #X
  2356. +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
  2357. +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
  2358. +#endif
  2359. +
  2360. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf)
  2361. +{
  2362. + nv_pair_list_elt_t *l;
  2363. +
  2364. + l = conf->arch_list.head;
  2365. + while (l) {
  2366. + nv_pair_t *nv = l->data;
  2367. + printf("arch %s %s\n", nv->name, nv->value);
  2368. + l = l->next;
  2369. + }
  2370. + return 0;
  2371. +}
  2372. +
  2373. +
  2374. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_cmd.h busybox-1.17.0/archival/libipkg/ipkg_cmd.h
  2375. --- busybox-1.17.0.orig/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
  2376. +++ busybox-1.17.0/archival/libipkg/ipkg_cmd.h 2010-07-16 14:45:14.406043529 +0200
  2377. @@ -0,0 +1,41 @@
  2378. +/* ipkg_cmd.h - the itsy package management system
  2379. +
  2380. + Carl D. Worth
  2381. +
  2382. + Copyright (C) 2001 University of Southern California
  2383. +
  2384. + This program is free software; you can redistribute it and/or
  2385. + modify it under the terms of the GNU General Public License as
  2386. + published by the Free Software Foundation; either version 2, or (at
  2387. + your option) any later version.
  2388. +
  2389. + This program is distributed in the hope that it will be useful, but
  2390. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2391. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2392. + General Public License for more details.
  2393. +*/
  2394. +
  2395. +#ifndef IPKG_CMD_H
  2396. +#define IPKG_CMD_H
  2397. +
  2398. +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
  2399. +
  2400. +struct ipkg_cmd
  2401. +{
  2402. + const char *name;
  2403. + int requires_args;
  2404. + ipkg_cmd_fun_t fun;
  2405. +};
  2406. +typedef struct ipkg_cmd ipkg_cmd_t;
  2407. +
  2408. +ipkg_cmd_t *ipkg_cmd_find(const char *name);
  2409. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
  2410. + const char **argv, void *userdata);
  2411. +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
  2412. +/* install any packges with state_want == SW_INSTALL */
  2413. +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
  2414. +/* ensure that all dependences are satisfied */
  2415. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
  2416. +int pkg_mark_provides(pkg_t *pkg);
  2417. +
  2418. +#endif
  2419. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_conf.c busybox-1.17.0/archival/libipkg/ipkg_conf.c
  2420. --- busybox-1.17.0.orig/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
  2421. +++ busybox-1.17.0/archival/libipkg/ipkg_conf.c 2010-07-16 14:45:14.466584493 +0200
  2422. @@ -0,0 +1,711 @@
  2423. +/* ipkg_conf.c - the itsy package management system
  2424. +
  2425. + Carl D. Worth
  2426. +
  2427. + Copyright (C) 2001 University of Southern California
  2428. +
  2429. + This program is free software; you can redistribute it and/or
  2430. + modify it under the terms of the GNU General Public License as
  2431. + published by the Free Software Foundation; either version 2, or (at
  2432. + your option) any later version.
  2433. +
  2434. + This program is distributed in the hope that it will be useful, but
  2435. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2436. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2437. + General Public License for more details.
  2438. +*/
  2439. +
  2440. +#include <glob.h>
  2441. +
  2442. +#include "ipkg.h"
  2443. +#include "ipkg_conf.h"
  2444. +
  2445. +#include "xregex.h"
  2446. +#include "sprintf_alloc.h"
  2447. +#include "ipkg_conf.h"
  2448. +#include "ipkg_message.h"
  2449. +#include "file_util.h"
  2450. +#include "str_util.h"
  2451. +#include "xsystem.h"
  2452. +
  2453. +
  2454. +ipkg_conf_t *global_conf;
  2455. +
  2456. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2457. + pkg_src_list_t *pkg_src_list,
  2458. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2459. + char **tmp_lists_dir);
  2460. +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
  2461. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  2462. + const char *name, const char *value);
  2463. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2464. + const char *default_dest_name);
  2465. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
  2466. + pkg_src_list_t *nv_pair_list);
  2467. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
  2468. + nv_pair_list_t *nv_pair_list, char * lists_dir);
  2469. +
  2470. +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
  2471. +{
  2472. + ipkg_option_t tmp[] = {
  2473. + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
  2474. + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
  2475. + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
  2476. + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
  2477. + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
  2478. + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
  2479. + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
  2480. + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
  2481. + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
  2482. + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
  2483. + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
  2484. + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
  2485. + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
  2486. + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
  2487. + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
  2488. + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
  2489. + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
  2490. + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
  2491. + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
  2492. + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
  2493. + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
  2494. + { NULL }
  2495. + };
  2496. +
  2497. + *options = (ipkg_option_t *)malloc(sizeof(tmp));
  2498. + if ( options == NULL ){
  2499. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  2500. + return -1;
  2501. + }
  2502. +
  2503. + memcpy(*options, tmp, sizeof(tmp));
  2504. + return 0;
  2505. +};
  2506. +
  2507. +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
  2508. +{
  2509. + if (arg_str) {
  2510. + if (*conf_str) {
  2511. + free(*conf_str);
  2512. + }
  2513. + *conf_str = strdup(arg_str);
  2514. + }
  2515. +}
  2516. +
  2517. +static void ipkg_conf_free_string(char **conf_str)
  2518. +{
  2519. + if (*conf_str) {
  2520. + free(*conf_str);
  2521. + *conf_str = NULL;
  2522. + }
  2523. +}
  2524. +
  2525. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
  2526. +{
  2527. + int err;
  2528. + char *tmp_dir_base;
  2529. + nv_pair_list_t tmp_dest_nv_pair_list;
  2530. + char * lists_dir =NULL;
  2531. + glob_t globbuf;
  2532. + const char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
  2533. + char *pending_dir =NULL;
  2534. +
  2535. + memset(conf, 0, sizeof(ipkg_conf_t));
  2536. +
  2537. + pkg_src_list_init(&conf->pkg_src_list);
  2538. +
  2539. + nv_pair_list_init(&tmp_dest_nv_pair_list);
  2540. + pkg_dest_list_init(&conf->pkg_dest_list);
  2541. +
  2542. + nv_pair_list_init(&conf->arch_list);
  2543. +
  2544. + conf->restrict_to_default_dest = 0;
  2545. + conf->default_dest = NULL;
  2546. +
  2547. +
  2548. + if (args->tmp_dir)
  2549. + tmp_dir_base = args->tmp_dir;
  2550. + else
  2551. + tmp_dir_base = getenv("TMPDIR");
  2552. + sprintf_alloc(&conf->tmp_dir, "%s/%s",
  2553. + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
  2554. + IPKG_CONF_TMP_DIR_SUFFIX);
  2555. + conf->tmp_dir = mkdtemp(conf->tmp_dir);
  2556. + if (conf->tmp_dir == NULL) {
  2557. + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
  2558. + __FUNCTION__, conf->tmp_dir, strerror(errno));
  2559. + return errno;
  2560. + }
  2561. +
  2562. + conf->force_depends = 0;
  2563. + conf->force_defaults = 0;
  2564. + conf->force_overwrite = 0;
  2565. + conf->force_downgrade = 0;
  2566. + conf->force_reinstall = 0;
  2567. + conf->force_space = 0;
  2568. + conf->force_removal_of_essential_packages = 0;
  2569. + conf->force_removal_of_dependent_packages = 0;
  2570. + conf->nodeps = 0;
  2571. + conf->verbose_wget = 0;
  2572. + conf->offline_root = NULL;
  2573. + conf->offline_root_pre_script_cmd = NULL;
  2574. + conf->offline_root_post_script_cmd = NULL;
  2575. + conf->multiple_providers = 0;
  2576. + conf->verbosity = 1;
  2577. + conf->noaction = 0;
  2578. +
  2579. + conf->http_proxy = NULL;
  2580. + conf->ftp_proxy = NULL;
  2581. + conf->no_proxy = NULL;
  2582. + conf->proxy_user = NULL;
  2583. + conf->proxy_passwd = NULL;
  2584. +
  2585. + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2586. + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2587. + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2588. + lists_dir=(char *)malloc(1);
  2589. + lists_dir[0]='\0';
  2590. + if (args->conf_file) {
  2591. + struct stat stat_buf;
  2592. + err = stat(args->conf_file, &stat_buf);
  2593. + if (err == 0)
  2594. + if (ipkg_conf_parse_file(conf, args->conf_file,
  2595. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2596. + /* Memory leakage from ipkg_conf_parse-file */
  2597. + return -1;
  2598. + }
  2599. +
  2600. + }
  2601. +
  2602. + /* if (!lists_dir ){*/
  2603. + if (strlen(lists_dir)<=1 ){
  2604. + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
  2605. + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
  2606. + }
  2607. +
  2608. + if (args->offline_root) {
  2609. + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
  2610. + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
  2611. + free(lists_dir);
  2612. + lists_dir = tmp;
  2613. + }
  2614. +
  2615. + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
  2616. + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
  2617. +
  2618. + conf->lists_dir = strdup(lists_dir);
  2619. + conf->pending_dir = strdup(pending_dir);
  2620. +
  2621. + if (args->offline_root)
  2622. + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
  2623. + memset(&globbuf, 0, sizeof(globbuf));
  2624. + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
  2625. + if (!err) {
  2626. + int i;
  2627. + for (i = 0; i < globbuf.gl_pathc; i++) {
  2628. + if (globbuf.gl_pathv[i])
  2629. + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
  2630. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2631. + /* Memory leakage from ipkg_conf_parse-file */
  2632. + return -1;
  2633. + }
  2634. + }
  2635. + }
  2636. + globfree(&globbuf);
  2637. +
  2638. + /* if no architectures were defined, then default all, noarch, and host architecture */
  2639. + if (nv_pair_list_empty(&conf->arch_list)) {
  2640. + nv_pair_list_append(&conf->arch_list, "all", "1");
  2641. + nv_pair_list_append(&conf->arch_list, "noarch", "1");
  2642. + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
  2643. + }
  2644. +
  2645. + /* Even if there is no conf file, we'll need at least one dest. */
  2646. + if (tmp_dest_nv_pair_list.head == NULL) {
  2647. + nv_pair_list_append(&tmp_dest_nv_pair_list,
  2648. + IPKG_CONF_DEFAULT_DEST_NAME,
  2649. + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
  2650. + }
  2651. +
  2652. + /* After parsing the file, set options from command-line, (so that
  2653. + command-line arguments take precedence) */
  2654. + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
  2655. + really needs to be cleaned up. There is so much duplication
  2656. + right now it is ridiculous. Maybe ipkg_conf_t should just save
  2657. + a pointer to args_t (which could then not be freed), rather
  2658. + than duplicating every field here? */
  2659. + if (args->force_depends) {
  2660. + conf->force_depends = 1;
  2661. + }
  2662. + if (args->force_defaults) {
  2663. + conf->force_defaults = 1;
  2664. + }
  2665. + if (args->force_overwrite) {
  2666. + conf->force_overwrite = 1;
  2667. + }
  2668. + if (args->force_downgrade) {
  2669. + conf->force_downgrade = 1;
  2670. + }
  2671. + if (args->force_reinstall) {
  2672. + conf->force_reinstall = 1;
  2673. + }
  2674. + if (args->force_removal_of_dependent_packages) {
  2675. + conf->force_removal_of_dependent_packages = 1;
  2676. + }
  2677. + if (args->force_removal_of_essential_packages) {
  2678. + conf->force_removal_of_essential_packages = 1;
  2679. + }
  2680. + if (args->nodeps) {
  2681. + conf->nodeps = 1;
  2682. + }
  2683. + if (args->noaction) {
  2684. + conf->noaction = 1;
  2685. + }
  2686. + if (args->query_all) {
  2687. + conf->query_all = 1;
  2688. + }
  2689. + if (args->verbose_wget) {
  2690. + conf->verbose_wget = 1;
  2691. + }
  2692. + if (args->multiple_providers) {
  2693. + conf->multiple_providers = 1;
  2694. + }
  2695. + if (args->verbosity != conf->verbosity) {
  2696. + conf->verbosity = args->verbosity;
  2697. + }
  2698. +
  2699. + ipkg_conf_override_string(&conf->offline_root,
  2700. + args->offline_root);
  2701. + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
  2702. + args->offline_root_pre_script_cmd);
  2703. + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
  2704. + args->offline_root_post_script_cmd);
  2705. +
  2706. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  2707. + read anything from there.
  2708. +*/
  2709. + if ( !(args->nocheckfordirorfile)){
  2710. + /* need to run load the source list before dest list -Jamey */
  2711. + if ( !(args->noreadfeedsfile))
  2712. + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
  2713. +
  2714. + /* Now that we have resolved conf->offline_root, we can commit to
  2715. + the directory names for the dests and load in all the package
  2716. + lists. */
  2717. + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
  2718. +
  2719. + if (args->dest) {
  2720. + err = ipkg_conf_set_default_dest(conf, args->dest);
  2721. + if (err) {
  2722. + return err;
  2723. + }
  2724. + }
  2725. + }
  2726. + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
  2727. + free(lists_dir);
  2728. + free(pending_dir);
  2729. +
  2730. + return 0;
  2731. +}
  2732. +
  2733. +void ipkg_conf_deinit(ipkg_conf_t *conf)
  2734. +{
  2735. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  2736. +#error
  2737. + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
  2738. + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  2739. + __FUNCTION__, conf->tmp_dir);
  2740. +#else
  2741. + int err;
  2742. +
  2743. + err = rmdir(conf->tmp_dir);
  2744. + if (err) {
  2745. + if (errno == ENOTEMPTY) {
  2746. + char *cmd;
  2747. + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
  2748. + err = xsystem(cmd);
  2749. + free(cmd);
  2750. + }
  2751. + if (err)
  2752. + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
  2753. + }
  2754. +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
  2755. +
  2756. + free(conf->tmp_dir); /*XXX*/
  2757. +
  2758. + pkg_src_list_deinit(&conf->pkg_src_list);
  2759. + pkg_dest_list_deinit(&conf->pkg_dest_list);
  2760. + nv_pair_list_deinit(&conf->arch_list);
  2761. + if (&conf->pkg_hash)
  2762. + pkg_hash_deinit(&conf->pkg_hash);
  2763. + if (&conf->file_hash)
  2764. + hash_table_deinit(&conf->file_hash);
  2765. + if (&conf->obs_file_hash)
  2766. + hash_table_deinit(&conf->obs_file_hash);
  2767. +
  2768. + ipkg_conf_free_string(&conf->offline_root);
  2769. + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
  2770. + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
  2771. +
  2772. + if (conf->verbosity > 1) {
  2773. + int i;
  2774. + hash_table_t *hashes[] = {
  2775. + &conf->pkg_hash,
  2776. + &conf->file_hash,
  2777. + &conf->obs_file_hash };
  2778. + for (i = 0; i < 3; i++) {
  2779. + hash_table_t *hash = hashes[i];
  2780. + int c = 0;
  2781. + int n_conflicts = 0;
  2782. + int j;
  2783. + for (j = 0; j < hash->n_entries; j++) {
  2784. + int len = 0;
  2785. + hash_entry_t *e = &hash->entries[j];
  2786. + if (e->next)
  2787. + n_conflicts++;
  2788. + while (e && e->key) {
  2789. + len++;
  2790. + e = e->next;
  2791. + }
  2792. + if (len > c)
  2793. + c = len;
  2794. + }
  2795. + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
  2796. + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
  2797. + hash_table_deinit(hash);
  2798. + }
  2799. + }
  2800. +}
  2801. +
  2802. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2803. + const char *default_dest_name)
  2804. +{
  2805. + pkg_dest_list_elt_t *iter;
  2806. + pkg_dest_t *dest;
  2807. +
  2808. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  2809. + dest = iter->data;
  2810. + if (strcmp(dest->name, default_dest_name) == 0) {
  2811. + conf->default_dest = dest;
  2812. + conf->restrict_to_default_dest = 1;
  2813. + return 0;
  2814. + }
  2815. + }
  2816. +
  2817. + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
  2818. +
  2819. + return 1;
  2820. +}
  2821. +
  2822. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
  2823. +{
  2824. + pkg_src_list_elt_t *iter;
  2825. + pkg_src_t *src;
  2826. + char *list_file;
  2827. +
  2828. + for (iter = pkg_src_list->head; iter; iter = iter->next) {
  2829. + src = iter->data;
  2830. + if (src == NULL) {
  2831. + continue;
  2832. + }
  2833. +
  2834. + sprintf_alloc(&list_file, "%s/%s",
  2835. + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
  2836. + src->name);
  2837. +
  2838. + if (file_exists(list_file)) {
  2839. + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
  2840. + }
  2841. + free(list_file);
  2842. + }
  2843. +
  2844. + return 0;
  2845. +}
  2846. +
  2847. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
  2848. +{
  2849. + nv_pair_list_elt_t *iter;
  2850. + nv_pair_t *nv_pair;
  2851. + pkg_dest_t *dest;
  2852. + char *root_dir;
  2853. +
  2854. + for (iter = nv_pair_list->head; iter; iter = iter->next) {
  2855. + nv_pair = iter->data;
  2856. +
  2857. + if (conf->offline_root) {
  2858. + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
  2859. + } else {
  2860. + root_dir = strdup(nv_pair->value);
  2861. + }
  2862. + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
  2863. + free(root_dir);
  2864. + if (dest == NULL) {
  2865. + continue;
  2866. + }
  2867. + if (conf->default_dest == NULL) {
  2868. + conf->default_dest = dest;
  2869. + }
  2870. + if (file_exists(dest->status_file_name)) {
  2871. + pkg_hash_add_from_file(conf, dest->status_file_name,
  2872. + NULL, dest, 1);
  2873. + }
  2874. + }
  2875. +
  2876. + return 0;
  2877. +}
  2878. +
  2879. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2880. + pkg_src_list_t *pkg_src_list,
  2881. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2882. + char **lists_dir)
  2883. +{
  2884. + ipkg_option_t * options;
  2885. + FILE *file = fopen(filename, "r");
  2886. + regex_t valid_line_re, comment_re;
  2887. +#define regmatch_size 12
  2888. + regmatch_t regmatch[regmatch_size];
  2889. +
  2890. + if (ipkg_init_options_array(conf, &options)<0)
  2891. + return ENOMEM;
  2892. +
  2893. + if (file == NULL) {
  2894. + fprintf(stderr, "%s: failed to open %s: %s\n",
  2895. + __FUNCTION__, filename, strerror(errno));
  2896. + free(options);
  2897. + return errno;
  2898. + }
  2899. + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
  2900. +
  2901. + xregcomp(&comment_re,
  2902. + "^[[:space:]]*(#.*|[[:space:]]*)$",
  2903. + REG_EXTENDED);
  2904. + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
  2905. +
  2906. + while(1) {
  2907. + int line_num = 0;
  2908. + char *line;
  2909. + char *type, *name, *value, *extra;
  2910. +
  2911. + line = file_read_line_alloc(file);
  2912. + line_num++;
  2913. + if (line == NULL) {
  2914. + break;
  2915. + }
  2916. +
  2917. + str_chomp(line);
  2918. +
  2919. + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
  2920. + goto NEXT_LINE;
  2921. + }
  2922. +
  2923. + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
  2924. + str_chomp(line);
  2925. + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
  2926. + filename, line_num, line);
  2927. + goto NEXT_LINE;
  2928. + }
  2929. +
  2930. + /* This has to be so ugly to deal with optional quotation marks */
  2931. + if (regmatch[2].rm_so > 0) {
  2932. + type = strndup(line + regmatch[2].rm_so,
  2933. + regmatch[2].rm_eo - regmatch[2].rm_so);
  2934. + } else {
  2935. + type = strndup(line + regmatch[3].rm_so,
  2936. + regmatch[3].rm_eo - regmatch[3].rm_so);
  2937. + }
  2938. + if (regmatch[5].rm_so > 0) {
  2939. + name = strndup(line + regmatch[5].rm_so,
  2940. + regmatch[5].rm_eo - regmatch[5].rm_so);
  2941. + } else {
  2942. + name = strndup(line + regmatch[6].rm_so,
  2943. + regmatch[6].rm_eo - regmatch[6].rm_so);
  2944. + }
  2945. + if (regmatch[8].rm_so > 0) {
  2946. + value = strndup(line + regmatch[8].rm_so,
  2947. + regmatch[8].rm_eo - regmatch[8].rm_so);
  2948. + } else {
  2949. + value = strndup(line + regmatch[9].rm_so,
  2950. + regmatch[9].rm_eo - regmatch[9].rm_so);
  2951. + }
  2952. + extra = NULL;
  2953. + if (regmatch[11].rm_so > 0) {
  2954. + extra = strndup (line + regmatch[11].rm_so,
  2955. + regmatch[11].rm_eo - regmatch[11].rm_so);
  2956. + }
  2957. +
  2958. + /* We use the tmp_dest_nv_pair_list below instead of
  2959. + conf->pkg_dest_list because we might encounter an
  2960. + offline_root option later and that would invalidate the
  2961. + directories we would have computed in
  2962. + pkg_dest_list_init. (We do a similar thing with
  2963. + tmp_src_nv_pair_list for sake of symmetry.) */
  2964. + if (strcmp(type, "option") == 0) {
  2965. + ipkg_conf_set_option(options, name, value);
  2966. + } else if (strcmp(type, "src") == 0) {
  2967. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  2968. + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
  2969. + } else {
  2970. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  2971. + name, value);
  2972. + }
  2973. + } else if (strcmp(type, "src/gz") == 0) {
  2974. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  2975. + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
  2976. + } else {
  2977. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  2978. + name, value);
  2979. + }
  2980. + } else if (strcmp(type, "dest") == 0) {
  2981. + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
  2982. + } else if (strcmp(type, "lists_dir") == 0) {
  2983. + *lists_dir = realloc(*lists_dir,strlen(value)+1);
  2984. + if (*lists_dir == NULL) {
  2985. + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
  2986. + free(options);
  2987. + return EINVAL;
  2988. + }
  2989. + sprintf (*lists_dir,"%s",value);
  2990. + } else if (strcmp(type, "arch") == 0) {
  2991. + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
  2992. + if (!value) {
  2993. + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
  2994. + value = strdup("10");
  2995. + }
  2996. + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
  2997. + } else {
  2998. + fprintf(stderr, "WARNING: Ignoring unknown configuration "
  2999. + "parameter: %s %s %s\n", type, name, value);
  3000. + free(options);
  3001. + return EINVAL;
  3002. + }
  3003. +
  3004. + free(type);
  3005. + free(name);
  3006. + free(value);
  3007. + if (extra)
  3008. + free (extra);
  3009. +
  3010. + NEXT_LINE:
  3011. + free(line);
  3012. + }
  3013. +
  3014. + free(options);
  3015. + regfree(&comment_re);
  3016. + regfree(&valid_line_re);
  3017. + fclose(file);
  3018. +
  3019. + return 0;
  3020. +}
  3021. +
  3022. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  3023. + const char *name, const char *value)
  3024. +{
  3025. + int i = 0;
  3026. + while (options[i].name) {
  3027. + if (strcmp(options[i].name, name) == 0) {
  3028. + switch (options[i].type) {
  3029. + case IPKG_OPT_TYPE_BOOL:
  3030. + *((int *)options[i].value) = 1;
  3031. + return 0;
  3032. + case IPKG_OPT_TYPE_INT:
  3033. + if (value) {
  3034. + *((int *)options[i].value) = atoi(value);
  3035. + return 0;
  3036. + } else {
  3037. + printf("%s: Option %s need an argument\n",
  3038. + __FUNCTION__, name);
  3039. + return EINVAL;
  3040. + }
  3041. + case IPKG_OPT_TYPE_STRING:
  3042. + if (value) {
  3043. + *((char **)options[i].value) = strdup(value);
  3044. + return 0;
  3045. + } else {
  3046. + printf("%s: Option %s need an argument\n",
  3047. + __FUNCTION__, name);
  3048. + return EINVAL;
  3049. + }
  3050. + }
  3051. + }
  3052. + i++;
  3053. + }
  3054. +
  3055. + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
  3056. + __FUNCTION__, name, value);
  3057. + return EINVAL;
  3058. +}
  3059. +
  3060. +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
  3061. +{
  3062. + pkg_dest_list_elt_t *iter;
  3063. + pkg_dest_t *dest;
  3064. + pkg_vec_t *all;
  3065. + pkg_t *pkg;
  3066. + register int i;
  3067. + int err;
  3068. +
  3069. + if (conf->noaction)
  3070. + return 0;
  3071. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3072. + dest = iter->data;
  3073. + dest->status_file = fopen(dest->status_file_tmp_name, "w");
  3074. + if (dest->status_file == NULL) {
  3075. + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
  3076. + __FUNCTION__, dest->status_file_name, strerror(errno));
  3077. + }
  3078. + }
  3079. +
  3080. + all = pkg_vec_alloc();
  3081. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  3082. +
  3083. + for(i = 0; i < all->len; i++) {
  3084. + pkg = all->pkgs[i];
  3085. + /* We don't need most uninstalled packages in the status file */
  3086. + if (pkg->state_status == SS_NOT_INSTALLED
  3087. + && (pkg->state_want == SW_UNKNOWN
  3088. + || pkg->state_want == SW_DEINSTALL
  3089. + || pkg->state_want == SW_PURGE)) {
  3090. + continue;
  3091. + }
  3092. + if (!pkg) {
  3093. + fprintf(stderr, "Null package\n");
  3094. + }
  3095. + if (pkg->dest == NULL) {
  3096. + fprintf(stderr, "%s: ERROR: Can't write status for "
  3097. + "package %s since it has a NULL dest\n",
  3098. + __FUNCTION__, pkg->name);
  3099. + continue;
  3100. + }
  3101. + if (pkg->dest->status_file) {
  3102. + pkg_print_status(pkg, pkg->dest->status_file);
  3103. + }
  3104. + }
  3105. +
  3106. + pkg_vec_free(all);
  3107. +
  3108. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3109. + dest = iter->data;
  3110. + if (dest->status_file) {
  3111. + err = ferror(dest->status_file);
  3112. + fclose(dest->status_file);
  3113. + dest->status_file = NULL;
  3114. + if (!err) {
  3115. + file_move(dest->status_file_tmp_name, dest->status_file_name);
  3116. + } else {
  3117. + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
  3118. + "retaining old %s\n", __FUNCTION__,
  3119. + dest->status_file_tmp_name, dest->status_file_name);
  3120. + }
  3121. + }
  3122. + }
  3123. +
  3124. + return 0;
  3125. +}
  3126. +
  3127. +
  3128. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
  3129. +{
  3130. + char *root_filename;
  3131. + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
  3132. + return root_filename;
  3133. +}
  3134. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_conf.h busybox-1.17.0/archival/libipkg/ipkg_conf.h
  3135. --- busybox-1.17.0.orig/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
  3136. +++ busybox-1.17.0/archival/libipkg/ipkg_conf.h 2010-07-16 14:45:14.547998162 +0200
  3137. @@ -0,0 +1,107 @@
  3138. +/* ipkg_conf.h - the itsy package management system
  3139. +
  3140. + Carl D. Worth
  3141. +
  3142. + Copyright (C) 2001 University of Southern California
  3143. +
  3144. + This program is free software; you can redistribute it and/or
  3145. + modify it under the terms of the GNU General Public License as
  3146. + published by the Free Software Foundation; either version 2, or (at
  3147. + your option) any later version.
  3148. +
  3149. + This program is distributed in the hope that it will be useful, but
  3150. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3151. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3152. + General Public License for more details.
  3153. +*/
  3154. +
  3155. +#ifndef IPKG_CONF_H
  3156. +#define IPKG_CONF_H
  3157. +
  3158. +typedef struct ipkg_conf ipkg_conf_t;
  3159. +
  3160. +#include "hash_table.h"
  3161. +#include "ipkg.h"
  3162. +#include "args.h"
  3163. +#include "pkg.h"
  3164. +#include "pkg_hash.h"
  3165. +#include "pkg_src_list.h"
  3166. +#include "pkg_dest_list.h"
  3167. +#include "nv_pair_list.h"
  3168. +
  3169. +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
  3170. +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
  3171. +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
  3172. +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
  3173. +
  3174. +/* In case the config file defines no dest */
  3175. +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
  3176. +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
  3177. +
  3178. +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
  3179. +
  3180. +struct ipkg_conf
  3181. +{
  3182. + pkg_src_list_t pkg_src_list;
  3183. + pkg_dest_list_t pkg_dest_list;
  3184. + nv_pair_list_t arch_list;
  3185. +
  3186. + int restrict_to_default_dest;
  3187. + pkg_dest_t *default_dest;
  3188. +
  3189. + char *tmp_dir;
  3190. + char *lists_dir;
  3191. + char *pending_dir;
  3192. +
  3193. + /* options */
  3194. + int force_depends;
  3195. + int force_defaults;
  3196. + int force_overwrite;
  3197. + int force_downgrade;
  3198. + int force_reinstall;
  3199. + int force_space;
  3200. + int force_removal_of_dependent_packages;
  3201. + int force_removal_of_essential_packages;
  3202. + int nodeps; /* do not follow dependences */
  3203. + int verbose_wget;
  3204. + int multiple_providers;
  3205. + char *offline_root;
  3206. + char *offline_root_pre_script_cmd;
  3207. + char *offline_root_post_script_cmd;
  3208. + int query_all;
  3209. + int verbosity;
  3210. + int noaction;
  3211. +
  3212. + /* proxy options */
  3213. + char *http_proxy;
  3214. + char *ftp_proxy;
  3215. + char *no_proxy;
  3216. + char *proxy_user;
  3217. + char *proxy_passwd;
  3218. +
  3219. + hash_table_t pkg_hash;
  3220. + hash_table_t file_hash;
  3221. + hash_table_t obs_file_hash;
  3222. +};
  3223. +
  3224. +enum ipkg_option_type {
  3225. + IPKG_OPT_TYPE_BOOL,
  3226. + IPKG_OPT_TYPE_INT,
  3227. + IPKG_OPT_TYPE_STRING
  3228. +};
  3229. +typedef enum ipkg_option_type ipkg_option_type_t;
  3230. +
  3231. +typedef struct ipkg_option ipkg_option_t;
  3232. +struct ipkg_option {
  3233. + const char *name;
  3234. + const ipkg_option_type_t type;
  3235. + const void *value;
  3236. +};
  3237. +
  3238. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
  3239. +void ipkg_conf_deinit(ipkg_conf_t *conf);
  3240. +
  3241. +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
  3242. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
  3243. +
  3244. +#endif
  3245. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_configure.c busybox-1.17.0/archival/libipkg/ipkg_configure.c
  3246. --- busybox-1.17.0.orig/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
  3247. +++ busybox-1.17.0/archival/libipkg/ipkg_configure.c 2010-07-16 14:45:14.597998235 +0200
  3248. @@ -0,0 +1,40 @@
  3249. +/* ipkg_configure.c - the itsy package management system
  3250. +
  3251. + Carl D. Worth
  3252. +
  3253. + Copyright (C) 2001 University of Southern California
  3254. +
  3255. + This program is free software; you can redistribute it and/or
  3256. + modify it under the terms of the GNU General Public License as
  3257. + published by the Free Software Foundation; either version 2, or (at
  3258. + your option) any later version.
  3259. +
  3260. + This program is distributed in the hope that it will be useful, but
  3261. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3262. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3263. + General Public License for more details.
  3264. +*/
  3265. +
  3266. +#include "ipkg.h"
  3267. +
  3268. +#include "ipkg_configure.h"
  3269. +
  3270. +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
  3271. +{
  3272. + int err;
  3273. +
  3274. + /* DPKG_INCOMPATIBILITY:
  3275. + dpkg actually does some conffile handling here, rather than at the
  3276. + end of ipkg_install(). Do we care? */
  3277. + /* DPKG_INCOMPATIBILITY:
  3278. + dpkg actually includes a version number to this script call */
  3279. + err = pkg_run_script(conf, pkg, "postinst", "configure");
  3280. + if (err) {
  3281. + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
  3282. + return err;
  3283. + }
  3284. +
  3285. + ipkg_state_changed++;
  3286. + return 0;
  3287. +}
  3288. +
  3289. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_configure.h busybox-1.17.0/archival/libipkg/ipkg_configure.h
  3290. --- busybox-1.17.0.orig/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
  3291. +++ busybox-1.17.0/archival/libipkg/ipkg_configure.h 2010-07-16 14:45:14.647999187 +0200
  3292. @@ -0,0 +1,25 @@
  3293. +/* ipkg_configure.h - the itsy package management system
  3294. +
  3295. + Carl D. Worth
  3296. +
  3297. + Copyright (C) 2001 University of Southern California
  3298. +
  3299. + This program is free software; you can redistribute it and/or
  3300. + modify it under the terms of the GNU General Public License as
  3301. + published by the Free Software Foundation; either version 2, or (at
  3302. + your option) any later version.
  3303. +
  3304. + This program is distributed in the hope that it will be useful, but
  3305. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3306. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3307. + General Public License for more details.
  3308. +*/
  3309. +
  3310. +#ifndef IPKG_CONFIGURE_H
  3311. +#define IPKG_CONFIGURE_H
  3312. +
  3313. +#include "ipkg_conf.h"
  3314. +
  3315. +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
  3316. +
  3317. +#endif
  3318. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_download.c busybox-1.17.0/archival/libipkg/ipkg_download.c
  3319. --- busybox-1.17.0.orig/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
  3320. +++ busybox-1.17.0/archival/libipkg/ipkg_download.c 2010-07-16 14:45:14.697999480 +0200
  3321. @@ -0,0 +1,195 @@
  3322. +/* ipkg_download.c - the itsy package management system
  3323. +
  3324. + Carl D. Worth
  3325. +
  3326. + Copyright (C) 2001 University of Southern California
  3327. +
  3328. + This program is free software; you can redistribute it and/or
  3329. + modify it under the terms of the GNU General Public License as
  3330. + published by the Free Software Foundation; either version 2, or (at
  3331. + your option) any later version.
  3332. +
  3333. + This program is distributed in the hope that it will be useful, but
  3334. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3335. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3336. + General Public License for more details.
  3337. +*/
  3338. +
  3339. +#include "ipkg.h"
  3340. +#include "ipkg_download.h"
  3341. +#include "ipkg_message.h"
  3342. +
  3343. +#include "sprintf_alloc.h"
  3344. +#include "xsystem.h"
  3345. +#include "file_util.h"
  3346. +#include "str_util.h"
  3347. +
  3348. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
  3349. +{
  3350. + int err = 0;
  3351. +
  3352. + char *src_basec = strdup(src);
  3353. + char *src_base = basename(src_basec);
  3354. + char *tmp_file_location;
  3355. + char *cmd;
  3356. +
  3357. + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
  3358. +
  3359. + fflush(stdout);
  3360. +
  3361. + if (str_starts_with(src, "file:")) {
  3362. + int ret;
  3363. + const char *file_src = src + 5;
  3364. + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
  3365. + ret = file_copy(src + 5, dest_file_name);
  3366. + ipkg_message(conf,IPKG_INFO,"Done.\n");
  3367. + return ret;
  3368. + }
  3369. +
  3370. + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
  3371. + err = unlink(tmp_file_location);
  3372. + if (err && errno != ENOENT) {
  3373. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
  3374. + __FUNCTION__, tmp_file_location, strerror(errno));
  3375. + free(tmp_file_location);
  3376. + return errno;
  3377. + }
  3378. +
  3379. + if (conf->http_proxy) {
  3380. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
  3381. + setenv("http_proxy", conf->http_proxy, 1);
  3382. + }
  3383. + if (conf->ftp_proxy) {
  3384. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
  3385. + setenv("ftp_proxy", conf->ftp_proxy, 1);
  3386. + }
  3387. + if (conf->no_proxy) {
  3388. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
  3389. + setenv("no_proxy", conf->no_proxy, 1);
  3390. + }
  3391. +
  3392. + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
  3393. + sprintf_alloc(&cmd, "wget %s %s%s %s%s %s -P %s %s",
  3394. + (conf->http_proxy || conf->ftp_proxy) ? "-Y on" : "",
  3395. + conf->proxy_user ? "--proxy-user=" : "",
  3396. + conf->proxy_user ? conf->proxy_user : "",
  3397. + conf->proxy_passwd ? "--proxy-passwd=" : "",
  3398. + conf->proxy_passwd ? conf->proxy_passwd : "",
  3399. + conf->verbose_wget ? "" : "-q",
  3400. + conf->tmp_dir,
  3401. + src);
  3402. + err = xsystem(cmd);
  3403. + if (err) {
  3404. + if (err != -1) {
  3405. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
  3406. + __FUNCTION__, err, cmd);
  3407. + }
  3408. + unlink(tmp_file_location);
  3409. + free(tmp_file_location);
  3410. + free(src_basec);
  3411. + free(cmd);
  3412. + return EINVAL;
  3413. + }
  3414. + free(cmd);
  3415. +
  3416. + err = file_move(tmp_file_location, dest_file_name);
  3417. +
  3418. + free(tmp_file_location);
  3419. + free(src_basec);
  3420. +
  3421. + if (err) {
  3422. + return err;
  3423. + }
  3424. +
  3425. + return 0;
  3426. +}
  3427. +
  3428. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
  3429. +{
  3430. + int err;
  3431. + char *url;
  3432. +
  3433. + if (pkg->src == NULL) {
  3434. + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
  3435. + pkg->name, pkg->parent->name);
  3436. + return -1;
  3437. + }
  3438. +
  3439. + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
  3440. +
  3441. + /* XXX: BUG: The pkg->filename might be something like
  3442. + "../../foo.ipk". While this is correct, and exactly what we
  3443. + want to use to construct url above, here we actually need to
  3444. + use just the filename part, without any directory. */
  3445. + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
  3446. +
  3447. + err = ipkg_download(conf, url, pkg->local_filename);
  3448. + free(url);
  3449. +
  3450. + return err;
  3451. +}
  3452. +
  3453. +/*
  3454. + * Downloads file from url, installs in package database, return package name.
  3455. + */
  3456. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
  3457. +{
  3458. + int err = 0;
  3459. + pkg_t *pkg;
  3460. + pkg = pkg_new();
  3461. + if (pkg == NULL)
  3462. + return ENOMEM;
  3463. +
  3464. + if (str_starts_with(url, "http://")
  3465. + || str_starts_with(url, "ftp://")) {
  3466. + char *tmp_file;
  3467. + char *file_basec = strdup(url);
  3468. + char *file_base = basename(file_basec);
  3469. +
  3470. + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
  3471. + err = ipkg_download(conf, url, tmp_file);
  3472. + if (err)
  3473. + return err;
  3474. +
  3475. + err = pkg_init_from_file(pkg, tmp_file);
  3476. + if (err)
  3477. + return err;
  3478. + pkg->local_filename = strdup(tmp_file);
  3479. +
  3480. + free(tmp_file);
  3481. + free(file_basec);
  3482. +
  3483. + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
  3484. + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
  3485. +
  3486. + err = pkg_init_from_file(pkg, url);
  3487. + if (err)
  3488. + return err;
  3489. + pkg->local_filename = strdup(url);
  3490. + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
  3491. + pkg->provided_by_hand = 1;
  3492. +
  3493. + } else {
  3494. + pkg_deinit(pkg);
  3495. + free(pkg);
  3496. + return 0;
  3497. + }
  3498. +
  3499. + if (!pkg->architecture) {
  3500. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3501. + return -EINVAL;
  3502. + }
  3503. +
  3504. + pkg->dest = conf->default_dest;
  3505. + pkg->state_want = SW_INSTALL;
  3506. + pkg->state_flag |= SF_PREFER;
  3507. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3508. + if ( pkg == NULL ){
  3509. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  3510. + return 0;
  3511. + }
  3512. + if (namep) {
  3513. + *namep = strdup(pkg->name);
  3514. + }
  3515. + return 0;
  3516. +}
  3517. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_download.h busybox-1.17.0/archival/libipkg/ipkg_download.h
  3518. --- busybox-1.17.0.orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
  3519. +++ busybox-1.17.0/archival/libipkg/ipkg_download.h 2010-07-16 14:45:14.769609415 +0200
  3520. @@ -0,0 +1,30 @@
  3521. +/* ipkg_download.h - the itsy package management system
  3522. +
  3523. + Carl D. Worth
  3524. +
  3525. + Copyright (C) 2001 University of Southern California
  3526. +
  3527. + This program is free software; you can redistribute it and/or
  3528. + modify it under the terms of the GNU General Public License as
  3529. + published by the Free Software Foundation; either version 2, or (at
  3530. + your option) any later version.
  3531. +
  3532. + This program is distributed in the hope that it will be useful, but
  3533. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3534. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3535. + General Public License for more details.
  3536. +*/
  3537. +
  3538. +#ifndef IPKG_DOWNLOAD_H
  3539. +#define IPKG_DOWNLOAD_H
  3540. +
  3541. +#include "ipkg_conf.h"
  3542. +
  3543. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
  3544. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
  3545. +/*
  3546. + * Downloads file from url, installs in package database, return package name.
  3547. + */
  3548. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
  3549. +
  3550. +#endif
  3551. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg.h busybox-1.17.0/archival/libipkg/ipkg.h
  3552. --- busybox-1.17.0.orig/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
  3553. +++ busybox-1.17.0/archival/libipkg/ipkg.h 2010-07-16 14:45:14.818000815 +0200
  3554. @@ -0,0 +1,68 @@
  3555. +/* ipkg.h - the itsy package management system
  3556. +
  3557. + Carl D. Worth
  3558. +
  3559. + Copyright (C) 2001 University of Southern California
  3560. +
  3561. + This program is free software; you can redistribute it and/or
  3562. + modify it under the terms of the GNU General Public License as
  3563. + published by the Free Software Foundation; either version 2, or (at
  3564. + your option) any later version.
  3565. +
  3566. + This program is distributed in the hope that it will be useful, but
  3567. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3568. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3569. + General Public License for more details.
  3570. +*/
  3571. +
  3572. +#ifndef IPKG_H
  3573. +#define IPKG_H
  3574. +
  3575. +#include "libbb.h"
  3576. +
  3577. +#include "ipkg_includes.h"
  3578. +#include "ipkg_conf.h"
  3579. +#include "ipkg_message.h"
  3580. +
  3581. +#define IPKG_PKG_EXTENSION ".ipk"
  3582. +#define DPKG_PKG_EXTENSION ".deb"
  3583. +
  3584. +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
  3585. +#define IPKG_PKG_VERSION_SEP_CHAR '_'
  3586. +
  3587. +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
  3588. +#define IPKG_LISTS_DIR_SUFFIX "lists"
  3589. +#define IPKG_INFO_DIR_SUFFIX "info"
  3590. +#define IPKG_STATUS_FILE_SUFFIX "status"
  3591. +
  3592. +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
  3593. +
  3594. +#define IPKG_LIST_DESCRIPTION_LENGTH 128
  3595. +
  3596. +#define IPKG_VERSION "1.00"
  3597. +
  3598. +
  3599. +enum ipkg_error {
  3600. + IPKG_SUCCESS = 0,
  3601. + IPKG_PKG_DEPS_UNSATISFIED,
  3602. + IPKG_PKG_IS_ESSENTIAL,
  3603. + IPKG_PKG_HAS_DEPENDENTS,
  3604. + IPKG_PKG_HAS_NO_CANDIDATE
  3605. +};
  3606. +typedef enum ipkg_error ipkg_error_t;
  3607. +
  3608. +extern int ipkg_state_changed;
  3609. +
  3610. +
  3611. +struct errlist {
  3612. + char * errmsg;
  3613. + struct errlist * next;
  3614. +} ;
  3615. +
  3616. +extern struct errlist* error_list;
  3617. +
  3618. +extern ipkg_conf_t *global_conf;
  3619. +
  3620. +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
  3621. +
  3622. +#endif
  3623. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_includes.h busybox-1.17.0/archival/libipkg/ipkg_includes.h
  3624. --- busybox-1.17.0.orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
  3625. +++ busybox-1.17.0/archival/libipkg/ipkg_includes.h 2010-07-16 14:46:37.026220036 +0200
  3626. @@ -0,0 +1,82 @@
  3627. +#ifndef IPKG_INCLUDES_H
  3628. +#define IPKG_INCLUDES_H
  3629. +
  3630. +/* Define to 1 if you have the <memory.h> header file. */
  3631. +#define HAVE_MEMORY_H 1
  3632. +
  3633. +/* Define to 1 if you have the <regex.h> header file. */
  3634. +#define HAVE_REGEX_H 1
  3635. +
  3636. +/* Define to 1 if you have the <stdlib.h> header file. */
  3637. +#define HAVE_STDLIB_H 1
  3638. +
  3639. +/* Define to 1 if you have the <strings.h> header file. */
  3640. +#define HAVE_STRINGS_H 1
  3641. +
  3642. +/* Define to 1 if you have the <string.h> header file. */
  3643. +#define HAVE_STRING_H 1
  3644. +
  3645. +/* Define to 1 if you have the <sys/stat.h> header file. */
  3646. +#define HAVE_SYS_STAT_H 1
  3647. +
  3648. +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
  3649. +#define HAVE_SYS_WAIT_H 1
  3650. +
  3651. +/* Define to 1 if you have the <unistd.h> header file. */
  3652. +#define HAVE_UNISTD_H 1
  3653. +
  3654. +/* Define to 1 if you have the ANSI C header files. */
  3655. +#define STDC_HEADERS 1
  3656. +
  3657. +
  3658. +#include <stdio.h>
  3659. +
  3660. +#if STDC_HEADERS
  3661. +# include <stdlib.h>
  3662. +# include <stdarg.h>
  3663. +# include <stddef.h>
  3664. +# include <ctype.h>
  3665. +# include <errno.h>
  3666. +#else
  3667. +# if HAVE_STDLIB_H
  3668. +# include <stdlib.h>
  3669. +# endif
  3670. +#endif
  3671. +
  3672. +#if HAVE_REGEX_H
  3673. +# include <regex.h>
  3674. +#endif
  3675. +
  3676. +#if HAVE_STRING_H
  3677. +# if !STDC_HEADERS && HAVE_MEMORY_H
  3678. +# include <memory.h>
  3679. +# endif
  3680. +/* XXX: What's the right way to pick up GNU's strndup declaration? */
  3681. +# if __GNUC__
  3682. +# define __USE_GNU 1
  3683. +# endif
  3684. +# include <string.h>
  3685. +# undef __USE_GNU
  3686. +#endif
  3687. +
  3688. +#if HAVE_STRINGS_H
  3689. +# include <strings.h>
  3690. +#endif
  3691. +
  3692. +#if HAVE_SYS_STAT_H
  3693. +# include <sys/stat.h>
  3694. +#endif
  3695. +
  3696. +#if HAVE_SYS_WAIT_H
  3697. +# include <sys/wait.h>
  3698. +#endif
  3699. +
  3700. +#if HAVE_UNISTD_H
  3701. +# include <sys/types.h>
  3702. +# include <unistd.h>
  3703. +#endif
  3704. +
  3705. +#include <sys/mount.h>
  3706. +#include <mntent.h>
  3707. +
  3708. +#endif /* IPKG_INCLUDES_H */
  3709. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_install.c busybox-1.17.0/archival/libipkg/ipkg_install.c
  3710. --- busybox-1.17.0.orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
  3711. +++ busybox-1.17.0/archival/libipkg/ipkg_install.c 2010-07-16 14:45:14.918001768 +0200
  3712. @@ -0,0 +1,1982 @@
  3713. +/* ipkg_install.c - the itsy package management system
  3714. +
  3715. + Carl D. Worth
  3716. +
  3717. + Copyright (C) 2001 University of Southern California
  3718. +
  3719. + This program is free software; you can redistribute it and/or
  3720. + modify it under the terms of the GNU General Public License as
  3721. + published by the Free Software Foundation; either version 2, or (at
  3722. + your option) any later version.
  3723. +
  3724. + This program is distributed in the hope that it will be useful, but
  3725. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3726. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3727. + General Public License for more details.
  3728. +*/
  3729. +
  3730. +#include "ipkg.h"
  3731. +#include <errno.h>
  3732. +#include <dirent.h>
  3733. +#include <glob.h>
  3734. +#include <time.h>
  3735. +#include <signal.h>
  3736. +typedef void (*sighandler_t)(int);
  3737. +
  3738. +#include "pkg.h"
  3739. +#include "pkg_hash.h"
  3740. +#include "pkg_extract.h"
  3741. +
  3742. +#include "ipkg_install.h"
  3743. +#include "ipkg_configure.h"
  3744. +#include "ipkg_download.h"
  3745. +#include "ipkg_remove.h"
  3746. +
  3747. +#include "ipkg_utils.h"
  3748. +#include "ipkg_message.h"
  3749. +
  3750. +#include "sprintf_alloc.h"
  3751. +#include "file_util.h"
  3752. +#include "str_util.h"
  3753. +#include "xsystem.h"
  3754. +#include "user.h"
  3755. +
  3756. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  3757. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
  3758. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
  3759. +
  3760. +/*
  3761. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3762. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3763. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3764. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3765. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3766. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3767. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3768. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
  3769. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3770. +*/
  3771. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3772. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3773. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg);
  3774. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3775. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg);
  3776. +
  3777. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3778. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3779. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
  3780. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
  3781. +
  3782. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
  3783. +
  3784. +static int user_prefers_old_conffile(const char *file, const char *backup);
  3785. +
  3786. +static char *backup_filename_alloc(const char *file_name);
  3787. +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
  3788. +static int backup_exists_for(const char *file_name);
  3789. +static int backup_remove(const char *file_name);
  3790. +
  3791. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees);
  3792. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3793. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3794. +
  3795. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
  3796. +{
  3797. + int err, cmp;
  3798. + pkg_t *pkg, *old;
  3799. + char *old_version, *new_version;
  3800. +
  3801. + pkg = pkg_new();
  3802. + if (pkg == NULL) {
  3803. + return ENOMEM;
  3804. + }
  3805. +
  3806. + err = pkg_init_from_file(pkg, filename);
  3807. + if (err) {
  3808. + return err;
  3809. + }
  3810. +
  3811. + if (!pkg->architecture) {
  3812. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3813. + return -EINVAL;
  3814. + }
  3815. +
  3816. + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
  3817. + freeing the pkg that we pass in. It might be nice to clean this up
  3818. + if possible. */
  3819. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3820. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  3821. +
  3822. + pkg->local_filename = strdup(filename);
  3823. +
  3824. + if (old) {
  3825. + old_version = pkg_version_str_alloc(old);
  3826. + new_version = pkg_version_str_alloc(pkg);
  3827. +
  3828. + cmp = pkg_compare_versions(old, pkg);
  3829. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3830. + cmp = -1 ; /* then we force ipkg to downgrade */
  3831. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3832. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3833. + }
  3834. + if (cmp > 0) {
  3835. + ipkg_message(conf, IPKG_NOTICE,
  3836. + "Not downgrading package %s on %s from %s to %s.\n",
  3837. + old->name, old->dest->name, old_version, new_version);
  3838. + pkg->state_want = SW_DEINSTALL;
  3839. + pkg->state_flag |= SF_OBSOLETE;
  3840. + free(old_version);
  3841. + free(new_version);
  3842. + return 0;
  3843. + } else {
  3844. + free(old_version);
  3845. + free(new_version);
  3846. + }
  3847. + }
  3848. +
  3849. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3850. + return ipkg_install_pkg(conf, pkg,0);
  3851. +}
  3852. +
  3853. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3854. +{
  3855. + int cmp;
  3856. + pkg_t *old, *new;
  3857. + char *old_version, *new_version;
  3858. +
  3859. + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
  3860. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  3861. + if ( old )
  3862. + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
  3863. +
  3864. + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
  3865. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  3866. + if ( new )
  3867. + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
  3868. +
  3869. +/* Pigi Basically here is broken the version stuff.
  3870. + What's happening is that nothing provide the version to differents
  3871. + functions, so the returned struct is always the latest.
  3872. + That's why the install by name don't work.
  3873. +*/
  3874. + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
  3875. +
  3876. + if ( old )
  3877. + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
  3878. + if ( new )
  3879. + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
  3880. + ipkg_message(conf, IPKG_DEBUG2, " \n");
  3881. +
  3882. + if (new == NULL) {
  3883. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3884. + }
  3885. +
  3886. + new->state_flag |= SF_USER;
  3887. + if (old) {
  3888. + old_version = pkg_version_str_alloc(old);
  3889. + new_version = pkg_version_str_alloc(new);
  3890. +
  3891. + cmp = pkg_compare_versions(old, new);
  3892. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3893. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
  3894. + cmp = -1 ; /* then we force ipkg to downgrade */
  3895. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3896. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3897. + }
  3898. + ipkg_message(conf, IPKG_DEBUG,
  3899. + "Comparing visible versions of pkg %s:"
  3900. + "\n\t%s is installed "
  3901. + "\n\t%s is available "
  3902. + "\n\t%d was comparison result\n",
  3903. + pkg_name, old_version, new_version, cmp);
  3904. + if (cmp == 0 && !conf->force_reinstall) {
  3905. + ipkg_message(conf, IPKG_NOTICE,
  3906. + "Package %s (%s) installed in %s is up to date.\n",
  3907. + old->name, old_version, old->dest->name);
  3908. + free(old_version);
  3909. + free(new_version);
  3910. + return 0;
  3911. + } else if (cmp > 0) {
  3912. + ipkg_message(conf, IPKG_NOTICE,
  3913. + "Not downgrading package %s on %s from %s to %s.\n",
  3914. + old->name, old->dest->name, old_version, new_version);
  3915. + free(old_version);
  3916. + free(new_version);
  3917. + return 0;
  3918. + } else if (cmp < 0) {
  3919. + new->dest = old->dest;
  3920. + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
  3921. + }
  3922. + }
  3923. +
  3924. + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
  3925. + supposed to be an ipkg_error_t, but ipkg_install_pkg could
  3926. + return any kind of integer, (might be errno from a syscall,
  3927. + etc.). This is a real mess and will need to be cleaned up if
  3928. + anyone ever wants to make a nice libipkg. */
  3929. +
  3930. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3931. + return ipkg_install_pkg(conf, new,0);
  3932. +}
  3933. +
  3934. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3935. +{
  3936. + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
  3937. + int i;
  3938. + ipkg_error_t err;
  3939. + abstract_pkg_t *ppkg ;
  3940. +
  3941. + if (providers == NULL)
  3942. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3943. +
  3944. + for (i = 0; i < providers->len; i++) {
  3945. + ppkg = abstract_pkg_vec_get(providers, i);
  3946. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
  3947. + err = ipkg_install_by_name(conf, ppkg->name);
  3948. + if (err)
  3949. + return err;
  3950. +/* XXX Maybe ppkg should be freed ? */
  3951. + }
  3952. + return 0;
  3953. +}
  3954. +
  3955. +/*
  3956. + * Walk dependence graph starting with pkg, collect packages to be
  3957. + * installed into pkgs_needed, in dependence order.
  3958. + */
  3959. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
  3960. +{
  3961. + int i, err;
  3962. + pkg_vec_t *depends = pkg_vec_alloc();
  3963. + char **unresolved = NULL;
  3964. + int ndepends;
  3965. +
  3966. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  3967. + pkg, depends,
  3968. + &unresolved);
  3969. +
  3970. + if (unresolved) {
  3971. + ipkg_message(conf, IPKG_ERROR,
  3972. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  3973. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  3974. + while (*unresolved) {
  3975. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  3976. + unresolved++;
  3977. + }
  3978. + ipkg_message(conf, IPKG_ERROR, "\n");
  3979. + if (! conf->force_depends) {
  3980. + ipkg_message(conf, IPKG_INFO,
  3981. + "This could mean that your package list is out of date or that the packages\n"
  3982. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  3983. + "of this problem try again with the '-force-depends' option.\n");
  3984. + pkg_vec_free(depends);
  3985. + return IPKG_PKG_DEPS_UNSATISFIED;
  3986. + }
  3987. + }
  3988. +
  3989. + if (ndepends <= 0) {
  3990. + pkg_vec_free(depends);
  3991. + return 0;
  3992. + }
  3993. +
  3994. + for (i = 0; i < depends->len; i++) {
  3995. + pkg_t *dep = depends->pkgs[i];
  3996. + /* The package was uninstalled when we started, but another
  3997. + dep earlier in this loop may have depended on it and pulled
  3998. + it in, so check first. */
  3999. + if ((dep->state_status != SS_INSTALLED)
  4000. + && (dep->state_status != SS_UNPACKED)
  4001. + && (dep->state_want != SW_INSTALL)) {
  4002. +
  4003. + /* Mark packages as to-be-installed */
  4004. + dep->state_want = SW_INSTALL;
  4005. +
  4006. + /* Dependencies should be installed the same place as pkg */
  4007. + if (dep->dest == NULL) {
  4008. + dep->dest = pkg->dest;
  4009. + }
  4010. +
  4011. + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
  4012. + if (err) {
  4013. + pkg_vec_free(depends);
  4014. + return err;
  4015. + }
  4016. + }
  4017. + }
  4018. + if (pkgs_needed)
  4019. + pkg_vec_insert(pkgs_needed, pkg);
  4020. +
  4021. + pkg_vec_free(depends);
  4022. +
  4023. + return 0;
  4024. +}
  4025. +
  4026. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
  4027. +{
  4028. + int cmp;
  4029. + pkg_t *old, *new;
  4030. + char *old_version, *new_version;
  4031. +
  4032. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  4033. +
  4034. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  4035. + if (new == NULL) {
  4036. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4037. + }
  4038. + if (old) {
  4039. + old_version = pkg_version_str_alloc(old);
  4040. + new_version = pkg_version_str_alloc(new);
  4041. +
  4042. + cmp = pkg_compare_versions(old, new);
  4043. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4044. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
  4045. + cmp = -1 ; /* then we force ipkg to downgrade */
  4046. + /* We need to use a value < 0 because in the 0 case we are asking to */
  4047. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4048. + }
  4049. + ipkg_message(conf, IPKG_DEBUG,
  4050. + "comparing visible versions of pkg %s:"
  4051. + "\n\t%s is installed "
  4052. + "\n\t%s is available "
  4053. + "\n\t%d was comparison result\n",
  4054. + pkg_name, old_version, new_version, cmp);
  4055. + if (cmp == 0 && !conf->force_reinstall) {
  4056. + ipkg_message(conf, IPKG_NOTICE,
  4057. + "Package %s (%s) installed in %s is up to date.\n",
  4058. + old->name, old_version, old->dest->name);
  4059. + free(old_version);
  4060. + free(new_version);
  4061. + return 0;
  4062. + } else if (cmp > 0) {
  4063. + ipkg_message(conf, IPKG_NOTICE,
  4064. + "Not downgrading package %s on %s from %s to %s.\n",
  4065. + old->name, old->dest->name, old_version, new_version);
  4066. + free(old_version);
  4067. + free(new_version);
  4068. + return 0;
  4069. + } else if (cmp < 0) {
  4070. + new->dest = old->dest;
  4071. + old->state_want = SW_DEINSTALL;
  4072. + old->state_flag |= SF_OBSOLETE;
  4073. + }
  4074. + }
  4075. + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
  4076. +}
  4077. +
  4078. +
  4079. +
  4080. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
  4081. +{
  4082. + int i, err;
  4083. + pkg_vec_t *depends = pkg_vec_alloc();
  4084. + pkg_t *dep;
  4085. + char **unresolved = NULL;
  4086. + int ndepends;
  4087. +
  4088. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4089. + pkg, depends,
  4090. + &unresolved);
  4091. +
  4092. + if (unresolved) {
  4093. + ipkg_message(conf, IPKG_ERROR,
  4094. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4095. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4096. + while (*unresolved) {
  4097. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4098. + unresolved++;
  4099. + }
  4100. + ipkg_message(conf, IPKG_ERROR, "\n");
  4101. + if (! conf->force_depends) {
  4102. + ipkg_message(conf, IPKG_INFO,
  4103. + "This could mean that your package list is out of date or that the packages\n"
  4104. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4105. + "of this problem try again with the '-force-depends' option.\n");
  4106. + pkg_vec_free(depends);
  4107. + return IPKG_PKG_DEPS_UNSATISFIED;
  4108. + }
  4109. + }
  4110. +
  4111. + if (ndepends <= 0) {
  4112. + return 0;
  4113. + }
  4114. +
  4115. + /* Mark packages as to-be-installed */
  4116. + for (i=0; i < depends->len; i++) {
  4117. + /* Dependencies should be installed the same place as pkg */
  4118. + if (depends->pkgs[i]->dest == NULL) {
  4119. + depends->pkgs[i]->dest = pkg->dest;
  4120. + }
  4121. + depends->pkgs[i]->state_want = SW_INSTALL;
  4122. + }
  4123. +
  4124. + for (i = 0; i < depends->len; i++) {
  4125. + dep = depends->pkgs[i];
  4126. + /* The package was uninstalled when we started, but another
  4127. + dep earlier in this loop may have depended on it and pulled
  4128. + it in, so check first. */
  4129. + if ((dep->state_status != SS_INSTALLED)
  4130. + && (dep->state_status != SS_UNPACKED)) {
  4131. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4132. + err = ipkg_install_pkg(conf, dep,0);
  4133. + if (err) {
  4134. + pkg_vec_free(depends);
  4135. + return err;
  4136. + }
  4137. + }
  4138. + }
  4139. +
  4140. + pkg_vec_free(depends);
  4141. +
  4142. + return 0;
  4143. +}
  4144. +
  4145. +
  4146. +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
  4147. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
  4148. +{
  4149. + if (conf->nodeps == 0) {
  4150. + int i;
  4151. + pkg_vec_t *installed = pkg_vec_alloc();
  4152. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  4153. + for (i = 0; i < installed->len; i++) {
  4154. + pkg_t *pkg = installed->pkgs[i];
  4155. + satisfy_dependencies_for(conf, pkg);
  4156. + }
  4157. + pkg_vec_free(installed);
  4158. + }
  4159. + return 0;
  4160. +}
  4161. +
  4162. +
  4163. +
  4164. +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
  4165. +{
  4166. + int i;
  4167. + pkg_vec_t *conflicts = NULL;
  4168. + int level;
  4169. + const char *prefix;
  4170. + if (conf->force_depends) {
  4171. + level = IPKG_NOTICE;
  4172. + prefix = "Warning";
  4173. + } else {
  4174. + level = IPKG_ERROR;
  4175. + prefix = "ERROR";
  4176. + }
  4177. +
  4178. + if (!conf->force_depends)
  4179. + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(pkg);
  4180. +
  4181. + if (conflicts) {
  4182. + ipkg_message(conf, level,
  4183. + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
  4184. + i = 0;
  4185. + while (i < conflicts->len)
  4186. + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
  4187. + ipkg_message(conf, level, "\n");
  4188. + pkg_vec_free(conflicts);
  4189. + return IPKG_PKG_DEPS_UNSATISFIED;
  4190. + }
  4191. + return 0;
  4192. +}
  4193. +
  4194. +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
  4195. +{
  4196. + str_list_t *new_list = pkg_get_installed_files(new_pkg);
  4197. + str_list_elt_t *iter;
  4198. +
  4199. + for (iter = new_list->head; iter; iter = iter->next) {
  4200. + char *new_file = iter->data;
  4201. + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
  4202. + if (!new_file)
  4203. + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
  4204. + if (!owner || (owner == old_pkg))
  4205. + file_hash_set_file_owner(conf, new_file, new_pkg);
  4206. + }
  4207. + if (old_pkg) {
  4208. + str_list_t *old_list = pkg_get_installed_files(old_pkg);
  4209. + for (iter = old_list->head; iter; iter = iter->next) {
  4210. + char *old_file = iter->data;
  4211. + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
  4212. + if (owner == old_pkg) {
  4213. + /* obsolete */
  4214. + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
  4215. + }
  4216. + }
  4217. + }
  4218. + return 0;
  4219. +}
  4220. +
  4221. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
  4222. +{
  4223. + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
  4224. +
  4225. + /* sma 6.20.02: yup; here's the first bit */
  4226. + /*
  4227. + * XXX: BUG easy for cworth
  4228. + * 1) please point the call below to the correct current root destination
  4229. + * 2) we need to resolve how to check the required space for a pending pkg,
  4230. + * my diddling with the .ipk file size below isn't going to cut it.
  4231. + * 3) return a proper error code instead of 1
  4232. + */
  4233. + int comp_size, blocks_available;
  4234. +
  4235. + if (!conf->force_space && pkg->installed_size != NULL) {
  4236. + blocks_available = get_available_blocks(conf->default_dest->root_dir);
  4237. +
  4238. + comp_size = strtoul(pkg->installed_size, NULL, 0);
  4239. + /* round up a blocks count without doing fancy-but-slow casting jazz */
  4240. + comp_size = (int)((comp_size + 1023) / 1024);
  4241. +
  4242. + if (comp_size >= blocks_available) {
  4243. + ipkg_message(conf, IPKG_ERROR,
  4244. + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
  4245. + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
  4246. + return ENOSPC;
  4247. + }
  4248. + }
  4249. + return 0;
  4250. +}
  4251. +
  4252. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
  4253. +{
  4254. + int err;
  4255. + char *conffiles_file_name;
  4256. + char *root_dir;
  4257. + FILE *conffiles_file;
  4258. +
  4259. + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
  4260. +
  4261. + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
  4262. + if (pkg->tmp_unpack_dir == NULL) {
  4263. + ipkg_message(conf, IPKG_ERROR,
  4264. + "%s: Failed to create temporary directory '%s': %s\n",
  4265. + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
  4266. + return errno;
  4267. + }
  4268. +
  4269. + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
  4270. + if (err) {
  4271. + return err;
  4272. + }
  4273. +
  4274. + /* XXX: CLEANUP: There might be a cleaner place to read in the
  4275. + conffiles. Seems like I should be able to get everything to go
  4276. + through pkg_init_from_file. If so, maybe it would make sense to
  4277. + move all of unpack_pkg_control_files to that function. */
  4278. +
  4279. + /* Don't need to re-read conffiles if we already have it */
  4280. + if (pkg->conffiles.head) {
  4281. + return 0;
  4282. + }
  4283. +
  4284. + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
  4285. + if (! file_exists(conffiles_file_name)) {
  4286. + free(conffiles_file_name);
  4287. + return 0;
  4288. + }
  4289. +
  4290. + conffiles_file = fopen(conffiles_file_name, "r");
  4291. + if (conffiles_file == NULL) {
  4292. + fprintf(stderr, "%s: failed to open %s: %s\n",
  4293. + __FUNCTION__, conffiles_file_name, strerror(errno));
  4294. + free(conffiles_file_name);
  4295. + return errno;
  4296. + }
  4297. + free(conffiles_file_name);
  4298. +
  4299. + while (1) {
  4300. + char *cf_name;
  4301. + char *cf_name_in_dest;
  4302. +
  4303. + cf_name = file_read_line_alloc(conffiles_file);
  4304. + if (cf_name == NULL) {
  4305. + break;
  4306. + }
  4307. + str_chomp(cf_name);
  4308. + if (cf_name[0] == '\0') {
  4309. + continue;
  4310. + }
  4311. +
  4312. + /* Prepend dest->root_dir to conffile name.
  4313. + Take pains to avoid multiple slashes. */
  4314. + root_dir = pkg->dest->root_dir;
  4315. + if (conf->offline_root)
  4316. + /* skip the offline_root prefix */
  4317. + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
  4318. + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
  4319. + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
  4320. +
  4321. + /* Can't get an md5sum now, (file isn't extracted yet).
  4322. + We'll wait until resolve_conffiles */
  4323. + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
  4324. +
  4325. + free(cf_name);
  4326. + free(cf_name_in_dest);
  4327. + }
  4328. +
  4329. + fclose(conffiles_file);
  4330. +
  4331. + return 0;
  4332. +}
  4333. +
  4334. +/* returns number of installed replacees */
  4335. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees)
  4336. +{
  4337. + abstract_pkg_t **replaces = pkg->replaces;
  4338. + int replaces_count = pkg->replaces_count;
  4339. + int i, j;
  4340. + for (i = 0; i < replaces_count; i++) {
  4341. + abstract_pkg_t *ab_pkg = replaces[i];
  4342. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  4343. + if (pkg_vec) {
  4344. + for (j = 0; j < pkg_vec->len; j++) {
  4345. + pkg_t *replacee = pkg_vec->pkgs[j];
  4346. + if (!pkg_conflicts(pkg, replacee))
  4347. + continue;
  4348. + if (replacee->state_status == SS_INSTALLED) {
  4349. + pkg_vec_insert(installed_replacees, replacee);
  4350. + }
  4351. + }
  4352. + }
  4353. + }
  4354. + return installed_replacees->len;
  4355. +}
  4356. +
  4357. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4358. +{
  4359. + int i;
  4360. + int replaces_count = replacees->len;
  4361. + for (i = 0; i < replaces_count; i++) {
  4362. + pkg_t *replacee = replacees->pkgs[i];
  4363. + int err;
  4364. + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
  4365. + err = ipkg_remove_pkg(conf, replacee,0);
  4366. + if (err)
  4367. + return err;
  4368. + }
  4369. + return 0;
  4370. +}
  4371. +
  4372. +/* to unwind the removal: make sure they are installed */
  4373. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4374. +{
  4375. + int i, err;
  4376. + int replaces_count = replacees->len;
  4377. + for (i = 0; i < replaces_count; i++) {
  4378. + pkg_t *replacee = replacees->pkgs[i];
  4379. + if (replacee->state_status != SS_INSTALLED) {
  4380. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4381. + err = ipkg_install_pkg(conf, replacee,0);
  4382. + if (err)
  4383. + return err;
  4384. + }
  4385. + }
  4386. + return 0;
  4387. +}
  4388. +
  4389. +int caught_sigint = 0;
  4390. +static void ipkg_install_pkg_sigint_handler(int sig)
  4391. +{
  4392. + caught_sigint = sig;
  4393. +}
  4394. +
  4395. +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
  4396. +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
  4397. +{
  4398. + if (old_pkg) {
  4399. + char message_out[15];
  4400. + char *old_version = pkg_version_str_alloc(old_pkg);
  4401. + char *new_version = pkg_version_str_alloc(pkg);
  4402. + int cmp = pkg_compare_versions(old_pkg, pkg);
  4403. + int rc = 0;
  4404. +
  4405. + memset(message_out,'\x0',15);
  4406. + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
  4407. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4408. + cmp = -1 ; /* then we force ipkg to downgrade */
  4409. + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
  4410. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4411. + }
  4412. +
  4413. + if (cmp > 0) {
  4414. + ipkg_message(conf, IPKG_NOTICE,
  4415. + "Not downgrading package %s on %s from %s to %s.\n",
  4416. + old_pkg->name, old_pkg->dest->name, old_version, new_version);
  4417. + rc = 1;
  4418. + } else if (cmp < 0) {
  4419. + ipkg_message(conf, IPKG_NOTICE,
  4420. + "%s%s on %s from %s to %s...\n",
  4421. + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
  4422. + pkg->dest = old_pkg->dest;
  4423. + rc = 0;
  4424. + } else /* cmp == 0 */ {
  4425. + if (conf->force_reinstall) {
  4426. + ipkg_message(conf, IPKG_NOTICE,
  4427. + "Reinstalling %s (%s) on %s...\n",
  4428. + pkg->name, new_version, old_pkg->dest->name);
  4429. + pkg->dest = old_pkg->dest;
  4430. + rc = 0;
  4431. + } else {
  4432. + ipkg_message(conf, IPKG_NOTICE,
  4433. + "Not installing %s (%s) on %s -- already installed.\n",
  4434. + pkg->name, new_version, old_pkg->dest->name);
  4435. + rc = 1;
  4436. + }
  4437. + }
  4438. + free(old_version);
  4439. + free(new_version);
  4440. + return rc;
  4441. + } else {
  4442. + char message_out[15], *version ;
  4443. + memset(message_out,'\x0',15);
  4444. + if ( message )
  4445. + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
  4446. + else
  4447. + strncpy( message_out,"Installing ",strlen("Installing ") );
  4448. + version = pkg_version_str_alloc(pkg);
  4449. +
  4450. + ipkg_message(conf, IPKG_NOTICE,
  4451. + "%s%s (%s) to %s...\n", message_out,
  4452. + pkg->name, version, pkg->dest->name);
  4453. + free(version);
  4454. + return 0;
  4455. + }
  4456. +}
  4457. +
  4458. +/* and now the meat... */
  4459. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
  4460. +{
  4461. + int err = 0;
  4462. + int message = 0;
  4463. + pkg_t *old_pkg = NULL;
  4464. + pkg_vec_t *replacees;
  4465. + abstract_pkg_t *ab_pkg = NULL;
  4466. + int old_state_flag;
  4467. + uint8_t *file_md5;
  4468. +
  4469. +
  4470. + if ( from_upgrade )
  4471. + message = 1; /* Coming from an upgrade, and should change the output message */
  4472. +
  4473. + if (!pkg) {
  4474. + ipkg_message(conf, IPKG_ERROR,
  4475. + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
  4476. + return -EINVAL;
  4477. + }
  4478. +
  4479. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
  4480. +
  4481. + if (!pkg_arch_supported(conf, pkg)) {
  4482. + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
  4483. + pkg->architecture, pkg->name);
  4484. + return -EINVAL;
  4485. + }
  4486. + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
  4487. + err = satisfy_dependencies_for(conf, pkg);
  4488. + if (err) { return err; }
  4489. +
  4490. + ipkg_message(conf, IPKG_NOTICE,
  4491. + "Package %s is already installed in %s.\n",
  4492. + pkg->name, pkg->dest->name);
  4493. + return 0;
  4494. + }
  4495. +
  4496. + if (pkg->dest == NULL) {
  4497. + pkg->dest = conf->default_dest;
  4498. + }
  4499. +
  4500. + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  4501. +
  4502. + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
  4503. + if (err) { return err; }
  4504. +
  4505. + pkg->state_want = SW_INSTALL;
  4506. + if (old_pkg){
  4507. + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
  4508. + }
  4509. +
  4510. +
  4511. + /* Abhaya: conflicts check */
  4512. + err = check_conflicts_for(conf, pkg);
  4513. + if (err) { return err; }
  4514. +
  4515. + /* this setup is to remove the upgrade scenario in the end when
  4516. + installing pkg A, A deps B & B deps on A. So both B and A are
  4517. + installed. Then A's installation is started resulting in an
  4518. + uncecessary upgrade */
  4519. + if (pkg->state_status == SS_INSTALLED
  4520. + && conf->force_reinstall == 0) return 0;
  4521. +
  4522. + err = verify_pkg_installable(conf, pkg);
  4523. + if (err) { return err; }
  4524. +
  4525. + if (pkg->local_filename == NULL) {
  4526. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  4527. + if (err) {
  4528. + ipkg_message(conf, IPKG_ERROR,
  4529. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  4530. + pkg->name);
  4531. + return err;
  4532. + }
  4533. + }
  4534. +
  4535. +/* Check for md5 values */
  4536. + if (pkg->md5sum)
  4537. + {
  4538. + file_md5 = file_md5sum_alloc(pkg->local_filename);
  4539. + if (strcmp((char *)file_md5, pkg->md5sum))
  4540. + {
  4541. + ipkg_message(conf, IPKG_ERROR,
  4542. + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
  4543. + pkg->name);
  4544. + free(file_md5);
  4545. + return err;
  4546. + }
  4547. + free(file_md5);
  4548. + }
  4549. +
  4550. + if (pkg->tmp_unpack_dir == NULL) {
  4551. + unpack_pkg_control_files(conf, pkg);
  4552. + }
  4553. +
  4554. + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
  4555. +/* Pigi: check if it will pass from here when replacing. It seems to fail */
  4556. +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
  4557. + err = update_file_ownership(conf, pkg, old_pkg);
  4558. + if (err) { return err; }
  4559. +
  4560. + if (conf->nodeps == 0) {
  4561. + err = satisfy_dependencies_for(conf, pkg);
  4562. + if (err) { return err; }
  4563. + }
  4564. +
  4565. + replacees = pkg_vec_alloc();
  4566. + pkg_get_installed_replacees(pkg, replacees);
  4567. +
  4568. + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
  4569. + {
  4570. + sigset_t newset, oldset;
  4571. + sighandler_t old_handler = NULL;
  4572. + int use_signal = 0;
  4573. + caught_sigint = 0;
  4574. + if (use_signal) {
  4575. + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
  4576. + } else {
  4577. + sigemptyset(&newset);
  4578. + sigaddset(&newset, SIGINT);
  4579. + sigprocmask(SIG_BLOCK, &newset, &oldset);
  4580. + }
  4581. +
  4582. + ipkg_state_changed++;
  4583. + pkg->state_flag |= SF_FILELIST_CHANGED;
  4584. +
  4585. + /* XXX: BUG: we really should treat replacement more like an upgrade
  4586. + * Instead, we're going to remove the replacees
  4587. + */
  4588. + err = pkg_remove_installed_replacees(conf, replacees);
  4589. + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
  4590. +
  4591. + /*
  4592. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  4593. + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
  4594. +
  4595. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  4596. + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
  4597. + */
  4598. +
  4599. + err = preinst_configure(conf, pkg, old_pkg);
  4600. + /*
  4601. + if (err) goto UNWIND_PREINST_CONFIGURE;
  4602. + */
  4603. +
  4604. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  4605. + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
  4606. +
  4607. + err = check_data_file_clashes(conf, pkg, old_pkg);
  4608. + /*
  4609. + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
  4610. +
  4611. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  4612. + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
  4613. + */
  4614. +
  4615. + if (conf->noaction) return 0;
  4616. +
  4617. + /* point of no return: no unwinding after this */
  4618. + if (old_pkg && !conf->force_reinstall) {
  4619. + old_pkg->state_want = SW_DEINSTALL;
  4620. +
  4621. + if (old_pkg->state_flag & SF_NOPRUNE) {
  4622. + ipkg_message(conf, IPKG_INFO,
  4623. + " not removing obsolesced files because package marked noprune\n");
  4624. + } else {
  4625. + ipkg_message(conf, IPKG_INFO,
  4626. + " removing obsolesced files\n");
  4627. + remove_obsolesced_files(conf, pkg, old_pkg);
  4628. + }
  4629. + /* removing files from old package, to avoid ghost files */
  4630. + remove_data_files_and_list(conf, old_pkg);
  4631. +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
  4632. + remove_maintainer_scripts_except_postrm(conf, old_pkg);
  4633. + remove_postrm(conf, old_pkg);
  4634. +/* Pigi */
  4635. +
  4636. + }
  4637. +
  4638. +
  4639. + ipkg_message(conf, IPKG_INFO,
  4640. + " installing maintainer scripts\n");
  4641. + install_maintainer_scripts(conf, pkg, old_pkg);
  4642. +
  4643. + /* the following just returns 0
  4644. + remove_disappeared(conf, pkg);
  4645. + */
  4646. +
  4647. + ipkg_message(conf, IPKG_INFO,
  4648. + " installing data files\n");
  4649. + install_data_files(conf, pkg);
  4650. +
  4651. +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
  4652. + err = check_data_file_clashes_change(conf, pkg);
  4653. +
  4654. + ipkg_message(conf, IPKG_INFO,
  4655. + " resolving conf files\n");
  4656. + resolve_conffiles(conf, pkg);
  4657. +
  4658. + pkg->state_status = SS_UNPACKED;
  4659. + old_state_flag = pkg->state_flag;
  4660. + pkg->state_flag &= ~SF_PREFER;
  4661. + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
  4662. +
  4663. + if (old_pkg && !conf->force_reinstall) {
  4664. + old_pkg->state_status = SS_NOT_INSTALLED;
  4665. + }
  4666. +
  4667. + time(&pkg->installed_time);
  4668. +
  4669. + ipkg_message(conf, IPKG_INFO,
  4670. + " cleanup temp files\n");
  4671. + cleanup_temporary_files(conf, pkg);
  4672. +
  4673. + ab_pkg = pkg->parent;
  4674. + if (ab_pkg)
  4675. + ab_pkg->state_status = pkg->state_status;
  4676. +
  4677. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  4678. +
  4679. + if (use_signal)
  4680. + signal(SIGINT, old_handler);
  4681. + else
  4682. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4683. +
  4684. + return 0;
  4685. +
  4686. +
  4687. + /*
  4688. + UNWIND_POSTRM_UPGRADE_OLD_PKG:
  4689. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4690. + UNWIND_CHECK_DATA_FILE_CLASHES:
  4691. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  4692. + */
  4693. + UNWIND_BACKUP_MODIFIED_CONFFILES:
  4694. + backup_modified_conffiles_unwind(pkg, old_pkg);
  4695. + /*
  4696. + UNWIND_PREINST_CONFIGURE:
  4697. + preinst_configure_unwind(conf, pkg, old_pkg);
  4698. + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
  4699. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  4700. + UNWIND_PRERM_UPGRADE_OLD_PKG:
  4701. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4702. + */
  4703. + UNWIND_REMOVE_INSTALLED_REPLACEES:
  4704. + pkg_remove_installed_replacees_unwind(conf, replacees);
  4705. +
  4706. + ipkg_message(conf, IPKG_INFO,
  4707. + " cleanup temp files\n");
  4708. + cleanup_temporary_files(conf, pkg);
  4709. +
  4710. + ipkg_message(conf, IPKG_INFO,
  4711. + "Failed.\n");
  4712. + if (use_signal)
  4713. + signal(SIGINT, old_handler);
  4714. + else
  4715. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4716. +
  4717. + return err;
  4718. + }
  4719. +}
  4720. +
  4721. +/*
  4722. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4723. +{
  4724. + DPKG_INCOMPATIBILITY:
  4725. + dpkg does some things here that we don't do yet. Do we care?
  4726. +
  4727. + 1. If a version of the package is already installed, call
  4728. + old-prerm upgrade new-version
  4729. + 2. If the script runs but exits with a non-zero exit status
  4730. + new-prerm failed-upgrade old-version
  4731. + Error unwind, for both the above cases:
  4732. + old-postinst abort-upgrade new-version
  4733. + return 0;
  4734. +}
  4735. +*/
  4736. +
  4737. +/*
  4738. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4739. +{
  4740. + DPKG_INCOMPATIBILITY:
  4741. + dpkg does some things here that we don't do yet. Do we care?
  4742. + (See prerm_upgrade_old_package for details)
  4743. +
  4744. + return 0;
  4745. +}
  4746. +*/
  4747. +
  4748. +/*
  4749. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4750. +{
  4751. + DPKG_INCOMPATIBILITY:
  4752. + dpkg does some things here that we don't do yet. Do we care?
  4753. + 2. If a 'conflicting' package is being removed at the same time:
  4754. + 1. If any packages depended on that conflicting package and
  4755. + --auto-deconfigure is specified, call, for each such package:
  4756. + deconfigured's-prerm deconfigure \
  4757. + in-favour package-being-installed version \
  4758. + removing conflicting-package version
  4759. + Error unwind:
  4760. + deconfigured's-postinst abort-deconfigure \
  4761. + in-favour package-being-installed-but-failed version \
  4762. + removing conflicting-package version
  4763. +
  4764. + The deconfigured packages are marked as requiring
  4765. + configuration, so that if --install is used they will be
  4766. + configured again if possible.
  4767. + 2. To prepare for removal of the conflicting package, call:
  4768. + conflictor's-prerm remove in-favour package new-version
  4769. + Error unwind:
  4770. + conflictor's-postinst abort-remove in-favour package new-version
  4771. + return 0;
  4772. +}
  4773. +*/
  4774. +
  4775. +/*
  4776. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4777. +{
  4778. + DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
  4779. + do yet. Do we care? (See prerm_deconfigure_conflictors for
  4780. + details)
  4781. + return 0;
  4782. +}
  4783. +*/
  4784. +
  4785. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4786. +{
  4787. + int err;
  4788. + char *preinst_args;
  4789. +
  4790. + if (old_pkg) {
  4791. + char *old_version = pkg_version_str_alloc(old_pkg);
  4792. + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
  4793. + free(old_version);
  4794. + } else if (pkg->state_status == SS_CONFIG_FILES) {
  4795. + char *pkg_version = pkg_version_str_alloc(pkg);
  4796. + sprintf_alloc(&preinst_args, "install %s", pkg_version);
  4797. + free(pkg_version);
  4798. + } else {
  4799. + preinst_args = strdup("install");
  4800. + }
  4801. +
  4802. + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
  4803. + if (err) {
  4804. + ipkg_message(conf, IPKG_ERROR,
  4805. + "Aborting installation of %s\n", pkg->name);
  4806. + return 1;
  4807. + }
  4808. +
  4809. + free(preinst_args);
  4810. +
  4811. + return 0;
  4812. +}
  4813. +
  4814. +/*
  4815. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4816. +{
  4817. + DPKG_INCOMPATIBILITY:
  4818. + dpkg does the following error unwind, should we?
  4819. + pkg->postrm abort-upgrade old-version
  4820. + OR pkg->postrm abort-install old-version
  4821. + OR pkg->postrm abort-install
  4822. + return 0;
  4823. +}
  4824. +*/
  4825. +
  4826. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4827. +{
  4828. + int err;
  4829. + conffile_list_elt_t *iter;
  4830. + conffile_t *cf;
  4831. +
  4832. + if (conf->noaction) return 0;
  4833. +
  4834. + /* Backup all modified conffiles */
  4835. + if (old_pkg) {
  4836. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4837. + char *cf_name;
  4838. +
  4839. + cf = iter->data;
  4840. + cf_name = root_filename_alloc(conf, cf->name);
  4841. +
  4842. + /* Don't worry if the conffile is just plain gone */
  4843. + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
  4844. + err = backup_make_backup(conf, cf_name);
  4845. + if (err) {
  4846. + return err;
  4847. + }
  4848. + }
  4849. + free(cf_name);
  4850. + }
  4851. + }
  4852. +
  4853. + /* Backup all conffiles that were not conffiles in old_pkg */
  4854. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4855. + char *cf_name;
  4856. + cf = iter->data;
  4857. + cf_name = root_filename_alloc(conf, cf->name);
  4858. + /* Ignore if this was a conffile in old_pkg as well */
  4859. + if (pkg_get_conffile(old_pkg, cf->name)) {
  4860. + continue;
  4861. + }
  4862. +
  4863. + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
  4864. + err = backup_make_backup(conf, cf_name);
  4865. + if (err) {
  4866. + return err;
  4867. + }
  4868. + }
  4869. + free(cf_name);
  4870. + }
  4871. +
  4872. + return 0;
  4873. +}
  4874. +
  4875. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg)
  4876. +{
  4877. + conffile_list_elt_t *iter;
  4878. +
  4879. + if (old_pkg) {
  4880. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4881. + backup_remove(iter->data->name);
  4882. + }
  4883. + }
  4884. +
  4885. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4886. + backup_remove(iter->data->name);
  4887. + }
  4888. +
  4889. + return 0;
  4890. +}
  4891. +
  4892. +
  4893. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4894. +{
  4895. + /* DPKG_INCOMPATIBILITY:
  4896. + ipkg takes a slightly different approach than dpkg at this
  4897. + point. dpkg installs each file in the new package while
  4898. + creating a backup for any file that is replaced, (so that it
  4899. + can unwind if necessary). To avoid complexity and redundant
  4900. + storage, ipkg doesn't do any installation until later, (at the
  4901. + point at which dpkg removes the backups.
  4902. +
  4903. + But, we do have to check for data file clashes, since after
  4904. + installing a package with a file clash, removing either of the
  4905. + packages involved in the clash has the potential to break the
  4906. + other package.
  4907. + */
  4908. + str_list_t *files_list;
  4909. + str_list_elt_t *iter;
  4910. +
  4911. + int clashes = 0;
  4912. +
  4913. + files_list = pkg_get_installed_files(pkg);
  4914. + for (iter = files_list->head; iter; iter = iter->next) {
  4915. + char *root_filename;
  4916. + char *filename = iter->data;
  4917. + root_filename = root_filename_alloc(conf, filename);
  4918. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  4919. + pkg_t *owner;
  4920. + pkg_t *obs;
  4921. + /* Pre-existing conffiles are OK */
  4922. + /* @@@@ should have way to check that it is a conffile -Jamey */
  4923. + if (backup_exists_for(root_filename)) {
  4924. + continue;
  4925. + }
  4926. +
  4927. + /* Pre-existing files are OK if force-overwrite was asserted. */
  4928. + if (conf->force_overwrite) {
  4929. + /* but we need to change who owns this file */
  4930. + file_hash_set_file_owner(conf, filename, pkg);
  4931. + continue;
  4932. + }
  4933. +
  4934. + owner = file_hash_get_file_owner(conf, filename);
  4935. +
  4936. + /* Pre-existing files are OK if owned by the pkg being upgraded. */
  4937. + if (owner && old_pkg) {
  4938. + if (strcmp(owner->name, old_pkg->name) == 0) {
  4939. + continue;
  4940. + }
  4941. + }
  4942. +
  4943. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  4944. + if (owner) {
  4945. + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
  4946. + if (pkg_replaces(pkg, owner)) {
  4947. + continue;
  4948. + }
  4949. +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
  4950. + then it's ok to overwrite. */
  4951. + if (strcmp(owner->name,pkg->name)==0){
  4952. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  4953. + continue;
  4954. + }
  4955. + }
  4956. +
  4957. + /* Pre-existing files are OK if they are obsolete */
  4958. + obs = hash_table_get(&conf->obs_file_hash, filename);
  4959. + if (obs) {
  4960. + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
  4961. + continue;
  4962. + }
  4963. +
  4964. + /* We have found a clash. */
  4965. + ipkg_message(conf, IPKG_ERROR,
  4966. + "Package %s wants to install file %s\n"
  4967. + "\tBut that file is already provided by package ",
  4968. + pkg->name, filename);
  4969. + if (owner) {
  4970. + ipkg_message(conf, IPKG_ERROR,
  4971. + "%s\n", owner->name);
  4972. + } else {
  4973. + ipkg_message(conf, IPKG_ERROR,
  4974. + "<no package>\nPlease move this file out of the way and try again.\n");
  4975. + }
  4976. + clashes++;
  4977. + }
  4978. + free(root_filename);
  4979. + }
  4980. + pkg_free_installed_files(pkg);
  4981. +
  4982. + return clashes;
  4983. +}
  4984. +
  4985. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg)
  4986. +{
  4987. + /* Basically that's the worst hack I could do to be able to change ownership of
  4988. + file list, but, being that we have no way to unwind the mods, due to structure
  4989. + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
  4990. + What we do here is change the ownership of file in hash if a replace ( or similar events
  4991. + happens )
  4992. + Only the action that are needed to change name should be considered.
  4993. + @@@ To change after 1.0 release.
  4994. + */
  4995. + str_list_t *files_list;
  4996. + str_list_elt_t *iter;
  4997. +
  4998. + int clashes = 0;
  4999. +
  5000. + files_list = pkg_get_installed_files(pkg);
  5001. + for (iter = files_list->head; iter; iter = iter->next) {
  5002. + char *root_filename;
  5003. + char *filename = iter->data;
  5004. + root_filename = root_filename_alloc(conf, filename);
  5005. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5006. + pkg_t *owner;
  5007. +
  5008. + if (conf->force_overwrite) {
  5009. + /* but we need to change who owns this file */
  5010. + file_hash_set_file_owner(conf, filename, pkg);
  5011. + continue;
  5012. + }
  5013. +
  5014. + owner = file_hash_get_file_owner(conf, filename);
  5015. +
  5016. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5017. + if (owner) {
  5018. + if (pkg_replaces(pkg, owner)) {
  5019. +/* It's now time to change the owner of that file.
  5020. + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
  5021. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5022. + file_hash_set_file_owner(conf, filename, pkg);
  5023. + continue;
  5024. + }
  5025. + }
  5026. +
  5027. + }
  5028. + free(root_filename);
  5029. + }
  5030. + pkg_free_installed_files(pkg);
  5031. +
  5032. + return clashes;
  5033. +}
  5034. +
  5035. +/*
  5036. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5037. +{
  5038. + Nothing to do since check_data_file_clashes doesn't change state
  5039. + return 0;
  5040. +}
  5041. +*/
  5042. +
  5043. +/*
  5044. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5045. +{
  5046. + DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
  5047. + 1. If the package is being upgraded, call
  5048. + old-postrm upgrade new-version
  5049. + 2. If this fails, attempt:
  5050. + new-postrm failed-upgrade old-version
  5051. + Error unwind, for both cases:
  5052. + old-preinst abort-upgrade new-version
  5053. + return 0;
  5054. +}
  5055. +*/
  5056. +
  5057. +/*
  5058. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5059. +{
  5060. + DPKG_INCOMPATIBILITY:
  5061. + dpkg does some things here that we don't do yet. Do we care?
  5062. + (See postrm_upgrade_old_pkg for details)
  5063. + return 0;
  5064. +}
  5065. +*/
  5066. +
  5067. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5068. +{
  5069. + int err;
  5070. + str_list_t *old_files;
  5071. + str_list_elt_t *of;
  5072. + str_list_t *new_files;
  5073. + str_list_elt_t *nf;
  5074. +
  5075. + if (old_pkg == NULL) {
  5076. + return 0;
  5077. + }
  5078. +
  5079. + old_files = pkg_get_installed_files(old_pkg);
  5080. + new_files = pkg_get_installed_files(pkg);
  5081. +
  5082. + for (of = old_files->head; of; of = of->next) {
  5083. + pkg_t *owner;
  5084. + char *old, *new;
  5085. + old = of->data;
  5086. + for (nf = new_files->head; nf; nf = nf->next) {
  5087. + new = nf->data;
  5088. + if (strcmp(old, new) == 0) {
  5089. + goto NOT_OBSOLETE;
  5090. + }
  5091. + }
  5092. + if (file_is_dir(old)) {
  5093. + continue;
  5094. + }
  5095. + owner = file_hash_get_file_owner(conf, old);
  5096. + if (owner != old_pkg) {
  5097. + /* in case obsolete file no longer belongs to old_pkg */
  5098. + continue;
  5099. + }
  5100. +
  5101. + /* old file is obsolete */
  5102. + ipkg_message(conf, IPKG_INFO,
  5103. + " removing obsolete file %s\n", old);
  5104. + if (!conf->noaction) {
  5105. + err = unlink(old);
  5106. + if (err) {
  5107. + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
  5108. + strerror(errno));
  5109. + }
  5110. + }
  5111. +
  5112. + NOT_OBSOLETE:
  5113. + ;
  5114. + }
  5115. +
  5116. + pkg_free_installed_files(old_pkg);
  5117. + pkg_free_installed_files(pkg);
  5118. +
  5119. + return 0;
  5120. +}
  5121. +
  5122. +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5123. +{
  5124. + int i;
  5125. + int err = 0;
  5126. + char *globpattern;
  5127. + glob_t globbuf;
  5128. + if (0) {
  5129. + if (!pkg->dest) {
  5130. + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
  5131. + return -1;
  5132. + }
  5133. + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
  5134. + err = glob(globpattern, 0, NULL, &globbuf);
  5135. + free(globpattern);
  5136. + if (err) {
  5137. + return err;
  5138. + }
  5139. + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
  5140. + for (i = 0; i < globbuf.gl_pathc; i++) {
  5141. + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
  5142. + globbuf.gl_pathv[i], old_pkg->name);
  5143. + if (!conf->noaction)
  5144. + unlink(globbuf.gl_pathv[i]);
  5145. + }
  5146. + globfree(&globbuf);
  5147. + }
  5148. + return err;
  5149. +}
  5150. +
  5151. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5152. +{
  5153. + int ret;
  5154. + char *prefix;
  5155. +
  5156. + if (old_pkg)
  5157. + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
  5158. + sprintf_alloc(&prefix, "%s.", pkg->name);
  5159. + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
  5160. + pkg->dest->info_dir,
  5161. + prefix);
  5162. + free(prefix);
  5163. + return ret;
  5164. +}
  5165. +
  5166. +/*
  5167. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
  5168. +{
  5169. + DPKG_INCOMPATIBILITY:
  5170. + This is a fairly sophisticated dpkg operation. Shall we
  5171. + skip it?
  5172. +
  5173. + Any packages all of whose files have been overwritten during the
  5174. + installation, and which aren't required for dependencies, are
  5175. + considered to have been removed. For each such package
  5176. + 1. disappearer's-postrm disappear overwriter overwriter-version
  5177. + 2. The package's maintainer scripts are removed
  5178. + 3. It is noted in the status database as being in a sane state,
  5179. + namely not installed (any conffiles it may have are ignored,
  5180. + rather than being removed by dpkg). Note that disappearing
  5181. + packages do not have their prerm called, because dpkg doesn't
  5182. + know in advance that the package is going to vanish.
  5183. +
  5184. +
  5185. + return 0;
  5186. +}
  5187. +*/
  5188. +
  5189. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
  5190. +{
  5191. + int err;
  5192. +
  5193. + /* ipkg takes a slightly different approach to data file backups
  5194. + than dpkg. Rather than removing backups at this point, we
  5195. + actually do the data file installation now. See comments in
  5196. + check_data_file_clashes() for more details. */
  5197. +
  5198. + ipkg_message(conf, IPKG_INFO,
  5199. + " extracting data files to %s\n", pkg->dest->root_dir);
  5200. + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
  5201. + if (err) {
  5202. + return err;
  5203. + }
  5204. +
  5205. + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
  5206. + so we can't save ourself from removing important packages
  5207. + At this point we (should) have extracted the .control file, so it
  5208. + would be a good idea to reload the data in it, and set the Essential
  5209. + state in *pkg. From now on the Essential is back in status file and
  5210. + we can protect again.
  5211. + We should operate this way:
  5212. + fopen the file ( pkg->dest->root_dir/pkg->name.control )
  5213. + check for "Essential" in it
  5214. + set the value in pkg->essential.
  5215. + This new routine could be useful also for every other flag
  5216. + Pigi: 16/03/2004 */
  5217. + set_flags_from_control(conf, pkg) ;
  5218. +
  5219. + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
  5220. + err = pkg_write_filelist(conf, pkg);
  5221. + if (err)
  5222. + return err;
  5223. +
  5224. + /* XXX: FEATURE: ipkg should identify any files which existed
  5225. + before installation and which were overwritten, (see
  5226. + check_data_file_clashes()). What it must do is remove any such
  5227. + files from the filelist of the old package which provided the
  5228. + file. Otherwise, if the old package were removed at some point
  5229. + it would break the new package. Removing the new package will
  5230. + also break the old one, but this cannot be helped since the old
  5231. + package's file has already been deleted. This is the importance
  5232. + of check_data_file_clashes(), and only allowing ipkg to install
  5233. + a clashing package with a user force. */
  5234. +
  5235. + return 0;
  5236. +}
  5237. +
  5238. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
  5239. +{
  5240. + conffile_list_elt_t *iter;
  5241. + conffile_t *cf;
  5242. + char *cf_backup;
  5243. + uint8_t *md5sum;
  5244. +
  5245. +
  5246. + if (conf->noaction) return 0;
  5247. +
  5248. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  5249. + char *root_filename;
  5250. + cf = iter->data;
  5251. + root_filename = root_filename_alloc(conf, cf->name);
  5252. +
  5253. + /* Might need to initialize the md5sum for each conffile */
  5254. + if (cf->value == NULL) {
  5255. + cf->value = (char *)file_md5sum_alloc(root_filename);
  5256. + }
  5257. +
  5258. + if (!file_exists(root_filename)) {
  5259. + free(root_filename);
  5260. + continue;
  5261. + }
  5262. +
  5263. + cf_backup = backup_filename_alloc(root_filename);
  5264. +
  5265. +
  5266. + if (file_exists(cf_backup)) {
  5267. + /* Let's compute md5 to test if files are changed */
  5268. + md5sum = file_md5sum_alloc(cf_backup);
  5269. + if (strcmp( cf->value, (char *)md5sum) != 0 ) {
  5270. + if (conf->force_defaults
  5271. + || user_prefers_old_conffile(cf->name, cf_backup) ) {
  5272. + rename(cf_backup, root_filename);
  5273. + }
  5274. + }
  5275. + unlink(cf_backup);
  5276. + free(md5sum);
  5277. + }
  5278. +
  5279. + free(cf_backup);
  5280. + free(root_filename);
  5281. + }
  5282. +
  5283. + return 0;
  5284. +}
  5285. +
  5286. +static int user_prefers_old_conffile(const char *file_name, const char *backup)
  5287. +{
  5288. + char *response;
  5289. + const char *short_file_name;
  5290. +
  5291. + short_file_name = strrchr(file_name, '/');
  5292. + if (short_file_name) {
  5293. + short_file_name++;
  5294. + } else {
  5295. + short_file_name = file_name;
  5296. + }
  5297. +
  5298. + while (1) {
  5299. + response = get_user_response(" Configuration file '%s'\n"
  5300. + " ==> File on system created by you or by a script.\n"
  5301. + " ==> File also in package provided by package maintainer.\n"
  5302. + " What would you like to do about it ? Your options are:\n"
  5303. + " Y or I : install the package maintainer's version\n"
  5304. + " N or O : keep your currently-installed version\n"
  5305. +#ifdef CONFIG_DIFF
  5306. + " D : show the differences between the versions\n"
  5307. +#endif
  5308. + " The default action is to keep your current version.\n"
  5309. + " *** %s (Y/I/N/O"
  5310. +#ifdef CONFIG_DIFF
  5311. + "/D"
  5312. +#endif
  5313. + ") [default=N] ? ", file_name, short_file_name);
  5314. + if (strcmp(response, "y") == 0
  5315. + || strcmp(response, "i") == 0
  5316. + || strcmp(response, "yes") == 0) {
  5317. + free(response);
  5318. + return 0;
  5319. + }
  5320. +
  5321. +#ifdef CONFIG_DIFF
  5322. + if (strcmp(response, "d") == 0) {
  5323. + char *cmd;
  5324. +
  5325. + free(response);
  5326. + /* XXX: BUG rewrite to use exec or busybox's internal diff */
  5327. + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
  5328. + xsystem(cmd);
  5329. + free(cmd);
  5330. + printf(" [Press ENTER to continue]\n");
  5331. + response = file_read_line_alloc(stdin);
  5332. + free(response);
  5333. + continue;
  5334. + }
  5335. +#endif
  5336. +
  5337. + free(response);
  5338. + return 1;
  5339. + }
  5340. +}
  5341. +
  5342. +/* XXX: CLEANUP: I'd like to move all of the code for
  5343. + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
  5344. + it would make sense to cleanup pkg->tmp_unpack_dir directly from
  5345. + pkg_deinit for example). */
  5346. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
  5347. +{
  5348. + DIR *tmp_dir;
  5349. + struct dirent *dirent;
  5350. + char *tmp_file;
  5351. +
  5352. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  5353. +#error
  5354. + ipkg_message(conf, IPKG_DEBUG,
  5355. + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  5356. + __FUNCTION__, pkg->tmp_unpack_dir);
  5357. + return 0;
  5358. +#endif
  5359. +
  5360. + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
  5361. + tmp_dir = opendir(pkg->tmp_unpack_dir);
  5362. + if (tmp_dir) {
  5363. + while (1) {
  5364. + dirent = readdir(tmp_dir);
  5365. + if (dirent == NULL) {
  5366. + break;
  5367. + }
  5368. + sprintf_alloc(&tmp_file, "%s/%s",
  5369. + pkg->tmp_unpack_dir, dirent->d_name);
  5370. + if (! file_is_dir(tmp_file)) {
  5371. + unlink(tmp_file);
  5372. + }
  5373. + free(tmp_file);
  5374. + }
  5375. + closedir(tmp_dir);
  5376. + rmdir(pkg->tmp_unpack_dir);
  5377. + free(pkg->tmp_unpack_dir);
  5378. + pkg->tmp_unpack_dir = NULL;
  5379. + }
  5380. + }
  5381. +
  5382. + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
  5383. + pkg->name, pkg->local_filename, conf->tmp_dir);
  5384. + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
  5385. + unlink(pkg->local_filename);
  5386. + free(pkg->local_filename);
  5387. + pkg->local_filename = NULL;
  5388. + }
  5389. +
  5390. + return 0;
  5391. +}
  5392. +
  5393. +static char *backup_filename_alloc(const char *file_name)
  5394. +{
  5395. + char *backup;
  5396. +
  5397. + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
  5398. +
  5399. + return backup;
  5400. +}
  5401. +
  5402. +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
  5403. +{
  5404. + int err;
  5405. + char *backup;
  5406. +
  5407. + backup = backup_filename_alloc(file_name);
  5408. + err = file_copy(file_name, backup);
  5409. + if (err) {
  5410. + ipkg_message(conf, IPKG_ERROR,
  5411. + "%s: Failed to copy %s to %s\n",
  5412. + __FUNCTION__, file_name, backup);
  5413. + }
  5414. +
  5415. + free(backup);
  5416. +
  5417. + return err;
  5418. +}
  5419. +
  5420. +static int backup_exists_for(const char *file_name)
  5421. +{
  5422. + int ret;
  5423. + char *backup;
  5424. +
  5425. + backup = backup_filename_alloc(file_name);
  5426. +
  5427. + ret = file_exists(backup);
  5428. +
  5429. + free(backup);
  5430. +
  5431. + return ret;
  5432. +}
  5433. +
  5434. +static int backup_remove(const char *file_name)
  5435. +{
  5436. + char *backup;
  5437. +
  5438. + backup = backup_filename_alloc(file_name);
  5439. + unlink(backup);
  5440. + free(backup);
  5441. +
  5442. + return 0;
  5443. +}
  5444. +
  5445. +
  5446. +
  5447. +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
  5448. +
  5449. +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
  5450. +{
  5451. + /* first, remove the packages that need removing */
  5452. + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
  5453. + pkg_t *pkg = pkgs_to_remove->pkgs[i];
  5454. + err = ipkg_remove_pkg(conf, pkg,0);
  5455. + if (err) return err;
  5456. + }
  5457. + return 0;
  5458. +}
  5459. +
  5460. +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)
  5461. +{
  5462. + int i;
  5463. + /* now one more pass checking on the ones that need to be installed */
  5464. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5465. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5466. + if (pkg->dest == NULL)
  5467. + pkg->dest = conf->default_dest;
  5468. +
  5469. + pkg->state_want = SW_INSTALL;
  5470. +
  5471. + /* Abhaya: conflicts check */
  5472. + err = check_conflicts_for(conf, pkg);
  5473. + if (err) { return err; }
  5474. + }
  5475. + return 0;
  5476. +}
  5477. +
  5478. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5479. +{
  5480. + int i;
  5481. + /* now one more pass checking on the ones that need to be installed */
  5482. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5483. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5484. +
  5485. + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
  5486. + pkg_vec_t *replacees = pkg_vec_alloc();
  5487. + pkg_get_installed_replacees(pkg, replacees);
  5488. +
  5489. + /* XXX: BUG: we really should treat replacement more like an upgrade
  5490. + * Instead, we're going to remove the replacees
  5491. + */
  5492. + err = pkg_remove_installed_replacees(conf, replacees);
  5493. + if (err) return err;
  5494. + pkg->state_flag |= SF_REMOVED_REPLACEES;
  5495. + }
  5496. + return 0;
  5497. +}
  5498. +
  5499. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5500. +{
  5501. + int i;
  5502. + /* now one more pass checking on the ones that need to be installed */
  5503. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5504. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5505. + if (pkg->local_filename == NULL) {
  5506. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  5507. + if (err) {
  5508. + ipkg_message(conf, IPKG_ERROR,
  5509. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  5510. + pkg->name);
  5511. + return err;
  5512. + }
  5513. + }
  5514. + if (pkg->tmp_unpack_dir == NULL) {
  5515. + err = unpack_pkg_control_files(conf, pkg);
  5516. + if (err) return err;
  5517. + }
  5518. + }
  5519. + return 0;
  5520. +}
  5521. +
  5522. +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5523. +{
  5524. + int i;
  5525. + /* now one more pass checking on the ones that need to be installed */
  5526. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5527. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5528. + pkg_t *old_pkg = pkg->old_pkg;
  5529. +
  5530. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  5531. + if (err) return err;
  5532. +
  5533. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  5534. + if (err) return err;
  5535. +
  5536. + err = preinst_configure(conf, pkg, old_pkg);
  5537. + if (err) return err;
  5538. +
  5539. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  5540. + if (err) return err;
  5541. +
  5542. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  5543. + if (err) return err;
  5544. + }
  5545. + return 0;
  5546. +}
  5547. +
  5548. +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5549. +{
  5550. + int i;
  5551. + /* now one more pass checking on the ones that need to be installed */
  5552. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5553. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5554. + pkg_t *old_pkg = pkg->old_pkg;
  5555. +
  5556. + if (old_pkg) {
  5557. + old_pkg->state_want = SW_DEINSTALL;
  5558. +
  5559. + if (old_pkg->state_flag & SF_NOPRUNE) {
  5560. + ipkg_message(conf, IPKG_INFO,
  5561. + " not removing obsolesced files because package marked noprune\n");
  5562. + } else {
  5563. + ipkg_message(conf, IPKG_INFO,
  5564. + " removing obsolesced files\n");
  5565. + remove_obsolesced_files(conf, pkg, old_pkg);
  5566. + }
  5567. + }
  5568. +
  5569. + ipkg_message(conf, IPKG_INFO,
  5570. + " installing maintainer scripts\n");
  5571. + install_maintainer_scripts(conf, pkg, old_pkg);
  5572. +
  5573. + /* the following just returns 0 */
  5574. + remove_disappeared(conf, pkg);
  5575. +
  5576. + ipkg_message(conf, IPKG_INFO,
  5577. + " installing data files\n");
  5578. + install_data_files(conf, pkg);
  5579. +
  5580. + ipkg_message(conf, IPKG_INFO,
  5581. + " resolving conf files\n");
  5582. + resolve_conffiles(conf, pkg);
  5583. +
  5584. + pkg->state_status = SS_UNPACKED;
  5585. +
  5586. + if (old_pkg) {
  5587. + old_pkg->state_status = SS_NOT_INSTALLED;
  5588. + }
  5589. +
  5590. + time(&pkg->installed_time);
  5591. +
  5592. + ipkg_message(conf, IPKG_INFO,
  5593. + " cleanup temp files\n");
  5594. + cleanup_temporary_files(conf, pkg);
  5595. +
  5596. + if (pkg->parent)
  5597. + pkg->parent->state_status = pkg->state_status;
  5598. + }
  5599. + return 0;
  5600. +}
  5601. +
  5602. +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5603. +{
  5604. + int i;
  5605. + /* now one more pass checking on the ones that need to be installed */
  5606. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5607. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5608. + pkg_t *old_pkg = pkg->old_pkg;
  5609. +
  5610. + if (old_pkg) {
  5611. + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
  5612. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5613. + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
  5614. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  5615. + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
  5616. + backup_modified_conffiles_unwind(pkg, old_pkg);
  5617. + */
  5618. + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
  5619. + preinst_configure_unwind(conf, pkg, old_pkg);
  5620. + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
  5621. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  5622. + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
  5623. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5624. + */
  5625. +
  5626. + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
  5627. + remove_installed_replacees_unwind(conf, pkg, old_pkg);
  5628. +
  5629. + }
  5630. + }
  5631. + return 0;
  5632. +}
  5633. +
  5634. +/*
  5635. + * Perform all the actions.
  5636. + *
  5637. + * pkgs_to_remove are packages marked for removal.
  5638. + * pkgs_superseded are the old packages being replaced by upgrades.
  5639. + *
  5640. + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
  5641. + */
  5642. +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)
  5643. +{
  5644. + int err;
  5645. + int i;
  5646. +
  5647. + err = ipkg_remove_packages(conf, pkgs_to_remove);
  5648. + if (err) return err;
  5649. +
  5650. + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
  5651. + if (err) return err;
  5652. +
  5653. + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
  5654. + if (err) goto UNWIND;
  5655. +
  5656. + /* @@@@ look at ipkg_install_pkg for handling replacements */
  5657. + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
  5658. + if (err) goto UNWIND;
  5659. +
  5660. + /*
  5661. + * Now that we have the packages unpacked, we can look for data
  5662. + * file clashes. First, we mark the files from the superseded
  5663. + * packages as obsolete. Then we scan the files in
  5664. + * pkgs_to_install, and only complain about clashes with
  5665. + * non-obsolete files.
  5666. + */
  5667. +
  5668. + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
  5669. + if (err) goto UNWIND;
  5670. +
  5671. + /* this was before checking data file clashes */
  5672. + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
  5673. + if (err) goto UNWIND;
  5674. +
  5675. + /* point of no return: no unwinding after this */
  5676. + err = ipkg_process_actions_install(conf, pkgs_to_install);
  5677. + if (err) return err;
  5678. +
  5679. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  5680. + return 0;
  5681. +
  5682. + UNWIND:
  5683. + ipkg_process_actions_unwind(conf, pkgs_to_install);
  5684. +
  5685. + ipkg_message(conf, IPKG_INFO,
  5686. + " cleanup temp files\n");
  5687. + cleanup_temporary_files(conf, pkg);
  5688. +
  5689. + ipkg_message(conf, IPKG_INFO,
  5690. + "Failed.\n");
  5691. + return err;
  5692. +}
  5693. +
  5694. +#endif
  5695. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_install.h busybox-1.17.0/archival/libipkg/ipkg_install.h
  5696. --- busybox-1.17.0.orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
  5697. +++ busybox-1.17.0/archival/libipkg/ipkg_install.h 2010-07-16 14:45:14.957118010 +0200
  5698. @@ -0,0 +1,35 @@
  5699. +/* ipkg_install.h - the itsy package management system
  5700. +
  5701. + Carl D. Worth
  5702. +
  5703. + Copyright (C) 2001 University of Southern California
  5704. +
  5705. + This program is free software; you can redistribute it and/or
  5706. + modify it under the terms of the GNU General Public License as
  5707. + published by the Free Software Foundation; either version 2, or (at
  5708. + your option) any later version.
  5709. +
  5710. + This program is distributed in the hope that it will be useful, but
  5711. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5712. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5713. + General Public License for more details.
  5714. +*/
  5715. +
  5716. +#ifndef IPKG_INSTALL_H
  5717. +#define IPKG_INSTALL_H
  5718. +
  5719. +#include "pkg.h"
  5720. +#include "ipkg_conf.h"
  5721. +
  5722. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5723. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5724. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
  5725. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
  5726. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  5727. +
  5728. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
  5729. +
  5730. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
  5731. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
  5732. +
  5733. +#endif
  5734. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_message.c busybox-1.17.0/archival/libipkg/ipkg_message.c
  5735. --- busybox-1.17.0.orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
  5736. +++ busybox-1.17.0/archival/libipkg/ipkg_message.c 2010-07-16 14:45:15.005966372 +0200
  5737. @@ -0,0 +1,35 @@
  5738. +/* ipkg_message.c - the itsy package management system
  5739. +
  5740. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5741. +
  5742. + This program is free software; you can redistribute it and/or
  5743. + modify it under the terms of the GNU General Public License as
  5744. + published by the Free Software Foundation; either version 2, or (at
  5745. + your option) any later version.
  5746. +
  5747. + This program is distributed in the hope that it will be useful, but
  5748. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5749. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5750. + General Public License for more details.
  5751. +*/
  5752. +
  5753. +
  5754. +#include "ipkg.h"
  5755. +#include "ipkg_conf.h"
  5756. +#include "ipkg_message.h"
  5757. +#include "libipkg.h"
  5758. +
  5759. +void
  5760. +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
  5761. +{
  5762. + va_list ap;
  5763. + char ts[256];
  5764. +
  5765. + if (ipkg_cb_message)
  5766. + {
  5767. + va_start (ap, fmt);
  5768. + vsnprintf (ts,256,fmt, ap);
  5769. + va_end (ap);
  5770. + ipkg_cb_message(conf,level,ts);
  5771. + }
  5772. +}
  5773. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_message.h busybox-1.17.0/archival/libipkg/ipkg_message.h
  5774. --- busybox-1.17.0.orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
  5775. +++ busybox-1.17.0/archival/libipkg/ipkg_message.h 2010-07-16 14:45:15.049608234 +0200
  5776. @@ -0,0 +1,32 @@
  5777. +/* ipkg_message.h - the itsy package management system
  5778. +
  5779. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5780. +
  5781. + This program is free software; you can redistribute it and/or
  5782. + modify it under the terms of the GNU General Public License as
  5783. + published by the Free Software Foundation; either version 2, or (at
  5784. + your option) any later version.
  5785. +
  5786. + This program is distributed in the hope that it will be useful, but
  5787. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5788. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5789. + General Public License for more details.
  5790. +*/
  5791. +
  5792. +#ifndef _IPKG_MESSAGE_H_
  5793. +#define _IPKG_MESSAGE_H_
  5794. +
  5795. +#include "ipkg.h"
  5796. +#include "ipkg_conf.h"
  5797. +
  5798. +typedef enum {
  5799. + IPKG_ERROR, /* error conditions */
  5800. + IPKG_NOTICE, /* normal but significant condition */
  5801. + IPKG_INFO, /* informational message */
  5802. + IPKG_DEBUG, /* debug level message */
  5803. + IPKG_DEBUG2, /* more debug level message */
  5804. +} message_level_t;
  5805. +
  5806. +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
  5807. +
  5808. +#endif /* _IPKG_MESSAGE_H_ */
  5809. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_remove.c busybox-1.17.0/archival/libipkg/ipkg_remove.c
  5810. --- busybox-1.17.0.orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
  5811. +++ busybox-1.17.0/archival/libipkg/ipkg_remove.c 2010-07-16 14:45:15.105856995 +0200
  5812. @@ -0,0 +1,385 @@
  5813. +/* ipkg_remove.c - the itsy package management system
  5814. +
  5815. + Carl D. Worth
  5816. +
  5817. + Copyright (C) 2001 University of Southern California
  5818. +
  5819. + This program is free software; you can redistribute it and/or
  5820. + modify it under the terms of the GNU General Public License as
  5821. + published by the Free Software Foundation; either version 2, or (at
  5822. + your option) any later version.
  5823. +
  5824. + This program is distributed in the hope that it will be useful, but
  5825. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5826. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5827. + General Public License for more details.
  5828. +*/
  5829. +
  5830. +#include "ipkg.h"
  5831. +#include "ipkg_message.h"
  5832. +
  5833. +#include <glob.h>
  5834. +
  5835. +#include "ipkg_remove.h"
  5836. +
  5837. +#include "file_util.h"
  5838. +#include "sprintf_alloc.h"
  5839. +#include "str_util.h"
  5840. +
  5841. +#include "ipkg_cmd.h"
  5842. +
  5843. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents);
  5844. +
  5845. +/*
  5846. + * Returns number of the number of packages depending on the packages provided by this package.
  5847. + * Every package implicitly provides itself.
  5848. + */
  5849. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents)
  5850. +{
  5851. + int nprovides = pkg->provides_count;
  5852. + abstract_pkg_t **provides = pkg->provides;
  5853. + int n_installed_dependents = 0;
  5854. + int i;
  5855. + for (i = 0; i <= nprovides; i++) {
  5856. + abstract_pkg_t *providee = provides[i];
  5857. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5858. + abstract_pkg_t *dep_ab_pkg;
  5859. + if (dependers == NULL)
  5860. + continue;
  5861. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5862. + if (dep_ab_pkg->state_status == SS_INSTALLED){
  5863. + n_installed_dependents++;
  5864. + }
  5865. + }
  5866. +
  5867. + }
  5868. + /* if caller requested the set of installed dependents */
  5869. + if (pdependents) {
  5870. + int p = 0;
  5871. + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
  5872. +
  5873. + if ( dependents == NULL ){
  5874. + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
  5875. + return -1;
  5876. + }
  5877. +
  5878. + *pdependents = dependents;
  5879. + for (i = 0; i <= nprovides; i++) {
  5880. + abstract_pkg_t *providee = provides[i];
  5881. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5882. + abstract_pkg_t *dep_ab_pkg;
  5883. + if (dependers == NULL)
  5884. + continue;
  5885. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5886. + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
  5887. + dependents[p++] = dep_ab_pkg;
  5888. + dep_ab_pkg->state_flag |= SF_MARKED;
  5889. + }
  5890. + }
  5891. + }
  5892. + dependents[p] = NULL;
  5893. + /* now clear the marks */
  5894. + for (i = 0; i < p; i++) {
  5895. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5896. + dep_ab_pkg->state_flag &= ~SF_MARKED;
  5897. + }
  5898. + }
  5899. + return n_installed_dependents;
  5900. +}
  5901. +
  5902. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5903. +{
  5904. + int i;
  5905. + int a;
  5906. + int count;
  5907. + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
  5908. + abstract_pkg_t * ab_pkg;
  5909. +
  5910. + if((ab_pkg = pkg->parent) == NULL){
  5911. + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
  5912. + __FUNCTION__, pkg->name);
  5913. + return 0;
  5914. + }
  5915. +
  5916. + if (dependents == NULL)
  5917. + return 0;
  5918. +
  5919. + // here i am using the dependencies_checked
  5920. + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
  5921. + return 0; // has already been encountered in the process
  5922. + // of marking packages for removal - Karthik
  5923. + ab_pkg->dependencies_checked = 2;
  5924. +
  5925. + i = 0;
  5926. + count = 1;
  5927. + while (dependents [i] != NULL) {
  5928. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5929. +
  5930. + if (dep_ab_pkg->dependencies_checked == 2){
  5931. + i++;
  5932. + continue;
  5933. + }
  5934. + if (dep_ab_pkg->state_status == SS_INSTALLED) {
  5935. + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
  5936. + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
  5937. + if (dep_pkg->state_status == SS_INSTALLED) {
  5938. + pkg_vec_insert(dependent_pkgs, dep_pkg);
  5939. + count++;
  5940. + }
  5941. + }
  5942. + }
  5943. + i++;
  5944. + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
  5945. + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
  5946. + }
  5947. +
  5948. + if (count == 1)
  5949. + return 0;
  5950. +
  5951. +
  5952. + for (i = 0; i < dependent_pkgs->len; i++) {
  5953. + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
  5954. + if (err)
  5955. + return err;
  5956. + }
  5957. + return 0;
  5958. +}
  5959. +
  5960. +static int user_prefers_removing_dependents(ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5961. +{
  5962. + abstract_pkg_t *dep_ab_pkg;
  5963. + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
  5964. + while ((dep_ab_pkg = *dependents++) != NULL) {
  5965. + if (dep_ab_pkg->state_status == SS_INSTALLED)
  5966. + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
  5967. + }
  5968. + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
  5969. + ipkg_message(conf, IPKG_ERROR, "");
  5970. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
  5971. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
  5972. + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
  5973. + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
  5974. + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
  5975. + return 0;
  5976. +}
  5977. +
  5978. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
  5979. +{
  5980. +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
  5981. + thus I wan't check for essential, as I'm upgrading.
  5982. + I hope it won't break anything :)
  5983. +*/
  5984. + int err;
  5985. + abstract_pkg_t *parent_pkg = NULL;
  5986. +
  5987. + if (pkg->essential && !message) {
  5988. + if (conf->force_removal_of_essential_packages) {
  5989. + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
  5990. + "\tIf your system breaks, you get to keep both pieces\n",
  5991. + pkg->name);
  5992. + } else {
  5993. + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
  5994. + "\tRemoving an essential package may lead to an unusable system, but if\n"
  5995. + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
  5996. + "\tits will with the option: -force-removal-of-essential-packages\n",
  5997. + pkg->name);
  5998. + return IPKG_PKG_IS_ESSENTIAL;
  5999. + }
  6000. + }
  6001. +
  6002. + if ((parent_pkg = pkg->parent) == NULL)
  6003. + return 0;
  6004. +
  6005. + /* only attempt to remove dependent installed packages if
  6006. + * force_depends is not specified or the package is being
  6007. + * replaced.
  6008. + */
  6009. + if (!conf->force_depends
  6010. + && !(pkg->state_flag & SF_REPLACE)) {
  6011. + abstract_pkg_t **dependents;
  6012. + int has_installed_dependents =
  6013. + pkg_has_installed_dependents(pkg, &dependents);
  6014. +
  6015. + if (has_installed_dependents) {
  6016. + /*
  6017. + * if this package is depended up by others, then either we should
  6018. + * not remove it or we should remove it and all of its dependents
  6019. + */
  6020. +
  6021. + if (!conf->force_removal_of_dependent_packages
  6022. + && !user_prefers_removing_dependents(conf, pkg, dependents)) {
  6023. + return IPKG_PKG_HAS_DEPENDENTS;
  6024. + }
  6025. +
  6026. + /* remove packages depending on this package - Karthik */
  6027. + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
  6028. + free(dependents);
  6029. + if (err) return err;
  6030. + }
  6031. + }
  6032. +
  6033. + if ( message==0 ){
  6034. + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
  6035. + fflush(stdout);
  6036. + }
  6037. + pkg->state_flag |= SF_FILELIST_CHANGED;
  6038. +
  6039. + pkg->state_want = SW_DEINSTALL;
  6040. + ipkg_state_changed++;
  6041. +
  6042. + pkg_run_script(conf, pkg, "prerm", "remove");
  6043. +
  6044. + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
  6045. + maintains an empty filelist rather than deleting it. That seems
  6046. + like a big pain, and I don't see that that should make a big
  6047. + difference, but for anyone who wants tighter compatibility,
  6048. + feel free to fix this. */
  6049. + remove_data_files_and_list(conf, pkg);
  6050. +
  6051. + pkg_run_script(conf, pkg, "postrm", "remove");
  6052. +
  6053. + remove_maintainer_scripts_except_postrm(conf, pkg);
  6054. +
  6055. + /* Aman Gupta - Since ipkg is made for handheld devices with limited
  6056. + * space, it doesn't make sense to leave extra configurations, files,
  6057. + * and maintainer scripts left around. So, we make remove like purge,
  6058. + * and take out all the crap :) */
  6059. +
  6060. + remove_postrm(conf, pkg);
  6061. + pkg->state_status = SS_NOT_INSTALLED;
  6062. +
  6063. + if (parent_pkg)
  6064. + parent_pkg->state_status = SS_NOT_INSTALLED;
  6065. +
  6066. + return 0;
  6067. +}
  6068. +
  6069. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
  6070. +{
  6071. + ipkg_remove_pkg(conf, pkg,0);
  6072. + return 0;
  6073. +}
  6074. +
  6075. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
  6076. +{
  6077. + str_list_t installed_dirs;
  6078. + str_list_t *installed_files;
  6079. + str_list_elt_t *iter;
  6080. + char *file_name;
  6081. + conffile_t *conffile;
  6082. + int removed_a_dir;
  6083. + pkg_t *owner;
  6084. +
  6085. + str_list_init(&installed_dirs);
  6086. + installed_files = pkg_get_installed_files(pkg);
  6087. +
  6088. + for (iter = installed_files->head; iter; iter = iter->next) {
  6089. + file_name = iter->data;
  6090. +
  6091. + if (file_is_dir(file_name)) {
  6092. + str_list_append(&installed_dirs, strdup(file_name));
  6093. + continue;
  6094. + }
  6095. +
  6096. + conffile = pkg_get_conffile(pkg, file_name);
  6097. + if (conffile) {
  6098. + /* XXX: QUESTION: Is this right? I figure we only need to
  6099. + save the conffile if it has been modified. Is that what
  6100. + dpkg does? Or does dpkg preserve all conffiles? If so,
  6101. + this seems like a better thing to do to conserve
  6102. + space. */
  6103. + if (conffile_has_been_modified(conf, conffile)) {
  6104. + printf(" not deleting modified conffile %s\n", file_name);
  6105. + fflush(stdout);
  6106. + continue;
  6107. + }
  6108. + }
  6109. +
  6110. + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
  6111. + if (!conf->noaction)
  6112. + unlink(file_name);
  6113. + }
  6114. +
  6115. + if (!conf->noaction) {
  6116. + do {
  6117. + removed_a_dir = 0;
  6118. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6119. + file_name = iter->data;
  6120. +
  6121. + if (rmdir(file_name) == 0) {
  6122. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
  6123. + removed_a_dir = 1;
  6124. + str_list_remove(&installed_dirs, &iter);
  6125. + }
  6126. + }
  6127. + } while (removed_a_dir);
  6128. + }
  6129. +
  6130. + pkg_free_installed_files(pkg);
  6131. + /* We have to remove the file list now, so that
  6132. + find_pkg_owning_file does not always just report this package */
  6133. + pkg_remove_installed_files_list(conf, pkg);
  6134. +
  6135. + /* Don't print warning for dirs that are provided by other packages */
  6136. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6137. + file_name = iter->data;
  6138. +
  6139. + owner = file_hash_get_file_owner(conf, file_name);
  6140. + if (owner) {
  6141. + free(iter->data);
  6142. + iter->data = NULL;
  6143. + str_list_remove(&installed_dirs, &iter);
  6144. + }
  6145. + }
  6146. +
  6147. + /* cleanup */
  6148. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6149. + free(iter->data);
  6150. + iter->data = NULL;
  6151. + }
  6152. + str_list_deinit(&installed_dirs);
  6153. +
  6154. + return 0;
  6155. +}
  6156. +
  6157. +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6158. +{
  6159. + int i, err;
  6160. + char *globpattern;
  6161. + glob_t globbuf;
  6162. +
  6163. + if (conf->noaction) return 0;
  6164. +
  6165. + sprintf_alloc(&globpattern, "%s/%s.*",
  6166. + pkg->dest->info_dir, pkg->name);
  6167. + err = glob(globpattern, 0, NULL, &globbuf);
  6168. + free(globpattern);
  6169. + if (err) {
  6170. + return 0;
  6171. + }
  6172. +
  6173. + for (i = 0; i < globbuf.gl_pathc; i++) {
  6174. + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
  6175. + continue;
  6176. + }
  6177. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
  6178. + unlink(globbuf.gl_pathv[i]);
  6179. + }
  6180. + globfree(&globbuf);
  6181. +
  6182. + return 0;
  6183. +}
  6184. +
  6185. +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6186. +{
  6187. + char *postrm_file_name;
  6188. +
  6189. + if (conf->noaction) return 0;
  6190. +
  6191. + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
  6192. + pkg->dest->info_dir, pkg->name);
  6193. + unlink(postrm_file_name);
  6194. + free(postrm_file_name);
  6195. +
  6196. + return 0;
  6197. +}
  6198. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_remove.h busybox-1.17.0/archival/libipkg/ipkg_remove.h
  6199. --- busybox-1.17.0.orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
  6200. +++ busybox-1.17.0/archival/libipkg/ipkg_remove.h 2010-07-16 14:45:15.156542175 +0200
  6201. @@ -0,0 +1,33 @@
  6202. +/* ipkg_remove.h - the itsy package management system
  6203. +
  6204. + Carl D. Worth
  6205. +
  6206. + Copyright (C) 2001 University of Southern California
  6207. +
  6208. + This program is free software; you can redistribute it and/or
  6209. + modify it under the terms of the GNU General Public License as
  6210. + published by the Free Software Foundation; either version 2, or (at
  6211. + your option) any later version.
  6212. +
  6213. + This program is distributed in the hope that it will be useful, but
  6214. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6215. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6216. + General Public License for more details.
  6217. +*/
  6218. +
  6219. +#ifndef IPKG_REMOVE_H
  6220. +#define IPKG_REMOVE_H
  6221. +
  6222. +#include "pkg.h"
  6223. +#include "ipkg_conf.h"
  6224. +
  6225. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
  6226. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
  6227. +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
  6228. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents);
  6229. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
  6230. +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6231. +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6232. +
  6233. +
  6234. +#endif
  6235. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_upgrade.c busybox-1.17.0/archival/libipkg/ipkg_upgrade.c
  6236. --- busybox-1.17.0.orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
  6237. +++ busybox-1.17.0/archival/libipkg/ipkg_upgrade.c 2010-07-16 14:45:15.216616661 +0200
  6238. @@ -0,0 +1,79 @@
  6239. +/* ipkg_upgrade.c - the itsy package management system
  6240. +
  6241. + Carl D. Worth
  6242. + Copyright (C) 2001 University of Southern California
  6243. +
  6244. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6245. +
  6246. + This program is free software; you can redistribute it and/or
  6247. + modify it under the terms of the GNU General Public License as
  6248. + published by the Free Software Foundation; either version 2, or (at
  6249. + your option) any later version.
  6250. +
  6251. + This program is distributed in the hope that it will be useful, but
  6252. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6253. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6254. + General Public License for more details.
  6255. +*/
  6256. +
  6257. +#include "ipkg.h"
  6258. +#include "ipkg_install.h"
  6259. +#include "ipkg_message.h"
  6260. +
  6261. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6262. +
  6263. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
  6264. +{
  6265. + pkg_t *new;
  6266. + int cmp;
  6267. + char *old_version, *new_version;
  6268. +
  6269. + if (old->state_flag & SF_HOLD) {
  6270. + ipkg_message(conf, IPKG_NOTICE,
  6271. + "Not upgrading package %s which is marked "
  6272. + "hold (flags=%#x)\n", old->name, old->state_flag);
  6273. + return 0;
  6274. + }
  6275. +
  6276. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
  6277. + if (new == NULL) {
  6278. + old_version = pkg_version_str_alloc(old);
  6279. + ipkg_message(conf, IPKG_NOTICE,
  6280. + "Assuming locally installed package %s (%s) "
  6281. + "is up to date.\n", old->name, old_version);
  6282. + free(old_version);
  6283. + return 0;
  6284. + }
  6285. +
  6286. + old_version = pkg_version_str_alloc(old);
  6287. + new_version = pkg_version_str_alloc(new);
  6288. +
  6289. + cmp = pkg_compare_versions(old, new);
  6290. + ipkg_message(conf, IPKG_DEBUG,
  6291. + "comparing visible versions of pkg %s:"
  6292. + "\n\t%s is installed "
  6293. + "\n\t%s is available "
  6294. + "\n\t%d was comparison result\n",
  6295. + old->name, old_version, new_version, cmp);
  6296. + if (cmp == 0) {
  6297. + ipkg_message(conf, IPKG_INFO,
  6298. + "Package %s (%s) installed in %s is up to date.\n",
  6299. + old->name, old_version, old->dest->name);
  6300. + free(old_version);
  6301. + free(new_version);
  6302. + return 0;
  6303. + } else if (cmp > 0) {
  6304. + ipkg_message(conf, IPKG_NOTICE,
  6305. + "Not downgrading package %s on %s from %s to %s.\n",
  6306. + old->name, old->dest->name, old_version, new_version);
  6307. + free(old_version);
  6308. + free(new_version);
  6309. + return 0;
  6310. + } else if (cmp < 0) {
  6311. + new->dest = old->dest;
  6312. + old->state_want = SW_DEINSTALL;
  6313. + }
  6314. +
  6315. + new->state_flag |= SF_USER;
  6316. + return ipkg_install_pkg(conf, new,1);
  6317. +}
  6318. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_upgrade.h busybox-1.17.0/archival/libipkg/ipkg_upgrade.h
  6319. --- busybox-1.17.0.orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
  6320. +++ busybox-1.17.0/archival/libipkg/ipkg_upgrade.h 2010-07-16 14:45:15.306333688 +0200
  6321. @@ -0,0 +1,18 @@
  6322. +/* ipkg_upgrade.c - the itsy package management system
  6323. +
  6324. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6325. +
  6326. + This program is free software; you can redistribute it and/or
  6327. + modify it under the terms of the GNU General Public License as
  6328. + published by the Free Software Foundation; either version 2, or (at
  6329. + your option) any later version.
  6330. +
  6331. + This program is distributed in the hope that it will be useful, but
  6332. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6333. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6334. + General Public License for more details.
  6335. +*/
  6336. +
  6337. +#include "ipkg.h"
  6338. +
  6339. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6340. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_utils.c busybox-1.17.0/archival/libipkg/ipkg_utils.c
  6341. --- busybox-1.17.0.orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
  6342. +++ busybox-1.17.0/archival/libipkg/ipkg_utils.c 2010-07-16 14:45:15.355860255 +0200
  6343. @@ -0,0 +1,185 @@
  6344. +/* ipkg_utils.c - the itsy package management system
  6345. +
  6346. + Steven M. Ayer
  6347. +
  6348. + Copyright (C) 2002 Compaq Computer Corporation
  6349. +
  6350. + This program is free software; you can redistribute it and/or
  6351. + modify it under the terms of the GNU General Public License as
  6352. + published by the Free Software Foundation; either version 2, or (at
  6353. + your option) any later version.
  6354. +
  6355. + This program is distributed in the hope that it will be useful, but
  6356. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6357. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6358. + General Public License for more details.
  6359. +*/
  6360. +
  6361. +#include "ipkg.h"
  6362. +#include <errno.h>
  6363. +#include <ctype.h>
  6364. +#include <sys/vfs.h>
  6365. +
  6366. +#include "ipkg_utils.h"
  6367. +#include "pkg.h"
  6368. +#include "pkg_hash.h"
  6369. +
  6370. +void push_error_list(struct errlist ** errors, char * msg);
  6371. +void reverse_error_list(struct errlist **errors);
  6372. +void free_error_list(struct errlist **errors);
  6373. +
  6374. +struct errlist* error_list;
  6375. +
  6376. +int get_available_blocks(char * filesystem)
  6377. +{
  6378. + struct statfs sfs;
  6379. +
  6380. + if(statfs(filesystem, &sfs)){
  6381. + fprintf(stderr, "bad statfs\n");
  6382. + return 0;
  6383. + }
  6384. + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
  6385. + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
  6386. +}
  6387. +
  6388. +char **read_raw_pkgs_from_file(const char *file_name)
  6389. +{
  6390. + FILE *fp;
  6391. + char **ret;
  6392. +
  6393. + if(!(fp = fopen(file_name, "r"))){
  6394. + fprintf(stderr, "can't get %s open for read\n", file_name);
  6395. + return NULL;
  6396. + }
  6397. +
  6398. + ret = read_raw_pkgs_from_stream(fp);
  6399. +
  6400. + fclose(fp);
  6401. +
  6402. + return ret;
  6403. +}
  6404. +
  6405. +char **read_raw_pkgs_from_stream(FILE *fp)
  6406. +{
  6407. + char **raw = NULL, *buf, *scout;
  6408. + int count = 0;
  6409. + size_t size = 512;
  6410. +
  6411. + buf = malloc (size);
  6412. +
  6413. + while (fgets(buf, size, fp)) {
  6414. + while (strlen (buf) == (size - 1)
  6415. + && buf[size-2] != '\n') {
  6416. + size_t o = size - 1;
  6417. + size *= 2;
  6418. + buf = realloc (buf, size);
  6419. + if (fgets (buf + o, size - o, fp) == NULL)
  6420. + break;
  6421. + }
  6422. +
  6423. + if(!(count % 50))
  6424. + raw = realloc(raw, (count + 50) * sizeof(char *));
  6425. +
  6426. + if((scout = strchr(buf, '\n')))
  6427. + *scout = '\0';
  6428. +
  6429. + raw[count++] = strdup(buf);
  6430. + }
  6431. +
  6432. + raw = realloc(raw, (count + 1) * sizeof(char *));
  6433. + raw[count] = NULL;
  6434. +
  6435. + free (buf);
  6436. +
  6437. + return raw;
  6438. +}
  6439. +
  6440. +/* something to remove whitespace, a hash pooper */
  6441. +char *trim_alloc(char *line)
  6442. +{
  6443. + char *new;
  6444. + char *dest, *src, *end;
  6445. +
  6446. + new = malloc(strlen(line) + 1);
  6447. + if ( new == NULL ){
  6448. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  6449. + return NULL;
  6450. + }
  6451. + dest = new, src = line, end = line + (strlen(line) - 1);
  6452. +
  6453. + /* remove it from the front */
  6454. + while(src &&
  6455. + isspace(*src) &&
  6456. + *src)
  6457. + src++;
  6458. + /* and now from the back */
  6459. + while((end > src) &&
  6460. + isspace(*end))
  6461. + end--;
  6462. + end++;
  6463. + *end = '\0';
  6464. + strcpy(new, src);
  6465. + /* this does from the first space
  6466. + * blasting away any versions stuff in depends
  6467. + while(src &&
  6468. + !isspace(*src) &&
  6469. + *src)
  6470. + *dest++ = *src++;
  6471. + *dest = '\0';
  6472. + */
  6473. +
  6474. + return new;
  6475. +}
  6476. +
  6477. +int line_is_blank(const char *line)
  6478. +{
  6479. + const char *s;
  6480. +
  6481. + for (s = line; *s; s++) {
  6482. + if (!isspace(*s))
  6483. + return 0;
  6484. + }
  6485. + return 1;
  6486. +}
  6487. +
  6488. +void push_error_list(struct errlist ** errors, char * msg){
  6489. + struct errlist *err_lst_tmp;
  6490. +
  6491. +
  6492. + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
  6493. + err_lst_tmp->errmsg=strdup(msg) ;
  6494. + err_lst_tmp->next = *errors;
  6495. + *errors = err_lst_tmp;
  6496. +}
  6497. +
  6498. +
  6499. +void reverse_error_list(struct errlist **errors){
  6500. + struct errlist *result=NULL;
  6501. + struct errlist *current= *errors;
  6502. + struct errlist *next;
  6503. +
  6504. + while ( current != NULL ) {
  6505. + next = current->next;
  6506. + current->next=result;
  6507. + result=current;
  6508. + current=next;
  6509. + }
  6510. + *errors=result;
  6511. +
  6512. +}
  6513. +
  6514. +
  6515. +void free_error_list(struct errlist **errors){
  6516. + struct errlist *current = *errors;
  6517. +
  6518. + while (current != NULL) {
  6519. + free(current->errmsg);
  6520. + current = (*errors)->next;
  6521. + free(*errors);
  6522. + *errors = current;
  6523. + }
  6524. +
  6525. +
  6526. +}
  6527. +
  6528. +
  6529. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_utils.h busybox-1.17.0/archival/libipkg/ipkg_utils.h
  6530. --- busybox-1.17.0.orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
  6531. +++ busybox-1.17.0/archival/libipkg/ipkg_utils.h 2010-07-16 14:45:15.406576638 +0200
  6532. @@ -0,0 +1,29 @@
  6533. +/* ipkg_utils.h - the itsy package management system
  6534. +
  6535. + Steven M. Ayer
  6536. +
  6537. + Copyright (C) 2002 Compaq Computer Corporation
  6538. +
  6539. + This program is free software; you can redistribute it and/or
  6540. + modify it under the terms of the GNU General Public License as
  6541. + published by the Free Software Foundation; either version 2, or (at
  6542. + your option) any later version.
  6543. +
  6544. + This program is distributed in the hope that it will be useful, but
  6545. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6546. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6547. + General Public License for more details.
  6548. +*/
  6549. +
  6550. +#ifndef IPKG_UTILS_H
  6551. +#define IPKG_UTILS_H
  6552. +
  6553. +#include "pkg.h"
  6554. +
  6555. +int get_available_blocks(char * filesystem);
  6556. +char **read_raw_pkgs_from_file(const char *file_name);
  6557. +char **read_raw_pkgs_from_stream(FILE *fp);
  6558. +char *trim_alloc(char * line);
  6559. +int line_is_blank(const char *line);
  6560. +
  6561. +#endif
  6562. diff -Nur busybox-1.17.0.orig/archival/libipkg/Kbuild busybox-1.17.0/archival/libipkg/Kbuild
  6563. --- busybox-1.17.0.orig/archival/libipkg/Kbuild 1970-01-01 01:00:00.000000000 +0100
  6564. +++ busybox-1.17.0/archival/libipkg/Kbuild 2010-07-16 14:45:15.455870929 +0200
  6565. @@ -0,0 +1,60 @@
  6566. +# Makefile for busybox
  6567. +#
  6568. +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  6569. +# Copyright (C) 2006 OpenWrt.org
  6570. +#
  6571. +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  6572. +
  6573. +LIBIPKG_CORE_OBJS:= \
  6574. + args.o \
  6575. + libipkg.o \
  6576. + user.o \
  6577. +
  6578. +LIBIPKG_CMD_OBJS:= \
  6579. + ipkg_cmd.o \
  6580. + ipkg_configure.o \
  6581. + ipkg_download.o \
  6582. + ipkg_install.o \
  6583. + ipkg_remove.o \
  6584. + ipkg_upgrade.o \
  6585. +
  6586. +LIBIPKG_DB_OBJS:= \
  6587. + hash_table.o \
  6588. + ipkg_conf.o \
  6589. + ipkg_utils.o \
  6590. + pkg.o \
  6591. + pkg_depends.o \
  6592. + pkg_extract.o \
  6593. + pkg_hash.o \
  6594. + pkg_parse.o \
  6595. + pkg_vec.o \
  6596. +
  6597. +LIBIPKG_LIST_OBJS:= \
  6598. + conffile.o \
  6599. + conffile_list.o \
  6600. + nv_pair.o \
  6601. + nv_pair_list.o \
  6602. + pkg_dest.o \
  6603. + pkg_dest_list.o \
  6604. + pkg_src.o \
  6605. + pkg_src_list.o \
  6606. + str_list.o \
  6607. + void_list.o \
  6608. +
  6609. +LIBIPKG_UTIL_OBJS:= \
  6610. + file_util.o \
  6611. + ipkg_message.o \
  6612. + str_util.o \
  6613. + xsystem.o \
  6614. +
  6615. +lib-y :=
  6616. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
  6617. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
  6618. +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
  6619. +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
  6620. +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
  6621. +
  6622. +ifeq ($(strip $(IPKG_ARCH)),)
  6623. +IPKG_ARCH:=$(TARGET_ARCH)
  6624. +endif
  6625. +CFLAGS += -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
  6626. diff -Nur busybox-1.17.0.orig/archival/libipkg/libipkg.c busybox-1.17.0/archival/libipkg/libipkg.c
  6627. --- busybox-1.17.0.orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
  6628. +++ busybox-1.17.0/archival/libipkg/libipkg.c 2010-07-16 14:50:02.146220075 +0200
  6629. @@ -0,0 +1,570 @@
  6630. +/* ipkglib.c - the itsy package management system
  6631. +
  6632. + Florina Boor
  6633. +
  6634. + Copyright (C) 2003 kernel concepts
  6635. +
  6636. + This program is free software; you can redistribute it and/or
  6637. + modify it under the terms of the GNU General Public License as
  6638. + published by the Free Software Foundation; either version 2, or (at
  6639. + your option) any later version.
  6640. +
  6641. + This program is distributed in the hope that it will be useful, but
  6642. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6643. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6644. + General Public License for more details.
  6645. +*/
  6646. +
  6647. +#include "ipkg.h"
  6648. +#include "ipkg_includes.h"
  6649. +#include "libipkg.h"
  6650. +
  6651. +#include "args.h"
  6652. +#include "ipkg_conf.h"
  6653. +#include "ipkg_cmd.h"
  6654. +#include "file_util.h"
  6655. +
  6656. +int ipkg_file_what(args_t *args, const char *file, const char* command);
  6657. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  6658. + char *msg);
  6659. +int default_ipkg_list_callback(char *name, char *desc, char *version);
  6660. +int default_ipkg_files_callback(char *desc);
  6661. +int default_ipkg_status_callback(char *desc);
  6662. +char* default_ipkg_response_callback(char *question);
  6663. +
  6664. +
  6665. +ipkg_message_callback ipkg_cb_message = NULL;
  6666. +ipkg_response_callback ipkg_cb_response = NULL;
  6667. +ipkg_status_callback ipkg_cb_status = NULL;
  6668. +ipkg_list_callback ipkg_cb_list = NULL;
  6669. +
  6670. +
  6671. +int
  6672. +ipkg_init (ipkg_message_callback mcall,
  6673. + ipkg_response_callback rcall,
  6674. + args_t * args)
  6675. +{
  6676. + ipkg_cb_message = mcall;
  6677. + ipkg_cb_response = rcall;
  6678. +
  6679. + args_init (args);
  6680. +
  6681. + return 0;
  6682. +}
  6683. +
  6684. +
  6685. +int
  6686. +ipkg_deinit (args_t * args)
  6687. +{
  6688. + args_deinit (args);
  6689. + ipkg_cb_message = NULL;
  6690. + ipkg_cb_response = NULL;
  6691. +
  6692. + /* place other cleanup stuff here */
  6693. +
  6694. + return 0;
  6695. +}
  6696. +
  6697. +
  6698. +int
  6699. +ipkg_packages_list(args_t *args,
  6700. + const char *packages,
  6701. + ipkg_list_callback cblist,
  6702. + void *userdata)
  6703. +{
  6704. + ipkg_cmd_t *cmd;
  6705. + ipkg_conf_t ipkg_conf;
  6706. + int err;
  6707. +
  6708. + err = ipkg_conf_init (&ipkg_conf, args);
  6709. + if (err)
  6710. + {
  6711. + return err;
  6712. + }
  6713. +
  6714. + ipkg_cb_list = cblist;
  6715. + /* we need to do this because of static declarations,
  6716. + * maybe a good idea to change */
  6717. + cmd = ipkg_cmd_find ("list");
  6718. + if (packages)
  6719. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6720. + else
  6721. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6722. + ipkg_cb_list = NULL;
  6723. + ipkg_conf_deinit (&ipkg_conf);
  6724. + return (err);
  6725. +}
  6726. +
  6727. +
  6728. +int
  6729. +ipkg_packages_status(args_t *args,
  6730. + const char *packages,
  6731. + ipkg_status_callback cbstatus,
  6732. + void *userdata)
  6733. +{
  6734. + ipkg_cmd_t *cmd;
  6735. + ipkg_conf_t ipkg_conf;
  6736. + int err;
  6737. +
  6738. + err = ipkg_conf_init (&ipkg_conf, args);
  6739. + if (err)
  6740. + {
  6741. + return err;
  6742. + }
  6743. +
  6744. + ipkg_cb_status = cbstatus;
  6745. +
  6746. + /* we need to do this because of static declarations,
  6747. + * maybe a good idea to change */
  6748. + cmd = ipkg_cmd_find ("status");
  6749. + if (packages)
  6750. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6751. + else
  6752. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6753. +
  6754. + ipkg_cb_status = NULL;
  6755. + ipkg_conf_deinit (&ipkg_conf);
  6756. + return (err);
  6757. +}
  6758. +
  6759. +
  6760. +int
  6761. +ipkg_packages_info(args_t *args,
  6762. + const char *packages,
  6763. + ipkg_status_callback cbstatus,
  6764. + void *userdata)
  6765. +{
  6766. + ipkg_cmd_t *cmd;
  6767. + ipkg_conf_t ipkg_conf;
  6768. + int err;
  6769. +
  6770. + err = ipkg_conf_init (&ipkg_conf, args);
  6771. + if (err)
  6772. + {
  6773. + return err;
  6774. + }
  6775. +
  6776. + ipkg_cb_status = cbstatus;
  6777. +
  6778. + /* we need to do this because of static declarations,
  6779. + * maybe a good idea to change */
  6780. + cmd = ipkg_cmd_find ("info");
  6781. + if (packages)
  6782. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6783. + else
  6784. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6785. +
  6786. + ipkg_cb_status = NULL;
  6787. + ipkg_conf_deinit (&ipkg_conf);
  6788. + return (err);
  6789. +}
  6790. +
  6791. +
  6792. +int
  6793. +ipkg_packages_install (args_t * args, const char *name)
  6794. +{
  6795. + ipkg_cmd_t *cmd;
  6796. + ipkg_conf_t ipkg_conf;
  6797. + int err;
  6798. +
  6799. + /* this error should be handled in application */
  6800. + if (!name || !strlen (name))
  6801. + return (-1);
  6802. +
  6803. + err = ipkg_conf_init (&ipkg_conf, args);
  6804. + if (err)
  6805. + {
  6806. + return err;
  6807. + }
  6808. +
  6809. + /* we need to do this because of static declarations,
  6810. + * maybe a good idea to change */
  6811. + cmd = ipkg_cmd_find ("install");
  6812. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6813. +
  6814. + ipkg_conf_deinit(&ipkg_conf);
  6815. + return (err);
  6816. +}
  6817. +
  6818. +
  6819. +int
  6820. +ipkg_packages_remove(args_t *args, const char *name, int purge)
  6821. +{
  6822. + ipkg_cmd_t *cmd;
  6823. + ipkg_conf_t ipkg_conf;
  6824. + int err;
  6825. +
  6826. + /* this error should be handled in application */
  6827. + if (!name || !strlen (name))
  6828. + return (-1);
  6829. +
  6830. + err = ipkg_conf_init (&ipkg_conf, args);
  6831. + if (err)
  6832. + {
  6833. + return err;
  6834. + }
  6835. +
  6836. + /* we need to do this because of static declarations,
  6837. + * maybe a good idea to change */
  6838. + if (purge)
  6839. + cmd = ipkg_cmd_find ("purge");
  6840. + else
  6841. + cmd = ipkg_cmd_find ("remove");
  6842. +
  6843. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6844. +
  6845. + ipkg_conf_deinit(&ipkg_conf);
  6846. + return (err);
  6847. +}
  6848. +
  6849. +
  6850. +int
  6851. +ipkg_lists_update(args_t *args)
  6852. +{
  6853. + ipkg_cmd_t *cmd;
  6854. + ipkg_conf_t ipkg_conf;
  6855. + int err;
  6856. +
  6857. + err = ipkg_conf_init (&ipkg_conf, args);
  6858. + if (err)
  6859. + {
  6860. + return err;
  6861. + }
  6862. +
  6863. + /* we need to do this because of static declarations,
  6864. + * maybe a good idea to change */
  6865. + cmd = ipkg_cmd_find ("update");
  6866. +
  6867. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6868. +
  6869. + ipkg_conf_deinit(&ipkg_conf);
  6870. + return (err);
  6871. +}
  6872. +
  6873. +
  6874. +int
  6875. +ipkg_packages_upgrade(args_t *args)
  6876. +{
  6877. + ipkg_cmd_t *cmd;
  6878. + ipkg_conf_t ipkg_conf;
  6879. + int err;
  6880. +
  6881. + err = ipkg_conf_init (&ipkg_conf, args);
  6882. + if (err)
  6883. + {
  6884. + return err;
  6885. + }
  6886. +
  6887. + /* we need to do this because of static declarations,
  6888. + * maybe a good idea to change */
  6889. + cmd = ipkg_cmd_find ("upgrade");
  6890. +
  6891. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6892. +
  6893. + ipkg_conf_deinit(&ipkg_conf);
  6894. + return (err);
  6895. +}
  6896. +
  6897. +
  6898. +int
  6899. +ipkg_packages_download (args_t * args, const char *name)
  6900. +{
  6901. + ipkg_cmd_t *cmd;
  6902. + ipkg_conf_t ipkg_conf;
  6903. + int err;
  6904. +
  6905. + /* this error should be handled in application */
  6906. + if (!name || !strlen (name))
  6907. + return (-1);
  6908. +
  6909. + err = ipkg_conf_init (&ipkg_conf, args);
  6910. + if (err)
  6911. + {
  6912. + return err;
  6913. + }
  6914. +
  6915. + /* we need to do this because of static declarations,
  6916. + * maybe a good idea to change */
  6917. + cmd = ipkg_cmd_find ("download");
  6918. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6919. +
  6920. + ipkg_conf_deinit(&ipkg_conf);
  6921. + return (err);
  6922. +}
  6923. +
  6924. +
  6925. +int
  6926. +ipkg_package_files(args_t *args,
  6927. + const char *name,
  6928. + ipkg_list_callback cblist,
  6929. + void *userdata)
  6930. +{
  6931. + ipkg_cmd_t *cmd;
  6932. + ipkg_conf_t ipkg_conf;
  6933. + int err;
  6934. +
  6935. + /* this error should be handled in application */
  6936. + if (!name || !strlen (name))
  6937. + return (-1);
  6938. +
  6939. + err = ipkg_conf_init (&ipkg_conf, args);
  6940. + if (err)
  6941. + {
  6942. + return err;
  6943. + }
  6944. +
  6945. + ipkg_cb_list = cblist;
  6946. +
  6947. + /* we need to do this because of static declarations,
  6948. + * maybe a good idea to change */
  6949. + cmd = ipkg_cmd_find ("files");
  6950. +
  6951. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
  6952. +
  6953. + ipkg_cb_list = NULL;
  6954. + ipkg_conf_deinit(&ipkg_conf);
  6955. + return (err);
  6956. +}
  6957. +
  6958. +
  6959. +int
  6960. +ipkg_file_search(args_t *args,
  6961. + const char *file,
  6962. + ipkg_list_callback cblist,
  6963. + void *userdata)
  6964. +{
  6965. + ipkg_cmd_t *cmd;
  6966. + ipkg_conf_t ipkg_conf;
  6967. + int err;
  6968. +
  6969. + /* this error should be handled in application */
  6970. + if (!file || !strlen (file))
  6971. + return (-1);
  6972. +
  6973. + err = ipkg_conf_init (&ipkg_conf, args);
  6974. + if (err)
  6975. + {
  6976. + return err;
  6977. + }
  6978. +
  6979. + ipkg_cb_list = cblist;
  6980. +
  6981. + /* we need to do this because of static declarations,
  6982. + * maybe a good idea to change */
  6983. + cmd = ipkg_cmd_find ("search");
  6984. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
  6985. +
  6986. + ipkg_cb_list = NULL;
  6987. + ipkg_conf_deinit(&ipkg_conf);
  6988. + return(err);
  6989. +}
  6990. +
  6991. +
  6992. +int
  6993. +ipkg_file_what(args_t *args, const char *file, const char* command)
  6994. +{
  6995. + ipkg_cmd_t *cmd;
  6996. + ipkg_conf_t ipkg_conf;
  6997. + int err;
  6998. +
  6999. + /* this error should be handled in application */
  7000. + if (!file || !strlen (file))
  7001. + return (-1);
  7002. +
  7003. + err = ipkg_conf_init (&ipkg_conf, args);
  7004. + if (err)
  7005. + {
  7006. + return err;
  7007. + }
  7008. +
  7009. + /* we need to do this because of static declarations,
  7010. + * maybe a good idea to change */
  7011. + cmd = ipkg_cmd_find (command);
  7012. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
  7013. +
  7014. + ipkg_conf_deinit(&ipkg_conf);
  7015. + return(err);
  7016. +}
  7017. +
  7018. +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
  7019. +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
  7020. +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
  7021. +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
  7022. +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
  7023. +
  7024. +
  7025. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  7026. + char *msg)
  7027. +{
  7028. + if (conf && (conf->verbosity < level)) {
  7029. + return 0;
  7030. + } else {
  7031. + if ( level == IPKG_ERROR )
  7032. + push_error_list(&error_list, msg);
  7033. + else
  7034. + printf(msg);
  7035. + }
  7036. + return 0;
  7037. +}
  7038. +
  7039. +int default_ipkg_list_callback(char *name, char *desc, char *version)
  7040. +{
  7041. + if (desc)
  7042. + printf("%s - %s - %s\n", name, version, desc);
  7043. + else
  7044. + printf("%s - %s\n", name, version);
  7045. + return 0;
  7046. +}
  7047. +
  7048. +int default_ipkg_files_callback(char *desc)
  7049. +{
  7050. + if (desc)
  7051. + printf("%s\n", desc);
  7052. + return 0;
  7053. +}
  7054. +
  7055. +int default_ipkg_status_callback(char *desc)
  7056. +{
  7057. + printf("%s\n", desc);
  7058. + return 0;
  7059. +}
  7060. +
  7061. +char* default_ipkg_response_callback(char *question)
  7062. +{
  7063. + char *response = NULL;
  7064. + printf(question);
  7065. + fflush(stdout);
  7066. + do {
  7067. + response = (char *)file_read_line_alloc(stdin);
  7068. + } while (response == NULL);
  7069. + return response;
  7070. +}
  7071. +
  7072. +/* This is used for backward compatibility */
  7073. +int
  7074. +ipkg_op (int argc, char *argv[])
  7075. +{
  7076. + int err, optind_;
  7077. + args_t args;
  7078. + char *cmd_name;
  7079. + ipkg_cmd_t *cmd;
  7080. + ipkg_conf_t ipkg_conf;
  7081. + const char *message = "ipkg must have one sub-command argument";
  7082. + FILE *f;
  7083. + struct mntent *mnt;
  7084. + int remountroot;
  7085. +
  7086. + args_init (&args);
  7087. +
  7088. + optind_ = args_parse (&args, argc, argv);
  7089. + if (optind_ == argc || optind_ < 0)
  7090. + {
  7091. + args_usage(message);
  7092. + }
  7093. +
  7094. + cmd_name = argv[optind_++];
  7095. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  7096. + read anything from there.
  7097. +*/
  7098. + if ( !strcmp(cmd_name,"print-architecture") ||
  7099. + !strcmp(cmd_name,"print_architecture") ||
  7100. + !strcmp(cmd_name,"print-installation-architecture") ||
  7101. + !strcmp(cmd_name,"print_installation_architecture") )
  7102. + args.nocheckfordirorfile = 1;
  7103. +
  7104. +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
  7105. + read anything from there.
  7106. +*/
  7107. + if ( !strcmp(cmd_name,"flag") ||
  7108. + !strcmp(cmd_name,"configure") ||
  7109. + !strcmp(cmd_name,"remove") ||
  7110. + !strcmp(cmd_name,"files") ||
  7111. + !strcmp(cmd_name,"search") ||
  7112. + !strcmp(cmd_name,"compare_versions") ||
  7113. + !strcmp(cmd_name,"compare-versions") ||
  7114. + !strcmp(cmd_name,"list_installed") ||
  7115. + !strcmp(cmd_name,"list-installed") ||
  7116. + !strcmp(cmd_name,"status") )
  7117. + args.noreadfeedsfile = 1;
  7118. +
  7119. +
  7120. + remountroot = 0;
  7121. + /* check if /dev/root is mounted read-only */
  7122. + if ((f = setmntent("/proc/mounts", "r")) == NULL)
  7123. + fprintf (stderr, "Checking /proc/mounts failed\n");
  7124. +
  7125. + while ((mnt = getmntent(f)) != NULL) {
  7126. + if (strcmp(mnt->mnt_fsname, "/dev/root") == 0 &&
  7127. + hasmntopt(mnt, MNTOPT_RO) != NULL) {
  7128. + remountroot = 1;
  7129. + }
  7130. + }
  7131. +
  7132. + endmntent(f);
  7133. +
  7134. + if (remountroot) {
  7135. + if ( !strcmp(cmd_name,"install") ||
  7136. + !strcmp(cmd_name,"update") ||
  7137. + !strcmp(cmd_name,"upgrade") ||
  7138. + !strcmp(cmd_name,"flag") ||
  7139. + !strcmp(cmd_name,"configure") ||
  7140. + !strcmp(cmd_name,"remove") ) {
  7141. + /* mount rootfs read-write */
  7142. + if (mount("","/",0,MS_REMOUNT,0)<0)
  7143. + fprintf (stderr, "Mounting rootfs read-write failed\n");
  7144. + }
  7145. + }
  7146. +
  7147. +
  7148. + err = ipkg_conf_init (&ipkg_conf, &args);
  7149. + if (err)
  7150. + {
  7151. + return err;
  7152. + }
  7153. +
  7154. + args_deinit (&args);
  7155. +
  7156. + ipkg_cb_message = default_ipkg_message_callback;
  7157. + ipkg_cb_response = default_ipkg_response_callback;
  7158. + ipkg_cb_status = (ipkg_status_callback)default_ipkg_status_callback;
  7159. + if ( strcmp(cmd_name, "files")==0)
  7160. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_files_callback;
  7161. + else
  7162. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_list_callback;
  7163. +
  7164. + cmd = ipkg_cmd_find (cmd_name);
  7165. + if (cmd == NULL)
  7166. + {
  7167. + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
  7168. + cmd_name);
  7169. + args_usage (NULL);
  7170. + }
  7171. +
  7172. + if (cmd->requires_args && optind_ == argc)
  7173. + {
  7174. + fprintf (stderr,
  7175. + "%s: the ``%s'' command requires at least one argument\n",
  7176. + __FUNCTION__, cmd_name);
  7177. + args_usage (NULL);
  7178. + }
  7179. +
  7180. + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind_, (const char **) (argv + optind_), NULL);
  7181. +
  7182. + ipkg_conf_deinit (&ipkg_conf);
  7183. +
  7184. + if (remountroot) {
  7185. + if ( !strcmp(cmd_name,"install") ||
  7186. + !strcmp(cmd_name,"update") ||
  7187. + !strcmp(cmd_name,"upgrade") ||
  7188. + !strcmp(cmd_name,"flag") ||
  7189. + !strcmp(cmd_name,"configure") ||
  7190. + !strcmp(cmd_name,"remove") ) {
  7191. + sync();
  7192. + /* mount rootfs read-only */
  7193. + if (mount("","/",0,MS_REMOUNT|MS_RDONLY,0)<0)
  7194. + fprintf (stderr, "Mounting rootfs read-only failed\n");
  7195. + }
  7196. + }
  7197. +
  7198. + return err;
  7199. +}
  7200. diff -Nur busybox-1.17.0.orig/archival/libipkg/libipkg.h busybox-1.17.0/archival/libipkg/libipkg.h
  7201. --- busybox-1.17.0.orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
  7202. +++ busybox-1.17.0/archival/libipkg/libipkg.h 2010-07-16 14:45:15.555913735 +0200
  7203. @@ -0,0 +1,78 @@
  7204. +/* ipkglib.h - the itsy package management system
  7205. +
  7206. + Florian Boor <florian.boor@kernelconcepts.de>
  7207. +
  7208. + This program is free software; you can redistribute it and/or
  7209. + modify it under the terms of the GNU General Public License as
  7210. + published by the Free Software Foundation; either version 2, or (at
  7211. + your option) any later version.
  7212. +
  7213. + This program is distributed in the hope that it will be useful, but
  7214. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7215. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7216. + General Public License for more details.
  7217. +*/
  7218. +
  7219. +#ifndef IPKGLIB_H
  7220. +#define IPKGLIB_H
  7221. +
  7222. +#include "ipkg_conf.h"
  7223. +#include "ipkg_message.h"
  7224. +
  7225. +#include "args.h"
  7226. +#include "pkg.h"
  7227. +
  7228. +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
  7229. + char *msg);
  7230. +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
  7231. + pkg_state_status_t status, void *userdata);
  7232. +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
  7233. + void *userdata);
  7234. +typedef char* (*ipkg_response_callback)(char *question);
  7235. +
  7236. +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
  7237. +extern int ipkg_init (ipkg_message_callback mcall,
  7238. + ipkg_response_callback rcall,
  7239. + args_t * args);
  7240. +
  7241. +extern int ipkg_deinit (args_t *args);
  7242. +extern int ipkg_packages_list(args_t *args,
  7243. + const char *packages,
  7244. + ipkg_list_callback cblist,
  7245. + void *userdata);
  7246. +extern int ipkg_packages_status(args_t *args,
  7247. + const char *packages,
  7248. + ipkg_status_callback cbstatus,
  7249. + void *userdata);
  7250. +extern int ipkg_packages_info(args_t *args,
  7251. + const char *packages,
  7252. + ipkg_status_callback cbstatus,
  7253. + void *userdata);
  7254. +extern int ipkg_packages_install(args_t *args, const char *name);
  7255. +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
  7256. +extern int ipkg_lists_update(args_t *args);
  7257. +extern int ipkg_packages_upgrade(args_t *args);
  7258. +extern int ipkg_packages_download(args_t *args, const char *name);
  7259. +extern int ipkg_package_files(args_t *args,
  7260. + const char *name,
  7261. + ipkg_list_callback cblist,
  7262. + void *userdata);
  7263. +extern int ipkg_file_search(args_t *args,
  7264. + const char *file,
  7265. + ipkg_list_callback cblist,
  7266. + void *userdata);
  7267. +extern int ipkg_package_whatdepends(args_t *args, const char *file);
  7268. +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
  7269. +extern int ipkg_package_whatprovides(args_t *args, const char *file);
  7270. +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
  7271. +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
  7272. +
  7273. +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
  7274. +extern ipkg_response_callback ipkg_cb_response;
  7275. +extern ipkg_status_callback ipkg_cb_status;
  7276. +extern ipkg_list_callback ipkg_cb_list;
  7277. +extern void push_error_list(struct errlist **errors,char * msg);
  7278. +extern void reverse_error_list(struct errlist **errors);
  7279. +extern void free_error_list(struct errlist **errors);
  7280. +
  7281. +#endif
  7282. diff -Nur busybox-1.17.0.orig/archival/libipkg/nv_pair.c busybox-1.17.0/archival/libipkg/nv_pair.c
  7283. --- busybox-1.17.0.orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
  7284. +++ busybox-1.17.0/archival/libipkg/nv_pair.c 2010-07-16 14:45:15.615872635 +0200
  7285. @@ -0,0 +1,40 @@
  7286. +/* nv_pair.c - the itsy package management system
  7287. +
  7288. + Carl D. Worth
  7289. +
  7290. + Copyright (C) 2001 University of Southern California
  7291. +
  7292. + This program is free software; you can redistribute it and/or
  7293. + modify it under the terms of the GNU General Public License as
  7294. + published by the Free Software Foundation; either version 2, or (at
  7295. + your option) any later version.
  7296. +
  7297. + This program is distributed in the hope that it will be useful, but
  7298. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7299. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7300. + General Public License for more details.
  7301. +*/
  7302. +
  7303. +#include "ipkg.h"
  7304. +
  7305. +#include "nv_pair.h"
  7306. +#include "str_util.h"
  7307. +
  7308. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
  7309. +{
  7310. + nv_pair->name = str_dup_safe(name);
  7311. + nv_pair->value = str_dup_safe(value);
  7312. +
  7313. + return 0;
  7314. +}
  7315. +
  7316. +void nv_pair_deinit(nv_pair_t *nv_pair)
  7317. +{
  7318. + free(nv_pair->name);
  7319. + nv_pair->name = NULL;
  7320. +
  7321. + free(nv_pair->value);
  7322. + nv_pair->value = NULL;
  7323. +}
  7324. +
  7325. +
  7326. diff -Nur busybox-1.17.0.orig/archival/libipkg/nv_pair.h busybox-1.17.0/archival/libipkg/nv_pair.h
  7327. --- busybox-1.17.0.orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
  7328. +++ busybox-1.17.0/archival/libipkg/nv_pair.h 2010-07-16 14:45:15.665893931 +0200
  7329. @@ -0,0 +1,32 @@
  7330. +/* nv_pair.h - the itsy package management system
  7331. +
  7332. + Carl D. Worth
  7333. +
  7334. + Copyright (C) 2001 University of Southern California
  7335. +
  7336. + This program is free software; you can redistribute it and/or
  7337. + modify it under the terms of the GNU General Public License as
  7338. + published by the Free Software Foundation; either version 2, or (at
  7339. + your option) any later version.
  7340. +
  7341. + This program is distributed in the hope that it will be useful, but
  7342. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7343. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7344. + General Public License for more details.
  7345. +*/
  7346. +
  7347. +#ifndef NV_PAIR_H
  7348. +#define NV_PAIR_H
  7349. +
  7350. +typedef struct nv_pair nv_pair_t;
  7351. +struct nv_pair
  7352. +{
  7353. + char *name;
  7354. + char *value;
  7355. +};
  7356. +
  7357. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
  7358. +void nv_pair_deinit(nv_pair_t *nv_pair);
  7359. +
  7360. +#endif
  7361. +
  7362. diff -Nur busybox-1.17.0.orig/archival/libipkg/nv_pair_list.c busybox-1.17.0/archival/libipkg/nv_pair_list.c
  7363. --- busybox-1.17.0.orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
  7364. +++ busybox-1.17.0/archival/libipkg/nv_pair_list.c 2010-07-16 14:45:15.715867897 +0200
  7365. @@ -0,0 +1,98 @@
  7366. +/* nv_pair_list.c - the itsy package management system
  7367. +
  7368. + Carl D. Worth
  7369. +
  7370. + Copyright (C) 2001 University of Southern California
  7371. +
  7372. + This program is free software; you can redistribute it and/or
  7373. + modify it under the terms of the GNU General Public License as
  7374. + published by the Free Software Foundation; either version 2, or (at
  7375. + your option) any later version.
  7376. +
  7377. + This program is distributed in the hope that it will be useful, but
  7378. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7379. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7380. + General Public License for more details.
  7381. +*/
  7382. +
  7383. +#include "ipkg.h"
  7384. +
  7385. +#include "nv_pair.h"
  7386. +#include "void_list.h"
  7387. +#include "nv_pair_list.h"
  7388. +
  7389. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
  7390. +{
  7391. + return void_list_elt_init((void_list_elt_t *) elt, data);
  7392. +}
  7393. +
  7394. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
  7395. +{
  7396. + void_list_elt_deinit((void_list_elt_t *) elt);
  7397. +}
  7398. +
  7399. +int nv_pair_list_init(nv_pair_list_t *list)
  7400. +{
  7401. + return void_list_init((void_list_t *) list);
  7402. +}
  7403. +
  7404. +void nv_pair_list_deinit(nv_pair_list_t *list)
  7405. +{
  7406. + nv_pair_list_elt_t *iter;
  7407. + nv_pair_t *nv_pair;
  7408. +
  7409. + for (iter = list->head; iter; iter = iter->next) {
  7410. + nv_pair = iter->data;
  7411. + nv_pair_deinit(nv_pair);
  7412. +
  7413. + /* malloced in nv_pair_list_append */
  7414. + free(nv_pair);
  7415. + iter->data = NULL;
  7416. + }
  7417. + void_list_deinit((void_list_t *) list);
  7418. +}
  7419. +
  7420. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
  7421. +{
  7422. + int err;
  7423. +
  7424. + /* freed in nv_pair_list_deinit */
  7425. + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
  7426. +
  7427. + if (nv_pair == NULL) {
  7428. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7429. + return NULL;
  7430. + }
  7431. + nv_pair_init(nv_pair, name, value);
  7432. +
  7433. + err = void_list_append((void_list_t *) list, nv_pair);
  7434. + if (err) {
  7435. + return NULL;
  7436. + }
  7437. +
  7438. + return nv_pair;
  7439. +}
  7440. +
  7441. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
  7442. +{
  7443. + return void_list_push((void_list_t *) list, data);
  7444. +}
  7445. +
  7446. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
  7447. +{
  7448. + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
  7449. +}
  7450. +
  7451. +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
  7452. +{
  7453. + nv_pair_list_elt_t *iter;
  7454. + nv_pair_t *nv_pair;
  7455. +
  7456. + for (iter = list->head; iter; iter = iter->next) {
  7457. + nv_pair = iter->data;
  7458. + if (strcmp(nv_pair->name, name) == 0) {
  7459. + return nv_pair->value;
  7460. + }
  7461. + }
  7462. + return NULL;
  7463. +}
  7464. diff -Nur busybox-1.17.0.orig/archival/libipkg/nv_pair_list.h busybox-1.17.0/archival/libipkg/nv_pair_list.h
  7465. --- busybox-1.17.0.orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
  7466. +++ busybox-1.17.0/archival/libipkg/nv_pair_list.h 2010-07-16 14:45:15.785860379 +0200
  7467. @@ -0,0 +1,60 @@
  7468. +/* nv_pair_list.h - the itsy package management system
  7469. +
  7470. + Carl D. Worth
  7471. +
  7472. + Copyright (C) 2001 University of Southern California
  7473. +
  7474. + This program is free software; you can redistribute it and/or
  7475. + modify it under the terms of the GNU General Public License as
  7476. + published by the Free Software Foundation; either version 2, or (at
  7477. + your option) any later version.
  7478. +
  7479. + This program is distributed in the hope that it will be useful, but
  7480. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7481. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7482. + General Public License for more details.
  7483. +*/
  7484. +
  7485. +#ifndef NV_PAIR_LIST_H
  7486. +#define NV_PAIR_LIST_H
  7487. +
  7488. +#include "nv_pair.h"
  7489. +#include "void_list.h"
  7490. +
  7491. +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
  7492. +struct nv_pair_list_elt
  7493. +{
  7494. + nv_pair_list_elt_t *next;
  7495. + nv_pair_t *data;
  7496. +};
  7497. +
  7498. +typedef struct nv_pair_list nv_pair_list_t;
  7499. +struct nv_pair_list
  7500. +{
  7501. + nv_pair_list_elt_t pre_head;
  7502. + nv_pair_list_elt_t *head;
  7503. + nv_pair_list_elt_t *tail;
  7504. +};
  7505. +
  7506. +static inline int nv_pair_list_empty(nv_pair_list_t *list)
  7507. +{
  7508. + if (list->head == NULL)
  7509. + return 1;
  7510. + else
  7511. + return 0;
  7512. +}
  7513. +
  7514. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
  7515. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
  7516. +
  7517. +int nv_pair_list_init(nv_pair_list_t *list);
  7518. +void nv_pair_list_deinit(nv_pair_list_t *list);
  7519. +
  7520. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
  7521. + const char *name, const char *value);
  7522. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
  7523. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
  7524. +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
  7525. +
  7526. +#endif
  7527. +
  7528. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg.c busybox-1.17.0/archival/libipkg/pkg.c
  7529. --- busybox-1.17.0.orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
  7530. +++ busybox-1.17.0/archival/libipkg/pkg.c 2010-07-16 14:45:15.845860385 +0200
  7531. @@ -0,0 +1,1757 @@
  7532. +/* pkg.c - the itsy package management system
  7533. +
  7534. + Carl D. Worth
  7535. +
  7536. + Copyright (C) 2001 University of Southern California
  7537. +
  7538. + This program is free software; you can redistribute it and/or
  7539. + modify it under the terms of the GNU General Public License as
  7540. + published by the Free Software Foundation; either version 2, or (at
  7541. + your option) any later version.
  7542. +
  7543. + This program is distributed in the hope that it will be useful, but
  7544. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7545. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7546. + General Public License for more details.
  7547. +*/
  7548. +
  7549. +#include "ipkg.h"
  7550. +#include <ctype.h>
  7551. +#include <string.h>
  7552. +#include <errno.h>
  7553. +
  7554. +#include "pkg.h"
  7555. +
  7556. +#include "pkg_parse.h"
  7557. +#include "pkg_extract.h"
  7558. +#include "ipkg_message.h"
  7559. +#include "ipkg_utils.h"
  7560. +
  7561. +#include "sprintf_alloc.h"
  7562. +#include "file_util.h"
  7563. +#include "str_util.h"
  7564. +#include "xsystem.h"
  7565. +#include "ipkg_conf.h"
  7566. +
  7567. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname);
  7568. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_);
  7569. +
  7570. +typedef struct enum_map enum_map_t;
  7571. +struct enum_map
  7572. +{
  7573. + int value;
  7574. + const char *str;
  7575. +};
  7576. +
  7577. +static const enum_map_t pkg_state_want_map[] = {
  7578. + { SW_UNKNOWN, "unknown"},
  7579. + { SW_INSTALL, "install"},
  7580. + { SW_DEINSTALL, "deinstall"},
  7581. + { SW_PURGE, "purge"}
  7582. +};
  7583. +
  7584. +static const enum_map_t pkg_state_flag_map[] = {
  7585. + { SF_OK, "ok"},
  7586. + { SF_REINSTREQ, "reinstreq"},
  7587. + { SF_HOLD, "hold"},
  7588. + { SF_REPLACE, "replace"},
  7589. + { SF_NOPRUNE, "noprune"},
  7590. + { SF_PREFER, "prefer"},
  7591. + { SF_OBSOLETE, "obsolete"},
  7592. + { SF_USER, "user"},
  7593. +};
  7594. +
  7595. +static const enum_map_t pkg_state_status_map[] = {
  7596. + { SS_NOT_INSTALLED, "not-installed" },
  7597. + { SS_UNPACKED, "unpacked" },
  7598. + { SS_HALF_CONFIGURED, "half-configured" },
  7599. + { SS_INSTALLED, "installed" },
  7600. + { SS_HALF_INSTALLED, "half-installed" },
  7601. + { SS_CONFIG_FILES, "config-files" },
  7602. + { SS_POST_INST_FAILED, "post-inst-failed" },
  7603. + { SS_REMOVAL_FAILED, "removal-failed" }
  7604. +};
  7605. +
  7606. +static int verrevcmp(const char *val, const char *ref);
  7607. +
  7608. +
  7609. +pkg_t *pkg_new(void)
  7610. +{
  7611. + pkg_t *pkg;
  7612. +
  7613. + pkg = malloc(sizeof(pkg_t));
  7614. + if (pkg == NULL) {
  7615. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7616. + return NULL;
  7617. + }
  7618. +
  7619. + pkg_init(pkg);
  7620. +
  7621. + return pkg;
  7622. +}
  7623. +
  7624. +int pkg_init(pkg_t *pkg)
  7625. +{
  7626. + memset(pkg, 0, sizeof(pkg_t));
  7627. + pkg->name = NULL;
  7628. + pkg->epoch = 0;
  7629. + pkg->version = NULL;
  7630. + pkg->revision = NULL;
  7631. + pkg->familiar_revision = NULL;
  7632. + pkg->dest = NULL;
  7633. + pkg->src = NULL;
  7634. + pkg->architecture = NULL;
  7635. + pkg->maintainer = NULL;
  7636. + pkg->section = NULL;
  7637. + pkg->description = NULL;
  7638. + pkg->state_want = SW_UNKNOWN;
  7639. + pkg->state_flag = SF_OK;
  7640. + pkg->state_status = SS_NOT_INSTALLED;
  7641. + pkg->depends_str = NULL;
  7642. + pkg->provides_str = NULL;
  7643. + pkg->depends_count = 0;
  7644. + pkg->depends = NULL;
  7645. + pkg->suggests_str = NULL;
  7646. + pkg->recommends_str = NULL;
  7647. + pkg->suggests_count = 0;
  7648. + pkg->recommends_count = 0;
  7649. +
  7650. + /* Abhaya: added init for conflicts fields */
  7651. + pkg->conflicts = NULL;
  7652. + pkg->conflicts_count = 0;
  7653. +
  7654. + /* added for replaces. Jamey 7/23/2002 */
  7655. + pkg->replaces = NULL;
  7656. + pkg->replaces_count = 0;
  7657. +
  7658. + pkg->pre_depends_count = 0;
  7659. + pkg->pre_depends_str = NULL;
  7660. + pkg->provides_count = 0;
  7661. + pkg->provides = NULL;
  7662. + pkg->filename = NULL;
  7663. + pkg->local_filename = NULL;
  7664. + pkg->tmp_unpack_dir = NULL;
  7665. + pkg->md5sum = NULL;
  7666. + pkg->size = NULL;
  7667. + pkg->installed_size = NULL;
  7668. + pkg->priority = NULL;
  7669. + pkg->source = NULL;
  7670. + conffile_list_init(&pkg->conffiles);
  7671. + pkg->installed_files = NULL;
  7672. + pkg->installed_files_ref_cnt = 0;
  7673. + pkg->essential = 0;
  7674. + pkg->provided_by_hand = 0;
  7675. +
  7676. + return 0;
  7677. +}
  7678. +
  7679. +void pkg_deinit(pkg_t *pkg)
  7680. +{
  7681. + free(pkg->name);
  7682. + pkg->name = NULL;
  7683. + pkg->epoch = 0;
  7684. + free(pkg->version);
  7685. + pkg->version = NULL;
  7686. + /* revision and familiar_revision share storage with version, so
  7687. + don't free */
  7688. + pkg->revision = NULL;
  7689. + pkg->familiar_revision = NULL;
  7690. + /* owned by ipkg_conf_t */
  7691. + pkg->dest = NULL;
  7692. + /* owned by ipkg_conf_t */
  7693. + pkg->src = NULL;
  7694. + free(pkg->architecture);
  7695. + pkg->architecture = NULL;
  7696. + free(pkg->maintainer);
  7697. + pkg->maintainer = NULL;
  7698. + free(pkg->section);
  7699. + pkg->section = NULL;
  7700. + free(pkg->description);
  7701. + pkg->description = NULL;
  7702. + pkg->state_want = SW_UNKNOWN;
  7703. + pkg->state_flag = SF_OK;
  7704. + pkg->state_status = SS_NOT_INSTALLED;
  7705. + free(pkg->depends_str);
  7706. + pkg->depends_str = NULL;
  7707. + free(pkg->provides_str);
  7708. + pkg->provides_str = NULL;
  7709. + pkg->depends_count = 0;
  7710. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
  7711. + pkg->pre_depends_count = 0;
  7712. + free(pkg->pre_depends_str);
  7713. + pkg->pre_depends_str = NULL;
  7714. + pkg->provides_count = 0;
  7715. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
  7716. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
  7717. + free(pkg->filename);
  7718. + pkg->filename = NULL;
  7719. + free(pkg->local_filename);
  7720. + pkg->local_filename = NULL;
  7721. + /* CLEANUP: It'd be nice to pullin the cleanup function from
  7722. + ipkg_install.c here. See comment in
  7723. + ipkg_install.c:cleanup_temporary_files */
  7724. + free(pkg->tmp_unpack_dir);
  7725. + pkg->tmp_unpack_dir = NULL;
  7726. + free(pkg->md5sum);
  7727. + pkg->md5sum = NULL;
  7728. + free(pkg->size);
  7729. + pkg->size = NULL;
  7730. + free(pkg->installed_size);
  7731. + pkg->installed_size = NULL;
  7732. + free(pkg->priority);
  7733. + pkg->priority = NULL;
  7734. + free(pkg->source);
  7735. + pkg->source = NULL;
  7736. + conffile_list_deinit(&pkg->conffiles);
  7737. + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
  7738. + since if they are calling deinit, they should know. Maybe do an
  7739. + assertion here instead? */
  7740. + pkg->installed_files_ref_cnt = 1;
  7741. + pkg_free_installed_files(pkg);
  7742. + pkg->essential = 0;
  7743. +}
  7744. +
  7745. +int pkg_init_from_file(pkg_t *pkg, const char *filename)
  7746. +{
  7747. + int err;
  7748. + char **raw;
  7749. + FILE *control_file;
  7750. +
  7751. + err = pkg_init(pkg);
  7752. + if (err) { return err; }
  7753. +
  7754. + pkg->local_filename = strdup(filename);
  7755. +
  7756. + control_file = tmpfile();
  7757. + err = pkg_extract_control_file_to_stream(pkg, control_file);
  7758. + if (err) { return err; }
  7759. +
  7760. + rewind(control_file);
  7761. + raw = read_raw_pkgs_from_stream(control_file);
  7762. + pkg_parse_raw(pkg, &raw, NULL, NULL);
  7763. +
  7764. + fclose(control_file);
  7765. +
  7766. + return 0;
  7767. +}
  7768. +
  7769. +/* Merge any new information in newpkg into oldpkg */
  7770. +/* XXX: CLEANUP: This function shouldn't actually modify anything in
  7771. + newpkg, but should leave it usable. This rework is so that
  7772. + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
  7773. +/*
  7774. + * uh, i thought that i had originally written this so that it took
  7775. + * two pkgs and returned a new one? we can do that again... -sma
  7776. + */
  7777. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
  7778. +{
  7779. + if (oldpkg == newpkg) {
  7780. + return 0;
  7781. + }
  7782. +
  7783. + if (!oldpkg->src)
  7784. + oldpkg->src = newpkg->src;
  7785. + if (!oldpkg->dest)
  7786. + oldpkg->dest = newpkg->dest;
  7787. + if (!oldpkg->architecture)
  7788. + oldpkg->architecture = str_dup_safe(newpkg->architecture);
  7789. + if (!oldpkg->arch_priority)
  7790. + oldpkg->arch_priority = newpkg->arch_priority;
  7791. + if (!oldpkg->section)
  7792. + oldpkg->section = str_dup_safe(newpkg->section);
  7793. + if(!oldpkg->maintainer)
  7794. + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
  7795. + if(!oldpkg->description)
  7796. + oldpkg->description = str_dup_safe(newpkg->description);
  7797. + if (set_status) {
  7798. + /* merge the state_flags from the new package */
  7799. + oldpkg->state_want = newpkg->state_want;
  7800. + oldpkg->state_status = newpkg->state_status;
  7801. + oldpkg->state_flag = newpkg->state_flag;
  7802. + } else {
  7803. + if (oldpkg->state_want == SW_UNKNOWN)
  7804. + oldpkg->state_want = newpkg->state_want;
  7805. + if (oldpkg->state_status == SS_NOT_INSTALLED)
  7806. + oldpkg->state_status = newpkg->state_status;
  7807. + oldpkg->state_flag |= newpkg->state_flag;
  7808. + }
  7809. +
  7810. + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
  7811. + oldpkg->depends_str = newpkg->depends_str;
  7812. + newpkg->depends_str = NULL;
  7813. + oldpkg->depends_count = newpkg->depends_count;
  7814. + newpkg->depends_count = 0;
  7815. +
  7816. + oldpkg->depends = newpkg->depends;
  7817. + newpkg->depends = NULL;
  7818. +
  7819. + oldpkg->pre_depends_str = newpkg->pre_depends_str;
  7820. + newpkg->pre_depends_str = NULL;
  7821. + oldpkg->pre_depends_count = newpkg->pre_depends_count;
  7822. + newpkg->pre_depends_count = 0;
  7823. +
  7824. + oldpkg->recommends_str = newpkg->recommends_str;
  7825. + newpkg->recommends_str = NULL;
  7826. + oldpkg->recommends_count = newpkg->recommends_count;
  7827. + newpkg->recommends_count = 0;
  7828. +
  7829. + oldpkg->suggests_str = newpkg->suggests_str;
  7830. + newpkg->suggests_str = NULL;
  7831. + oldpkg->suggests_count = newpkg->suggests_count;
  7832. + newpkg->suggests_count = 0;
  7833. + }
  7834. +
  7835. + if (!oldpkg->provides_str) {
  7836. + oldpkg->provides_str = newpkg->provides_str;
  7837. + newpkg->provides_str = NULL;
  7838. + oldpkg->provides_count = newpkg->provides_count;
  7839. + newpkg->provides_count = 0;
  7840. +
  7841. + oldpkg->provides = newpkg->provides;
  7842. + newpkg->provides = NULL;
  7843. + }
  7844. +
  7845. + if (!oldpkg->conflicts_str) {
  7846. + oldpkg->conflicts_str = newpkg->conflicts_str;
  7847. + newpkg->conflicts_str = NULL;
  7848. + oldpkg->conflicts_count = newpkg->conflicts_count;
  7849. + newpkg->conflicts_count = 0;
  7850. +
  7851. + oldpkg->conflicts = newpkg->conflicts;
  7852. + newpkg->conflicts = NULL;
  7853. + }
  7854. +
  7855. + if (!oldpkg->replaces_str) {
  7856. + oldpkg->replaces_str = newpkg->replaces_str;
  7857. + newpkg->replaces_str = NULL;
  7858. + oldpkg->replaces_count = newpkg->replaces_count;
  7859. + newpkg->replaces_count = 0;
  7860. +
  7861. + oldpkg->replaces = newpkg->replaces;
  7862. + newpkg->replaces = NULL;
  7863. + }
  7864. +
  7865. + if (!oldpkg->filename)
  7866. + oldpkg->filename = str_dup_safe(newpkg->filename);
  7867. + if (0)
  7868. + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
  7869. + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
  7870. + if (!oldpkg->local_filename)
  7871. + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
  7872. + if (!oldpkg->tmp_unpack_dir)
  7873. + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
  7874. + if (!oldpkg->md5sum)
  7875. + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
  7876. + if (!oldpkg->size)
  7877. + oldpkg->size = str_dup_safe(newpkg->size);
  7878. + if (!oldpkg->installed_size)
  7879. + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
  7880. + if (!oldpkg->priority)
  7881. + oldpkg->priority = str_dup_safe(newpkg->priority);
  7882. + if (!oldpkg->source)
  7883. + oldpkg->source = str_dup_safe(newpkg->source);
  7884. + if (oldpkg->conffiles.head == NULL){
  7885. + oldpkg->conffiles = newpkg->conffiles;
  7886. + conffile_list_init(&newpkg->conffiles);
  7887. + }
  7888. + if (!oldpkg->installed_files){
  7889. + oldpkg->installed_files = newpkg->installed_files;
  7890. + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
  7891. + newpkg->installed_files = NULL;
  7892. + }
  7893. + if (!oldpkg->essential)
  7894. + oldpkg->essential = newpkg->essential;
  7895. +
  7896. + return 0;
  7897. +}
  7898. +
  7899. +abstract_pkg_t *abstract_pkg_new(void)
  7900. +{
  7901. + abstract_pkg_t * ab_pkg;
  7902. +
  7903. + ab_pkg = malloc(sizeof(abstract_pkg_t));
  7904. +
  7905. + if (ab_pkg == NULL) {
  7906. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7907. + return NULL;
  7908. + }
  7909. +
  7910. + if ( abstract_pkg_init(ab_pkg) < 0 )
  7911. + return NULL;
  7912. +
  7913. + return ab_pkg;
  7914. +}
  7915. +
  7916. +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
  7917. +{
  7918. + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
  7919. +
  7920. + ab_pkg->provided_by = abstract_pkg_vec_alloc();
  7921. + if (ab_pkg->provided_by==NULL){
  7922. + return -1;
  7923. + }
  7924. + ab_pkg->dependencies_checked = 0;
  7925. + ab_pkg->state_status = SS_NOT_INSTALLED;
  7926. +
  7927. + return 0;
  7928. +}
  7929. +
  7930. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
  7931. + char * temp_str;
  7932. + char **raw =NULL;
  7933. + char **raw_start=NULL;
  7934. +
  7935. + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
  7936. + if (temp_str == NULL ){
  7937. + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
  7938. + return;
  7939. + }
  7940. + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
  7941. +
  7942. + raw = raw_start = read_raw_pkgs_from_file(temp_str);
  7943. + if (raw == NULL ){
  7944. + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
  7945. + return;
  7946. + }
  7947. +
  7948. + while(*raw){
  7949. + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
  7950. + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
  7951. + }
  7952. + }
  7953. + raw = raw_start;
  7954. + while (*raw) {
  7955. + if (raw!=NULL)
  7956. + free(*raw++);
  7957. + }
  7958. +
  7959. + free(raw_start);
  7960. + free(temp_str);
  7961. +
  7962. + return ;
  7963. +
  7964. +}
  7965. +
  7966. +char * pkg_formatted_info(pkg_t *pkg )
  7967. +{
  7968. + char *line;
  7969. + char * buff;
  7970. +
  7971. + buff = malloc(8192);
  7972. + if (buff == NULL) {
  7973. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7974. + return NULL;
  7975. + }
  7976. +
  7977. + buff[0] = '\0';
  7978. +
  7979. + line = pkg_formatted_field(pkg, "Package");
  7980. + strncat(buff ,line, strlen(line));
  7981. + free(line);
  7982. +
  7983. + line = pkg_formatted_field(pkg, "Version");
  7984. + strncat(buff ,line, strlen(line));
  7985. + free(line);
  7986. +
  7987. + line = pkg_formatted_field(pkg, "Depends");
  7988. + strncat(buff ,line, strlen(line));
  7989. + free(line);
  7990. +
  7991. + line = pkg_formatted_field(pkg, "Recommends");
  7992. + strncat(buff ,line, strlen(line));
  7993. + free(line);
  7994. +
  7995. + line = pkg_formatted_field(pkg, "Suggests");
  7996. + strncat(buff ,line, strlen(line));
  7997. + free(line);
  7998. +
  7999. + line = pkg_formatted_field(pkg, "Provides");
  8000. + strncat(buff ,line, strlen(line));
  8001. + free(line);
  8002. +
  8003. + line = pkg_formatted_field(pkg, "Replaces");
  8004. + strncat(buff ,line, strlen(line));
  8005. + free(line);
  8006. +
  8007. + line = pkg_formatted_field(pkg, "Conflicts");
  8008. + strncat(buff ,line, strlen(line));
  8009. + free(line);
  8010. +
  8011. + line = pkg_formatted_field(pkg, "Status");
  8012. + strncat(buff ,line, strlen(line));
  8013. + free(line);
  8014. +
  8015. + line = pkg_formatted_field(pkg, "Section");
  8016. + strncat(buff ,line, strlen(line));
  8017. + free(line);
  8018. +
  8019. + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
  8020. + strncat(buff ,line, strlen(line));
  8021. + free(line);
  8022. +
  8023. + line = pkg_formatted_field(pkg, "Architecture");
  8024. + strncat(buff ,line, strlen(line));
  8025. + free(line);
  8026. +
  8027. + line = pkg_formatted_field(pkg, "Maintainer");
  8028. + strncat(buff ,line, strlen(line));
  8029. + free(line);
  8030. +
  8031. + line = pkg_formatted_field(pkg, "MD5sum");
  8032. + strncat(buff ,line, strlen(line));
  8033. + free(line);
  8034. +
  8035. + line = pkg_formatted_field(pkg, "Size");
  8036. + strncat(buff ,line, strlen(line));
  8037. + free(line);
  8038. +
  8039. + line = pkg_formatted_field(pkg, "Filename");
  8040. + strncat(buff ,line, strlen(line));
  8041. + free(line);
  8042. +
  8043. + line = pkg_formatted_field(pkg, "Conffiles");
  8044. + strncat(buff ,line, strlen(line));
  8045. + free(line);
  8046. +
  8047. + line = pkg_formatted_field(pkg, "Source");
  8048. + strncat(buff ,line, strlen(line));
  8049. + free(line);
  8050. +
  8051. + line = pkg_formatted_field(pkg, "Description");
  8052. + strncat(buff ,line, strlen(line));
  8053. + free(line);
  8054. +
  8055. + line = pkg_formatted_field(pkg, "Installed-Time");
  8056. + strncat(buff ,line, strlen(line));
  8057. + free(line);
  8058. +
  8059. + return buff;
  8060. +}
  8061. +
  8062. +char * pkg_formatted_field(pkg_t *pkg, const char *field )
  8063. +{
  8064. + static size_t LINE_LEN = 128;
  8065. + char * temp = (char *)malloc(1);
  8066. + int len = 0;
  8067. + int flag_provide_false = 0;
  8068. +
  8069. +/*
  8070. + Pigi: After some discussion with Florian we decided to modify the full procedure in
  8071. + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
  8072. +*/
  8073. +
  8074. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8075. + goto UNKNOWN_FMT_FIELD;
  8076. + }
  8077. +
  8078. + temp[0]='\0';
  8079. +
  8080. + switch (field[0])
  8081. + {
  8082. + case 'a':
  8083. + case 'A':
  8084. + if (strcasecmp(field, "Architecture") == 0) {
  8085. + /* Architecture */
  8086. + if (pkg->architecture) {
  8087. + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
  8088. + if ( temp == NULL ){
  8089. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8090. + return NULL;
  8091. + }
  8092. + temp[0]='\0';
  8093. + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
  8094. + }
  8095. + } else {
  8096. + goto UNKNOWN_FMT_FIELD;
  8097. + }
  8098. + break;
  8099. + case 'c':
  8100. + case 'C':
  8101. + if (strcasecmp(field, "Conffiles") == 0) {
  8102. + /* Conffiles */
  8103. + conffile_list_elt_t *iter;
  8104. + char confstr_[LINE_LEN];
  8105. +
  8106. + if (pkg->conffiles.head == NULL) {
  8107. + return temp;
  8108. + }
  8109. +
  8110. + len = 14 ;
  8111. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8112. + if (iter->data->name && iter->data->value) {
  8113. + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
  8114. + }
  8115. + }
  8116. + temp = (char *)realloc(temp,len);
  8117. + if ( temp == NULL ){
  8118. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8119. + return NULL;
  8120. + }
  8121. + temp[0]='\0';
  8122. + strncpy(temp, "Conffiles:\n", 12);
  8123. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8124. + if (iter->data->name && iter->data->value) {
  8125. + snprintf(confstr_, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
  8126. + strncat(temp, confstr_, strlen(confstr_));
  8127. + }
  8128. + }
  8129. + } else if (strcasecmp(field, "Conflicts") == 0) {
  8130. + int i;
  8131. +
  8132. + if (pkg->conflicts_count) {
  8133. + char conflictstr[LINE_LEN];
  8134. + len = 14 ;
  8135. + for(i = 0; i < pkg->conflicts_count; i++) {
  8136. + len = len + (strlen(pkg->conflicts_str[i])+5);
  8137. + }
  8138. + temp = (char *)realloc(temp,len);
  8139. + if ( temp == NULL ){
  8140. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8141. + return NULL;
  8142. + }
  8143. + temp[0]='\0';
  8144. + strncpy(temp, "Conflicts:", 11);
  8145. + for(i = 0; i < pkg->conflicts_count; i++) {
  8146. + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
  8147. + strncat(temp, conflictstr, strlen(conflictstr));
  8148. + }
  8149. + strncat(temp, "\n", strlen("\n"));
  8150. + }
  8151. + } else {
  8152. + goto UNKNOWN_FMT_FIELD;
  8153. + }
  8154. + break;
  8155. + case 'd':
  8156. + case 'D':
  8157. + if (strcasecmp(field, "Depends") == 0) {
  8158. + /* Depends */
  8159. + int i;
  8160. +
  8161. + if (pkg->depends_count) {
  8162. + char depstr[LINE_LEN];
  8163. + len = 14 ;
  8164. + for(i = 0; i < pkg->depends_count; i++) {
  8165. + len = len + (strlen(pkg->depends_str[i])+4);
  8166. + }
  8167. + temp = (char *)realloc(temp,len);
  8168. + if ( temp == NULL ){
  8169. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8170. + return NULL;
  8171. + }
  8172. + temp[0]='\0';
  8173. + strncpy(temp, "Depends:", 10);
  8174. + for(i = 0; i < pkg->depends_count; i++) {
  8175. + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
  8176. + strncat(temp, depstr, strlen(depstr));
  8177. + }
  8178. + strncat(temp, "\n", strlen("\n"));
  8179. + }
  8180. + } else if (strcasecmp(field, "Description") == 0) {
  8181. + /* Description */
  8182. + if (pkg->description) {
  8183. + temp = (char *)realloc(temp,strlen(pkg->description)+16);
  8184. + if ( temp == NULL ){
  8185. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8186. + return NULL;
  8187. + }
  8188. + temp[0]='\0';
  8189. + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
  8190. + }
  8191. + } else {
  8192. + goto UNKNOWN_FMT_FIELD;
  8193. + }
  8194. + break;
  8195. + case 'e':
  8196. + case 'E': {
  8197. + /* Essential */
  8198. + if (pkg->essential) {
  8199. + temp = (char *)realloc(temp,16);
  8200. + if ( temp == NULL ){
  8201. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8202. + return NULL;
  8203. + }
  8204. + temp[0]='\0';
  8205. + snprintf(temp, (16), "Essential: yes\n");
  8206. + }
  8207. + }
  8208. + break;
  8209. + case 'f':
  8210. + case 'F': {
  8211. + /* Filename */
  8212. + if (pkg->filename) {
  8213. + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
  8214. + if ( temp == NULL ){
  8215. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8216. + return NULL;
  8217. + }
  8218. + temp[0]='\0';
  8219. + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
  8220. + }
  8221. + }
  8222. + break;
  8223. + case 'i':
  8224. + case 'I': {
  8225. + if (strcasecmp(field, "Installed-Size") == 0) {
  8226. + /* Installed-Size */
  8227. + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
  8228. + if ( temp == NULL ){
  8229. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8230. + return NULL;
  8231. + }
  8232. + temp[0]='\0';
  8233. + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
  8234. + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
  8235. + temp = (char *)realloc(temp,29);
  8236. + if ( temp == NULL ){
  8237. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8238. + return NULL;
  8239. + }
  8240. + temp[0]='\0';
  8241. + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
  8242. + }
  8243. + }
  8244. + break;
  8245. + case 'm':
  8246. + case 'M': {
  8247. + /* Maintainer | MD5sum */
  8248. + if (strcasecmp(field, "Maintainer") == 0) {
  8249. + /* Maintainer */
  8250. + if (pkg->maintainer) {
  8251. + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
  8252. + if ( temp == NULL ){
  8253. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8254. + return NULL;
  8255. + }
  8256. + temp[0]='\0';
  8257. + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
  8258. + }
  8259. + } else if (strcasecmp(field, "MD5sum") == 0) {
  8260. + /* MD5sum */
  8261. + if (pkg->md5sum) {
  8262. + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
  8263. + if ( temp == NULL ){
  8264. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8265. + return NULL;
  8266. + }
  8267. + temp[0]='\0';
  8268. + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
  8269. + }
  8270. + } else {
  8271. + goto UNKNOWN_FMT_FIELD;
  8272. + }
  8273. + }
  8274. + break;
  8275. + case 'p':
  8276. + case 'P': {
  8277. + if (strcasecmp(field, "Package") == 0) {
  8278. + /* Package */
  8279. + temp = (char *)realloc(temp,strlen(pkg->name)+11);
  8280. + if ( temp == NULL ){
  8281. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8282. + return NULL;
  8283. + }
  8284. + temp[0]='\0';
  8285. + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
  8286. + } else if (strcasecmp(field, "Priority") == 0) {
  8287. + /* Priority */
  8288. + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
  8289. + if ( temp == NULL ){
  8290. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8291. + return NULL;
  8292. + }
  8293. + temp[0]='\0';
  8294. + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
  8295. + } else if (strcasecmp(field, "Provides") == 0) {
  8296. + /* Provides */
  8297. + int i;
  8298. +
  8299. + if (pkg->provides_count) {
  8300. + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
  8301. + for ( i=0; i < pkg->provides_count; i++ ){
  8302. + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
  8303. + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
  8304. + flag_provide_false = 1;
  8305. + }
  8306. + }
  8307. + if ( !flag_provide_false || /* Pigi there is not my trick flag */
  8308. + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
  8309. + char provstr[LINE_LEN];
  8310. + len = 15;
  8311. + for(i = 0; i < pkg->provides_count; i++) {
  8312. + len = len + (strlen(pkg->provides_str[i])+5);
  8313. + }
  8314. + temp = (char *)realloc(temp,len);
  8315. + if ( temp == NULL ){
  8316. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8317. + return NULL;
  8318. + }
  8319. + temp[0]='\0';
  8320. + strncpy(temp, "Provides:", 12);
  8321. + for(i = 0; i < pkg->provides_count; i++) {
  8322. + if (strlen(pkg->provides_str[i])>0){;
  8323. + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
  8324. + strncat(temp, provstr, strlen(provstr));
  8325. + }
  8326. + }
  8327. + strncat(temp, "\n", strlen("\n"));
  8328. + }
  8329. + }
  8330. + } else {
  8331. + goto UNKNOWN_FMT_FIELD;
  8332. + }
  8333. + }
  8334. + break;
  8335. + case 'r':
  8336. + case 'R': {
  8337. + int i;
  8338. + /* Replaces | Recommends*/
  8339. + if (strcasecmp (field, "Replaces") == 0) {
  8340. + if (pkg->replaces_count) {
  8341. + char replstr[LINE_LEN];
  8342. + len = 14;
  8343. + for (i = 0; i < pkg->replaces_count; i++) {
  8344. + len = len + (strlen(pkg->replaces_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, "Replaces:", 12);
  8353. + for (i = 0; i < pkg->replaces_count; i++) {
  8354. + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
  8355. + strncat(temp, replstr, strlen(replstr));
  8356. + }
  8357. + strncat(temp, "\n", strlen("\n"));
  8358. + }
  8359. + } else if (strcasecmp (field, "Recommends") == 0) {
  8360. + if (pkg->recommends_count) {
  8361. + char recstr[LINE_LEN];
  8362. + len = 15;
  8363. + for(i = 0; i < pkg->recommends_count; i++) {
  8364. + len = len + (strlen( pkg->recommends_str[i])+5);
  8365. + }
  8366. + temp = (char *)realloc(temp,len);
  8367. + if ( temp == NULL ){
  8368. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8369. + return NULL;
  8370. + }
  8371. + temp[0]='\0';
  8372. + strncpy(temp, "Recommends:", 13);
  8373. + for(i = 0; i < pkg->recommends_count; i++) {
  8374. + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
  8375. + strncat(temp, recstr, strlen(recstr));
  8376. + }
  8377. + strncat(temp, "\n", strlen("\n"));
  8378. + }
  8379. + } else {
  8380. + goto UNKNOWN_FMT_FIELD;
  8381. + }
  8382. + }
  8383. + break;
  8384. + case 's':
  8385. + case 'S': {
  8386. + /* Section | Size | Source | Status | Suggests */
  8387. + if (strcasecmp(field, "Section") == 0) {
  8388. + /* Section */
  8389. + if (pkg->section) {
  8390. + temp = (char *)realloc(temp,strlen(pkg->section)+11);
  8391. + if ( temp == NULL ){
  8392. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8393. + return NULL;
  8394. + }
  8395. + temp[0]='\0';
  8396. + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
  8397. + }
  8398. + } else if (strcasecmp(field, "Size") == 0) {
  8399. + /* Size */
  8400. + if (pkg->size) {
  8401. + temp = (char *)realloc(temp,strlen(pkg->size)+8);
  8402. + if ( temp == NULL ){
  8403. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8404. + return NULL;
  8405. + }
  8406. + temp[0]='\0';
  8407. + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
  8408. + }
  8409. + } else if (strcasecmp(field, "Source") == 0) {
  8410. + /* Source */
  8411. + if (pkg->source) {
  8412. + temp = (char *)realloc(temp,strlen(pkg->source)+10);
  8413. + if ( temp == NULL ){
  8414. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8415. + return NULL;
  8416. + }
  8417. + temp[0]='\0';
  8418. + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
  8419. + }
  8420. + } else if (strcasecmp(field, "Status") == 0) {
  8421. + /* Status */
  8422. + /* Benjamin Pineau note: we should avoid direct usage of
  8423. + * strlen(arg) without keeping "arg" for later free()
  8424. + */
  8425. + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
  8426. + char *pstat=pkg_state_status_to_str(pkg->state_status);
  8427. + char *pwant=pkg_state_want_to_str(pkg->state_want);
  8428. +
  8429. + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
  8430. + temp = (char *)realloc(temp,sum_of_sizes);
  8431. + if ( temp == NULL ){
  8432. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8433. + return NULL;
  8434. + }
  8435. + temp[0]='\0';
  8436. + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
  8437. + free(pflag);
  8438. + free(pwant);
  8439. + if(pstat) /* pfstat can be NULL if ENOMEM */
  8440. + free(pstat);
  8441. + } else if (strcasecmp(field, "Suggests") == 0) {
  8442. + if (pkg->suggests_count) {
  8443. + int i;
  8444. + char sugstr[LINE_LEN];
  8445. + len = 13;
  8446. + for(i = 0; i < pkg->suggests_count; i++) {
  8447. + len = len + (strlen(pkg->suggests_str[i])+5);
  8448. + }
  8449. + temp = (char *)realloc(temp,len);
  8450. + if ( temp == NULL ){
  8451. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8452. + return NULL;
  8453. + }
  8454. + temp[0]='\0';
  8455. + strncpy(temp, "Suggests:", 10);
  8456. + for(i = 0; i < pkg->suggests_count; i++) {
  8457. + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
  8458. + strncat(temp, sugstr, strlen(sugstr));
  8459. + }
  8460. + strncat(temp, "\n", strlen("\n"));
  8461. + }
  8462. + } else {
  8463. + goto UNKNOWN_FMT_FIELD;
  8464. + }
  8465. + }
  8466. + break;
  8467. + case 'v':
  8468. + case 'V': {
  8469. + /* Version */
  8470. + char *version = pkg_version_str_alloc(pkg);
  8471. + temp = (char *)realloc(temp,strlen(version)+14);
  8472. + if ( temp == NULL ){
  8473. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8474. + return NULL;
  8475. + }
  8476. + temp[0]='\0';
  8477. + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
  8478. + free(version);
  8479. + }
  8480. + break;
  8481. + default:
  8482. + goto UNKNOWN_FMT_FIELD;
  8483. + }
  8484. +
  8485. + if ( strlen(temp)<2 ) {
  8486. + temp[0]='\0';
  8487. + }
  8488. + return temp;
  8489. +
  8490. + UNKNOWN_FMT_FIELD:
  8491. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
  8492. + if ( strlen(temp)<2 ) {
  8493. + temp[0]='\0';
  8494. + }
  8495. +
  8496. + return temp;
  8497. +}
  8498. +
  8499. +void pkg_print_info(pkg_t *pkg, FILE *file)
  8500. +{
  8501. + char * buff;
  8502. + if (pkg == NULL) {
  8503. + return;
  8504. + }
  8505. +
  8506. + buff = pkg_formatted_info(pkg);
  8507. + if ( buff == NULL )
  8508. + return;
  8509. + if (strlen(buff)>2){
  8510. + fwrite(buff, 1, strlen(buff), file);
  8511. + }
  8512. + free(buff);
  8513. +}
  8514. +
  8515. +void pkg_print_status(pkg_t * pkg, FILE * file)
  8516. +{
  8517. + if (pkg == NULL) {
  8518. + return;
  8519. + }
  8520. +
  8521. + /* XXX: QUESTION: Do we actually want more fields here? The
  8522. + original idea was to save space by installing only what was
  8523. + needed for actual computation, (package, version, status,
  8524. + essential, conffiles). The assumption is that all other fields
  8525. + can be found in th available file.
  8526. +
  8527. + But, someone proposed the idea to make it possible to
  8528. + reconstruct a .ipk from an installed package, (ie. for beaming
  8529. + from one handheld to another). So, maybe we actually want a few
  8530. + more fields here, (depends, suggests, etc.), so that that would
  8531. + be guaranteed to work even in the absence of more information
  8532. + from the available file.
  8533. +
  8534. + 28-MAR-03: kergoth and I discussed this yesterday. We think
  8535. + the essential info needs to be here for all installed packages
  8536. + because they may not appear in the Packages files on various
  8537. + feeds. Furthermore, one should be able to install from URL or
  8538. + local storage without requiring a Packages file from any feed.
  8539. + -Jamey
  8540. + */
  8541. + pkg_print_field(pkg, file, "Package");
  8542. + pkg_print_field(pkg, file, "Version");
  8543. + pkg_print_field(pkg, file, "Depends");
  8544. + pkg_print_field(pkg, file, "Recommends");
  8545. + pkg_print_field(pkg, file, "Suggests");
  8546. + pkg_print_field(pkg, file, "Provides");
  8547. + pkg_print_field(pkg, file, "Replaces");
  8548. + pkg_print_field(pkg, file, "Conflicts");
  8549. + pkg_print_field(pkg, file, "Status");
  8550. + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
  8551. + pkg_print_field(pkg, file, "Architecture");
  8552. + pkg_print_field(pkg, file, "Conffiles");
  8553. + pkg_print_field(pkg, file, "Installed-Time");
  8554. + fputs("\n", file);
  8555. +}
  8556. +
  8557. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
  8558. +{
  8559. + char *buff;
  8560. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8561. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
  8562. + __FUNCTION__, field);
  8563. + }
  8564. + buff = pkg_formatted_field(pkg, field);
  8565. + if (strlen(buff)>2) {
  8566. + fprintf(file, "%s", buff);
  8567. + fflush(file);
  8568. + }
  8569. + free(buff);
  8570. + return;
  8571. +}
  8572. +
  8573. +/*
  8574. + * libdpkg - Debian packaging suite library routines
  8575. + * vercmp.c - comparison of version numbers
  8576. + *
  8577. + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  8578. + */
  8579. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
  8580. +{
  8581. + int r;
  8582. +
  8583. + if (pkg->epoch > ref_pkg->epoch) {
  8584. + return 1;
  8585. + }
  8586. +
  8587. + if (pkg->epoch < ref_pkg->epoch) {
  8588. + return -1;
  8589. + }
  8590. +
  8591. + r = verrevcmp(pkg->version, ref_pkg->version);
  8592. + if (r) {
  8593. + return r;
  8594. + }
  8595. +
  8596. +#ifdef USE_DEBVERSION
  8597. + r = verrevcmp(pkg->revision, ref_pkg->revision);
  8598. + if (r) {
  8599. + return r;
  8600. + }
  8601. +
  8602. + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
  8603. +#endif
  8604. +
  8605. + return r;
  8606. +}
  8607. +
  8608. +int verrevcmp(const char *val, const char *ref)
  8609. +{
  8610. + int vc, rc;
  8611. + long vl, rl;
  8612. + const char *vp, *rp;
  8613. + const char *vsep, *rsep;
  8614. +
  8615. + if (!val) val= "";
  8616. + if (!ref) ref= "";
  8617. + for (;;) {
  8618. + vp= val; while (*vp && !isdigit(*vp)) vp++;
  8619. + rp= ref; while (*rp && !isdigit(*rp)) rp++;
  8620. + for (;;) {
  8621. + vc= (val == vp) ? 0 : *val++;
  8622. + rc= (ref == rp) ? 0 : *ref++;
  8623. + if (!rc && !vc) break;
  8624. + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
  8625. + if (rc && !isalpha(rc)) rc += 256;
  8626. + if (vc != rc) return vc - rc;
  8627. + }
  8628. + val= vp;
  8629. + ref= rp;
  8630. + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
  8631. + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
  8632. + if (vl != rl) return vl - rl;
  8633. +
  8634. + vc = *val;
  8635. + rc = *ref;
  8636. + vsep = strchr(".-", vc);
  8637. + rsep = strchr(".-", rc);
  8638. + if (vsep && !rsep) return -1;
  8639. + if (!vsep && rsep) return +1;
  8640. +
  8641. + if (!*val && !*ref) return 0;
  8642. + if (!*val) return -1;
  8643. + if (!*ref) return +1;
  8644. + }
  8645. +}
  8646. +
  8647. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
  8648. +{
  8649. + int r;
  8650. +
  8651. + r = pkg_compare_versions(it, ref);
  8652. +
  8653. + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
  8654. + return r <= 0;
  8655. + }
  8656. +
  8657. + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
  8658. + return r >= 0;
  8659. + }
  8660. +
  8661. + if (strcmp(op, "<<") == 0) {
  8662. + return r < 0;
  8663. + }
  8664. +
  8665. + if (strcmp(op, ">>") == 0) {
  8666. + return r > 0;
  8667. + }
  8668. +
  8669. + if (strcmp(op, "=") == 0) {
  8670. + return r == 0;
  8671. + }
  8672. +
  8673. + fprintf(stderr, "unknown operator: %s", op);
  8674. + return 0;
  8675. +}
  8676. +
  8677. +int pkg_name_version_and_architecture_compare(pkg_t *p1, pkg_t *p2)
  8678. +{
  8679. + const pkg_t *a = *(const pkg_t **)p1;
  8680. + const pkg_t *b = *(const pkg_t **)p2;
  8681. + int namecmp;
  8682. + int vercmp;
  8683. + if (!a->name || !b->name) {
  8684. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8685. + a, a->name, b, b->name);
  8686. + return 0;
  8687. + }
  8688. +
  8689. + namecmp = strcmp(a->name, b->name);
  8690. + if (namecmp)
  8691. + return namecmp;
  8692. + vercmp = pkg_compare_versions(a, b);
  8693. + if (vercmp)
  8694. + return vercmp;
  8695. + if (!a->arch_priority || !b->arch_priority) {
  8696. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
  8697. + a, a->arch_priority, b, b->arch_priority);
  8698. + return 0;
  8699. + }
  8700. + if (a->arch_priority > b->arch_priority)
  8701. + return 1;
  8702. + if (a->arch_priority < b->arch_priority)
  8703. + return -1;
  8704. + return 0;
  8705. +}
  8706. +
  8707. +int abstract_pkg_name_compare(abstract_pkg_t *p1, abstract_pkg_t *p2)
  8708. +{
  8709. + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
  8710. + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
  8711. + if (!a->name || !b->name) {
  8712. + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8713. + a, a->name, b, b->name);
  8714. + return 0;
  8715. + }
  8716. + return strcmp(a->name, b->name);
  8717. +}
  8718. +
  8719. +
  8720. +char *pkg_version_str_alloc(pkg_t *pkg)
  8721. +{
  8722. + char *complete_version;
  8723. + char *epoch_str;
  8724. +#ifdef USE_DEBVERSION
  8725. + char *revision_str;
  8726. + char *familiar_revision_str;
  8727. +#endif
  8728. +
  8729. + if (pkg->epoch) {
  8730. + sprintf_alloc(&epoch_str, "%lu:", (unsigned long)pkg->epoch);
  8731. + } else {
  8732. + epoch_str = strdup("");
  8733. + }
  8734. +
  8735. +#ifdef USE_DEBVERSION
  8736. + if (pkg->revision && strlen(pkg->revision)) {
  8737. + sprintf_alloc(&revision_str, "-%s", pkg->revision);
  8738. + } else {
  8739. + revision_str = strdup("");
  8740. + }
  8741. +
  8742. + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
  8743. + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
  8744. + } else {
  8745. + familiar_revision_str = strdup("");
  8746. + }
  8747. +#endif
  8748. +
  8749. +#ifdef USE_DEBVERSION
  8750. + sprintf_alloc(&complete_version, "%s%s%s%s",
  8751. + epoch_str, pkg->version, revision_str, familiar_revision_str);
  8752. +#else
  8753. + sprintf_alloc(&complete_version, "%s%s",
  8754. + epoch_str, pkg->version);
  8755. +#endif
  8756. +
  8757. + free(epoch_str);
  8758. +#ifdef USE_DEBVERSION
  8759. + free(revision_str);
  8760. + free(familiar_revision_str);
  8761. +#endif
  8762. +
  8763. + return complete_version;
  8764. +}
  8765. +
  8766. +str_list_t *pkg_get_installed_files(pkg_t *pkg)
  8767. +{
  8768. + int err;
  8769. + char *list_file_name = NULL;
  8770. + FILE *list_file = NULL;
  8771. + char *line;
  8772. + char *installed_file_name;
  8773. + int rootdirlen;
  8774. +
  8775. + pkg->installed_files_ref_cnt++;
  8776. +
  8777. + if (pkg->installed_files) {
  8778. + return pkg->installed_files;
  8779. + }
  8780. +
  8781. + pkg->installed_files = str_list_alloc();
  8782. + if (pkg->installed_files == NULL) {
  8783. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8784. + return NULL;
  8785. + }
  8786. +
  8787. + /* For uninstalled packages, get the file list firectly from the package.
  8788. + For installed packages, look at the package.list file in the database.
  8789. + */
  8790. + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
  8791. + if (pkg->local_filename == NULL) {
  8792. + return pkg->installed_files;
  8793. + }
  8794. + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
  8795. + file. In other words, change deb_extract so that it can
  8796. + simply return the file list as a char *[] rather than
  8797. + insisting on writing in to a FILE * as it does now. */
  8798. + list_file = tmpfile();
  8799. + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
  8800. + if (err) {
  8801. + fclose(list_file);
  8802. + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
  8803. + __FUNCTION__, pkg->local_filename, strerror(err));
  8804. + return pkg->installed_files;
  8805. + }
  8806. + rewind(list_file);
  8807. + } else {
  8808. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8809. + pkg->dest->info_dir, pkg->name);
  8810. + if (! file_exists(list_file_name)) {
  8811. + free(list_file_name);
  8812. + return pkg->installed_files;
  8813. + }
  8814. +
  8815. + list_file = fopen(list_file_name, "r");
  8816. + if (list_file == NULL) {
  8817. + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
  8818. + list_file_name, strerror(errno));
  8819. + free(list_file_name);
  8820. + return pkg->installed_files;
  8821. + }
  8822. + free(list_file_name);
  8823. + }
  8824. +
  8825. + rootdirlen = strlen( pkg->dest->root_dir );
  8826. + while (1) {
  8827. + char *file_name;
  8828. +
  8829. + line = file_read_line_alloc(list_file);
  8830. + if (line == NULL) {
  8831. + break;
  8832. + }
  8833. + str_chomp(line);
  8834. + file_name = line;
  8835. +
  8836. + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
  8837. + if( strncmp( pkg->dest->root_dir,
  8838. + file_name,
  8839. + rootdirlen ) ) {
  8840. + if (*file_name == '.') {
  8841. + file_name++;
  8842. + }
  8843. + if (*file_name == '/') {
  8844. + file_name++;
  8845. + }
  8846. +
  8847. + /* Freed in pkg_free_installed_files */
  8848. + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
  8849. + } else {
  8850. + // already contains root_dir as header -> ABSOLUTE
  8851. + sprintf_alloc(&installed_file_name, "%s", file_name);
  8852. + }
  8853. + str_list_append(pkg->installed_files, installed_file_name);
  8854. + free(line);
  8855. + }
  8856. +
  8857. + fclose(list_file);
  8858. +
  8859. + return pkg->installed_files;
  8860. +}
  8861. +
  8862. +/* XXX: CLEANUP: This function and it's counterpart,
  8863. + (pkg_get_installed_files), do not match our init/deinit naming
  8864. + convention. Nor the alloc/free convention. But, then again, neither
  8865. + of these conventions currrently fit the way these two functions
  8866. + work. */
  8867. +int pkg_free_installed_files(pkg_t *pkg)
  8868. +{
  8869. + str_list_elt_t *iter;
  8870. +
  8871. + pkg->installed_files_ref_cnt--;
  8872. + if (pkg->installed_files_ref_cnt > 0) {
  8873. + return 0;
  8874. + }
  8875. +
  8876. + if (pkg->installed_files) {
  8877. +
  8878. + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
  8879. + /* malloced in pkg_get_installed_files */
  8880. + free (iter->data);
  8881. + iter->data = NULL;
  8882. + }
  8883. +
  8884. + str_list_deinit(pkg->installed_files);
  8885. + }
  8886. +
  8887. + pkg->installed_files = NULL;
  8888. +
  8889. + return 0;
  8890. +}
  8891. +
  8892. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
  8893. +{
  8894. + int err;
  8895. + char *list_file_name;
  8896. +
  8897. + //I don't think pkg_free_installed_files should be called here. Jamey
  8898. + //pkg_free_installed_files(pkg);
  8899. +
  8900. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8901. + pkg->dest->info_dir, pkg->name);
  8902. + if (!conf->noaction) {
  8903. + err = unlink(list_file_name);
  8904. + free(list_file_name);
  8905. +
  8906. + if (err) {
  8907. + return errno;
  8908. + }
  8909. + }
  8910. + return 0;
  8911. +}
  8912. +
  8913. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
  8914. +{
  8915. + conffile_list_elt_t *iter;
  8916. + conffile_t *conffile;
  8917. +
  8918. + if (pkg == NULL) {
  8919. + return NULL;
  8920. + }
  8921. +
  8922. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8923. + conffile = iter->data;
  8924. +
  8925. + if (strcmp(conffile->name, file_name) == 0) {
  8926. + return conffile;
  8927. + }
  8928. + }
  8929. +
  8930. + return NULL;
  8931. +}
  8932. +
  8933. +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
  8934. + const char *script, const char *args)
  8935. +{
  8936. + int err;
  8937. + char *path;
  8938. + char *cmd;
  8939. +
  8940. + /* XXX: FEATURE: When conf->offline_root is set, we should run the
  8941. + maintainer script within a chroot environment. */
  8942. +
  8943. + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
  8944. + have scripts in pkg->tmp_unpack_dir. */
  8945. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  8946. + if (pkg->dest == NULL) {
  8947. + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
  8948. + __FUNCTION__, pkg->name);
  8949. + return EINVAL;
  8950. + }
  8951. + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
  8952. + } else {
  8953. + if (pkg->tmp_unpack_dir == NULL) {
  8954. + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
  8955. + __FUNCTION__, pkg->name);
  8956. + return EINVAL;
  8957. + }
  8958. + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
  8959. + }
  8960. +
  8961. + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
  8962. + if (conf->noaction) return 0;
  8963. +
  8964. + /* XXX: CLEANUP: There must be a better way to handle maintainer
  8965. + scripts when running with offline_root mode and/or a dest other
  8966. + than '/'. I've been playing around with some clever chroot
  8967. + tricks and I might come up with something workable. */
  8968. + if (conf->offline_root) {
  8969. + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
  8970. + }
  8971. +
  8972. + setenv("PKG_ROOT",
  8973. + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
  8974. +
  8975. + if (! file_exists(path)) {
  8976. + free(path);
  8977. + return 0;
  8978. + }
  8979. +
  8980. + if (conf->offline_root) {
  8981. + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
  8982. + free(path);
  8983. + return 0;
  8984. + }
  8985. +
  8986. + sprintf_alloc(&cmd, "%s %s", path, args);
  8987. + free(path);
  8988. +
  8989. + err = xsystem(cmd);
  8990. + free(cmd);
  8991. +
  8992. + if (err) {
  8993. + fprintf(stderr, "%s script returned status %d\n", script, err);
  8994. + return err;
  8995. + }
  8996. +
  8997. + return 0;
  8998. +}
  8999. +
  9000. +char *pkg_state_want_to_str(pkg_state_want_t sw)
  9001. +{
  9002. + int i;
  9003. +
  9004. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9005. + if (pkg_state_want_map[i].value == sw) {
  9006. + return strdup(pkg_state_want_map[i].str);
  9007. + }
  9008. + }
  9009. +
  9010. + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
  9011. + __FUNCTION__, sw);
  9012. + return strdup("<STATE_WANT_UNKNOWN>");
  9013. +}
  9014. +
  9015. +pkg_state_want_t pkg_state_want_from_str(char *str)
  9016. +{
  9017. + int i;
  9018. +
  9019. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9020. + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
  9021. + return pkg_state_want_map[i].value;
  9022. + }
  9023. + }
  9024. +
  9025. + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
  9026. + __FUNCTION__, str);
  9027. + return SW_UNKNOWN;
  9028. +}
  9029. +
  9030. +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
  9031. +{
  9032. + int i;
  9033. + int len = 3; /* ok\000 is minimum */
  9034. + char *str = NULL;
  9035. +
  9036. + /* clear the temporary flags before converting to string */
  9037. + sf &= SF_NONVOLATILE_FLAGS;
  9038. +
  9039. + if (sf == 0) {
  9040. + return strdup("ok");
  9041. + } else {
  9042. +
  9043. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9044. + if (sf & pkg_state_flag_map[i].value) {
  9045. + len += strlen(pkg_state_flag_map[i].str) + 1;
  9046. + }
  9047. + }
  9048. + str = malloc(len);
  9049. + if ( str == NULL ) {
  9050. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9051. + return NULL;
  9052. + }
  9053. + str[0] = 0;
  9054. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9055. + if (sf & pkg_state_flag_map[i].value) {
  9056. + strcat(str, pkg_state_flag_map[i].str);
  9057. + strcat(str, ",");
  9058. + }
  9059. + }
  9060. + len = strlen(str);
  9061. + str[len-1] = 0; /* squash last comma */
  9062. + return str;
  9063. + }
  9064. +}
  9065. +
  9066. +pkg_state_flag_t pkg_state_flag_from_str(char *str)
  9067. +{
  9068. + int i;
  9069. + int sf = SF_OK;
  9070. +
  9071. + if (strcmp(str, "ok") == 0) {
  9072. + return SF_OK;
  9073. + }
  9074. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9075. + const char *sfname = pkg_state_flag_map[i].str;
  9076. + int sfname_len = strlen(sfname);
  9077. + if (strncmp(str, sfname, sfname_len) == 0) {
  9078. + sf |= pkg_state_flag_map[i].value;
  9079. + str += sfname_len;
  9080. + if (str[0] == ',') {
  9081. + str++;
  9082. + } else {
  9083. + break;
  9084. + }
  9085. + }
  9086. + }
  9087. +
  9088. + return sf;
  9089. +}
  9090. +
  9091. +char *pkg_state_status_to_str(pkg_state_status_t ss)
  9092. +{
  9093. + int i;
  9094. +
  9095. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9096. + if (pkg_state_status_map[i].value == ss) {
  9097. + return strdup(pkg_state_status_map[i].str);
  9098. + }
  9099. + }
  9100. +
  9101. + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
  9102. + __FUNCTION__, ss);
  9103. + return strdup("<STATE_STATUS_UNKNOWN>");
  9104. +}
  9105. +
  9106. +pkg_state_status_t pkg_state_status_from_str(char *str)
  9107. +{
  9108. + int i;
  9109. +
  9110. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9111. + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
  9112. + return pkg_state_status_map[i].value;
  9113. + }
  9114. + }
  9115. +
  9116. + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
  9117. + __FUNCTION__, str);
  9118. + return SS_NOT_INSTALLED;
  9119. +}
  9120. +
  9121. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
  9122. +{
  9123. + nv_pair_list_elt_t *l;
  9124. +
  9125. + if (!pkg->architecture)
  9126. + return 1;
  9127. +
  9128. + l = conf->arch_list.head;
  9129. +
  9130. + while (l) {
  9131. + nv_pair_t *nv = l->data;
  9132. + if (strcmp(nv->name, pkg->architecture) == 0) {
  9133. + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
  9134. + return 1;
  9135. + }
  9136. + l = l->next;
  9137. + }
  9138. +
  9139. + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
  9140. + return 0;
  9141. +}
  9142. +
  9143. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
  9144. +{
  9145. + nv_pair_list_elt_t *l;
  9146. +
  9147. + l = conf->arch_list.head;
  9148. +
  9149. + while (l) {
  9150. + nv_pair_t *nv = l->data;
  9151. + if (strcmp(nv->name, archname) == 0) {
  9152. + int priority = strtol(nv->value, NULL, 0);
  9153. + return priority;
  9154. + }
  9155. + l = l->next;
  9156. + }
  9157. + return 0;
  9158. +}
  9159. +
  9160. +int pkg_info_preinstall_check(ipkg_conf_t *conf)
  9161. +{
  9162. + int i;
  9163. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9164. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  9165. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9166. +
  9167. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
  9168. + pkg_hash_fetch_available(pkg_hash, available_pkgs);
  9169. + /* update arch_priority for each package */
  9170. + for (i = 0; i < available_pkgs->len; i++) {
  9171. + pkg_t *pkg = available_pkgs->pkgs[i];
  9172. + int arch_priority = 1;
  9173. + if (!pkg)
  9174. + continue;
  9175. + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
  9176. + if (pkg->architecture)
  9177. + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
  9178. + else
  9179. + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
  9180. + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
  9181. + pkg->arch_priority = arch_priority;
  9182. + }
  9183. +
  9184. + for (i = 0; i < available_pkgs->len; i++) {
  9185. + pkg_t *pkg = available_pkgs->pkgs[i];
  9186. + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
  9187. + /* clear flags and want for any uninstallable package */
  9188. + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
  9189. + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
  9190. + pkg->state_want = SW_UNKNOWN;
  9191. + pkg->state_flag = 0;
  9192. + }
  9193. + }
  9194. + pkg_vec_free(available_pkgs);
  9195. +
  9196. + /* update the file owner data structure */
  9197. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
  9198. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9199. + for (i = 0; i < installed_pkgs->len; i++) {
  9200. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9201. + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
  9202. + str_list_elt_t *iter;
  9203. + if (installed_files == NULL) {
  9204. + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
  9205. + break;
  9206. + }
  9207. + for (iter = installed_files->head; iter; iter = iter->next) {
  9208. + char *installed_file = iter->data;
  9209. + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
  9210. + file_hash_set_file_owner(conf, installed_file, pkg);
  9211. + }
  9212. + }
  9213. + pkg_vec_free(installed_pkgs);
  9214. +
  9215. + return 0;
  9216. +}
  9217. +
  9218. +struct pkg_write_filelist_data {
  9219. + ipkg_conf_t *conf;
  9220. + pkg_t *pkg;
  9221. + FILE *stream;
  9222. +};
  9223. +
  9224. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
  9225. +{
  9226. + struct pkg_write_filelist_data *data = data_;
  9227. + pkg_t *entry = entry_;
  9228. + if (entry == data->pkg) {
  9229. + fprintf(data->stream, "%s\n", key);
  9230. + }
  9231. +}
  9232. +
  9233. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
  9234. +{
  9235. + struct pkg_write_filelist_data data;
  9236. + char *list_file_name = NULL;
  9237. + int err = 0;
  9238. +
  9239. + if (!pkg) {
  9240. + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
  9241. + return -EINVAL;
  9242. + }
  9243. + ipkg_message(conf, IPKG_INFO,
  9244. + " creating %s.list file\n", pkg->name);
  9245. + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
  9246. + if (!list_file_name) {
  9247. + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
  9248. + return -ENOMEM;
  9249. + }
  9250. + ipkg_message(conf, IPKG_INFO,
  9251. + " creating %s file for pkg %s\n", list_file_name, pkg->name);
  9252. + data.stream = fopen(list_file_name, "w");
  9253. + if (!data.stream) {
  9254. + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
  9255. + list_file_name, strerror(errno));
  9256. + return errno;
  9257. + }
  9258. + data.pkg = pkg;
  9259. + data.conf = conf;
  9260. + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
  9261. + fclose(data.stream);
  9262. + free(list_file_name);
  9263. +
  9264. + return err;
  9265. +}
  9266. +
  9267. +int pkg_write_changed_filelists(ipkg_conf_t *conf)
  9268. +{
  9269. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9270. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9271. + int i;
  9272. + int err;
  9273. + if (conf->noaction)
  9274. + return 0;
  9275. +
  9276. + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
  9277. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9278. + for (i = 0; i < installed_pkgs->len; i++) {
  9279. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9280. + if (pkg->state_flag & SF_FILELIST_CHANGED) {
  9281. + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
  9282. + err = pkg_write_filelist(conf, pkg);
  9283. + if (err)
  9284. + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
  9285. + }
  9286. + }
  9287. + return 0;
  9288. +}
  9289. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_depends.c busybox-1.17.0/archival/libipkg/pkg_depends.c
  9290. --- busybox-1.17.0.orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
  9291. +++ busybox-1.17.0/archival/libipkg/pkg_depends.c 2010-07-16 14:45:15.895924044 +0200
  9292. @@ -0,0 +1,1032 @@
  9293. +/* pkg_depends.c - the itsy package management system
  9294. +
  9295. + Steven M. Ayer
  9296. +
  9297. + Copyright (C) 2002 Compaq Computer Corporation
  9298. +
  9299. + This program is free software; you can redistribute it and/or
  9300. + modify it under the terms of the GNU General Public License as
  9301. + published by the Free Software Foundation; either version 2, or (at
  9302. + your option) any later version.
  9303. +
  9304. + This program is distributed in the hope that it will be useful, but
  9305. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9306. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9307. + General Public License for more details.
  9308. +*/
  9309. +
  9310. +#include "ipkg.h"
  9311. +#include <errno.h>
  9312. +#include <ctype.h>
  9313. +
  9314. +#include "pkg.h"
  9315. +#include "ipkg_utils.h"
  9316. +#include "pkg_hash.h"
  9317. +#include "ipkg_message.h"
  9318. +#include "pkg_parse.h"
  9319. +#include "hash_table.h"
  9320. +
  9321. +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
  9322. +static depend_t * depend_init(void);
  9323. +static void depend_deinit(depend_t *d);
  9324. +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
  9325. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
  9326. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
  9327. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg);
  9328. +
  9329. +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
  9330. +{
  9331. + depend_t *depend = (depend_t *)cdata;
  9332. + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
  9333. + return 1;
  9334. + else
  9335. + return 0;
  9336. +}
  9337. +
  9338. +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
  9339. +{
  9340. + depend_t *depend = (depend_t *)cdata;
  9341. +#if 0
  9342. + pkg_t * temp = pkg_new();
  9343. + int comparison;
  9344. + parseVersion(temp, depend->version);
  9345. + comparison = pkg_compare_versions(pkg, temp);
  9346. + free(temp);
  9347. +
  9348. + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
  9349. + __FUNCTION__, pkg->name, pkg->version,
  9350. + depend, depend->constraint, depend->version,
  9351. + comparison, version_constraints_satisfied(depend, pkg));
  9352. +#endif
  9353. + if (version_constraints_satisfied(depend, pkg))
  9354. + return 1;
  9355. + else
  9356. + return 0;
  9357. +}
  9358. +
  9359. +/* returns ndependences or negative error value */
  9360. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
  9361. + pkg_vec_t *unsatisfied, char *** unresolved)
  9362. +{
  9363. + pkg_t * satisfier_entry_pkg;
  9364. + register int i, j, k, l;
  9365. + int count, found;
  9366. + char ** the_lost;
  9367. + abstract_pkg_t * ab_pkg;
  9368. +
  9369. + /*
  9370. + * this is a setup to check for redundant/cyclic dependency checks,
  9371. + * which are marked at the abstract_pkg level
  9372. + */
  9373. + if (!(ab_pkg = pkg->parent)) {
  9374. + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
  9375. + *unresolved = NULL;
  9376. + return 0;
  9377. + }
  9378. + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
  9379. + *unresolved = NULL;
  9380. + return 0;
  9381. + } else {
  9382. + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
  9383. + }
  9384. + /**/
  9385. +
  9386. + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
  9387. + if (!count){
  9388. + *unresolved = NULL;
  9389. + return 0;
  9390. + }
  9391. +
  9392. + the_lost = NULL;
  9393. +
  9394. + /* foreach dependency */
  9395. + for (i = 0; i < count; i++) {
  9396. + compound_depend_t * compound_depend = &pkg->depends[i];
  9397. + depend_t ** possible_satisfiers = compound_depend->possibilities;;
  9398. + found = 0;
  9399. + satisfier_entry_pkg = NULL;
  9400. +
  9401. + if (compound_depend->type == GREEDY_DEPEND) {
  9402. + /* foreach possible satisfier */
  9403. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9404. + /* foreach provided_by, which includes the abstract_pkg itself */
  9405. + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
  9406. + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
  9407. + int nposs = ab_provider_vec->len;
  9408. + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
  9409. + for (l = 0; l < nposs; l++) {
  9410. + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
  9411. + /* if no depends on this one, try the first package that Provides this one */
  9412. + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
  9413. + continue;
  9414. + }
  9415. +
  9416. + /* cruise this possiblity's pkg_vec looking for an installed version */
  9417. + for (k = 0; k < test_vec->len; k++) {
  9418. + pkg_t *pkg_scout = test_vec->pkgs[k];
  9419. + /* not installed, and not already known about? */
  9420. + if ((pkg_scout->state_want != SW_INSTALL)
  9421. + && !pkg_scout->parent->dependencies_checked
  9422. + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
  9423. + char ** newstuff = NULL;
  9424. + int rc;
  9425. + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
  9426. + /* check for not-already-installed dependencies */
  9427. + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
  9428. + pkg_scout,
  9429. + tmp_vec,
  9430. + &newstuff);
  9431. + if (newstuff == NULL) {
  9432. + int ok = 1;
  9433. + for (i = 0; i < rc; i++) {
  9434. + pkg_t *p = tmp_vec->pkgs[i];
  9435. + if (p->state_want == SW_INSTALL)
  9436. + continue;
  9437. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
  9438. + ok = 0;
  9439. + break;
  9440. + }
  9441. + pkg_vec_free (tmp_vec);
  9442. + if (ok) {
  9443. + /* mark this one for installation */
  9444. + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
  9445. + pkg_vec_insert(unsatisfied, pkg_scout);
  9446. + }
  9447. + } else {
  9448. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
  9449. + free (newstuff);
  9450. + }
  9451. + }
  9452. + }
  9453. + }
  9454. + }
  9455. +
  9456. + continue;
  9457. + }
  9458. +
  9459. + /* foreach possible satisfier, look for installed package */
  9460. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9461. + /* foreach provided_by, which includes the abstract_pkg itself */
  9462. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9463. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9464. + pkg_t *satisfying_pkg =
  9465. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9466. + pkg_installed_and_constraint_satisfied,
  9467. + dependence_to_satisfy, 1);
  9468. + /* Being that I can't test constraing in pkg_hash, I will test it here */
  9469. + if (satisfying_pkg != NULL) {
  9470. + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9471. + satisfying_pkg = NULL;
  9472. + }
  9473. + }
  9474. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
  9475. + if (satisfying_pkg != NULL) {
  9476. + found = 1;
  9477. + break;
  9478. + }
  9479. +
  9480. + }
  9481. + /* if nothing installed matches, then look for uninstalled satisfier */
  9482. + if (!found) {
  9483. + /* foreach possible satisfier, look for installed package */
  9484. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9485. + /* foreach provided_by, which includes the abstract_pkg itself */
  9486. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9487. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9488. + pkg_t *satisfying_pkg =
  9489. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9490. + pkg_constraint_satisfied,
  9491. + dependence_to_satisfy, 1);
  9492. + /* Being that I can't test constraing in pkg_hash, I will test it here too */
  9493. + if (satisfying_pkg != NULL) {
  9494. + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9495. + satisfying_pkg = NULL;
  9496. + }
  9497. + }
  9498. +
  9499. + /* user request overrides package recommendation */
  9500. + if (satisfying_pkg != NULL
  9501. + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
  9502. + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
  9503. + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
  9504. + pkg->name, satisfying_pkg->name);
  9505. + continue;
  9506. + }
  9507. +
  9508. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
  9509. + if (satisfying_pkg != NULL) {
  9510. + satisfier_entry_pkg = satisfying_pkg;
  9511. + break;
  9512. + }
  9513. + }
  9514. + }
  9515. +
  9516. + /* we didn't find one, add something to the unsatisfied vector */
  9517. + if (!found) {
  9518. + if (!satisfier_entry_pkg) {
  9519. + /* failure to meet recommendations is not an error */
  9520. + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
  9521. + the_lost = add_unresolved_dep(pkg, the_lost, i);
  9522. + else
  9523. + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
  9524. + pkg->name, compound_depend->possibilities[0]->pkg->name);
  9525. + }
  9526. + else {
  9527. + if (compound_depend->type == SUGGEST) {
  9528. + /* just mention it politely */
  9529. + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
  9530. + pkg->name, satisfier_entry_pkg->name);
  9531. + } else {
  9532. + char ** newstuff = NULL;
  9533. +
  9534. + if (satisfier_entry_pkg != pkg &&
  9535. + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
  9536. + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
  9537. + pkg_hash_fetch_unsatisfied_dependencies(conf,
  9538. + satisfier_entry_pkg,
  9539. + unsatisfied,
  9540. + &newstuff);
  9541. + the_lost = merge_unresolved(the_lost, newstuff);
  9542. + }
  9543. + }
  9544. + }
  9545. + }
  9546. + }
  9547. + *unresolved = the_lost;
  9548. +
  9549. + return unsatisfied->len;
  9550. +}
  9551. +
  9552. +/*checking for conflicts !in replaces
  9553. + If a packages conflicts with another but is also replacing it, I should not consider it a
  9554. + really conflicts
  9555. + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
  9556. +*/
  9557. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
  9558. +{
  9559. + int i ;
  9560. + int replaces_count = pkg->replaces_count;
  9561. + abstract_pkg_t **replaces;
  9562. +
  9563. + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
  9564. + return 0;
  9565. +
  9566. + replaces = pkg->replaces;
  9567. +
  9568. + for (i = 0; i < replaces_count; i++) {
  9569. + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
  9570. + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
  9571. + return 1;
  9572. + }
  9573. + }
  9574. + return 0;
  9575. +
  9576. +}
  9577. +
  9578. +
  9579. +/* Abhaya: added support for conflicts */
  9580. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg)
  9581. +{
  9582. + pkg_vec_t * installed_conflicts, * test_vec;
  9583. + compound_depend_t * conflicts;
  9584. + depend_t ** possible_satisfiers;
  9585. + depend_t * possible_satisfier;
  9586. + register int i, j, k;
  9587. + int count;
  9588. + abstract_pkg_t * ab_pkg;
  9589. + pkg_t **pkg_scouts;
  9590. + pkg_t *pkg_scout;
  9591. +
  9592. + /*
  9593. + * this is a setup to check for redundant/cyclic dependency checks,
  9594. + * which are marked at the abstract_pkg level
  9595. + */
  9596. + if(!(ab_pkg = pkg->parent)){
  9597. + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
  9598. + return (pkg_vec_t *)NULL;
  9599. + }
  9600. +
  9601. + conflicts = pkg->conflicts;
  9602. + if(!conflicts){
  9603. + return (pkg_vec_t *)NULL;
  9604. + }
  9605. + installed_conflicts = pkg_vec_alloc();
  9606. +
  9607. + count = pkg->conflicts_count;
  9608. +
  9609. +
  9610. +
  9611. + /* foreach conflict */
  9612. + for(i = 0; i < pkg->conflicts_count; i++){
  9613. +
  9614. + possible_satisfiers = conflicts->possibilities;
  9615. +
  9616. + /* foreach possible satisfier */
  9617. + for(j = 0; j < conflicts->possibility_count; j++){
  9618. + possible_satisfier = possible_satisfiers[j];
  9619. + if (!possible_satisfier)
  9620. + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
  9621. + if (!possible_satisfier->pkg)
  9622. + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
  9623. + test_vec = possible_satisfier->pkg->pkgs;
  9624. + if (test_vec) {
  9625. + /* pkg_vec found, it is an actual package conflict
  9626. + * cruise this possiblity's pkg_vec looking for an installed version */
  9627. + pkg_scouts = test_vec->pkgs;
  9628. + for(k = 0; k < test_vec->len; k++){
  9629. + pkg_scout = pkg_scouts[k];
  9630. + if (!pkg_scout) {
  9631. + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
  9632. + continue;
  9633. + }
  9634. + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
  9635. + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
  9636. + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
  9637. + pkg_vec_insert(installed_conflicts, pkg_scout);
  9638. + }
  9639. + }
  9640. + }
  9641. + }
  9642. + }
  9643. + conflicts++;
  9644. + }
  9645. +
  9646. + if (installed_conflicts->len)
  9647. + return installed_conflicts;
  9648. + pkg_vec_free(installed_conflicts);
  9649. + return (pkg_vec_t *)NULL;
  9650. +}
  9651. +
  9652. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
  9653. +{
  9654. + pkg_t * temp;
  9655. + int comparison;
  9656. +
  9657. + if(depends->constraint == NONE)
  9658. + return 1;
  9659. +
  9660. + temp = pkg_new();
  9661. +
  9662. + parseVersion(temp, depends->version);
  9663. +
  9664. + comparison = pkg_compare_versions(pkg, temp);
  9665. +
  9666. + free(temp);
  9667. +
  9668. + if((depends->constraint == EARLIER) &&
  9669. + (comparison < 0))
  9670. + return 1;
  9671. + else if((depends->constraint == LATER) &&
  9672. + (comparison > 0))
  9673. + return 1;
  9674. + else if(comparison == 0)
  9675. + return 1;
  9676. + else if((depends->constraint == LATER_EQUAL) &&
  9677. + (comparison >= 0))
  9678. + return 1;
  9679. + else if((depends->constraint == EARLIER_EQUAL) &&
  9680. + (comparison <= 0))
  9681. + return 1;
  9682. +
  9683. + return 0;
  9684. +}
  9685. +
  9686. +int pkg_dependence_satisfiable(depend_t *depend)
  9687. +{
  9688. + abstract_pkg_t *apkg = depend->pkg;
  9689. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9690. + int n_providers = provider_apkgs->len;
  9691. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9692. + pkg_vec_t *pkg_vec;
  9693. + int n_pkgs ;
  9694. + int i;
  9695. + int j;
  9696. +
  9697. + for (i = 0; i < n_providers; i++) {
  9698. + abstract_pkg_t *papkg = apkgs[i];
  9699. + pkg_vec = papkg->pkgs;
  9700. + if (pkg_vec) {
  9701. + n_pkgs = pkg_vec->len;
  9702. + for (j = 0; j < n_pkgs; j++) {
  9703. + pkg_t *pkg = pkg_vec->pkgs[j];
  9704. + if (version_constraints_satisfied(depend, pkg)) {
  9705. + return 1;
  9706. + }
  9707. + }
  9708. + }
  9709. + }
  9710. + return 0;
  9711. +}
  9712. +
  9713. +int pkg_dependence_satisfied(depend_t *depend)
  9714. +{
  9715. + abstract_pkg_t *apkg = depend->pkg;
  9716. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9717. + int n_providers = provider_apkgs->len;
  9718. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9719. + int i;
  9720. + int n_pkgs;
  9721. + int j;
  9722. +
  9723. + for (i = 0; i < n_providers; i++) {
  9724. + abstract_pkg_t *papkg = apkgs[i];
  9725. + pkg_vec_t *pkg_vec = papkg->pkgs;
  9726. + if (pkg_vec) {
  9727. + n_pkgs = pkg_vec->len;
  9728. + for (j = 0; j < n_pkgs; j++) {
  9729. + pkg_t *pkg = pkg_vec->pkgs[j];
  9730. + if (version_constraints_satisfied(depend, pkg)) {
  9731. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
  9732. + return 1;
  9733. + }
  9734. + }
  9735. + }
  9736. + }
  9737. + return 0;
  9738. +}
  9739. +
  9740. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
  9741. +{
  9742. + register int i;
  9743. + pkg_t ** pkgs = vec->pkgs;
  9744. +
  9745. + for(i = 0; i < vec->len; i++)
  9746. + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
  9747. + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
  9748. + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
  9749. + return 1;
  9750. + return 0;
  9751. +}
  9752. +
  9753. +
  9754. +#ifdef DeadCode
  9755. +/**
  9756. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  9757. + * the same abstract package and 0 otherwise.
  9758. + */
  9759. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
  9760. +{
  9761. + abstract_pkg_t **provides = pkg->provides;
  9762. + int provides_count = pkg->provides_count;
  9763. + abstract_pkg_t **replacee_provides = replacee->provides;
  9764. + int replacee_provides_count = replacee->provides_count;
  9765. + int i, j;
  9766. + for (i = 0; i < provides_count; i++) {
  9767. + abstract_pkg_t *apkg = provides[i];
  9768. + for (j = 0; j < replacee_provides_count; j++) {
  9769. + abstract_pkg_t *replacee_apkg = replacee_provides[i];
  9770. + if (apkg == replacee_apkg)
  9771. + return 1;
  9772. + }
  9773. + }
  9774. + return 0;
  9775. +}
  9776. +#endif
  9777. +
  9778. +/**
  9779. + * pkg_provides_abstract returns 1 if pkg->provides contains providee
  9780. + * and 0 otherwise.
  9781. + */
  9782. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
  9783. +{
  9784. + abstract_pkg_t **provides = pkg->provides;
  9785. + int provides_count = pkg->provides_count;
  9786. + int i;
  9787. + for (i = 0; i < provides_count; i++) {
  9788. + if (provides[i] == providee)
  9789. + return 1;
  9790. + }
  9791. + return 0;
  9792. +}
  9793. +
  9794. +/**
  9795. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  9796. + * otherwise.
  9797. + */
  9798. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
  9799. +{
  9800. + abstract_pkg_t **replaces = pkg->replaces;
  9801. + int replaces_count = pkg->replaces_count;
  9802. + /* abstract_pkg_t **replacee_provides = pkg->provides;
  9803. + int replacee_provides_count = pkg->provides_count; */
  9804. + int i, j;
  9805. + for (i = 0; i < replaces_count; i++) {
  9806. + abstract_pkg_t *abstract_replacee = replaces[i];
  9807. + for (j = 0; j < replaces_count; j++) {
  9808. + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
  9809. + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
  9810. + if (replacee->provides[j] == abstract_replacee)
  9811. + return 1;
  9812. + }
  9813. + }
  9814. + return 0;
  9815. +}
  9816. +
  9817. +
  9818. +/**
  9819. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
  9820. + * otherwise.
  9821. + */
  9822. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
  9823. +{
  9824. + compound_depend_t *conflicts = pkg->conflicts;
  9825. + int conflicts_count = pkg->conflicts_count;
  9826. + int i, j;
  9827. + for (i = 0; i < conflicts_count; i++) {
  9828. + int possibility_count = conflicts[i].possibility_count;
  9829. + struct depend **possibilities = conflicts[i].possibilities;
  9830. + for (j = 0; j < possibility_count; j++) {
  9831. + if (possibilities[j]->pkg == conflictee) {
  9832. + return 1;
  9833. + }
  9834. + }
  9835. + }
  9836. + return 0;
  9837. +}
  9838. +
  9839. +/**
  9840. + * pkg_conflicts returns 1 if pkg->conflicts contains one of
  9841. + * conflictee's provides and 0 otherwise.
  9842. + */
  9843. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
  9844. +{
  9845. + compound_depend_t *conflicts = pkg->conflicts;
  9846. + int conflicts_count = pkg->conflicts_count;
  9847. + abstract_pkg_t **conflictee_provides = conflictee->provides;
  9848. + int conflictee_provides_count = conflictee->provides_count;
  9849. + int i, j, k;
  9850. + int possibility_count;
  9851. + struct depend **possibilities;
  9852. + abstract_pkg_t *possibility ;
  9853. +
  9854. + for (i = 0; i < conflicts_count; i++) {
  9855. + possibility_count = conflicts[i].possibility_count;
  9856. + possibilities = conflicts[i].possibilities;
  9857. + for (j = 0; j < possibility_count; j++) {
  9858. + possibility = possibilities[j]->pkg;
  9859. + for (k = 0; k < conflictee_provides_count; k++) {
  9860. + if (possibility == conflictee_provides[k]) {
  9861. + return 1;
  9862. + }
  9863. + }
  9864. + }
  9865. + }
  9866. + return 0;
  9867. +}
  9868. +
  9869. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
  9870. +{
  9871. + int oldlen = 0, newlen = 0;
  9872. + char ** result;
  9873. + register int i, j;
  9874. +
  9875. + if(!newstuff)
  9876. + return oldstuff;
  9877. +
  9878. + while(oldstuff && oldstuff[oldlen]) oldlen++;
  9879. + while(newstuff && newstuff[newlen]) newlen++;
  9880. +
  9881. + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
  9882. + if (result == NULL) {
  9883. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9884. + return NULL;
  9885. + }
  9886. +
  9887. + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
  9888. + *(result + i) = *(newstuff + j);
  9889. +
  9890. + *(result + i) = NULL;
  9891. +
  9892. + return result;
  9893. +}
  9894. +
  9895. +/*
  9896. + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
  9897. + * this is null terminated, no count is carried around
  9898. + */
  9899. +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
  9900. +{
  9901. + int count;
  9902. + char ** resized;
  9903. + char *depend_str = pkg_depend_str(pkg, ref_ndx);
  9904. +
  9905. + count = 0;
  9906. + while(the_lost && the_lost[count]) count++;
  9907. +
  9908. + count++; /* need one to hold the null */
  9909. + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
  9910. + if (resized == NULL) {
  9911. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9912. + return NULL;
  9913. + }
  9914. + resized[count - 1] = strdup(depend_str);
  9915. + resized[count] = NULL;
  9916. +
  9917. + return resized;
  9918. +}
  9919. +
  9920. +void printDepends(pkg_t * pkg)
  9921. +{
  9922. + register int i, j;
  9923. + compound_depend_t * depend;
  9924. + int count;
  9925. +
  9926. + count = pkg->pre_depends_count + pkg->depends_count;
  9927. +
  9928. + depend = pkg->depends;
  9929. + if(!depend){
  9930. + fprintf(stderr, "Depends pointer is NULL\n");
  9931. + return;
  9932. + }
  9933. + for(i = 0; i < count; i++){
  9934. + fprintf(stderr, "%s has %d possibilities:\n",
  9935. + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
  9936. + depend->possibility_count);
  9937. + for(j = 0; j < depend->possibility_count; j++)
  9938. + fprintf(stderr, "\t%s version %s (%d)\n",
  9939. + depend->possibilities[j]->pkg->name,
  9940. + depend->possibilities[j]->version,
  9941. + depend->possibilities[j]->constraint);
  9942. + depend++;
  9943. + }
  9944. +}
  9945. +
  9946. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  9947. +{
  9948. + register int i, j;
  9949. +
  9950. + /* every pkg provides itself */
  9951. + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
  9952. +
  9953. + if (!pkg->provides_count)
  9954. + return 0;
  9955. +
  9956. + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
  9957. + if (pkg->provides == NULL) {
  9958. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9959. + return -1 ;
  9960. + }
  9961. + pkg->provides[0] = ab_pkg;
  9962. +
  9963. + // if (strcmp(ab_pkg->name, pkg->name))
  9964. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  9965. +
  9966. + for(i = 0; i < pkg->provides_count; i++){
  9967. + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
  9968. +
  9969. + pkg->provides[i+1] = provided_abpkg;
  9970. +
  9971. + j = 0;
  9972. + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
  9973. + }
  9974. + return 0;
  9975. +}
  9976. +
  9977. +/* Abhaya: added conflicts support */
  9978. +int buildConflicts(hash_table_t * hash, pkg_t * pkg)
  9979. +{
  9980. + register int i;
  9981. + compound_depend_t * conflicts;
  9982. +
  9983. + if (!pkg->conflicts_count)
  9984. + return 0;
  9985. +
  9986. + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
  9987. + pkg->conflicts_count);
  9988. + if (conflicts == NULL) {
  9989. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9990. + return -1;
  9991. + }
  9992. + for (i = 0; i < pkg->conflicts_count; i++) {
  9993. + conflicts->type = CONFLICTS;
  9994. + parseDepends(conflicts, hash,
  9995. + pkg->conflicts_str[i]);
  9996. +#if 0
  9997. + for (j = 0; j < conflicts->possibility_count; j++) {
  9998. + depend_t *possibility = conflicts->possibilities[j];
  9999. + abstract_pkg_t *conflicting_apkg = possibility->pkg;
  10000. + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
  10001. + }
  10002. +#endif
  10003. + conflicts++;
  10004. + }
  10005. + return 0;
  10006. +}
  10007. +
  10008. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10009. +{
  10010. + register int i, j;
  10011. +
  10012. + if (!pkg->replaces_count)
  10013. + return 0;
  10014. +
  10015. + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
  10016. + if (pkg->replaces == NULL) {
  10017. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10018. + return -1;
  10019. + }
  10020. +
  10021. + // if (strcmp(ab_pkg->name, pkg->name))
  10022. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10023. +
  10024. + for(i = 0; i < pkg->replaces_count; i++){
  10025. + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
  10026. +
  10027. + pkg->replaces[i] = old_abpkg;
  10028. +
  10029. + j = 0;
  10030. + if (!old_abpkg->replaced_by)
  10031. + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
  10032. + if ( old_abpkg->replaced_by == NULL ){
  10033. + return -1;
  10034. + }
  10035. + /* if a package pkg both replaces and conflicts old_abpkg,
  10036. + * then add it to the replaced_by vector so that old_abpkg
  10037. + * will be upgraded to ab_pkg automatically */
  10038. + if (pkg_conflicts_abstract(pkg, old_abpkg))
  10039. + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
  10040. + }
  10041. + return 0;
  10042. +}
  10043. +
  10044. +int buildDepends(hash_table_t * hash, pkg_t * pkg)
  10045. +{
  10046. + int count;
  10047. + register int i;
  10048. + compound_depend_t * depends;
  10049. +
  10050. + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
  10051. + return 0;
  10052. +
  10053. + if (0 && pkg->pre_depends_count)
  10054. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10055. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10056. + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
  10057. + if (depends == NULL) {
  10058. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10059. + return -1;
  10060. + }
  10061. +
  10062. +
  10063. + for(i = 0; i < pkg->pre_depends_count; i++){
  10064. + parseDepends(depends, hash, pkg->pre_depends_str[i]);
  10065. + if (0 && pkg->pre_depends_count)
  10066. + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
  10067. + pkg->pre_depends_str[i], depends, depends->possibility_count);
  10068. + depends->type = PREDEPEND;
  10069. + depends++;
  10070. + }
  10071. +
  10072. + for(i = 0; i < pkg->recommends_count; i++){
  10073. + parseDepends(depends, hash, pkg->recommends_str[i]);
  10074. + if (0 && pkg->recommends_count)
  10075. + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
  10076. + pkg->recommends_str[i], depends, depends->possibility_count);
  10077. + depends->type = RECOMMEND;
  10078. + depends++;
  10079. + }
  10080. +
  10081. + for(i = 0; i < pkg->suggests_count; i++){
  10082. + parseDepends(depends, hash, pkg->suggests_str[i]);
  10083. + if (0 && pkg->suggests_count)
  10084. + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
  10085. + pkg->suggests_str[i], depends, depends->possibility_count);
  10086. + depends->type = SUGGEST;
  10087. + depends++;
  10088. + }
  10089. +
  10090. + for(i = 0; i < pkg->depends_count; i++){
  10091. + parseDepends(depends, hash, pkg->depends_str[i]);
  10092. + if (0 && pkg->depends_count)
  10093. + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
  10094. + pkg->depends_str[i], depends, depends->possibility_count);
  10095. + depends++;
  10096. + }
  10097. + return 0;
  10098. +}
  10099. +
  10100. +/*
  10101. + * pkg_depend_string: returns the depends string specified by index_.
  10102. + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
  10103. + * [0,npredepends) -> returns pre_depends_str[index_]
  10104. + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index_]
  10105. + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index_]
  10106. + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index_]
  10107. + */
  10108. +char *pkg_depend_str(pkg_t *pkg, int index_)
  10109. +{
  10110. + if (index_ < pkg->pre_depends_count) {
  10111. + return pkg->pre_depends_str[index_];
  10112. + }
  10113. + index_ -= pkg->pre_depends_count;
  10114. +
  10115. + if (index_ < pkg->recommends_count) {
  10116. + return pkg->recommends_str[index_];
  10117. + }
  10118. + index_ -= pkg->recommends_count;
  10119. +
  10120. + if (index_ < pkg->suggests_count) {
  10121. + return pkg->suggests_str[index_];
  10122. + }
  10123. + index_ -= pkg->suggests_count;
  10124. +
  10125. + if (index_ < pkg->depends_count) {
  10126. + return pkg->depends_str[index_];
  10127. + }
  10128. + fprintf(stderr, "pkg_depend_str: index_ %d out of range for pkg=%s\n", index_, pkg->name);
  10129. + return NULL;
  10130. +}
  10131. +
  10132. +void freeDepends(pkg_t *pkg)
  10133. +{
  10134. + int i;
  10135. +
  10136. + if (pkg == NULL || pkg->depends == NULL) {
  10137. + return;
  10138. + }
  10139. +
  10140. + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
  10141. + for (i=0; i < pkg->depends->possibility_count; i++) {
  10142. + depend_deinit(pkg->depends->possibilities[i]);
  10143. + }
  10144. + free(pkg->depends->possibilities);
  10145. + free(pkg->depends);
  10146. + pkg->depends = NULL;
  10147. +}
  10148. +
  10149. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
  10150. +{
  10151. + compound_depend_t * depends;
  10152. + int count, othercount;
  10153. + register int i, j;
  10154. + abstract_pkg_t * ab_depend;
  10155. + abstract_pkg_t ** temp;
  10156. +
  10157. + count = pkg->pre_depends_count + pkg->depends_count;
  10158. + depends = pkg->depends;
  10159. +
  10160. + if (0 && pkg->pre_depends_count)
  10161. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10162. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10163. + for (i = 0; i < count; i++) {
  10164. + if (0 && pkg->pre_depends_count)
  10165. + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
  10166. + for (j = 0; j < depends->possibility_count; j++){
  10167. + ab_depend = depends->possibilities[j]->pkg;
  10168. + if(!ab_depend->depended_upon_by)
  10169. + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
  10170. +
  10171. + temp = ab_depend->depended_upon_by;
  10172. + othercount = 1;
  10173. + while(*temp){
  10174. + temp++;
  10175. + othercount++;
  10176. + }
  10177. + *temp = ab_pkg;
  10178. +
  10179. + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
  10180. + (othercount + 1) * sizeof(abstract_pkg_t *));
  10181. + /* the array may have moved */
  10182. + temp = ab_depend->depended_upon_by + othercount;
  10183. + *temp = NULL;
  10184. + }
  10185. + depends++;
  10186. + }
  10187. +}
  10188. +
  10189. +static depend_t * depend_init(void)
  10190. +{
  10191. + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
  10192. + if ( d==NULL ){
  10193. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10194. + return NULL;
  10195. + }
  10196. + d->constraint = NONE;
  10197. + d->version = NULL;
  10198. + d->pkg = NULL;
  10199. +
  10200. + return d;
  10201. +}
  10202. +
  10203. +static void depend_deinit(depend_t *d)
  10204. +{
  10205. + free(d);
  10206. +}
  10207. +
  10208. +static int parseDepends(compound_depend_t *compound_depend,
  10209. + hash_table_t * hash, char * depend_str)
  10210. +{
  10211. + char * pkg_name, buffer[2048];
  10212. + int num_of_ors = 0;
  10213. + register int i;
  10214. + register char * src, * dest;
  10215. + depend_t ** possibilities;
  10216. +
  10217. + /* first count the number of ored possibilities for satisfying dependency */
  10218. + src = depend_str;
  10219. + while(*src)
  10220. + if(*src++ == '|')
  10221. + num_of_ors++;
  10222. +
  10223. + compound_depend->type = DEPEND;
  10224. +
  10225. + compound_depend->possibility_count = num_of_ors + 1;
  10226. + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
  10227. + if (!possibilities)
  10228. + return -ENOMEM;
  10229. + compound_depend->possibilities = possibilities;
  10230. +
  10231. + src = depend_str;
  10232. + for(i = 0; i < num_of_ors + 1; i++){
  10233. + possibilities[i] = depend_init();
  10234. + if (!possibilities[i])
  10235. + return -ENOMEM;
  10236. + /* gobble up just the name first */
  10237. + dest = buffer;
  10238. + while(*src &&
  10239. + !isspace(*src) &&
  10240. + (*src != '(') &&
  10241. + (*src != '*') &&
  10242. + (*src != '|'))
  10243. + *dest++ = *src++;
  10244. + *dest = '\0';
  10245. + pkg_name = trim_alloc(buffer);
  10246. + if (pkg_name == NULL )
  10247. + return -ENOMEM;
  10248. +
  10249. + /* now look at possible version info */
  10250. +
  10251. + /* skip to next chars */
  10252. + if(isspace(*src))
  10253. + while(*src && isspace(*src)) src++;
  10254. +
  10255. + /* extract constraint and version */
  10256. + if(*src == '('){
  10257. + src++;
  10258. + if(!strncmp(src, "<<", 2)){
  10259. + possibilities[i]->constraint = EARLIER;
  10260. + src += 2;
  10261. + }
  10262. + else if(!strncmp(src, "<=", 2)){
  10263. + possibilities[i]->constraint = EARLIER_EQUAL;
  10264. + src += 2;
  10265. + }
  10266. + else if(!strncmp(src, ">=", 2)){
  10267. + possibilities[i]->constraint = LATER_EQUAL;
  10268. + src += 2;
  10269. + }
  10270. + else if(!strncmp(src, ">>", 2)){
  10271. + possibilities[i]->constraint = LATER;
  10272. + src += 2;
  10273. + }
  10274. + else if(!strncmp(src, "=", 1)){
  10275. + possibilities[i]->constraint = EQUAL;
  10276. + src++;
  10277. + }
  10278. + /* should these be here to support deprecated designations; dpkg does */
  10279. + else if(!strncmp(src, "<", 1)){
  10280. + possibilities[i]->constraint = EARLIER_EQUAL;
  10281. + src++;
  10282. + }
  10283. + else if(!strncmp(src, ">", 1)){
  10284. + possibilities[i]->constraint = LATER_EQUAL;
  10285. + src++;
  10286. + }
  10287. +
  10288. + /* now we have any constraint, pass space to version string */
  10289. + while(isspace(*src)) src++;
  10290. +
  10291. + /* this would be the version string */
  10292. + dest = buffer;
  10293. + while(*src && *src != ')')
  10294. + *dest++ = *src++;
  10295. + *dest = '\0';
  10296. +
  10297. + possibilities[i]->version = trim_alloc(buffer);
  10298. + /* fprintf(stderr, "let's print the depends version string:");
  10299. + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
  10300. + if (possibilities[i]->version == NULL )
  10301. + return -ENOMEM;
  10302. +
  10303. +
  10304. + }
  10305. + /* hook up the dependency to its abstract pkg */
  10306. + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
  10307. +
  10308. + free(pkg_name);
  10309. +
  10310. + /* now get past the ) and any possible | chars */
  10311. + while(*src &&
  10312. + (isspace(*src) ||
  10313. + (*src == ')') ||
  10314. + (*src == '|')))
  10315. + src++;
  10316. + if (*src == '*')
  10317. + {
  10318. + compound_depend->type = GREEDY_DEPEND;
  10319. + src++;
  10320. + }
  10321. + }
  10322. +
  10323. + return 0;
  10324. +}
  10325. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_depends.h busybox-1.17.0/archival/libipkg/pkg_depends.h
  10326. --- busybox-1.17.0.orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
  10327. +++ busybox-1.17.0/archival/libipkg/pkg_depends.h 2010-07-16 14:45:15.978010218 +0200
  10328. @@ -0,0 +1,105 @@
  10329. +/* pkg_depends.h - the itsy package management system
  10330. +
  10331. + Steven M. Ayer
  10332. +
  10333. + Copyright (C) 2002 Compaq Computer Corporation
  10334. +
  10335. + This program is free software; you can redistribute it and/or
  10336. + modify it under the terms of the GNU General Public License as
  10337. + published by the Free Software Foundation; either version 2, or (at
  10338. + your option) any later version.
  10339. +
  10340. + This program is distributed in the hope that it will be useful, but
  10341. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10342. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10343. + General Public License for more details.
  10344. +*/
  10345. +
  10346. +#ifndef PKG_DEPENDS_H
  10347. +#define PKG_DEPENDS_H
  10348. +
  10349. +#include "pkg.h"
  10350. +#include "pkg_hash.h"
  10351. +
  10352. +enum depend_type {
  10353. + PREDEPEND,
  10354. + DEPEND,
  10355. + CONFLICTS,
  10356. + GREEDY_DEPEND,
  10357. + RECOMMEND,
  10358. + SUGGEST
  10359. +};
  10360. +typedef enum depend_type depend_type_t;
  10361. +
  10362. +enum version_constraint {
  10363. + NONE,
  10364. + EARLIER,
  10365. + EARLIER_EQUAL,
  10366. + EQUAL,
  10367. + LATER_EQUAL,
  10368. + LATER
  10369. +};
  10370. +typedef enum version_constraint version_constraint_t;
  10371. +
  10372. +struct depend{
  10373. + version_constraint_t constraint;
  10374. + char * version;
  10375. + abstract_pkg_t * pkg;
  10376. +};
  10377. +typedef struct depend depend_t;
  10378. +
  10379. +struct compound_depend{
  10380. + depend_type_t type;
  10381. + int possibility_count;
  10382. + struct depend ** possibilities;
  10383. +};
  10384. +typedef struct compound_depend compound_depend_t;
  10385. +
  10386. +#include "hash_table.h"
  10387. +
  10388. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10389. +int buildConflicts(hash_table_t * hash, pkg_t * pkg);
  10390. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10391. +int buildDepends(hash_table_t * hash, pkg_t * pkg);
  10392. +
  10393. +/**
  10394. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10395. + * the same abstract package and 0 otherwise.
  10396. + */
  10397. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
  10398. +
  10399. +/**
  10400. + * pkg_provides returns 1 if pkg->provides contains providee and 0
  10401. + * otherwise.
  10402. + */
  10403. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
  10404. +
  10405. +/**
  10406. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10407. + * otherwise.
  10408. + */
  10409. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
  10410. +
  10411. +/**
  10412. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
  10413. + * otherwise.
  10414. + */
  10415. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
  10416. +
  10417. +/**
  10418. + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
  10419. + * otherwise.
  10420. + */
  10421. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
  10422. +
  10423. +char *pkg_depend_str(pkg_t *pkg, int index_);
  10424. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
  10425. +void freeDepends(pkg_t *pkg);
  10426. +void printDepends(pkg_t * pkg);
  10427. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
  10428. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
  10429. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
  10430. +int pkg_dependence_satisfiable(depend_t *depend);
  10431. +int pkg_dependence_satisfied(depend_t *depend);
  10432. +
  10433. +#endif
  10434. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_dest.c busybox-1.17.0/archival/libipkg/pkg_dest.c
  10435. --- busybox-1.17.0.orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
  10436. +++ busybox-1.17.0/archival/libipkg/pkg_dest.c 2010-07-16 14:45:16.028014203 +0200
  10437. @@ -0,0 +1,92 @@
  10438. +/* pkg_dest.c - the itsy package management system
  10439. +
  10440. + Carl D. Worth
  10441. +
  10442. + Copyright (C) 2001 University of Southern California
  10443. +
  10444. + This program is free software; you can redistribute it and/or
  10445. + modify it under the terms of the GNU General Public License as
  10446. + published by the Free Software Foundation; either version 2, or (at
  10447. + your option) any later version.
  10448. +
  10449. + This program is distributed in the hope that it will be useful, but
  10450. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10451. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10452. + General Public License for more details.
  10453. +*/
  10454. +
  10455. +#include "ipkg.h"
  10456. +
  10457. +#include "pkg_dest.h"
  10458. +#include "file_util.h"
  10459. +#include "str_util.h"
  10460. +#include "sprintf_alloc.h"
  10461. +
  10462. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
  10463. +{
  10464. + dest->name = strdup(name);
  10465. +
  10466. + /* Guarantee that dest->root_dir ends with a '/' */
  10467. + if (str_ends_with(root_dir, "/")) {
  10468. + dest->root_dir = strdup(root_dir);
  10469. + } else {
  10470. + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
  10471. + }
  10472. + file_mkdir_hier(dest->root_dir, 0755);
  10473. +
  10474. + sprintf_alloc(&dest->ipkg_dir, "%s%s",
  10475. + dest->root_dir, IPKG_STATE_DIR_PREFIX);
  10476. + file_mkdir_hier(dest->ipkg_dir, 0755);
  10477. +
  10478. + if (str_starts_with (lists_dir, "/"))
  10479. + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
  10480. + else
  10481. + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
  10482. +
  10483. + file_mkdir_hier(dest->lists_dir, 0755);
  10484. +
  10485. + sprintf_alloc(&dest->info_dir, "%s/%s",
  10486. + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
  10487. + file_mkdir_hier(dest->info_dir, 0755);
  10488. +
  10489. + sprintf_alloc(&dest->status_file_name, "%s/%s",
  10490. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10491. +
  10492. + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
  10493. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10494. +
  10495. + dest->status_file = NULL;
  10496. +
  10497. + return 0;
  10498. +}
  10499. +
  10500. +void pkg_dest_deinit(pkg_dest_t *dest)
  10501. +{
  10502. + free(dest->name);
  10503. + dest->name = NULL;
  10504. +
  10505. + free(dest->root_dir);
  10506. + dest->root_dir = NULL;
  10507. +
  10508. + free(dest->ipkg_dir);
  10509. + dest->ipkg_dir = NULL;
  10510. +
  10511. + free(dest->lists_dir);
  10512. + dest->lists_dir = NULL;
  10513. +
  10514. + free(dest->info_dir);
  10515. + dest->info_dir = NULL;
  10516. +
  10517. + free(dest->status_file_name);
  10518. + dest->status_file_name = NULL;
  10519. +
  10520. + free(dest->status_file_tmp_name);
  10521. + dest->status_file_tmp_name = NULL;
  10522. +
  10523. + if (dest->status_file) {
  10524. + fclose(dest->status_file);
  10525. + }
  10526. + dest->status_file = NULL;
  10527. +
  10528. + dest->root_dir = NULL;
  10529. +}
  10530. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_dest.h busybox-1.17.0/archival/libipkg/pkg_dest.h
  10531. --- busybox-1.17.0.orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
  10532. +++ busybox-1.17.0/archival/libipkg/pkg_dest.h 2010-07-16 14:45:16.076098683 +0200
  10533. @@ -0,0 +1,38 @@
  10534. +/* pkg_dest.h - the itsy package management system
  10535. +
  10536. + Carl D. Worth
  10537. +
  10538. + Copyright (C) 2001 University of Southern California
  10539. +
  10540. + This program is free software; you can redistribute it and/or
  10541. + modify it under the terms of the GNU General Public License as
  10542. + published by the Free Software Foundation; either version 2, or (at
  10543. + your option) any later version.
  10544. +
  10545. + This program is distributed in the hope that it will be useful, but
  10546. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10547. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10548. + General Public License for more details.
  10549. +*/
  10550. +
  10551. +#ifndef PKG_DEST_H
  10552. +#define PKG_DEST_H
  10553. +
  10554. +typedef struct pkg_dest pkg_dest_t;
  10555. +struct pkg_dest
  10556. +{
  10557. + char *name;
  10558. + char *root_dir;
  10559. + char *ipkg_dir;
  10560. + char *lists_dir;
  10561. + char *info_dir;
  10562. + char *status_file_name;
  10563. + char *status_file_tmp_name;
  10564. + FILE *status_file;
  10565. +};
  10566. +
  10567. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
  10568. +void pkg_dest_deinit(pkg_dest_t *dest);
  10569. +
  10570. +#endif
  10571. +
  10572. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_dest_list.c busybox-1.17.0/archival/libipkg/pkg_dest_list.c
  10573. --- busybox-1.17.0.orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
  10574. +++ busybox-1.17.0/archival/libipkg/pkg_dest_list.c 2010-07-16 14:45:16.115906540 +0200
  10575. @@ -0,0 +1,85 @@
  10576. +/* pkg_dest_list.c - the itsy package management system
  10577. +
  10578. + Carl D. Worth
  10579. +
  10580. + Copyright (C) 2001 University of Southern California
  10581. +
  10582. + This program is free software; you can redistribute it and/or
  10583. + modify it under the terms of the GNU General Public License as
  10584. + published by the Free Software Foundation; either version 2, or (at
  10585. + your option) any later version.
  10586. +
  10587. + This program is distributed in the hope that it will be useful, but
  10588. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10589. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10590. + General Public License for more details.
  10591. +*/
  10592. +
  10593. +#include "ipkg.h"
  10594. +
  10595. +#include "pkg_dest.h"
  10596. +#include "void_list.h"
  10597. +#include "pkg_dest_list.h"
  10598. +
  10599. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
  10600. +{
  10601. + return void_list_elt_init((void_list_elt_t *) elt, data);
  10602. +}
  10603. +
  10604. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
  10605. +{
  10606. + void_list_elt_deinit((void_list_elt_t *) elt);
  10607. +}
  10608. +
  10609. +int pkg_dest_list_init(pkg_dest_list_t *list)
  10610. +{
  10611. + return void_list_init((void_list_t *) list);
  10612. +}
  10613. +
  10614. +void pkg_dest_list_deinit(pkg_dest_list_t *list)
  10615. +{
  10616. + pkg_dest_list_elt_t *iter;
  10617. + pkg_dest_t *pkg_dest;
  10618. +
  10619. + for (iter = list->head; iter; iter = iter->next) {
  10620. + pkg_dest = iter->data;
  10621. + pkg_dest_deinit(pkg_dest);
  10622. +
  10623. + /* malloced in pkg_dest_list_append */
  10624. + free(pkg_dest);
  10625. + iter->data = NULL;
  10626. + }
  10627. + void_list_deinit((void_list_t *) list);
  10628. +}
  10629. +
  10630. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10631. + const char *root_dir,const char *lists_dir)
  10632. +{
  10633. + int err;
  10634. + pkg_dest_t *pkg_dest;
  10635. +
  10636. + /* freed in plg_dest_list_deinit */
  10637. + pkg_dest = malloc(sizeof(pkg_dest_t));
  10638. + if (pkg_dest == NULL) {
  10639. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10640. + return NULL;
  10641. + }
  10642. +
  10643. + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
  10644. + err = void_list_append((void_list_t *) list, pkg_dest);
  10645. + if (err) {
  10646. + return NULL;
  10647. + }
  10648. +
  10649. + return pkg_dest;
  10650. +}
  10651. +
  10652. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
  10653. +{
  10654. + return void_list_push((void_list_t *) list, data);
  10655. +}
  10656. +
  10657. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
  10658. +{
  10659. + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
  10660. +}
  10661. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_dest_list.h busybox-1.17.0/archival/libipkg/pkg_dest_list.h
  10662. --- busybox-1.17.0.orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
  10663. +++ busybox-1.17.0/archival/libipkg/pkg_dest_list.h 2010-07-16 14:45:16.168015911 +0200
  10664. @@ -0,0 +1,50 @@
  10665. +/* pkg_dest_list.h - the itsy package management system
  10666. +
  10667. + Carl D. Worth
  10668. +
  10669. + Copyright (C) 2001 University of Southern California
  10670. +
  10671. + This program is free software; you can redistribute it and/or
  10672. + modify it under the terms of the GNU General Public License as
  10673. + published by the Free Software Foundation; either version 2, or (at
  10674. + your option) any later version.
  10675. +
  10676. + This program is distributed in the hope that it will be useful, but
  10677. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10678. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10679. + General Public License for more details.
  10680. +*/
  10681. +
  10682. +#ifndef PKG_DEST_LIST_H
  10683. +#define PKG_DEST_LIST_H
  10684. +
  10685. +#include "pkg_dest.h"
  10686. +
  10687. +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
  10688. +struct pkg_dest_list_elt
  10689. +{
  10690. + pkg_dest_list_elt_t *next;
  10691. + pkg_dest_t *data;
  10692. +};
  10693. +
  10694. +typedef struct pkg_dest_list pkg_dest_list_t;
  10695. +struct pkg_dest_list
  10696. +{
  10697. + pkg_dest_list_elt_t pre_head;
  10698. + pkg_dest_list_elt_t *head;
  10699. + pkg_dest_list_elt_t *tail;
  10700. +};
  10701. +
  10702. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
  10703. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
  10704. +
  10705. +int pkg_dest_list_init(pkg_dest_list_t *list);
  10706. +void pkg_dest_list_deinit(pkg_dest_list_t *list);
  10707. +
  10708. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10709. + const char *root_dir,const char* lists_dir);
  10710. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
  10711. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
  10712. +
  10713. +#endif
  10714. +
  10715. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_extract.c busybox-1.17.0/archival/libipkg/pkg_extract.c
  10716. --- busybox-1.17.0.orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
  10717. +++ busybox-1.17.0/archival/libipkg/pkg_extract.c 2010-07-16 14:45:16.218016333 +0200
  10718. @@ -0,0 +1,255 @@
  10719. +/* pkg_extract.c - the itsy package management system
  10720. +
  10721. + Carl D. Worth
  10722. +
  10723. + Copyright (C) 2001 University of Southern California
  10724. +
  10725. + This program is free software; you can redistribute it and/or
  10726. + modify it under the terms of the GNU General Public License as
  10727. + published by the Free Software Foundation; either version 2, or (at
  10728. + your option) any later version.
  10729. +
  10730. + This program is distributed in the hope that it will be useful, but
  10731. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10732. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10733. + General Public License for more details.
  10734. +*/
  10735. +
  10736. +#include "ipkg.h"
  10737. +#include <errno.h>
  10738. +#include <fcntl.h>
  10739. +#include <stdio.h>
  10740. +
  10741. +#include "pkg_extract.h"
  10742. +
  10743. +#include "libbb.h"
  10744. +#include "file_util.h"
  10745. +#include "sprintf_alloc.h"
  10746. +#include "unarchive.h"
  10747. +
  10748. +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
  10749. +#define IPKG_DATA_ARCHIVE "data.tar.gz"
  10750. +#define IPKG_CONTROL_FILE "control"
  10751. +
  10752. +static void FAST_FUNC ipkg_data_extract_all_prefix(archive_handle_t *archive_handle)
  10753. +{
  10754. + char *name_ptr = archive_handle->file_header->name;
  10755. +
  10756. + /* Skip all leading "/" */
  10757. + while (*name_ptr == '/')
  10758. + name_ptr++;
  10759. + /* Skip all leading "./" and "../" */
  10760. + while (name_ptr[0] == '.') {
  10761. + if (name_ptr[1] == '.' && name_ptr[2] == '/')
  10762. + name_ptr++;
  10763. + if (name_ptr[1] != '/')
  10764. + break;
  10765. + name_ptr += 2;
  10766. + }
  10767. +
  10768. + if (name_ptr[0] != '\0') {
  10769. + archive_handle->file_header->name = xasprintf("%s%s", archive_handle->dpkg__buffer, name_ptr);
  10770. + data_extract_all(archive_handle);
  10771. + }
  10772. +}
  10773. +
  10774. +static void FAST_FUNC ipkg_data_extract_to_buffer(archive_handle_t *archive_handle)
  10775. +{
  10776. + unsigned size = archive_handle->file_header->size;
  10777. +
  10778. + archive_handle->dpkg__buffer = xzalloc(size + 1);
  10779. + xread(archive_handle->src_fd, archive_handle->dpkg__buffer, size);
  10780. +}
  10781. +
  10782. +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
  10783. +{
  10784. + archive_handle_t *archive;
  10785. + char *path;
  10786. +
  10787. + sprintf_alloc(&path, "%s/", dir);
  10788. + archive = init_handle();
  10789. + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
  10790. + archive->filter = filter_accept_list;
  10791. + llist_add_to(&(archive->accept), (char *)filename);
  10792. + archive->dpkg__buffer = path;
  10793. + archive->action_data = ipkg_data_extract_all_prefix;
  10794. + archive->ah_flags |= ARCHIVE_UNLINK_OLD;
  10795. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10796. + close(archive->src_fd);
  10797. + free(archive->accept);
  10798. + free(archive);
  10799. + free(path);
  10800. +}
  10801. +
  10802. +static void FAST_FUNC data_extract_file_name_to_buffer(archive_handle_t *archive)
  10803. +{
  10804. + unsigned int size = strlen(archive->file_header->name) + 2;
  10805. +
  10806. + if (archive->dpkg__buffer == NULL) {
  10807. + archive->dpkg__buffer = xmalloc(size);
  10808. + strcpy(archive->dpkg__buffer, archive->file_header->name);
  10809. + } else {
  10810. + size += strlen(archive->dpkg__buffer);
  10811. + archive->dpkg__buffer = xrealloc(archive->dpkg__buffer, size);
  10812. + strcat(archive->dpkg__buffer, archive->file_header->name);
  10813. + }
  10814. + strcat(archive->dpkg__buffer, "\n");
  10815. + data_skip(archive);
  10816. +}
  10817. +
  10818. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
  10819. +{
  10820. + archive_handle_t *archive;
  10821. + char *name;
  10822. + const char *filename = "./" IPKG_CONTROL_FILE;
  10823. +
  10824. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10825. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10826. + archive = init_handle();
  10827. + archive->src_fd = xopen(name, O_RDONLY);
  10828. + archive->filter = filter_accept_list;
  10829. + llist_add_to(&(archive->accept), (char *)filename);
  10830. + archive->action_data = ipkg_data_extract_to_buffer;
  10831. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10832. + close(archive->src_fd);
  10833. + fputs(archive->dpkg__buffer, stream);
  10834. + free(archive->dpkg__buffer);
  10835. + free(archive->accept);
  10836. + free(archive);
  10837. + free(name);
  10838. +
  10839. + return 0;
  10840. +}
  10841. +
  10842. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
  10843. +{
  10844. + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
  10845. +}
  10846. +
  10847. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
  10848. +{
  10849. + archive_handle_t *archive;
  10850. + char *name;
  10851. + char *path;
  10852. +
  10853. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10854. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10855. + sprintf_alloc(&path, "%s/%s", dir, prefix);
  10856. + archive = init_handle();
  10857. + archive->src_fd = xopen(name, O_RDONLY);
  10858. + archive->filter = filter_accept_all;
  10859. + archive->dpkg__buffer = path;
  10860. + archive->action_data = ipkg_data_extract_all_prefix;
  10861. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  10862. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10863. + close(archive->src_fd);
  10864. + free(archive);
  10865. + free(path);
  10866. + free(name);
  10867. +
  10868. + return 0;
  10869. +}
  10870. +
  10871. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
  10872. +{
  10873. + archive_handle_t *archive;
  10874. + char *name;
  10875. + char *path;
  10876. +
  10877. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  10878. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  10879. + sprintf_alloc(&path, "%s/", dir);
  10880. + archive = init_handle();
  10881. + archive->src_fd = xopen(name, O_RDONLY);
  10882. + archive->filter = filter_accept_all;
  10883. + archive->dpkg__buffer = path;
  10884. + archive->action_data = ipkg_data_extract_all_prefix;
  10885. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  10886. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10887. + close(archive->src_fd);
  10888. + free(archive);
  10889. + free(path);
  10890. + free(name);
  10891. +
  10892. + return 0;
  10893. +}
  10894. +
  10895. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
  10896. +{
  10897. + int err=0;
  10898. + char *line, *data_file;
  10899. + FILE *file;
  10900. + FILE *tmp;
  10901. +
  10902. + file = fopen(file_name, "w");
  10903. + if (file == NULL) {
  10904. + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
  10905. + __FUNCTION__, file_name);
  10906. + return EINVAL;
  10907. + }
  10908. +
  10909. + tmp = tmpfile();
  10910. + if (pkg->installed_files) {
  10911. + str_list_elt_t *elt;
  10912. + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
  10913. + fprintf(file, "%s\n", elt->data);
  10914. + }
  10915. + } else {
  10916. + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
  10917. + if (err) {
  10918. + fclose(file);
  10919. + fclose(tmp);
  10920. + return err;
  10921. + }
  10922. +
  10923. + /* Fixup data file names by removing the initial '.' */
  10924. + rewind(tmp);
  10925. + while (1) {
  10926. + line = file_read_line_alloc(tmp);
  10927. + if (line == NULL) {
  10928. + break;
  10929. + }
  10930. +
  10931. + data_file = line;
  10932. + if (*data_file == '.') {
  10933. + data_file++;
  10934. + }
  10935. +
  10936. + if (*data_file != '/') {
  10937. + fputs("/", file);
  10938. + }
  10939. +
  10940. + /* I have no idea why, but this is what dpkg does */
  10941. + if (strcmp(data_file, "/\n") == 0) {
  10942. + fputs("/.\n", file);
  10943. + } else {
  10944. + fputs(data_file, file);
  10945. + }
  10946. + }
  10947. + }
  10948. + fclose(tmp);
  10949. + fclose(file);
  10950. +
  10951. + return err;
  10952. +}
  10953. +
  10954. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
  10955. +{
  10956. + archive_handle_t *archive;
  10957. + char *name;
  10958. +
  10959. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  10960. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  10961. + archive = init_handle();
  10962. + archive->src_fd = xopen(name, O_RDONLY);
  10963. + archive->filter = filter_accept_all;
  10964. + archive->action_data = data_extract_file_name_to_buffer;
  10965. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10966. + close(archive->src_fd);
  10967. + fputs(archive->dpkg__buffer, file);
  10968. + free(archive->dpkg__buffer);
  10969. + free(archive);
  10970. + free(name);
  10971. +
  10972. + return 0;
  10973. +}
  10974. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_extract.h busybox-1.17.0/archival/libipkg/pkg_extract.h
  10975. --- busybox-1.17.0.orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
  10976. +++ busybox-1.17.0/archival/libipkg/pkg_extract.h 2010-07-16 14:45:16.268017317 +0200
  10977. @@ -0,0 +1,32 @@
  10978. +/* pkg_extract.c - the itsy package management system
  10979. +
  10980. + Carl D. Worth
  10981. +
  10982. + Copyright (C) 2001 University of Southern California
  10983. +
  10984. + This program is free software; you can redistribute it and/or
  10985. + modify it under the terms of the GNU General Public License as
  10986. + published by the Free Software Foundation; either version 2, or (at
  10987. + your option) any later version.
  10988. +
  10989. + This program is distributed in the hope that it will be useful, but
  10990. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10991. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10992. + General Public License for more details.
  10993. +*/
  10994. +
  10995. +#ifndef PKG_EXTRACT_H
  10996. +#define PKG_EXTRACT_H
  10997. +
  10998. +#include "pkg.h"
  10999. +
  11000. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
  11001. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
  11002. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
  11003. + const char *dir,
  11004. + const char *prefix);
  11005. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
  11006. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
  11007. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
  11008. +
  11009. +#endif
  11010. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg.h busybox-1.17.0/archival/libipkg/pkg.h
  11011. --- busybox-1.17.0.orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
  11012. +++ busybox-1.17.0/archival/libipkg/pkg.h 2010-07-16 14:45:16.318017216 +0200
  11013. @@ -0,0 +1,229 @@
  11014. +/* pkg.h - the itsy package management system
  11015. +
  11016. + Carl D. Worth
  11017. +
  11018. + Copyright (C) 2001 University of Southern California
  11019. +
  11020. + This program is free software; you can redistribute it and/or
  11021. + modify it under the terms of the GNU General Public License as
  11022. + published by the Free Software Foundation; either version 2, or (at
  11023. + your option) any later version.
  11024. +
  11025. + This program is distributed in the hope that it will be useful, but
  11026. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11027. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11028. + General Public License for more details.
  11029. +*/
  11030. +
  11031. +#ifndef PKG_H
  11032. +#define PKG_H
  11033. +
  11034. +#include <sys/types.h>
  11035. +#include <sys/stat.h>
  11036. +#include <unistd.h>
  11037. +
  11038. +#include "pkg_vec.h"
  11039. +#include "str_list.h"
  11040. +#include "pkg_src.h"
  11041. +#include "pkg_dest.h"
  11042. +#include "ipkg_conf.h"
  11043. +#include "conffile_list.h"
  11044. +
  11045. +struct ipkg_conf;
  11046. +
  11047. +/* I think "Size" is currently the shortest field name */
  11048. +#define PKG_MINIMUM_FIELD_NAME_LEN 4
  11049. +
  11050. +enum pkg_state_want
  11051. +{
  11052. + SW_UNKNOWN = 1,
  11053. + SW_INSTALL,
  11054. + SW_DEINSTALL,
  11055. + SW_PURGE,
  11056. + SW_LAST_STATE_WANT
  11057. +};
  11058. +typedef enum pkg_state_want pkg_state_want_t;
  11059. +
  11060. +enum pkg_state_flag
  11061. +{
  11062. + SF_OK = 0,
  11063. + SF_REINSTREQ = 1,
  11064. + SF_HOLD = 2, /* do not upgrade version */
  11065. + SF_REPLACE = 4, /* replace this package */
  11066. + SF_NOPRUNE = 8, /* do not remove obsolete files */
  11067. + SF_PREFER = 16, /* prefer this version */
  11068. + SF_OBSOLETE = 32, /* old package in upgrade pair */
  11069. + SF_MARKED = 64, /* temporary mark */
  11070. + SF_FILELIST_CHANGED = 128, /* needs filelist written */
  11071. + SF_USER = 256,
  11072. + SF_LAST_STATE_FLAG
  11073. +};
  11074. +typedef enum pkg_state_flag pkg_state_flag_t;
  11075. +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
  11076. +
  11077. +enum pkg_state_status
  11078. +{
  11079. + SS_NOT_INSTALLED = 1,
  11080. + SS_UNPACKED,
  11081. + SS_HALF_CONFIGURED,
  11082. + SS_INSTALLED,
  11083. + SS_HALF_INSTALLED,
  11084. + SS_CONFIG_FILES,
  11085. + SS_POST_INST_FAILED,
  11086. + SS_REMOVAL_FAILED,
  11087. + SS_LAST_STATE_STATUS
  11088. +};
  11089. +typedef enum pkg_state_status pkg_state_status_t;
  11090. +
  11091. +struct abstract_pkg{
  11092. + char * name;
  11093. + int dependencies_checked;
  11094. + pkg_vec_t * pkgs;
  11095. + pkg_state_status_t state_status;
  11096. + pkg_state_flag_t state_flag;
  11097. + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
  11098. + abstract_pkg_vec_t * provided_by;
  11099. + abstract_pkg_vec_t * replaced_by;
  11100. +};
  11101. +
  11102. +#include "pkg_depends.h"
  11103. +
  11104. +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
  11105. +
  11106. + The 3 version fields should go into a single version struct. (This
  11107. + is especially important since, currently, pkg->version can easily
  11108. + be mistaken for pkg_verson_str_alloc(pkg) although they are very
  11109. + distinct. This has been the source of multiple bugs.
  11110. +
  11111. + The 3 state fields could possibly also go into their own struct.
  11112. +
  11113. + All fields which deal with lists of packages, (Depends,
  11114. + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
  11115. + be handled by a single struct in pkg_t
  11116. +
  11117. + All string fields for which there is a small set of possible
  11118. + values, (section, maintainer, architecture, maybe version?), that
  11119. + are reused among different packages -- for all such packages we
  11120. + should move from "char *"s to some atom datatype to share data
  11121. + storage and use less memory. We might even do reference counting,
  11122. + but probably not since most often we only create new pkg_t structs,
  11123. + we don't often free them. */
  11124. +struct pkg
  11125. +{
  11126. + char *name;
  11127. + unsigned long epoch;
  11128. + char *version;
  11129. + char *revision;
  11130. + char *familiar_revision;
  11131. + pkg_src_t *src;
  11132. + pkg_dest_t *dest;
  11133. + char *architecture;
  11134. + char *section;
  11135. + char *maintainer;
  11136. + char *description;
  11137. + pkg_state_want_t state_want;
  11138. + pkg_state_flag_t state_flag;
  11139. + pkg_state_status_t state_status;
  11140. + char **depends_str;
  11141. + int depends_count;
  11142. + char **pre_depends_str;
  11143. + int pre_depends_count;
  11144. + char **recommends_str;
  11145. + int recommends_count;
  11146. + char **suggests_str;
  11147. + int suggests_count;
  11148. + compound_depend_t * depends;
  11149. +
  11150. + /* Abhaya: new conflicts */
  11151. + char **conflicts_str;
  11152. + compound_depend_t * conflicts;
  11153. + int conflicts_count;
  11154. +
  11155. + char **replaces_str;
  11156. + int replaces_count;
  11157. + abstract_pkg_t ** replaces;
  11158. +
  11159. + char **provides_str;
  11160. + int provides_count;
  11161. + abstract_pkg_t ** provides;
  11162. +
  11163. + abstract_pkg_t *parent;
  11164. +
  11165. + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
  11166. +
  11167. + char *filename;
  11168. + char *local_filename;
  11169. + char *url;
  11170. + char *tmp_unpack_dir;
  11171. + char *md5sum;
  11172. + char *size;
  11173. + char *installed_size;
  11174. + char *priority;
  11175. + char *source;
  11176. + conffile_list_t conffiles;
  11177. + time_t installed_time;
  11178. + /* As pointer for lazy evaluation */
  11179. + str_list_t *installed_files;
  11180. + /* XXX: CLEANUP: I'd like to perhaps come up with a better
  11181. + mechanism to avoid the problem here, (which is that the
  11182. + installed_files list was being freed from an inner loop while
  11183. + still being used within an outer loop. */
  11184. + int installed_files_ref_cnt;
  11185. + int essential;
  11186. + int arch_priority;
  11187. +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
  11188. + int provided_by_hand;
  11189. +};
  11190. +
  11191. +pkg_t *pkg_new(void);
  11192. +int pkg_init(pkg_t *pkg);
  11193. +void pkg_deinit(pkg_t *pkg);
  11194. +int pkg_init_from_file(pkg_t *pkg, const char *filename);
  11195. +abstract_pkg_t *abstract_pkg_new(void);
  11196. +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
  11197. +
  11198. +/*
  11199. + * merges fields from newpkg into oldpkg.
  11200. + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
  11201. + */
  11202. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
  11203. +
  11204. +char *pkg_version_str_alloc(pkg_t *pkg);
  11205. +
  11206. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
  11207. +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
  11208. +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
  11209. +
  11210. +char * pkg_formatted_info(pkg_t *pkg );
  11211. +char * pkg_formatted_field(pkg_t *pkg, const char *field );
  11212. +
  11213. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
  11214. +
  11215. +void pkg_print_info(pkg_t *pkg, FILE *file);
  11216. +void pkg_print_status(pkg_t * pkg, FILE * file);
  11217. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
  11218. +str_list_t *pkg_get_installed_files(pkg_t *pkg);
  11219. +int pkg_free_installed_files(pkg_t *pkg);
  11220. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
  11221. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
  11222. +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
  11223. + const char *script, const char *args);
  11224. +
  11225. +/* enum mappings */
  11226. +char *pkg_state_want_to_str(pkg_state_want_t sw);
  11227. +pkg_state_want_t pkg_state_want_from_str(char *str);
  11228. +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
  11229. +pkg_state_flag_t pkg_state_flag_from_str(char *str);
  11230. +char *pkg_state_status_to_str(pkg_state_status_t ss);
  11231. +pkg_state_status_t pkg_state_status_from_str(char *str);
  11232. +
  11233. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
  11234. +
  11235. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
  11236. +int pkg_info_preinstall_check(ipkg_conf_t *conf);
  11237. +int pkg_free_installed_files(pkg_t *pkg);
  11238. +
  11239. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
  11240. +int pkg_write_changed_filelists(ipkg_conf_t *conf);
  11241. +
  11242. +#endif
  11243. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_hash.c busybox-1.17.0/archival/libipkg/pkg_hash.c
  11244. --- busybox-1.17.0.orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
  11245. +++ busybox-1.17.0/archival/libipkg/pkg_hash.c 2010-07-16 14:45:16.368018250 +0200
  11246. @@ -0,0 +1,623 @@
  11247. +/* ipkg_hash.c - the itsy package management system
  11248. +
  11249. + Steven M. Ayer
  11250. +
  11251. + Copyright (C) 2002 Compaq Computer Corporation
  11252. +
  11253. + This program is free software; you can redistribute it and/or
  11254. + modify it under the terms of the GNU General Public License as
  11255. + published by the Free Software Foundation; either version 2, or (at
  11256. + your option) any later version.
  11257. +
  11258. + This program is distributed in the hope that it will be useful, but
  11259. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11260. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11261. + General Public License for more details.
  11262. +*/
  11263. +
  11264. +#include "ipkg.h"
  11265. +#include <errno.h>
  11266. +#include <ctype.h>
  11267. +#include <stdlib.h>
  11268. +#include <string.h>
  11269. +
  11270. +#include "hash_table.h"
  11271. +#include "pkg.h"
  11272. +#include "ipkg_message.h"
  11273. +#include "pkg_vec.h"
  11274. +#include "pkg_hash.h"
  11275. +#include "pkg_parse.h"
  11276. +#include "ipkg_utils.h"
  11277. +
  11278. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11279. +
  11280. +/*
  11281. + * this will talk to both feeds-lists files and installed status files
  11282. + * example api:
  11283. + *
  11284. + * hash_table_t hash;
  11285. + * pkg_hash_init(name, &hash, 1000);
  11286. + * pkg_hash_add_from_file(<feed filename>);
  11287. + *
  11288. + * the query function is just there as a shell to prove to me that this
  11289. + * sort of works, but isn't far from doing something useful
  11290. + *
  11291. + * -sma, 12/21/01
  11292. + * modified: CDW 3 Jan. 2002
  11293. + */
  11294. +
  11295. +
  11296. +
  11297. +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
  11298. +{
  11299. + return hash_table_init(name, hash, len);
  11300. +}
  11301. +
  11302. +void pkg_hash_deinit(hash_table_t *hash)
  11303. +{
  11304. + hash_table_deinit(hash);
  11305. +}
  11306. +
  11307. +
  11308. +/* Find the default arch for a given package status file if none is given. */
  11309. +static char *pkg_get_default_arch(ipkg_conf_t *conf)
  11310. +{
  11311. + nv_pair_list_elt_t *l;
  11312. + const char *def_arch = HOST_CPU_STR; /* Default arch */
  11313. + int def_prio = 0; /* Other archs override this */
  11314. +
  11315. + l = conf->arch_list.head;
  11316. +
  11317. + while (l) {
  11318. + nv_pair_t *nv = l->data;
  11319. + int priority = strtol(nv->value, NULL, 0);
  11320. +
  11321. + /* Check if this arch has higher priority, and is valid */
  11322. + if ((priority > def_prio) &&
  11323. + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
  11324. + /* Our new default */
  11325. + def_prio = priority;
  11326. + def_arch = nv->name;
  11327. + }
  11328. + l = l->next;
  11329. + }
  11330. +
  11331. + return strdup(def_arch);
  11332. +}
  11333. +
  11334. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11335. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
  11336. +{
  11337. + hash_table_t *hash = &conf->pkg_hash;
  11338. + char **raw;
  11339. + char **raw_start;
  11340. + pkg_t *pkg;
  11341. +
  11342. + raw = raw_start = read_raw_pkgs_from_file(file_name);
  11343. + if (!raw)
  11344. + return -ENOMEM;
  11345. +
  11346. + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
  11347. + pkg = pkg_new();
  11348. + if (!pkg)
  11349. + return -ENOMEM;
  11350. +
  11351. + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
  11352. + if (!pkg->architecture) {
  11353. + char *version_str = pkg_version_str_alloc(pkg);
  11354. + pkg->architecture = pkg_get_default_arch(conf);
  11355. + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
  11356. + pkg->name, version_str, pkg->architecture);
  11357. + free(version_str);
  11358. + }
  11359. + hash_insert_pkg(hash, pkg, is_status_file,conf);
  11360. + } else {
  11361. + free(pkg);
  11362. + }
  11363. + }
  11364. +
  11365. + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
  11366. + memory after read_raw_pkgs_from_file */
  11367. + raw = raw_start;
  11368. + while (*raw) {
  11369. + free(*raw++);
  11370. + }
  11371. + free(raw_start);
  11372. + return 0;
  11373. +}
  11374. +
  11375. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
  11376. +{
  11377. + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
  11378. +}
  11379. +
  11380. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
  11381. +{
  11382. + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
  11383. + if (apkg)
  11384. + return NULL;
  11385. + return apkg->provided_by;
  11386. +}
  11387. +
  11388. +
  11389. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11390. + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
  11391. +{
  11392. + int i;
  11393. + int nprovides = 0;
  11394. + int nmatching = 0;
  11395. + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
  11396. + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
  11397. + abstract_pkg_vec_t *provided_apkg_vec;
  11398. + abstract_pkg_t **provided_apkgs;
  11399. + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
  11400. + pkg_t *latest_installed_parent = NULL;
  11401. + pkg_t *latest_matching = NULL;
  11402. + pkg_t *held_pkg = NULL;
  11403. + pkg_t *good_pkg_by_name = NULL;
  11404. +
  11405. + if (matching_apkgs == NULL || providers == NULL ||
  11406. + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
  11407. + return NULL;
  11408. +
  11409. + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
  11410. +
  11411. + provided_apkg_vec = apkg->provided_by;
  11412. + nprovides = provided_apkg_vec->len;
  11413. + provided_apkgs = provided_apkg_vec->pkgs;
  11414. + if (nprovides > 1)
  11415. + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
  11416. +
  11417. + /* accumulate all the providers */
  11418. + for (i = 0; i < nprovides; i++) {
  11419. + abstract_pkg_t *provider_apkg = provided_apkgs[i];
  11420. + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
  11421. + abstract_pkg_vec_insert(providers, provider_apkg);
  11422. + }
  11423. + nprovides = providers->len;
  11424. +
  11425. + for (i = 0; i < nprovides; i++) {
  11426. + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
  11427. + abstract_pkg_t *replacement_apkg = NULL;
  11428. + pkg_vec_t *vec;
  11429. +
  11430. + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
  11431. + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
  11432. + if (provider_apkg->replaced_by->len > 1) {
  11433. + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
  11434. + provider_apkg->name, replacement_apkg->name);
  11435. + }
  11436. + }
  11437. +
  11438. + if (replacement_apkg)
  11439. + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
  11440. + replacement_apkg->name, provider_apkg->name);
  11441. +
  11442. + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
  11443. + if (abstract_pkg_vec_contains(providers, replacement_apkg))
  11444. + continue;
  11445. + else
  11446. + provider_apkg = replacement_apkg;
  11447. + }
  11448. +
  11449. + if (!(vec = provider_apkg->pkgs)) {
  11450. + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
  11451. + continue;
  11452. + }
  11453. +
  11454. +
  11455. + /* now check for supported architecture */
  11456. + {
  11457. + int max_count = 0;
  11458. + int j;
  11459. +
  11460. + /* count packages matching max arch priority and keep track of last one */
  11461. + for (j = 0; j < vec->len; j++) {
  11462. + pkg_t *maybe = vec->pkgs[j];
  11463. + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
  11464. + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
  11465. + if (maybe->arch_priority > 0) {
  11466. + max_count++;
  11467. + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
  11468. + pkg_vec_insert(matching_pkgs, maybe);
  11469. + }
  11470. + }
  11471. + }
  11472. + }
  11473. +
  11474. + if (matching_pkgs->len > 1)
  11475. + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
  11476. + if (matching_apkgs->len > 1)
  11477. + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
  11478. +
  11479. +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
  11480. + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
  11481. +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
  11482. + Until now I always got the latest, but that breaks the downgrade option.
  11483. + If I stop at the first one, I would probably miss the new ones
  11484. + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
  11485. + or from a Packages feed.
  11486. + 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*/
  11487. +/*Pigi*/
  11488. +
  11489. + for (i = 0; i < matching_pkgs->len; i++) {
  11490. + pkg_t *matching = matching_pkgs->pkgs[i];
  11491. + if (constraint_fcn(matching, cdata)) { /* We found it */
  11492. + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
  11493. + good_pkg_by_name = matching;
  11494. + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
  11495. + break;
  11496. + }
  11497. + }
  11498. +
  11499. +
  11500. + for (i = 0; i < matching_pkgs->len; i++) {
  11501. + pkg_t *matching = matching_pkgs->pkgs[i];
  11502. + latest_matching = matching;
  11503. + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
  11504. + latest_installed_parent = matching;
  11505. + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
  11506. + if (held_pkg)
  11507. + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
  11508. + held_pkg->name, matching->name);
  11509. + held_pkg = matching;
  11510. + }
  11511. + }
  11512. +
  11513. + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
  11514. + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
  11515. + apkg->name, matching_apkgs->len);
  11516. + for (i = 0; i < matching_apkgs->len; i++) {
  11517. + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
  11518. + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
  11519. + }
  11520. + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
  11521. + }
  11522. +
  11523. + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
  11524. + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
  11525. + __FUNCTION__, apkg->name, matching_pkgs->len);
  11526. + for (i = 0; i < matching_pkgs->len; i++) {
  11527. + pkg_t *matching = matching_pkgs->pkgs[i];
  11528. + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
  11529. + matching->name, matching->version, matching->architecture);
  11530. + }
  11531. + }
  11532. +
  11533. + nmatching = matching_apkgs->len;
  11534. +
  11535. + pkg_vec_free(matching_pkgs);
  11536. + abstract_pkg_vec_free(matching_apkgs);
  11537. + abstract_pkg_vec_free(providers);
  11538. +
  11539. + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
  11540. + return good_pkg_by_name;
  11541. + }
  11542. + if (held_pkg) {
  11543. + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
  11544. + return held_pkg;
  11545. + }
  11546. + if (latest_installed_parent) {
  11547. + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
  11548. + return latest_installed_parent;
  11549. + }
  11550. + if (nmatching > 1) {
  11551. + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
  11552. + return NULL;
  11553. + }
  11554. + if (latest_matching) {
  11555. + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
  11556. + latest_matching->name, latest_matching->version, latest_matching->architecture);
  11557. + return latest_matching;
  11558. + }
  11559. + return NULL;
  11560. +}
  11561. +
  11562. +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
  11563. +{
  11564. + const char *name = (const char *)cdata;
  11565. + if (strcmp(pkg->name, name) == 0)
  11566. + return 1;
  11567. + else
  11568. + return 0;
  11569. +}
  11570. +
  11571. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
  11572. +{
  11573. + hash_table_t *hash = &conf->pkg_hash;
  11574. + abstract_pkg_t *apkg = NULL;
  11575. +
  11576. + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
  11577. + return NULL;
  11578. +
  11579. + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
  11580. +}
  11581. +
  11582. +
  11583. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11584. + const char *pkg_name,
  11585. + const char * version)
  11586. +{
  11587. + pkg_vec_t * vec;
  11588. + register int i;
  11589. + char *version_str = NULL;
  11590. +
  11591. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
  11592. + return NULL;
  11593. +
  11594. + for(i = 0; i < vec->len; i++) {
  11595. + version_str = pkg_version_str_alloc(vec->pkgs[i]);
  11596. + if(!strcmp(version_str, version)) {
  11597. + free(version_str);
  11598. + break;
  11599. + }
  11600. + free(version_str);
  11601. + }
  11602. +
  11603. + if(i == vec->len)
  11604. + return NULL;
  11605. +
  11606. + return vec->pkgs[i];
  11607. +}
  11608. +
  11609. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11610. + const char *pkg_name,
  11611. + pkg_dest_t *dest)
  11612. +{
  11613. + pkg_vec_t * vec;
  11614. + register int i;
  11615. +
  11616. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
  11617. + return NULL;
  11618. + }
  11619. +
  11620. + for(i = 0; i < vec->len; i++)
  11621. + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
  11622. + return vec->pkgs[i];
  11623. + }
  11624. + return NULL;
  11625. +}
  11626. +
  11627. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11628. + const char *pkg_name)
  11629. +{
  11630. + pkg_vec_t * vec;
  11631. + register int i;
  11632. +
  11633. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
  11634. + return NULL;
  11635. + }
  11636. +
  11637. + for(i = 0; i < vec->len; i++)
  11638. + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
  11639. + return vec->pkgs[i];
  11640. + }
  11641. +
  11642. + return NULL;
  11643. +}
  11644. +
  11645. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
  11646. +{
  11647. + abstract_pkg_t * ab_pkg;
  11648. +
  11649. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
  11650. + return NULL;
  11651. + }
  11652. +
  11653. + if (ab_pkg->pkgs) {
  11654. + return ab_pkg->pkgs;
  11655. + } else if (ab_pkg->provided_by) {
  11656. + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
  11657. + if (abpkg != NULL){
  11658. + return abpkg->pkgs;
  11659. + } else {
  11660. + return ab_pkg->pkgs;
  11661. + }
  11662. + } else {
  11663. + return NULL;
  11664. + }
  11665. +}
  11666. +
  11667. +static int pkg_compare_names(const void *p1, const void *p2)
  11668. +{
  11669. + const pkg_t *pkg1 = *(const pkg_t **)p1;
  11670. + const pkg_t *pkg2 = *(const pkg_t **)p2;
  11671. + if (pkg1->name == NULL)
  11672. + return 1;
  11673. + if (pkg2->name == NULL)
  11674. + return -1;
  11675. + return(strcmp(pkg1->name, pkg2->name));
  11676. +}
  11677. +
  11678. +
  11679. +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
  11680. +{
  11681. + int j;
  11682. + const char *name;
  11683. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11684. + pkg_vec_t *all = (pkg_vec_t *)data;
  11685. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11686. + name = pkg_name;
  11687. + if (pkg_vec) {
  11688. + for (j = 0; j < pkg_vec->len; j++) {
  11689. + pkg_t *pkg = pkg_vec->pkgs[j];
  11690. + pkg_vec_insert(all, pkg);
  11691. + }
  11692. + }
  11693. +}
  11694. +
  11695. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
  11696. +{
  11697. + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
  11698. + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
  11699. +}
  11700. +
  11701. +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
  11702. +{
  11703. + const char *name;
  11704. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11705. + pkg_vec_t *all = (pkg_vec_t *)data;
  11706. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11707. + int j;
  11708. + name = pkg_name;
  11709. + if (pkg_vec) {
  11710. + for (j = 0; j < pkg_vec->len; j++) {
  11711. + pkg_t *pkg = pkg_vec->pkgs[j];
  11712. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  11713. + pkg_vec_insert(all, pkg);
  11714. + }
  11715. + }
  11716. + }
  11717. +}
  11718. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
  11719. +{
  11720. + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
  11721. + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
  11722. +}
  11723. +
  11724. +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
  11725. +{
  11726. + int i;
  11727. + pkg_t *pkg;
  11728. + const char *name;
  11729. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11730. + ipkg_conf_t *conf = (ipkg_conf_t *)data;
  11731. + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
  11732. + name = pkg_name;
  11733. + fprintf(stdout, "%s\n", ab_pkg->name);
  11734. + i = 0;
  11735. + if (dependents != NULL)
  11736. + while (dependents [i] != NULL)
  11737. + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
  11738. + dependents = ab_pkg->provided_by->pkgs;
  11739. + i = 0;
  11740. + if (dependents != NULL)
  11741. + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
  11742. + printf ("\tprovided by - %s\n", dependents [i ++]->name);
  11743. + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
  11744. + if (pkg) {
  11745. + i = 0;
  11746. + while (i < pkg->depends_count)
  11747. + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
  11748. + }
  11749. +}
  11750. +void pkg_hash_dump(hash_table_t *hash, void *data)
  11751. +{
  11752. +
  11753. + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
  11754. + hash_table_foreach(hash, pkg_hash_dump_helper, data);
  11755. + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
  11756. +}
  11757. +
  11758. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11759. +{
  11760. + abstract_pkg_t * ab_pkg;
  11761. +
  11762. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
  11763. + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
  11764. +
  11765. + return ab_pkg;
  11766. +}
  11767. +
  11768. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  11769. +{
  11770. + abstract_pkg_t * ab_pkg;
  11771. + int arch_priority;
  11772. +
  11773. + if(!pkg)
  11774. + return pkg;
  11775. +
  11776. + arch_priority = pkg->arch_priority;
  11777. +
  11778. + if (buildDepends(hash, pkg)<0){
  11779. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11780. + return NULL;
  11781. + }
  11782. + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
  11783. +
  11784. + if (set_status) {
  11785. + if (pkg->state_status == SS_INSTALLED) {
  11786. + ab_pkg->state_status = SS_INSTALLED;
  11787. + } else if (pkg->state_status == SS_UNPACKED) {
  11788. + ab_pkg->state_status = SS_UNPACKED;
  11789. + }
  11790. + }
  11791. +
  11792. + if(!ab_pkg->pkgs)
  11793. + ab_pkg->pkgs = pkg_vec_alloc();
  11794. +
  11795. + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
  11796. + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
  11797. + pkg->parent = ab_pkg;
  11798. +
  11799. + if (buildProvides(hash, ab_pkg, pkg)<0){
  11800. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11801. + return NULL;
  11802. + }
  11803. + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
  11804. + if (buildConflicts(hash, pkg)<0){
  11805. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11806. + return NULL;
  11807. + }
  11808. + if (buildReplaces(hash, ab_pkg, pkg)<0) {
  11809. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11810. + return NULL;
  11811. + }
  11812. +
  11813. + buildDependedUponBy(pkg, ab_pkg);
  11814. + return pkg;
  11815. +}
  11816. +
  11817. +/*
  11818. + * this will assume that we've already determined that
  11819. + * the abstract pkg doesn't exist, 'cause we should know these things...
  11820. + */
  11821. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11822. +{
  11823. + abstract_pkg_t * ab_pkg;
  11824. +
  11825. + ab_pkg = abstract_pkg_new();
  11826. + if (ab_pkg == NULL) { return NULL; }
  11827. +
  11828. + ab_pkg->name = strdup(pkg_name);
  11829. + hash_table_insert(hash, pkg_name, ab_pkg);
  11830. +
  11831. + return ab_pkg;
  11832. +}
  11833. +
  11834. +
  11835. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
  11836. +{
  11837. + hash_table_t *file_hash = &conf->file_hash;
  11838. +
  11839. + return hash_table_get(file_hash, file_name);
  11840. +}
  11841. +
  11842. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
  11843. +{
  11844. + hash_table_t *file_hash = &conf->file_hash;
  11845. + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
  11846. + int file_name_len = strlen(file_name);
  11847. +
  11848. + if (file_name[file_name_len -1] == '/')
  11849. + return 0;
  11850. +
  11851. + if (conf->offline_root) {
  11852. + int len = strlen(conf->offline_root);
  11853. + if (strncmp(file_name, conf->offline_root, len) == 0) {
  11854. + file_name += len;
  11855. + }
  11856. + }
  11857. +
  11858. + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
  11859. + hash_table_insert(file_hash, file_name, owning_pkg);
  11860. + if (old_owning_pkg) {
  11861. + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
  11862. + /* mark this package to have its filelist written */
  11863. + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11864. + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11865. + }
  11866. + return 0;
  11867. +}
  11868. +
  11869. +
  11870. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_hash.h busybox-1.17.0/archival/libipkg/pkg_hash.h
  11871. --- busybox-1.17.0.orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
  11872. +++ busybox-1.17.0/archival/libipkg/pkg_hash.h 2010-07-16 14:45:16.418019147 +0200
  11873. @@ -0,0 +1,61 @@
  11874. +/* pkg_hash.h - the itsy package management system
  11875. +
  11876. + Steven M. Ayer
  11877. +
  11878. + Copyright (C) 2002 Compaq Computer Corporation
  11879. +
  11880. + This program is free software; you can redistribute it and/or
  11881. + modify it under the terms of the GNU General Public License as
  11882. + published by the Free Software Foundation; either version 2, or (at
  11883. + your option) any later version.
  11884. +
  11885. + This program is distributed in the hope that it will be useful, but
  11886. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11887. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11888. + General Public License for more details.
  11889. +*/
  11890. +
  11891. +#ifndef PKG_HASH_H
  11892. +#define PKG_HASH_H
  11893. +
  11894. +#include "pkg.h"
  11895. +#include "pkg_vec.h"
  11896. +#include "hash_table.h"
  11897. +
  11898. +
  11899. +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
  11900. +void pkg_hash_deinit(hash_table_t *hash);
  11901. +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
  11902. +
  11903. +void pkg_hash_dump(hash_table_t *hash, void *data);
  11904. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
  11905. +
  11906. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11907. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
  11908. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
  11909. +
  11910. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11911. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
  11912. +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11913. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
  11914. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11915. + const char *pkg_name,
  11916. + const char * version);
  11917. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
  11918. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11919. + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
  11920. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
  11921. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11922. + const char *pkg_name);
  11923. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11924. + const char *pkg_name,
  11925. + pkg_dest_t *dest);
  11926. +
  11927. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
  11928. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
  11929. +
  11930. +/* XXX: shouldn't this go in pkg_vec.[ch]? */
  11931. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11932. +
  11933. +#endif
  11934. +
  11935. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_parse.c busybox-1.17.0/archival/libipkg/pkg_parse.c
  11936. --- busybox-1.17.0.orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
  11937. +++ busybox-1.17.0/archival/libipkg/pkg_parse.c 2010-07-16 14:45:16.475967111 +0200
  11938. @@ -0,0 +1,368 @@
  11939. +/* pkg_parse.c - the itsy package management system
  11940. +
  11941. + Steven M. Ayer
  11942. +
  11943. + Copyright (C) 2002 Compaq Computer Corporation
  11944. +
  11945. + This program is free software; you can redistribute it and/or
  11946. + modify it under the terms of the GNU General Public License as
  11947. + published by the Free Software Foundation; either version 2, or (at
  11948. + your option) any later version.
  11949. +
  11950. + This program is distributed in the hope that it will be useful, but
  11951. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11952. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11953. + General Public License for more details.
  11954. +*/
  11955. +
  11956. +#include "ipkg.h"
  11957. +#include <errno.h>
  11958. +#include <ctype.h>
  11959. +
  11960. +#include "pkg.h"
  11961. +#include "ipkg_utils.h"
  11962. +#include "pkg_parse.h"
  11963. +
  11964. +int alterProvidesLine(char *raw, char *temp);
  11965. +
  11966. +int isGenericFieldType(char * type, char * line)
  11967. +{
  11968. + if(!strncmp(line, type, strlen(type)))
  11969. + return 1;
  11970. + return 0;
  11971. +}
  11972. +
  11973. +char * parseGenericFieldType(char * type, char * raw)
  11974. +{
  11975. + char * field_value = raw + (strlen(type) + 1);
  11976. + return trim_alloc(field_value);
  11977. +}
  11978. +
  11979. +void parseStatus(pkg_t *pkg, char * raw)
  11980. +{
  11981. + char sw_str[64], sf_str[64], ss_str[64];
  11982. +
  11983. + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
  11984. + pkg->state_want = pkg_state_want_from_str(sw_str);
  11985. + pkg->state_flag = pkg_state_flag_from_str(sf_str);
  11986. + pkg->state_status = pkg_state_status_from_str(ss_str);
  11987. +}
  11988. +
  11989. +char ** parseDependsString(char * raw, int * depends_count)
  11990. +{
  11991. + char ** depends = NULL;
  11992. + int line_count = 0;
  11993. + char buff[2048], * dest;
  11994. +
  11995. + while(raw && *raw && !isspace(*raw)) {
  11996. + raw++;
  11997. + }
  11998. +
  11999. + if(line_is_blank(raw)){
  12000. + *depends_count = line_count;
  12001. + return NULL;
  12002. + }
  12003. + while(raw && *raw){
  12004. + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
  12005. +
  12006. + while(isspace(*raw)) raw++;
  12007. +
  12008. + dest = buff;
  12009. + while((*raw != ',') && *raw)
  12010. + *dest++ = *raw++;
  12011. +
  12012. + *dest = '\0';
  12013. + depends[line_count] = trim_alloc(buff);
  12014. + if(depends[line_count] ==NULL)
  12015. + return NULL;
  12016. + line_count++;
  12017. + if(*raw == ',')
  12018. + raw++;
  12019. + }
  12020. + *depends_count = line_count;
  12021. + return depends;
  12022. +}
  12023. +
  12024. +void parseConffiles(pkg_t * pkg, char * raw)
  12025. +{
  12026. + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
  12027. +
  12028. + if(!strncmp(raw, "Conffiles:", 10))
  12029. + raw += strlen("Conffiles:");
  12030. +
  12031. + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
  12032. + conffile_list_append(&pkg->conffiles, file_name, md5sum);
  12033. + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
  12034. + while (*raw && isspace(*raw)) {
  12035. + raw++;
  12036. + }
  12037. + raw += strlen(file_name);
  12038. + while (*raw && isspace(*raw)) {
  12039. + raw++;
  12040. + }
  12041. + raw += strlen(md5sum);
  12042. + }
  12043. +}
  12044. +
  12045. +int parseVersion(pkg_t *pkg, char *raw)
  12046. +{
  12047. + char *colon, *eepochcolon;
  12048. +#ifdef USE_DEBVERSION
  12049. + char *hyphen;
  12050. +#endif
  12051. + unsigned long epoch;
  12052. +
  12053. + if (!*raw) {
  12054. + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
  12055. + return EINVAL;
  12056. + }
  12057. +
  12058. + if (strncmp(raw, "Version:", 8) == 0) {
  12059. + raw += 8;
  12060. + }
  12061. + while (*raw && isspace(*raw)) {
  12062. + raw++;
  12063. + }
  12064. +
  12065. + colon= strchr(raw,':');
  12066. + if (colon) {
  12067. + epoch= strtoul(raw,&eepochcolon,10);
  12068. + if (colon != eepochcolon) {
  12069. + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
  12070. + return EINVAL;
  12071. + }
  12072. + if (!*++colon) {
  12073. + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
  12074. + return EINVAL;
  12075. + }
  12076. + raw= colon;
  12077. + pkg->epoch= epoch;
  12078. + } else {
  12079. + pkg->epoch= 0;
  12080. + }
  12081. +
  12082. + pkg->revision = (char *)"";
  12083. + pkg->familiar_revision = (char *)"";
  12084. +
  12085. + pkg->version= malloc(strlen(raw)+1);
  12086. + if ( pkg->version == NULL ) {
  12087. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12088. + return ENOMEM;
  12089. + }
  12090. + strcpy(pkg->version, raw);
  12091. +
  12092. +#ifdef USE_DEBVERSION
  12093. + hyphen= strrchr(pkg->version,'-');
  12094. +
  12095. + if (hyphen) {
  12096. + *hyphen++= 0;
  12097. + if (strncmp("fam", hyphen, 3) == 0) {
  12098. + pkg->familiar_revision=hyphen+3;
  12099. + hyphen= strrchr(pkg->version,'-');
  12100. + if (hyphen) {
  12101. + *hyphen++= 0;
  12102. + pkg->revision = hyphen;
  12103. + }
  12104. + } else {
  12105. + pkg->revision = hyphen;
  12106. + }
  12107. + }
  12108. +#endif
  12109. +
  12110. +/*
  12111. + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
  12112. + pkg->epoch,
  12113. + pkg->version,
  12114. + pkg->revision,
  12115. + pkg->familiar_revision);
  12116. +*/
  12117. +
  12118. + return 0;
  12119. +}
  12120. +
  12121. +
  12122. +/* This code is needed to insert in first position the keyword for the aligning bug */
  12123. +
  12124. +int alterProvidesLine(char *raw, char *temp)
  12125. +{
  12126. +
  12127. +
  12128. + if (!*raw) {
  12129. + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
  12130. + return -EINVAL;
  12131. + }
  12132. +
  12133. + if ( temp == NULL ) {
  12134. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12135. + return -ENOMEM;
  12136. + }
  12137. +
  12138. + if (strncmp(raw, "Provides:", 9) == 0) {
  12139. + raw += 9;
  12140. + }
  12141. + while (*raw && isspace(*raw)) {
  12142. + raw++;
  12143. + }
  12144. +
  12145. + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
  12146. + while (*raw) {
  12147. + strncat( temp, raw++, 1);
  12148. + }
  12149. + return 0;
  12150. +
  12151. +}
  12152. +
  12153. +/* Some random thoughts from Carl:
  12154. +
  12155. + This function could be considerably simplified if we just kept
  12156. + an array of all the generic string-valued field names, and looped
  12157. + through those looking for a match. Also, these fields could perhaps
  12158. + be stored in the package as an array as well, (or, probably better,
  12159. + as an nv_pair_list_t).
  12160. +
  12161. + Fields which require special parsing or storage, (such as Depends:
  12162. + and Status:) could be handled as they are now.
  12163. +*/
  12164. +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
  12165. + to a dependency list. And, since we already have
  12166. + Depends/Pre-Depends and need to add Conflicts, Recommends, and
  12167. + Enhances, perhaps we could generalize all of these and save some
  12168. + code duplication.
  12169. +*/
  12170. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
  12171. +{
  12172. + int reading_conffiles, reading_description;
  12173. + int pkg_false_provides=1;
  12174. + char ** lines;
  12175. + char * provide=NULL;
  12176. +
  12177. + pkg->src = src;
  12178. + pkg->dest = dest;
  12179. +
  12180. + reading_conffiles = reading_description = 0;
  12181. +
  12182. + for (lines = *raw; *lines; lines++) {
  12183. + /* fprintf(stderr, "PARSING %s\n", *lines);*/
  12184. + if(isGenericFieldType((char *)"Package:", *lines))
  12185. + pkg->name = parseGenericFieldType((char *)"Package", *lines);
  12186. + else if(isGenericFieldType((char *)"Architecture:", *lines))
  12187. + pkg->architecture = parseGenericFieldType((char *)"Architecture", *lines);
  12188. + else if(isGenericFieldType((char *)"Filename:", *lines))
  12189. + pkg->filename = parseGenericFieldType((char *)"Filename", *lines);
  12190. + else if(isGenericFieldType((char *)"Section:", *lines))
  12191. + pkg->section = parseGenericFieldType((char *)"Section", *lines);
  12192. + else if(isGenericFieldType((char *)"MD5sum:", *lines))
  12193. + pkg->md5sum = parseGenericFieldType((char *)"MD5sum", *lines);
  12194. + /* The old ipkg wrote out status files with the wrong case for MD5sum,
  12195. + let's parse it either way */
  12196. + else if(isGenericFieldType((char *)"MD5Sum:", *lines))
  12197. + pkg->md5sum = parseGenericFieldType((char *)"MD5Sum", *lines);
  12198. + else if(isGenericFieldType((char *)"Size:", *lines))
  12199. + pkg->size = parseGenericFieldType((char *)"Size", *lines);
  12200. + else if(isGenericFieldType((char *)"Source:", *lines))
  12201. + pkg->source = parseGenericFieldType((char *)"Source", *lines);
  12202. + else if(isGenericFieldType((char *)"Installed-Size:", *lines))
  12203. + pkg->installed_size = parseGenericFieldType((char *)"Installed-Size", *lines);
  12204. + else if(isGenericFieldType((char *)"Installed-Time:", *lines)) {
  12205. + char *time_str = parseGenericFieldType((char *)"Installed-Time", *lines);
  12206. + pkg->installed_time = strtoul(time_str, NULL, 0);
  12207. + } else if(isGenericFieldType((char *)"Priority:", *lines))
  12208. + pkg->priority = parseGenericFieldType((char *)"Priority", *lines);
  12209. + else if(isGenericFieldType((char *)"Essential:", *lines)) {
  12210. + char *essential_value;
  12211. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12212. + if (strcmp(essential_value, "yes") == 0) {
  12213. + pkg->essential = 1;
  12214. + }
  12215. + free(essential_value);
  12216. + }
  12217. + else if(isGenericFieldType((char *)"Status", *lines))
  12218. + parseStatus(pkg, *lines);
  12219. + else if(isGenericFieldType((char *)"Version", *lines))
  12220. + parseVersion(pkg, *lines);
  12221. + else if(isGenericFieldType((char *)"Maintainer", *lines))
  12222. + pkg->maintainer = parseGenericFieldType((char *)"Maintainer", *lines);
  12223. + else if(isGenericFieldType((char *)"Conffiles", *lines)){
  12224. + parseConffiles(pkg, *lines);
  12225. + reading_conffiles = 1;
  12226. + }
  12227. + else if(isGenericFieldType((char *)"Description", *lines)) {
  12228. + pkg->description = parseGenericFieldType((char *)"Description", *lines);
  12229. + reading_conffiles = 0;
  12230. + reading_description = 1;
  12231. + }
  12232. +
  12233. + else if(isGenericFieldType((char *)"Provides", *lines)){
  12234. +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
  12235. + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
  12236. + if ( alterProvidesLine(*lines,provide) ){
  12237. + return EINVAL;
  12238. + }
  12239. + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
  12240. +/* Let's try to hack a bit here.
  12241. + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
  12242. + in alot of other places. We will remove it before writing down the status database */
  12243. + pkg_false_provides=0;
  12244. + free(provide);
  12245. + }
  12246. +
  12247. + else if(isGenericFieldType((char *)"Depends", *lines))
  12248. + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
  12249. + else if(isGenericFieldType((char *)"Pre-Depends", *lines))
  12250. + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
  12251. + else if(isGenericFieldType((char *)"Recommends", *lines))
  12252. + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
  12253. + else if(isGenericFieldType((char *)"Suggests", *lines))
  12254. + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
  12255. + /* Abhaya: support for conflicts */
  12256. + else if(isGenericFieldType((char *)"Conflicts", *lines))
  12257. + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
  12258. + else if(isGenericFieldType((char *)"Replaces", *lines))
  12259. + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
  12260. + else if(line_is_blank(*lines)) {
  12261. + lines++;
  12262. + break;
  12263. + }
  12264. + else if(**lines == ' '){
  12265. + if(reading_description) {
  12266. + /* we already know it's not blank, so the rest of description */
  12267. + pkg->description = realloc(pkg->description,
  12268. + strlen(pkg->description)
  12269. + + 1 + strlen(*lines) + 1);
  12270. + strcat(pkg->description, "\n");
  12271. + strcat(pkg->description, (*lines));
  12272. + }
  12273. + else if(reading_conffiles)
  12274. + parseConffiles(pkg, *lines);
  12275. + }
  12276. + }
  12277. + *raw = lines;
  12278. +/* If the ipk has not a Provides line, we insert our false line */
  12279. + if ( pkg_false_provides==1)
  12280. + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
  12281. +
  12282. + if (pkg->name) {
  12283. + return 0;
  12284. + } else {
  12285. + return EINVAL;
  12286. + }
  12287. +}
  12288. +
  12289. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
  12290. +{
  12291. + char ** lines;
  12292. +
  12293. + for (lines = *raw; *lines; lines++) {
  12294. + if(isGenericFieldType((char *)"Essential:", *lines)) {
  12295. + char *essential_value;
  12296. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12297. + if (strcmp(essential_value, "yes") == 0) {
  12298. + pkg->essential = 1;
  12299. + }
  12300. + free(essential_value);
  12301. + }
  12302. + }
  12303. + *raw = lines;
  12304. +
  12305. + return 0;
  12306. +}
  12307. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_parse.h busybox-1.17.0/archival/libipkg/pkg_parse.h
  12308. --- busybox-1.17.0.orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
  12309. +++ busybox-1.17.0/archival/libipkg/pkg_parse.h 2010-07-16 14:45:16.517118157 +0200
  12310. @@ -0,0 +1,31 @@
  12311. +/* pkg_parse.h - the itsy package management system
  12312. +
  12313. + Steven M. Ayer
  12314. +
  12315. + Copyright (C) 2002 Compaq Computer Corporation
  12316. +
  12317. + This program is free software; you can redistribute it and/or
  12318. + modify it under the terms of the GNU General Public License as
  12319. + published by the Free Software Foundation; either version 2, or (at
  12320. + your option) any later version.
  12321. +
  12322. + This program is distributed in the hope that it will be useful, but
  12323. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12324. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12325. + General Public License for more details.
  12326. +*/
  12327. +
  12328. +#ifndef PKG_PARSE_H
  12329. +#define PKG_PARSE_H
  12330. +
  12331. +int isGenericFieldType(char * type, char * line);
  12332. +char * parseGenericFieldType(char * type, char * raw);
  12333. +void parseStatus(pkg_t *pkg, char * raw);
  12334. +int parseVersion(pkg_t *pkg, char *raw);
  12335. +char ** parseDependsString(char * raw, int * depends_count);
  12336. +int parseVersion(pkg_t *pkg, char *raw);
  12337. +void parseConffiles(pkg_t * pkg, char * raw);
  12338. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
  12339. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
  12340. +
  12341. +#endif
  12342. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_src.c busybox-1.17.0/archival/libipkg/pkg_src.c
  12343. --- busybox-1.17.0.orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
  12344. +++ busybox-1.17.0/archival/libipkg/pkg_src.c 2010-07-16 14:45:16.558020529 +0200
  12345. @@ -0,0 +1,43 @@
  12346. +/* pkg_src.c - the itsy package management system
  12347. +
  12348. + Carl D. Worth
  12349. +
  12350. + Copyright (C) 2001 University of Southern California
  12351. +
  12352. + This program is free software; you can redistribute it and/or
  12353. + modify it under the terms of the GNU General Public License as
  12354. + published by the Free Software Foundation; either version 2, or (at
  12355. + your option) any later version.
  12356. +
  12357. + This program is distributed in the hope that it will be useful, but
  12358. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12359. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12360. + General Public License for more details.
  12361. +*/
  12362. +
  12363. +#include "ipkg.h"
  12364. +
  12365. +#include "pkg_src.h"
  12366. +#include "str_util.h"
  12367. +
  12368. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
  12369. +{
  12370. + src->gzip = gzip;
  12371. + src->name = str_dup_safe (name);
  12372. + src->value = str_dup_safe (base_url);
  12373. + if (extra_data)
  12374. + src->extra_data = str_dup_safe (extra_data);
  12375. + else
  12376. + src->extra_data = NULL;
  12377. + return 0;
  12378. +}
  12379. +
  12380. +void pkg_src_deinit(pkg_src_t *src)
  12381. +{
  12382. + free (src->name);
  12383. + free (src->value);
  12384. + if (src->extra_data)
  12385. + free (src->extra_data);
  12386. +}
  12387. +
  12388. +
  12389. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_src.h busybox-1.17.0/archival/libipkg/pkg_src.h
  12390. --- busybox-1.17.0.orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
  12391. +++ busybox-1.17.0/archival/libipkg/pkg_src.h 2010-07-16 14:45:16.608020995 +0200
  12392. @@ -0,0 +1,34 @@
  12393. +/* pkg_src.h - the itsy package management system
  12394. +
  12395. + Carl D. Worth
  12396. +
  12397. + Copyright (C) 2001 University of Southern California
  12398. +
  12399. + This program is free software; you can redistribute it and/or
  12400. + modify it under the terms of the GNU General Public License as
  12401. + published by the Free Software Foundation; either version 2, or (at
  12402. + your option) any later version.
  12403. +
  12404. + This program is distributed in the hope that it will be useful, but
  12405. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12406. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12407. + General Public License for more details.
  12408. +*/
  12409. +
  12410. +#ifndef PKG_SRC_H
  12411. +#define PKG_SRC_H
  12412. +
  12413. +#include "nv_pair.h"
  12414. +
  12415. +typedef struct
  12416. +{
  12417. + char *name;
  12418. + char *value;
  12419. + char *extra_data;
  12420. + int gzip;
  12421. +} pkg_src_t;
  12422. +
  12423. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
  12424. +void pkg_src_deinit(pkg_src_t *src);
  12425. +
  12426. +#endif
  12427. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_src_list.c busybox-1.17.0/archival/libipkg/pkg_src_list.c
  12428. --- busybox-1.17.0.orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
  12429. +++ busybox-1.17.0/archival/libipkg/pkg_src_list.c 2010-07-16 14:45:16.656033705 +0200
  12430. @@ -0,0 +1,75 @@
  12431. +/* pkg_src_list.c - the itsy package management system
  12432. +
  12433. + Carl D. Worth
  12434. +
  12435. + Copyright (C) 2001 University of Southern California
  12436. +
  12437. + This program is free software; you can redistribute it and/or
  12438. + modify it under the terms of the GNU General Public License as
  12439. + published by the Free Software Foundation; either version 2, or (at
  12440. + your option) any later version.
  12441. +
  12442. + This program is distributed in the hope that it will be useful, but
  12443. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12444. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12445. + General Public License for more details.
  12446. +*/
  12447. +
  12448. +#include "ipkg.h"
  12449. +
  12450. +#include "pkg_src_list.h"
  12451. +#include "void_list.h"
  12452. +
  12453. +int pkg_src_list_init(pkg_src_list_t *list)
  12454. +{
  12455. + return void_list_init((void_list_t *) list);
  12456. +}
  12457. +
  12458. +void pkg_src_list_deinit(pkg_src_list_t *list)
  12459. +{
  12460. + pkg_src_list_elt_t *iter;
  12461. + pkg_src_t *pkg_src;
  12462. +
  12463. + for (iter = list->head; iter; iter = iter->next) {
  12464. + pkg_src = iter->data;
  12465. + pkg_src_deinit(pkg_src);
  12466. +
  12467. + /* malloced in pkg_src_list_append */
  12468. + free(pkg_src);
  12469. + iter->data = NULL;
  12470. + }
  12471. + void_list_deinit((void_list_t *) list);
  12472. +}
  12473. +
  12474. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
  12475. + const char *name, const char *base_url, const char *extra_data,
  12476. + int gzip)
  12477. +{
  12478. + int err;
  12479. +
  12480. + /* freed in pkg_src_list_deinit */
  12481. + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
  12482. +
  12483. + if (pkg_src == NULL) {
  12484. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12485. + return NULL;
  12486. + }
  12487. + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
  12488. +
  12489. + err = void_list_append((void_list_t *) list, pkg_src);
  12490. + if (err) {
  12491. + return NULL;
  12492. + }
  12493. +
  12494. + return pkg_src;
  12495. +}
  12496. +
  12497. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
  12498. +{
  12499. + return void_list_push((void_list_t *) list, data);
  12500. +}
  12501. +
  12502. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
  12503. +{
  12504. + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
  12505. +}
  12506. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_src_list.h busybox-1.17.0/archival/libipkg/pkg_src_list.h
  12507. --- busybox-1.17.0.orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
  12508. +++ busybox-1.17.0/archival/libipkg/pkg_src_list.h 2010-07-16 14:45:16.705865996 +0200
  12509. @@ -0,0 +1,57 @@
  12510. +/* pkg_src_list.h - the itsy package management system
  12511. +
  12512. + Carl D. Worth
  12513. +
  12514. + Copyright (C) 2001 University of Southern California
  12515. +
  12516. + This program is free software; you can redistribute it and/or
  12517. + modify it under the terms of the GNU General Public License as
  12518. + published by the Free Software Foundation; either version 2, or (at
  12519. + your option) any later version.
  12520. +
  12521. + This program is distributed in the hope that it will be useful, but
  12522. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12523. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12524. + General Public License for more details.
  12525. +*/
  12526. +
  12527. +#ifndef PKG_SRC_LIST_H
  12528. +#define PKG_SRC_LIST_H
  12529. +
  12530. +#include "pkg_src.h"
  12531. +
  12532. +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
  12533. +struct pkg_src_list_elt
  12534. +{
  12535. + pkg_src_list_elt_t *next;
  12536. + pkg_src_t *data;
  12537. +};
  12538. +
  12539. +typedef struct pkg_src_list pkg_src_list_t;
  12540. +struct pkg_src_list
  12541. +{
  12542. + pkg_src_list_elt_t pre_head;
  12543. + pkg_src_list_elt_t *head;
  12544. + pkg_src_list_elt_t *tail;
  12545. +};
  12546. +
  12547. +static inline int pkg_src_list_empty(pkg_src_list_t *list)
  12548. +{
  12549. + if (list->head == NULL)
  12550. + return 1;
  12551. + else
  12552. + return 0;
  12553. +}
  12554. +
  12555. +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
  12556. +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
  12557. +
  12558. +int pkg_src_list_init(pkg_src_list_t *list);
  12559. +void pkg_src_list_deinit(pkg_src_list_t *list);
  12560. +
  12561. +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);
  12562. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
  12563. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
  12564. +
  12565. +#endif
  12566. +
  12567. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_vec.c busybox-1.17.0/archival/libipkg/pkg_vec.c
  12568. --- busybox-1.17.0.orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
  12569. +++ busybox-1.17.0/archival/libipkg/pkg_vec.c 2010-07-16 14:45:16.745865955 +0200
  12570. @@ -0,0 +1,231 @@
  12571. +/* pkg_vec.c - the itsy package management system
  12572. +
  12573. + Steven M. Ayer
  12574. +
  12575. + Copyright (C) 2002 Compaq Computer Corporation
  12576. +
  12577. + This program is free software; you can redistribute it and/or
  12578. + modify it under the terms of the GNU General Public License as
  12579. + published by the Free Software Foundation; either version 2, or (at
  12580. + your option) any later version.
  12581. +
  12582. + This program is distributed in the hope that it will be useful, but
  12583. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12584. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12585. + General Public License for more details.
  12586. +*/
  12587. +
  12588. +#include <stdlib.h>
  12589. +#include <fnmatch.h>
  12590. +#include "libbb.h"
  12591. +#include "xregex.h"
  12592. +#include "ipkg.h"
  12593. +#include "pkg.h"
  12594. +
  12595. +pkg_vec_t * pkg_vec_alloc(void)
  12596. +{
  12597. + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
  12598. + if (!vec) {
  12599. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12600. + return NULL;
  12601. + }
  12602. + vec->pkgs = NULL;
  12603. + vec->len = 0;
  12604. +
  12605. + return vec;
  12606. +}
  12607. +
  12608. +void pkg_vec_free(pkg_vec_t *vec)
  12609. +{
  12610. + free(vec->pkgs);
  12611. + free(vec);
  12612. +}
  12613. +
  12614. +/*
  12615. + * assumption: all names in a vector are identical
  12616. + * assumption: all version strings are trimmed,
  12617. + * so identical versions have identical version strings,
  12618. + * implying identical packages; let's marry these
  12619. + */
  12620. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  12621. +{
  12622. + int i;
  12623. + int found = 0;
  12624. +
  12625. + /* look for a duplicate pkg by name, version, and architecture */
  12626. + for (i = 0; i < vec->len; i++){
  12627. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
  12628. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
  12629. + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
  12630. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12631. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12632. + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
  12633. + found = 1;
  12634. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
  12635. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12636. + break;
  12637. + }
  12638. + }
  12639. +
  12640. + /* we didn't find one, add it */
  12641. + if (!found){
  12642. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
  12643. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12644. +
  12645. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12646. + vec->pkgs[vec->len] = pkg;
  12647. + vec->len++;
  12648. + return pkg;
  12649. + }
  12650. + /* update the one that we have */
  12651. + else {
  12652. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
  12653. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12654. + if (set_status) {
  12655. + /* this is from the status file, so need to merge with existing database */
  12656. + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
  12657. + pkg_merge(vec->pkgs[i], pkg, set_status);
  12658. + /* XXX: CLEANUP: It's not so polite to free something here
  12659. + that was passed in from above. */
  12660. + pkg_deinit(pkg);
  12661. + free(pkg);
  12662. + } else {
  12663. + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
  12664. + /* just overwrite the old one */
  12665. + pkg_deinit(vec->pkgs[i]);
  12666. + free(vec->pkgs[i]);
  12667. + vec->pkgs[i] = pkg;
  12668. + }
  12669. + return vec->pkgs[i];
  12670. + }
  12671. +}
  12672. +
  12673. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
  12674. +{
  12675. + int i;
  12676. + int found = 0;
  12677. +
  12678. + /* look for a duplicate pkg by name, version, and architecture */
  12679. + for (i = 0; i < vec->len; i++)
  12680. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12681. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12682. + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
  12683. + found = 1;
  12684. + break;
  12685. + }
  12686. +
  12687. + /* we didn't find one, add it */
  12688. + if(!found){
  12689. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12690. + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
  12691. + vec->len++;
  12692. + }
  12693. +}
  12694. +
  12695. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
  12696. +{
  12697. + int i;
  12698. + for (i = 0; i < vec->len; i++)
  12699. + if (vec->pkgs[i] == apkg)
  12700. + return 1;
  12701. + return 0;
  12702. +}
  12703. +
  12704. +typedef int (*compare_fcn_t)(const void *, const void *);
  12705. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
  12706. +{
  12707. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12708. +}
  12709. +
  12710. +int pkg_vec_clear_marks(pkg_vec_t *vec)
  12711. +{
  12712. + int npkgs = vec->len;
  12713. + int i;
  12714. + for (i = 0; i < npkgs; i++) {
  12715. + pkg_t *pkg = vec->pkgs[i];
  12716. + pkg->state_flag &= ~SF_MARKED;
  12717. + }
  12718. + return 0;
  12719. +}
  12720. +
  12721. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
  12722. +{
  12723. + int matching_count = 0;
  12724. + pkg_t **pkgs = vec->pkgs;
  12725. + int npkgs = vec->len;
  12726. + int i;
  12727. + for (i = 0; i < npkgs; i++) {
  12728. + pkg_t *pkg = pkgs[i];
  12729. + if (fnmatch(pattern, pkg->name, 0)==0) {
  12730. + pkg->state_flag |= SF_MARKED;
  12731. + matching_count++;
  12732. + }
  12733. + }
  12734. + return matching_count;
  12735. +}
  12736. +
  12737. +
  12738. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
  12739. +{
  12740. + abstract_pkg_vec_t * vec ;
  12741. + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
  12742. + if (!vec) {
  12743. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12744. + return NULL;
  12745. + }
  12746. + vec->pkgs = NULL;
  12747. + vec->len = 0;
  12748. +
  12749. + return vec;
  12750. +}
  12751. +
  12752. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
  12753. +{
  12754. + free(vec->pkgs);
  12755. + free(vec);
  12756. +}
  12757. +
  12758. +/*
  12759. + * assumption: all names in a vector are unique
  12760. + */
  12761. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
  12762. +{
  12763. + int i;
  12764. +
  12765. + /* look for a duplicate pkg by name */
  12766. + for(i = 0; i < vec->len; i++)
  12767. + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12768. + break;
  12769. +
  12770. + /* we didn't find one, add it */
  12771. + if(i == vec->len){
  12772. + vec->pkgs =
  12773. + (abstract_pkg_t **)
  12774. + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
  12775. + vec->pkgs[vec->len] = pkg;
  12776. + vec->len++;
  12777. + }
  12778. +}
  12779. +
  12780. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
  12781. +{
  12782. + if (vec->len > i)
  12783. + return vec->pkgs[i];
  12784. + else
  12785. + return NULL;
  12786. +}
  12787. +
  12788. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
  12789. +{
  12790. + int i;
  12791. + for (i = 0; i < vec->len; i++)
  12792. + if (vec->pkgs[i] == apkg)
  12793. + return 1;
  12794. + return 0;
  12795. +}
  12796. +
  12797. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
  12798. +{
  12799. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12800. +}
  12801. +
  12802. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_vec.h busybox-1.17.0/archival/libipkg/pkg_vec.h
  12803. --- busybox-1.17.0.orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
  12804. +++ busybox-1.17.0/archival/libipkg/pkg_vec.h 2010-07-16 14:45:16.796544368 +0200
  12805. @@ -0,0 +1,62 @@
  12806. +/* pkg_vec.h - the itsy package management system
  12807. +
  12808. + Steven M. Ayer
  12809. +
  12810. + Copyright (C) 2002 Compaq Computer Corporation
  12811. +
  12812. + This program is free software; you can redistribute it and/or
  12813. + modify it under the terms of the GNU General Public License as
  12814. + published by the Free Software Foundation; either version 2, or (at
  12815. + your option) any later version.
  12816. +
  12817. + This program is distributed in the hope that it will be useful, but
  12818. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12819. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12820. + General Public License for more details.
  12821. +*/
  12822. +
  12823. +#ifndef PKG_VEC_H
  12824. +#define PKG_VEC_H
  12825. +
  12826. +typedef struct pkg pkg_t;
  12827. +typedef struct abstract_pkg abstract_pkg_t;
  12828. +
  12829. +struct pkg_vec
  12830. +{
  12831. + pkg_t **pkgs;
  12832. + int len;
  12833. +};
  12834. +typedef struct pkg_vec pkg_vec_t;
  12835. +
  12836. +struct abstract_pkg_vec
  12837. +{
  12838. + abstract_pkg_t **pkgs;
  12839. + int len;
  12840. +};
  12841. +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
  12842. +
  12843. +
  12844. +pkg_vec_t * pkg_vec_alloc(void);
  12845. +void pkg_vec_free(pkg_vec_t *vec);
  12846. +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
  12847. +
  12848. +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
  12849. +/* pkg_vec_insert_merge: might munge pkg.
  12850. +* returns the pkg that is in the pkg graph */
  12851. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
  12852. +/* this one never munges pkg */
  12853. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
  12854. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
  12855. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
  12856. +
  12857. +int pkg_vec_clear_marks(pkg_vec_t *vec);
  12858. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
  12859. +
  12860. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
  12861. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
  12862. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
  12863. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
  12864. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
  12865. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
  12866. +#endif
  12867. +
  12868. diff -Nur busybox-1.17.0.orig/archival/libipkg/sprintf_alloc.h busybox-1.17.0/archival/libipkg/sprintf_alloc.h
  12869. --- busybox-1.17.0.orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
  12870. +++ busybox-1.17.0/archival/libipkg/sprintf_alloc.h 2010-07-16 14:45:16.846154965 +0200
  12871. @@ -0,0 +1,25 @@
  12872. +/* sprintf_alloca.c -- like sprintf with memory allocation
  12873. +
  12874. + Carl D. Worth
  12875. +
  12876. + Copyright (C) 2001 University of Southern California
  12877. +
  12878. + This program is free software; you can redistribute it and/or modify
  12879. + it under the terms of the GNU General Public License as published by
  12880. + the Free Software Foundation; either version 2, or (at your option)
  12881. + any later version.
  12882. +
  12883. + This program is distributed in the hope that it will be useful,
  12884. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  12885. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12886. + GNU General Public License for more details.
  12887. +*/
  12888. +
  12889. +#ifndef SPRINTF_ALLOC_H
  12890. +#define SPRINTF_ALLOC_H
  12891. +
  12892. +#include "libbb.h"
  12893. +
  12894. +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
  12895. +
  12896. +#endif
  12897. diff -Nur busybox-1.17.0.orig/archival/libipkg/str_list.c busybox-1.17.0/archival/libipkg/str_list.c
  12898. --- busybox-1.17.0.orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
  12899. +++ busybox-1.17.0/archival/libipkg/str_list.c 2010-07-16 14:45:16.905860157 +0200
  12900. @@ -0,0 +1,76 @@
  12901. +/* str_list.c - the itsy package management system
  12902. +
  12903. + Carl D. Worth
  12904. +
  12905. + Copyright (C) 2001 University of Southern California
  12906. +
  12907. + This program is free software; you can redistribute it and/or
  12908. + modify it under the terms of the GNU General Public License as
  12909. + published by the Free Software Foundation; either version 2, or (at
  12910. + your option) any later version.
  12911. +
  12912. + This program is distributed in the hope that it will be useful, but
  12913. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12914. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12915. + General Public License for more details.
  12916. +*/
  12917. +
  12918. +#include "ipkg.h"
  12919. +
  12920. +#include "str_list.h"
  12921. +
  12922. +int str_list_elt_init(str_list_elt_t *elt, char *data)
  12923. +{
  12924. + return void_list_elt_init((void_list_elt_t *) elt, data);
  12925. +}
  12926. +
  12927. +void str_list_elt_deinit(str_list_elt_t *elt)
  12928. +{
  12929. + void_list_elt_deinit((void_list_elt_t *) elt);
  12930. +}
  12931. +
  12932. +str_list_t *str_list_alloc(void)
  12933. +{
  12934. + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
  12935. + if (list)
  12936. + str_list_init(list);
  12937. + return list;
  12938. +}
  12939. +
  12940. +int str_list_init(str_list_t *list)
  12941. +{
  12942. + return void_list_init((void_list_t *) list);
  12943. +}
  12944. +
  12945. +void str_list_deinit(str_list_t *list)
  12946. +{
  12947. + void_list_deinit((void_list_t *) list);
  12948. +}
  12949. +
  12950. +int str_list_append(str_list_t *list, char *data)
  12951. +{
  12952. + return void_list_append((void_list_t *) list, data);
  12953. +}
  12954. +
  12955. +int str_list_push(str_list_t *list, char *data)
  12956. +{
  12957. + return void_list_push((void_list_t *) list, data);
  12958. +}
  12959. +
  12960. +str_list_elt_t *str_list_pop(str_list_t *list)
  12961. +{
  12962. + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
  12963. +}
  12964. +
  12965. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
  12966. +{
  12967. + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
  12968. + (void_list_elt_t **) iter);
  12969. +}
  12970. +
  12971. +char *str_list_remove_elt(str_list_t *list, const char *target_str)
  12972. +{
  12973. + return (char *)void_list_remove_elt((void_list_t *) list,
  12974. + (void *)target_str,
  12975. + (void_list_cmp_t)strcmp);
  12976. +}
  12977. diff -Nur busybox-1.17.0.orig/archival/libipkg/str_list.h busybox-1.17.0/archival/libipkg/str_list.h
  12978. --- busybox-1.17.0.orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
  12979. +++ busybox-1.17.0/archival/libipkg/str_list.h 2010-07-16 14:45:16.945860092 +0200
  12980. @@ -0,0 +1,51 @@
  12981. +/* str_list.h - the itsy package management system
  12982. +
  12983. + Carl D. Worth
  12984. +
  12985. + Copyright (C) 2001 University of Southern California
  12986. +
  12987. + This program is free software; you can redistribute it and/or
  12988. + modify it under the terms of the GNU General Public License as
  12989. + published by the Free Software Foundation; either version 2, or (at
  12990. + your option) any later version.
  12991. +
  12992. + This program is distributed in the hope that it will be useful, but
  12993. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12994. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12995. + General Public License for more details.
  12996. +*/
  12997. +
  12998. +#ifndef STR_LIST_H
  12999. +#define STR_LIST_H
  13000. +
  13001. +#include "void_list.h"
  13002. +
  13003. +typedef struct str_list_elt str_list_elt_t;
  13004. +struct str_list_elt
  13005. +{
  13006. + str_list_elt_t *next;
  13007. + char *data;
  13008. +};
  13009. +
  13010. +typedef struct xstr_list str_list_t;
  13011. +struct xstr_list
  13012. +{
  13013. + str_list_elt_t pre_head;
  13014. + str_list_elt_t *head;
  13015. + str_list_elt_t *tail;
  13016. +};
  13017. +
  13018. +int str_list_elt_init(str_list_elt_t *elt, char *data);
  13019. +void str_list_elt_deinit(str_list_elt_t *elt);
  13020. +
  13021. +str_list_t *str_list_alloc(void);
  13022. +int str_list_init(str_list_t *list);
  13023. +void str_list_deinit(str_list_t *list);
  13024. +
  13025. +int str_list_append(str_list_t *list, char *data);
  13026. +int str_list_push(str_list_t *list, char *data);
  13027. +str_list_elt_t *str_list_pop(str_list_t *list);
  13028. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
  13029. +char *str_list_remove_elt(str_list_t *list, const char *target_str);
  13030. +
  13031. +#endif
  13032. diff -Nur busybox-1.17.0.orig/archival/libipkg/str_util.c busybox-1.17.0/archival/libipkg/str_util.c
  13033. --- busybox-1.17.0.orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
  13034. +++ busybox-1.17.0/archival/libipkg/str_util.c 2010-07-16 14:45:16.996024988 +0200
  13035. @@ -0,0 +1,69 @@
  13036. +/* str_utils.c - the itsy package management system
  13037. +
  13038. + Carl D. Worth
  13039. +
  13040. + Copyright (C) 2001 University of Southern California
  13041. +
  13042. + This program is free software; you can redistribute it and/or
  13043. + modify it under the terms of the GNU General Public License as
  13044. + published by the Free Software Foundation; either version 2, or (at
  13045. + your option) any later version.
  13046. +
  13047. + This program is distributed in the hope that it will be useful, but
  13048. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13049. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13050. + General Public License for more details.
  13051. +*/
  13052. +
  13053. +#include "ipkg.h"
  13054. +
  13055. +int str_starts_with(const char *str, const char *prefix);
  13056. +int str_ends_with(const char *str, const char *suffix);
  13057. +int str_chomp(char *str);
  13058. +int str_toupper(char *str);
  13059. +char *str_dup_safe(const char *str);
  13060. +
  13061. +int str_starts_with(const char *str, const char *prefix)
  13062. +{
  13063. + return (strncmp(str, prefix, strlen(prefix)) == 0);
  13064. +}
  13065. +
  13066. +int str_ends_with(const char *str, const char *suffix)
  13067. +{
  13068. + int suffix_len;
  13069. + int str_len;
  13070. +
  13071. + str_len = strlen(str);
  13072. + suffix_len = strlen(suffix);
  13073. +
  13074. + if (str_len < suffix_len) {
  13075. + return 0;
  13076. + }
  13077. +
  13078. + return (strcmp(str + str_len - suffix_len, suffix) == 0);
  13079. +}
  13080. +
  13081. +int str_chomp(char *str)
  13082. +{
  13083. + if (str[strlen(str) - 1] == '\n') {
  13084. + str[strlen(str) - 1] = '\0';
  13085. + return 1;
  13086. + }
  13087. + return 0;
  13088. +}
  13089. +
  13090. +int str_toupper(char *str)
  13091. +{
  13092. + while (*str) {
  13093. + *str = toupper(*str);
  13094. + str++;
  13095. + }
  13096. +
  13097. + return 0;
  13098. +}
  13099. +
  13100. +char *str_dup_safe(const char *str)
  13101. +{
  13102. + return str ? strdup(str) : NULL;
  13103. +}
  13104. +
  13105. diff -Nur busybox-1.17.0.orig/archival/libipkg/str_util.h busybox-1.17.0/archival/libipkg/str_util.h
  13106. --- busybox-1.17.0.orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
  13107. +++ busybox-1.17.0/archival/libipkg/str_util.h 2010-07-16 14:45:17.046338652 +0200
  13108. @@ -0,0 +1,27 @@
  13109. +/* str_utils.h - the itsy package management system
  13110. +
  13111. + Carl D. Worth
  13112. +
  13113. + Copyright (C) 2001 University of Southern California
  13114. +
  13115. + This program is free software; you can redistribute it and/or
  13116. + modify it under the terms of the GNU General Public License as
  13117. + published by the Free Software Foundation; either version 2, or (at
  13118. + your option) any later version.
  13119. +
  13120. + This program is distributed in the hope that it will be useful, but
  13121. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13122. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13123. + General Public License for more details.
  13124. +*/
  13125. +
  13126. +#ifndef STR_UTILS_H
  13127. +#define STR_UTILS_H
  13128. +
  13129. +int str_starts_with(const char *str, const char *prefix);
  13130. +int str_ends_with(const char *str, const char *suffix);
  13131. +int str_chomp(char *str);
  13132. +int str_toupper(char *str);
  13133. +char *str_dup_safe(const char *str);
  13134. +
  13135. +#endif
  13136. diff -Nur busybox-1.17.0.orig/archival/libipkg/user.c busybox-1.17.0/archival/libipkg/user.c
  13137. --- busybox-1.17.0.orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
  13138. +++ busybox-1.17.0/archival/libipkg/user.c 2010-07-16 14:45:17.106069026 +0200
  13139. @@ -0,0 +1,49 @@
  13140. +/* user.c - the itsy package management system
  13141. +
  13142. + Jamey Hicks
  13143. +
  13144. + Copyright (C) 2002 Hewlett Packard Company
  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. +#include <stdio.h>
  13159. +#include <stdarg.h>
  13160. +#include "libbb.h"
  13161. +#include "file_util.h"
  13162. +#include "str_util.h"
  13163. +#include "libipkg.h"
  13164. +
  13165. +char *get_user_response(const char *format, ...);
  13166. +static char *question = NULL;
  13167. +static int question_len = 255;
  13168. +
  13169. +char *get_user_response(const char *format, ...)
  13170. +{
  13171. + int len = question_len;
  13172. + va_list ap;
  13173. + char *response;
  13174. + va_start(ap, format);
  13175. +
  13176. + do {
  13177. + if (question == NULL || len > question_len) {
  13178. + question = realloc(question, len + 1);
  13179. + question_len = len;
  13180. + }
  13181. + len = vsnprintf(question,question_len,format,ap);
  13182. + } while (len > question_len);
  13183. + response = strdup(ipkg_cb_response(question));
  13184. + str_chomp(response);
  13185. + str_tolower(response);
  13186. +
  13187. + return response;
  13188. +}
  13189. diff -Nur busybox-1.17.0.orig/archival/libipkg/user.h busybox-1.17.0/archival/libipkg/user.h
  13190. --- busybox-1.17.0.orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
  13191. +++ busybox-1.17.0/archival/libipkg/user.h 2010-07-16 14:45:17.146036094 +0200
  13192. @@ -0,0 +1,23 @@
  13193. +/* user.c - the itsy package management system
  13194. +
  13195. + Jamey Hicks
  13196. +
  13197. + Copyright (C) 2002 Hewlett Packard Company
  13198. + Copyright (C) 2001 University of Southern California
  13199. +
  13200. + This program is free software; you can redistribute it and/or
  13201. + modify it under the terms of the GNU General Public License as
  13202. + published by the Free Software Foundation; either version 2, or (at
  13203. + your option) any later version.
  13204. +
  13205. + This program is distributed in the hope that it will be useful, but
  13206. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13207. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13208. + General Public License for more details.
  13209. +*/
  13210. +
  13211. +#include <stdio.h>
  13212. +#include <stdarg.h>
  13213. +
  13214. +char *get_user_response(const char *format, ...);
  13215. +
  13216. diff -Nur busybox-1.17.0.orig/archival/libipkg/void_list.c busybox-1.17.0/archival/libipkg/void_list.c
  13217. --- busybox-1.17.0.orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
  13218. +++ busybox-1.17.0/archival/libipkg/void_list.c 2010-07-16 14:45:17.206049751 +0200
  13219. @@ -0,0 +1,194 @@
  13220. +/* void_list.c - the itsy package management system
  13221. +
  13222. + Carl D. Worth
  13223. +
  13224. + Copyright (C) 2001 University of Southern California
  13225. +
  13226. + This program is free software; you can redistribute it and/or
  13227. + modify it under the terms of the GNU General Public License as
  13228. + published by the Free Software Foundation; either version 2, or (at
  13229. + your option) any later version.
  13230. +
  13231. + This program is distributed in the hope that it will be useful, but
  13232. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13233. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13234. + General Public License for more details.
  13235. +*/
  13236. +
  13237. +#include "ipkg.h"
  13238. +#include <errno.h>
  13239. +
  13240. +#include "void_list.h"
  13241. +
  13242. +int void_list_elt_init(void_list_elt_t *elt, void *data)
  13243. +{
  13244. + elt->next = NULL;
  13245. + elt->data = data;
  13246. +
  13247. + return 0;
  13248. +}
  13249. +
  13250. +void void_list_elt_deinit(void_list_elt_t *elt)
  13251. +{
  13252. + void_list_elt_init(elt, NULL);
  13253. +}
  13254. +
  13255. +int void_list_init(void_list_t *list)
  13256. +{
  13257. + void_list_elt_init(&list->pre_head, NULL);
  13258. + list->head = NULL;
  13259. + list->pre_head.next = list->head;
  13260. + list->tail = NULL;
  13261. +
  13262. + return 0;
  13263. +}
  13264. +
  13265. +void void_list_deinit(void_list_t *list)
  13266. +{
  13267. + void_list_elt_t *elt;
  13268. +
  13269. + while (list->head) {
  13270. + elt = void_list_pop(list);
  13271. + void_list_elt_deinit(elt);
  13272. + /* malloced in void_list_append */
  13273. + free(elt);
  13274. + }
  13275. +}
  13276. +
  13277. +int void_list_append(void_list_t *list, void *data)
  13278. +{
  13279. + void_list_elt_t *elt;
  13280. +
  13281. + /* freed in void_list_deinit */
  13282. + elt = malloc(sizeof(void_list_elt_t));
  13283. + if (elt == NULL) {
  13284. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13285. + return ENOMEM;
  13286. + }
  13287. +
  13288. + void_list_elt_init(elt, data);
  13289. +
  13290. + if (list->tail) {
  13291. + list->tail->next = elt;
  13292. + list->tail = elt;
  13293. + } else {
  13294. + list->head = elt;
  13295. + list->pre_head.next = list->head;
  13296. + list->tail = elt;
  13297. + }
  13298. +
  13299. + return 0;
  13300. +}
  13301. +
  13302. +int void_list_push(void_list_t *list, void *data)
  13303. +{
  13304. + void_list_elt_t *elt;
  13305. +
  13306. + elt = malloc(sizeof(void_list_elt_t));
  13307. + if (elt == NULL) {
  13308. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13309. + return ENOMEM;
  13310. + }
  13311. +
  13312. + void_list_elt_init(elt, data);
  13313. +
  13314. + elt->next = list->head;
  13315. + list->head->next = elt;
  13316. + if (list->tail == NULL) {
  13317. + list->tail = list->head;
  13318. + }
  13319. +
  13320. + return 0;
  13321. +}
  13322. +
  13323. +void_list_elt_t *void_list_pop(void_list_t *list)
  13324. +{
  13325. + void_list_elt_t *elt;
  13326. +
  13327. + elt = list->head;
  13328. +
  13329. + if (list->head) {
  13330. + list->head = list->head->next;
  13331. + list->pre_head.next = list->head;
  13332. + if (list->head == NULL) {
  13333. + list->tail = NULL;
  13334. + }
  13335. + }
  13336. +
  13337. + return elt;
  13338. +}
  13339. +
  13340. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
  13341. +{
  13342. + void_list_elt_t *prior;
  13343. + void_list_elt_t *old_elt;
  13344. + void *old_data;
  13345. +
  13346. + old_elt = *iter;
  13347. + old_data = old_elt->data;
  13348. +
  13349. + if (old_elt == list->head) {
  13350. + prior = &list->pre_head;
  13351. + void_list_pop(list);
  13352. + } else {
  13353. + for (prior = list->head; prior; prior = prior->next) {
  13354. + if (prior->next == old_elt) {
  13355. + break;
  13356. + }
  13357. + }
  13358. + if (prior == NULL || prior->next != old_elt) {
  13359. + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
  13360. + return NULL;
  13361. + }
  13362. + prior->next = old_elt->next;
  13363. +
  13364. + if (old_elt == list->tail) {
  13365. + list->tail = prior;
  13366. + }
  13367. + }
  13368. +
  13369. + void_list_elt_deinit(old_elt);
  13370. + *iter = prior;
  13371. +
  13372. + return old_data;
  13373. +}
  13374. +
  13375. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13376. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
  13377. +{
  13378. + void_list_elt_t *prior;
  13379. + void_list_elt_t *old_elt = NULL;
  13380. + void *old_data = NULL;
  13381. +
  13382. + /* first element */
  13383. + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
  13384. + old_elt = list->head;
  13385. + old_data = list->head->data;
  13386. + void_list_pop(list);
  13387. + } else {
  13388. + int found = 0;
  13389. + for (prior = list->head; prior && prior->next; prior = prior->next) {
  13390. + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
  13391. + old_elt = prior->next;
  13392. + old_data = old_elt->data;
  13393. + found = 1;
  13394. + break;
  13395. + }
  13396. + }
  13397. + if (!found) {
  13398. + return NULL;
  13399. + }
  13400. + prior->next = old_elt->next;
  13401. +
  13402. + if (old_elt == list->tail) {
  13403. + list->tail = prior;
  13404. + }
  13405. + }
  13406. + if (old_elt)
  13407. + void_list_elt_deinit(old_elt);
  13408. +
  13409. + if (old_data)
  13410. + return old_data;
  13411. + else
  13412. + return NULL;
  13413. +}
  13414. diff -Nur busybox-1.17.0.orig/archival/libipkg/void_list.h busybox-1.17.0/archival/libipkg/void_list.h
  13415. --- busybox-1.17.0.orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
  13416. +++ busybox-1.17.0/archival/libipkg/void_list.h 2010-07-16 14:45:17.247118189 +0200
  13417. @@ -0,0 +1,59 @@
  13418. +/* void_list.h - the itsy package management system
  13419. +
  13420. + Carl D. Worth
  13421. +
  13422. + Copyright (C) 2001 University of Southern California
  13423. +
  13424. + This program is free software; you can redistribute it and/or
  13425. + modify it under the terms of the GNU General Public License as
  13426. + published by the Free Software Foundation; either version 2, or (at
  13427. + your option) any later version.
  13428. +
  13429. + This program is distributed in the hope that it will be useful, but
  13430. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13431. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13432. + General Public License for more details.
  13433. +*/
  13434. +
  13435. +#ifndef VOID_LIST_H
  13436. +#define VOID_LIST_H
  13437. +
  13438. +typedef struct void_list_elt void_list_elt_t;
  13439. +struct void_list_elt
  13440. +{
  13441. + void_list_elt_t *next;
  13442. + void *data;
  13443. +};
  13444. +
  13445. +typedef struct void_list void_list_t;
  13446. +struct void_list
  13447. +{
  13448. + void_list_elt_t pre_head;
  13449. + void_list_elt_t *head;
  13450. + void_list_elt_t *tail;
  13451. +};
  13452. +
  13453. +static inline int void_list_empty(void_list_t *list)
  13454. +{
  13455. + if (list->head == NULL)
  13456. + return 1;
  13457. + else
  13458. + return 0;
  13459. +}
  13460. +
  13461. +int void_list_elt_init(void_list_elt_t *elt, void *data);
  13462. +void void_list_elt_deinit(void_list_elt_t *elt);
  13463. +
  13464. +int void_list_init(void_list_t *list);
  13465. +void void_list_deinit(void_list_t *list);
  13466. +
  13467. +int void_list_append(void_list_t *list, void *data);
  13468. +int void_list_push(void_list_t *list, void *data);
  13469. +void_list_elt_t *void_list_pop(void_list_t *list);
  13470. +
  13471. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
  13472. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13473. +typedef int (*void_list_cmp_t)(const void *, const void *);
  13474. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
  13475. +
  13476. +#endif
  13477. diff -Nur busybox-1.17.0.orig/archival/libipkg/xsystem.c busybox-1.17.0/archival/libipkg/xsystem.c
  13478. --- busybox-1.17.0.orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
  13479. +++ busybox-1.17.0/archival/libipkg/xsystem.c 2010-07-16 14:45:17.296015041 +0200
  13480. @@ -0,0 +1,64 @@
  13481. +/* xsystem.c - system(3) with error messages
  13482. +
  13483. + Carl D. Worth
  13484. +
  13485. + Copyright (C) 2001 University of Southern California
  13486. +
  13487. + This program is free software; you can redistribute it and/or
  13488. + modify it under the terms of the GNU General Public License as
  13489. + published by the Free Software Foundation; either version 2, or (at
  13490. + your option) any later version.
  13491. +
  13492. + This program is distributed in the hope that it will be useful, but
  13493. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13494. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13495. + General Public License for more details.
  13496. +*/
  13497. +
  13498. +#include "ipkg.h"
  13499. +#include <sys/wait.h>
  13500. +
  13501. +#include "xsystem.h"
  13502. +
  13503. +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
  13504. + really need the /bin/sh invocation which takes resources and
  13505. + introduces security problems. I should switch all of this to a sort
  13506. + of execl() or execv() interface/implementation.
  13507. +*/
  13508. +
  13509. +/* Like system(3), but with error messages printed if the fork fails
  13510. + or if the child process dies due to an uncaught signal. Also, the
  13511. + return value is a bit simpler:
  13512. +
  13513. + -1 if there was any problem
  13514. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13515. + as defined in <sys/wait.h>.
  13516. +*/
  13517. +int xsystem(const char *cmd)
  13518. +{
  13519. + int err;
  13520. +
  13521. + err = system(cmd);
  13522. +
  13523. + if (err == -1) {
  13524. + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
  13525. + __FUNCTION__, cmd);
  13526. + return -1;
  13527. + }
  13528. +
  13529. + if (WIFSIGNALED(err)) {
  13530. + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
  13531. + __FUNCTION__, WTERMSIG(err), cmd);
  13532. + return -1;
  13533. + }
  13534. +
  13535. + if (WIFEXITED(err)) {
  13536. + /* Normal child exit */
  13537. + return WEXITSTATUS(err);
  13538. + }
  13539. +
  13540. + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
  13541. + __FUNCTION__, err);
  13542. + return -1;
  13543. +}
  13544. +
  13545. diff -Nur busybox-1.17.0.orig/archival/libipkg/xsystem.h busybox-1.17.0/archival/libipkg/xsystem.h
  13546. --- busybox-1.17.0.orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
  13547. +++ busybox-1.17.0/archival/libipkg/xsystem.h 2010-07-16 14:45:17.335862137 +0200
  13548. @@ -0,0 +1,34 @@
  13549. +/* xsystem.h - system(3) with error messages
  13550. +
  13551. + Carl D. Worth
  13552. +
  13553. + Copyright (C) 2001 University of Southern California
  13554. +
  13555. + This program is free software; you can redistribute it and/or
  13556. + modify it under the terms of the GNU General Public License as
  13557. + published by the Free Software Foundation; either version 2, or (at
  13558. + your option) any later version.
  13559. +
  13560. + This program is distributed in the hope that it will be useful, but
  13561. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13562. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13563. + General Public License for more details.
  13564. +*/
  13565. +
  13566. +#ifndef XSYSTEM_H
  13567. +#define XSYSTEM_H
  13568. +
  13569. +#include <stdlib.h>
  13570. +
  13571. +/* Like system(3), but with error messages printed if the fork fails
  13572. + or if the child process dies due to an uncaught signal. Also, the
  13573. + return value is a bit simpler:
  13574. +
  13575. + -1 if there was any problem
  13576. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13577. + as defined in <sys/wait.h>.
  13578. +*/
  13579. +int xsystem(const char *cmd);
  13580. +
  13581. +#endif
  13582. +
  13583. diff -Nur busybox-1.17.0.orig/archival/libunarchive/Kbuild.src busybox-1.17.0/archival/libunarchive/Kbuild.src
  13584. --- busybox-1.17.0.orig/archival/libunarchive/Kbuild.src 2010-07-06 02:15:46.000000000 +0200
  13585. +++ busybox-1.17.0/archival/libunarchive/Kbuild.src 2010-07-16 14:45:17.385857294 +0200
  13586. @@ -43,6 +43,7 @@
  13587. lib-$(CONFIG_DPKG) += $(DPKG_FILES)
  13588. lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
  13589. lib-$(CONFIG_GUNZIP) += decompress_unzip.o
  13590. +lib-$(CONFIG_IPKG) += open_transformer.o get_header_tar.o get_header_tar_gz.o
  13591. lib-$(CONFIG_RPM2CPIO) += decompress_unzip.o get_header_cpio.o
  13592. lib-$(CONFIG_RPM) += open_transformer.o decompress_unzip.o get_header_cpio.o
  13593. lib-$(CONFIG_TAR) += get_header_tar.o
  13594. diff -Nur busybox-1.17.0.orig/include/applets.src.h busybox-1.17.0/include/applets.src.h
  13595. --- busybox-1.17.0.orig/include/applets.src.h 2010-06-24 04:40:43.000000000 +0200
  13596. +++ busybox-1.17.0/include/applets.src.h 2010-07-16 14:45:17.435860440 +0200
  13597. @@ -209,6 +209,7 @@
  13598. IF_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_DROP))
  13599. IF_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
  13600. IF_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
  13601. +IF_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_DROP))
  13602. IF_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_DROP))
  13603. IF_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_DROP))
  13604. IF_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_DROP))
  13605. diff -Nur busybox-1.17.0.orig/include/unarchive.h busybox-1.17.0/include/unarchive.h
  13606. --- busybox-1.17.0.orig/include/unarchive.h 2010-07-03 13:18:17.000000000 +0200
  13607. +++ busybox-1.17.0/include/unarchive.h 2010-07-16 14:45:17.486389646 +0200
  13608. @@ -76,7 +76,7 @@
  13609. off_t offset;
  13610. /* Archiver specific. Can make it a union if it ever gets big */
  13611. -#if ENABLE_TAR || ENABLE_DPKG || ENABLE_DPKG_DEB
  13612. +#if ENABLE_TAR || ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13613. smallint tar__end;
  13614. # if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
  13615. char* tar__longname;
  13616. @@ -95,7 +95,7 @@
  13617. struct hardlinks_t *cpio__hardlinks_to_create;
  13618. struct hardlinks_t *cpio__created_hardlinks;
  13619. #endif
  13620. -#if ENABLE_DPKG || ENABLE_DPKG_DEB
  13621. +#if ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13622. /* Temporary storage */
  13623. char *dpkg__buffer;
  13624. /* How to process any sub archive, e.g. get_header_tar_gz */
  13625. diff -Nur busybox-1.17.0.orig/include/usage.src.h busybox-1.17.0/include/usage.src.h
  13626. --- busybox-1.17.0.orig/include/usage.src.h 2010-07-03 13:18:17.000000000 +0200
  13627. +++ busybox-1.17.0/include/usage.src.h 2010-07-16 14:45:17.555889367 +0200
  13628. @@ -1556,6 +1556,82 @@
  13629. "$ ls -la /tmp/busybox*\n" \
  13630. "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
  13631. +#define ipkg_trivial_usage \
  13632. + "[options]... sub-command [arguments]..."
  13633. +#define ipkg_full_usage \
  13634. + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
  13635. + "\n" \
  13636. + "Sub-commands:\n" \
  13637. + "\nPackage Manipulation:\n" \
  13638. + "\tupdate Update list of available packages\n" \
  13639. + "\tupgrade Upgrade all installed packages to latest version\n" \
  13640. + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
  13641. + "\tinstall <file.ipk> Install package <file.ipk>\n" \
  13642. + "\tconfigure [<pkg>] Configure unpacked packages\n" \
  13643. + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
  13644. + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
  13645. + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
  13646. + "\n" \
  13647. + "Informational Commands:\n" \
  13648. + "\tlist List available packages and descriptions\n" \
  13649. + "\tlist_installed List all and only the installed packages and description \n" \
  13650. + "\tfiles <pkg> List all files belonging to <pkg>\n" \
  13651. + "\tsearch <file|regexp> Search for a package providing <file>\n" \
  13652. + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
  13653. + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
  13654. + "\tdownload <pkg> Download <pkg> to current directory.\n" \
  13655. + "\tcompare_versions <v1> <op> <v2>\n" \
  13656. + "\t compare versions using <= < > >= = << >>\n" \
  13657. + "\tprint_architecture prints the architecture.\n" \
  13658. + "\tprint_installation_architecture\n" \
  13659. + "\twhatdepends [-A] [pkgname|pat]+\n" \
  13660. + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
  13661. + "\twhatprovides [-A] [pkgname|pat]+\n" \
  13662. + "\twhatconflicts [-A] [pkgname|pat]+\n" \
  13663. + "\twhatreplaces [-A] [pkgname|pat]+\n" \
  13664. + "\t prints the installation architecture.\n" \
  13665. + "\n" \
  13666. + "\nOptions:\n" \
  13667. + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
  13668. + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
  13669. + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
  13670. + "\t 0 errors only\n" \
  13671. + "\t 1 normal messages (default)\n" \
  13672. + "\t 2 informative messages\n" \
  13673. + "\t 3 debug output\n" \
  13674. + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
  13675. + "\t-conf <conf_file> Default configuration file location\n" \
  13676. + " is /etc/ipkg.conf\n" \
  13677. + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
  13678. + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
  13679. + " <dest_name> should be a defined dest name from\n" \
  13680. + " the configuration file, (but can also be a\n" \
  13681. + " directory name in a pinch).\n" \
  13682. + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
  13683. + "\t-offline <offline_root> offline installation of packages.\n" \
  13684. + "\t-verbose_wget more wget messages\n" \
  13685. + "\n" \
  13686. + "Force Options (use when ipkg is too smart for its own good):\n" \
  13687. + "\t-force-depends Make dependency checks warnings instead of errors\n" \
  13688. + "\t Install/remove package in spite of failed dependences\n" \
  13689. + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
  13690. + " (no prompts). Note that this will not prevent\n" \
  13691. + " package installation scripts from prompting.\n" \
  13692. + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
  13693. + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
  13694. + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
  13695. + "\t-force_space Install even if there does not seem to be enough space.\n" \
  13696. + "\t-noaction No action -- test only\n" \
  13697. + "\t-nodeps Do not follow dependences\n" \
  13698. + "\t-force-removal-of-dependent-packages\n" \
  13699. + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
  13700. + "\t-test No action -- test only\n" \
  13701. + "\t-t Specify tmp-dir.\n" \
  13702. + "\t--tmp-dir Specify tmp-dir.\n" \
  13703. + "\n" \
  13704. + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
  13705. + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
  13706. +
  13707. #define halt_trivial_usage \
  13708. "[-d DELAY] [-n] [-f]" IF_FEATURE_WTMP(" [-w]")
  13709. #define halt_full_usage "\n\n" \
  13710. diff -Nur busybox-1.17.0.orig/Makefile busybox-1.17.0/Makefile
  13711. --- busybox-1.17.0.orig/Makefile 2010-07-06 04:16:45.000000000 +0200
  13712. +++ busybox-1.17.0/Makefile 2010-07-16 14:45:17.608032062 +0200
  13713. @@ -459,6 +459,7 @@
  13714. libs-y := \
  13715. archival/ \
  13716. + archival/libipkg/ \
  13717. archival/libunarchive/ \
  13718. console-tools/ \
  13719. coreutils/ \