001-ipkg.patch 424 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721
  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 00:06:51.575859707 +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-15 21:53:14.569608030 +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-15 21:53:14.636101678 +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-15 21:53:14.717767584 +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-15 21:53:14.778358426 +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-15 21:53:14.827854501 +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-15 21:53:14.868358189 +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-15 21:53:14.908357825 +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-15 21:53:14.967045150 +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-15 21:53:15.086069590 +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-15 21:53:15.795859120 +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-15 21:53:15.845858632 +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-15 21:53:15.905858755 +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-15 21:53:15.965858850 +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-15 21:53:16.045859465 +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-15 21:53:16.105858435 +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-15 21:53:16.175858692 +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-15 21:53:16.225858869 +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-15 21:53:16.275858348 +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-15 21:53:16.345858594 +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-15 21:53:16.406244872 +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-15 21:53:16.506386988 +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-15 21:53:16.575858691 +0200
  3626. @@ -0,0 +1,81 @@
  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. +
  3707. +#endif /* IPKG_INCLUDES_H */
  3708. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_install.c busybox-1.17.0/archival/libipkg/ipkg_install.c
  3709. --- busybox-1.17.0.orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
  3710. +++ busybox-1.17.0/archival/libipkg/ipkg_install.c 2010-07-15 21:53:16.645858623 +0200
  3711. @@ -0,0 +1,1982 @@
  3712. +/* ipkg_install.c - the itsy package management system
  3713. +
  3714. + Carl D. Worth
  3715. +
  3716. + Copyright (C) 2001 University of Southern California
  3717. +
  3718. + This program is free software; you can redistribute it and/or
  3719. + modify it under the terms of the GNU General Public License as
  3720. + published by the Free Software Foundation; either version 2, or (at
  3721. + your option) any later version.
  3722. +
  3723. + This program is distributed in the hope that it will be useful, but
  3724. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3725. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3726. + General Public License for more details.
  3727. +*/
  3728. +
  3729. +#include "ipkg.h"
  3730. +#include <errno.h>
  3731. +#include <dirent.h>
  3732. +#include <glob.h>
  3733. +#include <time.h>
  3734. +#include <signal.h>
  3735. +typedef void (*sighandler_t)(int);
  3736. +
  3737. +#include "pkg.h"
  3738. +#include "pkg_hash.h"
  3739. +#include "pkg_extract.h"
  3740. +
  3741. +#include "ipkg_install.h"
  3742. +#include "ipkg_configure.h"
  3743. +#include "ipkg_download.h"
  3744. +#include "ipkg_remove.h"
  3745. +
  3746. +#include "ipkg_utils.h"
  3747. +#include "ipkg_message.h"
  3748. +
  3749. +#include "sprintf_alloc.h"
  3750. +#include "file_util.h"
  3751. +#include "str_util.h"
  3752. +#include "xsystem.h"
  3753. +#include "user.h"
  3754. +
  3755. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  3756. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
  3757. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
  3758. +
  3759. +/*
  3760. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3761. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3762. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3763. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3764. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3765. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3766. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3767. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
  3768. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3769. +*/
  3770. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3771. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3772. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg);
  3773. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3774. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg);
  3775. +
  3776. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3777. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3778. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
  3779. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
  3780. +
  3781. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
  3782. +
  3783. +static int user_prefers_old_conffile(const char *file, const char *backup);
  3784. +
  3785. +static char *backup_filename_alloc(const char *file_name);
  3786. +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
  3787. +static int backup_exists_for(const char *file_name);
  3788. +static int backup_remove(const char *file_name);
  3789. +
  3790. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees);
  3791. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3792. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3793. +
  3794. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
  3795. +{
  3796. + int err, cmp;
  3797. + pkg_t *pkg, *old;
  3798. + char *old_version, *new_version;
  3799. +
  3800. + pkg = pkg_new();
  3801. + if (pkg == NULL) {
  3802. + return ENOMEM;
  3803. + }
  3804. +
  3805. + err = pkg_init_from_file(pkg, filename);
  3806. + if (err) {
  3807. + return err;
  3808. + }
  3809. +
  3810. + if (!pkg->architecture) {
  3811. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3812. + return -EINVAL;
  3813. + }
  3814. +
  3815. + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
  3816. + freeing the pkg that we pass in. It might be nice to clean this up
  3817. + if possible. */
  3818. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3819. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  3820. +
  3821. + pkg->local_filename = strdup(filename);
  3822. +
  3823. + if (old) {
  3824. + old_version = pkg_version_str_alloc(old);
  3825. + new_version = pkg_version_str_alloc(pkg);
  3826. +
  3827. + cmp = pkg_compare_versions(old, pkg);
  3828. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3829. + cmp = -1 ; /* then we force ipkg to downgrade */
  3830. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3831. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3832. + }
  3833. + if (cmp > 0) {
  3834. + ipkg_message(conf, IPKG_NOTICE,
  3835. + "Not downgrading package %s on %s from %s to %s.\n",
  3836. + old->name, old->dest->name, old_version, new_version);
  3837. + pkg->state_want = SW_DEINSTALL;
  3838. + pkg->state_flag |= SF_OBSOLETE;
  3839. + free(old_version);
  3840. + free(new_version);
  3841. + return 0;
  3842. + } else {
  3843. + free(old_version);
  3844. + free(new_version);
  3845. + }
  3846. + }
  3847. +
  3848. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3849. + return ipkg_install_pkg(conf, pkg,0);
  3850. +}
  3851. +
  3852. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3853. +{
  3854. + int cmp;
  3855. + pkg_t *old, *new;
  3856. + char *old_version, *new_version;
  3857. +
  3858. + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
  3859. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  3860. + if ( old )
  3861. + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
  3862. +
  3863. + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
  3864. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  3865. + if ( new )
  3866. + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
  3867. +
  3868. +/* Pigi Basically here is broken the version stuff.
  3869. + What's happening is that nothing provide the version to differents
  3870. + functions, so the returned struct is always the latest.
  3871. + That's why the install by name don't work.
  3872. +*/
  3873. + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
  3874. +
  3875. + if ( old )
  3876. + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
  3877. + if ( new )
  3878. + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
  3879. + ipkg_message(conf, IPKG_DEBUG2, " \n");
  3880. +
  3881. + if (new == NULL) {
  3882. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3883. + }
  3884. +
  3885. + new->state_flag |= SF_USER;
  3886. + if (old) {
  3887. + old_version = pkg_version_str_alloc(old);
  3888. + new_version = pkg_version_str_alloc(new);
  3889. +
  3890. + cmp = pkg_compare_versions(old, new);
  3891. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3892. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
  3893. + cmp = -1 ; /* then we force ipkg to downgrade */
  3894. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3895. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3896. + }
  3897. + ipkg_message(conf, IPKG_DEBUG,
  3898. + "Comparing visible versions of pkg %s:"
  3899. + "\n\t%s is installed "
  3900. + "\n\t%s is available "
  3901. + "\n\t%d was comparison result\n",
  3902. + pkg_name, old_version, new_version, cmp);
  3903. + if (cmp == 0 && !conf->force_reinstall) {
  3904. + ipkg_message(conf, IPKG_NOTICE,
  3905. + "Package %s (%s) installed in %s is up to date.\n",
  3906. + old->name, old_version, old->dest->name);
  3907. + free(old_version);
  3908. + free(new_version);
  3909. + return 0;
  3910. + } else if (cmp > 0) {
  3911. + ipkg_message(conf, IPKG_NOTICE,
  3912. + "Not downgrading package %s on %s from %s to %s.\n",
  3913. + old->name, old->dest->name, old_version, new_version);
  3914. + free(old_version);
  3915. + free(new_version);
  3916. + return 0;
  3917. + } else if (cmp < 0) {
  3918. + new->dest = old->dest;
  3919. + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
  3920. + }
  3921. + }
  3922. +
  3923. + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
  3924. + supposed to be an ipkg_error_t, but ipkg_install_pkg could
  3925. + return any kind of integer, (might be errno from a syscall,
  3926. + etc.). This is a real mess and will need to be cleaned up if
  3927. + anyone ever wants to make a nice libipkg. */
  3928. +
  3929. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3930. + return ipkg_install_pkg(conf, new,0);
  3931. +}
  3932. +
  3933. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3934. +{
  3935. + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
  3936. + int i;
  3937. + ipkg_error_t err;
  3938. + abstract_pkg_t *ppkg ;
  3939. +
  3940. + if (providers == NULL)
  3941. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3942. +
  3943. + for (i = 0; i < providers->len; i++) {
  3944. + ppkg = abstract_pkg_vec_get(providers, i);
  3945. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
  3946. + err = ipkg_install_by_name(conf, ppkg->name);
  3947. + if (err)
  3948. + return err;
  3949. +/* XXX Maybe ppkg should be freed ? */
  3950. + }
  3951. + return 0;
  3952. +}
  3953. +
  3954. +/*
  3955. + * Walk dependence graph starting with pkg, collect packages to be
  3956. + * installed into pkgs_needed, in dependence order.
  3957. + */
  3958. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
  3959. +{
  3960. + int i, err;
  3961. + pkg_vec_t *depends = pkg_vec_alloc();
  3962. + char **unresolved = NULL;
  3963. + int ndepends;
  3964. +
  3965. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  3966. + pkg, depends,
  3967. + &unresolved);
  3968. +
  3969. + if (unresolved) {
  3970. + ipkg_message(conf, IPKG_ERROR,
  3971. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  3972. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  3973. + while (*unresolved) {
  3974. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  3975. + unresolved++;
  3976. + }
  3977. + ipkg_message(conf, IPKG_ERROR, "\n");
  3978. + if (! conf->force_depends) {
  3979. + ipkg_message(conf, IPKG_INFO,
  3980. + "This could mean that your package list is out of date or that the packages\n"
  3981. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  3982. + "of this problem try again with the '-force-depends' option.\n");
  3983. + pkg_vec_free(depends);
  3984. + return IPKG_PKG_DEPS_UNSATISFIED;
  3985. + }
  3986. + }
  3987. +
  3988. + if (ndepends <= 0) {
  3989. + pkg_vec_free(depends);
  3990. + return 0;
  3991. + }
  3992. +
  3993. + for (i = 0; i < depends->len; i++) {
  3994. + pkg_t *dep = depends->pkgs[i];
  3995. + /* The package was uninstalled when we started, but another
  3996. + dep earlier in this loop may have depended on it and pulled
  3997. + it in, so check first. */
  3998. + if ((dep->state_status != SS_INSTALLED)
  3999. + && (dep->state_status != SS_UNPACKED)
  4000. + && (dep->state_want != SW_INSTALL)) {
  4001. +
  4002. + /* Mark packages as to-be-installed */
  4003. + dep->state_want = SW_INSTALL;
  4004. +
  4005. + /* Dependencies should be installed the same place as pkg */
  4006. + if (dep->dest == NULL) {
  4007. + dep->dest = pkg->dest;
  4008. + }
  4009. +
  4010. + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
  4011. + if (err) {
  4012. + pkg_vec_free(depends);
  4013. + return err;
  4014. + }
  4015. + }
  4016. + }
  4017. + if (pkgs_needed)
  4018. + pkg_vec_insert(pkgs_needed, pkg);
  4019. +
  4020. + pkg_vec_free(depends);
  4021. +
  4022. + return 0;
  4023. +}
  4024. +
  4025. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
  4026. +{
  4027. + int cmp;
  4028. + pkg_t *old, *new;
  4029. + char *old_version, *new_version;
  4030. +
  4031. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  4032. +
  4033. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  4034. + if (new == NULL) {
  4035. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4036. + }
  4037. + if (old) {
  4038. + old_version = pkg_version_str_alloc(old);
  4039. + new_version = pkg_version_str_alloc(new);
  4040. +
  4041. + cmp = pkg_compare_versions(old, new);
  4042. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4043. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
  4044. + cmp = -1 ; /* then we force ipkg to downgrade */
  4045. + /* We need to use a value < 0 because in the 0 case we are asking to */
  4046. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4047. + }
  4048. + ipkg_message(conf, IPKG_DEBUG,
  4049. + "comparing visible versions of pkg %s:"
  4050. + "\n\t%s is installed "
  4051. + "\n\t%s is available "
  4052. + "\n\t%d was comparison result\n",
  4053. + pkg_name, old_version, new_version, cmp);
  4054. + if (cmp == 0 && !conf->force_reinstall) {
  4055. + ipkg_message(conf, IPKG_NOTICE,
  4056. + "Package %s (%s) installed in %s is up to date.\n",
  4057. + old->name, old_version, old->dest->name);
  4058. + free(old_version);
  4059. + free(new_version);
  4060. + return 0;
  4061. + } else if (cmp > 0) {
  4062. + ipkg_message(conf, IPKG_NOTICE,
  4063. + "Not downgrading package %s on %s from %s to %s.\n",
  4064. + old->name, old->dest->name, old_version, new_version);
  4065. + free(old_version);
  4066. + free(new_version);
  4067. + return 0;
  4068. + } else if (cmp < 0) {
  4069. + new->dest = old->dest;
  4070. + old->state_want = SW_DEINSTALL;
  4071. + old->state_flag |= SF_OBSOLETE;
  4072. + }
  4073. + }
  4074. + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
  4075. +}
  4076. +
  4077. +
  4078. +
  4079. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
  4080. +{
  4081. + int i, err;
  4082. + pkg_vec_t *depends = pkg_vec_alloc();
  4083. + pkg_t *dep;
  4084. + char **unresolved = NULL;
  4085. + int ndepends;
  4086. +
  4087. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4088. + pkg, depends,
  4089. + &unresolved);
  4090. +
  4091. + if (unresolved) {
  4092. + ipkg_message(conf, IPKG_ERROR,
  4093. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4094. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4095. + while (*unresolved) {
  4096. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4097. + unresolved++;
  4098. + }
  4099. + ipkg_message(conf, IPKG_ERROR, "\n");
  4100. + if (! conf->force_depends) {
  4101. + ipkg_message(conf, IPKG_INFO,
  4102. + "This could mean that your package list is out of date or that the packages\n"
  4103. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4104. + "of this problem try again with the '-force-depends' option.\n");
  4105. + pkg_vec_free(depends);
  4106. + return IPKG_PKG_DEPS_UNSATISFIED;
  4107. + }
  4108. + }
  4109. +
  4110. + if (ndepends <= 0) {
  4111. + return 0;
  4112. + }
  4113. +
  4114. + /* Mark packages as to-be-installed */
  4115. + for (i=0; i < depends->len; i++) {
  4116. + /* Dependencies should be installed the same place as pkg */
  4117. + if (depends->pkgs[i]->dest == NULL) {
  4118. + depends->pkgs[i]->dest = pkg->dest;
  4119. + }
  4120. + depends->pkgs[i]->state_want = SW_INSTALL;
  4121. + }
  4122. +
  4123. + for (i = 0; i < depends->len; i++) {
  4124. + dep = depends->pkgs[i];
  4125. + /* The package was uninstalled when we started, but another
  4126. + dep earlier in this loop may have depended on it and pulled
  4127. + it in, so check first. */
  4128. + if ((dep->state_status != SS_INSTALLED)
  4129. + && (dep->state_status != SS_UNPACKED)) {
  4130. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4131. + err = ipkg_install_pkg(conf, dep,0);
  4132. + if (err) {
  4133. + pkg_vec_free(depends);
  4134. + return err;
  4135. + }
  4136. + }
  4137. + }
  4138. +
  4139. + pkg_vec_free(depends);
  4140. +
  4141. + return 0;
  4142. +}
  4143. +
  4144. +
  4145. +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
  4146. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
  4147. +{
  4148. + if (conf->nodeps == 0) {
  4149. + int i;
  4150. + pkg_vec_t *installed = pkg_vec_alloc();
  4151. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  4152. + for (i = 0; i < installed->len; i++) {
  4153. + pkg_t *pkg = installed->pkgs[i];
  4154. + satisfy_dependencies_for(conf, pkg);
  4155. + }
  4156. + pkg_vec_free(installed);
  4157. + }
  4158. + return 0;
  4159. +}
  4160. +
  4161. +
  4162. +
  4163. +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
  4164. +{
  4165. + int i;
  4166. + pkg_vec_t *conflicts = NULL;
  4167. + int level;
  4168. + const char *prefix;
  4169. + if (conf->force_depends) {
  4170. + level = IPKG_NOTICE;
  4171. + prefix = "Warning";
  4172. + } else {
  4173. + level = IPKG_ERROR;
  4174. + prefix = "ERROR";
  4175. + }
  4176. +
  4177. + if (!conf->force_depends)
  4178. + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(pkg);
  4179. +
  4180. + if (conflicts) {
  4181. + ipkg_message(conf, level,
  4182. + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
  4183. + i = 0;
  4184. + while (i < conflicts->len)
  4185. + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
  4186. + ipkg_message(conf, level, "\n");
  4187. + pkg_vec_free(conflicts);
  4188. + return IPKG_PKG_DEPS_UNSATISFIED;
  4189. + }
  4190. + return 0;
  4191. +}
  4192. +
  4193. +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
  4194. +{
  4195. + str_list_t *new_list = pkg_get_installed_files(new_pkg);
  4196. + str_list_elt_t *iter;
  4197. +
  4198. + for (iter = new_list->head; iter; iter = iter->next) {
  4199. + char *new_file = iter->data;
  4200. + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
  4201. + if (!new_file)
  4202. + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
  4203. + if (!owner || (owner == old_pkg))
  4204. + file_hash_set_file_owner(conf, new_file, new_pkg);
  4205. + }
  4206. + if (old_pkg) {
  4207. + str_list_t *old_list = pkg_get_installed_files(old_pkg);
  4208. + for (iter = old_list->head; iter; iter = iter->next) {
  4209. + char *old_file = iter->data;
  4210. + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
  4211. + if (owner == old_pkg) {
  4212. + /* obsolete */
  4213. + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
  4214. + }
  4215. + }
  4216. + }
  4217. + return 0;
  4218. +}
  4219. +
  4220. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
  4221. +{
  4222. + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
  4223. +
  4224. + /* sma 6.20.02: yup; here's the first bit */
  4225. + /*
  4226. + * XXX: BUG easy for cworth
  4227. + * 1) please point the call below to the correct current root destination
  4228. + * 2) we need to resolve how to check the required space for a pending pkg,
  4229. + * my diddling with the .ipk file size below isn't going to cut it.
  4230. + * 3) return a proper error code instead of 1
  4231. + */
  4232. + int comp_size, blocks_available;
  4233. +
  4234. + if (!conf->force_space && pkg->installed_size != NULL) {
  4235. + blocks_available = get_available_blocks(conf->default_dest->root_dir);
  4236. +
  4237. + comp_size = strtoul(pkg->installed_size, NULL, 0);
  4238. + /* round up a blocks count without doing fancy-but-slow casting jazz */
  4239. + comp_size = (int)((comp_size + 1023) / 1024);
  4240. +
  4241. + if (comp_size >= blocks_available) {
  4242. + ipkg_message(conf, IPKG_ERROR,
  4243. + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
  4244. + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
  4245. + return ENOSPC;
  4246. + }
  4247. + }
  4248. + return 0;
  4249. +}
  4250. +
  4251. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
  4252. +{
  4253. + int err;
  4254. + char *conffiles_file_name;
  4255. + char *root_dir;
  4256. + FILE *conffiles_file;
  4257. +
  4258. + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
  4259. +
  4260. + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
  4261. + if (pkg->tmp_unpack_dir == NULL) {
  4262. + ipkg_message(conf, IPKG_ERROR,
  4263. + "%s: Failed to create temporary directory '%s': %s\n",
  4264. + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
  4265. + return errno;
  4266. + }
  4267. +
  4268. + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
  4269. + if (err) {
  4270. + return err;
  4271. + }
  4272. +
  4273. + /* XXX: CLEANUP: There might be a cleaner place to read in the
  4274. + conffiles. Seems like I should be able to get everything to go
  4275. + through pkg_init_from_file. If so, maybe it would make sense to
  4276. + move all of unpack_pkg_control_files to that function. */
  4277. +
  4278. + /* Don't need to re-read conffiles if we already have it */
  4279. + if (pkg->conffiles.head) {
  4280. + return 0;
  4281. + }
  4282. +
  4283. + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
  4284. + if (! file_exists(conffiles_file_name)) {
  4285. + free(conffiles_file_name);
  4286. + return 0;
  4287. + }
  4288. +
  4289. + conffiles_file = fopen(conffiles_file_name, "r");
  4290. + if (conffiles_file == NULL) {
  4291. + fprintf(stderr, "%s: failed to open %s: %s\n",
  4292. + __FUNCTION__, conffiles_file_name, strerror(errno));
  4293. + free(conffiles_file_name);
  4294. + return errno;
  4295. + }
  4296. + free(conffiles_file_name);
  4297. +
  4298. + while (1) {
  4299. + char *cf_name;
  4300. + char *cf_name_in_dest;
  4301. +
  4302. + cf_name = file_read_line_alloc(conffiles_file);
  4303. + if (cf_name == NULL) {
  4304. + break;
  4305. + }
  4306. + str_chomp(cf_name);
  4307. + if (cf_name[0] == '\0') {
  4308. + continue;
  4309. + }
  4310. +
  4311. + /* Prepend dest->root_dir to conffile name.
  4312. + Take pains to avoid multiple slashes. */
  4313. + root_dir = pkg->dest->root_dir;
  4314. + if (conf->offline_root)
  4315. + /* skip the offline_root prefix */
  4316. + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
  4317. + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
  4318. + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
  4319. +
  4320. + /* Can't get an md5sum now, (file isn't extracted yet).
  4321. + We'll wait until resolve_conffiles */
  4322. + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
  4323. +
  4324. + free(cf_name);
  4325. + free(cf_name_in_dest);
  4326. + }
  4327. +
  4328. + fclose(conffiles_file);
  4329. +
  4330. + return 0;
  4331. +}
  4332. +
  4333. +/* returns number of installed replacees */
  4334. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees)
  4335. +{
  4336. + abstract_pkg_t **replaces = pkg->replaces;
  4337. + int replaces_count = pkg->replaces_count;
  4338. + int i, j;
  4339. + for (i = 0; i < replaces_count; i++) {
  4340. + abstract_pkg_t *ab_pkg = replaces[i];
  4341. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  4342. + if (pkg_vec) {
  4343. + for (j = 0; j < pkg_vec->len; j++) {
  4344. + pkg_t *replacee = pkg_vec->pkgs[j];
  4345. + if (!pkg_conflicts(pkg, replacee))
  4346. + continue;
  4347. + if (replacee->state_status == SS_INSTALLED) {
  4348. + pkg_vec_insert(installed_replacees, replacee);
  4349. + }
  4350. + }
  4351. + }
  4352. + }
  4353. + return installed_replacees->len;
  4354. +}
  4355. +
  4356. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4357. +{
  4358. + int i;
  4359. + int replaces_count = replacees->len;
  4360. + for (i = 0; i < replaces_count; i++) {
  4361. + pkg_t *replacee = replacees->pkgs[i];
  4362. + int err;
  4363. + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
  4364. + err = ipkg_remove_pkg(conf, replacee,0);
  4365. + if (err)
  4366. + return err;
  4367. + }
  4368. + return 0;
  4369. +}
  4370. +
  4371. +/* to unwind the removal: make sure they are installed */
  4372. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4373. +{
  4374. + int i, err;
  4375. + int replaces_count = replacees->len;
  4376. + for (i = 0; i < replaces_count; i++) {
  4377. + pkg_t *replacee = replacees->pkgs[i];
  4378. + if (replacee->state_status != SS_INSTALLED) {
  4379. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4380. + err = ipkg_install_pkg(conf, replacee,0);
  4381. + if (err)
  4382. + return err;
  4383. + }
  4384. + }
  4385. + return 0;
  4386. +}
  4387. +
  4388. +int caught_sigint = 0;
  4389. +static void ipkg_install_pkg_sigint_handler(int sig)
  4390. +{
  4391. + caught_sigint = sig;
  4392. +}
  4393. +
  4394. +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
  4395. +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
  4396. +{
  4397. + if (old_pkg) {
  4398. + char message_out[15];
  4399. + char *old_version = pkg_version_str_alloc(old_pkg);
  4400. + char *new_version = pkg_version_str_alloc(pkg);
  4401. + int cmp = pkg_compare_versions(old_pkg, pkg);
  4402. + int rc = 0;
  4403. +
  4404. + memset(message_out,'\x0',15);
  4405. + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
  4406. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4407. + cmp = -1 ; /* then we force ipkg to downgrade */
  4408. + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
  4409. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4410. + }
  4411. +
  4412. + if (cmp > 0) {
  4413. + ipkg_message(conf, IPKG_NOTICE,
  4414. + "Not downgrading package %s on %s from %s to %s.\n",
  4415. + old_pkg->name, old_pkg->dest->name, old_version, new_version);
  4416. + rc = 1;
  4417. + } else if (cmp < 0) {
  4418. + ipkg_message(conf, IPKG_NOTICE,
  4419. + "%s%s on %s from %s to %s...\n",
  4420. + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
  4421. + pkg->dest = old_pkg->dest;
  4422. + rc = 0;
  4423. + } else /* cmp == 0 */ {
  4424. + if (conf->force_reinstall) {
  4425. + ipkg_message(conf, IPKG_NOTICE,
  4426. + "Reinstalling %s (%s) on %s...\n",
  4427. + pkg->name, new_version, old_pkg->dest->name);
  4428. + pkg->dest = old_pkg->dest;
  4429. + rc = 0;
  4430. + } else {
  4431. + ipkg_message(conf, IPKG_NOTICE,
  4432. + "Not installing %s (%s) on %s -- already installed.\n",
  4433. + pkg->name, new_version, old_pkg->dest->name);
  4434. + rc = 1;
  4435. + }
  4436. + }
  4437. + free(old_version);
  4438. + free(new_version);
  4439. + return rc;
  4440. + } else {
  4441. + char message_out[15], *version ;
  4442. + memset(message_out,'\x0',15);
  4443. + if ( message )
  4444. + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
  4445. + else
  4446. + strncpy( message_out,"Installing ",strlen("Installing ") );
  4447. + version = pkg_version_str_alloc(pkg);
  4448. +
  4449. + ipkg_message(conf, IPKG_NOTICE,
  4450. + "%s%s (%s) to %s...\n", message_out,
  4451. + pkg->name, version, pkg->dest->name);
  4452. + free(version);
  4453. + return 0;
  4454. + }
  4455. +}
  4456. +
  4457. +/* and now the meat... */
  4458. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
  4459. +{
  4460. + int err = 0;
  4461. + int message = 0;
  4462. + pkg_t *old_pkg = NULL;
  4463. + pkg_vec_t *replacees;
  4464. + abstract_pkg_t *ab_pkg = NULL;
  4465. + int old_state_flag;
  4466. + uint8_t *file_md5;
  4467. +
  4468. +
  4469. + if ( from_upgrade )
  4470. + message = 1; /* Coming from an upgrade, and should change the output message */
  4471. +
  4472. + if (!pkg) {
  4473. + ipkg_message(conf, IPKG_ERROR,
  4474. + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
  4475. + return -EINVAL;
  4476. + }
  4477. +
  4478. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
  4479. +
  4480. + if (!pkg_arch_supported(conf, pkg)) {
  4481. + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
  4482. + pkg->architecture, pkg->name);
  4483. + return -EINVAL;
  4484. + }
  4485. + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
  4486. + err = satisfy_dependencies_for(conf, pkg);
  4487. + if (err) { return err; }
  4488. +
  4489. + ipkg_message(conf, IPKG_NOTICE,
  4490. + "Package %s is already installed in %s.\n",
  4491. + pkg->name, pkg->dest->name);
  4492. + return 0;
  4493. + }
  4494. +
  4495. + if (pkg->dest == NULL) {
  4496. + pkg->dest = conf->default_dest;
  4497. + }
  4498. +
  4499. + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  4500. +
  4501. + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
  4502. + if (err) { return err; }
  4503. +
  4504. + pkg->state_want = SW_INSTALL;
  4505. + if (old_pkg){
  4506. + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
  4507. + }
  4508. +
  4509. +
  4510. + /* Abhaya: conflicts check */
  4511. + err = check_conflicts_for(conf, pkg);
  4512. + if (err) { return err; }
  4513. +
  4514. + /* this setup is to remove the upgrade scenario in the end when
  4515. + installing pkg A, A deps B & B deps on A. So both B and A are
  4516. + installed. Then A's installation is started resulting in an
  4517. + uncecessary upgrade */
  4518. + if (pkg->state_status == SS_INSTALLED
  4519. + && conf->force_reinstall == 0) return 0;
  4520. +
  4521. + err = verify_pkg_installable(conf, pkg);
  4522. + if (err) { return err; }
  4523. +
  4524. + if (pkg->local_filename == NULL) {
  4525. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  4526. + if (err) {
  4527. + ipkg_message(conf, IPKG_ERROR,
  4528. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  4529. + pkg->name);
  4530. + return err;
  4531. + }
  4532. + }
  4533. +
  4534. +/* Check for md5 values */
  4535. + if (pkg->md5sum)
  4536. + {
  4537. + file_md5 = file_md5sum_alloc(pkg->local_filename);
  4538. + if (strcmp((char *)file_md5, pkg->md5sum))
  4539. + {
  4540. + ipkg_message(conf, IPKG_ERROR,
  4541. + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
  4542. + pkg->name);
  4543. + free(file_md5);
  4544. + return err;
  4545. + }
  4546. + free(file_md5);
  4547. + }
  4548. +
  4549. + if (pkg->tmp_unpack_dir == NULL) {
  4550. + unpack_pkg_control_files(conf, pkg);
  4551. + }
  4552. +
  4553. + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
  4554. +/* Pigi: check if it will pass from here when replacing. It seems to fail */
  4555. +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
  4556. + err = update_file_ownership(conf, pkg, old_pkg);
  4557. + if (err) { return err; }
  4558. +
  4559. + if (conf->nodeps == 0) {
  4560. + err = satisfy_dependencies_for(conf, pkg);
  4561. + if (err) { return err; }
  4562. + }
  4563. +
  4564. + replacees = pkg_vec_alloc();
  4565. + pkg_get_installed_replacees(pkg, replacees);
  4566. +
  4567. + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
  4568. + {
  4569. + sigset_t newset, oldset;
  4570. + sighandler_t old_handler = NULL;
  4571. + int use_signal = 0;
  4572. + caught_sigint = 0;
  4573. + if (use_signal) {
  4574. + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
  4575. + } else {
  4576. + sigemptyset(&newset);
  4577. + sigaddset(&newset, SIGINT);
  4578. + sigprocmask(SIG_BLOCK, &newset, &oldset);
  4579. + }
  4580. +
  4581. + ipkg_state_changed++;
  4582. + pkg->state_flag |= SF_FILELIST_CHANGED;
  4583. +
  4584. + /* XXX: BUG: we really should treat replacement more like an upgrade
  4585. + * Instead, we're going to remove the replacees
  4586. + */
  4587. + err = pkg_remove_installed_replacees(conf, replacees);
  4588. + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
  4589. +
  4590. + /*
  4591. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  4592. + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
  4593. +
  4594. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  4595. + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
  4596. + */
  4597. +
  4598. + err = preinst_configure(conf, pkg, old_pkg);
  4599. + /*
  4600. + if (err) goto UNWIND_PREINST_CONFIGURE;
  4601. + */
  4602. +
  4603. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  4604. + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
  4605. +
  4606. + err = check_data_file_clashes(conf, pkg, old_pkg);
  4607. + /*
  4608. + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
  4609. +
  4610. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  4611. + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
  4612. + */
  4613. +
  4614. + if (conf->noaction) return 0;
  4615. +
  4616. + /* point of no return: no unwinding after this */
  4617. + if (old_pkg && !conf->force_reinstall) {
  4618. + old_pkg->state_want = SW_DEINSTALL;
  4619. +
  4620. + if (old_pkg->state_flag & SF_NOPRUNE) {
  4621. + ipkg_message(conf, IPKG_INFO,
  4622. + " not removing obsolesced files because package marked noprune\n");
  4623. + } else {
  4624. + ipkg_message(conf, IPKG_INFO,
  4625. + " removing obsolesced files\n");
  4626. + remove_obsolesced_files(conf, pkg, old_pkg);
  4627. + }
  4628. + /* removing files from old package, to avoid ghost files */
  4629. + remove_data_files_and_list(conf, old_pkg);
  4630. +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
  4631. + remove_maintainer_scripts_except_postrm(conf, old_pkg);
  4632. + remove_postrm(conf, old_pkg);
  4633. +/* Pigi */
  4634. +
  4635. + }
  4636. +
  4637. +
  4638. + ipkg_message(conf, IPKG_INFO,
  4639. + " installing maintainer scripts\n");
  4640. + install_maintainer_scripts(conf, pkg, old_pkg);
  4641. +
  4642. + /* the following just returns 0
  4643. + remove_disappeared(conf, pkg);
  4644. + */
  4645. +
  4646. + ipkg_message(conf, IPKG_INFO,
  4647. + " installing data files\n");
  4648. + install_data_files(conf, pkg);
  4649. +
  4650. +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
  4651. + err = check_data_file_clashes_change(conf, pkg);
  4652. +
  4653. + ipkg_message(conf, IPKG_INFO,
  4654. + " resolving conf files\n");
  4655. + resolve_conffiles(conf, pkg);
  4656. +
  4657. + pkg->state_status = SS_UNPACKED;
  4658. + old_state_flag = pkg->state_flag;
  4659. + pkg->state_flag &= ~SF_PREFER;
  4660. + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
  4661. +
  4662. + if (old_pkg && !conf->force_reinstall) {
  4663. + old_pkg->state_status = SS_NOT_INSTALLED;
  4664. + }
  4665. +
  4666. + time(&pkg->installed_time);
  4667. +
  4668. + ipkg_message(conf, IPKG_INFO,
  4669. + " cleanup temp files\n");
  4670. + cleanup_temporary_files(conf, pkg);
  4671. +
  4672. + ab_pkg = pkg->parent;
  4673. + if (ab_pkg)
  4674. + ab_pkg->state_status = pkg->state_status;
  4675. +
  4676. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  4677. +
  4678. + if (use_signal)
  4679. + signal(SIGINT, old_handler);
  4680. + else
  4681. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4682. +
  4683. + return 0;
  4684. +
  4685. +
  4686. + /*
  4687. + UNWIND_POSTRM_UPGRADE_OLD_PKG:
  4688. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4689. + UNWIND_CHECK_DATA_FILE_CLASHES:
  4690. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  4691. + */
  4692. + UNWIND_BACKUP_MODIFIED_CONFFILES:
  4693. + backup_modified_conffiles_unwind(pkg, old_pkg);
  4694. + /*
  4695. + UNWIND_PREINST_CONFIGURE:
  4696. + preinst_configure_unwind(conf, pkg, old_pkg);
  4697. + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
  4698. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  4699. + UNWIND_PRERM_UPGRADE_OLD_PKG:
  4700. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4701. + */
  4702. + UNWIND_REMOVE_INSTALLED_REPLACEES:
  4703. + pkg_remove_installed_replacees_unwind(conf, replacees);
  4704. +
  4705. + ipkg_message(conf, IPKG_INFO,
  4706. + " cleanup temp files\n");
  4707. + cleanup_temporary_files(conf, pkg);
  4708. +
  4709. + ipkg_message(conf, IPKG_INFO,
  4710. + "Failed.\n");
  4711. + if (use_signal)
  4712. + signal(SIGINT, old_handler);
  4713. + else
  4714. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4715. +
  4716. + return err;
  4717. + }
  4718. +}
  4719. +
  4720. +/*
  4721. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4722. +{
  4723. + DPKG_INCOMPATIBILITY:
  4724. + dpkg does some things here that we don't do yet. Do we care?
  4725. +
  4726. + 1. If a version of the package is already installed, call
  4727. + old-prerm upgrade new-version
  4728. + 2. If the script runs but exits with a non-zero exit status
  4729. + new-prerm failed-upgrade old-version
  4730. + Error unwind, for both the above cases:
  4731. + old-postinst abort-upgrade new-version
  4732. + return 0;
  4733. +}
  4734. +*/
  4735. +
  4736. +/*
  4737. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4738. +{
  4739. + DPKG_INCOMPATIBILITY:
  4740. + dpkg does some things here that we don't do yet. Do we care?
  4741. + (See prerm_upgrade_old_package for details)
  4742. +
  4743. + return 0;
  4744. +}
  4745. +*/
  4746. +
  4747. +/*
  4748. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4749. +{
  4750. + DPKG_INCOMPATIBILITY:
  4751. + dpkg does some things here that we don't do yet. Do we care?
  4752. + 2. If a 'conflicting' package is being removed at the same time:
  4753. + 1. If any packages depended on that conflicting package and
  4754. + --auto-deconfigure is specified, call, for each such package:
  4755. + deconfigured's-prerm deconfigure \
  4756. + in-favour package-being-installed version \
  4757. + removing conflicting-package version
  4758. + Error unwind:
  4759. + deconfigured's-postinst abort-deconfigure \
  4760. + in-favour package-being-installed-but-failed version \
  4761. + removing conflicting-package version
  4762. +
  4763. + The deconfigured packages are marked as requiring
  4764. + configuration, so that if --install is used they will be
  4765. + configured again if possible.
  4766. + 2. To prepare for removal of the conflicting package, call:
  4767. + conflictor's-prerm remove in-favour package new-version
  4768. + Error unwind:
  4769. + conflictor's-postinst abort-remove in-favour package new-version
  4770. + return 0;
  4771. +}
  4772. +*/
  4773. +
  4774. +/*
  4775. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4776. +{
  4777. + DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
  4778. + do yet. Do we care? (See prerm_deconfigure_conflictors for
  4779. + details)
  4780. + return 0;
  4781. +}
  4782. +*/
  4783. +
  4784. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4785. +{
  4786. + int err;
  4787. + char *preinst_args;
  4788. +
  4789. + if (old_pkg) {
  4790. + char *old_version = pkg_version_str_alloc(old_pkg);
  4791. + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
  4792. + free(old_version);
  4793. + } else if (pkg->state_status == SS_CONFIG_FILES) {
  4794. + char *pkg_version = pkg_version_str_alloc(pkg);
  4795. + sprintf_alloc(&preinst_args, "install %s", pkg_version);
  4796. + free(pkg_version);
  4797. + } else {
  4798. + preinst_args = strdup("install");
  4799. + }
  4800. +
  4801. + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
  4802. + if (err) {
  4803. + ipkg_message(conf, IPKG_ERROR,
  4804. + "Aborting installation of %s\n", pkg->name);
  4805. + return 1;
  4806. + }
  4807. +
  4808. + free(preinst_args);
  4809. +
  4810. + return 0;
  4811. +}
  4812. +
  4813. +/*
  4814. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4815. +{
  4816. + DPKG_INCOMPATIBILITY:
  4817. + dpkg does the following error unwind, should we?
  4818. + pkg->postrm abort-upgrade old-version
  4819. + OR pkg->postrm abort-install old-version
  4820. + OR pkg->postrm abort-install
  4821. + return 0;
  4822. +}
  4823. +*/
  4824. +
  4825. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4826. +{
  4827. + int err;
  4828. + conffile_list_elt_t *iter;
  4829. + conffile_t *cf;
  4830. +
  4831. + if (conf->noaction) return 0;
  4832. +
  4833. + /* Backup all modified conffiles */
  4834. + if (old_pkg) {
  4835. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4836. + char *cf_name;
  4837. +
  4838. + cf = iter->data;
  4839. + cf_name = root_filename_alloc(conf, cf->name);
  4840. +
  4841. + /* Don't worry if the conffile is just plain gone */
  4842. + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
  4843. + err = backup_make_backup(conf, cf_name);
  4844. + if (err) {
  4845. + return err;
  4846. + }
  4847. + }
  4848. + free(cf_name);
  4849. + }
  4850. + }
  4851. +
  4852. + /* Backup all conffiles that were not conffiles in old_pkg */
  4853. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4854. + char *cf_name;
  4855. + cf = iter->data;
  4856. + cf_name = root_filename_alloc(conf, cf->name);
  4857. + /* Ignore if this was a conffile in old_pkg as well */
  4858. + if (pkg_get_conffile(old_pkg, cf->name)) {
  4859. + continue;
  4860. + }
  4861. +
  4862. + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
  4863. + err = backup_make_backup(conf, cf_name);
  4864. + if (err) {
  4865. + return err;
  4866. + }
  4867. + }
  4868. + free(cf_name);
  4869. + }
  4870. +
  4871. + return 0;
  4872. +}
  4873. +
  4874. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg)
  4875. +{
  4876. + conffile_list_elt_t *iter;
  4877. +
  4878. + if (old_pkg) {
  4879. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4880. + backup_remove(iter->data->name);
  4881. + }
  4882. + }
  4883. +
  4884. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4885. + backup_remove(iter->data->name);
  4886. + }
  4887. +
  4888. + return 0;
  4889. +}
  4890. +
  4891. +
  4892. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4893. +{
  4894. + /* DPKG_INCOMPATIBILITY:
  4895. + ipkg takes a slightly different approach than dpkg at this
  4896. + point. dpkg installs each file in the new package while
  4897. + creating a backup for any file that is replaced, (so that it
  4898. + can unwind if necessary). To avoid complexity and redundant
  4899. + storage, ipkg doesn't do any installation until later, (at the
  4900. + point at which dpkg removes the backups.
  4901. +
  4902. + But, we do have to check for data file clashes, since after
  4903. + installing a package with a file clash, removing either of the
  4904. + packages involved in the clash has the potential to break the
  4905. + other package.
  4906. + */
  4907. + str_list_t *files_list;
  4908. + str_list_elt_t *iter;
  4909. +
  4910. + int clashes = 0;
  4911. +
  4912. + files_list = pkg_get_installed_files(pkg);
  4913. + for (iter = files_list->head; iter; iter = iter->next) {
  4914. + char *root_filename;
  4915. + char *filename = iter->data;
  4916. + root_filename = root_filename_alloc(conf, filename);
  4917. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  4918. + pkg_t *owner;
  4919. + pkg_t *obs;
  4920. + /* Pre-existing conffiles are OK */
  4921. + /* @@@@ should have way to check that it is a conffile -Jamey */
  4922. + if (backup_exists_for(root_filename)) {
  4923. + continue;
  4924. + }
  4925. +
  4926. + /* Pre-existing files are OK if force-overwrite was asserted. */
  4927. + if (conf->force_overwrite) {
  4928. + /* but we need to change who owns this file */
  4929. + file_hash_set_file_owner(conf, filename, pkg);
  4930. + continue;
  4931. + }
  4932. +
  4933. + owner = file_hash_get_file_owner(conf, filename);
  4934. +
  4935. + /* Pre-existing files are OK if owned by the pkg being upgraded. */
  4936. + if (owner && old_pkg) {
  4937. + if (strcmp(owner->name, old_pkg->name) == 0) {
  4938. + continue;
  4939. + }
  4940. + }
  4941. +
  4942. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  4943. + if (owner) {
  4944. + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
  4945. + if (pkg_replaces(pkg, owner)) {
  4946. + continue;
  4947. + }
  4948. +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
  4949. + then it's ok to overwrite. */
  4950. + if (strcmp(owner->name,pkg->name)==0){
  4951. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  4952. + continue;
  4953. + }
  4954. + }
  4955. +
  4956. + /* Pre-existing files are OK if they are obsolete */
  4957. + obs = hash_table_get(&conf->obs_file_hash, filename);
  4958. + if (obs) {
  4959. + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
  4960. + continue;
  4961. + }
  4962. +
  4963. + /* We have found a clash. */
  4964. + ipkg_message(conf, IPKG_ERROR,
  4965. + "Package %s wants to install file %s\n"
  4966. + "\tBut that file is already provided by package ",
  4967. + pkg->name, filename);
  4968. + if (owner) {
  4969. + ipkg_message(conf, IPKG_ERROR,
  4970. + "%s\n", owner->name);
  4971. + } else {
  4972. + ipkg_message(conf, IPKG_ERROR,
  4973. + "<no package>\nPlease move this file out of the way and try again.\n");
  4974. + }
  4975. + clashes++;
  4976. + }
  4977. + free(root_filename);
  4978. + }
  4979. + pkg_free_installed_files(pkg);
  4980. +
  4981. + return clashes;
  4982. +}
  4983. +
  4984. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg)
  4985. +{
  4986. + /* Basically that's the worst hack I could do to be able to change ownership of
  4987. + file list, but, being that we have no way to unwind the mods, due to structure
  4988. + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
  4989. + What we do here is change the ownership of file in hash if a replace ( or similar events
  4990. + happens )
  4991. + Only the action that are needed to change name should be considered.
  4992. + @@@ To change after 1.0 release.
  4993. + */
  4994. + str_list_t *files_list;
  4995. + str_list_elt_t *iter;
  4996. +
  4997. + int clashes = 0;
  4998. +
  4999. + files_list = pkg_get_installed_files(pkg);
  5000. + for (iter = files_list->head; iter; iter = iter->next) {
  5001. + char *root_filename;
  5002. + char *filename = iter->data;
  5003. + root_filename = root_filename_alloc(conf, filename);
  5004. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5005. + pkg_t *owner;
  5006. +
  5007. + if (conf->force_overwrite) {
  5008. + /* but we need to change who owns this file */
  5009. + file_hash_set_file_owner(conf, filename, pkg);
  5010. + continue;
  5011. + }
  5012. +
  5013. + owner = file_hash_get_file_owner(conf, filename);
  5014. +
  5015. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5016. + if (owner) {
  5017. + if (pkg_replaces(pkg, owner)) {
  5018. +/* It's now time to change the owner of that file.
  5019. + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
  5020. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5021. + file_hash_set_file_owner(conf, filename, pkg);
  5022. + continue;
  5023. + }
  5024. + }
  5025. +
  5026. + }
  5027. + free(root_filename);
  5028. + }
  5029. + pkg_free_installed_files(pkg);
  5030. +
  5031. + return clashes;
  5032. +}
  5033. +
  5034. +/*
  5035. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5036. +{
  5037. + Nothing to do since check_data_file_clashes doesn't change state
  5038. + return 0;
  5039. +}
  5040. +*/
  5041. +
  5042. +/*
  5043. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5044. +{
  5045. + DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
  5046. + 1. If the package is being upgraded, call
  5047. + old-postrm upgrade new-version
  5048. + 2. If this fails, attempt:
  5049. + new-postrm failed-upgrade old-version
  5050. + Error unwind, for both cases:
  5051. + old-preinst abort-upgrade new-version
  5052. + return 0;
  5053. +}
  5054. +*/
  5055. +
  5056. +/*
  5057. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5058. +{
  5059. + DPKG_INCOMPATIBILITY:
  5060. + dpkg does some things here that we don't do yet. Do we care?
  5061. + (See postrm_upgrade_old_pkg for details)
  5062. + return 0;
  5063. +}
  5064. +*/
  5065. +
  5066. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5067. +{
  5068. + int err;
  5069. + str_list_t *old_files;
  5070. + str_list_elt_t *of;
  5071. + str_list_t *new_files;
  5072. + str_list_elt_t *nf;
  5073. +
  5074. + if (old_pkg == NULL) {
  5075. + return 0;
  5076. + }
  5077. +
  5078. + old_files = pkg_get_installed_files(old_pkg);
  5079. + new_files = pkg_get_installed_files(pkg);
  5080. +
  5081. + for (of = old_files->head; of; of = of->next) {
  5082. + pkg_t *owner;
  5083. + char *old, *new;
  5084. + old = of->data;
  5085. + for (nf = new_files->head; nf; nf = nf->next) {
  5086. + new = nf->data;
  5087. + if (strcmp(old, new) == 0) {
  5088. + goto NOT_OBSOLETE;
  5089. + }
  5090. + }
  5091. + if (file_is_dir(old)) {
  5092. + continue;
  5093. + }
  5094. + owner = file_hash_get_file_owner(conf, old);
  5095. + if (owner != old_pkg) {
  5096. + /* in case obsolete file no longer belongs to old_pkg */
  5097. + continue;
  5098. + }
  5099. +
  5100. + /* old file is obsolete */
  5101. + ipkg_message(conf, IPKG_INFO,
  5102. + " removing obsolete file %s\n", old);
  5103. + if (!conf->noaction) {
  5104. + err = unlink(old);
  5105. + if (err) {
  5106. + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
  5107. + strerror(errno));
  5108. + }
  5109. + }
  5110. +
  5111. + NOT_OBSOLETE:
  5112. + ;
  5113. + }
  5114. +
  5115. + pkg_free_installed_files(old_pkg);
  5116. + pkg_free_installed_files(pkg);
  5117. +
  5118. + return 0;
  5119. +}
  5120. +
  5121. +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5122. +{
  5123. + int i;
  5124. + int err = 0;
  5125. + char *globpattern;
  5126. + glob_t globbuf;
  5127. + if (0) {
  5128. + if (!pkg->dest) {
  5129. + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
  5130. + return -1;
  5131. + }
  5132. + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
  5133. + err = glob(globpattern, 0, NULL, &globbuf);
  5134. + free(globpattern);
  5135. + if (err) {
  5136. + return err;
  5137. + }
  5138. + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
  5139. + for (i = 0; i < globbuf.gl_pathc; i++) {
  5140. + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
  5141. + globbuf.gl_pathv[i], old_pkg->name);
  5142. + if (!conf->noaction)
  5143. + unlink(globbuf.gl_pathv[i]);
  5144. + }
  5145. + globfree(&globbuf);
  5146. + }
  5147. + return err;
  5148. +}
  5149. +
  5150. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5151. +{
  5152. + int ret;
  5153. + char *prefix;
  5154. +
  5155. + if (old_pkg)
  5156. + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
  5157. + sprintf_alloc(&prefix, "%s.", pkg->name);
  5158. + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
  5159. + pkg->dest->info_dir,
  5160. + prefix);
  5161. + free(prefix);
  5162. + return ret;
  5163. +}
  5164. +
  5165. +/*
  5166. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
  5167. +{
  5168. + DPKG_INCOMPATIBILITY:
  5169. + This is a fairly sophisticated dpkg operation. Shall we
  5170. + skip it?
  5171. +
  5172. + Any packages all of whose files have been overwritten during the
  5173. + installation, and which aren't required for dependencies, are
  5174. + considered to have been removed. For each such package
  5175. + 1. disappearer's-postrm disappear overwriter overwriter-version
  5176. + 2. The package's maintainer scripts are removed
  5177. + 3. It is noted in the status database as being in a sane state,
  5178. + namely not installed (any conffiles it may have are ignored,
  5179. + rather than being removed by dpkg). Note that disappearing
  5180. + packages do not have their prerm called, because dpkg doesn't
  5181. + know in advance that the package is going to vanish.
  5182. +
  5183. +
  5184. + return 0;
  5185. +}
  5186. +*/
  5187. +
  5188. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
  5189. +{
  5190. + int err;
  5191. +
  5192. + /* ipkg takes a slightly different approach to data file backups
  5193. + than dpkg. Rather than removing backups at this point, we
  5194. + actually do the data file installation now. See comments in
  5195. + check_data_file_clashes() for more details. */
  5196. +
  5197. + ipkg_message(conf, IPKG_INFO,
  5198. + " extracting data files to %s\n", pkg->dest->root_dir);
  5199. + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
  5200. + if (err) {
  5201. + return err;
  5202. + }
  5203. +
  5204. + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
  5205. + so we can't save ourself from removing important packages
  5206. + At this point we (should) have extracted the .control file, so it
  5207. + would be a good idea to reload the data in it, and set the Essential
  5208. + state in *pkg. From now on the Essential is back in status file and
  5209. + we can protect again.
  5210. + We should operate this way:
  5211. + fopen the file ( pkg->dest->root_dir/pkg->name.control )
  5212. + check for "Essential" in it
  5213. + set the value in pkg->essential.
  5214. + This new routine could be useful also for every other flag
  5215. + Pigi: 16/03/2004 */
  5216. + set_flags_from_control(conf, pkg) ;
  5217. +
  5218. + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
  5219. + err = pkg_write_filelist(conf, pkg);
  5220. + if (err)
  5221. + return err;
  5222. +
  5223. + /* XXX: FEATURE: ipkg should identify any files which existed
  5224. + before installation and which were overwritten, (see
  5225. + check_data_file_clashes()). What it must do is remove any such
  5226. + files from the filelist of the old package which provided the
  5227. + file. Otherwise, if the old package were removed at some point
  5228. + it would break the new package. Removing the new package will
  5229. + also break the old one, but this cannot be helped since the old
  5230. + package's file has already been deleted. This is the importance
  5231. + of check_data_file_clashes(), and only allowing ipkg to install
  5232. + a clashing package with a user force. */
  5233. +
  5234. + return 0;
  5235. +}
  5236. +
  5237. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
  5238. +{
  5239. + conffile_list_elt_t *iter;
  5240. + conffile_t *cf;
  5241. + char *cf_backup;
  5242. + uint8_t *md5sum;
  5243. +
  5244. +
  5245. + if (conf->noaction) return 0;
  5246. +
  5247. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  5248. + char *root_filename;
  5249. + cf = iter->data;
  5250. + root_filename = root_filename_alloc(conf, cf->name);
  5251. +
  5252. + /* Might need to initialize the md5sum for each conffile */
  5253. + if (cf->value == NULL) {
  5254. + cf->value = (char *)file_md5sum_alloc(root_filename);
  5255. + }
  5256. +
  5257. + if (!file_exists(root_filename)) {
  5258. + free(root_filename);
  5259. + continue;
  5260. + }
  5261. +
  5262. + cf_backup = backup_filename_alloc(root_filename);
  5263. +
  5264. +
  5265. + if (file_exists(cf_backup)) {
  5266. + /* Let's compute md5 to test if files are changed */
  5267. + md5sum = file_md5sum_alloc(cf_backup);
  5268. + if (strcmp( cf->value, (char *)md5sum) != 0 ) {
  5269. + if (conf->force_defaults
  5270. + || user_prefers_old_conffile(cf->name, cf_backup) ) {
  5271. + rename(cf_backup, root_filename);
  5272. + }
  5273. + }
  5274. + unlink(cf_backup);
  5275. + free(md5sum);
  5276. + }
  5277. +
  5278. + free(cf_backup);
  5279. + free(root_filename);
  5280. + }
  5281. +
  5282. + return 0;
  5283. +}
  5284. +
  5285. +static int user_prefers_old_conffile(const char *file_name, const char *backup)
  5286. +{
  5287. + char *response;
  5288. + const char *short_file_name;
  5289. +
  5290. + short_file_name = strrchr(file_name, '/');
  5291. + if (short_file_name) {
  5292. + short_file_name++;
  5293. + } else {
  5294. + short_file_name = file_name;
  5295. + }
  5296. +
  5297. + while (1) {
  5298. + response = get_user_response(" Configuration file '%s'\n"
  5299. + " ==> File on system created by you or by a script.\n"
  5300. + " ==> File also in package provided by package maintainer.\n"
  5301. + " What would you like to do about it ? Your options are:\n"
  5302. + " Y or I : install the package maintainer's version\n"
  5303. + " N or O : keep your currently-installed version\n"
  5304. +#ifdef CONFIG_DIFF
  5305. + " D : show the differences between the versions\n"
  5306. +#endif
  5307. + " The default action is to keep your current version.\n"
  5308. + " *** %s (Y/I/N/O"
  5309. +#ifdef CONFIG_DIFF
  5310. + "/D"
  5311. +#endif
  5312. + ") [default=N] ? ", file_name, short_file_name);
  5313. + if (strcmp(response, "y") == 0
  5314. + || strcmp(response, "i") == 0
  5315. + || strcmp(response, "yes") == 0) {
  5316. + free(response);
  5317. + return 0;
  5318. + }
  5319. +
  5320. +#ifdef CONFIG_DIFF
  5321. + if (strcmp(response, "d") == 0) {
  5322. + char *cmd;
  5323. +
  5324. + free(response);
  5325. + /* XXX: BUG rewrite to use exec or busybox's internal diff */
  5326. + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
  5327. + xsystem(cmd);
  5328. + free(cmd);
  5329. + printf(" [Press ENTER to continue]\n");
  5330. + response = file_read_line_alloc(stdin);
  5331. + free(response);
  5332. + continue;
  5333. + }
  5334. +#endif
  5335. +
  5336. + free(response);
  5337. + return 1;
  5338. + }
  5339. +}
  5340. +
  5341. +/* XXX: CLEANUP: I'd like to move all of the code for
  5342. + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
  5343. + it would make sense to cleanup pkg->tmp_unpack_dir directly from
  5344. + pkg_deinit for example). */
  5345. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
  5346. +{
  5347. + DIR *tmp_dir;
  5348. + struct dirent *dirent;
  5349. + char *tmp_file;
  5350. +
  5351. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  5352. +#error
  5353. + ipkg_message(conf, IPKG_DEBUG,
  5354. + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  5355. + __FUNCTION__, pkg->tmp_unpack_dir);
  5356. + return 0;
  5357. +#endif
  5358. +
  5359. + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
  5360. + tmp_dir = opendir(pkg->tmp_unpack_dir);
  5361. + if (tmp_dir) {
  5362. + while (1) {
  5363. + dirent = readdir(tmp_dir);
  5364. + if (dirent == NULL) {
  5365. + break;
  5366. + }
  5367. + sprintf_alloc(&tmp_file, "%s/%s",
  5368. + pkg->tmp_unpack_dir, dirent->d_name);
  5369. + if (! file_is_dir(tmp_file)) {
  5370. + unlink(tmp_file);
  5371. + }
  5372. + free(tmp_file);
  5373. + }
  5374. + closedir(tmp_dir);
  5375. + rmdir(pkg->tmp_unpack_dir);
  5376. + free(pkg->tmp_unpack_dir);
  5377. + pkg->tmp_unpack_dir = NULL;
  5378. + }
  5379. + }
  5380. +
  5381. + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
  5382. + pkg->name, pkg->local_filename, conf->tmp_dir);
  5383. + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
  5384. + unlink(pkg->local_filename);
  5385. + free(pkg->local_filename);
  5386. + pkg->local_filename = NULL;
  5387. + }
  5388. +
  5389. + return 0;
  5390. +}
  5391. +
  5392. +static char *backup_filename_alloc(const char *file_name)
  5393. +{
  5394. + char *backup;
  5395. +
  5396. + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
  5397. +
  5398. + return backup;
  5399. +}
  5400. +
  5401. +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
  5402. +{
  5403. + int err;
  5404. + char *backup;
  5405. +
  5406. + backup = backup_filename_alloc(file_name);
  5407. + err = file_copy(file_name, backup);
  5408. + if (err) {
  5409. + ipkg_message(conf, IPKG_ERROR,
  5410. + "%s: Failed to copy %s to %s\n",
  5411. + __FUNCTION__, file_name, backup);
  5412. + }
  5413. +
  5414. + free(backup);
  5415. +
  5416. + return err;
  5417. +}
  5418. +
  5419. +static int backup_exists_for(const char *file_name)
  5420. +{
  5421. + int ret;
  5422. + char *backup;
  5423. +
  5424. + backup = backup_filename_alloc(file_name);
  5425. +
  5426. + ret = file_exists(backup);
  5427. +
  5428. + free(backup);
  5429. +
  5430. + return ret;
  5431. +}
  5432. +
  5433. +static int backup_remove(const char *file_name)
  5434. +{
  5435. + char *backup;
  5436. +
  5437. + backup = backup_filename_alloc(file_name);
  5438. + unlink(backup);
  5439. + free(backup);
  5440. +
  5441. + return 0;
  5442. +}
  5443. +
  5444. +
  5445. +
  5446. +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
  5447. +
  5448. +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
  5449. +{
  5450. + /* first, remove the packages that need removing */
  5451. + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
  5452. + pkg_t *pkg = pkgs_to_remove->pkgs[i];
  5453. + err = ipkg_remove_pkg(conf, pkg,0);
  5454. + if (err) return err;
  5455. + }
  5456. + return 0;
  5457. +}
  5458. +
  5459. +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)
  5460. +{
  5461. + int i;
  5462. + /* now one more pass checking on the ones that need to be installed */
  5463. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5464. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5465. + if (pkg->dest == NULL)
  5466. + pkg->dest = conf->default_dest;
  5467. +
  5468. + pkg->state_want = SW_INSTALL;
  5469. +
  5470. + /* Abhaya: conflicts check */
  5471. + err = check_conflicts_for(conf, pkg);
  5472. + if (err) { return err; }
  5473. + }
  5474. + return 0;
  5475. +}
  5476. +
  5477. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5478. +{
  5479. + int i;
  5480. + /* now one more pass checking on the ones that need to be installed */
  5481. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5482. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5483. +
  5484. + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
  5485. + pkg_vec_t *replacees = pkg_vec_alloc();
  5486. + pkg_get_installed_replacees(pkg, replacees);
  5487. +
  5488. + /* XXX: BUG: we really should treat replacement more like an upgrade
  5489. + * Instead, we're going to remove the replacees
  5490. + */
  5491. + err = pkg_remove_installed_replacees(conf, replacees);
  5492. + if (err) return err;
  5493. + pkg->state_flag |= SF_REMOVED_REPLACEES;
  5494. + }
  5495. + return 0;
  5496. +}
  5497. +
  5498. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5499. +{
  5500. + int i;
  5501. + /* now one more pass checking on the ones that need to be installed */
  5502. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5503. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5504. + if (pkg->local_filename == NULL) {
  5505. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  5506. + if (err) {
  5507. + ipkg_message(conf, IPKG_ERROR,
  5508. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  5509. + pkg->name);
  5510. + return err;
  5511. + }
  5512. + }
  5513. + if (pkg->tmp_unpack_dir == NULL) {
  5514. + err = unpack_pkg_control_files(conf, pkg);
  5515. + if (err) return err;
  5516. + }
  5517. + }
  5518. + return 0;
  5519. +}
  5520. +
  5521. +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5522. +{
  5523. + int i;
  5524. + /* now one more pass checking on the ones that need to be installed */
  5525. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5526. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5527. + pkg_t *old_pkg = pkg->old_pkg;
  5528. +
  5529. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  5530. + if (err) return err;
  5531. +
  5532. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  5533. + if (err) return err;
  5534. +
  5535. + err = preinst_configure(conf, pkg, old_pkg);
  5536. + if (err) return err;
  5537. +
  5538. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  5539. + if (err) return err;
  5540. +
  5541. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  5542. + if (err) return err;
  5543. + }
  5544. + return 0;
  5545. +}
  5546. +
  5547. +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5548. +{
  5549. + int i;
  5550. + /* now one more pass checking on the ones that need to be installed */
  5551. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5552. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5553. + pkg_t *old_pkg = pkg->old_pkg;
  5554. +
  5555. + if (old_pkg) {
  5556. + old_pkg->state_want = SW_DEINSTALL;
  5557. +
  5558. + if (old_pkg->state_flag & SF_NOPRUNE) {
  5559. + ipkg_message(conf, IPKG_INFO,
  5560. + " not removing obsolesced files because package marked noprune\n");
  5561. + } else {
  5562. + ipkg_message(conf, IPKG_INFO,
  5563. + " removing obsolesced files\n");
  5564. + remove_obsolesced_files(conf, pkg, old_pkg);
  5565. + }
  5566. + }
  5567. +
  5568. + ipkg_message(conf, IPKG_INFO,
  5569. + " installing maintainer scripts\n");
  5570. + install_maintainer_scripts(conf, pkg, old_pkg);
  5571. +
  5572. + /* the following just returns 0 */
  5573. + remove_disappeared(conf, pkg);
  5574. +
  5575. + ipkg_message(conf, IPKG_INFO,
  5576. + " installing data files\n");
  5577. + install_data_files(conf, pkg);
  5578. +
  5579. + ipkg_message(conf, IPKG_INFO,
  5580. + " resolving conf files\n");
  5581. + resolve_conffiles(conf, pkg);
  5582. +
  5583. + pkg->state_status = SS_UNPACKED;
  5584. +
  5585. + if (old_pkg) {
  5586. + old_pkg->state_status = SS_NOT_INSTALLED;
  5587. + }
  5588. +
  5589. + time(&pkg->installed_time);
  5590. +
  5591. + ipkg_message(conf, IPKG_INFO,
  5592. + " cleanup temp files\n");
  5593. + cleanup_temporary_files(conf, pkg);
  5594. +
  5595. + if (pkg->parent)
  5596. + pkg->parent->state_status = pkg->state_status;
  5597. + }
  5598. + return 0;
  5599. +}
  5600. +
  5601. +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5602. +{
  5603. + int i;
  5604. + /* now one more pass checking on the ones that need to be installed */
  5605. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5606. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5607. + pkg_t *old_pkg = pkg->old_pkg;
  5608. +
  5609. + if (old_pkg) {
  5610. + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
  5611. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5612. + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
  5613. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  5614. + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
  5615. + backup_modified_conffiles_unwind(pkg, old_pkg);
  5616. + */
  5617. + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
  5618. + preinst_configure_unwind(conf, pkg, old_pkg);
  5619. + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
  5620. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  5621. + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
  5622. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5623. + */
  5624. +
  5625. + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
  5626. + remove_installed_replacees_unwind(conf, pkg, old_pkg);
  5627. +
  5628. + }
  5629. + }
  5630. + return 0;
  5631. +}
  5632. +
  5633. +/*
  5634. + * Perform all the actions.
  5635. + *
  5636. + * pkgs_to_remove are packages marked for removal.
  5637. + * pkgs_superseded are the old packages being replaced by upgrades.
  5638. + *
  5639. + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
  5640. + */
  5641. +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)
  5642. +{
  5643. + int err;
  5644. + int i;
  5645. +
  5646. + err = ipkg_remove_packages(conf, pkgs_to_remove);
  5647. + if (err) return err;
  5648. +
  5649. + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
  5650. + if (err) return err;
  5651. +
  5652. + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
  5653. + if (err) goto UNWIND;
  5654. +
  5655. + /* @@@@ look at ipkg_install_pkg for handling replacements */
  5656. + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
  5657. + if (err) goto UNWIND;
  5658. +
  5659. + /*
  5660. + * Now that we have the packages unpacked, we can look for data
  5661. + * file clashes. First, we mark the files from the superseded
  5662. + * packages as obsolete. Then we scan the files in
  5663. + * pkgs_to_install, and only complain about clashes with
  5664. + * non-obsolete files.
  5665. + */
  5666. +
  5667. + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
  5668. + if (err) goto UNWIND;
  5669. +
  5670. + /* this was before checking data file clashes */
  5671. + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
  5672. + if (err) goto UNWIND;
  5673. +
  5674. + /* point of no return: no unwinding after this */
  5675. + err = ipkg_process_actions_install(conf, pkgs_to_install);
  5676. + if (err) return err;
  5677. +
  5678. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  5679. + return 0;
  5680. +
  5681. + UNWIND:
  5682. + ipkg_process_actions_unwind(conf, pkgs_to_install);
  5683. +
  5684. + ipkg_message(conf, IPKG_INFO,
  5685. + " cleanup temp files\n");
  5686. + cleanup_temporary_files(conf, pkg);
  5687. +
  5688. + ipkg_message(conf, IPKG_INFO,
  5689. + "Failed.\n");
  5690. + return err;
  5691. +}
  5692. +
  5693. +#endif
  5694. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_install.h busybox-1.17.0/archival/libipkg/ipkg_install.h
  5695. --- busybox-1.17.0.orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
  5696. +++ busybox-1.17.0/archival/libipkg/ipkg_install.h 2010-07-15 21:53:16.705858734 +0200
  5697. @@ -0,0 +1,35 @@
  5698. +/* ipkg_install.h - the itsy package management system
  5699. +
  5700. + Carl D. Worth
  5701. +
  5702. + Copyright (C) 2001 University of Southern California
  5703. +
  5704. + This program is free software; you can redistribute it and/or
  5705. + modify it under the terms of the GNU General Public License as
  5706. + published by the Free Software Foundation; either version 2, or (at
  5707. + your option) any later version.
  5708. +
  5709. + This program is distributed in the hope that it will be useful, but
  5710. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5711. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5712. + General Public License for more details.
  5713. +*/
  5714. +
  5715. +#ifndef IPKG_INSTALL_H
  5716. +#define IPKG_INSTALL_H
  5717. +
  5718. +#include "pkg.h"
  5719. +#include "ipkg_conf.h"
  5720. +
  5721. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5722. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5723. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
  5724. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
  5725. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  5726. +
  5727. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
  5728. +
  5729. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
  5730. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
  5731. +
  5732. +#endif
  5733. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_message.c busybox-1.17.0/archival/libipkg/ipkg_message.c
  5734. --- busybox-1.17.0.orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
  5735. +++ busybox-1.17.0/archival/libipkg/ipkg_message.c 2010-07-15 21:53:16.765858774 +0200
  5736. @@ -0,0 +1,35 @@
  5737. +/* ipkg_message.c - the itsy package management system
  5738. +
  5739. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5740. +
  5741. + This program is free software; you can redistribute it and/or
  5742. + modify it under the terms of the GNU General Public License as
  5743. + published by the Free Software Foundation; either version 2, or (at
  5744. + your option) any later version.
  5745. +
  5746. + This program is distributed in the hope that it will be useful, but
  5747. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5748. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5749. + General Public License for more details.
  5750. +*/
  5751. +
  5752. +
  5753. +#include "ipkg.h"
  5754. +#include "ipkg_conf.h"
  5755. +#include "ipkg_message.h"
  5756. +#include "libipkg.h"
  5757. +
  5758. +void
  5759. +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
  5760. +{
  5761. + va_list ap;
  5762. + char ts[256];
  5763. +
  5764. + if (ipkg_cb_message)
  5765. + {
  5766. + va_start (ap, fmt);
  5767. + vsnprintf (ts,256,fmt, ap);
  5768. + va_end (ap);
  5769. + ipkg_cb_message(conf,level,ts);
  5770. + }
  5771. +}
  5772. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_message.h busybox-1.17.0/archival/libipkg/ipkg_message.h
  5773. --- busybox-1.17.0.orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
  5774. +++ busybox-1.17.0/archival/libipkg/ipkg_message.h 2010-07-15 21:53:16.815858747 +0200
  5775. @@ -0,0 +1,32 @@
  5776. +/* ipkg_message.h - the itsy package management system
  5777. +
  5778. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5779. +
  5780. + This program is free software; you can redistribute it and/or
  5781. + modify it under the terms of the GNU General Public License as
  5782. + published by the Free Software Foundation; either version 2, or (at
  5783. + your option) any later version.
  5784. +
  5785. + This program is distributed in the hope that it will be useful, but
  5786. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5787. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5788. + General Public License for more details.
  5789. +*/
  5790. +
  5791. +#ifndef _IPKG_MESSAGE_H_
  5792. +#define _IPKG_MESSAGE_H_
  5793. +
  5794. +#include "ipkg.h"
  5795. +#include "ipkg_conf.h"
  5796. +
  5797. +typedef enum {
  5798. + IPKG_ERROR, /* error conditions */
  5799. + IPKG_NOTICE, /* normal but significant condition */
  5800. + IPKG_INFO, /* informational message */
  5801. + IPKG_DEBUG, /* debug level message */
  5802. + IPKG_DEBUG2, /* more debug level message */
  5803. +} message_level_t;
  5804. +
  5805. +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
  5806. +
  5807. +#endif /* _IPKG_MESSAGE_H_ */
  5808. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_remove.c busybox-1.17.0/archival/libipkg/ipkg_remove.c
  5809. --- busybox-1.17.0.orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
  5810. +++ busybox-1.17.0/archival/libipkg/ipkg_remove.c 2010-07-15 21:53:16.865858801 +0200
  5811. @@ -0,0 +1,385 @@
  5812. +/* ipkg_remove.c - the itsy package management system
  5813. +
  5814. + Carl D. Worth
  5815. +
  5816. + Copyright (C) 2001 University of Southern California
  5817. +
  5818. + This program is free software; you can redistribute it and/or
  5819. + modify it under the terms of the GNU General Public License as
  5820. + published by the Free Software Foundation; either version 2, or (at
  5821. + your option) any later version.
  5822. +
  5823. + This program is distributed in the hope that it will be useful, but
  5824. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5825. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5826. + General Public License for more details.
  5827. +*/
  5828. +
  5829. +#include "ipkg.h"
  5830. +#include "ipkg_message.h"
  5831. +
  5832. +#include <glob.h>
  5833. +
  5834. +#include "ipkg_remove.h"
  5835. +
  5836. +#include "file_util.h"
  5837. +#include "sprintf_alloc.h"
  5838. +#include "str_util.h"
  5839. +
  5840. +#include "ipkg_cmd.h"
  5841. +
  5842. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents);
  5843. +
  5844. +/*
  5845. + * Returns number of the number of packages depending on the packages provided by this package.
  5846. + * Every package implicitly provides itself.
  5847. + */
  5848. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents)
  5849. +{
  5850. + int nprovides = pkg->provides_count;
  5851. + abstract_pkg_t **provides = pkg->provides;
  5852. + int n_installed_dependents = 0;
  5853. + int i;
  5854. + for (i = 0; i <= nprovides; i++) {
  5855. + abstract_pkg_t *providee = provides[i];
  5856. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5857. + abstract_pkg_t *dep_ab_pkg;
  5858. + if (dependers == NULL)
  5859. + continue;
  5860. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5861. + if (dep_ab_pkg->state_status == SS_INSTALLED){
  5862. + n_installed_dependents++;
  5863. + }
  5864. + }
  5865. +
  5866. + }
  5867. + /* if caller requested the set of installed dependents */
  5868. + if (pdependents) {
  5869. + int p = 0;
  5870. + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
  5871. +
  5872. + if ( dependents == NULL ){
  5873. + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
  5874. + return -1;
  5875. + }
  5876. +
  5877. + *pdependents = dependents;
  5878. + for (i = 0; i <= nprovides; i++) {
  5879. + abstract_pkg_t *providee = provides[i];
  5880. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5881. + abstract_pkg_t *dep_ab_pkg;
  5882. + if (dependers == NULL)
  5883. + continue;
  5884. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5885. + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
  5886. + dependents[p++] = dep_ab_pkg;
  5887. + dep_ab_pkg->state_flag |= SF_MARKED;
  5888. + }
  5889. + }
  5890. + }
  5891. + dependents[p] = NULL;
  5892. + /* now clear the marks */
  5893. + for (i = 0; i < p; i++) {
  5894. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5895. + dep_ab_pkg->state_flag &= ~SF_MARKED;
  5896. + }
  5897. + }
  5898. + return n_installed_dependents;
  5899. +}
  5900. +
  5901. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5902. +{
  5903. + int i;
  5904. + int a;
  5905. + int count;
  5906. + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
  5907. + abstract_pkg_t * ab_pkg;
  5908. +
  5909. + if((ab_pkg = pkg->parent) == NULL){
  5910. + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
  5911. + __FUNCTION__, pkg->name);
  5912. + return 0;
  5913. + }
  5914. +
  5915. + if (dependents == NULL)
  5916. + return 0;
  5917. +
  5918. + // here i am using the dependencies_checked
  5919. + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
  5920. + return 0; // has already been encountered in the process
  5921. + // of marking packages for removal - Karthik
  5922. + ab_pkg->dependencies_checked = 2;
  5923. +
  5924. + i = 0;
  5925. + count = 1;
  5926. + while (dependents [i] != NULL) {
  5927. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5928. +
  5929. + if (dep_ab_pkg->dependencies_checked == 2){
  5930. + i++;
  5931. + continue;
  5932. + }
  5933. + if (dep_ab_pkg->state_status == SS_INSTALLED) {
  5934. + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
  5935. + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
  5936. + if (dep_pkg->state_status == SS_INSTALLED) {
  5937. + pkg_vec_insert(dependent_pkgs, dep_pkg);
  5938. + count++;
  5939. + }
  5940. + }
  5941. + }
  5942. + i++;
  5943. + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
  5944. + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
  5945. + }
  5946. +
  5947. + if (count == 1)
  5948. + return 0;
  5949. +
  5950. +
  5951. + for (i = 0; i < dependent_pkgs->len; i++) {
  5952. + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
  5953. + if (err)
  5954. + return err;
  5955. + }
  5956. + return 0;
  5957. +}
  5958. +
  5959. +static int user_prefers_removing_dependents(ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5960. +{
  5961. + abstract_pkg_t *dep_ab_pkg;
  5962. + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
  5963. + while ((dep_ab_pkg = *dependents++) != NULL) {
  5964. + if (dep_ab_pkg->state_status == SS_INSTALLED)
  5965. + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
  5966. + }
  5967. + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
  5968. + ipkg_message(conf, IPKG_ERROR, "");
  5969. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
  5970. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
  5971. + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
  5972. + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
  5973. + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
  5974. + return 0;
  5975. +}
  5976. +
  5977. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
  5978. +{
  5979. +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
  5980. + thus I wan't check for essential, as I'm upgrading.
  5981. + I hope it won't break anything :)
  5982. +*/
  5983. + int err;
  5984. + abstract_pkg_t *parent_pkg = NULL;
  5985. +
  5986. + if (pkg->essential && !message) {
  5987. + if (conf->force_removal_of_essential_packages) {
  5988. + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
  5989. + "\tIf your system breaks, you get to keep both pieces\n",
  5990. + pkg->name);
  5991. + } else {
  5992. + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
  5993. + "\tRemoving an essential package may lead to an unusable system, but if\n"
  5994. + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
  5995. + "\tits will with the option: -force-removal-of-essential-packages\n",
  5996. + pkg->name);
  5997. + return IPKG_PKG_IS_ESSENTIAL;
  5998. + }
  5999. + }
  6000. +
  6001. + if ((parent_pkg = pkg->parent) == NULL)
  6002. + return 0;
  6003. +
  6004. + /* only attempt to remove dependent installed packages if
  6005. + * force_depends is not specified or the package is being
  6006. + * replaced.
  6007. + */
  6008. + if (!conf->force_depends
  6009. + && !(pkg->state_flag & SF_REPLACE)) {
  6010. + abstract_pkg_t **dependents;
  6011. + int has_installed_dependents =
  6012. + pkg_has_installed_dependents(pkg, &dependents);
  6013. +
  6014. + if (has_installed_dependents) {
  6015. + /*
  6016. + * if this package is depended up by others, then either we should
  6017. + * not remove it or we should remove it and all of its dependents
  6018. + */
  6019. +
  6020. + if (!conf->force_removal_of_dependent_packages
  6021. + && !user_prefers_removing_dependents(conf, pkg, dependents)) {
  6022. + return IPKG_PKG_HAS_DEPENDENTS;
  6023. + }
  6024. +
  6025. + /* remove packages depending on this package - Karthik */
  6026. + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
  6027. + free(dependents);
  6028. + if (err) return err;
  6029. + }
  6030. + }
  6031. +
  6032. + if ( message==0 ){
  6033. + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
  6034. + fflush(stdout);
  6035. + }
  6036. + pkg->state_flag |= SF_FILELIST_CHANGED;
  6037. +
  6038. + pkg->state_want = SW_DEINSTALL;
  6039. + ipkg_state_changed++;
  6040. +
  6041. + pkg_run_script(conf, pkg, "prerm", "remove");
  6042. +
  6043. + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
  6044. + maintains an empty filelist rather than deleting it. That seems
  6045. + like a big pain, and I don't see that that should make a big
  6046. + difference, but for anyone who wants tighter compatibility,
  6047. + feel free to fix this. */
  6048. + remove_data_files_and_list(conf, pkg);
  6049. +
  6050. + pkg_run_script(conf, pkg, "postrm", "remove");
  6051. +
  6052. + remove_maintainer_scripts_except_postrm(conf, pkg);
  6053. +
  6054. + /* Aman Gupta - Since ipkg is made for handheld devices with limited
  6055. + * space, it doesn't make sense to leave extra configurations, files,
  6056. + * and maintainer scripts left around. So, we make remove like purge,
  6057. + * and take out all the crap :) */
  6058. +
  6059. + remove_postrm(conf, pkg);
  6060. + pkg->state_status = SS_NOT_INSTALLED;
  6061. +
  6062. + if (parent_pkg)
  6063. + parent_pkg->state_status = SS_NOT_INSTALLED;
  6064. +
  6065. + return 0;
  6066. +}
  6067. +
  6068. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
  6069. +{
  6070. + ipkg_remove_pkg(conf, pkg,0);
  6071. + return 0;
  6072. +}
  6073. +
  6074. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
  6075. +{
  6076. + str_list_t installed_dirs;
  6077. + str_list_t *installed_files;
  6078. + str_list_elt_t *iter;
  6079. + char *file_name;
  6080. + conffile_t *conffile;
  6081. + int removed_a_dir;
  6082. + pkg_t *owner;
  6083. +
  6084. + str_list_init(&installed_dirs);
  6085. + installed_files = pkg_get_installed_files(pkg);
  6086. +
  6087. + for (iter = installed_files->head; iter; iter = iter->next) {
  6088. + file_name = iter->data;
  6089. +
  6090. + if (file_is_dir(file_name)) {
  6091. + str_list_append(&installed_dirs, strdup(file_name));
  6092. + continue;
  6093. + }
  6094. +
  6095. + conffile = pkg_get_conffile(pkg, file_name);
  6096. + if (conffile) {
  6097. + /* XXX: QUESTION: Is this right? I figure we only need to
  6098. + save the conffile if it has been modified. Is that what
  6099. + dpkg does? Or does dpkg preserve all conffiles? If so,
  6100. + this seems like a better thing to do to conserve
  6101. + space. */
  6102. + if (conffile_has_been_modified(conf, conffile)) {
  6103. + printf(" not deleting modified conffile %s\n", file_name);
  6104. + fflush(stdout);
  6105. + continue;
  6106. + }
  6107. + }
  6108. +
  6109. + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
  6110. + if (!conf->noaction)
  6111. + unlink(file_name);
  6112. + }
  6113. +
  6114. + if (!conf->noaction) {
  6115. + do {
  6116. + removed_a_dir = 0;
  6117. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6118. + file_name = iter->data;
  6119. +
  6120. + if (rmdir(file_name) == 0) {
  6121. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
  6122. + removed_a_dir = 1;
  6123. + str_list_remove(&installed_dirs, &iter);
  6124. + }
  6125. + }
  6126. + } while (removed_a_dir);
  6127. + }
  6128. +
  6129. + pkg_free_installed_files(pkg);
  6130. + /* We have to remove the file list now, so that
  6131. + find_pkg_owning_file does not always just report this package */
  6132. + pkg_remove_installed_files_list(conf, pkg);
  6133. +
  6134. + /* Don't print warning for dirs that are provided by other packages */
  6135. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6136. + file_name = iter->data;
  6137. +
  6138. + owner = file_hash_get_file_owner(conf, file_name);
  6139. + if (owner) {
  6140. + free(iter->data);
  6141. + iter->data = NULL;
  6142. + str_list_remove(&installed_dirs, &iter);
  6143. + }
  6144. + }
  6145. +
  6146. + /* cleanup */
  6147. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6148. + free(iter->data);
  6149. + iter->data = NULL;
  6150. + }
  6151. + str_list_deinit(&installed_dirs);
  6152. +
  6153. + return 0;
  6154. +}
  6155. +
  6156. +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6157. +{
  6158. + int i, err;
  6159. + char *globpattern;
  6160. + glob_t globbuf;
  6161. +
  6162. + if (conf->noaction) return 0;
  6163. +
  6164. + sprintf_alloc(&globpattern, "%s/%s.*",
  6165. + pkg->dest->info_dir, pkg->name);
  6166. + err = glob(globpattern, 0, NULL, &globbuf);
  6167. + free(globpattern);
  6168. + if (err) {
  6169. + return 0;
  6170. + }
  6171. +
  6172. + for (i = 0; i < globbuf.gl_pathc; i++) {
  6173. + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
  6174. + continue;
  6175. + }
  6176. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
  6177. + unlink(globbuf.gl_pathv[i]);
  6178. + }
  6179. + globfree(&globbuf);
  6180. +
  6181. + return 0;
  6182. +}
  6183. +
  6184. +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6185. +{
  6186. + char *postrm_file_name;
  6187. +
  6188. + if (conf->noaction) return 0;
  6189. +
  6190. + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
  6191. + pkg->dest->info_dir, pkg->name);
  6192. + unlink(postrm_file_name);
  6193. + free(postrm_file_name);
  6194. +
  6195. + return 0;
  6196. +}
  6197. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_remove.h busybox-1.17.0/archival/libipkg/ipkg_remove.h
  6198. --- busybox-1.17.0.orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
  6199. +++ busybox-1.17.0/archival/libipkg/ipkg_remove.h 2010-07-15 21:53:16.915858471 +0200
  6200. @@ -0,0 +1,33 @@
  6201. +/* ipkg_remove.h - the itsy package management system
  6202. +
  6203. + Carl D. Worth
  6204. +
  6205. + Copyright (C) 2001 University of Southern California
  6206. +
  6207. + This program is free software; you can redistribute it and/or
  6208. + modify it under the terms of the GNU General Public License as
  6209. + published by the Free Software Foundation; either version 2, or (at
  6210. + your option) any later version.
  6211. +
  6212. + This program is distributed in the hope that it will be useful, but
  6213. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6214. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6215. + General Public License for more details.
  6216. +*/
  6217. +
  6218. +#ifndef IPKG_REMOVE_H
  6219. +#define IPKG_REMOVE_H
  6220. +
  6221. +#include "pkg.h"
  6222. +#include "ipkg_conf.h"
  6223. +
  6224. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
  6225. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
  6226. +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
  6227. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents);
  6228. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
  6229. +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6230. +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6231. +
  6232. +
  6233. +#endif
  6234. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_upgrade.c busybox-1.17.0/archival/libipkg/ipkg_upgrade.c
  6235. --- busybox-1.17.0.orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
  6236. +++ busybox-1.17.0/archival/libipkg/ipkg_upgrade.c 2010-07-15 21:53:16.975859007 +0200
  6237. @@ -0,0 +1,79 @@
  6238. +/* ipkg_upgrade.c - the itsy package management system
  6239. +
  6240. + Carl D. Worth
  6241. + Copyright (C) 2001 University of Southern California
  6242. +
  6243. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6244. +
  6245. + This program is free software; you can redistribute it and/or
  6246. + modify it under the terms of the GNU General Public License as
  6247. + published by the Free Software Foundation; either version 2, or (at
  6248. + your option) any later version.
  6249. +
  6250. + This program is distributed in the hope that it will be useful, but
  6251. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6252. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6253. + General Public License for more details.
  6254. +*/
  6255. +
  6256. +#include "ipkg.h"
  6257. +#include "ipkg_install.h"
  6258. +#include "ipkg_message.h"
  6259. +
  6260. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6261. +
  6262. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
  6263. +{
  6264. + pkg_t *new;
  6265. + int cmp;
  6266. + char *old_version, *new_version;
  6267. +
  6268. + if (old->state_flag & SF_HOLD) {
  6269. + ipkg_message(conf, IPKG_NOTICE,
  6270. + "Not upgrading package %s which is marked "
  6271. + "hold (flags=%#x)\n", old->name, old->state_flag);
  6272. + return 0;
  6273. + }
  6274. +
  6275. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
  6276. + if (new == NULL) {
  6277. + old_version = pkg_version_str_alloc(old);
  6278. + ipkg_message(conf, IPKG_NOTICE,
  6279. + "Assuming locally installed package %s (%s) "
  6280. + "is up to date.\n", old->name, old_version);
  6281. + free(old_version);
  6282. + return 0;
  6283. + }
  6284. +
  6285. + old_version = pkg_version_str_alloc(old);
  6286. + new_version = pkg_version_str_alloc(new);
  6287. +
  6288. + cmp = pkg_compare_versions(old, new);
  6289. + ipkg_message(conf, IPKG_DEBUG,
  6290. + "comparing visible versions of pkg %s:"
  6291. + "\n\t%s is installed "
  6292. + "\n\t%s is available "
  6293. + "\n\t%d was comparison result\n",
  6294. + old->name, old_version, new_version, cmp);
  6295. + if (cmp == 0) {
  6296. + ipkg_message(conf, IPKG_INFO,
  6297. + "Package %s (%s) installed in %s is up to date.\n",
  6298. + old->name, old_version, old->dest->name);
  6299. + free(old_version);
  6300. + free(new_version);
  6301. + return 0;
  6302. + } else if (cmp > 0) {
  6303. + ipkg_message(conf, IPKG_NOTICE,
  6304. + "Not downgrading package %s on %s from %s to %s.\n",
  6305. + old->name, old->dest->name, old_version, new_version);
  6306. + free(old_version);
  6307. + free(new_version);
  6308. + return 0;
  6309. + } else if (cmp < 0) {
  6310. + new->dest = old->dest;
  6311. + old->state_want = SW_DEINSTALL;
  6312. + }
  6313. +
  6314. + new->state_flag |= SF_USER;
  6315. + return ipkg_install_pkg(conf, new,1);
  6316. +}
  6317. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_upgrade.h busybox-1.17.0/archival/libipkg/ipkg_upgrade.h
  6318. --- busybox-1.17.0.orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
  6319. +++ busybox-1.17.0/archival/libipkg/ipkg_upgrade.h 2010-07-15 21:53:17.045908173 +0200
  6320. @@ -0,0 +1,18 @@
  6321. +/* ipkg_upgrade.c - the itsy package management system
  6322. +
  6323. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6324. +
  6325. + This program is free software; you can redistribute it and/or
  6326. + modify it under the terms of the GNU General Public License as
  6327. + published by the Free Software Foundation; either version 2, or (at
  6328. + your option) any later version.
  6329. +
  6330. + This program is distributed in the hope that it will be useful, but
  6331. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6332. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6333. + General Public License for more details.
  6334. +*/
  6335. +
  6336. +#include "ipkg.h"
  6337. +
  6338. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6339. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_utils.c busybox-1.17.0/archival/libipkg/ipkg_utils.c
  6340. --- busybox-1.17.0.orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
  6341. +++ busybox-1.17.0/archival/libipkg/ipkg_utils.c 2010-07-15 21:53:17.106749166 +0200
  6342. @@ -0,0 +1,185 @@
  6343. +/* ipkg_utils.c - the itsy package management system
  6344. +
  6345. + Steven M. Ayer
  6346. +
  6347. + Copyright (C) 2002 Compaq Computer Corporation
  6348. +
  6349. + This program is free software; you can redistribute it and/or
  6350. + modify it under the terms of the GNU General Public License as
  6351. + published by the Free Software Foundation; either version 2, or (at
  6352. + your option) any later version.
  6353. +
  6354. + This program is distributed in the hope that it will be useful, but
  6355. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6356. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6357. + General Public License for more details.
  6358. +*/
  6359. +
  6360. +#include "ipkg.h"
  6361. +#include <errno.h>
  6362. +#include <ctype.h>
  6363. +#include <sys/vfs.h>
  6364. +
  6365. +#include "ipkg_utils.h"
  6366. +#include "pkg.h"
  6367. +#include "pkg_hash.h"
  6368. +
  6369. +void push_error_list(struct errlist ** errors, char * msg);
  6370. +void reverse_error_list(struct errlist **errors);
  6371. +void free_error_list(struct errlist **errors);
  6372. +
  6373. +struct errlist* error_list;
  6374. +
  6375. +int get_available_blocks(char * filesystem)
  6376. +{
  6377. + struct statfs sfs;
  6378. +
  6379. + if(statfs(filesystem, &sfs)){
  6380. + fprintf(stderr, "bad statfs\n");
  6381. + return 0;
  6382. + }
  6383. + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
  6384. + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
  6385. +}
  6386. +
  6387. +char **read_raw_pkgs_from_file(const char *file_name)
  6388. +{
  6389. + FILE *fp;
  6390. + char **ret;
  6391. +
  6392. + if(!(fp = fopen(file_name, "r"))){
  6393. + fprintf(stderr, "can't get %s open for read\n", file_name);
  6394. + return NULL;
  6395. + }
  6396. +
  6397. + ret = read_raw_pkgs_from_stream(fp);
  6398. +
  6399. + fclose(fp);
  6400. +
  6401. + return ret;
  6402. +}
  6403. +
  6404. +char **read_raw_pkgs_from_stream(FILE *fp)
  6405. +{
  6406. + char **raw = NULL, *buf, *scout;
  6407. + int count = 0;
  6408. + size_t size = 512;
  6409. +
  6410. + buf = malloc (size);
  6411. +
  6412. + while (fgets(buf, size, fp)) {
  6413. + while (strlen (buf) == (size - 1)
  6414. + && buf[size-2] != '\n') {
  6415. + size_t o = size - 1;
  6416. + size *= 2;
  6417. + buf = realloc (buf, size);
  6418. + if (fgets (buf + o, size - o, fp) == NULL)
  6419. + break;
  6420. + }
  6421. +
  6422. + if(!(count % 50))
  6423. + raw = realloc(raw, (count + 50) * sizeof(char *));
  6424. +
  6425. + if((scout = strchr(buf, '\n')))
  6426. + *scout = '\0';
  6427. +
  6428. + raw[count++] = strdup(buf);
  6429. + }
  6430. +
  6431. + raw = realloc(raw, (count + 1) * sizeof(char *));
  6432. + raw[count] = NULL;
  6433. +
  6434. + free (buf);
  6435. +
  6436. + return raw;
  6437. +}
  6438. +
  6439. +/* something to remove whitespace, a hash pooper */
  6440. +char *trim_alloc(char *line)
  6441. +{
  6442. + char *new;
  6443. + char *dest, *src, *end;
  6444. +
  6445. + new = malloc(strlen(line) + 1);
  6446. + if ( new == NULL ){
  6447. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  6448. + return NULL;
  6449. + }
  6450. + dest = new, src = line, end = line + (strlen(line) - 1);
  6451. +
  6452. + /* remove it from the front */
  6453. + while(src &&
  6454. + isspace(*src) &&
  6455. + *src)
  6456. + src++;
  6457. + /* and now from the back */
  6458. + while((end > src) &&
  6459. + isspace(*end))
  6460. + end--;
  6461. + end++;
  6462. + *end = '\0';
  6463. + strcpy(new, src);
  6464. + /* this does from the first space
  6465. + * blasting away any versions stuff in depends
  6466. + while(src &&
  6467. + !isspace(*src) &&
  6468. + *src)
  6469. + *dest++ = *src++;
  6470. + *dest = '\0';
  6471. + */
  6472. +
  6473. + return new;
  6474. +}
  6475. +
  6476. +int line_is_blank(const char *line)
  6477. +{
  6478. + const char *s;
  6479. +
  6480. + for (s = line; *s; s++) {
  6481. + if (!isspace(*s))
  6482. + return 0;
  6483. + }
  6484. + return 1;
  6485. +}
  6486. +
  6487. +void push_error_list(struct errlist ** errors, char * msg){
  6488. + struct errlist *err_lst_tmp;
  6489. +
  6490. +
  6491. + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
  6492. + err_lst_tmp->errmsg=strdup(msg) ;
  6493. + err_lst_tmp->next = *errors;
  6494. + *errors = err_lst_tmp;
  6495. +}
  6496. +
  6497. +
  6498. +void reverse_error_list(struct errlist **errors){
  6499. + struct errlist *result=NULL;
  6500. + struct errlist *current= *errors;
  6501. + struct errlist *next;
  6502. +
  6503. + while ( current != NULL ) {
  6504. + next = current->next;
  6505. + current->next=result;
  6506. + result=current;
  6507. + current=next;
  6508. + }
  6509. + *errors=result;
  6510. +
  6511. +}
  6512. +
  6513. +
  6514. +void free_error_list(struct errlist **errors){
  6515. + struct errlist *current = *errors;
  6516. +
  6517. + while (current != NULL) {
  6518. + free(current->errmsg);
  6519. + current = (*errors)->next;
  6520. + free(*errors);
  6521. + *errors = current;
  6522. + }
  6523. +
  6524. +
  6525. +}
  6526. +
  6527. +
  6528. diff -Nur busybox-1.17.0.orig/archival/libipkg/ipkg_utils.h busybox-1.17.0/archival/libipkg/ipkg_utils.h
  6529. --- busybox-1.17.0.orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
  6530. +++ busybox-1.17.0/archival/libipkg/ipkg_utils.h 2010-07-15 21:53:17.166689441 +0200
  6531. @@ -0,0 +1,29 @@
  6532. +/* ipkg_utils.h - the itsy package management system
  6533. +
  6534. + Steven M. Ayer
  6535. +
  6536. + Copyright (C) 2002 Compaq Computer Corporation
  6537. +
  6538. + This program is free software; you can redistribute it and/or
  6539. + modify it under the terms of the GNU General Public License as
  6540. + published by the Free Software Foundation; either version 2, or (at
  6541. + your option) any later version.
  6542. +
  6543. + This program is distributed in the hope that it will be useful, but
  6544. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6545. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6546. + General Public License for more details.
  6547. +*/
  6548. +
  6549. +#ifndef IPKG_UTILS_H
  6550. +#define IPKG_UTILS_H
  6551. +
  6552. +#include "pkg.h"
  6553. +
  6554. +int get_available_blocks(char * filesystem);
  6555. +char **read_raw_pkgs_from_file(const char *file_name);
  6556. +char **read_raw_pkgs_from_stream(FILE *fp);
  6557. +char *trim_alloc(char * line);
  6558. +int line_is_blank(const char *line);
  6559. +
  6560. +#endif
  6561. diff -Nur busybox-1.17.0.orig/archival/libipkg/Kbuild busybox-1.17.0/archival/libipkg/Kbuild
  6562. --- busybox-1.17.0.orig/archival/libipkg/Kbuild 1970-01-01 01:00:00.000000000 +0100
  6563. +++ busybox-1.17.0/archival/libipkg/Kbuild 2010-07-15 21:53:17.247190505 +0200
  6564. @@ -0,0 +1,60 @@
  6565. +# Makefile for busybox
  6566. +#
  6567. +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  6568. +# Copyright (C) 2006 OpenWrt.org
  6569. +#
  6570. +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  6571. +
  6572. +LIBIPKG_CORE_OBJS:= \
  6573. + args.o \
  6574. + libipkg.o \
  6575. + user.o \
  6576. +
  6577. +LIBIPKG_CMD_OBJS:= \
  6578. + ipkg_cmd.o \
  6579. + ipkg_configure.o \
  6580. + ipkg_download.o \
  6581. + ipkg_install.o \
  6582. + ipkg_remove.o \
  6583. + ipkg_upgrade.o \
  6584. +
  6585. +LIBIPKG_DB_OBJS:= \
  6586. + hash_table.o \
  6587. + ipkg_conf.o \
  6588. + ipkg_utils.o \
  6589. + pkg.o \
  6590. + pkg_depends.o \
  6591. + pkg_extract.o \
  6592. + pkg_hash.o \
  6593. + pkg_parse.o \
  6594. + pkg_vec.o \
  6595. +
  6596. +LIBIPKG_LIST_OBJS:= \
  6597. + conffile.o \
  6598. + conffile_list.o \
  6599. + nv_pair.o \
  6600. + nv_pair_list.o \
  6601. + pkg_dest.o \
  6602. + pkg_dest_list.o \
  6603. + pkg_src.o \
  6604. + pkg_src_list.o \
  6605. + str_list.o \
  6606. + void_list.o \
  6607. +
  6608. +LIBIPKG_UTIL_OBJS:= \
  6609. + file_util.o \
  6610. + ipkg_message.o \
  6611. + str_util.o \
  6612. + xsystem.o \
  6613. +
  6614. +lib-y :=
  6615. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
  6616. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
  6617. +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
  6618. +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
  6619. +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
  6620. +
  6621. +ifeq ($(strip $(IPKG_ARCH)),)
  6622. +IPKG_ARCH:=$(TARGET_ARCH)
  6623. +endif
  6624. +CFLAGS += -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
  6625. diff -Nur busybox-1.17.0.orig/archival/libipkg/libipkg.c busybox-1.17.0/archival/libipkg/libipkg.c
  6626. --- busybox-1.17.0.orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
  6627. +++ busybox-1.17.0/archival/libipkg/libipkg.c 2010-07-15 23:20:48.266532316 +0200
  6628. @@ -0,0 +1,568 @@
  6629. +/* ipkglib.c - the itsy package management system
  6630. +
  6631. + Florina Boor
  6632. +
  6633. + Copyright (C) 2003 kernel concepts
  6634. +
  6635. + This program is free software; you can redistribute it and/or
  6636. + modify it under the terms of the GNU General Public License as
  6637. + published by the Free Software Foundation; either version 2, or (at
  6638. + your option) any later version.
  6639. +
  6640. + This program is distributed in the hope that it will be useful, but
  6641. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6642. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6643. + General Public License for more details.
  6644. +*/
  6645. +
  6646. +#include "ipkg.h"
  6647. +#include "ipkg_includes.h"
  6648. +#include "libipkg.h"
  6649. +
  6650. +#include "args.h"
  6651. +#include "ipkg_conf.h"
  6652. +#include "ipkg_cmd.h"
  6653. +#include "file_util.h"
  6654. +
  6655. +int ipkg_file_what(args_t *args, const char *file, const char* command);
  6656. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  6657. + char *msg);
  6658. +int default_ipkg_list_callback(char *name, char *desc, char *version);
  6659. +int default_ipkg_files_callback(char *desc);
  6660. +int default_ipkg_status_callback(char *desc);
  6661. +char* default_ipkg_response_callback(char *question);
  6662. +
  6663. +
  6664. +ipkg_message_callback ipkg_cb_message = NULL;
  6665. +ipkg_response_callback ipkg_cb_response = NULL;
  6666. +ipkg_status_callback ipkg_cb_status = NULL;
  6667. +ipkg_list_callback ipkg_cb_list = NULL;
  6668. +
  6669. +
  6670. +int
  6671. +ipkg_init (ipkg_message_callback mcall,
  6672. + ipkg_response_callback rcall,
  6673. + args_t * args)
  6674. +{
  6675. + ipkg_cb_message = mcall;
  6676. + ipkg_cb_response = rcall;
  6677. +
  6678. + args_init (args);
  6679. +
  6680. + return 0;
  6681. +}
  6682. +
  6683. +
  6684. +int
  6685. +ipkg_deinit (args_t * args)
  6686. +{
  6687. + args_deinit (args);
  6688. + ipkg_cb_message = NULL;
  6689. + ipkg_cb_response = NULL;
  6690. +
  6691. + /* place other cleanup stuff here */
  6692. +
  6693. + return 0;
  6694. +}
  6695. +
  6696. +
  6697. +int
  6698. +ipkg_packages_list(args_t *args,
  6699. + const char *packages,
  6700. + ipkg_list_callback cblist,
  6701. + void *userdata)
  6702. +{
  6703. + ipkg_cmd_t *cmd;
  6704. + ipkg_conf_t ipkg_conf;
  6705. + int err;
  6706. +
  6707. + err = ipkg_conf_init (&ipkg_conf, args);
  6708. + if (err)
  6709. + {
  6710. + return err;
  6711. + }
  6712. +
  6713. + ipkg_cb_list = cblist;
  6714. + /* we need to do this because of static declarations,
  6715. + * maybe a good idea to change */
  6716. + cmd = ipkg_cmd_find ("list");
  6717. + if (packages)
  6718. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6719. + else
  6720. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6721. + ipkg_cb_list = NULL;
  6722. + ipkg_conf_deinit (&ipkg_conf);
  6723. + return (err);
  6724. +}
  6725. +
  6726. +
  6727. +int
  6728. +ipkg_packages_status(args_t *args,
  6729. + const char *packages,
  6730. + ipkg_status_callback cbstatus,
  6731. + void *userdata)
  6732. +{
  6733. + ipkg_cmd_t *cmd;
  6734. + ipkg_conf_t ipkg_conf;
  6735. + int err;
  6736. +
  6737. + err = ipkg_conf_init (&ipkg_conf, args);
  6738. + if (err)
  6739. + {
  6740. + return err;
  6741. + }
  6742. +
  6743. + ipkg_cb_status = cbstatus;
  6744. +
  6745. + /* we need to do this because of static declarations,
  6746. + * maybe a good idea to change */
  6747. + cmd = ipkg_cmd_find ("status");
  6748. + if (packages)
  6749. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6750. + else
  6751. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6752. +
  6753. + ipkg_cb_status = NULL;
  6754. + ipkg_conf_deinit (&ipkg_conf);
  6755. + return (err);
  6756. +}
  6757. +
  6758. +
  6759. +int
  6760. +ipkg_packages_info(args_t *args,
  6761. + const char *packages,
  6762. + ipkg_status_callback cbstatus,
  6763. + void *userdata)
  6764. +{
  6765. + ipkg_cmd_t *cmd;
  6766. + ipkg_conf_t ipkg_conf;
  6767. + int err;
  6768. +
  6769. + err = ipkg_conf_init (&ipkg_conf, args);
  6770. + if (err)
  6771. + {
  6772. + return err;
  6773. + }
  6774. +
  6775. + ipkg_cb_status = cbstatus;
  6776. +
  6777. + /* we need to do this because of static declarations,
  6778. + * maybe a good idea to change */
  6779. + cmd = ipkg_cmd_find ("info");
  6780. + if (packages)
  6781. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6782. + else
  6783. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6784. +
  6785. + ipkg_cb_status = NULL;
  6786. + ipkg_conf_deinit (&ipkg_conf);
  6787. + return (err);
  6788. +}
  6789. +
  6790. +
  6791. +int
  6792. +ipkg_packages_install (args_t * args, const char *name)
  6793. +{
  6794. + ipkg_cmd_t *cmd;
  6795. + ipkg_conf_t ipkg_conf;
  6796. + int err;
  6797. +
  6798. + /* this error should be handled in application */
  6799. + if (!name || !strlen (name))
  6800. + return (-1);
  6801. +
  6802. + err = ipkg_conf_init (&ipkg_conf, args);
  6803. + if (err)
  6804. + {
  6805. + return err;
  6806. + }
  6807. +
  6808. + /* we need to do this because of static declarations,
  6809. + * maybe a good idea to change */
  6810. + cmd = ipkg_cmd_find ("install");
  6811. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6812. +
  6813. + ipkg_conf_deinit(&ipkg_conf);
  6814. + return (err);
  6815. +}
  6816. +
  6817. +
  6818. +int
  6819. +ipkg_packages_remove(args_t *args, const char *name, int purge)
  6820. +{
  6821. + ipkg_cmd_t *cmd;
  6822. + ipkg_conf_t ipkg_conf;
  6823. + int err;
  6824. +
  6825. + /* this error should be handled in application */
  6826. + if (!name || !strlen (name))
  6827. + return (-1);
  6828. +
  6829. + err = ipkg_conf_init (&ipkg_conf, args);
  6830. + if (err)
  6831. + {
  6832. + return err;
  6833. + }
  6834. +
  6835. + /* we need to do this because of static declarations,
  6836. + * maybe a good idea to change */
  6837. + if (purge)
  6838. + cmd = ipkg_cmd_find ("purge");
  6839. + else
  6840. + cmd = ipkg_cmd_find ("remove");
  6841. +
  6842. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6843. +
  6844. + ipkg_conf_deinit(&ipkg_conf);
  6845. + return (err);
  6846. +}
  6847. +
  6848. +
  6849. +int
  6850. +ipkg_lists_update(args_t *args)
  6851. +{
  6852. + ipkg_cmd_t *cmd;
  6853. + ipkg_conf_t ipkg_conf;
  6854. + int err;
  6855. +
  6856. + err = ipkg_conf_init (&ipkg_conf, args);
  6857. + if (err)
  6858. + {
  6859. + return err;
  6860. + }
  6861. +
  6862. + /* we need to do this because of static declarations,
  6863. + * maybe a good idea to change */
  6864. + cmd = ipkg_cmd_find ("update");
  6865. +
  6866. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6867. +
  6868. + ipkg_conf_deinit(&ipkg_conf);
  6869. + return (err);
  6870. +}
  6871. +
  6872. +
  6873. +int
  6874. +ipkg_packages_upgrade(args_t *args)
  6875. +{
  6876. + ipkg_cmd_t *cmd;
  6877. + ipkg_conf_t ipkg_conf;
  6878. + int err;
  6879. +
  6880. + err = ipkg_conf_init (&ipkg_conf, args);
  6881. + if (err)
  6882. + {
  6883. + return err;
  6884. + }
  6885. +
  6886. + /* we need to do this because of static declarations,
  6887. + * maybe a good idea to change */
  6888. + cmd = ipkg_cmd_find ("upgrade");
  6889. +
  6890. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6891. +
  6892. + ipkg_conf_deinit(&ipkg_conf);
  6893. + return (err);
  6894. +}
  6895. +
  6896. +
  6897. +int
  6898. +ipkg_packages_download (args_t * args, const char *name)
  6899. +{
  6900. + ipkg_cmd_t *cmd;
  6901. + ipkg_conf_t ipkg_conf;
  6902. + int err;
  6903. +
  6904. + /* this error should be handled in application */
  6905. + if (!name || !strlen (name))
  6906. + return (-1);
  6907. +
  6908. + err = ipkg_conf_init (&ipkg_conf, args);
  6909. + if (err)
  6910. + {
  6911. + return err;
  6912. + }
  6913. +
  6914. + /* we need to do this because of static declarations,
  6915. + * maybe a good idea to change */
  6916. + cmd = ipkg_cmd_find ("download");
  6917. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6918. +
  6919. + ipkg_conf_deinit(&ipkg_conf);
  6920. + return (err);
  6921. +}
  6922. +
  6923. +
  6924. +int
  6925. +ipkg_package_files(args_t *args,
  6926. + const char *name,
  6927. + ipkg_list_callback cblist,
  6928. + void *userdata)
  6929. +{
  6930. + ipkg_cmd_t *cmd;
  6931. + ipkg_conf_t ipkg_conf;
  6932. + int err;
  6933. +
  6934. + /* this error should be handled in application */
  6935. + if (!name || !strlen (name))
  6936. + return (-1);
  6937. +
  6938. + err = ipkg_conf_init (&ipkg_conf, args);
  6939. + if (err)
  6940. + {
  6941. + return err;
  6942. + }
  6943. +
  6944. + ipkg_cb_list = cblist;
  6945. +
  6946. + /* we need to do this because of static declarations,
  6947. + * maybe a good idea to change */
  6948. + cmd = ipkg_cmd_find ("files");
  6949. +
  6950. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
  6951. +
  6952. + ipkg_cb_list = NULL;
  6953. + ipkg_conf_deinit(&ipkg_conf);
  6954. + return (err);
  6955. +}
  6956. +
  6957. +
  6958. +int
  6959. +ipkg_file_search(args_t *args,
  6960. + const char *file,
  6961. + ipkg_list_callback cblist,
  6962. + void *userdata)
  6963. +{
  6964. + ipkg_cmd_t *cmd;
  6965. + ipkg_conf_t ipkg_conf;
  6966. + int err;
  6967. +
  6968. + /* this error should be handled in application */
  6969. + if (!file || !strlen (file))
  6970. + return (-1);
  6971. +
  6972. + err = ipkg_conf_init (&ipkg_conf, args);
  6973. + if (err)
  6974. + {
  6975. + return err;
  6976. + }
  6977. +
  6978. + ipkg_cb_list = cblist;
  6979. +
  6980. + /* we need to do this because of static declarations,
  6981. + * maybe a good idea to change */
  6982. + cmd = ipkg_cmd_find ("search");
  6983. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
  6984. +
  6985. + ipkg_cb_list = NULL;
  6986. + ipkg_conf_deinit(&ipkg_conf);
  6987. + return(err);
  6988. +}
  6989. +
  6990. +
  6991. +int
  6992. +ipkg_file_what(args_t *args, const char *file, const char* command)
  6993. +{
  6994. + ipkg_cmd_t *cmd;
  6995. + ipkg_conf_t ipkg_conf;
  6996. + int err;
  6997. +
  6998. + /* this error should be handled in application */
  6999. + if (!file || !strlen (file))
  7000. + return (-1);
  7001. +
  7002. + err = ipkg_conf_init (&ipkg_conf, args);
  7003. + if (err)
  7004. + {
  7005. + return err;
  7006. + }
  7007. +
  7008. + /* we need to do this because of static declarations,
  7009. + * maybe a good idea to change */
  7010. + cmd = ipkg_cmd_find (command);
  7011. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
  7012. +
  7013. + ipkg_conf_deinit(&ipkg_conf);
  7014. + return(err);
  7015. +}
  7016. +
  7017. +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
  7018. +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
  7019. +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
  7020. +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
  7021. +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
  7022. +
  7023. +
  7024. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  7025. + char *msg)
  7026. +{
  7027. + if (conf && (conf->verbosity < level)) {
  7028. + return 0;
  7029. + } else {
  7030. + if ( level == IPKG_ERROR )
  7031. + push_error_list(&error_list, msg);
  7032. + else
  7033. + printf(msg);
  7034. + }
  7035. + return 0;
  7036. +}
  7037. +
  7038. +int default_ipkg_list_callback(char *name, char *desc, char *version)
  7039. +{
  7040. + if (desc)
  7041. + printf("%s - %s - %s\n", name, version, desc);
  7042. + else
  7043. + printf("%s - %s\n", name, version);
  7044. + return 0;
  7045. +}
  7046. +
  7047. +int default_ipkg_files_callback(char *desc)
  7048. +{
  7049. + if (desc)
  7050. + printf("%s\n", desc);
  7051. + return 0;
  7052. +}
  7053. +
  7054. +int default_ipkg_status_callback(char *desc)
  7055. +{
  7056. + printf("%s\n", desc);
  7057. + return 0;
  7058. +}
  7059. +
  7060. +char* default_ipkg_response_callback(char *question)
  7061. +{
  7062. + char *response = NULL;
  7063. + printf(question);
  7064. + fflush(stdout);
  7065. + do {
  7066. + response = (char *)file_read_line_alloc(stdin);
  7067. + } while (response == NULL);
  7068. + return response;
  7069. +}
  7070. +
  7071. +/* This is used for backward compatibility */
  7072. +int
  7073. +ipkg_op (int argc, char *argv[])
  7074. +{
  7075. + int err, optind_;
  7076. + args_t args;
  7077. + char *cmd_name;
  7078. + ipkg_cmd_t *cmd;
  7079. + ipkg_conf_t ipkg_conf;
  7080. + const char *message = "ipkg must have one sub-command argument";
  7081. + FILE *f;
  7082. + struct mntent *mnt;
  7083. + int remountroot;
  7084. +
  7085. + args_init (&args);
  7086. +
  7087. + optind_ = args_parse (&args, argc, argv);
  7088. + if (optind_ == argc || optind_ < 0)
  7089. + {
  7090. + args_usage(message);
  7091. + }
  7092. +
  7093. + cmd_name = argv[optind_++];
  7094. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  7095. + read anything from there.
  7096. +*/
  7097. + if ( !strcmp(cmd_name,"print-architecture") ||
  7098. + !strcmp(cmd_name,"print_architecture") ||
  7099. + !strcmp(cmd_name,"print-installation-architecture") ||
  7100. + !strcmp(cmd_name,"print_installation_architecture") )
  7101. + args.nocheckfordirorfile = 1;
  7102. +
  7103. +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
  7104. + read anything from there.
  7105. +*/
  7106. + if ( !strcmp(cmd_name,"flag") ||
  7107. + !strcmp(cmd_name,"configure") ||
  7108. + !strcmp(cmd_name,"remove") ||
  7109. + !strcmp(cmd_name,"files") ||
  7110. + !strcmp(cmd_name,"search") ||
  7111. + !strcmp(cmd_name,"compare_versions") ||
  7112. + !strcmp(cmd_name,"compare-versions") ||
  7113. + !strcmp(cmd_name,"list_installed") ||
  7114. + !strcmp(cmd_name,"list-installed") ||
  7115. + !strcmp(cmd_name,"status") )
  7116. + args.noreadfeedsfile = 1;
  7117. +
  7118. +
  7119. + /* check if /dev/root is mounted read-only */
  7120. + if ((f = setmntent("/proc/mounts", "r")) == NULL)
  7121. + fprintf (stderr, "Checking /proc/mounts failed\n");
  7122. +
  7123. + while ((mnt = getmntent(f)) != NULL) {
  7124. + if (strcmp(mnt->mnt_fsname, "/dev/root") == 0 &&
  7125. + hasmntopt(mnt, MNTOPT_RO) != NULL)
  7126. + remountroot = 1;
  7127. + }
  7128. +
  7129. + endmntent(f);
  7130. +
  7131. + if (remountroot) {
  7132. + if ( !strcmp(cmd_name,"install") ||
  7133. + !strcmp(cmd_name,"update") ||
  7134. + !strcmp(cmd_name,"upgrade") ||
  7135. + !strcmp(cmd_name,"flag") ||
  7136. + !strcmp(cmd_name,"configure") ||
  7137. + !strcmp(cmd_name,"remove") ) {
  7138. + /* mount rootfs read-write */
  7139. + if (mount("","/",0,MS_REMOUNT,0)<0)
  7140. + fprintf (stderr, "Mounting rootfs read-write failed\n");
  7141. + }
  7142. + }
  7143. +
  7144. +
  7145. + err = ipkg_conf_init (&ipkg_conf, &args);
  7146. + if (err)
  7147. + {
  7148. + return err;
  7149. + }
  7150. +
  7151. + args_deinit (&args);
  7152. +
  7153. + ipkg_cb_message = default_ipkg_message_callback;
  7154. + ipkg_cb_response = default_ipkg_response_callback;
  7155. + ipkg_cb_status = (ipkg_status_callback)default_ipkg_status_callback;
  7156. + if ( strcmp(cmd_name, "files")==0)
  7157. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_files_callback;
  7158. + else
  7159. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_list_callback;
  7160. +
  7161. + cmd = ipkg_cmd_find (cmd_name);
  7162. + if (cmd == NULL)
  7163. + {
  7164. + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
  7165. + cmd_name);
  7166. + args_usage (NULL);
  7167. + }
  7168. +
  7169. + if (cmd->requires_args && optind_ == argc)
  7170. + {
  7171. + fprintf (stderr,
  7172. + "%s: the ``%s'' command requires at least one argument\n",
  7173. + __FUNCTION__, cmd_name);
  7174. + args_usage (NULL);
  7175. + }
  7176. +
  7177. + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind_, (const char **) (argv + optind_), NULL);
  7178. +
  7179. + ipkg_conf_deinit (&ipkg_conf);
  7180. +
  7181. + if (remountroot) {
  7182. + if ( !strcmp(cmd_name,"install") ||
  7183. + !strcmp(cmd_name,"update") ||
  7184. + !strcmp(cmd_name,"upgrade") ||
  7185. + !strcmp(cmd_name,"flag") ||
  7186. + !strcmp(cmd_name,"configure") ||
  7187. + !strcmp(cmd_name,"remove") ) {
  7188. + sync();
  7189. + /* mount rootfs read-only */
  7190. + if (mount("","/",0,MS_REMOUNT|MS_RDONLY,0)<0)
  7191. + fprintf (stderr, "Mounting rootfs read-only failed\n");
  7192. + }
  7193. + }
  7194. +
  7195. + return err;
  7196. +}
  7197. diff -Nur busybox-1.17.0.orig/archival/libipkg/libipkg.h busybox-1.17.0/archival/libipkg/libipkg.h
  7198. --- busybox-1.17.0.orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
  7199. +++ busybox-1.17.0/archival/libipkg/libipkg.h 2010-07-15 21:53:17.408358605 +0200
  7200. @@ -0,0 +1,78 @@
  7201. +/* ipkglib.h - the itsy package management system
  7202. +
  7203. + Florian Boor <florian.boor@kernelconcepts.de>
  7204. +
  7205. + This program is free software; you can redistribute it and/or
  7206. + modify it under the terms of the GNU General Public License as
  7207. + published by the Free Software Foundation; either version 2, or (at
  7208. + your option) any later version.
  7209. +
  7210. + This program is distributed in the hope that it will be useful, but
  7211. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7212. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7213. + General Public License for more details.
  7214. +*/
  7215. +
  7216. +#ifndef IPKGLIB_H
  7217. +#define IPKGLIB_H
  7218. +
  7219. +#include "ipkg_conf.h"
  7220. +#include "ipkg_message.h"
  7221. +
  7222. +#include "args.h"
  7223. +#include "pkg.h"
  7224. +
  7225. +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
  7226. + char *msg);
  7227. +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
  7228. + pkg_state_status_t status, void *userdata);
  7229. +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
  7230. + void *userdata);
  7231. +typedef char* (*ipkg_response_callback)(char *question);
  7232. +
  7233. +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
  7234. +extern int ipkg_init (ipkg_message_callback mcall,
  7235. + ipkg_response_callback rcall,
  7236. + args_t * args);
  7237. +
  7238. +extern int ipkg_deinit (args_t *args);
  7239. +extern int ipkg_packages_list(args_t *args,
  7240. + const char *packages,
  7241. + ipkg_list_callback cblist,
  7242. + void *userdata);
  7243. +extern int ipkg_packages_status(args_t *args,
  7244. + const char *packages,
  7245. + ipkg_status_callback cbstatus,
  7246. + void *userdata);
  7247. +extern int ipkg_packages_info(args_t *args,
  7248. + const char *packages,
  7249. + ipkg_status_callback cbstatus,
  7250. + void *userdata);
  7251. +extern int ipkg_packages_install(args_t *args, const char *name);
  7252. +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
  7253. +extern int ipkg_lists_update(args_t *args);
  7254. +extern int ipkg_packages_upgrade(args_t *args);
  7255. +extern int ipkg_packages_download(args_t *args, const char *name);
  7256. +extern int ipkg_package_files(args_t *args,
  7257. + const char *name,
  7258. + ipkg_list_callback cblist,
  7259. + void *userdata);
  7260. +extern int ipkg_file_search(args_t *args,
  7261. + const char *file,
  7262. + ipkg_list_callback cblist,
  7263. + void *userdata);
  7264. +extern int ipkg_package_whatdepends(args_t *args, const char *file);
  7265. +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
  7266. +extern int ipkg_package_whatprovides(args_t *args, const char *file);
  7267. +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
  7268. +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
  7269. +
  7270. +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
  7271. +extern ipkg_response_callback ipkg_cb_response;
  7272. +extern ipkg_status_callback ipkg_cb_status;
  7273. +extern ipkg_list_callback ipkg_cb_list;
  7274. +extern void push_error_list(struct errlist **errors,char * msg);
  7275. +extern void reverse_error_list(struct errlist **errors);
  7276. +extern void free_error_list(struct errlist **errors);
  7277. +
  7278. +#endif
  7279. diff -Nur busybox-1.17.0.orig/archival/libipkg/nv_pair.c busybox-1.17.0/archival/libipkg/nv_pair.c
  7280. --- busybox-1.17.0.orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
  7281. +++ busybox-1.17.0/archival/libipkg/nv_pair.c 2010-07-15 21:53:17.465860022 +0200
  7282. @@ -0,0 +1,40 @@
  7283. +/* nv_pair.c - the itsy package management system
  7284. +
  7285. + Carl D. Worth
  7286. +
  7287. + Copyright (C) 2001 University of Southern California
  7288. +
  7289. + This program is free software; you can redistribute it and/or
  7290. + modify it under the terms of the GNU General Public License as
  7291. + published by the Free Software Foundation; either version 2, or (at
  7292. + your option) any later version.
  7293. +
  7294. + This program is distributed in the hope that it will be useful, but
  7295. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7296. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7297. + General Public License for more details.
  7298. +*/
  7299. +
  7300. +#include "ipkg.h"
  7301. +
  7302. +#include "nv_pair.h"
  7303. +#include "str_util.h"
  7304. +
  7305. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
  7306. +{
  7307. + nv_pair->name = str_dup_safe(name);
  7308. + nv_pair->value = str_dup_safe(value);
  7309. +
  7310. + return 0;
  7311. +}
  7312. +
  7313. +void nv_pair_deinit(nv_pair_t *nv_pair)
  7314. +{
  7315. + free(nv_pair->name);
  7316. + nv_pair->name = NULL;
  7317. +
  7318. + free(nv_pair->value);
  7319. + nv_pair->value = NULL;
  7320. +}
  7321. +
  7322. +
  7323. diff -Nur busybox-1.17.0.orig/archival/libipkg/nv_pair.h busybox-1.17.0/archival/libipkg/nv_pair.h
  7324. --- busybox-1.17.0.orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
  7325. +++ busybox-1.17.0/archival/libipkg/nv_pair.h 2010-07-15 21:53:17.526477558 +0200
  7326. @@ -0,0 +1,32 @@
  7327. +/* nv_pair.h - the itsy package management system
  7328. +
  7329. + Carl D. Worth
  7330. +
  7331. + Copyright (C) 2001 University of Southern California
  7332. +
  7333. + This program is free software; you can redistribute it and/or
  7334. + modify it under the terms of the GNU General Public License as
  7335. + published by the Free Software Foundation; either version 2, or (at
  7336. + your option) any later version.
  7337. +
  7338. + This program is distributed in the hope that it will be useful, but
  7339. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7340. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7341. + General Public License for more details.
  7342. +*/
  7343. +
  7344. +#ifndef NV_PAIR_H
  7345. +#define NV_PAIR_H
  7346. +
  7347. +typedef struct nv_pair nv_pair_t;
  7348. +struct nv_pair
  7349. +{
  7350. + char *name;
  7351. + char *value;
  7352. +};
  7353. +
  7354. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
  7355. +void nv_pair_deinit(nv_pair_t *nv_pair);
  7356. +
  7357. +#endif
  7358. +
  7359. diff -Nur busybox-1.17.0.orig/archival/libipkg/nv_pair_list.c busybox-1.17.0/archival/libipkg/nv_pair_list.c
  7360. --- busybox-1.17.0.orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
  7361. +++ busybox-1.17.0/archival/libipkg/nv_pair_list.c 2010-07-15 21:53:17.636164506 +0200
  7362. @@ -0,0 +1,98 @@
  7363. +/* nv_pair_list.c - the itsy package management system
  7364. +
  7365. + Carl D. Worth
  7366. +
  7367. + Copyright (C) 2001 University of Southern California
  7368. +
  7369. + This program is free software; you can redistribute it and/or
  7370. + modify it under the terms of the GNU General Public License as
  7371. + published by the Free Software Foundation; either version 2, or (at
  7372. + your option) any later version.
  7373. +
  7374. + This program is distributed in the hope that it will be useful, but
  7375. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7376. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7377. + General Public License for more details.
  7378. +*/
  7379. +
  7380. +#include "ipkg.h"
  7381. +
  7382. +#include "nv_pair.h"
  7383. +#include "void_list.h"
  7384. +#include "nv_pair_list.h"
  7385. +
  7386. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
  7387. +{
  7388. + return void_list_elt_init((void_list_elt_t *) elt, data);
  7389. +}
  7390. +
  7391. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
  7392. +{
  7393. + void_list_elt_deinit((void_list_elt_t *) elt);
  7394. +}
  7395. +
  7396. +int nv_pair_list_init(nv_pair_list_t *list)
  7397. +{
  7398. + return void_list_init((void_list_t *) list);
  7399. +}
  7400. +
  7401. +void nv_pair_list_deinit(nv_pair_list_t *list)
  7402. +{
  7403. + nv_pair_list_elt_t *iter;
  7404. + nv_pair_t *nv_pair;
  7405. +
  7406. + for (iter = list->head; iter; iter = iter->next) {
  7407. + nv_pair = iter->data;
  7408. + nv_pair_deinit(nv_pair);
  7409. +
  7410. + /* malloced in nv_pair_list_append */
  7411. + free(nv_pair);
  7412. + iter->data = NULL;
  7413. + }
  7414. + void_list_deinit((void_list_t *) list);
  7415. +}
  7416. +
  7417. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
  7418. +{
  7419. + int err;
  7420. +
  7421. + /* freed in nv_pair_list_deinit */
  7422. + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
  7423. +
  7424. + if (nv_pair == NULL) {
  7425. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7426. + return NULL;
  7427. + }
  7428. + nv_pair_init(nv_pair, name, value);
  7429. +
  7430. + err = void_list_append((void_list_t *) list, nv_pair);
  7431. + if (err) {
  7432. + return NULL;
  7433. + }
  7434. +
  7435. + return nv_pair;
  7436. +}
  7437. +
  7438. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
  7439. +{
  7440. + return void_list_push((void_list_t *) list, data);
  7441. +}
  7442. +
  7443. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
  7444. +{
  7445. + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
  7446. +}
  7447. +
  7448. +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
  7449. +{
  7450. + nv_pair_list_elt_t *iter;
  7451. + nv_pair_t *nv_pair;
  7452. +
  7453. + for (iter = list->head; iter; iter = iter->next) {
  7454. + nv_pair = iter->data;
  7455. + if (strcmp(nv_pair->name, name) == 0) {
  7456. + return nv_pair->value;
  7457. + }
  7458. + }
  7459. + return NULL;
  7460. +}
  7461. diff -Nur busybox-1.17.0.orig/archival/libipkg/nv_pair_list.h busybox-1.17.0/archival/libipkg/nv_pair_list.h
  7462. --- busybox-1.17.0.orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
  7463. +++ busybox-1.17.0/archival/libipkg/nv_pair_list.h 2010-07-15 21:53:17.715950659 +0200
  7464. @@ -0,0 +1,60 @@
  7465. +/* nv_pair_list.h - the itsy package management system
  7466. +
  7467. + Carl D. Worth
  7468. +
  7469. + Copyright (C) 2001 University of Southern California
  7470. +
  7471. + This program is free software; you can redistribute it and/or
  7472. + modify it under the terms of the GNU General Public License as
  7473. + published by the Free Software Foundation; either version 2, or (at
  7474. + your option) any later version.
  7475. +
  7476. + This program is distributed in the hope that it will be useful, but
  7477. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7478. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7479. + General Public License for more details.
  7480. +*/
  7481. +
  7482. +#ifndef NV_PAIR_LIST_H
  7483. +#define NV_PAIR_LIST_H
  7484. +
  7485. +#include "nv_pair.h"
  7486. +#include "void_list.h"
  7487. +
  7488. +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
  7489. +struct nv_pair_list_elt
  7490. +{
  7491. + nv_pair_list_elt_t *next;
  7492. + nv_pair_t *data;
  7493. +};
  7494. +
  7495. +typedef struct nv_pair_list nv_pair_list_t;
  7496. +struct nv_pair_list
  7497. +{
  7498. + nv_pair_list_elt_t pre_head;
  7499. + nv_pair_list_elt_t *head;
  7500. + nv_pair_list_elt_t *tail;
  7501. +};
  7502. +
  7503. +static inline int nv_pair_list_empty(nv_pair_list_t *list)
  7504. +{
  7505. + if (list->head == NULL)
  7506. + return 1;
  7507. + else
  7508. + return 0;
  7509. +}
  7510. +
  7511. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
  7512. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
  7513. +
  7514. +int nv_pair_list_init(nv_pair_list_t *list);
  7515. +void nv_pair_list_deinit(nv_pair_list_t *list);
  7516. +
  7517. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
  7518. + const char *name, const char *value);
  7519. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
  7520. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
  7521. +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
  7522. +
  7523. +#endif
  7524. +
  7525. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg.c busybox-1.17.0/archival/libipkg/pkg.c
  7526. --- busybox-1.17.0.orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
  7527. +++ busybox-1.17.0/archival/libipkg/pkg.c 2010-07-15 21:53:17.787221929 +0200
  7528. @@ -0,0 +1,1757 @@
  7529. +/* pkg.c - the itsy package management system
  7530. +
  7531. + Carl D. Worth
  7532. +
  7533. + Copyright (C) 2001 University of Southern California
  7534. +
  7535. + This program is free software; you can redistribute it and/or
  7536. + modify it under the terms of the GNU General Public License as
  7537. + published by the Free Software Foundation; either version 2, or (at
  7538. + your option) any later version.
  7539. +
  7540. + This program is distributed in the hope that it will be useful, but
  7541. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7542. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7543. + General Public License for more details.
  7544. +*/
  7545. +
  7546. +#include "ipkg.h"
  7547. +#include <ctype.h>
  7548. +#include <string.h>
  7549. +#include <errno.h>
  7550. +
  7551. +#include "pkg.h"
  7552. +
  7553. +#include "pkg_parse.h"
  7554. +#include "pkg_extract.h"
  7555. +#include "ipkg_message.h"
  7556. +#include "ipkg_utils.h"
  7557. +
  7558. +#include "sprintf_alloc.h"
  7559. +#include "file_util.h"
  7560. +#include "str_util.h"
  7561. +#include "xsystem.h"
  7562. +#include "ipkg_conf.h"
  7563. +
  7564. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname);
  7565. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_);
  7566. +
  7567. +typedef struct enum_map enum_map_t;
  7568. +struct enum_map
  7569. +{
  7570. + int value;
  7571. + const char *str;
  7572. +};
  7573. +
  7574. +static const enum_map_t pkg_state_want_map[] = {
  7575. + { SW_UNKNOWN, "unknown"},
  7576. + { SW_INSTALL, "install"},
  7577. + { SW_DEINSTALL, "deinstall"},
  7578. + { SW_PURGE, "purge"}
  7579. +};
  7580. +
  7581. +static const enum_map_t pkg_state_flag_map[] = {
  7582. + { SF_OK, "ok"},
  7583. + { SF_REINSTREQ, "reinstreq"},
  7584. + { SF_HOLD, "hold"},
  7585. + { SF_REPLACE, "replace"},
  7586. + { SF_NOPRUNE, "noprune"},
  7587. + { SF_PREFER, "prefer"},
  7588. + { SF_OBSOLETE, "obsolete"},
  7589. + { SF_USER, "user"},
  7590. +};
  7591. +
  7592. +static const enum_map_t pkg_state_status_map[] = {
  7593. + { SS_NOT_INSTALLED, "not-installed" },
  7594. + { SS_UNPACKED, "unpacked" },
  7595. + { SS_HALF_CONFIGURED, "half-configured" },
  7596. + { SS_INSTALLED, "installed" },
  7597. + { SS_HALF_INSTALLED, "half-installed" },
  7598. + { SS_CONFIG_FILES, "config-files" },
  7599. + { SS_POST_INST_FAILED, "post-inst-failed" },
  7600. + { SS_REMOVAL_FAILED, "removal-failed" }
  7601. +};
  7602. +
  7603. +static int verrevcmp(const char *val, const char *ref);
  7604. +
  7605. +
  7606. +pkg_t *pkg_new(void)
  7607. +{
  7608. + pkg_t *pkg;
  7609. +
  7610. + pkg = malloc(sizeof(pkg_t));
  7611. + if (pkg == NULL) {
  7612. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7613. + return NULL;
  7614. + }
  7615. +
  7616. + pkg_init(pkg);
  7617. +
  7618. + return pkg;
  7619. +}
  7620. +
  7621. +int pkg_init(pkg_t *pkg)
  7622. +{
  7623. + memset(pkg, 0, sizeof(pkg_t));
  7624. + pkg->name = NULL;
  7625. + pkg->epoch = 0;
  7626. + pkg->version = NULL;
  7627. + pkg->revision = NULL;
  7628. + pkg->familiar_revision = NULL;
  7629. + pkg->dest = NULL;
  7630. + pkg->src = NULL;
  7631. + pkg->architecture = NULL;
  7632. + pkg->maintainer = NULL;
  7633. + pkg->section = NULL;
  7634. + pkg->description = NULL;
  7635. + pkg->state_want = SW_UNKNOWN;
  7636. + pkg->state_flag = SF_OK;
  7637. + pkg->state_status = SS_NOT_INSTALLED;
  7638. + pkg->depends_str = NULL;
  7639. + pkg->provides_str = NULL;
  7640. + pkg->depends_count = 0;
  7641. + pkg->depends = NULL;
  7642. + pkg->suggests_str = NULL;
  7643. + pkg->recommends_str = NULL;
  7644. + pkg->suggests_count = 0;
  7645. + pkg->recommends_count = 0;
  7646. +
  7647. + /* Abhaya: added init for conflicts fields */
  7648. + pkg->conflicts = NULL;
  7649. + pkg->conflicts_count = 0;
  7650. +
  7651. + /* added for replaces. Jamey 7/23/2002 */
  7652. + pkg->replaces = NULL;
  7653. + pkg->replaces_count = 0;
  7654. +
  7655. + pkg->pre_depends_count = 0;
  7656. + pkg->pre_depends_str = NULL;
  7657. + pkg->provides_count = 0;
  7658. + pkg->provides = NULL;
  7659. + pkg->filename = NULL;
  7660. + pkg->local_filename = NULL;
  7661. + pkg->tmp_unpack_dir = NULL;
  7662. + pkg->md5sum = NULL;
  7663. + pkg->size = NULL;
  7664. + pkg->installed_size = NULL;
  7665. + pkg->priority = NULL;
  7666. + pkg->source = NULL;
  7667. + conffile_list_init(&pkg->conffiles);
  7668. + pkg->installed_files = NULL;
  7669. + pkg->installed_files_ref_cnt = 0;
  7670. + pkg->essential = 0;
  7671. + pkg->provided_by_hand = 0;
  7672. +
  7673. + return 0;
  7674. +}
  7675. +
  7676. +void pkg_deinit(pkg_t *pkg)
  7677. +{
  7678. + free(pkg->name);
  7679. + pkg->name = NULL;
  7680. + pkg->epoch = 0;
  7681. + free(pkg->version);
  7682. + pkg->version = NULL;
  7683. + /* revision and familiar_revision share storage with version, so
  7684. + don't free */
  7685. + pkg->revision = NULL;
  7686. + pkg->familiar_revision = NULL;
  7687. + /* owned by ipkg_conf_t */
  7688. + pkg->dest = NULL;
  7689. + /* owned by ipkg_conf_t */
  7690. + pkg->src = NULL;
  7691. + free(pkg->architecture);
  7692. + pkg->architecture = NULL;
  7693. + free(pkg->maintainer);
  7694. + pkg->maintainer = NULL;
  7695. + free(pkg->section);
  7696. + pkg->section = NULL;
  7697. + free(pkg->description);
  7698. + pkg->description = NULL;
  7699. + pkg->state_want = SW_UNKNOWN;
  7700. + pkg->state_flag = SF_OK;
  7701. + pkg->state_status = SS_NOT_INSTALLED;
  7702. + free(pkg->depends_str);
  7703. + pkg->depends_str = NULL;
  7704. + free(pkg->provides_str);
  7705. + pkg->provides_str = NULL;
  7706. + pkg->depends_count = 0;
  7707. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
  7708. + pkg->pre_depends_count = 0;
  7709. + free(pkg->pre_depends_str);
  7710. + pkg->pre_depends_str = NULL;
  7711. + pkg->provides_count = 0;
  7712. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
  7713. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
  7714. + free(pkg->filename);
  7715. + pkg->filename = NULL;
  7716. + free(pkg->local_filename);
  7717. + pkg->local_filename = NULL;
  7718. + /* CLEANUP: It'd be nice to pullin the cleanup function from
  7719. + ipkg_install.c here. See comment in
  7720. + ipkg_install.c:cleanup_temporary_files */
  7721. + free(pkg->tmp_unpack_dir);
  7722. + pkg->tmp_unpack_dir = NULL;
  7723. + free(pkg->md5sum);
  7724. + pkg->md5sum = NULL;
  7725. + free(pkg->size);
  7726. + pkg->size = NULL;
  7727. + free(pkg->installed_size);
  7728. + pkg->installed_size = NULL;
  7729. + free(pkg->priority);
  7730. + pkg->priority = NULL;
  7731. + free(pkg->source);
  7732. + pkg->source = NULL;
  7733. + conffile_list_deinit(&pkg->conffiles);
  7734. + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
  7735. + since if they are calling deinit, they should know. Maybe do an
  7736. + assertion here instead? */
  7737. + pkg->installed_files_ref_cnt = 1;
  7738. + pkg_free_installed_files(pkg);
  7739. + pkg->essential = 0;
  7740. +}
  7741. +
  7742. +int pkg_init_from_file(pkg_t *pkg, const char *filename)
  7743. +{
  7744. + int err;
  7745. + char **raw;
  7746. + FILE *control_file;
  7747. +
  7748. + err = pkg_init(pkg);
  7749. + if (err) { return err; }
  7750. +
  7751. + pkg->local_filename = strdup(filename);
  7752. +
  7753. + control_file = tmpfile();
  7754. + err = pkg_extract_control_file_to_stream(pkg, control_file);
  7755. + if (err) { return err; }
  7756. +
  7757. + rewind(control_file);
  7758. + raw = read_raw_pkgs_from_stream(control_file);
  7759. + pkg_parse_raw(pkg, &raw, NULL, NULL);
  7760. +
  7761. + fclose(control_file);
  7762. +
  7763. + return 0;
  7764. +}
  7765. +
  7766. +/* Merge any new information in newpkg into oldpkg */
  7767. +/* XXX: CLEANUP: This function shouldn't actually modify anything in
  7768. + newpkg, but should leave it usable. This rework is so that
  7769. + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
  7770. +/*
  7771. + * uh, i thought that i had originally written this so that it took
  7772. + * two pkgs and returned a new one? we can do that again... -sma
  7773. + */
  7774. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
  7775. +{
  7776. + if (oldpkg == newpkg) {
  7777. + return 0;
  7778. + }
  7779. +
  7780. + if (!oldpkg->src)
  7781. + oldpkg->src = newpkg->src;
  7782. + if (!oldpkg->dest)
  7783. + oldpkg->dest = newpkg->dest;
  7784. + if (!oldpkg->architecture)
  7785. + oldpkg->architecture = str_dup_safe(newpkg->architecture);
  7786. + if (!oldpkg->arch_priority)
  7787. + oldpkg->arch_priority = newpkg->arch_priority;
  7788. + if (!oldpkg->section)
  7789. + oldpkg->section = str_dup_safe(newpkg->section);
  7790. + if(!oldpkg->maintainer)
  7791. + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
  7792. + if(!oldpkg->description)
  7793. + oldpkg->description = str_dup_safe(newpkg->description);
  7794. + if (set_status) {
  7795. + /* merge the state_flags from the new package */
  7796. + oldpkg->state_want = newpkg->state_want;
  7797. + oldpkg->state_status = newpkg->state_status;
  7798. + oldpkg->state_flag = newpkg->state_flag;
  7799. + } else {
  7800. + if (oldpkg->state_want == SW_UNKNOWN)
  7801. + oldpkg->state_want = newpkg->state_want;
  7802. + if (oldpkg->state_status == SS_NOT_INSTALLED)
  7803. + oldpkg->state_status = newpkg->state_status;
  7804. + oldpkg->state_flag |= newpkg->state_flag;
  7805. + }
  7806. +
  7807. + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
  7808. + oldpkg->depends_str = newpkg->depends_str;
  7809. + newpkg->depends_str = NULL;
  7810. + oldpkg->depends_count = newpkg->depends_count;
  7811. + newpkg->depends_count = 0;
  7812. +
  7813. + oldpkg->depends = newpkg->depends;
  7814. + newpkg->depends = NULL;
  7815. +
  7816. + oldpkg->pre_depends_str = newpkg->pre_depends_str;
  7817. + newpkg->pre_depends_str = NULL;
  7818. + oldpkg->pre_depends_count = newpkg->pre_depends_count;
  7819. + newpkg->pre_depends_count = 0;
  7820. +
  7821. + oldpkg->recommends_str = newpkg->recommends_str;
  7822. + newpkg->recommends_str = NULL;
  7823. + oldpkg->recommends_count = newpkg->recommends_count;
  7824. + newpkg->recommends_count = 0;
  7825. +
  7826. + oldpkg->suggests_str = newpkg->suggests_str;
  7827. + newpkg->suggests_str = NULL;
  7828. + oldpkg->suggests_count = newpkg->suggests_count;
  7829. + newpkg->suggests_count = 0;
  7830. + }
  7831. +
  7832. + if (!oldpkg->provides_str) {
  7833. + oldpkg->provides_str = newpkg->provides_str;
  7834. + newpkg->provides_str = NULL;
  7835. + oldpkg->provides_count = newpkg->provides_count;
  7836. + newpkg->provides_count = 0;
  7837. +
  7838. + oldpkg->provides = newpkg->provides;
  7839. + newpkg->provides = NULL;
  7840. + }
  7841. +
  7842. + if (!oldpkg->conflicts_str) {
  7843. + oldpkg->conflicts_str = newpkg->conflicts_str;
  7844. + newpkg->conflicts_str = NULL;
  7845. + oldpkg->conflicts_count = newpkg->conflicts_count;
  7846. + newpkg->conflicts_count = 0;
  7847. +
  7848. + oldpkg->conflicts = newpkg->conflicts;
  7849. + newpkg->conflicts = NULL;
  7850. + }
  7851. +
  7852. + if (!oldpkg->replaces_str) {
  7853. + oldpkg->replaces_str = newpkg->replaces_str;
  7854. + newpkg->replaces_str = NULL;
  7855. + oldpkg->replaces_count = newpkg->replaces_count;
  7856. + newpkg->replaces_count = 0;
  7857. +
  7858. + oldpkg->replaces = newpkg->replaces;
  7859. + newpkg->replaces = NULL;
  7860. + }
  7861. +
  7862. + if (!oldpkg->filename)
  7863. + oldpkg->filename = str_dup_safe(newpkg->filename);
  7864. + if (0)
  7865. + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
  7866. + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
  7867. + if (!oldpkg->local_filename)
  7868. + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
  7869. + if (!oldpkg->tmp_unpack_dir)
  7870. + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
  7871. + if (!oldpkg->md5sum)
  7872. + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
  7873. + if (!oldpkg->size)
  7874. + oldpkg->size = str_dup_safe(newpkg->size);
  7875. + if (!oldpkg->installed_size)
  7876. + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
  7877. + if (!oldpkg->priority)
  7878. + oldpkg->priority = str_dup_safe(newpkg->priority);
  7879. + if (!oldpkg->source)
  7880. + oldpkg->source = str_dup_safe(newpkg->source);
  7881. + if (oldpkg->conffiles.head == NULL){
  7882. + oldpkg->conffiles = newpkg->conffiles;
  7883. + conffile_list_init(&newpkg->conffiles);
  7884. + }
  7885. + if (!oldpkg->installed_files){
  7886. + oldpkg->installed_files = newpkg->installed_files;
  7887. + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
  7888. + newpkg->installed_files = NULL;
  7889. + }
  7890. + if (!oldpkg->essential)
  7891. + oldpkg->essential = newpkg->essential;
  7892. +
  7893. + return 0;
  7894. +}
  7895. +
  7896. +abstract_pkg_t *abstract_pkg_new(void)
  7897. +{
  7898. + abstract_pkg_t * ab_pkg;
  7899. +
  7900. + ab_pkg = malloc(sizeof(abstract_pkg_t));
  7901. +
  7902. + if (ab_pkg == NULL) {
  7903. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7904. + return NULL;
  7905. + }
  7906. +
  7907. + if ( abstract_pkg_init(ab_pkg) < 0 )
  7908. + return NULL;
  7909. +
  7910. + return ab_pkg;
  7911. +}
  7912. +
  7913. +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
  7914. +{
  7915. + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
  7916. +
  7917. + ab_pkg->provided_by = abstract_pkg_vec_alloc();
  7918. + if (ab_pkg->provided_by==NULL){
  7919. + return -1;
  7920. + }
  7921. + ab_pkg->dependencies_checked = 0;
  7922. + ab_pkg->state_status = SS_NOT_INSTALLED;
  7923. +
  7924. + return 0;
  7925. +}
  7926. +
  7927. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
  7928. + char * temp_str;
  7929. + char **raw =NULL;
  7930. + char **raw_start=NULL;
  7931. +
  7932. + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
  7933. + if (temp_str == NULL ){
  7934. + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
  7935. + return;
  7936. + }
  7937. + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
  7938. +
  7939. + raw = raw_start = read_raw_pkgs_from_file(temp_str);
  7940. + if (raw == NULL ){
  7941. + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
  7942. + return;
  7943. + }
  7944. +
  7945. + while(*raw){
  7946. + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
  7947. + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
  7948. + }
  7949. + }
  7950. + raw = raw_start;
  7951. + while (*raw) {
  7952. + if (raw!=NULL)
  7953. + free(*raw++);
  7954. + }
  7955. +
  7956. + free(raw_start);
  7957. + free(temp_str);
  7958. +
  7959. + return ;
  7960. +
  7961. +}
  7962. +
  7963. +char * pkg_formatted_info(pkg_t *pkg )
  7964. +{
  7965. + char *line;
  7966. + char * buff;
  7967. +
  7968. + buff = malloc(8192);
  7969. + if (buff == NULL) {
  7970. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7971. + return NULL;
  7972. + }
  7973. +
  7974. + buff[0] = '\0';
  7975. +
  7976. + line = pkg_formatted_field(pkg, "Package");
  7977. + strncat(buff ,line, strlen(line));
  7978. + free(line);
  7979. +
  7980. + line = pkg_formatted_field(pkg, "Version");
  7981. + strncat(buff ,line, strlen(line));
  7982. + free(line);
  7983. +
  7984. + line = pkg_formatted_field(pkg, "Depends");
  7985. + strncat(buff ,line, strlen(line));
  7986. + free(line);
  7987. +
  7988. + line = pkg_formatted_field(pkg, "Recommends");
  7989. + strncat(buff ,line, strlen(line));
  7990. + free(line);
  7991. +
  7992. + line = pkg_formatted_field(pkg, "Suggests");
  7993. + strncat(buff ,line, strlen(line));
  7994. + free(line);
  7995. +
  7996. + line = pkg_formatted_field(pkg, "Provides");
  7997. + strncat(buff ,line, strlen(line));
  7998. + free(line);
  7999. +
  8000. + line = pkg_formatted_field(pkg, "Replaces");
  8001. + strncat(buff ,line, strlen(line));
  8002. + free(line);
  8003. +
  8004. + line = pkg_formatted_field(pkg, "Conflicts");
  8005. + strncat(buff ,line, strlen(line));
  8006. + free(line);
  8007. +
  8008. + line = pkg_formatted_field(pkg, "Status");
  8009. + strncat(buff ,line, strlen(line));
  8010. + free(line);
  8011. +
  8012. + line = pkg_formatted_field(pkg, "Section");
  8013. + strncat(buff ,line, strlen(line));
  8014. + free(line);
  8015. +
  8016. + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
  8017. + strncat(buff ,line, strlen(line));
  8018. + free(line);
  8019. +
  8020. + line = pkg_formatted_field(pkg, "Architecture");
  8021. + strncat(buff ,line, strlen(line));
  8022. + free(line);
  8023. +
  8024. + line = pkg_formatted_field(pkg, "Maintainer");
  8025. + strncat(buff ,line, strlen(line));
  8026. + free(line);
  8027. +
  8028. + line = pkg_formatted_field(pkg, "MD5sum");
  8029. + strncat(buff ,line, strlen(line));
  8030. + free(line);
  8031. +
  8032. + line = pkg_formatted_field(pkg, "Size");
  8033. + strncat(buff ,line, strlen(line));
  8034. + free(line);
  8035. +
  8036. + line = pkg_formatted_field(pkg, "Filename");
  8037. + strncat(buff ,line, strlen(line));
  8038. + free(line);
  8039. +
  8040. + line = pkg_formatted_field(pkg, "Conffiles");
  8041. + strncat(buff ,line, strlen(line));
  8042. + free(line);
  8043. +
  8044. + line = pkg_formatted_field(pkg, "Source");
  8045. + strncat(buff ,line, strlen(line));
  8046. + free(line);
  8047. +
  8048. + line = pkg_formatted_field(pkg, "Description");
  8049. + strncat(buff ,line, strlen(line));
  8050. + free(line);
  8051. +
  8052. + line = pkg_formatted_field(pkg, "Installed-Time");
  8053. + strncat(buff ,line, strlen(line));
  8054. + free(line);
  8055. +
  8056. + return buff;
  8057. +}
  8058. +
  8059. +char * pkg_formatted_field(pkg_t *pkg, const char *field )
  8060. +{
  8061. + static size_t LINE_LEN = 128;
  8062. + char * temp = (char *)malloc(1);
  8063. + int len = 0;
  8064. + int flag_provide_false = 0;
  8065. +
  8066. +/*
  8067. + Pigi: After some discussion with Florian we decided to modify the full procedure in
  8068. + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
  8069. +*/
  8070. +
  8071. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8072. + goto UNKNOWN_FMT_FIELD;
  8073. + }
  8074. +
  8075. + temp[0]='\0';
  8076. +
  8077. + switch (field[0])
  8078. + {
  8079. + case 'a':
  8080. + case 'A':
  8081. + if (strcasecmp(field, "Architecture") == 0) {
  8082. + /* Architecture */
  8083. + if (pkg->architecture) {
  8084. + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
  8085. + if ( temp == NULL ){
  8086. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8087. + return NULL;
  8088. + }
  8089. + temp[0]='\0';
  8090. + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
  8091. + }
  8092. + } else {
  8093. + goto UNKNOWN_FMT_FIELD;
  8094. + }
  8095. + break;
  8096. + case 'c':
  8097. + case 'C':
  8098. + if (strcasecmp(field, "Conffiles") == 0) {
  8099. + /* Conffiles */
  8100. + conffile_list_elt_t *iter;
  8101. + char confstr_[LINE_LEN];
  8102. +
  8103. + if (pkg->conffiles.head == NULL) {
  8104. + return temp;
  8105. + }
  8106. +
  8107. + len = 14 ;
  8108. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8109. + if (iter->data->name && iter->data->value) {
  8110. + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
  8111. + }
  8112. + }
  8113. + temp = (char *)realloc(temp,len);
  8114. + if ( temp == NULL ){
  8115. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8116. + return NULL;
  8117. + }
  8118. + temp[0]='\0';
  8119. + strncpy(temp, "Conffiles:\n", 12);
  8120. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8121. + if (iter->data->name && iter->data->value) {
  8122. + snprintf(confstr_, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
  8123. + strncat(temp, confstr_, strlen(confstr_));
  8124. + }
  8125. + }
  8126. + } else if (strcasecmp(field, "Conflicts") == 0) {
  8127. + int i;
  8128. +
  8129. + if (pkg->conflicts_count) {
  8130. + char conflictstr[LINE_LEN];
  8131. + len = 14 ;
  8132. + for(i = 0; i < pkg->conflicts_count; i++) {
  8133. + len = len + (strlen(pkg->conflicts_str[i])+5);
  8134. + }
  8135. + temp = (char *)realloc(temp,len);
  8136. + if ( temp == NULL ){
  8137. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8138. + return NULL;
  8139. + }
  8140. + temp[0]='\0';
  8141. + strncpy(temp, "Conflicts:", 11);
  8142. + for(i = 0; i < pkg->conflicts_count; i++) {
  8143. + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
  8144. + strncat(temp, conflictstr, strlen(conflictstr));
  8145. + }
  8146. + strncat(temp, "\n", strlen("\n"));
  8147. + }
  8148. + } else {
  8149. + goto UNKNOWN_FMT_FIELD;
  8150. + }
  8151. + break;
  8152. + case 'd':
  8153. + case 'D':
  8154. + if (strcasecmp(field, "Depends") == 0) {
  8155. + /* Depends */
  8156. + int i;
  8157. +
  8158. + if (pkg->depends_count) {
  8159. + char depstr[LINE_LEN];
  8160. + len = 14 ;
  8161. + for(i = 0; i < pkg->depends_count; i++) {
  8162. + len = len + (strlen(pkg->depends_str[i])+4);
  8163. + }
  8164. + temp = (char *)realloc(temp,len);
  8165. + if ( temp == NULL ){
  8166. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8167. + return NULL;
  8168. + }
  8169. + temp[0]='\0';
  8170. + strncpy(temp, "Depends:", 10);
  8171. + for(i = 0; i < pkg->depends_count; i++) {
  8172. + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
  8173. + strncat(temp, depstr, strlen(depstr));
  8174. + }
  8175. + strncat(temp, "\n", strlen("\n"));
  8176. + }
  8177. + } else if (strcasecmp(field, "Description") == 0) {
  8178. + /* Description */
  8179. + if (pkg->description) {
  8180. + temp = (char *)realloc(temp,strlen(pkg->description)+16);
  8181. + if ( temp == NULL ){
  8182. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8183. + return NULL;
  8184. + }
  8185. + temp[0]='\0';
  8186. + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
  8187. + }
  8188. + } else {
  8189. + goto UNKNOWN_FMT_FIELD;
  8190. + }
  8191. + break;
  8192. + case 'e':
  8193. + case 'E': {
  8194. + /* Essential */
  8195. + if (pkg->essential) {
  8196. + temp = (char *)realloc(temp,16);
  8197. + if ( temp == NULL ){
  8198. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8199. + return NULL;
  8200. + }
  8201. + temp[0]='\0';
  8202. + snprintf(temp, (16), "Essential: yes\n");
  8203. + }
  8204. + }
  8205. + break;
  8206. + case 'f':
  8207. + case 'F': {
  8208. + /* Filename */
  8209. + if (pkg->filename) {
  8210. + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
  8211. + if ( temp == NULL ){
  8212. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8213. + return NULL;
  8214. + }
  8215. + temp[0]='\0';
  8216. + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
  8217. + }
  8218. + }
  8219. + break;
  8220. + case 'i':
  8221. + case 'I': {
  8222. + if (strcasecmp(field, "Installed-Size") == 0) {
  8223. + /* Installed-Size */
  8224. + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
  8225. + if ( temp == NULL ){
  8226. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8227. + return NULL;
  8228. + }
  8229. + temp[0]='\0';
  8230. + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
  8231. + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
  8232. + temp = (char *)realloc(temp,29);
  8233. + if ( temp == NULL ){
  8234. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8235. + return NULL;
  8236. + }
  8237. + temp[0]='\0';
  8238. + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
  8239. + }
  8240. + }
  8241. + break;
  8242. + case 'm':
  8243. + case 'M': {
  8244. + /* Maintainer | MD5sum */
  8245. + if (strcasecmp(field, "Maintainer") == 0) {
  8246. + /* Maintainer */
  8247. + if (pkg->maintainer) {
  8248. + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
  8249. + if ( temp == NULL ){
  8250. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8251. + return NULL;
  8252. + }
  8253. + temp[0]='\0';
  8254. + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
  8255. + }
  8256. + } else if (strcasecmp(field, "MD5sum") == 0) {
  8257. + /* MD5sum */
  8258. + if (pkg->md5sum) {
  8259. + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
  8260. + if ( temp == NULL ){
  8261. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8262. + return NULL;
  8263. + }
  8264. + temp[0]='\0';
  8265. + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
  8266. + }
  8267. + } else {
  8268. + goto UNKNOWN_FMT_FIELD;
  8269. + }
  8270. + }
  8271. + break;
  8272. + case 'p':
  8273. + case 'P': {
  8274. + if (strcasecmp(field, "Package") == 0) {
  8275. + /* Package */
  8276. + temp = (char *)realloc(temp,strlen(pkg->name)+11);
  8277. + if ( temp == NULL ){
  8278. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8279. + return NULL;
  8280. + }
  8281. + temp[0]='\0';
  8282. + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
  8283. + } else if (strcasecmp(field, "Priority") == 0) {
  8284. + /* Priority */
  8285. + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
  8286. + if ( temp == NULL ){
  8287. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8288. + return NULL;
  8289. + }
  8290. + temp[0]='\0';
  8291. + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
  8292. + } else if (strcasecmp(field, "Provides") == 0) {
  8293. + /* Provides */
  8294. + int i;
  8295. +
  8296. + if (pkg->provides_count) {
  8297. + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
  8298. + for ( i=0; i < pkg->provides_count; i++ ){
  8299. + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
  8300. + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
  8301. + flag_provide_false = 1;
  8302. + }
  8303. + }
  8304. + if ( !flag_provide_false || /* Pigi there is not my trick flag */
  8305. + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
  8306. + char provstr[LINE_LEN];
  8307. + len = 15;
  8308. + for(i = 0; i < pkg->provides_count; i++) {
  8309. + len = len + (strlen(pkg->provides_str[i])+5);
  8310. + }
  8311. + temp = (char *)realloc(temp,len);
  8312. + if ( temp == NULL ){
  8313. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8314. + return NULL;
  8315. + }
  8316. + temp[0]='\0';
  8317. + strncpy(temp, "Provides:", 12);
  8318. + for(i = 0; i < pkg->provides_count; i++) {
  8319. + if (strlen(pkg->provides_str[i])>0){;
  8320. + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
  8321. + strncat(temp, provstr, strlen(provstr));
  8322. + }
  8323. + }
  8324. + strncat(temp, "\n", strlen("\n"));
  8325. + }
  8326. + }
  8327. + } else {
  8328. + goto UNKNOWN_FMT_FIELD;
  8329. + }
  8330. + }
  8331. + break;
  8332. + case 'r':
  8333. + case 'R': {
  8334. + int i;
  8335. + /* Replaces | Recommends*/
  8336. + if (strcasecmp (field, "Replaces") == 0) {
  8337. + if (pkg->replaces_count) {
  8338. + char replstr[LINE_LEN];
  8339. + len = 14;
  8340. + for (i = 0; i < pkg->replaces_count; i++) {
  8341. + len = len + (strlen(pkg->replaces_str[i])+5);
  8342. + }
  8343. + temp = (char *)realloc(temp,len);
  8344. + if ( temp == NULL ){
  8345. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8346. + return NULL;
  8347. + }
  8348. + temp[0]='\0';
  8349. + strncpy(temp, "Replaces:", 12);
  8350. + for (i = 0; i < pkg->replaces_count; i++) {
  8351. + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
  8352. + strncat(temp, replstr, strlen(replstr));
  8353. + }
  8354. + strncat(temp, "\n", strlen("\n"));
  8355. + }
  8356. + } else if (strcasecmp (field, "Recommends") == 0) {
  8357. + if (pkg->recommends_count) {
  8358. + char recstr[LINE_LEN];
  8359. + len = 15;
  8360. + for(i = 0; i < pkg->recommends_count; i++) {
  8361. + len = len + (strlen( pkg->recommends_str[i])+5);
  8362. + }
  8363. + temp = (char *)realloc(temp,len);
  8364. + if ( temp == NULL ){
  8365. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8366. + return NULL;
  8367. + }
  8368. + temp[0]='\0';
  8369. + strncpy(temp, "Recommends:", 13);
  8370. + for(i = 0; i < pkg->recommends_count; i++) {
  8371. + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
  8372. + strncat(temp, recstr, strlen(recstr));
  8373. + }
  8374. + strncat(temp, "\n", strlen("\n"));
  8375. + }
  8376. + } else {
  8377. + goto UNKNOWN_FMT_FIELD;
  8378. + }
  8379. + }
  8380. + break;
  8381. + case 's':
  8382. + case 'S': {
  8383. + /* Section | Size | Source | Status | Suggests */
  8384. + if (strcasecmp(field, "Section") == 0) {
  8385. + /* Section */
  8386. + if (pkg->section) {
  8387. + temp = (char *)realloc(temp,strlen(pkg->section)+11);
  8388. + if ( temp == NULL ){
  8389. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8390. + return NULL;
  8391. + }
  8392. + temp[0]='\0';
  8393. + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
  8394. + }
  8395. + } else if (strcasecmp(field, "Size") == 0) {
  8396. + /* Size */
  8397. + if (pkg->size) {
  8398. + temp = (char *)realloc(temp,strlen(pkg->size)+8);
  8399. + if ( temp == NULL ){
  8400. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8401. + return NULL;
  8402. + }
  8403. + temp[0]='\0';
  8404. + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
  8405. + }
  8406. + } else if (strcasecmp(field, "Source") == 0) {
  8407. + /* Source */
  8408. + if (pkg->source) {
  8409. + temp = (char *)realloc(temp,strlen(pkg->source)+10);
  8410. + if ( temp == NULL ){
  8411. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8412. + return NULL;
  8413. + }
  8414. + temp[0]='\0';
  8415. + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
  8416. + }
  8417. + } else if (strcasecmp(field, "Status") == 0) {
  8418. + /* Status */
  8419. + /* Benjamin Pineau note: we should avoid direct usage of
  8420. + * strlen(arg) without keeping "arg" for later free()
  8421. + */
  8422. + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
  8423. + char *pstat=pkg_state_status_to_str(pkg->state_status);
  8424. + char *pwant=pkg_state_want_to_str(pkg->state_want);
  8425. +
  8426. + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
  8427. + temp = (char *)realloc(temp,sum_of_sizes);
  8428. + if ( temp == NULL ){
  8429. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8430. + return NULL;
  8431. + }
  8432. + temp[0]='\0';
  8433. + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
  8434. + free(pflag);
  8435. + free(pwant);
  8436. + if(pstat) /* pfstat can be NULL if ENOMEM */
  8437. + free(pstat);
  8438. + } else if (strcasecmp(field, "Suggests") == 0) {
  8439. + if (pkg->suggests_count) {
  8440. + int i;
  8441. + char sugstr[LINE_LEN];
  8442. + len = 13;
  8443. + for(i = 0; i < pkg->suggests_count; i++) {
  8444. + len = len + (strlen(pkg->suggests_str[i])+5);
  8445. + }
  8446. + temp = (char *)realloc(temp,len);
  8447. + if ( temp == NULL ){
  8448. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8449. + return NULL;
  8450. + }
  8451. + temp[0]='\0';
  8452. + strncpy(temp, "Suggests:", 10);
  8453. + for(i = 0; i < pkg->suggests_count; i++) {
  8454. + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
  8455. + strncat(temp, sugstr, strlen(sugstr));
  8456. + }
  8457. + strncat(temp, "\n", strlen("\n"));
  8458. + }
  8459. + } else {
  8460. + goto UNKNOWN_FMT_FIELD;
  8461. + }
  8462. + }
  8463. + break;
  8464. + case 'v':
  8465. + case 'V': {
  8466. + /* Version */
  8467. + char *version = pkg_version_str_alloc(pkg);
  8468. + temp = (char *)realloc(temp,strlen(version)+14);
  8469. + if ( temp == NULL ){
  8470. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8471. + return NULL;
  8472. + }
  8473. + temp[0]='\0';
  8474. + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
  8475. + free(version);
  8476. + }
  8477. + break;
  8478. + default:
  8479. + goto UNKNOWN_FMT_FIELD;
  8480. + }
  8481. +
  8482. + if ( strlen(temp)<2 ) {
  8483. + temp[0]='\0';
  8484. + }
  8485. + return temp;
  8486. +
  8487. + UNKNOWN_FMT_FIELD:
  8488. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
  8489. + if ( strlen(temp)<2 ) {
  8490. + temp[0]='\0';
  8491. + }
  8492. +
  8493. + return temp;
  8494. +}
  8495. +
  8496. +void pkg_print_info(pkg_t *pkg, FILE *file)
  8497. +{
  8498. + char * buff;
  8499. + if (pkg == NULL) {
  8500. + return;
  8501. + }
  8502. +
  8503. + buff = pkg_formatted_info(pkg);
  8504. + if ( buff == NULL )
  8505. + return;
  8506. + if (strlen(buff)>2){
  8507. + fwrite(buff, 1, strlen(buff), file);
  8508. + }
  8509. + free(buff);
  8510. +}
  8511. +
  8512. +void pkg_print_status(pkg_t * pkg, FILE * file)
  8513. +{
  8514. + if (pkg == NULL) {
  8515. + return;
  8516. + }
  8517. +
  8518. + /* XXX: QUESTION: Do we actually want more fields here? The
  8519. + original idea was to save space by installing only what was
  8520. + needed for actual computation, (package, version, status,
  8521. + essential, conffiles). The assumption is that all other fields
  8522. + can be found in th available file.
  8523. +
  8524. + But, someone proposed the idea to make it possible to
  8525. + reconstruct a .ipk from an installed package, (ie. for beaming
  8526. + from one handheld to another). So, maybe we actually want a few
  8527. + more fields here, (depends, suggests, etc.), so that that would
  8528. + be guaranteed to work even in the absence of more information
  8529. + from the available file.
  8530. +
  8531. + 28-MAR-03: kergoth and I discussed this yesterday. We think
  8532. + the essential info needs to be here for all installed packages
  8533. + because they may not appear in the Packages files on various
  8534. + feeds. Furthermore, one should be able to install from URL or
  8535. + local storage without requiring a Packages file from any feed.
  8536. + -Jamey
  8537. + */
  8538. + pkg_print_field(pkg, file, "Package");
  8539. + pkg_print_field(pkg, file, "Version");
  8540. + pkg_print_field(pkg, file, "Depends");
  8541. + pkg_print_field(pkg, file, "Recommends");
  8542. + pkg_print_field(pkg, file, "Suggests");
  8543. + pkg_print_field(pkg, file, "Provides");
  8544. + pkg_print_field(pkg, file, "Replaces");
  8545. + pkg_print_field(pkg, file, "Conflicts");
  8546. + pkg_print_field(pkg, file, "Status");
  8547. + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
  8548. + pkg_print_field(pkg, file, "Architecture");
  8549. + pkg_print_field(pkg, file, "Conffiles");
  8550. + pkg_print_field(pkg, file, "Installed-Time");
  8551. + fputs("\n", file);
  8552. +}
  8553. +
  8554. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
  8555. +{
  8556. + char *buff;
  8557. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8558. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
  8559. + __FUNCTION__, field);
  8560. + }
  8561. + buff = pkg_formatted_field(pkg, field);
  8562. + if (strlen(buff)>2) {
  8563. + fprintf(file, "%s", buff);
  8564. + fflush(file);
  8565. + }
  8566. + free(buff);
  8567. + return;
  8568. +}
  8569. +
  8570. +/*
  8571. + * libdpkg - Debian packaging suite library routines
  8572. + * vercmp.c - comparison of version numbers
  8573. + *
  8574. + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  8575. + */
  8576. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
  8577. +{
  8578. + int r;
  8579. +
  8580. + if (pkg->epoch > ref_pkg->epoch) {
  8581. + return 1;
  8582. + }
  8583. +
  8584. + if (pkg->epoch < ref_pkg->epoch) {
  8585. + return -1;
  8586. + }
  8587. +
  8588. + r = verrevcmp(pkg->version, ref_pkg->version);
  8589. + if (r) {
  8590. + return r;
  8591. + }
  8592. +
  8593. +#ifdef USE_DEBVERSION
  8594. + r = verrevcmp(pkg->revision, ref_pkg->revision);
  8595. + if (r) {
  8596. + return r;
  8597. + }
  8598. +
  8599. + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
  8600. +#endif
  8601. +
  8602. + return r;
  8603. +}
  8604. +
  8605. +int verrevcmp(const char *val, const char *ref)
  8606. +{
  8607. + int vc, rc;
  8608. + long vl, rl;
  8609. + const char *vp, *rp;
  8610. + const char *vsep, *rsep;
  8611. +
  8612. + if (!val) val= "";
  8613. + if (!ref) ref= "";
  8614. + for (;;) {
  8615. + vp= val; while (*vp && !isdigit(*vp)) vp++;
  8616. + rp= ref; while (*rp && !isdigit(*rp)) rp++;
  8617. + for (;;) {
  8618. + vc= (val == vp) ? 0 : *val++;
  8619. + rc= (ref == rp) ? 0 : *ref++;
  8620. + if (!rc && !vc) break;
  8621. + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
  8622. + if (rc && !isalpha(rc)) rc += 256;
  8623. + if (vc != rc) return vc - rc;
  8624. + }
  8625. + val= vp;
  8626. + ref= rp;
  8627. + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
  8628. + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
  8629. + if (vl != rl) return vl - rl;
  8630. +
  8631. + vc = *val;
  8632. + rc = *ref;
  8633. + vsep = strchr(".-", vc);
  8634. + rsep = strchr(".-", rc);
  8635. + if (vsep && !rsep) return -1;
  8636. + if (!vsep && rsep) return +1;
  8637. +
  8638. + if (!*val && !*ref) return 0;
  8639. + if (!*val) return -1;
  8640. + if (!*ref) return +1;
  8641. + }
  8642. +}
  8643. +
  8644. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
  8645. +{
  8646. + int r;
  8647. +
  8648. + r = pkg_compare_versions(it, ref);
  8649. +
  8650. + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
  8651. + return r <= 0;
  8652. + }
  8653. +
  8654. + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
  8655. + return r >= 0;
  8656. + }
  8657. +
  8658. + if (strcmp(op, "<<") == 0) {
  8659. + return r < 0;
  8660. + }
  8661. +
  8662. + if (strcmp(op, ">>") == 0) {
  8663. + return r > 0;
  8664. + }
  8665. +
  8666. + if (strcmp(op, "=") == 0) {
  8667. + return r == 0;
  8668. + }
  8669. +
  8670. + fprintf(stderr, "unknown operator: %s", op);
  8671. + return 0;
  8672. +}
  8673. +
  8674. +int pkg_name_version_and_architecture_compare(pkg_t *p1, pkg_t *p2)
  8675. +{
  8676. + const pkg_t *a = *(const pkg_t **)p1;
  8677. + const pkg_t *b = *(const pkg_t **)p2;
  8678. + int namecmp;
  8679. + int vercmp;
  8680. + if (!a->name || !b->name) {
  8681. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8682. + a, a->name, b, b->name);
  8683. + return 0;
  8684. + }
  8685. +
  8686. + namecmp = strcmp(a->name, b->name);
  8687. + if (namecmp)
  8688. + return namecmp;
  8689. + vercmp = pkg_compare_versions(a, b);
  8690. + if (vercmp)
  8691. + return vercmp;
  8692. + if (!a->arch_priority || !b->arch_priority) {
  8693. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
  8694. + a, a->arch_priority, b, b->arch_priority);
  8695. + return 0;
  8696. + }
  8697. + if (a->arch_priority > b->arch_priority)
  8698. + return 1;
  8699. + if (a->arch_priority < b->arch_priority)
  8700. + return -1;
  8701. + return 0;
  8702. +}
  8703. +
  8704. +int abstract_pkg_name_compare(abstract_pkg_t *p1, abstract_pkg_t *p2)
  8705. +{
  8706. + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
  8707. + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
  8708. + if (!a->name || !b->name) {
  8709. + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8710. + a, a->name, b, b->name);
  8711. + return 0;
  8712. + }
  8713. + return strcmp(a->name, b->name);
  8714. +}
  8715. +
  8716. +
  8717. +char *pkg_version_str_alloc(pkg_t *pkg)
  8718. +{
  8719. + char *complete_version;
  8720. + char *epoch_str;
  8721. +#ifdef USE_DEBVERSION
  8722. + char *revision_str;
  8723. + char *familiar_revision_str;
  8724. +#endif
  8725. +
  8726. + if (pkg->epoch) {
  8727. + sprintf_alloc(&epoch_str, "%lu:", (unsigned long)pkg->epoch);
  8728. + } else {
  8729. + epoch_str = strdup("");
  8730. + }
  8731. +
  8732. +#ifdef USE_DEBVERSION
  8733. + if (pkg->revision && strlen(pkg->revision)) {
  8734. + sprintf_alloc(&revision_str, "-%s", pkg->revision);
  8735. + } else {
  8736. + revision_str = strdup("");
  8737. + }
  8738. +
  8739. + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
  8740. + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
  8741. + } else {
  8742. + familiar_revision_str = strdup("");
  8743. + }
  8744. +#endif
  8745. +
  8746. +#ifdef USE_DEBVERSION
  8747. + sprintf_alloc(&complete_version, "%s%s%s%s",
  8748. + epoch_str, pkg->version, revision_str, familiar_revision_str);
  8749. +#else
  8750. + sprintf_alloc(&complete_version, "%s%s",
  8751. + epoch_str, pkg->version);
  8752. +#endif
  8753. +
  8754. + free(epoch_str);
  8755. +#ifdef USE_DEBVERSION
  8756. + free(revision_str);
  8757. + free(familiar_revision_str);
  8758. +#endif
  8759. +
  8760. + return complete_version;
  8761. +}
  8762. +
  8763. +str_list_t *pkg_get_installed_files(pkg_t *pkg)
  8764. +{
  8765. + int err;
  8766. + char *list_file_name = NULL;
  8767. + FILE *list_file = NULL;
  8768. + char *line;
  8769. + char *installed_file_name;
  8770. + int rootdirlen;
  8771. +
  8772. + pkg->installed_files_ref_cnt++;
  8773. +
  8774. + if (pkg->installed_files) {
  8775. + return pkg->installed_files;
  8776. + }
  8777. +
  8778. + pkg->installed_files = str_list_alloc();
  8779. + if (pkg->installed_files == NULL) {
  8780. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8781. + return NULL;
  8782. + }
  8783. +
  8784. + /* For uninstalled packages, get the file list firectly from the package.
  8785. + For installed packages, look at the package.list file in the database.
  8786. + */
  8787. + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
  8788. + if (pkg->local_filename == NULL) {
  8789. + return pkg->installed_files;
  8790. + }
  8791. + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
  8792. + file. In other words, change deb_extract so that it can
  8793. + simply return the file list as a char *[] rather than
  8794. + insisting on writing in to a FILE * as it does now. */
  8795. + list_file = tmpfile();
  8796. + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
  8797. + if (err) {
  8798. + fclose(list_file);
  8799. + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
  8800. + __FUNCTION__, pkg->local_filename, strerror(err));
  8801. + return pkg->installed_files;
  8802. + }
  8803. + rewind(list_file);
  8804. + } else {
  8805. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8806. + pkg->dest->info_dir, pkg->name);
  8807. + if (! file_exists(list_file_name)) {
  8808. + free(list_file_name);
  8809. + return pkg->installed_files;
  8810. + }
  8811. +
  8812. + list_file = fopen(list_file_name, "r");
  8813. + if (list_file == NULL) {
  8814. + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
  8815. + list_file_name, strerror(errno));
  8816. + free(list_file_name);
  8817. + return pkg->installed_files;
  8818. + }
  8819. + free(list_file_name);
  8820. + }
  8821. +
  8822. + rootdirlen = strlen( pkg->dest->root_dir );
  8823. + while (1) {
  8824. + char *file_name;
  8825. +
  8826. + line = file_read_line_alloc(list_file);
  8827. + if (line == NULL) {
  8828. + break;
  8829. + }
  8830. + str_chomp(line);
  8831. + file_name = line;
  8832. +
  8833. + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
  8834. + if( strncmp( pkg->dest->root_dir,
  8835. + file_name,
  8836. + rootdirlen ) ) {
  8837. + if (*file_name == '.') {
  8838. + file_name++;
  8839. + }
  8840. + if (*file_name == '/') {
  8841. + file_name++;
  8842. + }
  8843. +
  8844. + /* Freed in pkg_free_installed_files */
  8845. + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
  8846. + } else {
  8847. + // already contains root_dir as header -> ABSOLUTE
  8848. + sprintf_alloc(&installed_file_name, "%s", file_name);
  8849. + }
  8850. + str_list_append(pkg->installed_files, installed_file_name);
  8851. + free(line);
  8852. + }
  8853. +
  8854. + fclose(list_file);
  8855. +
  8856. + return pkg->installed_files;
  8857. +}
  8858. +
  8859. +/* XXX: CLEANUP: This function and it's counterpart,
  8860. + (pkg_get_installed_files), do not match our init/deinit naming
  8861. + convention. Nor the alloc/free convention. But, then again, neither
  8862. + of these conventions currrently fit the way these two functions
  8863. + work. */
  8864. +int pkg_free_installed_files(pkg_t *pkg)
  8865. +{
  8866. + str_list_elt_t *iter;
  8867. +
  8868. + pkg->installed_files_ref_cnt--;
  8869. + if (pkg->installed_files_ref_cnt > 0) {
  8870. + return 0;
  8871. + }
  8872. +
  8873. + if (pkg->installed_files) {
  8874. +
  8875. + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
  8876. + /* malloced in pkg_get_installed_files */
  8877. + free (iter->data);
  8878. + iter->data = NULL;
  8879. + }
  8880. +
  8881. + str_list_deinit(pkg->installed_files);
  8882. + }
  8883. +
  8884. + pkg->installed_files = NULL;
  8885. +
  8886. + return 0;
  8887. +}
  8888. +
  8889. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
  8890. +{
  8891. + int err;
  8892. + char *list_file_name;
  8893. +
  8894. + //I don't think pkg_free_installed_files should be called here. Jamey
  8895. + //pkg_free_installed_files(pkg);
  8896. +
  8897. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8898. + pkg->dest->info_dir, pkg->name);
  8899. + if (!conf->noaction) {
  8900. + err = unlink(list_file_name);
  8901. + free(list_file_name);
  8902. +
  8903. + if (err) {
  8904. + return errno;
  8905. + }
  8906. + }
  8907. + return 0;
  8908. +}
  8909. +
  8910. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
  8911. +{
  8912. + conffile_list_elt_t *iter;
  8913. + conffile_t *conffile;
  8914. +
  8915. + if (pkg == NULL) {
  8916. + return NULL;
  8917. + }
  8918. +
  8919. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8920. + conffile = iter->data;
  8921. +
  8922. + if (strcmp(conffile->name, file_name) == 0) {
  8923. + return conffile;
  8924. + }
  8925. + }
  8926. +
  8927. + return NULL;
  8928. +}
  8929. +
  8930. +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
  8931. + const char *script, const char *args)
  8932. +{
  8933. + int err;
  8934. + char *path;
  8935. + char *cmd;
  8936. +
  8937. + /* XXX: FEATURE: When conf->offline_root is set, we should run the
  8938. + maintainer script within a chroot environment. */
  8939. +
  8940. + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
  8941. + have scripts in pkg->tmp_unpack_dir. */
  8942. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  8943. + if (pkg->dest == NULL) {
  8944. + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
  8945. + __FUNCTION__, pkg->name);
  8946. + return EINVAL;
  8947. + }
  8948. + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
  8949. + } else {
  8950. + if (pkg->tmp_unpack_dir == NULL) {
  8951. + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
  8952. + __FUNCTION__, pkg->name);
  8953. + return EINVAL;
  8954. + }
  8955. + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
  8956. + }
  8957. +
  8958. + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
  8959. + if (conf->noaction) return 0;
  8960. +
  8961. + /* XXX: CLEANUP: There must be a better way to handle maintainer
  8962. + scripts when running with offline_root mode and/or a dest other
  8963. + than '/'. I've been playing around with some clever chroot
  8964. + tricks and I might come up with something workable. */
  8965. + if (conf->offline_root) {
  8966. + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
  8967. + }
  8968. +
  8969. + setenv("PKG_ROOT",
  8970. + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
  8971. +
  8972. + if (! file_exists(path)) {
  8973. + free(path);
  8974. + return 0;
  8975. + }
  8976. +
  8977. + if (conf->offline_root) {
  8978. + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
  8979. + free(path);
  8980. + return 0;
  8981. + }
  8982. +
  8983. + sprintf_alloc(&cmd, "%s %s", path, args);
  8984. + free(path);
  8985. +
  8986. + err = xsystem(cmd);
  8987. + free(cmd);
  8988. +
  8989. + if (err) {
  8990. + fprintf(stderr, "%s script returned status %d\n", script, err);
  8991. + return err;
  8992. + }
  8993. +
  8994. + return 0;
  8995. +}
  8996. +
  8997. +char *pkg_state_want_to_str(pkg_state_want_t sw)
  8998. +{
  8999. + int i;
  9000. +
  9001. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9002. + if (pkg_state_want_map[i].value == sw) {
  9003. + return strdup(pkg_state_want_map[i].str);
  9004. + }
  9005. + }
  9006. +
  9007. + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
  9008. + __FUNCTION__, sw);
  9009. + return strdup("<STATE_WANT_UNKNOWN>");
  9010. +}
  9011. +
  9012. +pkg_state_want_t pkg_state_want_from_str(char *str)
  9013. +{
  9014. + int i;
  9015. +
  9016. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9017. + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
  9018. + return pkg_state_want_map[i].value;
  9019. + }
  9020. + }
  9021. +
  9022. + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
  9023. + __FUNCTION__, str);
  9024. + return SW_UNKNOWN;
  9025. +}
  9026. +
  9027. +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
  9028. +{
  9029. + int i;
  9030. + int len = 3; /* ok\000 is minimum */
  9031. + char *str = NULL;
  9032. +
  9033. + /* clear the temporary flags before converting to string */
  9034. + sf &= SF_NONVOLATILE_FLAGS;
  9035. +
  9036. + if (sf == 0) {
  9037. + return strdup("ok");
  9038. + } else {
  9039. +
  9040. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9041. + if (sf & pkg_state_flag_map[i].value) {
  9042. + len += strlen(pkg_state_flag_map[i].str) + 1;
  9043. + }
  9044. + }
  9045. + str = malloc(len);
  9046. + if ( str == NULL ) {
  9047. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9048. + return NULL;
  9049. + }
  9050. + str[0] = 0;
  9051. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9052. + if (sf & pkg_state_flag_map[i].value) {
  9053. + strcat(str, pkg_state_flag_map[i].str);
  9054. + strcat(str, ",");
  9055. + }
  9056. + }
  9057. + len = strlen(str);
  9058. + str[len-1] = 0; /* squash last comma */
  9059. + return str;
  9060. + }
  9061. +}
  9062. +
  9063. +pkg_state_flag_t pkg_state_flag_from_str(char *str)
  9064. +{
  9065. + int i;
  9066. + int sf = SF_OK;
  9067. +
  9068. + if (strcmp(str, "ok") == 0) {
  9069. + return SF_OK;
  9070. + }
  9071. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9072. + const char *sfname = pkg_state_flag_map[i].str;
  9073. + int sfname_len = strlen(sfname);
  9074. + if (strncmp(str, sfname, sfname_len) == 0) {
  9075. + sf |= pkg_state_flag_map[i].value;
  9076. + str += sfname_len;
  9077. + if (str[0] == ',') {
  9078. + str++;
  9079. + } else {
  9080. + break;
  9081. + }
  9082. + }
  9083. + }
  9084. +
  9085. + return sf;
  9086. +}
  9087. +
  9088. +char *pkg_state_status_to_str(pkg_state_status_t ss)
  9089. +{
  9090. + int i;
  9091. +
  9092. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9093. + if (pkg_state_status_map[i].value == ss) {
  9094. + return strdup(pkg_state_status_map[i].str);
  9095. + }
  9096. + }
  9097. +
  9098. + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
  9099. + __FUNCTION__, ss);
  9100. + return strdup("<STATE_STATUS_UNKNOWN>");
  9101. +}
  9102. +
  9103. +pkg_state_status_t pkg_state_status_from_str(char *str)
  9104. +{
  9105. + int i;
  9106. +
  9107. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9108. + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
  9109. + return pkg_state_status_map[i].value;
  9110. + }
  9111. + }
  9112. +
  9113. + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
  9114. + __FUNCTION__, str);
  9115. + return SS_NOT_INSTALLED;
  9116. +}
  9117. +
  9118. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
  9119. +{
  9120. + nv_pair_list_elt_t *l;
  9121. +
  9122. + if (!pkg->architecture)
  9123. + return 1;
  9124. +
  9125. + l = conf->arch_list.head;
  9126. +
  9127. + while (l) {
  9128. + nv_pair_t *nv = l->data;
  9129. + if (strcmp(nv->name, pkg->architecture) == 0) {
  9130. + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
  9131. + return 1;
  9132. + }
  9133. + l = l->next;
  9134. + }
  9135. +
  9136. + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
  9137. + return 0;
  9138. +}
  9139. +
  9140. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
  9141. +{
  9142. + nv_pair_list_elt_t *l;
  9143. +
  9144. + l = conf->arch_list.head;
  9145. +
  9146. + while (l) {
  9147. + nv_pair_t *nv = l->data;
  9148. + if (strcmp(nv->name, archname) == 0) {
  9149. + int priority = strtol(nv->value, NULL, 0);
  9150. + return priority;
  9151. + }
  9152. + l = l->next;
  9153. + }
  9154. + return 0;
  9155. +}
  9156. +
  9157. +int pkg_info_preinstall_check(ipkg_conf_t *conf)
  9158. +{
  9159. + int i;
  9160. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9161. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  9162. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9163. +
  9164. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
  9165. + pkg_hash_fetch_available(pkg_hash, available_pkgs);
  9166. + /* update arch_priority for each package */
  9167. + for (i = 0; i < available_pkgs->len; i++) {
  9168. + pkg_t *pkg = available_pkgs->pkgs[i];
  9169. + int arch_priority = 1;
  9170. + if (!pkg)
  9171. + continue;
  9172. + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
  9173. + if (pkg->architecture)
  9174. + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
  9175. + else
  9176. + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
  9177. + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
  9178. + pkg->arch_priority = arch_priority;
  9179. + }
  9180. +
  9181. + for (i = 0; i < available_pkgs->len; i++) {
  9182. + pkg_t *pkg = available_pkgs->pkgs[i];
  9183. + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
  9184. + /* clear flags and want for any uninstallable package */
  9185. + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
  9186. + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
  9187. + pkg->state_want = SW_UNKNOWN;
  9188. + pkg->state_flag = 0;
  9189. + }
  9190. + }
  9191. + pkg_vec_free(available_pkgs);
  9192. +
  9193. + /* update the file owner data structure */
  9194. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
  9195. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9196. + for (i = 0; i < installed_pkgs->len; i++) {
  9197. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9198. + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
  9199. + str_list_elt_t *iter;
  9200. + if (installed_files == NULL) {
  9201. + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
  9202. + break;
  9203. + }
  9204. + for (iter = installed_files->head; iter; iter = iter->next) {
  9205. + char *installed_file = iter->data;
  9206. + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
  9207. + file_hash_set_file_owner(conf, installed_file, pkg);
  9208. + }
  9209. + }
  9210. + pkg_vec_free(installed_pkgs);
  9211. +
  9212. + return 0;
  9213. +}
  9214. +
  9215. +struct pkg_write_filelist_data {
  9216. + ipkg_conf_t *conf;
  9217. + pkg_t *pkg;
  9218. + FILE *stream;
  9219. +};
  9220. +
  9221. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
  9222. +{
  9223. + struct pkg_write_filelist_data *data = data_;
  9224. + pkg_t *entry = entry_;
  9225. + if (entry == data->pkg) {
  9226. + fprintf(data->stream, "%s\n", key);
  9227. + }
  9228. +}
  9229. +
  9230. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
  9231. +{
  9232. + struct pkg_write_filelist_data data;
  9233. + char *list_file_name = NULL;
  9234. + int err = 0;
  9235. +
  9236. + if (!pkg) {
  9237. + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
  9238. + return -EINVAL;
  9239. + }
  9240. + ipkg_message(conf, IPKG_INFO,
  9241. + " creating %s.list file\n", pkg->name);
  9242. + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
  9243. + if (!list_file_name) {
  9244. + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
  9245. + return -ENOMEM;
  9246. + }
  9247. + ipkg_message(conf, IPKG_INFO,
  9248. + " creating %s file for pkg %s\n", list_file_name, pkg->name);
  9249. + data.stream = fopen(list_file_name, "w");
  9250. + if (!data.stream) {
  9251. + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
  9252. + list_file_name, strerror(errno));
  9253. + return errno;
  9254. + }
  9255. + data.pkg = pkg;
  9256. + data.conf = conf;
  9257. + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
  9258. + fclose(data.stream);
  9259. + free(list_file_name);
  9260. +
  9261. + return err;
  9262. +}
  9263. +
  9264. +int pkg_write_changed_filelists(ipkg_conf_t *conf)
  9265. +{
  9266. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9267. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9268. + int i;
  9269. + int err;
  9270. + if (conf->noaction)
  9271. + return 0;
  9272. +
  9273. + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
  9274. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9275. + for (i = 0; i < installed_pkgs->len; i++) {
  9276. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9277. + if (pkg->state_flag & SF_FILELIST_CHANGED) {
  9278. + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
  9279. + err = pkg_write_filelist(conf, pkg);
  9280. + if (err)
  9281. + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
  9282. + }
  9283. + }
  9284. + return 0;
  9285. +}
  9286. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_depends.c busybox-1.17.0/archival/libipkg/pkg_depends.c
  9287. --- busybox-1.17.0.orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
  9288. +++ busybox-1.17.0/archival/libipkg/pkg_depends.c 2010-07-15 21:53:17.848375755 +0200
  9289. @@ -0,0 +1,1032 @@
  9290. +/* pkg_depends.c - the itsy package management system
  9291. +
  9292. + Steven M. Ayer
  9293. +
  9294. + Copyright (C) 2002 Compaq Computer Corporation
  9295. +
  9296. + This program is free software; you can redistribute it and/or
  9297. + modify it under the terms of the GNU General Public License as
  9298. + published by the Free Software Foundation; either version 2, or (at
  9299. + your option) any later version.
  9300. +
  9301. + This program is distributed in the hope that it will be useful, but
  9302. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9303. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9304. + General Public License for more details.
  9305. +*/
  9306. +
  9307. +#include "ipkg.h"
  9308. +#include <errno.h>
  9309. +#include <ctype.h>
  9310. +
  9311. +#include "pkg.h"
  9312. +#include "ipkg_utils.h"
  9313. +#include "pkg_hash.h"
  9314. +#include "ipkg_message.h"
  9315. +#include "pkg_parse.h"
  9316. +#include "hash_table.h"
  9317. +
  9318. +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
  9319. +static depend_t * depend_init(void);
  9320. +static void depend_deinit(depend_t *d);
  9321. +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
  9322. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
  9323. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
  9324. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg);
  9325. +
  9326. +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
  9327. +{
  9328. + depend_t *depend = (depend_t *)cdata;
  9329. + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
  9330. + return 1;
  9331. + else
  9332. + return 0;
  9333. +}
  9334. +
  9335. +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
  9336. +{
  9337. + depend_t *depend = (depend_t *)cdata;
  9338. +#if 0
  9339. + pkg_t * temp = pkg_new();
  9340. + int comparison;
  9341. + parseVersion(temp, depend->version);
  9342. + comparison = pkg_compare_versions(pkg, temp);
  9343. + free(temp);
  9344. +
  9345. + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
  9346. + __FUNCTION__, pkg->name, pkg->version,
  9347. + depend, depend->constraint, depend->version,
  9348. + comparison, version_constraints_satisfied(depend, pkg));
  9349. +#endif
  9350. + if (version_constraints_satisfied(depend, pkg))
  9351. + return 1;
  9352. + else
  9353. + return 0;
  9354. +}
  9355. +
  9356. +/* returns ndependences or negative error value */
  9357. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
  9358. + pkg_vec_t *unsatisfied, char *** unresolved)
  9359. +{
  9360. + pkg_t * satisfier_entry_pkg;
  9361. + register int i, j, k, l;
  9362. + int count, found;
  9363. + char ** the_lost;
  9364. + abstract_pkg_t * ab_pkg;
  9365. +
  9366. + /*
  9367. + * this is a setup to check for redundant/cyclic dependency checks,
  9368. + * which are marked at the abstract_pkg level
  9369. + */
  9370. + if (!(ab_pkg = pkg->parent)) {
  9371. + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
  9372. + *unresolved = NULL;
  9373. + return 0;
  9374. + }
  9375. + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
  9376. + *unresolved = NULL;
  9377. + return 0;
  9378. + } else {
  9379. + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
  9380. + }
  9381. + /**/
  9382. +
  9383. + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
  9384. + if (!count){
  9385. + *unresolved = NULL;
  9386. + return 0;
  9387. + }
  9388. +
  9389. + the_lost = NULL;
  9390. +
  9391. + /* foreach dependency */
  9392. + for (i = 0; i < count; i++) {
  9393. + compound_depend_t * compound_depend = &pkg->depends[i];
  9394. + depend_t ** possible_satisfiers = compound_depend->possibilities;;
  9395. + found = 0;
  9396. + satisfier_entry_pkg = NULL;
  9397. +
  9398. + if (compound_depend->type == GREEDY_DEPEND) {
  9399. + /* foreach possible satisfier */
  9400. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9401. + /* foreach provided_by, which includes the abstract_pkg itself */
  9402. + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
  9403. + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
  9404. + int nposs = ab_provider_vec->len;
  9405. + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
  9406. + for (l = 0; l < nposs; l++) {
  9407. + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
  9408. + /* if no depends on this one, try the first package that Provides this one */
  9409. + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
  9410. + continue;
  9411. + }
  9412. +
  9413. + /* cruise this possiblity's pkg_vec looking for an installed version */
  9414. + for (k = 0; k < test_vec->len; k++) {
  9415. + pkg_t *pkg_scout = test_vec->pkgs[k];
  9416. + /* not installed, and not already known about? */
  9417. + if ((pkg_scout->state_want != SW_INSTALL)
  9418. + && !pkg_scout->parent->dependencies_checked
  9419. + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
  9420. + char ** newstuff = NULL;
  9421. + int rc;
  9422. + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
  9423. + /* check for not-already-installed dependencies */
  9424. + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
  9425. + pkg_scout,
  9426. + tmp_vec,
  9427. + &newstuff);
  9428. + if (newstuff == NULL) {
  9429. + int ok = 1;
  9430. + for (i = 0; i < rc; i++) {
  9431. + pkg_t *p = tmp_vec->pkgs[i];
  9432. + if (p->state_want == SW_INSTALL)
  9433. + continue;
  9434. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
  9435. + ok = 0;
  9436. + break;
  9437. + }
  9438. + pkg_vec_free (tmp_vec);
  9439. + if (ok) {
  9440. + /* mark this one for installation */
  9441. + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
  9442. + pkg_vec_insert(unsatisfied, pkg_scout);
  9443. + }
  9444. + } else {
  9445. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
  9446. + free (newstuff);
  9447. + }
  9448. + }
  9449. + }
  9450. + }
  9451. + }
  9452. +
  9453. + continue;
  9454. + }
  9455. +
  9456. + /* foreach possible satisfier, look for installed package */
  9457. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9458. + /* foreach provided_by, which includes the abstract_pkg itself */
  9459. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9460. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9461. + pkg_t *satisfying_pkg =
  9462. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9463. + pkg_installed_and_constraint_satisfied,
  9464. + dependence_to_satisfy, 1);
  9465. + /* Being that I can't test constraing in pkg_hash, I will test it here */
  9466. + if (satisfying_pkg != NULL) {
  9467. + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9468. + satisfying_pkg = NULL;
  9469. + }
  9470. + }
  9471. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
  9472. + if (satisfying_pkg != NULL) {
  9473. + found = 1;
  9474. + break;
  9475. + }
  9476. +
  9477. + }
  9478. + /* if nothing installed matches, then look for uninstalled satisfier */
  9479. + if (!found) {
  9480. + /* foreach possible satisfier, look for installed package */
  9481. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9482. + /* foreach provided_by, which includes the abstract_pkg itself */
  9483. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9484. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9485. + pkg_t *satisfying_pkg =
  9486. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9487. + pkg_constraint_satisfied,
  9488. + dependence_to_satisfy, 1);
  9489. + /* Being that I can't test constraing in pkg_hash, I will test it here too */
  9490. + if (satisfying_pkg != NULL) {
  9491. + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9492. + satisfying_pkg = NULL;
  9493. + }
  9494. + }
  9495. +
  9496. + /* user request overrides package recommendation */
  9497. + if (satisfying_pkg != NULL
  9498. + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
  9499. + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
  9500. + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
  9501. + pkg->name, satisfying_pkg->name);
  9502. + continue;
  9503. + }
  9504. +
  9505. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
  9506. + if (satisfying_pkg != NULL) {
  9507. + satisfier_entry_pkg = satisfying_pkg;
  9508. + break;
  9509. + }
  9510. + }
  9511. + }
  9512. +
  9513. + /* we didn't find one, add something to the unsatisfied vector */
  9514. + if (!found) {
  9515. + if (!satisfier_entry_pkg) {
  9516. + /* failure to meet recommendations is not an error */
  9517. + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
  9518. + the_lost = add_unresolved_dep(pkg, the_lost, i);
  9519. + else
  9520. + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
  9521. + pkg->name, compound_depend->possibilities[0]->pkg->name);
  9522. + }
  9523. + else {
  9524. + if (compound_depend->type == SUGGEST) {
  9525. + /* just mention it politely */
  9526. + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
  9527. + pkg->name, satisfier_entry_pkg->name);
  9528. + } else {
  9529. + char ** newstuff = NULL;
  9530. +
  9531. + if (satisfier_entry_pkg != pkg &&
  9532. + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
  9533. + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
  9534. + pkg_hash_fetch_unsatisfied_dependencies(conf,
  9535. + satisfier_entry_pkg,
  9536. + unsatisfied,
  9537. + &newstuff);
  9538. + the_lost = merge_unresolved(the_lost, newstuff);
  9539. + }
  9540. + }
  9541. + }
  9542. + }
  9543. + }
  9544. + *unresolved = the_lost;
  9545. +
  9546. + return unsatisfied->len;
  9547. +}
  9548. +
  9549. +/*checking for conflicts !in replaces
  9550. + If a packages conflicts with another but is also replacing it, I should not consider it a
  9551. + really conflicts
  9552. + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
  9553. +*/
  9554. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
  9555. +{
  9556. + int i ;
  9557. + int replaces_count = pkg->replaces_count;
  9558. + abstract_pkg_t **replaces;
  9559. +
  9560. + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
  9561. + return 0;
  9562. +
  9563. + replaces = pkg->replaces;
  9564. +
  9565. + for (i = 0; i < replaces_count; i++) {
  9566. + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
  9567. + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
  9568. + return 1;
  9569. + }
  9570. + }
  9571. + return 0;
  9572. +
  9573. +}
  9574. +
  9575. +
  9576. +/* Abhaya: added support for conflicts */
  9577. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg)
  9578. +{
  9579. + pkg_vec_t * installed_conflicts, * test_vec;
  9580. + compound_depend_t * conflicts;
  9581. + depend_t ** possible_satisfiers;
  9582. + depend_t * possible_satisfier;
  9583. + register int i, j, k;
  9584. + int count;
  9585. + abstract_pkg_t * ab_pkg;
  9586. + pkg_t **pkg_scouts;
  9587. + pkg_t *pkg_scout;
  9588. +
  9589. + /*
  9590. + * this is a setup to check for redundant/cyclic dependency checks,
  9591. + * which are marked at the abstract_pkg level
  9592. + */
  9593. + if(!(ab_pkg = pkg->parent)){
  9594. + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
  9595. + return (pkg_vec_t *)NULL;
  9596. + }
  9597. +
  9598. + conflicts = pkg->conflicts;
  9599. + if(!conflicts){
  9600. + return (pkg_vec_t *)NULL;
  9601. + }
  9602. + installed_conflicts = pkg_vec_alloc();
  9603. +
  9604. + count = pkg->conflicts_count;
  9605. +
  9606. +
  9607. +
  9608. + /* foreach conflict */
  9609. + for(i = 0; i < pkg->conflicts_count; i++){
  9610. +
  9611. + possible_satisfiers = conflicts->possibilities;
  9612. +
  9613. + /* foreach possible satisfier */
  9614. + for(j = 0; j < conflicts->possibility_count; j++){
  9615. + possible_satisfier = possible_satisfiers[j];
  9616. + if (!possible_satisfier)
  9617. + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
  9618. + if (!possible_satisfier->pkg)
  9619. + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
  9620. + test_vec = possible_satisfier->pkg->pkgs;
  9621. + if (test_vec) {
  9622. + /* pkg_vec found, it is an actual package conflict
  9623. + * cruise this possiblity's pkg_vec looking for an installed version */
  9624. + pkg_scouts = test_vec->pkgs;
  9625. + for(k = 0; k < test_vec->len; k++){
  9626. + pkg_scout = pkg_scouts[k];
  9627. + if (!pkg_scout) {
  9628. + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
  9629. + continue;
  9630. + }
  9631. + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
  9632. + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
  9633. + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
  9634. + pkg_vec_insert(installed_conflicts, pkg_scout);
  9635. + }
  9636. + }
  9637. + }
  9638. + }
  9639. + }
  9640. + conflicts++;
  9641. + }
  9642. +
  9643. + if (installed_conflicts->len)
  9644. + return installed_conflicts;
  9645. + pkg_vec_free(installed_conflicts);
  9646. + return (pkg_vec_t *)NULL;
  9647. +}
  9648. +
  9649. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
  9650. +{
  9651. + pkg_t * temp;
  9652. + int comparison;
  9653. +
  9654. + if(depends->constraint == NONE)
  9655. + return 1;
  9656. +
  9657. + temp = pkg_new();
  9658. +
  9659. + parseVersion(temp, depends->version);
  9660. +
  9661. + comparison = pkg_compare_versions(pkg, temp);
  9662. +
  9663. + free(temp);
  9664. +
  9665. + if((depends->constraint == EARLIER) &&
  9666. + (comparison < 0))
  9667. + return 1;
  9668. + else if((depends->constraint == LATER) &&
  9669. + (comparison > 0))
  9670. + return 1;
  9671. + else if(comparison == 0)
  9672. + return 1;
  9673. + else if((depends->constraint == LATER_EQUAL) &&
  9674. + (comparison >= 0))
  9675. + return 1;
  9676. + else if((depends->constraint == EARLIER_EQUAL) &&
  9677. + (comparison <= 0))
  9678. + return 1;
  9679. +
  9680. + return 0;
  9681. +}
  9682. +
  9683. +int pkg_dependence_satisfiable(depend_t *depend)
  9684. +{
  9685. + abstract_pkg_t *apkg = depend->pkg;
  9686. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9687. + int n_providers = provider_apkgs->len;
  9688. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9689. + pkg_vec_t *pkg_vec;
  9690. + int n_pkgs ;
  9691. + int i;
  9692. + int j;
  9693. +
  9694. + for (i = 0; i < n_providers; i++) {
  9695. + abstract_pkg_t *papkg = apkgs[i];
  9696. + pkg_vec = papkg->pkgs;
  9697. + if (pkg_vec) {
  9698. + n_pkgs = pkg_vec->len;
  9699. + for (j = 0; j < n_pkgs; j++) {
  9700. + pkg_t *pkg = pkg_vec->pkgs[j];
  9701. + if (version_constraints_satisfied(depend, pkg)) {
  9702. + return 1;
  9703. + }
  9704. + }
  9705. + }
  9706. + }
  9707. + return 0;
  9708. +}
  9709. +
  9710. +int pkg_dependence_satisfied(depend_t *depend)
  9711. +{
  9712. + abstract_pkg_t *apkg = depend->pkg;
  9713. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9714. + int n_providers = provider_apkgs->len;
  9715. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9716. + int i;
  9717. + int n_pkgs;
  9718. + int j;
  9719. +
  9720. + for (i = 0; i < n_providers; i++) {
  9721. + abstract_pkg_t *papkg = apkgs[i];
  9722. + pkg_vec_t *pkg_vec = papkg->pkgs;
  9723. + if (pkg_vec) {
  9724. + n_pkgs = pkg_vec->len;
  9725. + for (j = 0; j < n_pkgs; j++) {
  9726. + pkg_t *pkg = pkg_vec->pkgs[j];
  9727. + if (version_constraints_satisfied(depend, pkg)) {
  9728. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
  9729. + return 1;
  9730. + }
  9731. + }
  9732. + }
  9733. + }
  9734. + return 0;
  9735. +}
  9736. +
  9737. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
  9738. +{
  9739. + register int i;
  9740. + pkg_t ** pkgs = vec->pkgs;
  9741. +
  9742. + for(i = 0; i < vec->len; i++)
  9743. + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
  9744. + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
  9745. + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
  9746. + return 1;
  9747. + return 0;
  9748. +}
  9749. +
  9750. +
  9751. +#ifdef DeadCode
  9752. +/**
  9753. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  9754. + * the same abstract package and 0 otherwise.
  9755. + */
  9756. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
  9757. +{
  9758. + abstract_pkg_t **provides = pkg->provides;
  9759. + int provides_count = pkg->provides_count;
  9760. + abstract_pkg_t **replacee_provides = replacee->provides;
  9761. + int replacee_provides_count = replacee->provides_count;
  9762. + int i, j;
  9763. + for (i = 0; i < provides_count; i++) {
  9764. + abstract_pkg_t *apkg = provides[i];
  9765. + for (j = 0; j < replacee_provides_count; j++) {
  9766. + abstract_pkg_t *replacee_apkg = replacee_provides[i];
  9767. + if (apkg == replacee_apkg)
  9768. + return 1;
  9769. + }
  9770. + }
  9771. + return 0;
  9772. +}
  9773. +#endif
  9774. +
  9775. +/**
  9776. + * pkg_provides_abstract returns 1 if pkg->provides contains providee
  9777. + * and 0 otherwise.
  9778. + */
  9779. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
  9780. +{
  9781. + abstract_pkg_t **provides = pkg->provides;
  9782. + int provides_count = pkg->provides_count;
  9783. + int i;
  9784. + for (i = 0; i < provides_count; i++) {
  9785. + if (provides[i] == providee)
  9786. + return 1;
  9787. + }
  9788. + return 0;
  9789. +}
  9790. +
  9791. +/**
  9792. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  9793. + * otherwise.
  9794. + */
  9795. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
  9796. +{
  9797. + abstract_pkg_t **replaces = pkg->replaces;
  9798. + int replaces_count = pkg->replaces_count;
  9799. + /* abstract_pkg_t **replacee_provides = pkg->provides;
  9800. + int replacee_provides_count = pkg->provides_count; */
  9801. + int i, j;
  9802. + for (i = 0; i < replaces_count; i++) {
  9803. + abstract_pkg_t *abstract_replacee = replaces[i];
  9804. + for (j = 0; j < replaces_count; j++) {
  9805. + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
  9806. + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
  9807. + if (replacee->provides[j] == abstract_replacee)
  9808. + return 1;
  9809. + }
  9810. + }
  9811. + return 0;
  9812. +}
  9813. +
  9814. +
  9815. +/**
  9816. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
  9817. + * otherwise.
  9818. + */
  9819. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
  9820. +{
  9821. + compound_depend_t *conflicts = pkg->conflicts;
  9822. + int conflicts_count = pkg->conflicts_count;
  9823. + int i, j;
  9824. + for (i = 0; i < conflicts_count; i++) {
  9825. + int possibility_count = conflicts[i].possibility_count;
  9826. + struct depend **possibilities = conflicts[i].possibilities;
  9827. + for (j = 0; j < possibility_count; j++) {
  9828. + if (possibilities[j]->pkg == conflictee) {
  9829. + return 1;
  9830. + }
  9831. + }
  9832. + }
  9833. + return 0;
  9834. +}
  9835. +
  9836. +/**
  9837. + * pkg_conflicts returns 1 if pkg->conflicts contains one of
  9838. + * conflictee's provides and 0 otherwise.
  9839. + */
  9840. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
  9841. +{
  9842. + compound_depend_t *conflicts = pkg->conflicts;
  9843. + int conflicts_count = pkg->conflicts_count;
  9844. + abstract_pkg_t **conflictee_provides = conflictee->provides;
  9845. + int conflictee_provides_count = conflictee->provides_count;
  9846. + int i, j, k;
  9847. + int possibility_count;
  9848. + struct depend **possibilities;
  9849. + abstract_pkg_t *possibility ;
  9850. +
  9851. + for (i = 0; i < conflicts_count; i++) {
  9852. + possibility_count = conflicts[i].possibility_count;
  9853. + possibilities = conflicts[i].possibilities;
  9854. + for (j = 0; j < possibility_count; j++) {
  9855. + possibility = possibilities[j]->pkg;
  9856. + for (k = 0; k < conflictee_provides_count; k++) {
  9857. + if (possibility == conflictee_provides[k]) {
  9858. + return 1;
  9859. + }
  9860. + }
  9861. + }
  9862. + }
  9863. + return 0;
  9864. +}
  9865. +
  9866. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
  9867. +{
  9868. + int oldlen = 0, newlen = 0;
  9869. + char ** result;
  9870. + register int i, j;
  9871. +
  9872. + if(!newstuff)
  9873. + return oldstuff;
  9874. +
  9875. + while(oldstuff && oldstuff[oldlen]) oldlen++;
  9876. + while(newstuff && newstuff[newlen]) newlen++;
  9877. +
  9878. + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
  9879. + if (result == NULL) {
  9880. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9881. + return NULL;
  9882. + }
  9883. +
  9884. + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
  9885. + *(result + i) = *(newstuff + j);
  9886. +
  9887. + *(result + i) = NULL;
  9888. +
  9889. + return result;
  9890. +}
  9891. +
  9892. +/*
  9893. + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
  9894. + * this is null terminated, no count is carried around
  9895. + */
  9896. +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
  9897. +{
  9898. + int count;
  9899. + char ** resized;
  9900. + char *depend_str = pkg_depend_str(pkg, ref_ndx);
  9901. +
  9902. + count = 0;
  9903. + while(the_lost && the_lost[count]) count++;
  9904. +
  9905. + count++; /* need one to hold the null */
  9906. + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
  9907. + if (resized == NULL) {
  9908. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9909. + return NULL;
  9910. + }
  9911. + resized[count - 1] = strdup(depend_str);
  9912. + resized[count] = NULL;
  9913. +
  9914. + return resized;
  9915. +}
  9916. +
  9917. +void printDepends(pkg_t * pkg)
  9918. +{
  9919. + register int i, j;
  9920. + compound_depend_t * depend;
  9921. + int count;
  9922. +
  9923. + count = pkg->pre_depends_count + pkg->depends_count;
  9924. +
  9925. + depend = pkg->depends;
  9926. + if(!depend){
  9927. + fprintf(stderr, "Depends pointer is NULL\n");
  9928. + return;
  9929. + }
  9930. + for(i = 0; i < count; i++){
  9931. + fprintf(stderr, "%s has %d possibilities:\n",
  9932. + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
  9933. + depend->possibility_count);
  9934. + for(j = 0; j < depend->possibility_count; j++)
  9935. + fprintf(stderr, "\t%s version %s (%d)\n",
  9936. + depend->possibilities[j]->pkg->name,
  9937. + depend->possibilities[j]->version,
  9938. + depend->possibilities[j]->constraint);
  9939. + depend++;
  9940. + }
  9941. +}
  9942. +
  9943. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  9944. +{
  9945. + register int i, j;
  9946. +
  9947. + /* every pkg provides itself */
  9948. + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
  9949. +
  9950. + if (!pkg->provides_count)
  9951. + return 0;
  9952. +
  9953. + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
  9954. + if (pkg->provides == NULL) {
  9955. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9956. + return -1 ;
  9957. + }
  9958. + pkg->provides[0] = ab_pkg;
  9959. +
  9960. + // if (strcmp(ab_pkg->name, pkg->name))
  9961. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  9962. +
  9963. + for(i = 0; i < pkg->provides_count; i++){
  9964. + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
  9965. +
  9966. + pkg->provides[i+1] = provided_abpkg;
  9967. +
  9968. + j = 0;
  9969. + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
  9970. + }
  9971. + return 0;
  9972. +}
  9973. +
  9974. +/* Abhaya: added conflicts support */
  9975. +int buildConflicts(hash_table_t * hash, pkg_t * pkg)
  9976. +{
  9977. + register int i;
  9978. + compound_depend_t * conflicts;
  9979. +
  9980. + if (!pkg->conflicts_count)
  9981. + return 0;
  9982. +
  9983. + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
  9984. + pkg->conflicts_count);
  9985. + if (conflicts == NULL) {
  9986. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9987. + return -1;
  9988. + }
  9989. + for (i = 0; i < pkg->conflicts_count; i++) {
  9990. + conflicts->type = CONFLICTS;
  9991. + parseDepends(conflicts, hash,
  9992. + pkg->conflicts_str[i]);
  9993. +#if 0
  9994. + for (j = 0; j < conflicts->possibility_count; j++) {
  9995. + depend_t *possibility = conflicts->possibilities[j];
  9996. + abstract_pkg_t *conflicting_apkg = possibility->pkg;
  9997. + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
  9998. + }
  9999. +#endif
  10000. + conflicts++;
  10001. + }
  10002. + return 0;
  10003. +}
  10004. +
  10005. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10006. +{
  10007. + register int i, j;
  10008. +
  10009. + if (!pkg->replaces_count)
  10010. + return 0;
  10011. +
  10012. + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
  10013. + if (pkg->replaces == NULL) {
  10014. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10015. + return -1;
  10016. + }
  10017. +
  10018. + // if (strcmp(ab_pkg->name, pkg->name))
  10019. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10020. +
  10021. + for(i = 0; i < pkg->replaces_count; i++){
  10022. + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
  10023. +
  10024. + pkg->replaces[i] = old_abpkg;
  10025. +
  10026. + j = 0;
  10027. + if (!old_abpkg->replaced_by)
  10028. + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
  10029. + if ( old_abpkg->replaced_by == NULL ){
  10030. + return -1;
  10031. + }
  10032. + /* if a package pkg both replaces and conflicts old_abpkg,
  10033. + * then add it to the replaced_by vector so that old_abpkg
  10034. + * will be upgraded to ab_pkg automatically */
  10035. + if (pkg_conflicts_abstract(pkg, old_abpkg))
  10036. + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
  10037. + }
  10038. + return 0;
  10039. +}
  10040. +
  10041. +int buildDepends(hash_table_t * hash, pkg_t * pkg)
  10042. +{
  10043. + int count;
  10044. + register int i;
  10045. + compound_depend_t * depends;
  10046. +
  10047. + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
  10048. + return 0;
  10049. +
  10050. + if (0 && pkg->pre_depends_count)
  10051. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10052. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10053. + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
  10054. + if (depends == NULL) {
  10055. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10056. + return -1;
  10057. + }
  10058. +
  10059. +
  10060. + for(i = 0; i < pkg->pre_depends_count; i++){
  10061. + parseDepends(depends, hash, pkg->pre_depends_str[i]);
  10062. + if (0 && pkg->pre_depends_count)
  10063. + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
  10064. + pkg->pre_depends_str[i], depends, depends->possibility_count);
  10065. + depends->type = PREDEPEND;
  10066. + depends++;
  10067. + }
  10068. +
  10069. + for(i = 0; i < pkg->recommends_count; i++){
  10070. + parseDepends(depends, hash, pkg->recommends_str[i]);
  10071. + if (0 && pkg->recommends_count)
  10072. + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
  10073. + pkg->recommends_str[i], depends, depends->possibility_count);
  10074. + depends->type = RECOMMEND;
  10075. + depends++;
  10076. + }
  10077. +
  10078. + for(i = 0; i < pkg->suggests_count; i++){
  10079. + parseDepends(depends, hash, pkg->suggests_str[i]);
  10080. + if (0 && pkg->suggests_count)
  10081. + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
  10082. + pkg->suggests_str[i], depends, depends->possibility_count);
  10083. + depends->type = SUGGEST;
  10084. + depends++;
  10085. + }
  10086. +
  10087. + for(i = 0; i < pkg->depends_count; i++){
  10088. + parseDepends(depends, hash, pkg->depends_str[i]);
  10089. + if (0 && pkg->depends_count)
  10090. + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
  10091. + pkg->depends_str[i], depends, depends->possibility_count);
  10092. + depends++;
  10093. + }
  10094. + return 0;
  10095. +}
  10096. +
  10097. +/*
  10098. + * pkg_depend_string: returns the depends string specified by index_.
  10099. + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
  10100. + * [0,npredepends) -> returns pre_depends_str[index_]
  10101. + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index_]
  10102. + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index_]
  10103. + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index_]
  10104. + */
  10105. +char *pkg_depend_str(pkg_t *pkg, int index_)
  10106. +{
  10107. + if (index_ < pkg->pre_depends_count) {
  10108. + return pkg->pre_depends_str[index_];
  10109. + }
  10110. + index_ -= pkg->pre_depends_count;
  10111. +
  10112. + if (index_ < pkg->recommends_count) {
  10113. + return pkg->recommends_str[index_];
  10114. + }
  10115. + index_ -= pkg->recommends_count;
  10116. +
  10117. + if (index_ < pkg->suggests_count) {
  10118. + return pkg->suggests_str[index_];
  10119. + }
  10120. + index_ -= pkg->suggests_count;
  10121. +
  10122. + if (index_ < pkg->depends_count) {
  10123. + return pkg->depends_str[index_];
  10124. + }
  10125. + fprintf(stderr, "pkg_depend_str: index_ %d out of range for pkg=%s\n", index_, pkg->name);
  10126. + return NULL;
  10127. +}
  10128. +
  10129. +void freeDepends(pkg_t *pkg)
  10130. +{
  10131. + int i;
  10132. +
  10133. + if (pkg == NULL || pkg->depends == NULL) {
  10134. + return;
  10135. + }
  10136. +
  10137. + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
  10138. + for (i=0; i < pkg->depends->possibility_count; i++) {
  10139. + depend_deinit(pkg->depends->possibilities[i]);
  10140. + }
  10141. + free(pkg->depends->possibilities);
  10142. + free(pkg->depends);
  10143. + pkg->depends = NULL;
  10144. +}
  10145. +
  10146. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
  10147. +{
  10148. + compound_depend_t * depends;
  10149. + int count, othercount;
  10150. + register int i, j;
  10151. + abstract_pkg_t * ab_depend;
  10152. + abstract_pkg_t ** temp;
  10153. +
  10154. + count = pkg->pre_depends_count + pkg->depends_count;
  10155. + depends = pkg->depends;
  10156. +
  10157. + if (0 && pkg->pre_depends_count)
  10158. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10159. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10160. + for (i = 0; i < count; i++) {
  10161. + if (0 && pkg->pre_depends_count)
  10162. + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
  10163. + for (j = 0; j < depends->possibility_count; j++){
  10164. + ab_depend = depends->possibilities[j]->pkg;
  10165. + if(!ab_depend->depended_upon_by)
  10166. + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
  10167. +
  10168. + temp = ab_depend->depended_upon_by;
  10169. + othercount = 1;
  10170. + while(*temp){
  10171. + temp++;
  10172. + othercount++;
  10173. + }
  10174. + *temp = ab_pkg;
  10175. +
  10176. + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
  10177. + (othercount + 1) * sizeof(abstract_pkg_t *));
  10178. + /* the array may have moved */
  10179. + temp = ab_depend->depended_upon_by + othercount;
  10180. + *temp = NULL;
  10181. + }
  10182. + depends++;
  10183. + }
  10184. +}
  10185. +
  10186. +static depend_t * depend_init(void)
  10187. +{
  10188. + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
  10189. + if ( d==NULL ){
  10190. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10191. + return NULL;
  10192. + }
  10193. + d->constraint = NONE;
  10194. + d->version = NULL;
  10195. + d->pkg = NULL;
  10196. +
  10197. + return d;
  10198. +}
  10199. +
  10200. +static void depend_deinit(depend_t *d)
  10201. +{
  10202. + free(d);
  10203. +}
  10204. +
  10205. +static int parseDepends(compound_depend_t *compound_depend,
  10206. + hash_table_t * hash, char * depend_str)
  10207. +{
  10208. + char * pkg_name, buffer[2048];
  10209. + int num_of_ors = 0;
  10210. + register int i;
  10211. + register char * src, * dest;
  10212. + depend_t ** possibilities;
  10213. +
  10214. + /* first count the number of ored possibilities for satisfying dependency */
  10215. + src = depend_str;
  10216. + while(*src)
  10217. + if(*src++ == '|')
  10218. + num_of_ors++;
  10219. +
  10220. + compound_depend->type = DEPEND;
  10221. +
  10222. + compound_depend->possibility_count = num_of_ors + 1;
  10223. + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
  10224. + if (!possibilities)
  10225. + return -ENOMEM;
  10226. + compound_depend->possibilities = possibilities;
  10227. +
  10228. + src = depend_str;
  10229. + for(i = 0; i < num_of_ors + 1; i++){
  10230. + possibilities[i] = depend_init();
  10231. + if (!possibilities[i])
  10232. + return -ENOMEM;
  10233. + /* gobble up just the name first */
  10234. + dest = buffer;
  10235. + while(*src &&
  10236. + !isspace(*src) &&
  10237. + (*src != '(') &&
  10238. + (*src != '*') &&
  10239. + (*src != '|'))
  10240. + *dest++ = *src++;
  10241. + *dest = '\0';
  10242. + pkg_name = trim_alloc(buffer);
  10243. + if (pkg_name == NULL )
  10244. + return -ENOMEM;
  10245. +
  10246. + /* now look at possible version info */
  10247. +
  10248. + /* skip to next chars */
  10249. + if(isspace(*src))
  10250. + while(*src && isspace(*src)) src++;
  10251. +
  10252. + /* extract constraint and version */
  10253. + if(*src == '('){
  10254. + src++;
  10255. + if(!strncmp(src, "<<", 2)){
  10256. + possibilities[i]->constraint = EARLIER;
  10257. + src += 2;
  10258. + }
  10259. + else if(!strncmp(src, "<=", 2)){
  10260. + possibilities[i]->constraint = EARLIER_EQUAL;
  10261. + src += 2;
  10262. + }
  10263. + else if(!strncmp(src, ">=", 2)){
  10264. + possibilities[i]->constraint = LATER_EQUAL;
  10265. + src += 2;
  10266. + }
  10267. + else if(!strncmp(src, ">>", 2)){
  10268. + possibilities[i]->constraint = LATER;
  10269. + src += 2;
  10270. + }
  10271. + else if(!strncmp(src, "=", 1)){
  10272. + possibilities[i]->constraint = EQUAL;
  10273. + src++;
  10274. + }
  10275. + /* should these be here to support deprecated designations; dpkg does */
  10276. + else if(!strncmp(src, "<", 1)){
  10277. + possibilities[i]->constraint = EARLIER_EQUAL;
  10278. + src++;
  10279. + }
  10280. + else if(!strncmp(src, ">", 1)){
  10281. + possibilities[i]->constraint = LATER_EQUAL;
  10282. + src++;
  10283. + }
  10284. +
  10285. + /* now we have any constraint, pass space to version string */
  10286. + while(isspace(*src)) src++;
  10287. +
  10288. + /* this would be the version string */
  10289. + dest = buffer;
  10290. + while(*src && *src != ')')
  10291. + *dest++ = *src++;
  10292. + *dest = '\0';
  10293. +
  10294. + possibilities[i]->version = trim_alloc(buffer);
  10295. + /* fprintf(stderr, "let's print the depends version string:");
  10296. + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
  10297. + if (possibilities[i]->version == NULL )
  10298. + return -ENOMEM;
  10299. +
  10300. +
  10301. + }
  10302. + /* hook up the dependency to its abstract pkg */
  10303. + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
  10304. +
  10305. + free(pkg_name);
  10306. +
  10307. + /* now get past the ) and any possible | chars */
  10308. + while(*src &&
  10309. + (isspace(*src) ||
  10310. + (*src == ')') ||
  10311. + (*src == '|')))
  10312. + src++;
  10313. + if (*src == '*')
  10314. + {
  10315. + compound_depend->type = GREEDY_DEPEND;
  10316. + src++;
  10317. + }
  10318. + }
  10319. +
  10320. + return 0;
  10321. +}
  10322. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_depends.h busybox-1.17.0/archival/libipkg/pkg_depends.h
  10323. --- busybox-1.17.0.orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
  10324. +++ busybox-1.17.0/archival/libipkg/pkg_depends.h 2010-07-15 21:53:17.896612955 +0200
  10325. @@ -0,0 +1,105 @@
  10326. +/* pkg_depends.h - the itsy package management system
  10327. +
  10328. + Steven M. Ayer
  10329. +
  10330. + Copyright (C) 2002 Compaq Computer Corporation
  10331. +
  10332. + This program is free software; you can redistribute it and/or
  10333. + modify it under the terms of the GNU General Public License as
  10334. + published by the Free Software Foundation; either version 2, or (at
  10335. + your option) any later version.
  10336. +
  10337. + This program is distributed in the hope that it will be useful, but
  10338. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10339. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10340. + General Public License for more details.
  10341. +*/
  10342. +
  10343. +#ifndef PKG_DEPENDS_H
  10344. +#define PKG_DEPENDS_H
  10345. +
  10346. +#include "pkg.h"
  10347. +#include "pkg_hash.h"
  10348. +
  10349. +enum depend_type {
  10350. + PREDEPEND,
  10351. + DEPEND,
  10352. + CONFLICTS,
  10353. + GREEDY_DEPEND,
  10354. + RECOMMEND,
  10355. + SUGGEST
  10356. +};
  10357. +typedef enum depend_type depend_type_t;
  10358. +
  10359. +enum version_constraint {
  10360. + NONE,
  10361. + EARLIER,
  10362. + EARLIER_EQUAL,
  10363. + EQUAL,
  10364. + LATER_EQUAL,
  10365. + LATER
  10366. +};
  10367. +typedef enum version_constraint version_constraint_t;
  10368. +
  10369. +struct depend{
  10370. + version_constraint_t constraint;
  10371. + char * version;
  10372. + abstract_pkg_t * pkg;
  10373. +};
  10374. +typedef struct depend depend_t;
  10375. +
  10376. +struct compound_depend{
  10377. + depend_type_t type;
  10378. + int possibility_count;
  10379. + struct depend ** possibilities;
  10380. +};
  10381. +typedef struct compound_depend compound_depend_t;
  10382. +
  10383. +#include "hash_table.h"
  10384. +
  10385. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10386. +int buildConflicts(hash_table_t * hash, pkg_t * pkg);
  10387. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10388. +int buildDepends(hash_table_t * hash, pkg_t * pkg);
  10389. +
  10390. +/**
  10391. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10392. + * the same abstract package and 0 otherwise.
  10393. + */
  10394. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
  10395. +
  10396. +/**
  10397. + * pkg_provides returns 1 if pkg->provides contains providee and 0
  10398. + * otherwise.
  10399. + */
  10400. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
  10401. +
  10402. +/**
  10403. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10404. + * otherwise.
  10405. + */
  10406. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
  10407. +
  10408. +/**
  10409. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
  10410. + * otherwise.
  10411. + */
  10412. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
  10413. +
  10414. +/**
  10415. + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
  10416. + * otherwise.
  10417. + */
  10418. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
  10419. +
  10420. +char *pkg_depend_str(pkg_t *pkg, int index_);
  10421. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
  10422. +void freeDepends(pkg_t *pkg);
  10423. +void printDepends(pkg_t * pkg);
  10424. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
  10425. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
  10426. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
  10427. +int pkg_dependence_satisfiable(depend_t *depend);
  10428. +int pkg_dependence_satisfied(depend_t *depend);
  10429. +
  10430. +#endif
  10431. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_dest.c busybox-1.17.0/archival/libipkg/pkg_dest.c
  10432. --- busybox-1.17.0.orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
  10433. +++ busybox-1.17.0/archival/libipkg/pkg_dest.c 2010-07-15 21:53:17.966509602 +0200
  10434. @@ -0,0 +1,92 @@
  10435. +/* pkg_dest.c - the itsy package management system
  10436. +
  10437. + Carl D. Worth
  10438. +
  10439. + Copyright (C) 2001 University of Southern California
  10440. +
  10441. + This program is free software; you can redistribute it and/or
  10442. + modify it under the terms of the GNU General Public License as
  10443. + published by the Free Software Foundation; either version 2, or (at
  10444. + your option) any later version.
  10445. +
  10446. + This program is distributed in the hope that it will be useful, but
  10447. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10448. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10449. + General Public License for more details.
  10450. +*/
  10451. +
  10452. +#include "ipkg.h"
  10453. +
  10454. +#include "pkg_dest.h"
  10455. +#include "file_util.h"
  10456. +#include "str_util.h"
  10457. +#include "sprintf_alloc.h"
  10458. +
  10459. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
  10460. +{
  10461. + dest->name = strdup(name);
  10462. +
  10463. + /* Guarantee that dest->root_dir ends with a '/' */
  10464. + if (str_ends_with(root_dir, "/")) {
  10465. + dest->root_dir = strdup(root_dir);
  10466. + } else {
  10467. + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
  10468. + }
  10469. + file_mkdir_hier(dest->root_dir, 0755);
  10470. +
  10471. + sprintf_alloc(&dest->ipkg_dir, "%s%s",
  10472. + dest->root_dir, IPKG_STATE_DIR_PREFIX);
  10473. + file_mkdir_hier(dest->ipkg_dir, 0755);
  10474. +
  10475. + if (str_starts_with (lists_dir, "/"))
  10476. + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
  10477. + else
  10478. + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
  10479. +
  10480. + file_mkdir_hier(dest->lists_dir, 0755);
  10481. +
  10482. + sprintf_alloc(&dest->info_dir, "%s/%s",
  10483. + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
  10484. + file_mkdir_hier(dest->info_dir, 0755);
  10485. +
  10486. + sprintf_alloc(&dest->status_file_name, "%s/%s",
  10487. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10488. +
  10489. + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
  10490. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10491. +
  10492. + dest->status_file = NULL;
  10493. +
  10494. + return 0;
  10495. +}
  10496. +
  10497. +void pkg_dest_deinit(pkg_dest_t *dest)
  10498. +{
  10499. + free(dest->name);
  10500. + dest->name = NULL;
  10501. +
  10502. + free(dest->root_dir);
  10503. + dest->root_dir = NULL;
  10504. +
  10505. + free(dest->ipkg_dir);
  10506. + dest->ipkg_dir = NULL;
  10507. +
  10508. + free(dest->lists_dir);
  10509. + dest->lists_dir = NULL;
  10510. +
  10511. + free(dest->info_dir);
  10512. + dest->info_dir = NULL;
  10513. +
  10514. + free(dest->status_file_name);
  10515. + dest->status_file_name = NULL;
  10516. +
  10517. + free(dest->status_file_tmp_name);
  10518. + dest->status_file_tmp_name = NULL;
  10519. +
  10520. + if (dest->status_file) {
  10521. + fclose(dest->status_file);
  10522. + }
  10523. + dest->status_file = NULL;
  10524. +
  10525. + dest->root_dir = NULL;
  10526. +}
  10527. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_dest.h busybox-1.17.0/archival/libipkg/pkg_dest.h
  10528. --- busybox-1.17.0.orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
  10529. +++ busybox-1.17.0/archival/libipkg/pkg_dest.h 2010-07-15 21:53:18.056081396 +0200
  10530. @@ -0,0 +1,38 @@
  10531. +/* pkg_dest.h - the itsy package management system
  10532. +
  10533. + Carl D. Worth
  10534. +
  10535. + Copyright (C) 2001 University of Southern California
  10536. +
  10537. + This program is free software; you can redistribute it and/or
  10538. + modify it under the terms of the GNU General Public License as
  10539. + published by the Free Software Foundation; either version 2, or (at
  10540. + your option) any later version.
  10541. +
  10542. + This program is distributed in the hope that it will be useful, but
  10543. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10544. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10545. + General Public License for more details.
  10546. +*/
  10547. +
  10548. +#ifndef PKG_DEST_H
  10549. +#define PKG_DEST_H
  10550. +
  10551. +typedef struct pkg_dest pkg_dest_t;
  10552. +struct pkg_dest
  10553. +{
  10554. + char *name;
  10555. + char *root_dir;
  10556. + char *ipkg_dir;
  10557. + char *lists_dir;
  10558. + char *info_dir;
  10559. + char *status_file_name;
  10560. + char *status_file_tmp_name;
  10561. + FILE *status_file;
  10562. +};
  10563. +
  10564. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
  10565. +void pkg_dest_deinit(pkg_dest_t *dest);
  10566. +
  10567. +#endif
  10568. +
  10569. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_dest_list.c busybox-1.17.0/archival/libipkg/pkg_dest_list.c
  10570. --- busybox-1.17.0.orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
  10571. +++ busybox-1.17.0/archival/libipkg/pkg_dest_list.c 2010-07-15 21:53:18.125859108 +0200
  10572. @@ -0,0 +1,85 @@
  10573. +/* pkg_dest_list.c - the itsy package management system
  10574. +
  10575. + Carl D. Worth
  10576. +
  10577. + Copyright (C) 2001 University of Southern California
  10578. +
  10579. + This program is free software; you can redistribute it and/or
  10580. + modify it under the terms of the GNU General Public License as
  10581. + published by the Free Software Foundation; either version 2, or (at
  10582. + your option) any later version.
  10583. +
  10584. + This program is distributed in the hope that it will be useful, but
  10585. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10586. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10587. + General Public License for more details.
  10588. +*/
  10589. +
  10590. +#include "ipkg.h"
  10591. +
  10592. +#include "pkg_dest.h"
  10593. +#include "void_list.h"
  10594. +#include "pkg_dest_list.h"
  10595. +
  10596. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
  10597. +{
  10598. + return void_list_elt_init((void_list_elt_t *) elt, data);
  10599. +}
  10600. +
  10601. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
  10602. +{
  10603. + void_list_elt_deinit((void_list_elt_t *) elt);
  10604. +}
  10605. +
  10606. +int pkg_dest_list_init(pkg_dest_list_t *list)
  10607. +{
  10608. + return void_list_init((void_list_t *) list);
  10609. +}
  10610. +
  10611. +void pkg_dest_list_deinit(pkg_dest_list_t *list)
  10612. +{
  10613. + pkg_dest_list_elt_t *iter;
  10614. + pkg_dest_t *pkg_dest;
  10615. +
  10616. + for (iter = list->head; iter; iter = iter->next) {
  10617. + pkg_dest = iter->data;
  10618. + pkg_dest_deinit(pkg_dest);
  10619. +
  10620. + /* malloced in pkg_dest_list_append */
  10621. + free(pkg_dest);
  10622. + iter->data = NULL;
  10623. + }
  10624. + void_list_deinit((void_list_t *) list);
  10625. +}
  10626. +
  10627. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10628. + const char *root_dir,const char *lists_dir)
  10629. +{
  10630. + int err;
  10631. + pkg_dest_t *pkg_dest;
  10632. +
  10633. + /* freed in plg_dest_list_deinit */
  10634. + pkg_dest = malloc(sizeof(pkg_dest_t));
  10635. + if (pkg_dest == NULL) {
  10636. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10637. + return NULL;
  10638. + }
  10639. +
  10640. + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
  10641. + err = void_list_append((void_list_t *) list, pkg_dest);
  10642. + if (err) {
  10643. + return NULL;
  10644. + }
  10645. +
  10646. + return pkg_dest;
  10647. +}
  10648. +
  10649. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
  10650. +{
  10651. + return void_list_push((void_list_t *) list, data);
  10652. +}
  10653. +
  10654. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
  10655. +{
  10656. + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
  10657. +}
  10658. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_dest_list.h busybox-1.17.0/archival/libipkg/pkg_dest_list.h
  10659. --- busybox-1.17.0.orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
  10660. +++ busybox-1.17.0/archival/libipkg/pkg_dest_list.h 2010-07-15 21:53:18.185858992 +0200
  10661. @@ -0,0 +1,50 @@
  10662. +/* pkg_dest_list.h - the itsy package management system
  10663. +
  10664. + Carl D. Worth
  10665. +
  10666. + Copyright (C) 2001 University of Southern California
  10667. +
  10668. + This program is free software; you can redistribute it and/or
  10669. + modify it under the terms of the GNU General Public License as
  10670. + published by the Free Software Foundation; either version 2, or (at
  10671. + your option) any later version.
  10672. +
  10673. + This program is distributed in the hope that it will be useful, but
  10674. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10675. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10676. + General Public License for more details.
  10677. +*/
  10678. +
  10679. +#ifndef PKG_DEST_LIST_H
  10680. +#define PKG_DEST_LIST_H
  10681. +
  10682. +#include "pkg_dest.h"
  10683. +
  10684. +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
  10685. +struct pkg_dest_list_elt
  10686. +{
  10687. + pkg_dest_list_elt_t *next;
  10688. + pkg_dest_t *data;
  10689. +};
  10690. +
  10691. +typedef struct pkg_dest_list pkg_dest_list_t;
  10692. +struct pkg_dest_list
  10693. +{
  10694. + pkg_dest_list_elt_t pre_head;
  10695. + pkg_dest_list_elt_t *head;
  10696. + pkg_dest_list_elt_t *tail;
  10697. +};
  10698. +
  10699. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
  10700. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
  10701. +
  10702. +int pkg_dest_list_init(pkg_dest_list_t *list);
  10703. +void pkg_dest_list_deinit(pkg_dest_list_t *list);
  10704. +
  10705. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10706. + const char *root_dir,const char* lists_dir);
  10707. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
  10708. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
  10709. +
  10710. +#endif
  10711. +
  10712. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_extract.c busybox-1.17.0/archival/libipkg/pkg_extract.c
  10713. --- busybox-1.17.0.orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
  10714. +++ busybox-1.17.0/archival/libipkg/pkg_extract.c 2010-07-15 21:53:18.235859123 +0200
  10715. @@ -0,0 +1,255 @@
  10716. +/* pkg_extract.c - the itsy package management system
  10717. +
  10718. + Carl D. Worth
  10719. +
  10720. + Copyright (C) 2001 University of Southern California
  10721. +
  10722. + This program is free software; you can redistribute it and/or
  10723. + modify it under the terms of the GNU General Public License as
  10724. + published by the Free Software Foundation; either version 2, or (at
  10725. + your option) any later version.
  10726. +
  10727. + This program is distributed in the hope that it will be useful, but
  10728. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10729. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10730. + General Public License for more details.
  10731. +*/
  10732. +
  10733. +#include "ipkg.h"
  10734. +#include <errno.h>
  10735. +#include <fcntl.h>
  10736. +#include <stdio.h>
  10737. +
  10738. +#include "pkg_extract.h"
  10739. +
  10740. +#include "libbb.h"
  10741. +#include "file_util.h"
  10742. +#include "sprintf_alloc.h"
  10743. +#include "unarchive.h"
  10744. +
  10745. +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
  10746. +#define IPKG_DATA_ARCHIVE "data.tar.gz"
  10747. +#define IPKG_CONTROL_FILE "control"
  10748. +
  10749. +static void FAST_FUNC ipkg_data_extract_all_prefix(archive_handle_t *archive_handle)
  10750. +{
  10751. + char *name_ptr = archive_handle->file_header->name;
  10752. +
  10753. + /* Skip all leading "/" */
  10754. + while (*name_ptr == '/')
  10755. + name_ptr++;
  10756. + /* Skip all leading "./" and "../" */
  10757. + while (name_ptr[0] == '.') {
  10758. + if (name_ptr[1] == '.' && name_ptr[2] == '/')
  10759. + name_ptr++;
  10760. + if (name_ptr[1] != '/')
  10761. + break;
  10762. + name_ptr += 2;
  10763. + }
  10764. +
  10765. + if (name_ptr[0] != '\0') {
  10766. + archive_handle->file_header->name = xasprintf("%s%s", archive_handle->dpkg__buffer, name_ptr);
  10767. + data_extract_all(archive_handle);
  10768. + }
  10769. +}
  10770. +
  10771. +static void FAST_FUNC ipkg_data_extract_to_buffer(archive_handle_t *archive_handle)
  10772. +{
  10773. + unsigned size = archive_handle->file_header->size;
  10774. +
  10775. + archive_handle->dpkg__buffer = xzalloc(size + 1);
  10776. + xread(archive_handle->src_fd, archive_handle->dpkg__buffer, size);
  10777. +}
  10778. +
  10779. +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
  10780. +{
  10781. + archive_handle_t *archive;
  10782. + char *path;
  10783. +
  10784. + sprintf_alloc(&path, "%s/", dir);
  10785. + archive = init_handle();
  10786. + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
  10787. + archive->filter = filter_accept_list;
  10788. + llist_add_to(&(archive->accept), (char *)filename);
  10789. + archive->dpkg__buffer = path;
  10790. + archive->action_data = ipkg_data_extract_all_prefix;
  10791. + archive->ah_flags |= ARCHIVE_UNLINK_OLD;
  10792. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10793. + close(archive->src_fd);
  10794. + free(archive->accept);
  10795. + free(archive);
  10796. + free(path);
  10797. +}
  10798. +
  10799. +static void FAST_FUNC data_extract_file_name_to_buffer(archive_handle_t *archive)
  10800. +{
  10801. + unsigned int size = strlen(archive->file_header->name) + 2;
  10802. +
  10803. + if (archive->dpkg__buffer == NULL) {
  10804. + archive->dpkg__buffer = xmalloc(size);
  10805. + strcpy(archive->dpkg__buffer, archive->file_header->name);
  10806. + } else {
  10807. + size += strlen(archive->dpkg__buffer);
  10808. + archive->dpkg__buffer = xrealloc(archive->dpkg__buffer, size);
  10809. + strcat(archive->dpkg__buffer, archive->file_header->name);
  10810. + }
  10811. + strcat(archive->dpkg__buffer, "\n");
  10812. + data_skip(archive);
  10813. +}
  10814. +
  10815. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
  10816. +{
  10817. + archive_handle_t *archive;
  10818. + char *name;
  10819. + const char *filename = "./" IPKG_CONTROL_FILE;
  10820. +
  10821. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10822. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10823. + archive = init_handle();
  10824. + archive->src_fd = xopen(name, O_RDONLY);
  10825. + archive->filter = filter_accept_list;
  10826. + llist_add_to(&(archive->accept), (char *)filename);
  10827. + archive->action_data = ipkg_data_extract_to_buffer;
  10828. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10829. + close(archive->src_fd);
  10830. + fputs(archive->dpkg__buffer, stream);
  10831. + free(archive->dpkg__buffer);
  10832. + free(archive->accept);
  10833. + free(archive);
  10834. + free(name);
  10835. +
  10836. + return 0;
  10837. +}
  10838. +
  10839. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
  10840. +{
  10841. + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
  10842. +}
  10843. +
  10844. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
  10845. +{
  10846. + archive_handle_t *archive;
  10847. + char *name;
  10848. + char *path;
  10849. +
  10850. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10851. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10852. + sprintf_alloc(&path, "%s/%s", dir, prefix);
  10853. + archive = init_handle();
  10854. + archive->src_fd = xopen(name, O_RDONLY);
  10855. + archive->filter = filter_accept_all;
  10856. + archive->dpkg__buffer = path;
  10857. + archive->action_data = ipkg_data_extract_all_prefix;
  10858. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  10859. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10860. + close(archive->src_fd);
  10861. + free(archive);
  10862. + free(path);
  10863. + free(name);
  10864. +
  10865. + return 0;
  10866. +}
  10867. +
  10868. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
  10869. +{
  10870. + archive_handle_t *archive;
  10871. + char *name;
  10872. + char *path;
  10873. +
  10874. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  10875. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  10876. + sprintf_alloc(&path, "%s/", dir);
  10877. + archive = init_handle();
  10878. + archive->src_fd = xopen(name, O_RDONLY);
  10879. + archive->filter = filter_accept_all;
  10880. + archive->dpkg__buffer = path;
  10881. + archive->action_data = ipkg_data_extract_all_prefix;
  10882. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  10883. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10884. + close(archive->src_fd);
  10885. + free(archive);
  10886. + free(path);
  10887. + free(name);
  10888. +
  10889. + return 0;
  10890. +}
  10891. +
  10892. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
  10893. +{
  10894. + int err=0;
  10895. + char *line, *data_file;
  10896. + FILE *file;
  10897. + FILE *tmp;
  10898. +
  10899. + file = fopen(file_name, "w");
  10900. + if (file == NULL) {
  10901. + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
  10902. + __FUNCTION__, file_name);
  10903. + return EINVAL;
  10904. + }
  10905. +
  10906. + tmp = tmpfile();
  10907. + if (pkg->installed_files) {
  10908. + str_list_elt_t *elt;
  10909. + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
  10910. + fprintf(file, "%s\n", elt->data);
  10911. + }
  10912. + } else {
  10913. + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
  10914. + if (err) {
  10915. + fclose(file);
  10916. + fclose(tmp);
  10917. + return err;
  10918. + }
  10919. +
  10920. + /* Fixup data file names by removing the initial '.' */
  10921. + rewind(tmp);
  10922. + while (1) {
  10923. + line = file_read_line_alloc(tmp);
  10924. + if (line == NULL) {
  10925. + break;
  10926. + }
  10927. +
  10928. + data_file = line;
  10929. + if (*data_file == '.') {
  10930. + data_file++;
  10931. + }
  10932. +
  10933. + if (*data_file != '/') {
  10934. + fputs("/", file);
  10935. + }
  10936. +
  10937. + /* I have no idea why, but this is what dpkg does */
  10938. + if (strcmp(data_file, "/\n") == 0) {
  10939. + fputs("/.\n", file);
  10940. + } else {
  10941. + fputs(data_file, file);
  10942. + }
  10943. + }
  10944. + }
  10945. + fclose(tmp);
  10946. + fclose(file);
  10947. +
  10948. + return err;
  10949. +}
  10950. +
  10951. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
  10952. +{
  10953. + archive_handle_t *archive;
  10954. + char *name;
  10955. +
  10956. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  10957. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  10958. + archive = init_handle();
  10959. + archive->src_fd = xopen(name, O_RDONLY);
  10960. + archive->filter = filter_accept_all;
  10961. + archive->action_data = data_extract_file_name_to_buffer;
  10962. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10963. + close(archive->src_fd);
  10964. + fputs(archive->dpkg__buffer, file);
  10965. + free(archive->dpkg__buffer);
  10966. + free(archive);
  10967. + free(name);
  10968. +
  10969. + return 0;
  10970. +}
  10971. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_extract.h busybox-1.17.0/archival/libipkg/pkg_extract.h
  10972. --- busybox-1.17.0.orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
  10973. +++ busybox-1.17.0/archival/libipkg/pkg_extract.h 2010-07-15 21:53:18.285858724 +0200
  10974. @@ -0,0 +1,32 @@
  10975. +/* pkg_extract.c - the itsy package management system
  10976. +
  10977. + Carl D. Worth
  10978. +
  10979. + Copyright (C) 2001 University of Southern California
  10980. +
  10981. + This program is free software; you can redistribute it and/or
  10982. + modify it under the terms of the GNU General Public License as
  10983. + published by the Free Software Foundation; either version 2, or (at
  10984. + your option) any later version.
  10985. +
  10986. + This program is distributed in the hope that it will be useful, but
  10987. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10988. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10989. + General Public License for more details.
  10990. +*/
  10991. +
  10992. +#ifndef PKG_EXTRACT_H
  10993. +#define PKG_EXTRACT_H
  10994. +
  10995. +#include "pkg.h"
  10996. +
  10997. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
  10998. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
  10999. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
  11000. + const char *dir,
  11001. + const char *prefix);
  11002. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
  11003. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
  11004. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
  11005. +
  11006. +#endif
  11007. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg.h busybox-1.17.0/archival/libipkg/pkg.h
  11008. --- busybox-1.17.0.orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
  11009. +++ busybox-1.17.0/archival/libipkg/pkg.h 2010-07-15 21:53:18.345858659 +0200
  11010. @@ -0,0 +1,229 @@
  11011. +/* pkg.h - the itsy package management system
  11012. +
  11013. + Carl D. Worth
  11014. +
  11015. + Copyright (C) 2001 University of Southern California
  11016. +
  11017. + This program is free software; you can redistribute it and/or
  11018. + modify it under the terms of the GNU General Public License as
  11019. + published by the Free Software Foundation; either version 2, or (at
  11020. + your option) any later version.
  11021. +
  11022. + This program is distributed in the hope that it will be useful, but
  11023. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11024. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11025. + General Public License for more details.
  11026. +*/
  11027. +
  11028. +#ifndef PKG_H
  11029. +#define PKG_H
  11030. +
  11031. +#include <sys/types.h>
  11032. +#include <sys/stat.h>
  11033. +#include <unistd.h>
  11034. +
  11035. +#include "pkg_vec.h"
  11036. +#include "str_list.h"
  11037. +#include "pkg_src.h"
  11038. +#include "pkg_dest.h"
  11039. +#include "ipkg_conf.h"
  11040. +#include "conffile_list.h"
  11041. +
  11042. +struct ipkg_conf;
  11043. +
  11044. +/* I think "Size" is currently the shortest field name */
  11045. +#define PKG_MINIMUM_FIELD_NAME_LEN 4
  11046. +
  11047. +enum pkg_state_want
  11048. +{
  11049. + SW_UNKNOWN = 1,
  11050. + SW_INSTALL,
  11051. + SW_DEINSTALL,
  11052. + SW_PURGE,
  11053. + SW_LAST_STATE_WANT
  11054. +};
  11055. +typedef enum pkg_state_want pkg_state_want_t;
  11056. +
  11057. +enum pkg_state_flag
  11058. +{
  11059. + SF_OK = 0,
  11060. + SF_REINSTREQ = 1,
  11061. + SF_HOLD = 2, /* do not upgrade version */
  11062. + SF_REPLACE = 4, /* replace this package */
  11063. + SF_NOPRUNE = 8, /* do not remove obsolete files */
  11064. + SF_PREFER = 16, /* prefer this version */
  11065. + SF_OBSOLETE = 32, /* old package in upgrade pair */
  11066. + SF_MARKED = 64, /* temporary mark */
  11067. + SF_FILELIST_CHANGED = 128, /* needs filelist written */
  11068. + SF_USER = 256,
  11069. + SF_LAST_STATE_FLAG
  11070. +};
  11071. +typedef enum pkg_state_flag pkg_state_flag_t;
  11072. +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
  11073. +
  11074. +enum pkg_state_status
  11075. +{
  11076. + SS_NOT_INSTALLED = 1,
  11077. + SS_UNPACKED,
  11078. + SS_HALF_CONFIGURED,
  11079. + SS_INSTALLED,
  11080. + SS_HALF_INSTALLED,
  11081. + SS_CONFIG_FILES,
  11082. + SS_POST_INST_FAILED,
  11083. + SS_REMOVAL_FAILED,
  11084. + SS_LAST_STATE_STATUS
  11085. +};
  11086. +typedef enum pkg_state_status pkg_state_status_t;
  11087. +
  11088. +struct abstract_pkg{
  11089. + char * name;
  11090. + int dependencies_checked;
  11091. + pkg_vec_t * pkgs;
  11092. + pkg_state_status_t state_status;
  11093. + pkg_state_flag_t state_flag;
  11094. + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
  11095. + abstract_pkg_vec_t * provided_by;
  11096. + abstract_pkg_vec_t * replaced_by;
  11097. +};
  11098. +
  11099. +#include "pkg_depends.h"
  11100. +
  11101. +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
  11102. +
  11103. + The 3 version fields should go into a single version struct. (This
  11104. + is especially important since, currently, pkg->version can easily
  11105. + be mistaken for pkg_verson_str_alloc(pkg) although they are very
  11106. + distinct. This has been the source of multiple bugs.
  11107. +
  11108. + The 3 state fields could possibly also go into their own struct.
  11109. +
  11110. + All fields which deal with lists of packages, (Depends,
  11111. + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
  11112. + be handled by a single struct in pkg_t
  11113. +
  11114. + All string fields for which there is a small set of possible
  11115. + values, (section, maintainer, architecture, maybe version?), that
  11116. + are reused among different packages -- for all such packages we
  11117. + should move from "char *"s to some atom datatype to share data
  11118. + storage and use less memory. We might even do reference counting,
  11119. + but probably not since most often we only create new pkg_t structs,
  11120. + we don't often free them. */
  11121. +struct pkg
  11122. +{
  11123. + char *name;
  11124. + unsigned long epoch;
  11125. + char *version;
  11126. + char *revision;
  11127. + char *familiar_revision;
  11128. + pkg_src_t *src;
  11129. + pkg_dest_t *dest;
  11130. + char *architecture;
  11131. + char *section;
  11132. + char *maintainer;
  11133. + char *description;
  11134. + pkg_state_want_t state_want;
  11135. + pkg_state_flag_t state_flag;
  11136. + pkg_state_status_t state_status;
  11137. + char **depends_str;
  11138. + int depends_count;
  11139. + char **pre_depends_str;
  11140. + int pre_depends_count;
  11141. + char **recommends_str;
  11142. + int recommends_count;
  11143. + char **suggests_str;
  11144. + int suggests_count;
  11145. + compound_depend_t * depends;
  11146. +
  11147. + /* Abhaya: new conflicts */
  11148. + char **conflicts_str;
  11149. + compound_depend_t * conflicts;
  11150. + int conflicts_count;
  11151. +
  11152. + char **replaces_str;
  11153. + int replaces_count;
  11154. + abstract_pkg_t ** replaces;
  11155. +
  11156. + char **provides_str;
  11157. + int provides_count;
  11158. + abstract_pkg_t ** provides;
  11159. +
  11160. + abstract_pkg_t *parent;
  11161. +
  11162. + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
  11163. +
  11164. + char *filename;
  11165. + char *local_filename;
  11166. + char *url;
  11167. + char *tmp_unpack_dir;
  11168. + char *md5sum;
  11169. + char *size;
  11170. + char *installed_size;
  11171. + char *priority;
  11172. + char *source;
  11173. + conffile_list_t conffiles;
  11174. + time_t installed_time;
  11175. + /* As pointer for lazy evaluation */
  11176. + str_list_t *installed_files;
  11177. + /* XXX: CLEANUP: I'd like to perhaps come up with a better
  11178. + mechanism to avoid the problem here, (which is that the
  11179. + installed_files list was being freed from an inner loop while
  11180. + still being used within an outer loop. */
  11181. + int installed_files_ref_cnt;
  11182. + int essential;
  11183. + int arch_priority;
  11184. +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
  11185. + int provided_by_hand;
  11186. +};
  11187. +
  11188. +pkg_t *pkg_new(void);
  11189. +int pkg_init(pkg_t *pkg);
  11190. +void pkg_deinit(pkg_t *pkg);
  11191. +int pkg_init_from_file(pkg_t *pkg, const char *filename);
  11192. +abstract_pkg_t *abstract_pkg_new(void);
  11193. +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
  11194. +
  11195. +/*
  11196. + * merges fields from newpkg into oldpkg.
  11197. + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
  11198. + */
  11199. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
  11200. +
  11201. +char *pkg_version_str_alloc(pkg_t *pkg);
  11202. +
  11203. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
  11204. +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
  11205. +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
  11206. +
  11207. +char * pkg_formatted_info(pkg_t *pkg );
  11208. +char * pkg_formatted_field(pkg_t *pkg, const char *field );
  11209. +
  11210. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
  11211. +
  11212. +void pkg_print_info(pkg_t *pkg, FILE *file);
  11213. +void pkg_print_status(pkg_t * pkg, FILE * file);
  11214. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
  11215. +str_list_t *pkg_get_installed_files(pkg_t *pkg);
  11216. +int pkg_free_installed_files(pkg_t *pkg);
  11217. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
  11218. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
  11219. +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
  11220. + const char *script, const char *args);
  11221. +
  11222. +/* enum mappings */
  11223. +char *pkg_state_want_to_str(pkg_state_want_t sw);
  11224. +pkg_state_want_t pkg_state_want_from_str(char *str);
  11225. +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
  11226. +pkg_state_flag_t pkg_state_flag_from_str(char *str);
  11227. +char *pkg_state_status_to_str(pkg_state_status_t ss);
  11228. +pkg_state_status_t pkg_state_status_from_str(char *str);
  11229. +
  11230. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
  11231. +
  11232. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
  11233. +int pkg_info_preinstall_check(ipkg_conf_t *conf);
  11234. +int pkg_free_installed_files(pkg_t *pkg);
  11235. +
  11236. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
  11237. +int pkg_write_changed_filelists(ipkg_conf_t *conf);
  11238. +
  11239. +#endif
  11240. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_hash.c busybox-1.17.0/archival/libipkg/pkg_hash.c
  11241. --- busybox-1.17.0.orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
  11242. +++ busybox-1.17.0/archival/libipkg/pkg_hash.c 2010-07-15 21:53:18.405858501 +0200
  11243. @@ -0,0 +1,623 @@
  11244. +/* ipkg_hash.c - the itsy package management system
  11245. +
  11246. + Steven M. Ayer
  11247. +
  11248. + Copyright (C) 2002 Compaq Computer Corporation
  11249. +
  11250. + This program is free software; you can redistribute it and/or
  11251. + modify it under the terms of the GNU General Public License as
  11252. + published by the Free Software Foundation; either version 2, or (at
  11253. + your option) any later version.
  11254. +
  11255. + This program is distributed in the hope that it will be useful, but
  11256. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11257. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11258. + General Public License for more details.
  11259. +*/
  11260. +
  11261. +#include "ipkg.h"
  11262. +#include <errno.h>
  11263. +#include <ctype.h>
  11264. +#include <stdlib.h>
  11265. +#include <string.h>
  11266. +
  11267. +#include "hash_table.h"
  11268. +#include "pkg.h"
  11269. +#include "ipkg_message.h"
  11270. +#include "pkg_vec.h"
  11271. +#include "pkg_hash.h"
  11272. +#include "pkg_parse.h"
  11273. +#include "ipkg_utils.h"
  11274. +
  11275. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11276. +
  11277. +/*
  11278. + * this will talk to both feeds-lists files and installed status files
  11279. + * example api:
  11280. + *
  11281. + * hash_table_t hash;
  11282. + * pkg_hash_init(name, &hash, 1000);
  11283. + * pkg_hash_add_from_file(<feed filename>);
  11284. + *
  11285. + * the query function is just there as a shell to prove to me that this
  11286. + * sort of works, but isn't far from doing something useful
  11287. + *
  11288. + * -sma, 12/21/01
  11289. + * modified: CDW 3 Jan. 2002
  11290. + */
  11291. +
  11292. +
  11293. +
  11294. +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
  11295. +{
  11296. + return hash_table_init(name, hash, len);
  11297. +}
  11298. +
  11299. +void pkg_hash_deinit(hash_table_t *hash)
  11300. +{
  11301. + hash_table_deinit(hash);
  11302. +}
  11303. +
  11304. +
  11305. +/* Find the default arch for a given package status file if none is given. */
  11306. +static char *pkg_get_default_arch(ipkg_conf_t *conf)
  11307. +{
  11308. + nv_pair_list_elt_t *l;
  11309. + const char *def_arch = HOST_CPU_STR; /* Default arch */
  11310. + int def_prio = 0; /* Other archs override this */
  11311. +
  11312. + l = conf->arch_list.head;
  11313. +
  11314. + while (l) {
  11315. + nv_pair_t *nv = l->data;
  11316. + int priority = strtol(nv->value, NULL, 0);
  11317. +
  11318. + /* Check if this arch has higher priority, and is valid */
  11319. + if ((priority > def_prio) &&
  11320. + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
  11321. + /* Our new default */
  11322. + def_prio = priority;
  11323. + def_arch = nv->name;
  11324. + }
  11325. + l = l->next;
  11326. + }
  11327. +
  11328. + return strdup(def_arch);
  11329. +}
  11330. +
  11331. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11332. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
  11333. +{
  11334. + hash_table_t *hash = &conf->pkg_hash;
  11335. + char **raw;
  11336. + char **raw_start;
  11337. + pkg_t *pkg;
  11338. +
  11339. + raw = raw_start = read_raw_pkgs_from_file(file_name);
  11340. + if (!raw)
  11341. + return -ENOMEM;
  11342. +
  11343. + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
  11344. + pkg = pkg_new();
  11345. + if (!pkg)
  11346. + return -ENOMEM;
  11347. +
  11348. + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
  11349. + if (!pkg->architecture) {
  11350. + char *version_str = pkg_version_str_alloc(pkg);
  11351. + pkg->architecture = pkg_get_default_arch(conf);
  11352. + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
  11353. + pkg->name, version_str, pkg->architecture);
  11354. + free(version_str);
  11355. + }
  11356. + hash_insert_pkg(hash, pkg, is_status_file,conf);
  11357. + } else {
  11358. + free(pkg);
  11359. + }
  11360. + }
  11361. +
  11362. + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
  11363. + memory after read_raw_pkgs_from_file */
  11364. + raw = raw_start;
  11365. + while (*raw) {
  11366. + free(*raw++);
  11367. + }
  11368. + free(raw_start);
  11369. + return 0;
  11370. +}
  11371. +
  11372. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
  11373. +{
  11374. + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
  11375. +}
  11376. +
  11377. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
  11378. +{
  11379. + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
  11380. + if (apkg)
  11381. + return NULL;
  11382. + return apkg->provided_by;
  11383. +}
  11384. +
  11385. +
  11386. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11387. + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
  11388. +{
  11389. + int i;
  11390. + int nprovides = 0;
  11391. + int nmatching = 0;
  11392. + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
  11393. + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
  11394. + abstract_pkg_vec_t *provided_apkg_vec;
  11395. + abstract_pkg_t **provided_apkgs;
  11396. + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
  11397. + pkg_t *latest_installed_parent = NULL;
  11398. + pkg_t *latest_matching = NULL;
  11399. + pkg_t *held_pkg = NULL;
  11400. + pkg_t *good_pkg_by_name = NULL;
  11401. +
  11402. + if (matching_apkgs == NULL || providers == NULL ||
  11403. + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
  11404. + return NULL;
  11405. +
  11406. + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
  11407. +
  11408. + provided_apkg_vec = apkg->provided_by;
  11409. + nprovides = provided_apkg_vec->len;
  11410. + provided_apkgs = provided_apkg_vec->pkgs;
  11411. + if (nprovides > 1)
  11412. + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
  11413. +
  11414. + /* accumulate all the providers */
  11415. + for (i = 0; i < nprovides; i++) {
  11416. + abstract_pkg_t *provider_apkg = provided_apkgs[i];
  11417. + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
  11418. + abstract_pkg_vec_insert(providers, provider_apkg);
  11419. + }
  11420. + nprovides = providers->len;
  11421. +
  11422. + for (i = 0; i < nprovides; i++) {
  11423. + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
  11424. + abstract_pkg_t *replacement_apkg = NULL;
  11425. + pkg_vec_t *vec;
  11426. +
  11427. + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
  11428. + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
  11429. + if (provider_apkg->replaced_by->len > 1) {
  11430. + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
  11431. + provider_apkg->name, replacement_apkg->name);
  11432. + }
  11433. + }
  11434. +
  11435. + if (replacement_apkg)
  11436. + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
  11437. + replacement_apkg->name, provider_apkg->name);
  11438. +
  11439. + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
  11440. + if (abstract_pkg_vec_contains(providers, replacement_apkg))
  11441. + continue;
  11442. + else
  11443. + provider_apkg = replacement_apkg;
  11444. + }
  11445. +
  11446. + if (!(vec = provider_apkg->pkgs)) {
  11447. + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
  11448. + continue;
  11449. + }
  11450. +
  11451. +
  11452. + /* now check for supported architecture */
  11453. + {
  11454. + int max_count = 0;
  11455. + int j;
  11456. +
  11457. + /* count packages matching max arch priority and keep track of last one */
  11458. + for (j = 0; j < vec->len; j++) {
  11459. + pkg_t *maybe = vec->pkgs[j];
  11460. + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
  11461. + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
  11462. + if (maybe->arch_priority > 0) {
  11463. + max_count++;
  11464. + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
  11465. + pkg_vec_insert(matching_pkgs, maybe);
  11466. + }
  11467. + }
  11468. + }
  11469. + }
  11470. +
  11471. + if (matching_pkgs->len > 1)
  11472. + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
  11473. + if (matching_apkgs->len > 1)
  11474. + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
  11475. +
  11476. +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
  11477. + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
  11478. +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
  11479. + Until now I always got the latest, but that breaks the downgrade option.
  11480. + If I stop at the first one, I would probably miss the new ones
  11481. + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
  11482. + or from a Packages feed.
  11483. + 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*/
  11484. +/*Pigi*/
  11485. +
  11486. + for (i = 0; i < matching_pkgs->len; i++) {
  11487. + pkg_t *matching = matching_pkgs->pkgs[i];
  11488. + if (constraint_fcn(matching, cdata)) { /* We found it */
  11489. + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
  11490. + good_pkg_by_name = matching;
  11491. + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
  11492. + break;
  11493. + }
  11494. + }
  11495. +
  11496. +
  11497. + for (i = 0; i < matching_pkgs->len; i++) {
  11498. + pkg_t *matching = matching_pkgs->pkgs[i];
  11499. + latest_matching = matching;
  11500. + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
  11501. + latest_installed_parent = matching;
  11502. + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
  11503. + if (held_pkg)
  11504. + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
  11505. + held_pkg->name, matching->name);
  11506. + held_pkg = matching;
  11507. + }
  11508. + }
  11509. +
  11510. + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
  11511. + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
  11512. + apkg->name, matching_apkgs->len);
  11513. + for (i = 0; i < matching_apkgs->len; i++) {
  11514. + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
  11515. + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
  11516. + }
  11517. + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
  11518. + }
  11519. +
  11520. + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
  11521. + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
  11522. + __FUNCTION__, apkg->name, matching_pkgs->len);
  11523. + for (i = 0; i < matching_pkgs->len; i++) {
  11524. + pkg_t *matching = matching_pkgs->pkgs[i];
  11525. + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
  11526. + matching->name, matching->version, matching->architecture);
  11527. + }
  11528. + }
  11529. +
  11530. + nmatching = matching_apkgs->len;
  11531. +
  11532. + pkg_vec_free(matching_pkgs);
  11533. + abstract_pkg_vec_free(matching_apkgs);
  11534. + abstract_pkg_vec_free(providers);
  11535. +
  11536. + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
  11537. + return good_pkg_by_name;
  11538. + }
  11539. + if (held_pkg) {
  11540. + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
  11541. + return held_pkg;
  11542. + }
  11543. + if (latest_installed_parent) {
  11544. + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
  11545. + return latest_installed_parent;
  11546. + }
  11547. + if (nmatching > 1) {
  11548. + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
  11549. + return NULL;
  11550. + }
  11551. + if (latest_matching) {
  11552. + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
  11553. + latest_matching->name, latest_matching->version, latest_matching->architecture);
  11554. + return latest_matching;
  11555. + }
  11556. + return NULL;
  11557. +}
  11558. +
  11559. +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
  11560. +{
  11561. + const char *name = (const char *)cdata;
  11562. + if (strcmp(pkg->name, name) == 0)
  11563. + return 1;
  11564. + else
  11565. + return 0;
  11566. +}
  11567. +
  11568. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
  11569. +{
  11570. + hash_table_t *hash = &conf->pkg_hash;
  11571. + abstract_pkg_t *apkg = NULL;
  11572. +
  11573. + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
  11574. + return NULL;
  11575. +
  11576. + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
  11577. +}
  11578. +
  11579. +
  11580. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11581. + const char *pkg_name,
  11582. + const char * version)
  11583. +{
  11584. + pkg_vec_t * vec;
  11585. + register int i;
  11586. + char *version_str = NULL;
  11587. +
  11588. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
  11589. + return NULL;
  11590. +
  11591. + for(i = 0; i < vec->len; i++) {
  11592. + version_str = pkg_version_str_alloc(vec->pkgs[i]);
  11593. + if(!strcmp(version_str, version)) {
  11594. + free(version_str);
  11595. + break;
  11596. + }
  11597. + free(version_str);
  11598. + }
  11599. +
  11600. + if(i == vec->len)
  11601. + return NULL;
  11602. +
  11603. + return vec->pkgs[i];
  11604. +}
  11605. +
  11606. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11607. + const char *pkg_name,
  11608. + pkg_dest_t *dest)
  11609. +{
  11610. + pkg_vec_t * vec;
  11611. + register int i;
  11612. +
  11613. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
  11614. + return NULL;
  11615. + }
  11616. +
  11617. + for(i = 0; i < vec->len; i++)
  11618. + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
  11619. + return vec->pkgs[i];
  11620. + }
  11621. + return NULL;
  11622. +}
  11623. +
  11624. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11625. + const char *pkg_name)
  11626. +{
  11627. + pkg_vec_t * vec;
  11628. + register int i;
  11629. +
  11630. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
  11631. + return NULL;
  11632. + }
  11633. +
  11634. + for(i = 0; i < vec->len; i++)
  11635. + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
  11636. + return vec->pkgs[i];
  11637. + }
  11638. +
  11639. + return NULL;
  11640. +}
  11641. +
  11642. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
  11643. +{
  11644. + abstract_pkg_t * ab_pkg;
  11645. +
  11646. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
  11647. + return NULL;
  11648. + }
  11649. +
  11650. + if (ab_pkg->pkgs) {
  11651. + return ab_pkg->pkgs;
  11652. + } else if (ab_pkg->provided_by) {
  11653. + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
  11654. + if (abpkg != NULL){
  11655. + return abpkg->pkgs;
  11656. + } else {
  11657. + return ab_pkg->pkgs;
  11658. + }
  11659. + } else {
  11660. + return NULL;
  11661. + }
  11662. +}
  11663. +
  11664. +static int pkg_compare_names(const void *p1, const void *p2)
  11665. +{
  11666. + const pkg_t *pkg1 = *(const pkg_t **)p1;
  11667. + const pkg_t *pkg2 = *(const pkg_t **)p2;
  11668. + if (pkg1->name == NULL)
  11669. + return 1;
  11670. + if (pkg2->name == NULL)
  11671. + return -1;
  11672. + return(strcmp(pkg1->name, pkg2->name));
  11673. +}
  11674. +
  11675. +
  11676. +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
  11677. +{
  11678. + int j;
  11679. + const char *name;
  11680. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11681. + pkg_vec_t *all = (pkg_vec_t *)data;
  11682. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11683. + name = pkg_name;
  11684. + if (pkg_vec) {
  11685. + for (j = 0; j < pkg_vec->len; j++) {
  11686. + pkg_t *pkg = pkg_vec->pkgs[j];
  11687. + pkg_vec_insert(all, pkg);
  11688. + }
  11689. + }
  11690. +}
  11691. +
  11692. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
  11693. +{
  11694. + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
  11695. + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
  11696. +}
  11697. +
  11698. +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
  11699. +{
  11700. + const char *name;
  11701. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11702. + pkg_vec_t *all = (pkg_vec_t *)data;
  11703. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11704. + int j;
  11705. + name = pkg_name;
  11706. + if (pkg_vec) {
  11707. + for (j = 0; j < pkg_vec->len; j++) {
  11708. + pkg_t *pkg = pkg_vec->pkgs[j];
  11709. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  11710. + pkg_vec_insert(all, pkg);
  11711. + }
  11712. + }
  11713. + }
  11714. +}
  11715. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
  11716. +{
  11717. + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
  11718. + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
  11719. +}
  11720. +
  11721. +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
  11722. +{
  11723. + int i;
  11724. + pkg_t *pkg;
  11725. + const char *name;
  11726. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11727. + ipkg_conf_t *conf = (ipkg_conf_t *)data;
  11728. + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
  11729. + name = pkg_name;
  11730. + fprintf(stdout, "%s\n", ab_pkg->name);
  11731. + i = 0;
  11732. + if (dependents != NULL)
  11733. + while (dependents [i] != NULL)
  11734. + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
  11735. + dependents = ab_pkg->provided_by->pkgs;
  11736. + i = 0;
  11737. + if (dependents != NULL)
  11738. + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
  11739. + printf ("\tprovided by - %s\n", dependents [i ++]->name);
  11740. + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
  11741. + if (pkg) {
  11742. + i = 0;
  11743. + while (i < pkg->depends_count)
  11744. + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
  11745. + }
  11746. +}
  11747. +void pkg_hash_dump(hash_table_t *hash, void *data)
  11748. +{
  11749. +
  11750. + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
  11751. + hash_table_foreach(hash, pkg_hash_dump_helper, data);
  11752. + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
  11753. +}
  11754. +
  11755. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11756. +{
  11757. + abstract_pkg_t * ab_pkg;
  11758. +
  11759. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
  11760. + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
  11761. +
  11762. + return ab_pkg;
  11763. +}
  11764. +
  11765. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  11766. +{
  11767. + abstract_pkg_t * ab_pkg;
  11768. + int arch_priority;
  11769. +
  11770. + if(!pkg)
  11771. + return pkg;
  11772. +
  11773. + arch_priority = pkg->arch_priority;
  11774. +
  11775. + if (buildDepends(hash, pkg)<0){
  11776. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11777. + return NULL;
  11778. + }
  11779. + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
  11780. +
  11781. + if (set_status) {
  11782. + if (pkg->state_status == SS_INSTALLED) {
  11783. + ab_pkg->state_status = SS_INSTALLED;
  11784. + } else if (pkg->state_status == SS_UNPACKED) {
  11785. + ab_pkg->state_status = SS_UNPACKED;
  11786. + }
  11787. + }
  11788. +
  11789. + if(!ab_pkg->pkgs)
  11790. + ab_pkg->pkgs = pkg_vec_alloc();
  11791. +
  11792. + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
  11793. + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
  11794. + pkg->parent = ab_pkg;
  11795. +
  11796. + if (buildProvides(hash, ab_pkg, pkg)<0){
  11797. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11798. + return NULL;
  11799. + }
  11800. + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
  11801. + if (buildConflicts(hash, pkg)<0){
  11802. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11803. + return NULL;
  11804. + }
  11805. + if (buildReplaces(hash, ab_pkg, pkg)<0) {
  11806. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11807. + return NULL;
  11808. + }
  11809. +
  11810. + buildDependedUponBy(pkg, ab_pkg);
  11811. + return pkg;
  11812. +}
  11813. +
  11814. +/*
  11815. + * this will assume that we've already determined that
  11816. + * the abstract pkg doesn't exist, 'cause we should know these things...
  11817. + */
  11818. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11819. +{
  11820. + abstract_pkg_t * ab_pkg;
  11821. +
  11822. + ab_pkg = abstract_pkg_new();
  11823. + if (ab_pkg == NULL) { return NULL; }
  11824. +
  11825. + ab_pkg->name = strdup(pkg_name);
  11826. + hash_table_insert(hash, pkg_name, ab_pkg);
  11827. +
  11828. + return ab_pkg;
  11829. +}
  11830. +
  11831. +
  11832. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
  11833. +{
  11834. + hash_table_t *file_hash = &conf->file_hash;
  11835. +
  11836. + return hash_table_get(file_hash, file_name);
  11837. +}
  11838. +
  11839. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
  11840. +{
  11841. + hash_table_t *file_hash = &conf->file_hash;
  11842. + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
  11843. + int file_name_len = strlen(file_name);
  11844. +
  11845. + if (file_name[file_name_len -1] == '/')
  11846. + return 0;
  11847. +
  11848. + if (conf->offline_root) {
  11849. + int len = strlen(conf->offline_root);
  11850. + if (strncmp(file_name, conf->offline_root, len) == 0) {
  11851. + file_name += len;
  11852. + }
  11853. + }
  11854. +
  11855. + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
  11856. + hash_table_insert(file_hash, file_name, owning_pkg);
  11857. + if (old_owning_pkg) {
  11858. + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
  11859. + /* mark this package to have its filelist written */
  11860. + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11861. + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11862. + }
  11863. + return 0;
  11864. +}
  11865. +
  11866. +
  11867. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_hash.h busybox-1.17.0/archival/libipkg/pkg_hash.h
  11868. --- busybox-1.17.0.orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
  11869. +++ busybox-1.17.0/archival/libipkg/pkg_hash.h 2010-07-15 21:53:18.465858583 +0200
  11870. @@ -0,0 +1,61 @@
  11871. +/* pkg_hash.h - the itsy package management system
  11872. +
  11873. + Steven M. Ayer
  11874. +
  11875. + Copyright (C) 2002 Compaq Computer Corporation
  11876. +
  11877. + This program is free software; you can redistribute it and/or
  11878. + modify it under the terms of the GNU General Public License as
  11879. + published by the Free Software Foundation; either version 2, or (at
  11880. + your option) any later version.
  11881. +
  11882. + This program is distributed in the hope that it will be useful, but
  11883. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11884. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11885. + General Public License for more details.
  11886. +*/
  11887. +
  11888. +#ifndef PKG_HASH_H
  11889. +#define PKG_HASH_H
  11890. +
  11891. +#include "pkg.h"
  11892. +#include "pkg_vec.h"
  11893. +#include "hash_table.h"
  11894. +
  11895. +
  11896. +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
  11897. +void pkg_hash_deinit(hash_table_t *hash);
  11898. +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
  11899. +
  11900. +void pkg_hash_dump(hash_table_t *hash, void *data);
  11901. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
  11902. +
  11903. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11904. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
  11905. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
  11906. +
  11907. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11908. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
  11909. +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11910. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
  11911. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11912. + const char *pkg_name,
  11913. + const char * version);
  11914. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
  11915. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11916. + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
  11917. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
  11918. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11919. + const char *pkg_name);
  11920. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11921. + const char *pkg_name,
  11922. + pkg_dest_t *dest);
  11923. +
  11924. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
  11925. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
  11926. +
  11927. +/* XXX: shouldn't this go in pkg_vec.[ch]? */
  11928. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11929. +
  11930. +#endif
  11931. +
  11932. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_parse.c busybox-1.17.0/archival/libipkg/pkg_parse.c
  11933. --- busybox-1.17.0.orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
  11934. +++ busybox-1.17.0/archival/libipkg/pkg_parse.c 2010-07-15 21:53:18.525861517 +0200
  11935. @@ -0,0 +1,368 @@
  11936. +/* pkg_parse.c - the itsy package management system
  11937. +
  11938. + Steven M. Ayer
  11939. +
  11940. + Copyright (C) 2002 Compaq Computer Corporation
  11941. +
  11942. + This program is free software; you can redistribute it and/or
  11943. + modify it under the terms of the GNU General Public License as
  11944. + published by the Free Software Foundation; either version 2, or (at
  11945. + your option) any later version.
  11946. +
  11947. + This program is distributed in the hope that it will be useful, but
  11948. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11949. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11950. + General Public License for more details.
  11951. +*/
  11952. +
  11953. +#include "ipkg.h"
  11954. +#include <errno.h>
  11955. +#include <ctype.h>
  11956. +
  11957. +#include "pkg.h"
  11958. +#include "ipkg_utils.h"
  11959. +#include "pkg_parse.h"
  11960. +
  11961. +int alterProvidesLine(char *raw, char *temp);
  11962. +
  11963. +int isGenericFieldType(char * type, char * line)
  11964. +{
  11965. + if(!strncmp(line, type, strlen(type)))
  11966. + return 1;
  11967. + return 0;
  11968. +}
  11969. +
  11970. +char * parseGenericFieldType(char * type, char * raw)
  11971. +{
  11972. + char * field_value = raw + (strlen(type) + 1);
  11973. + return trim_alloc(field_value);
  11974. +}
  11975. +
  11976. +void parseStatus(pkg_t *pkg, char * raw)
  11977. +{
  11978. + char sw_str[64], sf_str[64], ss_str[64];
  11979. +
  11980. + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
  11981. + pkg->state_want = pkg_state_want_from_str(sw_str);
  11982. + pkg->state_flag = pkg_state_flag_from_str(sf_str);
  11983. + pkg->state_status = pkg_state_status_from_str(ss_str);
  11984. +}
  11985. +
  11986. +char ** parseDependsString(char * raw, int * depends_count)
  11987. +{
  11988. + char ** depends = NULL;
  11989. + int line_count = 0;
  11990. + char buff[2048], * dest;
  11991. +
  11992. + while(raw && *raw && !isspace(*raw)) {
  11993. + raw++;
  11994. + }
  11995. +
  11996. + if(line_is_blank(raw)){
  11997. + *depends_count = line_count;
  11998. + return NULL;
  11999. + }
  12000. + while(raw && *raw){
  12001. + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
  12002. +
  12003. + while(isspace(*raw)) raw++;
  12004. +
  12005. + dest = buff;
  12006. + while((*raw != ',') && *raw)
  12007. + *dest++ = *raw++;
  12008. +
  12009. + *dest = '\0';
  12010. + depends[line_count] = trim_alloc(buff);
  12011. + if(depends[line_count] ==NULL)
  12012. + return NULL;
  12013. + line_count++;
  12014. + if(*raw == ',')
  12015. + raw++;
  12016. + }
  12017. + *depends_count = line_count;
  12018. + return depends;
  12019. +}
  12020. +
  12021. +void parseConffiles(pkg_t * pkg, char * raw)
  12022. +{
  12023. + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
  12024. +
  12025. + if(!strncmp(raw, "Conffiles:", 10))
  12026. + raw += strlen("Conffiles:");
  12027. +
  12028. + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
  12029. + conffile_list_append(&pkg->conffiles, file_name, md5sum);
  12030. + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
  12031. + while (*raw && isspace(*raw)) {
  12032. + raw++;
  12033. + }
  12034. + raw += strlen(file_name);
  12035. + while (*raw && isspace(*raw)) {
  12036. + raw++;
  12037. + }
  12038. + raw += strlen(md5sum);
  12039. + }
  12040. +}
  12041. +
  12042. +int parseVersion(pkg_t *pkg, char *raw)
  12043. +{
  12044. + char *colon, *eepochcolon;
  12045. +#ifdef USE_DEBVERSION
  12046. + char *hyphen;
  12047. +#endif
  12048. + unsigned long epoch;
  12049. +
  12050. + if (!*raw) {
  12051. + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
  12052. + return EINVAL;
  12053. + }
  12054. +
  12055. + if (strncmp(raw, "Version:", 8) == 0) {
  12056. + raw += 8;
  12057. + }
  12058. + while (*raw && isspace(*raw)) {
  12059. + raw++;
  12060. + }
  12061. +
  12062. + colon= strchr(raw,':');
  12063. + if (colon) {
  12064. + epoch= strtoul(raw,&eepochcolon,10);
  12065. + if (colon != eepochcolon) {
  12066. + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
  12067. + return EINVAL;
  12068. + }
  12069. + if (!*++colon) {
  12070. + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
  12071. + return EINVAL;
  12072. + }
  12073. + raw= colon;
  12074. + pkg->epoch= epoch;
  12075. + } else {
  12076. + pkg->epoch= 0;
  12077. + }
  12078. +
  12079. + pkg->revision = (char *)"";
  12080. + pkg->familiar_revision = (char *)"";
  12081. +
  12082. + pkg->version= malloc(strlen(raw)+1);
  12083. + if ( pkg->version == NULL ) {
  12084. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12085. + return ENOMEM;
  12086. + }
  12087. + strcpy(pkg->version, raw);
  12088. +
  12089. +#ifdef USE_DEBVERSION
  12090. + hyphen= strrchr(pkg->version,'-');
  12091. +
  12092. + if (hyphen) {
  12093. + *hyphen++= 0;
  12094. + if (strncmp("fam", hyphen, 3) == 0) {
  12095. + pkg->familiar_revision=hyphen+3;
  12096. + hyphen= strrchr(pkg->version,'-');
  12097. + if (hyphen) {
  12098. + *hyphen++= 0;
  12099. + pkg->revision = hyphen;
  12100. + }
  12101. + } else {
  12102. + pkg->revision = hyphen;
  12103. + }
  12104. + }
  12105. +#endif
  12106. +
  12107. +/*
  12108. + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
  12109. + pkg->epoch,
  12110. + pkg->version,
  12111. + pkg->revision,
  12112. + pkg->familiar_revision);
  12113. +*/
  12114. +
  12115. + return 0;
  12116. +}
  12117. +
  12118. +
  12119. +/* This code is needed to insert in first position the keyword for the aligning bug */
  12120. +
  12121. +int alterProvidesLine(char *raw, char *temp)
  12122. +{
  12123. +
  12124. +
  12125. + if (!*raw) {
  12126. + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
  12127. + return -EINVAL;
  12128. + }
  12129. +
  12130. + if ( temp == NULL ) {
  12131. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12132. + return -ENOMEM;
  12133. + }
  12134. +
  12135. + if (strncmp(raw, "Provides:", 9) == 0) {
  12136. + raw += 9;
  12137. + }
  12138. + while (*raw && isspace(*raw)) {
  12139. + raw++;
  12140. + }
  12141. +
  12142. + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
  12143. + while (*raw) {
  12144. + strncat( temp, raw++, 1);
  12145. + }
  12146. + return 0;
  12147. +
  12148. +}
  12149. +
  12150. +/* Some random thoughts from Carl:
  12151. +
  12152. + This function could be considerably simplified if we just kept
  12153. + an array of all the generic string-valued field names, and looped
  12154. + through those looking for a match. Also, these fields could perhaps
  12155. + be stored in the package as an array as well, (or, probably better,
  12156. + as an nv_pair_list_t).
  12157. +
  12158. + Fields which require special parsing or storage, (such as Depends:
  12159. + and Status:) could be handled as they are now.
  12160. +*/
  12161. +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
  12162. + to a dependency list. And, since we already have
  12163. + Depends/Pre-Depends and need to add Conflicts, Recommends, and
  12164. + Enhances, perhaps we could generalize all of these and save some
  12165. + code duplication.
  12166. +*/
  12167. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
  12168. +{
  12169. + int reading_conffiles, reading_description;
  12170. + int pkg_false_provides=1;
  12171. + char ** lines;
  12172. + char * provide=NULL;
  12173. +
  12174. + pkg->src = src;
  12175. + pkg->dest = dest;
  12176. +
  12177. + reading_conffiles = reading_description = 0;
  12178. +
  12179. + for (lines = *raw; *lines; lines++) {
  12180. + /* fprintf(stderr, "PARSING %s\n", *lines);*/
  12181. + if(isGenericFieldType((char *)"Package:", *lines))
  12182. + pkg->name = parseGenericFieldType((char *)"Package", *lines);
  12183. + else if(isGenericFieldType((char *)"Architecture:", *lines))
  12184. + pkg->architecture = parseGenericFieldType((char *)"Architecture", *lines);
  12185. + else if(isGenericFieldType((char *)"Filename:", *lines))
  12186. + pkg->filename = parseGenericFieldType((char *)"Filename", *lines);
  12187. + else if(isGenericFieldType((char *)"Section:", *lines))
  12188. + pkg->section = parseGenericFieldType((char *)"Section", *lines);
  12189. + else if(isGenericFieldType((char *)"MD5sum:", *lines))
  12190. + pkg->md5sum = parseGenericFieldType((char *)"MD5sum", *lines);
  12191. + /* The old ipkg wrote out status files with the wrong case for MD5sum,
  12192. + let's parse it either way */
  12193. + else if(isGenericFieldType((char *)"MD5Sum:", *lines))
  12194. + pkg->md5sum = parseGenericFieldType((char *)"MD5Sum", *lines);
  12195. + else if(isGenericFieldType((char *)"Size:", *lines))
  12196. + pkg->size = parseGenericFieldType((char *)"Size", *lines);
  12197. + else if(isGenericFieldType((char *)"Source:", *lines))
  12198. + pkg->source = parseGenericFieldType((char *)"Source", *lines);
  12199. + else if(isGenericFieldType((char *)"Installed-Size:", *lines))
  12200. + pkg->installed_size = parseGenericFieldType((char *)"Installed-Size", *lines);
  12201. + else if(isGenericFieldType((char *)"Installed-Time:", *lines)) {
  12202. + char *time_str = parseGenericFieldType((char *)"Installed-Time", *lines);
  12203. + pkg->installed_time = strtoul(time_str, NULL, 0);
  12204. + } else if(isGenericFieldType((char *)"Priority:", *lines))
  12205. + pkg->priority = parseGenericFieldType((char *)"Priority", *lines);
  12206. + else if(isGenericFieldType((char *)"Essential:", *lines)) {
  12207. + char *essential_value;
  12208. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12209. + if (strcmp(essential_value, "yes") == 0) {
  12210. + pkg->essential = 1;
  12211. + }
  12212. + free(essential_value);
  12213. + }
  12214. + else if(isGenericFieldType((char *)"Status", *lines))
  12215. + parseStatus(pkg, *lines);
  12216. + else if(isGenericFieldType((char *)"Version", *lines))
  12217. + parseVersion(pkg, *lines);
  12218. + else if(isGenericFieldType((char *)"Maintainer", *lines))
  12219. + pkg->maintainer = parseGenericFieldType((char *)"Maintainer", *lines);
  12220. + else if(isGenericFieldType((char *)"Conffiles", *lines)){
  12221. + parseConffiles(pkg, *lines);
  12222. + reading_conffiles = 1;
  12223. + }
  12224. + else if(isGenericFieldType((char *)"Description", *lines)) {
  12225. + pkg->description = parseGenericFieldType((char *)"Description", *lines);
  12226. + reading_conffiles = 0;
  12227. + reading_description = 1;
  12228. + }
  12229. +
  12230. + else if(isGenericFieldType((char *)"Provides", *lines)){
  12231. +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
  12232. + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
  12233. + if ( alterProvidesLine(*lines,provide) ){
  12234. + return EINVAL;
  12235. + }
  12236. + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
  12237. +/* Let's try to hack a bit here.
  12238. + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
  12239. + in alot of other places. We will remove it before writing down the status database */
  12240. + pkg_false_provides=0;
  12241. + free(provide);
  12242. + }
  12243. +
  12244. + else if(isGenericFieldType((char *)"Depends", *lines))
  12245. + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
  12246. + else if(isGenericFieldType((char *)"Pre-Depends", *lines))
  12247. + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
  12248. + else if(isGenericFieldType((char *)"Recommends", *lines))
  12249. + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
  12250. + else if(isGenericFieldType((char *)"Suggests", *lines))
  12251. + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
  12252. + /* Abhaya: support for conflicts */
  12253. + else if(isGenericFieldType((char *)"Conflicts", *lines))
  12254. + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
  12255. + else if(isGenericFieldType((char *)"Replaces", *lines))
  12256. + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
  12257. + else if(line_is_blank(*lines)) {
  12258. + lines++;
  12259. + break;
  12260. + }
  12261. + else if(**lines == ' '){
  12262. + if(reading_description) {
  12263. + /* we already know it's not blank, so the rest of description */
  12264. + pkg->description = realloc(pkg->description,
  12265. + strlen(pkg->description)
  12266. + + 1 + strlen(*lines) + 1);
  12267. + strcat(pkg->description, "\n");
  12268. + strcat(pkg->description, (*lines));
  12269. + }
  12270. + else if(reading_conffiles)
  12271. + parseConffiles(pkg, *lines);
  12272. + }
  12273. + }
  12274. + *raw = lines;
  12275. +/* If the ipk has not a Provides line, we insert our false line */
  12276. + if ( pkg_false_provides==1)
  12277. + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
  12278. +
  12279. + if (pkg->name) {
  12280. + return 0;
  12281. + } else {
  12282. + return EINVAL;
  12283. + }
  12284. +}
  12285. +
  12286. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
  12287. +{
  12288. + char ** lines;
  12289. +
  12290. + for (lines = *raw; *lines; lines++) {
  12291. + if(isGenericFieldType((char *)"Essential:", *lines)) {
  12292. + char *essential_value;
  12293. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12294. + if (strcmp(essential_value, "yes") == 0) {
  12295. + pkg->essential = 1;
  12296. + }
  12297. + free(essential_value);
  12298. + }
  12299. + }
  12300. + *raw = lines;
  12301. +
  12302. + return 0;
  12303. +}
  12304. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_parse.h busybox-1.17.0/archival/libipkg/pkg_parse.h
  12305. --- busybox-1.17.0.orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
  12306. +++ busybox-1.17.0/archival/libipkg/pkg_parse.h 2010-07-15 21:53:18.585858787 +0200
  12307. @@ -0,0 +1,31 @@
  12308. +/* pkg_parse.h - the itsy package management system
  12309. +
  12310. + Steven M. Ayer
  12311. +
  12312. + Copyright (C) 2002 Compaq Computer Corporation
  12313. +
  12314. + This program is free software; you can redistribute it and/or
  12315. + modify it under the terms of the GNU General Public License as
  12316. + published by the Free Software Foundation; either version 2, or (at
  12317. + your option) any later version.
  12318. +
  12319. + This program is distributed in the hope that it will be useful, but
  12320. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12321. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12322. + General Public License for more details.
  12323. +*/
  12324. +
  12325. +#ifndef PKG_PARSE_H
  12326. +#define PKG_PARSE_H
  12327. +
  12328. +int isGenericFieldType(char * type, char * line);
  12329. +char * parseGenericFieldType(char * type, char * raw);
  12330. +void parseStatus(pkg_t *pkg, char * raw);
  12331. +int parseVersion(pkg_t *pkg, char *raw);
  12332. +char ** parseDependsString(char * raw, int * depends_count);
  12333. +int parseVersion(pkg_t *pkg, char *raw);
  12334. +void parseConffiles(pkg_t * pkg, char * raw);
  12335. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
  12336. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
  12337. +
  12338. +#endif
  12339. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_src.c busybox-1.17.0/archival/libipkg/pkg_src.c
  12340. --- busybox-1.17.0.orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
  12341. +++ busybox-1.17.0/archival/libipkg/pkg_src.c 2010-07-15 21:53:18.645858878 +0200
  12342. @@ -0,0 +1,43 @@
  12343. +/* pkg_src.c - the itsy package management system
  12344. +
  12345. + Carl D. Worth
  12346. +
  12347. + Copyright (C) 2001 University of Southern California
  12348. +
  12349. + This program is free software; you can redistribute it and/or
  12350. + modify it under the terms of the GNU General Public License as
  12351. + published by the Free Software Foundation; either version 2, or (at
  12352. + your option) any later version.
  12353. +
  12354. + This program is distributed in the hope that it will be useful, but
  12355. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12356. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12357. + General Public License for more details.
  12358. +*/
  12359. +
  12360. +#include "ipkg.h"
  12361. +
  12362. +#include "pkg_src.h"
  12363. +#include "str_util.h"
  12364. +
  12365. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
  12366. +{
  12367. + src->gzip = gzip;
  12368. + src->name = str_dup_safe (name);
  12369. + src->value = str_dup_safe (base_url);
  12370. + if (extra_data)
  12371. + src->extra_data = str_dup_safe (extra_data);
  12372. + else
  12373. + src->extra_data = NULL;
  12374. + return 0;
  12375. +}
  12376. +
  12377. +void pkg_src_deinit(pkg_src_t *src)
  12378. +{
  12379. + free (src->name);
  12380. + free (src->value);
  12381. + if (src->extra_data)
  12382. + free (src->extra_data);
  12383. +}
  12384. +
  12385. +
  12386. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_src.h busybox-1.17.0/archival/libipkg/pkg_src.h
  12387. --- busybox-1.17.0.orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
  12388. +++ busybox-1.17.0/archival/libipkg/pkg_src.h 2010-07-15 21:53:18.705858062 +0200
  12389. @@ -0,0 +1,34 @@
  12390. +/* pkg_src.h - the itsy package management system
  12391. +
  12392. + Carl D. Worth
  12393. +
  12394. + Copyright (C) 2001 University of Southern California
  12395. +
  12396. + This program is free software; you can redistribute it and/or
  12397. + modify it under the terms of the GNU General Public License as
  12398. + published by the Free Software Foundation; either version 2, or (at
  12399. + your option) any later version.
  12400. +
  12401. + This program is distributed in the hope that it will be useful, but
  12402. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12403. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12404. + General Public License for more details.
  12405. +*/
  12406. +
  12407. +#ifndef PKG_SRC_H
  12408. +#define PKG_SRC_H
  12409. +
  12410. +#include "nv_pair.h"
  12411. +
  12412. +typedef struct
  12413. +{
  12414. + char *name;
  12415. + char *value;
  12416. + char *extra_data;
  12417. + int gzip;
  12418. +} pkg_src_t;
  12419. +
  12420. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
  12421. +void pkg_src_deinit(pkg_src_t *src);
  12422. +
  12423. +#endif
  12424. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_src_list.c busybox-1.17.0/archival/libipkg/pkg_src_list.c
  12425. --- busybox-1.17.0.orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
  12426. +++ busybox-1.17.0/archival/libipkg/pkg_src_list.c 2010-07-15 21:53:18.765858954 +0200
  12427. @@ -0,0 +1,75 @@
  12428. +/* pkg_src_list.c - the itsy package management system
  12429. +
  12430. + Carl D. Worth
  12431. +
  12432. + Copyright (C) 2001 University of Southern California
  12433. +
  12434. + This program is free software; you can redistribute it and/or
  12435. + modify it under the terms of the GNU General Public License as
  12436. + published by the Free Software Foundation; either version 2, or (at
  12437. + your option) any later version.
  12438. +
  12439. + This program is distributed in the hope that it will be useful, but
  12440. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12441. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12442. + General Public License for more details.
  12443. +*/
  12444. +
  12445. +#include "ipkg.h"
  12446. +
  12447. +#include "pkg_src_list.h"
  12448. +#include "void_list.h"
  12449. +
  12450. +int pkg_src_list_init(pkg_src_list_t *list)
  12451. +{
  12452. + return void_list_init((void_list_t *) list);
  12453. +}
  12454. +
  12455. +void pkg_src_list_deinit(pkg_src_list_t *list)
  12456. +{
  12457. + pkg_src_list_elt_t *iter;
  12458. + pkg_src_t *pkg_src;
  12459. +
  12460. + for (iter = list->head; iter; iter = iter->next) {
  12461. + pkg_src = iter->data;
  12462. + pkg_src_deinit(pkg_src);
  12463. +
  12464. + /* malloced in pkg_src_list_append */
  12465. + free(pkg_src);
  12466. + iter->data = NULL;
  12467. + }
  12468. + void_list_deinit((void_list_t *) list);
  12469. +}
  12470. +
  12471. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
  12472. + const char *name, const char *base_url, const char *extra_data,
  12473. + int gzip)
  12474. +{
  12475. + int err;
  12476. +
  12477. + /* freed in pkg_src_list_deinit */
  12478. + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
  12479. +
  12480. + if (pkg_src == NULL) {
  12481. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12482. + return NULL;
  12483. + }
  12484. + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
  12485. +
  12486. + err = void_list_append((void_list_t *) list, pkg_src);
  12487. + if (err) {
  12488. + return NULL;
  12489. + }
  12490. +
  12491. + return pkg_src;
  12492. +}
  12493. +
  12494. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
  12495. +{
  12496. + return void_list_push((void_list_t *) list, data);
  12497. +}
  12498. +
  12499. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
  12500. +{
  12501. + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
  12502. +}
  12503. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_src_list.h busybox-1.17.0/archival/libipkg/pkg_src_list.h
  12504. --- busybox-1.17.0.orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
  12505. +++ busybox-1.17.0/archival/libipkg/pkg_src_list.h 2010-07-15 21:53:18.825858971 +0200
  12506. @@ -0,0 +1,57 @@
  12507. +/* pkg_src_list.h - the itsy package management system
  12508. +
  12509. + Carl D. Worth
  12510. +
  12511. + Copyright (C) 2001 University of Southern California
  12512. +
  12513. + This program is free software; you can redistribute it and/or
  12514. + modify it under the terms of the GNU General Public License as
  12515. + published by the Free Software Foundation; either version 2, or (at
  12516. + your option) any later version.
  12517. +
  12518. + This program is distributed in the hope that it will be useful, but
  12519. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12520. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12521. + General Public License for more details.
  12522. +*/
  12523. +
  12524. +#ifndef PKG_SRC_LIST_H
  12525. +#define PKG_SRC_LIST_H
  12526. +
  12527. +#include "pkg_src.h"
  12528. +
  12529. +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
  12530. +struct pkg_src_list_elt
  12531. +{
  12532. + pkg_src_list_elt_t *next;
  12533. + pkg_src_t *data;
  12534. +};
  12535. +
  12536. +typedef struct pkg_src_list pkg_src_list_t;
  12537. +struct pkg_src_list
  12538. +{
  12539. + pkg_src_list_elt_t pre_head;
  12540. + pkg_src_list_elt_t *head;
  12541. + pkg_src_list_elt_t *tail;
  12542. +};
  12543. +
  12544. +static inline int pkg_src_list_empty(pkg_src_list_t *list)
  12545. +{
  12546. + if (list->head == NULL)
  12547. + return 1;
  12548. + else
  12549. + return 0;
  12550. +}
  12551. +
  12552. +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
  12553. +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
  12554. +
  12555. +int pkg_src_list_init(pkg_src_list_t *list);
  12556. +void pkg_src_list_deinit(pkg_src_list_t *list);
  12557. +
  12558. +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);
  12559. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
  12560. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
  12561. +
  12562. +#endif
  12563. +
  12564. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_vec.c busybox-1.17.0/archival/libipkg/pkg_vec.c
  12565. --- busybox-1.17.0.orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
  12566. +++ busybox-1.17.0/archival/libipkg/pkg_vec.c 2010-07-15 21:53:18.875858745 +0200
  12567. @@ -0,0 +1,231 @@
  12568. +/* pkg_vec.c - the itsy package management system
  12569. +
  12570. + Steven M. Ayer
  12571. +
  12572. + Copyright (C) 2002 Compaq Computer Corporation
  12573. +
  12574. + This program is free software; you can redistribute it and/or
  12575. + modify it under the terms of the GNU General Public License as
  12576. + published by the Free Software Foundation; either version 2, or (at
  12577. + your option) any later version.
  12578. +
  12579. + This program is distributed in the hope that it will be useful, but
  12580. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12581. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12582. + General Public License for more details.
  12583. +*/
  12584. +
  12585. +#include <stdlib.h>
  12586. +#include <fnmatch.h>
  12587. +#include "libbb.h"
  12588. +#include "xregex.h"
  12589. +#include "ipkg.h"
  12590. +#include "pkg.h"
  12591. +
  12592. +pkg_vec_t * pkg_vec_alloc(void)
  12593. +{
  12594. + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
  12595. + if (!vec) {
  12596. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12597. + return NULL;
  12598. + }
  12599. + vec->pkgs = NULL;
  12600. + vec->len = 0;
  12601. +
  12602. + return vec;
  12603. +}
  12604. +
  12605. +void pkg_vec_free(pkg_vec_t *vec)
  12606. +{
  12607. + free(vec->pkgs);
  12608. + free(vec);
  12609. +}
  12610. +
  12611. +/*
  12612. + * assumption: all names in a vector are identical
  12613. + * assumption: all version strings are trimmed,
  12614. + * so identical versions have identical version strings,
  12615. + * implying identical packages; let's marry these
  12616. + */
  12617. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  12618. +{
  12619. + int i;
  12620. + int found = 0;
  12621. +
  12622. + /* look for a duplicate pkg by name, version, and architecture */
  12623. + for (i = 0; i < vec->len; i++){
  12624. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
  12625. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
  12626. + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
  12627. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12628. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12629. + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
  12630. + found = 1;
  12631. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
  12632. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12633. + break;
  12634. + }
  12635. + }
  12636. +
  12637. + /* we didn't find one, add it */
  12638. + if (!found){
  12639. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
  12640. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12641. +
  12642. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12643. + vec->pkgs[vec->len] = pkg;
  12644. + vec->len++;
  12645. + return pkg;
  12646. + }
  12647. + /* update the one that we have */
  12648. + else {
  12649. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
  12650. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12651. + if (set_status) {
  12652. + /* this is from the status file, so need to merge with existing database */
  12653. + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
  12654. + pkg_merge(vec->pkgs[i], pkg, set_status);
  12655. + /* XXX: CLEANUP: It's not so polite to free something here
  12656. + that was passed in from above. */
  12657. + pkg_deinit(pkg);
  12658. + free(pkg);
  12659. + } else {
  12660. + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
  12661. + /* just overwrite the old one */
  12662. + pkg_deinit(vec->pkgs[i]);
  12663. + free(vec->pkgs[i]);
  12664. + vec->pkgs[i] = pkg;
  12665. + }
  12666. + return vec->pkgs[i];
  12667. + }
  12668. +}
  12669. +
  12670. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
  12671. +{
  12672. + int i;
  12673. + int found = 0;
  12674. +
  12675. + /* look for a duplicate pkg by name, version, and architecture */
  12676. + for (i = 0; i < vec->len; i++)
  12677. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12678. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12679. + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
  12680. + found = 1;
  12681. + break;
  12682. + }
  12683. +
  12684. + /* we didn't find one, add it */
  12685. + if(!found){
  12686. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12687. + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
  12688. + vec->len++;
  12689. + }
  12690. +}
  12691. +
  12692. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
  12693. +{
  12694. + int i;
  12695. + for (i = 0; i < vec->len; i++)
  12696. + if (vec->pkgs[i] == apkg)
  12697. + return 1;
  12698. + return 0;
  12699. +}
  12700. +
  12701. +typedef int (*compare_fcn_t)(const void *, const void *);
  12702. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
  12703. +{
  12704. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12705. +}
  12706. +
  12707. +int pkg_vec_clear_marks(pkg_vec_t *vec)
  12708. +{
  12709. + int npkgs = vec->len;
  12710. + int i;
  12711. + for (i = 0; i < npkgs; i++) {
  12712. + pkg_t *pkg = vec->pkgs[i];
  12713. + pkg->state_flag &= ~SF_MARKED;
  12714. + }
  12715. + return 0;
  12716. +}
  12717. +
  12718. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
  12719. +{
  12720. + int matching_count = 0;
  12721. + pkg_t **pkgs = vec->pkgs;
  12722. + int npkgs = vec->len;
  12723. + int i;
  12724. + for (i = 0; i < npkgs; i++) {
  12725. + pkg_t *pkg = pkgs[i];
  12726. + if (fnmatch(pattern, pkg->name, 0)==0) {
  12727. + pkg->state_flag |= SF_MARKED;
  12728. + matching_count++;
  12729. + }
  12730. + }
  12731. + return matching_count;
  12732. +}
  12733. +
  12734. +
  12735. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
  12736. +{
  12737. + abstract_pkg_vec_t * vec ;
  12738. + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
  12739. + if (!vec) {
  12740. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12741. + return NULL;
  12742. + }
  12743. + vec->pkgs = NULL;
  12744. + vec->len = 0;
  12745. +
  12746. + return vec;
  12747. +}
  12748. +
  12749. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
  12750. +{
  12751. + free(vec->pkgs);
  12752. + free(vec);
  12753. +}
  12754. +
  12755. +/*
  12756. + * assumption: all names in a vector are unique
  12757. + */
  12758. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
  12759. +{
  12760. + int i;
  12761. +
  12762. + /* look for a duplicate pkg by name */
  12763. + for(i = 0; i < vec->len; i++)
  12764. + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12765. + break;
  12766. +
  12767. + /* we didn't find one, add it */
  12768. + if(i == vec->len){
  12769. + vec->pkgs =
  12770. + (abstract_pkg_t **)
  12771. + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
  12772. + vec->pkgs[vec->len] = pkg;
  12773. + vec->len++;
  12774. + }
  12775. +}
  12776. +
  12777. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
  12778. +{
  12779. + if (vec->len > i)
  12780. + return vec->pkgs[i];
  12781. + else
  12782. + return NULL;
  12783. +}
  12784. +
  12785. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
  12786. +{
  12787. + int i;
  12788. + for (i = 0; i < vec->len; i++)
  12789. + if (vec->pkgs[i] == apkg)
  12790. + return 1;
  12791. + return 0;
  12792. +}
  12793. +
  12794. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
  12795. +{
  12796. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12797. +}
  12798. +
  12799. diff -Nur busybox-1.17.0.orig/archival/libipkg/pkg_vec.h busybox-1.17.0/archival/libipkg/pkg_vec.h
  12800. --- busybox-1.17.0.orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
  12801. +++ busybox-1.17.0/archival/libipkg/pkg_vec.h 2010-07-15 21:53:18.935858471 +0200
  12802. @@ -0,0 +1,62 @@
  12803. +/* pkg_vec.h - the itsy package management system
  12804. +
  12805. + Steven M. Ayer
  12806. +
  12807. + Copyright (C) 2002 Compaq Computer Corporation
  12808. +
  12809. + This program is free software; you can redistribute it and/or
  12810. + modify it under the terms of the GNU General Public License as
  12811. + published by the Free Software Foundation; either version 2, or (at
  12812. + your option) any later version.
  12813. +
  12814. + This program is distributed in the hope that it will be useful, but
  12815. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12816. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12817. + General Public License for more details.
  12818. +*/
  12819. +
  12820. +#ifndef PKG_VEC_H
  12821. +#define PKG_VEC_H
  12822. +
  12823. +typedef struct pkg pkg_t;
  12824. +typedef struct abstract_pkg abstract_pkg_t;
  12825. +
  12826. +struct pkg_vec
  12827. +{
  12828. + pkg_t **pkgs;
  12829. + int len;
  12830. +};
  12831. +typedef struct pkg_vec pkg_vec_t;
  12832. +
  12833. +struct abstract_pkg_vec
  12834. +{
  12835. + abstract_pkg_t **pkgs;
  12836. + int len;
  12837. +};
  12838. +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
  12839. +
  12840. +
  12841. +pkg_vec_t * pkg_vec_alloc(void);
  12842. +void pkg_vec_free(pkg_vec_t *vec);
  12843. +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
  12844. +
  12845. +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
  12846. +/* pkg_vec_insert_merge: might munge pkg.
  12847. +* returns the pkg that is in the pkg graph */
  12848. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
  12849. +/* this one never munges pkg */
  12850. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
  12851. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
  12852. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
  12853. +
  12854. +int pkg_vec_clear_marks(pkg_vec_t *vec);
  12855. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
  12856. +
  12857. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
  12858. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
  12859. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
  12860. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
  12861. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
  12862. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
  12863. +#endif
  12864. +
  12865. diff -Nur busybox-1.17.0.orig/archival/libipkg/sprintf_alloc.h busybox-1.17.0/archival/libipkg/sprintf_alloc.h
  12866. --- busybox-1.17.0.orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
  12867. +++ busybox-1.17.0/archival/libipkg/sprintf_alloc.h 2010-07-15 21:53:18.995858549 +0200
  12868. @@ -0,0 +1,25 @@
  12869. +/* sprintf_alloca.c -- like sprintf with memory allocation
  12870. +
  12871. + Carl D. Worth
  12872. +
  12873. + Copyright (C) 2001 University of Southern California
  12874. +
  12875. + This program is free software; you can redistribute it and/or modify
  12876. + it under the terms of the GNU General Public License as published by
  12877. + the Free Software Foundation; either version 2, or (at your option)
  12878. + any later version.
  12879. +
  12880. + This program is distributed in the hope that it will be useful,
  12881. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  12882. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12883. + GNU General Public License for more details.
  12884. +*/
  12885. +
  12886. +#ifndef SPRINTF_ALLOC_H
  12887. +#define SPRINTF_ALLOC_H
  12888. +
  12889. +#include "libbb.h"
  12890. +
  12891. +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
  12892. +
  12893. +#endif
  12894. diff -Nur busybox-1.17.0.orig/archival/libipkg/str_list.c busybox-1.17.0/archival/libipkg/str_list.c
  12895. --- busybox-1.17.0.orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
  12896. +++ busybox-1.17.0/archival/libipkg/str_list.c 2010-07-15 21:53:19.055858313 +0200
  12897. @@ -0,0 +1,76 @@
  12898. +/* str_list.c - the itsy package management system
  12899. +
  12900. + Carl D. Worth
  12901. +
  12902. + Copyright (C) 2001 University of Southern California
  12903. +
  12904. + This program is free software; you can redistribute it and/or
  12905. + modify it under the terms of the GNU General Public License as
  12906. + published by the Free Software Foundation; either version 2, or (at
  12907. + your option) any later version.
  12908. +
  12909. + This program is distributed in the hope that it will be useful, but
  12910. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12911. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12912. + General Public License for more details.
  12913. +*/
  12914. +
  12915. +#include "ipkg.h"
  12916. +
  12917. +#include "str_list.h"
  12918. +
  12919. +int str_list_elt_init(str_list_elt_t *elt, char *data)
  12920. +{
  12921. + return void_list_elt_init((void_list_elt_t *) elt, data);
  12922. +}
  12923. +
  12924. +void str_list_elt_deinit(str_list_elt_t *elt)
  12925. +{
  12926. + void_list_elt_deinit((void_list_elt_t *) elt);
  12927. +}
  12928. +
  12929. +str_list_t *str_list_alloc(void)
  12930. +{
  12931. + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
  12932. + if (list)
  12933. + str_list_init(list);
  12934. + return list;
  12935. +}
  12936. +
  12937. +int str_list_init(str_list_t *list)
  12938. +{
  12939. + return void_list_init((void_list_t *) list);
  12940. +}
  12941. +
  12942. +void str_list_deinit(str_list_t *list)
  12943. +{
  12944. + void_list_deinit((void_list_t *) list);
  12945. +}
  12946. +
  12947. +int str_list_append(str_list_t *list, char *data)
  12948. +{
  12949. + return void_list_append((void_list_t *) list, data);
  12950. +}
  12951. +
  12952. +int str_list_push(str_list_t *list, char *data)
  12953. +{
  12954. + return void_list_push((void_list_t *) list, data);
  12955. +}
  12956. +
  12957. +str_list_elt_t *str_list_pop(str_list_t *list)
  12958. +{
  12959. + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
  12960. +}
  12961. +
  12962. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
  12963. +{
  12964. + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
  12965. + (void_list_elt_t **) iter);
  12966. +}
  12967. +
  12968. +char *str_list_remove_elt(str_list_t *list, const char *target_str)
  12969. +{
  12970. + return (char *)void_list_remove_elt((void_list_t *) list,
  12971. + (void *)target_str,
  12972. + (void_list_cmp_t)strcmp);
  12973. +}
  12974. diff -Nur busybox-1.17.0.orig/archival/libipkg/str_list.h busybox-1.17.0/archival/libipkg/str_list.h
  12975. --- busybox-1.17.0.orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
  12976. +++ busybox-1.17.0/archival/libipkg/str_list.h 2010-07-15 21:53:19.115858933 +0200
  12977. @@ -0,0 +1,51 @@
  12978. +/* str_list.h - the itsy package management system
  12979. +
  12980. + Carl D. Worth
  12981. +
  12982. + Copyright (C) 2001 University of Southern California
  12983. +
  12984. + This program is free software; you can redistribute it and/or
  12985. + modify it under the terms of the GNU General Public License as
  12986. + published by the Free Software Foundation; either version 2, or (at
  12987. + your option) any later version.
  12988. +
  12989. + This program is distributed in the hope that it will be useful, but
  12990. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12991. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12992. + General Public License for more details.
  12993. +*/
  12994. +
  12995. +#ifndef STR_LIST_H
  12996. +#define STR_LIST_H
  12997. +
  12998. +#include "void_list.h"
  12999. +
  13000. +typedef struct str_list_elt str_list_elt_t;
  13001. +struct str_list_elt
  13002. +{
  13003. + str_list_elt_t *next;
  13004. + char *data;
  13005. +};
  13006. +
  13007. +typedef struct xstr_list str_list_t;
  13008. +struct xstr_list
  13009. +{
  13010. + str_list_elt_t pre_head;
  13011. + str_list_elt_t *head;
  13012. + str_list_elt_t *tail;
  13013. +};
  13014. +
  13015. +int str_list_elt_init(str_list_elt_t *elt, char *data);
  13016. +void str_list_elt_deinit(str_list_elt_t *elt);
  13017. +
  13018. +str_list_t *str_list_alloc(void);
  13019. +int str_list_init(str_list_t *list);
  13020. +void str_list_deinit(str_list_t *list);
  13021. +
  13022. +int str_list_append(str_list_t *list, char *data);
  13023. +int str_list_push(str_list_t *list, char *data);
  13024. +str_list_elt_t *str_list_pop(str_list_t *list);
  13025. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
  13026. +char *str_list_remove_elt(str_list_t *list, const char *target_str);
  13027. +
  13028. +#endif
  13029. diff -Nur busybox-1.17.0.orig/archival/libipkg/str_util.c busybox-1.17.0/archival/libipkg/str_util.c
  13030. --- busybox-1.17.0.orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
  13031. +++ busybox-1.17.0/archival/libipkg/str_util.c 2010-07-15 21:53:19.165858466 +0200
  13032. @@ -0,0 +1,69 @@
  13033. +/* str_utils.c - the itsy package management system
  13034. +
  13035. + Carl D. Worth
  13036. +
  13037. + Copyright (C) 2001 University of Southern California
  13038. +
  13039. + This program is free software; you can redistribute it and/or
  13040. + modify it under the terms of the GNU General Public License as
  13041. + published by the Free Software Foundation; either version 2, or (at
  13042. + your option) any later version.
  13043. +
  13044. + This program is distributed in the hope that it will be useful, but
  13045. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13046. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13047. + General Public License for more details.
  13048. +*/
  13049. +
  13050. +#include "ipkg.h"
  13051. +
  13052. +int str_starts_with(const char *str, const char *prefix);
  13053. +int str_ends_with(const char *str, const char *suffix);
  13054. +int str_chomp(char *str);
  13055. +int str_toupper(char *str);
  13056. +char *str_dup_safe(const char *str);
  13057. +
  13058. +int str_starts_with(const char *str, const char *prefix)
  13059. +{
  13060. + return (strncmp(str, prefix, strlen(prefix)) == 0);
  13061. +}
  13062. +
  13063. +int str_ends_with(const char *str, const char *suffix)
  13064. +{
  13065. + int suffix_len;
  13066. + int str_len;
  13067. +
  13068. + str_len = strlen(str);
  13069. + suffix_len = strlen(suffix);
  13070. +
  13071. + if (str_len < suffix_len) {
  13072. + return 0;
  13073. + }
  13074. +
  13075. + return (strcmp(str + str_len - suffix_len, suffix) == 0);
  13076. +}
  13077. +
  13078. +int str_chomp(char *str)
  13079. +{
  13080. + if (str[strlen(str) - 1] == '\n') {
  13081. + str[strlen(str) - 1] = '\0';
  13082. + return 1;
  13083. + }
  13084. + return 0;
  13085. +}
  13086. +
  13087. +int str_toupper(char *str)
  13088. +{
  13089. + while (*str) {
  13090. + *str = toupper(*str);
  13091. + str++;
  13092. + }
  13093. +
  13094. + return 0;
  13095. +}
  13096. +
  13097. +char *str_dup_safe(const char *str)
  13098. +{
  13099. + return str ? strdup(str) : NULL;
  13100. +}
  13101. +
  13102. diff -Nur busybox-1.17.0.orig/archival/libipkg/str_util.h busybox-1.17.0/archival/libipkg/str_util.h
  13103. --- busybox-1.17.0.orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
  13104. +++ busybox-1.17.0/archival/libipkg/str_util.h 2010-07-15 21:53:19.215858689 +0200
  13105. @@ -0,0 +1,27 @@
  13106. +/* str_utils.h - the itsy package management system
  13107. +
  13108. + Carl D. Worth
  13109. +
  13110. + Copyright (C) 2001 University of Southern California
  13111. +
  13112. + This program is free software; you can redistribute it and/or
  13113. + modify it under the terms of the GNU General Public License as
  13114. + published by the Free Software Foundation; either version 2, or (at
  13115. + your option) any later version.
  13116. +
  13117. + This program is distributed in the hope that it will be useful, but
  13118. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13119. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13120. + General Public License for more details.
  13121. +*/
  13122. +
  13123. +#ifndef STR_UTILS_H
  13124. +#define STR_UTILS_H
  13125. +
  13126. +int str_starts_with(const char *str, const char *prefix);
  13127. +int str_ends_with(const char *str, const char *suffix);
  13128. +int str_chomp(char *str);
  13129. +int str_toupper(char *str);
  13130. +char *str_dup_safe(const char *str);
  13131. +
  13132. +#endif
  13133. diff -Nur busybox-1.17.0.orig/archival/libipkg/user.c busybox-1.17.0/archival/libipkg/user.c
  13134. --- busybox-1.17.0.orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
  13135. +++ busybox-1.17.0/archival/libipkg/user.c 2010-07-15 21:53:19.275857337 +0200
  13136. @@ -0,0 +1,49 @@
  13137. +/* user.c - the itsy package management system
  13138. +
  13139. + Jamey Hicks
  13140. +
  13141. + Copyright (C) 2002 Hewlett Packard Company
  13142. + Copyright (C) 2001 University of Southern California
  13143. +
  13144. + This program is free software; you can redistribute it and/or
  13145. + modify it under the terms of the GNU General Public License as
  13146. + published by the Free Software Foundation; either version 2, or (at
  13147. + your option) any later version.
  13148. +
  13149. + This program is distributed in the hope that it will be useful, but
  13150. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13151. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13152. + General Public License for more details.
  13153. +*/
  13154. +
  13155. +#include <stdio.h>
  13156. +#include <stdarg.h>
  13157. +#include "libbb.h"
  13158. +#include "file_util.h"
  13159. +#include "str_util.h"
  13160. +#include "libipkg.h"
  13161. +
  13162. +char *get_user_response(const char *format, ...);
  13163. +static char *question = NULL;
  13164. +static int question_len = 255;
  13165. +
  13166. +char *get_user_response(const char *format, ...)
  13167. +{
  13168. + int len = question_len;
  13169. + va_list ap;
  13170. + char *response;
  13171. + va_start(ap, format);
  13172. +
  13173. + do {
  13174. + if (question == NULL || len > question_len) {
  13175. + question = realloc(question, len + 1);
  13176. + question_len = len;
  13177. + }
  13178. + len = vsnprintf(question,question_len,format,ap);
  13179. + } while (len > question_len);
  13180. + response = strdup(ipkg_cb_response(question));
  13181. + str_chomp(response);
  13182. + str_tolower(response);
  13183. +
  13184. + return response;
  13185. +}
  13186. diff -Nur busybox-1.17.0.orig/archival/libipkg/user.h busybox-1.17.0/archival/libipkg/user.h
  13187. --- busybox-1.17.0.orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
  13188. +++ busybox-1.17.0/archival/libipkg/user.h 2010-07-15 21:53:19.355858716 +0200
  13189. @@ -0,0 +1,23 @@
  13190. +/* user.c - the itsy package management system
  13191. +
  13192. + Jamey Hicks
  13193. +
  13194. + Copyright (C) 2002 Hewlett Packard Company
  13195. + Copyright (C) 2001 University of Southern California
  13196. +
  13197. + This program is free software; you can redistribute it and/or
  13198. + modify it under the terms of the GNU General Public License as
  13199. + published by the Free Software Foundation; either version 2, or (at
  13200. + your option) any later version.
  13201. +
  13202. + This program is distributed in the hope that it will be useful, but
  13203. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13204. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13205. + General Public License for more details.
  13206. +*/
  13207. +
  13208. +#include <stdio.h>
  13209. +#include <stdarg.h>
  13210. +
  13211. +char *get_user_response(const char *format, ...);
  13212. +
  13213. diff -Nur busybox-1.17.0.orig/archival/libipkg/void_list.c busybox-1.17.0/archival/libipkg/void_list.c
  13214. --- busybox-1.17.0.orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
  13215. +++ busybox-1.17.0/archival/libipkg/void_list.c 2010-07-15 21:53:19.405860568 +0200
  13216. @@ -0,0 +1,194 @@
  13217. +/* void_list.c - the itsy package management system
  13218. +
  13219. + Carl D. Worth
  13220. +
  13221. + Copyright (C) 2001 University of Southern California
  13222. +
  13223. + This program is free software; you can redistribute it and/or
  13224. + modify it under the terms of the GNU General Public License as
  13225. + published by the Free Software Foundation; either version 2, or (at
  13226. + your option) any later version.
  13227. +
  13228. + This program is distributed in the hope that it will be useful, but
  13229. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13230. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13231. + General Public License for more details.
  13232. +*/
  13233. +
  13234. +#include "ipkg.h"
  13235. +#include <errno.h>
  13236. +
  13237. +#include "void_list.h"
  13238. +
  13239. +int void_list_elt_init(void_list_elt_t *elt, void *data)
  13240. +{
  13241. + elt->next = NULL;
  13242. + elt->data = data;
  13243. +
  13244. + return 0;
  13245. +}
  13246. +
  13247. +void void_list_elt_deinit(void_list_elt_t *elt)
  13248. +{
  13249. + void_list_elt_init(elt, NULL);
  13250. +}
  13251. +
  13252. +int void_list_init(void_list_t *list)
  13253. +{
  13254. + void_list_elt_init(&list->pre_head, NULL);
  13255. + list->head = NULL;
  13256. + list->pre_head.next = list->head;
  13257. + list->tail = NULL;
  13258. +
  13259. + return 0;
  13260. +}
  13261. +
  13262. +void void_list_deinit(void_list_t *list)
  13263. +{
  13264. + void_list_elt_t *elt;
  13265. +
  13266. + while (list->head) {
  13267. + elt = void_list_pop(list);
  13268. + void_list_elt_deinit(elt);
  13269. + /* malloced in void_list_append */
  13270. + free(elt);
  13271. + }
  13272. +}
  13273. +
  13274. +int void_list_append(void_list_t *list, void *data)
  13275. +{
  13276. + void_list_elt_t *elt;
  13277. +
  13278. + /* freed in void_list_deinit */
  13279. + elt = malloc(sizeof(void_list_elt_t));
  13280. + if (elt == NULL) {
  13281. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13282. + return ENOMEM;
  13283. + }
  13284. +
  13285. + void_list_elt_init(elt, data);
  13286. +
  13287. + if (list->tail) {
  13288. + list->tail->next = elt;
  13289. + list->tail = elt;
  13290. + } else {
  13291. + list->head = elt;
  13292. + list->pre_head.next = list->head;
  13293. + list->tail = elt;
  13294. + }
  13295. +
  13296. + return 0;
  13297. +}
  13298. +
  13299. +int void_list_push(void_list_t *list, void *data)
  13300. +{
  13301. + void_list_elt_t *elt;
  13302. +
  13303. + elt = malloc(sizeof(void_list_elt_t));
  13304. + if (elt == NULL) {
  13305. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13306. + return ENOMEM;
  13307. + }
  13308. +
  13309. + void_list_elt_init(elt, data);
  13310. +
  13311. + elt->next = list->head;
  13312. + list->head->next = elt;
  13313. + if (list->tail == NULL) {
  13314. + list->tail = list->head;
  13315. + }
  13316. +
  13317. + return 0;
  13318. +}
  13319. +
  13320. +void_list_elt_t *void_list_pop(void_list_t *list)
  13321. +{
  13322. + void_list_elt_t *elt;
  13323. +
  13324. + elt = list->head;
  13325. +
  13326. + if (list->head) {
  13327. + list->head = list->head->next;
  13328. + list->pre_head.next = list->head;
  13329. + if (list->head == NULL) {
  13330. + list->tail = NULL;
  13331. + }
  13332. + }
  13333. +
  13334. + return elt;
  13335. +}
  13336. +
  13337. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
  13338. +{
  13339. + void_list_elt_t *prior;
  13340. + void_list_elt_t *old_elt;
  13341. + void *old_data;
  13342. +
  13343. + old_elt = *iter;
  13344. + old_data = old_elt->data;
  13345. +
  13346. + if (old_elt == list->head) {
  13347. + prior = &list->pre_head;
  13348. + void_list_pop(list);
  13349. + } else {
  13350. + for (prior = list->head; prior; prior = prior->next) {
  13351. + if (prior->next == old_elt) {
  13352. + break;
  13353. + }
  13354. + }
  13355. + if (prior == NULL || prior->next != old_elt) {
  13356. + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
  13357. + return NULL;
  13358. + }
  13359. + prior->next = old_elt->next;
  13360. +
  13361. + if (old_elt == list->tail) {
  13362. + list->tail = prior;
  13363. + }
  13364. + }
  13365. +
  13366. + void_list_elt_deinit(old_elt);
  13367. + *iter = prior;
  13368. +
  13369. + return old_data;
  13370. +}
  13371. +
  13372. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13373. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
  13374. +{
  13375. + void_list_elt_t *prior;
  13376. + void_list_elt_t *old_elt = NULL;
  13377. + void *old_data = NULL;
  13378. +
  13379. + /* first element */
  13380. + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
  13381. + old_elt = list->head;
  13382. + old_data = list->head->data;
  13383. + void_list_pop(list);
  13384. + } else {
  13385. + int found = 0;
  13386. + for (prior = list->head; prior && prior->next; prior = prior->next) {
  13387. + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
  13388. + old_elt = prior->next;
  13389. + old_data = old_elt->data;
  13390. + found = 1;
  13391. + break;
  13392. + }
  13393. + }
  13394. + if (!found) {
  13395. + return NULL;
  13396. + }
  13397. + prior->next = old_elt->next;
  13398. +
  13399. + if (old_elt == list->tail) {
  13400. + list->tail = prior;
  13401. + }
  13402. + }
  13403. + if (old_elt)
  13404. + void_list_elt_deinit(old_elt);
  13405. +
  13406. + if (old_data)
  13407. + return old_data;
  13408. + else
  13409. + return NULL;
  13410. +}
  13411. diff -Nur busybox-1.17.0.orig/archival/libipkg/void_list.h busybox-1.17.0/archival/libipkg/void_list.h
  13412. --- busybox-1.17.0.orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
  13413. +++ busybox-1.17.0/archival/libipkg/void_list.h 2010-07-15 21:53:19.505858606 +0200
  13414. @@ -0,0 +1,59 @@
  13415. +/* void_list.h - the itsy package management system
  13416. +
  13417. + Carl D. Worth
  13418. +
  13419. + Copyright (C) 2001 University of Southern California
  13420. +
  13421. + This program is free software; you can redistribute it and/or
  13422. + modify it under the terms of the GNU General Public License as
  13423. + published by the Free Software Foundation; either version 2, or (at
  13424. + your option) any later version.
  13425. +
  13426. + This program is distributed in the hope that it will be useful, but
  13427. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13428. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13429. + General Public License for more details.
  13430. +*/
  13431. +
  13432. +#ifndef VOID_LIST_H
  13433. +#define VOID_LIST_H
  13434. +
  13435. +typedef struct void_list_elt void_list_elt_t;
  13436. +struct void_list_elt
  13437. +{
  13438. + void_list_elt_t *next;
  13439. + void *data;
  13440. +};
  13441. +
  13442. +typedef struct void_list void_list_t;
  13443. +struct void_list
  13444. +{
  13445. + void_list_elt_t pre_head;
  13446. + void_list_elt_t *head;
  13447. + void_list_elt_t *tail;
  13448. +};
  13449. +
  13450. +static inline int void_list_empty(void_list_t *list)
  13451. +{
  13452. + if (list->head == NULL)
  13453. + return 1;
  13454. + else
  13455. + return 0;
  13456. +}
  13457. +
  13458. +int void_list_elt_init(void_list_elt_t *elt, void *data);
  13459. +void void_list_elt_deinit(void_list_elt_t *elt);
  13460. +
  13461. +int void_list_init(void_list_t *list);
  13462. +void void_list_deinit(void_list_t *list);
  13463. +
  13464. +int void_list_append(void_list_t *list, void *data);
  13465. +int void_list_push(void_list_t *list, void *data);
  13466. +void_list_elt_t *void_list_pop(void_list_t *list);
  13467. +
  13468. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
  13469. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13470. +typedef int (*void_list_cmp_t)(const void *, const void *);
  13471. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
  13472. +
  13473. +#endif
  13474. diff -Nur busybox-1.17.0.orig/archival/libipkg/xsystem.c busybox-1.17.0/archival/libipkg/xsystem.c
  13475. --- busybox-1.17.0.orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
  13476. +++ busybox-1.17.0/archival/libipkg/xsystem.c 2010-07-15 21:53:19.555858540 +0200
  13477. @@ -0,0 +1,64 @@
  13478. +/* xsystem.c - system(3) with error messages
  13479. +
  13480. + Carl D. Worth
  13481. +
  13482. + Copyright (C) 2001 University of Southern California
  13483. +
  13484. + This program is free software; you can redistribute it and/or
  13485. + modify it under the terms of the GNU General Public License as
  13486. + published by the Free Software Foundation; either version 2, or (at
  13487. + your option) any later version.
  13488. +
  13489. + This program is distributed in the hope that it will be useful, but
  13490. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13491. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13492. + General Public License for more details.
  13493. +*/
  13494. +
  13495. +#include "ipkg.h"
  13496. +#include <sys/wait.h>
  13497. +
  13498. +#include "xsystem.h"
  13499. +
  13500. +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
  13501. + really need the /bin/sh invocation which takes resources and
  13502. + introduces security problems. I should switch all of this to a sort
  13503. + of execl() or execv() interface/implementation.
  13504. +*/
  13505. +
  13506. +/* Like system(3), but with error messages printed if the fork fails
  13507. + or if the child process dies due to an uncaught signal. Also, the
  13508. + return value is a bit simpler:
  13509. +
  13510. + -1 if there was any problem
  13511. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13512. + as defined in <sys/wait.h>.
  13513. +*/
  13514. +int xsystem(const char *cmd)
  13515. +{
  13516. + int err;
  13517. +
  13518. + err = system(cmd);
  13519. +
  13520. + if (err == -1) {
  13521. + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
  13522. + __FUNCTION__, cmd);
  13523. + return -1;
  13524. + }
  13525. +
  13526. + if (WIFSIGNALED(err)) {
  13527. + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
  13528. + __FUNCTION__, WTERMSIG(err), cmd);
  13529. + return -1;
  13530. + }
  13531. +
  13532. + if (WIFEXITED(err)) {
  13533. + /* Normal child exit */
  13534. + return WEXITSTATUS(err);
  13535. + }
  13536. +
  13537. + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
  13538. + __FUNCTION__, err);
  13539. + return -1;
  13540. +}
  13541. +
  13542. diff -Nur busybox-1.17.0.orig/archival/libipkg/xsystem.h busybox-1.17.0/archival/libipkg/xsystem.h
  13543. --- busybox-1.17.0.orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
  13544. +++ busybox-1.17.0/archival/libipkg/xsystem.h 2010-07-15 21:53:19.625858705 +0200
  13545. @@ -0,0 +1,34 @@
  13546. +/* xsystem.h - system(3) with error messages
  13547. +
  13548. + Carl D. Worth
  13549. +
  13550. + Copyright (C) 2001 University of Southern California
  13551. +
  13552. + This program is free software; you can redistribute it and/or
  13553. + modify it under the terms of the GNU General Public License as
  13554. + published by the Free Software Foundation; either version 2, or (at
  13555. + your option) any later version.
  13556. +
  13557. + This program is distributed in the hope that it will be useful, but
  13558. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13559. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13560. + General Public License for more details.
  13561. +*/
  13562. +
  13563. +#ifndef XSYSTEM_H
  13564. +#define XSYSTEM_H
  13565. +
  13566. +#include <stdlib.h>
  13567. +
  13568. +/* Like system(3), but with error messages printed if the fork fails
  13569. + or if the child process dies due to an uncaught signal. Also, the
  13570. + return value is a bit simpler:
  13571. +
  13572. + -1 if there was any problem
  13573. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13574. + as defined in <sys/wait.h>.
  13575. +*/
  13576. +int xsystem(const char *cmd);
  13577. +
  13578. +#endif
  13579. +
  13580. diff -Nur busybox-1.17.0.orig/archival/libunarchive/Kbuild.src busybox-1.17.0/archival/libunarchive/Kbuild.src
  13581. --- busybox-1.17.0.orig/archival/libunarchive/Kbuild.src 2010-07-06 02:15:46.000000000 +0200
  13582. +++ busybox-1.17.0/archival/libunarchive/Kbuild.src 2010-07-15 21:53:19.675857936 +0200
  13583. @@ -43,6 +43,7 @@
  13584. lib-$(CONFIG_DPKG) += $(DPKG_FILES)
  13585. lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
  13586. lib-$(CONFIG_GUNZIP) += decompress_unzip.o
  13587. +lib-$(CONFIG_IPKG) += open_transformer.o get_header_tar.o get_header_tar_gz.o
  13588. lib-$(CONFIG_RPM2CPIO) += decompress_unzip.o get_header_cpio.o
  13589. lib-$(CONFIG_RPM) += open_transformer.o decompress_unzip.o get_header_cpio.o
  13590. lib-$(CONFIG_TAR) += get_header_tar.o
  13591. diff -Nur busybox-1.17.0.orig/include/applets.src.h busybox-1.17.0/include/applets.src.h
  13592. --- busybox-1.17.0.orig/include/applets.src.h 2010-06-24 04:40:43.000000000 +0200
  13593. +++ busybox-1.17.0/include/applets.src.h 2010-07-15 21:53:19.765858931 +0200
  13594. @@ -209,6 +209,7 @@
  13595. IF_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_DROP))
  13596. IF_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
  13597. IF_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
  13598. +IF_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_DROP))
  13599. IF_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_DROP))
  13600. IF_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_DROP))
  13601. IF_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_DROP))
  13602. diff -Nur busybox-1.17.0.orig/include/unarchive.h busybox-1.17.0/include/unarchive.h
  13603. --- busybox-1.17.0.orig/include/unarchive.h 2010-07-03 13:18:17.000000000 +0200
  13604. +++ busybox-1.17.0/include/unarchive.h 2010-07-15 21:53:19.815859093 +0200
  13605. @@ -76,7 +76,7 @@
  13606. off_t offset;
  13607. /* Archiver specific. Can make it a union if it ever gets big */
  13608. -#if ENABLE_TAR || ENABLE_DPKG || ENABLE_DPKG_DEB
  13609. +#if ENABLE_TAR || ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13610. smallint tar__end;
  13611. # if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
  13612. char* tar__longname;
  13613. @@ -95,7 +95,7 @@
  13614. struct hardlinks_t *cpio__hardlinks_to_create;
  13615. struct hardlinks_t *cpio__created_hardlinks;
  13616. #endif
  13617. -#if ENABLE_DPKG || ENABLE_DPKG_DEB
  13618. +#if ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13619. /* Temporary storage */
  13620. char *dpkg__buffer;
  13621. /* How to process any sub archive, e.g. get_header_tar_gz */
  13622. diff -Nur busybox-1.17.0.orig/include/usage.src.h busybox-1.17.0/include/usage.src.h
  13623. --- busybox-1.17.0.orig/include/usage.src.h 2010-07-03 13:18:17.000000000 +0200
  13624. +++ busybox-1.17.0/include/usage.src.h 2010-07-15 21:53:19.825859052 +0200
  13625. @@ -1556,6 +1556,82 @@
  13626. "$ ls -la /tmp/busybox*\n" \
  13627. "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
  13628. +#define ipkg_trivial_usage \
  13629. + "[options]... sub-command [arguments]..."
  13630. +#define ipkg_full_usage \
  13631. + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
  13632. + "\n" \
  13633. + "Sub-commands:\n" \
  13634. + "\nPackage Manipulation:\n" \
  13635. + "\tupdate Update list of available packages\n" \
  13636. + "\tupgrade Upgrade all installed packages to latest version\n" \
  13637. + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
  13638. + "\tinstall <file.ipk> Install package <file.ipk>\n" \
  13639. + "\tconfigure [<pkg>] Configure unpacked packages\n" \
  13640. + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
  13641. + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
  13642. + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
  13643. + "\n" \
  13644. + "Informational Commands:\n" \
  13645. + "\tlist List available packages and descriptions\n" \
  13646. + "\tlist_installed List all and only the installed packages and description \n" \
  13647. + "\tfiles <pkg> List all files belonging to <pkg>\n" \
  13648. + "\tsearch <file|regexp> Search for a package providing <file>\n" \
  13649. + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
  13650. + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
  13651. + "\tdownload <pkg> Download <pkg> to current directory.\n" \
  13652. + "\tcompare_versions <v1> <op> <v2>\n" \
  13653. + "\t compare versions using <= < > >= = << >>\n" \
  13654. + "\tprint_architecture prints the architecture.\n" \
  13655. + "\tprint_installation_architecture\n" \
  13656. + "\twhatdepends [-A] [pkgname|pat]+\n" \
  13657. + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
  13658. + "\twhatprovides [-A] [pkgname|pat]+\n" \
  13659. + "\twhatconflicts [-A] [pkgname|pat]+\n" \
  13660. + "\twhatreplaces [-A] [pkgname|pat]+\n" \
  13661. + "\t prints the installation architecture.\n" \
  13662. + "\n" \
  13663. + "\nOptions:\n" \
  13664. + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
  13665. + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
  13666. + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
  13667. + "\t 0 errors only\n" \
  13668. + "\t 1 normal messages (default)\n" \
  13669. + "\t 2 informative messages\n" \
  13670. + "\t 3 debug output\n" \
  13671. + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
  13672. + "\t-conf <conf_file> Default configuration file location\n" \
  13673. + " is /etc/ipkg.conf\n" \
  13674. + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
  13675. + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
  13676. + " <dest_name> should be a defined dest name from\n" \
  13677. + " the configuration file, (but can also be a\n" \
  13678. + " directory name in a pinch).\n" \
  13679. + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
  13680. + "\t-offline <offline_root> offline installation of packages.\n" \
  13681. + "\t-verbose_wget more wget messages\n" \
  13682. + "\n" \
  13683. + "Force Options (use when ipkg is too smart for its own good):\n" \
  13684. + "\t-force-depends Make dependency checks warnings instead of errors\n" \
  13685. + "\t Install/remove package in spite of failed dependences\n" \
  13686. + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
  13687. + " (no prompts). Note that this will not prevent\n" \
  13688. + " package installation scripts from prompting.\n" \
  13689. + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
  13690. + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
  13691. + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
  13692. + "\t-force_space Install even if there does not seem to be enough space.\n" \
  13693. + "\t-noaction No action -- test only\n" \
  13694. + "\t-nodeps Do not follow dependences\n" \
  13695. + "\t-force-removal-of-dependent-packages\n" \
  13696. + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
  13697. + "\t-test No action -- test only\n" \
  13698. + "\t-t Specify tmp-dir.\n" \
  13699. + "\t--tmp-dir Specify tmp-dir.\n" \
  13700. + "\n" \
  13701. + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
  13702. + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
  13703. +
  13704. #define halt_trivial_usage \
  13705. "[-d DELAY] [-n] [-f]" IF_FEATURE_WTMP(" [-w]")
  13706. #define halt_full_usage "\n\n" \
  13707. diff -Nur busybox-1.17.0.orig/Makefile busybox-1.17.0/Makefile
  13708. --- busybox-1.17.0.orig/Makefile 2010-07-06 04:16:45.000000000 +0200
  13709. +++ busybox-1.17.0/Makefile 2010-07-15 21:53:19.896241138 +0200
  13710. @@ -459,6 +459,7 @@
  13711. libs-y := \
  13712. archival/ \
  13713. + archival/libipkg/ \
  13714. archival/libunarchive/ \
  13715. console-tools/ \
  13716. coreutils/ \