001-ipkg.patch 425 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805
  1. diff -Nur busybox-1.15.2.orig/archival/Config.in busybox-1.15.2/archival/Config.in
  2. --- busybox-1.15.2.orig/archival/Config.in 2009-10-08 02:59:09.000000000 +0200
  3. +++ busybox-1.15.2/archival/Config.in 2009-11-26 11:10:12.799860030 +0100
  4. @@ -180,6 +180,14 @@
  5. are actually slower than gzip at equivalent compression ratios
  6. and take up 3.2K of code.
  7. +config IPKG
  8. + bool "ipkg"
  9. + default n
  10. + select MD5SUM
  11. + select WGET
  12. + help
  13. + ipkg is the itsy package management system.
  14. +
  15. config RPM2CPIO
  16. bool "rpm2cpio"
  17. default n
  18. diff -Nur busybox-1.15.2.orig/archival/dpkg.c busybox-1.15.2/archival/dpkg.c
  19. --- busybox-1.15.2.orig/archival/dpkg.c 2009-10-08 02:59:09.000000000 +0200
  20. +++ busybox-1.15.2/archival/dpkg.c 2009-11-26 11:10:12.863858133 +0100
  21. @@ -1481,16 +1481,7 @@
  22. return ar_handle->sub_archive->buffer;
  23. }
  24. -static void FAST_FUNC data_extract_all_prefix(archive_handle_t *archive_handle)
  25. -{
  26. - char *name_ptr = archive_handle->file_header->name;
  27. -
  28. - name_ptr += strspn(name_ptr, "./");
  29. - if (name_ptr[0] != '\0') {
  30. - archive_handle->file_header->name = xasprintf("%s%s", archive_handle->buffer, name_ptr);
  31. - data_extract_all(archive_handle);
  32. - }
  33. -}
  34. +/* remove data_extract_all_prefix */
  35. static void unpack_package(deb_file_t *deb_file)
  36. {
  37. diff -Nur busybox-1.15.2.orig/archival/ipkg.c busybox-1.15.2/archival/ipkg.c
  38. --- busybox-1.15.2.orig/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
  39. +++ busybox-1.15.2/archival/ipkg.c 2009-11-26 11:10:12.867860320 +0100
  40. @@ -0,0 +1,28 @@
  41. +/* ipkg.c - the itsy package management system
  42. +
  43. + Florina Boor
  44. +
  45. + Copyright (C) 2003 kernel concepts
  46. +
  47. + This program is free software; you can redistribute it and/or
  48. + modify it under the terms of the GNU General Public License as
  49. + published by the Free Software Foundation; either version 2, or (at
  50. + your option) any later version.
  51. +
  52. + This program is distributed in the hope that it will be useful, but
  53. + WITHOUT ANY WARRANTY; without even the implied warranty of
  54. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  55. + General Public License for more details.
  56. +
  57. + ipkg command line frontend using libipkg
  58. +
  59. +*/
  60. +
  61. +#include "libbb.h"
  62. +#include "libipkg/libipkg.h"
  63. +
  64. +int ipkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  65. +int ipkg_main(int argc, char **argv)
  66. +{
  67. + return ipkg_op(argc, argv);
  68. +}
  69. diff -Nur busybox-1.15.2.orig/archival/Kbuild busybox-1.15.2/archival/Kbuild
  70. --- busybox-1.15.2.orig/archival/Kbuild 2009-09-26 15:14:56.000000000 +0200
  71. +++ busybox-1.15.2/archival/Kbuild 2009-11-26 11:11:08.370253633 +0100
  72. @@ -16,6 +16,7 @@
  73. lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
  74. lib-$(CONFIG_GUNZIP) += bbunzip.o
  75. lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
  76. +lib-$(CONFIG_IPKG) += ipkg.o
  77. lib-$(CONFIG_LZOP) += lzop.o lzo1x_1.o lzo1x_1o.o lzo1x_d.o bbunzip.o
  78. lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o
  79. lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
  80. diff -Nur busybox-1.15.2.orig/archival/libipkg/args.c busybox-1.15.2/archival/libipkg/args.c
  81. --- busybox-1.15.2.orig/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
  82. +++ busybox-1.15.2/archival/libipkg/args.c 2009-11-26 11:10:13.027859475 +0100
  83. @@ -0,0 +1,242 @@
  84. +/* args.c - parse command-line args
  85. +
  86. + Carl D. Worth
  87. +
  88. + Copyright 2001 University of Southern California
  89. +
  90. + This program is free software; you can redistribute it and/or modify
  91. + it under the terms of the GNU General Public License as published by
  92. + the Free Software Foundation; either version 2, or (at your option)
  93. + any later version.
  94. +
  95. + This program is distributed in the hope that it will be useful,
  96. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  97. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  98. + GNU General Public License for more details.
  99. + */
  100. +
  101. +#include <getopt.h>
  102. +#include <stdlib.h>
  103. +#include <string.h>
  104. +#include <unistd.h>
  105. +
  106. +#include "ipkg.h"
  107. +#include "ipkg_message.h"
  108. +
  109. +#include "args.h"
  110. +#include "sprintf_alloc.h"
  111. +
  112. +#include "libbb.h"
  113. +
  114. +
  115. +static void print_version(void);
  116. +
  117. +enum long_args_opt
  118. +{
  119. + ARGS_OPT_FORCE_DEFAULTS = 129,
  120. + ARGS_OPT_FORCE_DEPENDS,
  121. + ARGS_OPT_FORCE_OVERWRITE,
  122. + ARGS_OPT_FORCE_DOWNGRADE,
  123. + ARGS_OPT_FORCE_REINSTALL,
  124. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
  125. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
  126. + ARGS_OPT_FORCE_SPACE,
  127. + ARGS_OPT_NOACTION,
  128. + ARGS_OPT_NODEPS,
  129. + ARGS_OPT_VERBOSE_WGET,
  130. + ARGS_OPT_VERBOSITY,
  131. + ARGS_OPT_MULTIPLE_PROVIDERS
  132. +};
  133. +
  134. +int args_init(args_t *args)
  135. +{
  136. + const char *conf_file_dir;
  137. +
  138. + memset(args, 0, sizeof(args_t));
  139. +
  140. + args->dest = ARGS_DEFAULT_DEST;
  141. +
  142. + conf_file_dir = getenv("IPKG_CONF_DIR");
  143. + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
  144. + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
  145. + }
  146. + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
  147. + ARGS_DEFAULT_CONF_FILE_NAME);
  148. +
  149. + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
  150. + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
  151. + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
  152. + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
  153. + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
  154. + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
  155. + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
  156. + args->noaction = ARGS_DEFAULT_NOACTION;
  157. + args->nodeps = ARGS_DEFAULT_NODEPS;
  158. + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
  159. + args->verbosity = ARGS_DEFAULT_VERBOSITY;
  160. + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
  161. + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
  162. + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
  163. + args->multiple_providers = 0;
  164. + args->nocheckfordirorfile = 0;
  165. + args->noreadfeedsfile = 0;
  166. +
  167. + return 1;
  168. +}
  169. +
  170. +void args_deinit(args_t *args)
  171. +{
  172. + free(args->conf_file);
  173. + args->conf_file = NULL;
  174. +}
  175. +
  176. +int args_parse(args_t *args, int argc, char *argv[])
  177. +{
  178. + int c;
  179. + int option_index = 0;
  180. + int parse_err = 0;
  181. + static struct option long_options[] = {
  182. + {"query-all", 0, 0, 'A'},
  183. + {"conf-file", 1, 0, 'f'},
  184. + {"conf", 1, 0, 'f'},
  185. + {"dest", 1, 0, 'd'},
  186. + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  187. + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  188. + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  189. + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  190. + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  191. + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  192. + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  193. + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  194. + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  195. + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  196. + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
  197. + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
  198. + {"recursive", 0, 0,
  199. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  200. + {"force-removal-of-dependent-packages", 0, 0,
  201. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  202. + {"force_removal_of_dependent_packages", 0, 0,
  203. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  204. + {"force-removal-of-essential-packages", 0, 0,
  205. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  206. + {"force_removal_of_essential_packages", 0, 0,
  207. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  208. + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  209. + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  210. + {"noaction", 0, 0, ARGS_OPT_NOACTION},
  211. + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
  212. + {"offline", 1, 0, 'o'},
  213. + {"offline-root", 1, 0, 'o'},
  214. + {"test", 0, 0, ARGS_OPT_NOACTION},
  215. + {"tmp-dir", 1, 0, 't'},
  216. + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  217. + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  218. + {"verbosity", 2, 0, 'V'},
  219. + {"version", 0, 0, 'v'},
  220. + {0, 0, 0, 0}
  221. + };
  222. +
  223. + while (1) {
  224. + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
  225. + if (c == -1)
  226. + break;
  227. +
  228. + switch (c) {
  229. + case 'A':
  230. + args->query_all = 1;
  231. + break;
  232. + case 'd':
  233. + args->dest = optarg;
  234. + break;
  235. + case 'f':
  236. + free(args->conf_file);
  237. + args->conf_file = strdup(optarg);
  238. + break;
  239. + case 'o':
  240. + args->offline_root = optarg;
  241. + break;
  242. + case 'n':
  243. + args->noaction = 1;
  244. + break;
  245. + case 't':
  246. + args->tmp_dir = strdup(optarg);
  247. + break;
  248. + case 'v':
  249. + print_version();
  250. + exit(0);
  251. + case 'V':
  252. + case ARGS_OPT_VERBOSITY:
  253. + if (optarg)
  254. + args->verbosity = atoi(optarg);
  255. + else
  256. + args->verbosity += 1;
  257. + break;
  258. + case ARGS_OPT_FORCE_DEFAULTS:
  259. + args->force_defaults = 1;
  260. + break;
  261. + case ARGS_OPT_FORCE_DEPENDS:
  262. + args->force_depends = 1;
  263. + break;
  264. + case ARGS_OPT_FORCE_OVERWRITE:
  265. + args->force_overwrite = 1;
  266. + break;
  267. + case ARGS_OPT_FORCE_DOWNGRADE:
  268. + args->force_downgrade = 1;
  269. + break;
  270. + case ARGS_OPT_FORCE_REINSTALL:
  271. + args->force_reinstall = 1;
  272. + break;
  273. + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
  274. + args->force_removal_of_essential_packages = 1;
  275. + break;
  276. + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
  277. + args->force_removal_of_dependent_packages = 1;
  278. + break;
  279. + case ARGS_OPT_FORCE_SPACE:
  280. + args->force_space = 1;
  281. + break;
  282. + case ARGS_OPT_VERBOSE_WGET:
  283. + args->verbose_wget = 1;
  284. + break;
  285. + case ARGS_OPT_MULTIPLE_PROVIDERS:
  286. + args->multiple_providers = 1;
  287. + break;
  288. + case ARGS_OPT_NODEPS:
  289. + args->nodeps = 1;
  290. + break;
  291. + case ARGS_OPT_NOACTION:
  292. + args->noaction = 1;
  293. + break;
  294. + case ':':
  295. + parse_err++;
  296. + break;
  297. + case '?':
  298. + parse_err++;
  299. + break;
  300. + default:
  301. + bb_error_msg("Confusion: getopt_long returned %d\n", c);
  302. + }
  303. + }
  304. +
  305. + if (parse_err) {
  306. + return -parse_err;
  307. + } else {
  308. + return optind;
  309. + }
  310. +}
  311. +
  312. +void args_usage(const char *complaint)
  313. +{
  314. + if (complaint) {
  315. + bb_error_msg("%s\n", complaint);
  316. + }
  317. + print_version();
  318. + bb_show_usage();
  319. + exit(1);
  320. +}
  321. +
  322. +static void print_version(void)
  323. +{
  324. + bb_error_msg("version %s\n", IPKG_VERSION);
  325. +}
  326. diff -Nur busybox-1.15.2.orig/archival/libipkg/args.h busybox-1.15.2/archival/libipkg/args.h
  327. --- busybox-1.15.2.orig/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
  328. +++ busybox-1.15.2/archival/libipkg/args.h 2009-11-26 11:10:13.111859002 +0100
  329. @@ -0,0 +1,72 @@
  330. +/* args.h - parse command-line args
  331. +
  332. + Carl D. Worth
  333. +
  334. + Copyright 2001 University of Southern California
  335. +
  336. + This program is free software; you can redistribute it and/or modify
  337. + it under the terms of the GNU General Public License as published by
  338. + the Free Software Foundation; either version 2, or (at your option)
  339. + any later version.
  340. +
  341. + This program is distributed in the hope that it will be useful,
  342. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  343. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  344. + GNU General Public License for more details.
  345. +*/
  346. +
  347. +#ifndef ARGS_H
  348. +#define ARGS_H
  349. +
  350. +struct args
  351. +{
  352. + char *conf_file;
  353. + char *dest;
  354. + char *tmp_dir;
  355. + int force_defaults;
  356. + int force_depends;
  357. + int force_overwrite;
  358. + int force_downgrade;
  359. + int force_reinstall;
  360. + int force_removal_of_essential_packages;
  361. + int force_removal_of_dependent_packages;
  362. + int force_space;
  363. + int noaction;
  364. + int nodeps;
  365. + int multiple_providers;
  366. + int query_all;
  367. + int verbose_wget;
  368. + int verbosity;
  369. + int nocheckfordirorfile;
  370. + int noreadfeedsfile;
  371. + char *offline_root;
  372. + char *offline_root_pre_script_cmd;
  373. + char *offline_root_post_script_cmd;
  374. +};
  375. +typedef struct args args_t;
  376. +
  377. +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
  378. +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
  379. +#define ARGS_DEFAULT_DEST NULL
  380. +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
  381. +#define ARGS_DEFAULT_FORCE_DEPENDS 0
  382. +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
  383. +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
  384. +#define ARGS_DEFAULT_FORCE_REINSTALL 0
  385. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
  386. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
  387. +#define ARGS_DEFAULT_FORCE_SPACE 0
  388. +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
  389. +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
  390. +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
  391. +#define ARGS_DEFAULT_NOACTION 0
  392. +#define ARGS_DEFAULT_NODEPS 0
  393. +#define ARGS_DEFAULT_VERBOSE_WGET 0
  394. +#define ARGS_DEFAULT_VERBOSITY 1
  395. +
  396. +int args_init(args_t *args);
  397. +void args_deinit(args_t *args);
  398. +int args_parse(args_t *args, int argc, char *argv[]);
  399. +void args_usage(const char *complaint);
  400. +
  401. +#endif
  402. diff -Nur busybox-1.15.2.orig/archival/libipkg/conffile.c busybox-1.15.2/archival/libipkg/conffile.c
  403. --- busybox-1.15.2.orig/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
  404. +++ busybox-1.15.2/archival/libipkg/conffile.c 2009-11-26 11:10:13.115859512 +0100
  405. @@ -0,0 +1,65 @@
  406. +/* conffile.c - the itsy package management system
  407. +
  408. + Carl D. Worth
  409. +
  410. + Copyright (C) 2001 University of Southern California
  411. +
  412. + This program is free software; you can redistribute it and/or
  413. + modify it under the terms of the GNU General Public License as
  414. + published by the Free Software Foundation; either version 2, or (at
  415. + your option) any later version.
  416. +
  417. + This program is distributed in the hope that it will be useful, but
  418. + WITHOUT ANY WARRANTY; without even the implied warranty of
  419. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  420. + General Public License for more details.
  421. +*/
  422. +
  423. +#include <string.h>
  424. +#include <stdlib.h>
  425. +
  426. +#include "libbb.h"
  427. +#include "ipkg.h"
  428. +#include "ipkg_message.h"
  429. +
  430. +#include "conffile.h"
  431. +#include "file_util.h"
  432. +#include "sprintf_alloc.h"
  433. +
  434. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum)
  435. +{
  436. + return nv_pair_init(conffile, file_name, (char *)md5sum);
  437. +}
  438. +
  439. +void conffile_deinit(conffile_t *conffile)
  440. +{
  441. + nv_pair_deinit(conffile);
  442. +}
  443. +
  444. +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
  445. +{
  446. + uint8_t *md5sum;
  447. + char *filename = conffile->name;
  448. + char *root_filename;
  449. + int ret;
  450. +
  451. + if (conffile->value == NULL) {
  452. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
  453. + return 1;
  454. + }
  455. +
  456. + root_filename = root_filename_alloc(conf, filename);
  457. +
  458. + md5sum = file_md5sum_alloc(root_filename);
  459. +
  460. + ret = strcmp((char *)md5sum, conffile->value);
  461. + if (ret) {
  462. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
  463. + conffile->name, md5sum, conffile->value);
  464. + }
  465. +
  466. + free(root_filename);
  467. + free(md5sum);
  468. +
  469. + return ret;
  470. +}
  471. diff -Nur busybox-1.15.2.orig/archival/libipkg/conffile.h busybox-1.15.2/archival/libipkg/conffile.h
  472. --- busybox-1.15.2.orig/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
  473. +++ busybox-1.15.2/archival/libipkg/conffile.h 2009-11-26 11:10:13.115859512 +0100
  474. @@ -0,0 +1,30 @@
  475. +/* conffile.h - the itsy package management system
  476. +
  477. + Carl D. Worth
  478. +
  479. + Copyright (C) 2001 University of Southern California
  480. +
  481. + This program is free software; you can redistribute it and/or
  482. + modify it under the terms of the GNU General Public License as
  483. + published by the Free Software Foundation; either version 2, or (at
  484. + your option) any later version.
  485. +
  486. + This program is distributed in the hope that it will be useful, but
  487. + WITHOUT ANY WARRANTY; without even the implied warranty of
  488. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  489. + General Public License for more details.
  490. +*/
  491. +
  492. +#ifndef CONFFILE_H
  493. +#define CONFFILE_H
  494. +
  495. +#include "nv_pair.h"
  496. +
  497. +typedef struct nv_pair conffile_t;
  498. +
  499. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum);
  500. +void conffile_deinit(conffile_t *conffile);
  501. +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
  502. +
  503. +#endif
  504. +
  505. diff -Nur busybox-1.15.2.orig/archival/libipkg/conffile_list.c busybox-1.15.2/archival/libipkg/conffile_list.c
  506. --- busybox-1.15.2.orig/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
  507. +++ busybox-1.15.2/archival/libipkg/conffile_list.c 2009-11-26 11:10:13.171857147 +0100
  508. @@ -0,0 +1,47 @@
  509. +/* conffile_list.c - the itsy package management system
  510. +
  511. + Carl D. Worth
  512. +
  513. + Copyright (C) 2001 University of Southern California
  514. +
  515. + This program is free software; you can redistribute it and/or
  516. + modify it under the terms of the GNU General Public License as
  517. + published by the Free Software Foundation; either version 2, or (at
  518. + your option) any later version.
  519. +
  520. + This program is distributed in the hope that it will be useful, but
  521. + WITHOUT ANY WARRANTY; without even the implied warranty of
  522. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  523. + General Public License for more details.
  524. +*/
  525. +
  526. +#include "ipkg.h"
  527. +
  528. +#include "conffile_list.h"
  529. +
  530. +int conffile_list_init(conffile_list_t *list)
  531. +{
  532. + return nv_pair_list_init(list);
  533. +}
  534. +
  535. +void conffile_list_deinit(conffile_list_t *list)
  536. +{
  537. + nv_pair_list_deinit(list);
  538. +}
  539. +
  540. +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
  541. + const char *md5sum)
  542. +{
  543. + return nv_pair_list_append(list, file_name, md5sum);
  544. +}
  545. +
  546. +int conffile_list_push(conffile_list_t *list, conffile_t *data)
  547. +{
  548. + return nv_pair_list_push(list, data);
  549. +}
  550. +
  551. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
  552. +{
  553. + return nv_pair_list_pop(list);
  554. +}
  555. +
  556. diff -Nur busybox-1.15.2.orig/archival/libipkg/conffile_list.h busybox-1.15.2/archival/libipkg/conffile_list.h
  557. --- busybox-1.15.2.orig/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
  558. +++ busybox-1.15.2/archival/libipkg/conffile_list.h 2009-11-26 11:10:13.171857147 +0100
  559. @@ -0,0 +1,36 @@
  560. +/* conffile_list.h - the itsy package management system
  561. +
  562. + Carl D. Worth
  563. +
  564. + Copyright (C) 2001 University of Southern California
  565. +
  566. + This program is free software; you can redistribute it and/or
  567. + modify it under the terms of the GNU General Public License as
  568. + published by the Free Software Foundation; either version 2, or (at
  569. + your option) any later version.
  570. +
  571. + This program is distributed in the hope that it will be useful, but
  572. + WITHOUT ANY WARRANTY; without even the implied warranty of
  573. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  574. + General Public License for more details.
  575. +*/
  576. +
  577. +#ifndef CONFFILE_LIST_H
  578. +#define CONFFILE_LIST_H
  579. +
  580. +#include "conffile.h"
  581. +#include "nv_pair_list.h"
  582. +
  583. +typedef struct nv_pair_list_elt conffile_list_elt_t;
  584. +typedef struct nv_pair_list conffile_list_t;
  585. +
  586. +int conffile_list_init(conffile_list_t *list);
  587. +void conffile_list_deinit(conffile_list_t *list);
  588. +
  589. +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
  590. + const char *root_dir);
  591. +int conffile_list_push(conffile_list_t *list, conffile_t *data);
  592. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
  593. +
  594. +#endif
  595. +
  596. diff -Nur busybox-1.15.2.orig/archival/libipkg/file_util.c busybox-1.15.2/archival/libipkg/file_util.c
  597. --- busybox-1.15.2.orig/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
  598. +++ busybox-1.15.2/archival/libipkg/file_util.c 2009-11-27 18:30:35.846386159 +0100
  599. @@ -0,0 +1,186 @@
  600. +/* file_util.c - convenience routines for common stat operations
  601. +
  602. + Carl D. Worth
  603. +
  604. + Copyright (C) 2001 University of Southern California
  605. +
  606. + This program is free software; you can redistribute it and/or
  607. + modify it under the terms of the GNU General Public License as
  608. + published by the Free Software Foundation; either version 2, or (at
  609. + your option) any later version.
  610. +
  611. + This program is distributed in the hope that it will be useful, but
  612. + WITHOUT ANY WARRANTY; without even the implied warranty of
  613. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  614. + General Public License for more details.
  615. +*/
  616. +
  617. +#include "ipkg.h"
  618. +#include <sys/types.h>
  619. +#include <sys/stat.h>
  620. +
  621. +#include "sprintf_alloc.h"
  622. +#include "file_util.h"
  623. +#include "libbb.h"
  624. +#undef strlen
  625. +
  626. +int file_exists(const char *file_name)
  627. +{
  628. + int err;
  629. + struct stat stat_buf;
  630. +
  631. + err = stat(file_name, &stat_buf);
  632. + if (err == 0) {
  633. + return 1;
  634. + } else {
  635. + return 0;
  636. + }
  637. +}
  638. +
  639. +int file_is_dir(const char *file_name)
  640. +{
  641. + int err;
  642. + struct stat stat_buf;
  643. +
  644. + err = stat(file_name, &stat_buf);
  645. + if (err) {
  646. + return 0;
  647. + }
  648. +
  649. + return S_ISDIR(stat_buf.st_mode);
  650. +}
  651. +
  652. +/* read a single line from a file, stopping at a newline or EOF.
  653. + If a newline is read, it will appear in the resulting string.
  654. + Return value is a malloc'ed char * which should be freed at
  655. + some point by the caller.
  656. +
  657. + Return value is NULL if the file is at EOF when called.
  658. +*/
  659. +#define FILE_READ_LINE_BUF_SIZE 1024
  660. +char *file_read_line_alloc(FILE *file)
  661. +{
  662. + char buf[FILE_READ_LINE_BUF_SIZE];
  663. + int buf_len;
  664. + char *line = NULL;
  665. + int line_size = 0;
  666. +
  667. + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
  668. + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
  669. + buf_len = strlen(buf);
  670. + if (line) {
  671. + line_size += buf_len;
  672. + line = realloc(line, line_size);
  673. + if (line == NULL) {
  674. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  675. + break;
  676. + }
  677. + strcat(line, buf);
  678. + } else {
  679. + line_size = buf_len + 1;
  680. + line = strdup(buf);
  681. + }
  682. + if (buf[buf_len - 1] == '\n') {
  683. + break;
  684. + }
  685. + }
  686. +
  687. + return line;
  688. +}
  689. +
  690. +int file_move(const char *src, const char *dest)
  691. +{
  692. + int err;
  693. +
  694. + err = rename(src, dest);
  695. +
  696. + if (err && errno == EXDEV) {
  697. + err = file_copy(src, dest);
  698. + unlink(src);
  699. + } else if (err) {
  700. + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
  701. + __FUNCTION__, src, dest, strerror(errno));
  702. + }
  703. +
  704. + return err;
  705. +}
  706. +
  707. +/* I put these here to keep libbb dependencies from creeping all over
  708. + the ipkg code */
  709. +int file_copy(const char *src, const char *dest)
  710. +{
  711. + int err;
  712. +
  713. + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
  714. + if (err) {
  715. + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
  716. + __FUNCTION__, src, dest);
  717. + }
  718. +
  719. + return err;
  720. +}
  721. +
  722. +int file_mkdir_hier(char *path, long mode)
  723. +{
  724. + return bb_make_directory(path, mode, FILEUTILS_RECUR);
  725. +}
  726. +
  727. +static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
  728. + unsigned hash_length)
  729. +{
  730. + /* xzalloc zero-terminates */
  731. + char *hex_value = xzalloc((hash_length * 2) + 1);
  732. + bin2hex(hex_value, (char*)hash_value, hash_length);
  733. + return (unsigned char *)hex_value;
  734. +}
  735. +
  736. +static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
  737. +{
  738. + int src_fd, hash_len, count;
  739. + union _ctx_ {
  740. + sha1_ctx_t sha1;
  741. + md5_ctx_t md5;
  742. + } context;
  743. + uint8_t *hash_value = NULL;
  744. + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
  745. + void FAST_FUNC (*update)(const void*, size_t, void*);
  746. + void FAST_FUNC (*final)(void*, void*);
  747. +
  748. + src_fd = open_or_warn_stdin(filename);
  749. + if (src_fd < 0) {
  750. + return NULL;
  751. + }
  752. +
  753. + /* figure specific hash algorithims */
  754. + if (ENABLE_MD5SUM && hash_algo == HASH_MD5) {
  755. + md5_begin(&context.md5);
  756. + update = (void*)md5_hash;
  757. + final = (void*)md5_end;
  758. + hash_len = 16;
  759. + } else {
  760. + bb_error_msg_and_die("algorithm not supported");
  761. + }
  762. +
  763. + while (0 < (count = safe_read(src_fd, in_buf, 4096))) {
  764. + update(in_buf, count, &context);
  765. + }
  766. +
  767. + if (count == 0) {
  768. + final(in_buf, &context);
  769. + hash_value = hash_bin_to_hex(in_buf, hash_len);
  770. + }
  771. +
  772. + RELEASE_CONFIG_BUFFER(in_buf);
  773. +
  774. + if (src_fd != STDIN_FILENO) {
  775. + close(src_fd);
  776. + }
  777. +
  778. + return hash_value;
  779. +}
  780. +
  781. +uint8_t *file_md5sum_alloc(const char *file_name)
  782. +{
  783. + return hash_file(file_name, HASH_MD5);
  784. +}
  785. +
  786. diff -Nur busybox-1.15.2.orig/archival/libipkg/file_util.h busybox-1.15.2/archival/libipkg/file_util.h
  787. --- busybox-1.15.2.orig/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
  788. +++ busybox-1.15.2/archival/libipkg/file_util.h 2009-11-26 11:10:13.231859479 +0100
  789. @@ -0,0 +1,29 @@
  790. +/* file_util.h - convenience routines for common file operations
  791. +
  792. + Carl D. Worth
  793. +
  794. + Copyright (C) 2001 University of Southern California
  795. +
  796. + This program is free software; you can redistribute it and/or
  797. + modify it under the terms of the GNU General Public License as
  798. + published by the Free Software Foundation; either version 2, or (at
  799. + your option) any later version.
  800. +
  801. + This program is distributed in the hope that it will be useful, but
  802. + WITHOUT ANY WARRANTY; without even the implied warranty of
  803. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  804. + General Public License for more details.
  805. +*/
  806. +
  807. +#ifndef FILE_UTIL_H
  808. +#define FILE_UTIL_H
  809. +
  810. +int file_exists(const char *file_name);
  811. +int file_is_dir(const char *file_name);
  812. +char *file_read_line_alloc(FILE *file);
  813. +int file_move(const char *src, const char *dest);
  814. +int file_copy(const char *src, const char *dest);
  815. +int file_mkdir_hier(char *path, long mode);
  816. +uint8_t *file_md5sum_alloc(const char *file_name);
  817. +
  818. +#endif
  819. diff -Nur busybox-1.15.2.orig/archival/libipkg/hash_table.c busybox-1.15.2/archival/libipkg/hash_table.c
  820. --- busybox-1.15.2.orig/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
  821. +++ busybox-1.15.2/archival/libipkg/hash_table.c 2009-11-26 11:10:13.311857371 +0100
  822. @@ -0,0 +1,155 @@
  823. +/* hash.c - hash tables for ipkg
  824. +
  825. + Steven M. Ayer, Jamey Hicks
  826. +
  827. + Copyright (C) 2002 Compaq Computer Corporation
  828. +
  829. + This program is free software; you can redistribute it and/or
  830. + modify it under the terms of the GNU General Public License as
  831. + published by the Free Software Foundation; either version 2, or (at
  832. + your option) any later version.
  833. +
  834. + This program is distributed in the hope that it will be useful, but
  835. + WITHOUT ANY WARRANTY; without even the implied warranty of
  836. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  837. + General Public License for more details.
  838. +*/
  839. +
  840. +#include <errno.h>
  841. +#include <stdio.h>
  842. +#include <stdlib.h>
  843. +#include <string.h>
  844. +#include "hash_table.h"
  845. +#include "ipkg_message.h"
  846. +
  847. +
  848. +static int hash_index(hash_table_t *hash, const char *pkg_name);
  849. +static int rotating(const char *key, int len, int prime);
  850. +
  851. +static int hash_index(hash_table_t *hash, const char *pkg_name)
  852. +{
  853. + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
  854. +}
  855. +
  856. +static int rotating(const char *key, int len, int prime)
  857. +{
  858. + unsigned int hash, i;
  859. + for (hash=len, i=0; i<len; ++i)
  860. + hash = (hash<<4)^(hash>>28)^key[i];
  861. + return (hash % prime);
  862. +}
  863. +
  864. +
  865. +/*
  866. + * this is an open table keyed by strings
  867. + */
  868. +int hash_table_init(const char *name, hash_table_t *hash, int len)
  869. +{
  870. + static int primes_table[] = {
  871. + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
  872. + 19471, 23143, 33961, 46499, 49727, 99529, 0
  873. + };
  874. + int *picker;
  875. +
  876. + if (hash->entries != NULL) {
  877. + /* we have been here already */
  878. + return 0;
  879. + }
  880. +
  881. + hash->name = name;
  882. + hash->entries = NULL;
  883. + hash->n_entries = 0;
  884. + hash->hash_entry_key = NULL;
  885. +
  886. + picker = primes_table;
  887. + while(*picker && (*picker++ < len));
  888. + if(!*picker)
  889. + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
  890. + --picker;
  891. +
  892. + hash->n_entries = *picker;
  893. + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
  894. + if (hash->entries == NULL) {
  895. + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
  896. + return ENOMEM;
  897. + }
  898. + return 0;
  899. +}
  900. +
  901. +void hash_table_deinit(hash_table_t *hash)
  902. +{
  903. + free(hash->entries);
  904. + hash->entries = NULL;
  905. + hash->n_entries = 0;
  906. +}
  907. +
  908. +void *hash_table_get(hash_table_t *hash, const char *key)
  909. +{
  910. + int ndx= hash_index(hash, key);
  911. + hash_entry_t *hash_entry = hash->entries + ndx;
  912. + while (hash_entry)
  913. + {
  914. + if (hash_entry->key)
  915. + {
  916. + if (strcmp(key, hash_entry->key) == 0) {
  917. + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
  918. + return hash_entry->data;
  919. + }
  920. + }
  921. + hash_entry = hash_entry->next;
  922. + }
  923. + return NULL;
  924. +}
  925. +
  926. +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
  927. +{
  928. + int ndx= hash_index(hash, key);
  929. + hash_entry_t *hash_entry = hash->entries + ndx;
  930. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
  931. + if (hash_entry->key) {
  932. + if (strcmp(hash_entry->key, key) == 0) {
  933. + /* alread in table, update the value */
  934. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
  935. + hash_entry->data = value;
  936. + return 0;
  937. + } else {
  938. + /*
  939. + * if this is a collision, we have to go to the end of the ll,
  940. + * then add a new entry
  941. + * before we can hook up the value
  942. + */
  943. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
  944. + while (hash_entry->next)
  945. + hash_entry = hash_entry->next;
  946. + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
  947. + if (!hash_entry->next) {
  948. + return -ENOMEM;
  949. + }
  950. + hash_entry = hash_entry->next;
  951. + hash_entry->next = NULL;
  952. + }
  953. + }
  954. + hash->n_elements++;
  955. + hash_entry->key = strdup(key);
  956. + hash_entry->data = value;
  957. +
  958. + return 0;
  959. +}
  960. +
  961. +
  962. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
  963. +{
  964. + int i;
  965. + if (!hash || !f)
  966. + return;
  967. +
  968. + for (i = 0; i < hash->n_entries; i++) {
  969. + hash_entry_t *hash_entry = (hash->entries + i);
  970. + do {
  971. + if(hash_entry->key) {
  972. + f(hash_entry->key, hash_entry->data, data);
  973. + }
  974. + } while((hash_entry = hash_entry->next));
  975. + }
  976. +}
  977. +
  978. diff -Nur busybox-1.15.2.orig/archival/libipkg/hash_table.h busybox-1.15.2/archival/libipkg/hash_table.h
  979. --- busybox-1.15.2.orig/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
  980. +++ busybox-1.15.2/archival/libipkg/hash_table.h 2009-11-26 11:10:13.311857371 +0100
  981. @@ -0,0 +1,44 @@
  982. +/* hash.h - hash tables for ipkg
  983. +
  984. + Steven M. Ayer, Jamey Hicks
  985. +
  986. + Copyright (C) 2002 Compaq Computer Corporation
  987. +
  988. + This program is free software; you can redistribute it and/or
  989. + modify it under the terms of the GNU General Public License as
  990. + published by the Free Software Foundation; either version 2, or (at
  991. + your option) any later version.
  992. +
  993. + This program is distributed in the hope that it will be useful, but
  994. + WITHOUT ANY WARRANTY; without even the implied warranty of
  995. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  996. + General Public License for more details.
  997. +*/
  998. +
  999. +#ifndef _HASH_TABLE_H_
  1000. +#define _HASH_TABLE_H_
  1001. +
  1002. +typedef struct hash_entry hash_entry_t;
  1003. +typedef struct hash_table hash_table_t;
  1004. +
  1005. +struct hash_entry {
  1006. + const char * key;
  1007. + void * data;
  1008. + struct hash_entry * next;
  1009. +};
  1010. +
  1011. +struct hash_table {
  1012. + const char *name;
  1013. + hash_entry_t * entries;
  1014. + int n_entries; /* number of buckets */
  1015. + int n_elements;
  1016. + const char * (*hash_entry_key)(void * data);
  1017. +};
  1018. +
  1019. +int hash_table_init(const char *name, hash_table_t *hash, int len);
  1020. +void hash_table_deinit(hash_table_t *hash);
  1021. +void *hash_table_get(hash_table_t *hash, const char *key);
  1022. +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
  1023. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
  1024. +
  1025. +#endif /* _HASH_TABLE_H_ */
  1026. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_cmd.c busybox-1.15.2/archival/libipkg/ipkg_cmd.c
  1027. --- busybox-1.15.2.orig/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
  1028. +++ busybox-1.15.2/archival/libipkg/ipkg_cmd.c 2009-11-26 11:10:13.403858760 +0100
  1029. @@ -0,0 +1,1433 @@
  1030. +/* ipkg_cmd.c - the itsy package management system
  1031. +
  1032. + Carl D. Worth
  1033. +
  1034. + Copyright (C) 2001 University of Southern California
  1035. +
  1036. + This program is free software; you can redistribute it and/or
  1037. + modify it under the terms of the GNU General Public License as
  1038. + published by the Free Software Foundation; either version 2, or (at
  1039. + your option) any later version.
  1040. +
  1041. + This program is distributed in the hope that it will be useful, but
  1042. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1043. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1044. + General Public License for more details.
  1045. +*/
  1046. +
  1047. +#include <string.h>
  1048. +
  1049. +#include "ipkg.h"
  1050. +#include <libgen.h>
  1051. +#include <glob.h>
  1052. +#include <errno.h>
  1053. +#include <stdlib.h>
  1054. +#include <unistd.h>
  1055. +#include <signal.h>
  1056. +#include <stdio.h>
  1057. +#include <dirent.h>
  1058. +
  1059. +#include "ipkg_conf.h"
  1060. +#include "ipkg_cmd.h"
  1061. +#include "ipkg_message.h"
  1062. +#include "pkg.h"
  1063. +#include "pkg_dest.h"
  1064. +#include "pkg_parse.h"
  1065. +#include "sprintf_alloc.h"
  1066. +#include "pkg.h"
  1067. +#include "file_util.h"
  1068. +#include "str_util.h"
  1069. +#include "unarchive.h"
  1070. +
  1071. +#include <fnmatch.h>
  1072. +
  1073. +
  1074. +#include "ipkg_download.h"
  1075. +#include "ipkg_install.h"
  1076. +#include "ipkg_upgrade.h"
  1077. +#include "ipkg_remove.h"
  1078. +#include "ipkg_configure.h"
  1079. +#include "ipkg_message.h"
  1080. +
  1081. +#ifdef IPKG_LIB
  1082. +#include "libipkg.h"
  1083. +static void *p_userdata = NULL;
  1084. +#endif
  1085. +
  1086. +static int ipkg_update_cmd(ipkg_conf_t *conf);
  1087. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1088. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1089. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1090. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1091. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf);
  1092. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1093. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1094. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1095. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1096. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1097. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1098. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1099. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1100. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1101. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1102. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1103. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1104. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1105. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1106. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1107. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1108. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1109. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf);
  1110. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1111. +
  1112. +/* XXX: CLEANUP: The usage strings should be incorporated into this
  1113. + array for easier maintenance */
  1114. +static ipkg_cmd_t cmds[] = {
  1115. + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
  1116. + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
  1117. + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
  1118. + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
  1119. + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
  1120. + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
  1121. + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
  1122. + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
  1123. + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
  1124. + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
  1125. + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
  1126. + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
  1127. + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
  1128. + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
  1129. + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
  1130. + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1131. + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1132. + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1133. + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1134. + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1135. + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1136. + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
  1137. + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
  1138. + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
  1139. + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
  1140. + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
  1141. + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
  1142. + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
  1143. + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
  1144. +};
  1145. +
  1146. +int ipkg_state_changed;
  1147. +static void write_status_files_if_changed(ipkg_conf_t *conf)
  1148. +{
  1149. + if (ipkg_state_changed && !conf->noaction) {
  1150. + ipkg_message(conf, IPKG_INFO,
  1151. + " writing status file\n");
  1152. + ipkg_conf_write_status_files(conf);
  1153. + pkg_write_changed_filelists(conf);
  1154. + } else {
  1155. + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
  1156. + }
  1157. +}
  1158. +
  1159. +
  1160. +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
  1161. +
  1162. +ipkg_cmd_t *ipkg_cmd_find(const char *name)
  1163. +{
  1164. + int i;
  1165. + ipkg_cmd_t *cmd;
  1166. +
  1167. + for (i=0; i < num_cmds; i++) {
  1168. + cmd = &cmds[i];
  1169. + if (strcmp(name, cmd->name) == 0) {
  1170. + return cmd;
  1171. + }
  1172. + }
  1173. +
  1174. + return NULL;
  1175. +}
  1176. +
  1177. +#ifdef IPKG_LIB
  1178. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
  1179. +{
  1180. + int result;
  1181. + p_userdata = userdata;
  1182. +
  1183. +
  1184. + result = (cmd->fun)(conf, argc, argv);
  1185. + if ( result == 0 ) {
  1186. + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
  1187. + } else {
  1188. + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
  1189. +
  1190. + }
  1191. + if ( error_list ) {
  1192. + reverse_error_list(&error_list);
  1193. +
  1194. + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
  1195. + /* Here we print the errors collected and free the list */
  1196. + while (error_list != NULL) {
  1197. + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
  1198. + error_list = error_list->next;
  1199. +
  1200. + }
  1201. + free_error_list(&error_list);
  1202. +
  1203. + }
  1204. +
  1205. + p_userdata = NULL;
  1206. + return result;
  1207. +}
  1208. +#else
  1209. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv)
  1210. +{
  1211. + return (cmd->fun)(conf, argc, argv);
  1212. +}
  1213. +#endif
  1214. +
  1215. +static int ipkg_update_cmd(ipkg_conf_t *conf)
  1216. +{
  1217. + int err;
  1218. + int failures;
  1219. + char *lists_dir;
  1220. + pkg_src_list_elt_t *iter;
  1221. + pkg_src_t *src;
  1222. +
  1223. +
  1224. + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
  1225. +
  1226. + if (! file_is_dir(lists_dir)) {
  1227. + if (file_exists(lists_dir)) {
  1228. + ipkg_message(conf, IPKG_ERROR,
  1229. + "%s: ERROR: %s exists, but is not a directory\n",
  1230. + __FUNCTION__, lists_dir);
  1231. + free(lists_dir);
  1232. + return EINVAL;
  1233. + }
  1234. + err = file_mkdir_hier(lists_dir, 0755);
  1235. + if (err) {
  1236. + ipkg_message(conf, IPKG_ERROR,
  1237. + "%s: ERROR: failed to make directory %s: %s\n",
  1238. + __FUNCTION__, lists_dir, strerror(errno));
  1239. + free(lists_dir);
  1240. + return EINVAL;
  1241. + }
  1242. + }
  1243. +
  1244. + failures = 0;
  1245. + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
  1246. + char *url, *list_file_name;
  1247. +
  1248. + src = iter->data;
  1249. +
  1250. + if (src->extra_data) /* debian style? */
  1251. + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
  1252. + src->gzip ? "Packages.gz" : "Packages");
  1253. + else
  1254. + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
  1255. +
  1256. + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
  1257. + if (src->gzip) {
  1258. + char *tmp;
  1259. + char *tmp_file_name;
  1260. + FILE *in, *out;
  1261. +
  1262. + tmp = strdup ("/tmp/ipkg.XXXXXX");
  1263. +
  1264. + if (mkdtemp (tmp) == NULL) {
  1265. + perror ("mkdtemp");
  1266. + failures++;
  1267. + continue;
  1268. + }
  1269. +
  1270. + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
  1271. + err = ipkg_download(conf, url, tmp_file_name);
  1272. + if (err == 0) {
  1273. + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
  1274. + in = fopen (tmp_file_name, "r");
  1275. + out = fopen (list_file_name, "w");
  1276. + if (in && out) {
  1277. + inflate_unzip_result res;
  1278. + inflate_unzip (&res, 0x8000, fileno(in), fileno(out));
  1279. + } else
  1280. + err = 1;
  1281. + if (in)
  1282. + fclose (in);
  1283. + if (out)
  1284. + fclose (out);
  1285. + unlink (tmp_file_name);
  1286. + rmdir (tmp);
  1287. + free (tmp);
  1288. + }
  1289. + } else
  1290. + err = ipkg_download(conf, url, list_file_name);
  1291. + if (err) {
  1292. + failures++;
  1293. + } else {
  1294. + ipkg_message(conf, IPKG_NOTICE,
  1295. + "Updated list of available packages in %s\n",
  1296. + list_file_name);
  1297. + }
  1298. + free(url);
  1299. + free(list_file_name);
  1300. + }
  1301. + free(lists_dir);
  1302. +
  1303. +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
  1304. +#warning here
  1305. + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
  1306. + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
  1307. + * -Jamey 3/1/03
  1308. + */
  1309. + {
  1310. + int i;
  1311. + int changed = 0;
  1312. + pkg_vec_t *available = pkg_vec_alloc();
  1313. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1314. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
  1315. + for (i = 0; i < available->len; i++) {
  1316. + pkg_t *pkg = available->pkgs[i];
  1317. + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
  1318. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
  1319. + pkg->state_want = SW_UNKNOWN;
  1320. + changed = 1;
  1321. + }
  1322. + }
  1323. + pkg_vec_free(available);
  1324. + if (changed) {
  1325. + write_status_files_if_changed(conf);
  1326. + }
  1327. + }
  1328. +#endif
  1329. +
  1330. + return failures;
  1331. +}
  1332. +
  1333. +
  1334. +/* scan the args passed and cache the local filenames of the packages */
  1335. +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
  1336. +{
  1337. + int i;
  1338. + int err;
  1339. +
  1340. + /*
  1341. + * First scan through package names/urls
  1342. + * For any urls, download the packages and install in database.
  1343. + * For any files, install package info in database.
  1344. + */
  1345. + for (i = 0; i < argc; i ++) {
  1346. + char *filename = argv [i];
  1347. + //char *tmp = basename (tmp);
  1348. + //int tmplen = strlen (tmp);
  1349. +
  1350. + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
  1351. + // continue;
  1352. + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
  1353. + // continue;
  1354. +
  1355. + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
  1356. +
  1357. + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
  1358. + if (err)
  1359. + return err;
  1360. + }
  1361. + return 0;
  1362. +}
  1363. +
  1364. +struct ipkg_intercept
  1365. +{
  1366. + char *oldpath;
  1367. + char *statedir;
  1368. +};
  1369. +
  1370. +typedef struct ipkg_intercept *ipkg_intercept_t;
  1371. +ipkg_intercept_t ipkg_prep_intercepts(void);
  1372. +
  1373. +ipkg_intercept_t ipkg_prep_intercepts(void)
  1374. +{
  1375. + ipkg_intercept_t ctx;
  1376. + char *newpath;
  1377. + int gen;
  1378. +
  1379. + ctx = malloc (sizeof (*ctx));
  1380. + ctx->oldpath = strdup (getenv ("PATH"));
  1381. +
  1382. + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
  1383. + setenv ("PATH", newpath, 1);
  1384. + free (newpath);
  1385. +
  1386. + gen = 0;
  1387. + retry:
  1388. + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
  1389. + if (mkdir (ctx->statedir, 0770) < 0) {
  1390. + if (errno == EEXIST) {
  1391. + free (ctx->statedir);
  1392. + gen++;
  1393. + goto retry;
  1394. + }
  1395. + perror (ctx->statedir);
  1396. + return NULL;
  1397. + }
  1398. + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
  1399. + return ctx;
  1400. +}
  1401. +
  1402. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx);
  1403. +
  1404. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
  1405. +{
  1406. + char *cmd;
  1407. + DIR *dir;
  1408. + int err = 0;
  1409. +
  1410. + setenv ("PATH", ctx->oldpath, 1);
  1411. + free (ctx->oldpath);
  1412. +
  1413. + dir = opendir (ctx->statedir);
  1414. + if (dir) {
  1415. + struct dirent *de;
  1416. + while (de = readdir (dir), de != NULL) {
  1417. + char *path;
  1418. +
  1419. + if (de->d_name[0] == '.')
  1420. + continue;
  1421. +
  1422. + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
  1423. + if (access (path, X_OK) == 0) {
  1424. + if (system (path)) {
  1425. + err = errno;
  1426. + perror (de->d_name);
  1427. + }
  1428. + }
  1429. + free (path);
  1430. + }
  1431. + } else
  1432. + perror (ctx->statedir);
  1433. +
  1434. + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
  1435. + system (cmd);
  1436. + free (cmd);
  1437. +
  1438. + free (ctx->statedir);
  1439. + free (ctx);
  1440. +
  1441. + return err;
  1442. +}
  1443. +
  1444. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
  1445. +{
  1446. + pkg_vec_t *all;
  1447. + int i;
  1448. + pkg_t *pkg;
  1449. + ipkg_intercept_t ic;
  1450. + int r, err = 0;
  1451. +
  1452. + ipkg_message(conf, IPKG_INFO,
  1453. + "Configuring unpacked packages\n");
  1454. + fflush( stdout );
  1455. +
  1456. + all = pkg_vec_alloc();
  1457. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  1458. +
  1459. + ic = ipkg_prep_intercepts();
  1460. +
  1461. + for(i = 0; i < all->len; i++) {
  1462. + pkg = all->pkgs[i];
  1463. +
  1464. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1465. + continue;
  1466. +
  1467. + if (pkg->state_status == SS_UNPACKED) {
  1468. + ipkg_message(conf, IPKG_NOTICE,
  1469. + "Configuring %s\n", pkg->name);
  1470. + fflush( stdout );
  1471. + r = ipkg_configure(conf, pkg);
  1472. + if (r == 0) {
  1473. + pkg->state_status = SS_INSTALLED;
  1474. + pkg->parent->state_status = SS_INSTALLED;
  1475. + pkg->state_flag &= ~SF_PREFER;
  1476. + } else {
  1477. + if (!err)
  1478. + err = r;
  1479. + }
  1480. + }
  1481. + }
  1482. +
  1483. + r = ipkg_finalize_intercepts (ic);
  1484. + if (r && !err)
  1485. + err = r;
  1486. +
  1487. + pkg_vec_free(all);
  1488. + return err;
  1489. +}
  1490. +
  1491. +static void sigint_handler(int sig)
  1492. +{
  1493. + signal(sig, SIG_DFL);
  1494. + ipkg_message(NULL, IPKG_NOTICE,
  1495. + "ipkg: interrupted. writing out status database\n");
  1496. + write_status_files_if_changed(global_conf);
  1497. + exit(128 + sig);
  1498. +}
  1499. +
  1500. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1501. +{
  1502. + int i;
  1503. + char *arg;
  1504. + int err=0;
  1505. +
  1506. + global_conf = conf;
  1507. + signal(SIGINT, sigint_handler);
  1508. +
  1509. + /*
  1510. + * Now scan through package names and install
  1511. + */
  1512. + for (i=0; i < argc; i++) {
  1513. + arg = argv[i];
  1514. +
  1515. + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
  1516. + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
  1517. + if (err != EINVAL && err != 0)
  1518. + return err;
  1519. + }
  1520. + pkg_info_preinstall_check(conf);
  1521. +
  1522. + for (i=0; i < argc; i++) {
  1523. + arg = argv[i];
  1524. + if (conf->multiple_providers)
  1525. + err = ipkg_install_multi_by_name(conf, arg);
  1526. + else{
  1527. + err = ipkg_install_by_name(conf, arg);
  1528. + }
  1529. + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
  1530. + ipkg_message(conf, IPKG_ERROR,
  1531. + "Cannot find package %s.\n"
  1532. + "Check the spelling or perhaps run 'ipkg update'\n",
  1533. + arg);
  1534. + }
  1535. + }
  1536. +
  1537. + /* recheck to verify that all dependences are satisfied */
  1538. + if (0) ipkg_satisfy_all_dependences(conf);
  1539. +
  1540. + ipkg_configure_packages(conf, NULL);
  1541. +
  1542. + write_status_files_if_changed(conf);
  1543. +
  1544. + return err;
  1545. +}
  1546. +
  1547. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1548. +{
  1549. + int i;
  1550. + pkg_t *pkg;
  1551. + int err;
  1552. +
  1553. + global_conf = conf;
  1554. + signal(SIGINT, sigint_handler);
  1555. +
  1556. + if (argc) {
  1557. + for (i=0; i < argc; i++) {
  1558. + char *arg = argv[i];
  1559. +
  1560. + err = ipkg_prepare_url_for_install(conf, arg, &arg);
  1561. + if (err != EINVAL && err != 0)
  1562. + return err;
  1563. + }
  1564. + pkg_info_preinstall_check(conf);
  1565. +
  1566. + for (i=0; i < argc; i++) {
  1567. + char *arg = argv[i];
  1568. + if (conf->restrict_to_default_dest) {
  1569. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1570. + argv[i],
  1571. + conf->default_dest);
  1572. + if (pkg == NULL) {
  1573. + ipkg_message(conf, IPKG_NOTICE,
  1574. + "Package %s not installed in %s\n",
  1575. + argv[i], conf->default_dest->name);
  1576. + continue;
  1577. + }
  1578. + } else {
  1579. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  1580. + argv[i]);
  1581. + }
  1582. + if (pkg)
  1583. + ipkg_upgrade_pkg(conf, pkg);
  1584. + else {
  1585. + ipkg_install_by_name(conf, arg);
  1586. + }
  1587. + }
  1588. + } else {
  1589. + pkg_vec_t *installed = pkg_vec_alloc();
  1590. +
  1591. + pkg_info_preinstall_check(conf);
  1592. +
  1593. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  1594. + for (i = 0; i < installed->len; i++) {
  1595. + pkg = installed->pkgs[i];
  1596. + ipkg_upgrade_pkg(conf, pkg);
  1597. + }
  1598. + pkg_vec_free(installed);
  1599. + }
  1600. +
  1601. + /* recheck to verify that all dependences are satisfied */
  1602. + if (0) ipkg_satisfy_all_dependences(conf);
  1603. +
  1604. + ipkg_configure_packages(conf, NULL);
  1605. +
  1606. + write_status_files_if_changed(conf);
  1607. +
  1608. + return 0;
  1609. +}
  1610. +
  1611. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1612. +{
  1613. + int i, err;
  1614. + char *arg;
  1615. + pkg_t *pkg;
  1616. +
  1617. + pkg_info_preinstall_check(conf);
  1618. + for (i = 0; i < argc; i++) {
  1619. + arg = argv[i];
  1620. +
  1621. + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
  1622. + if (pkg == NULL) {
  1623. + ipkg_message(conf, IPKG_ERROR,
  1624. + "Cannot find package %s.\n"
  1625. + "Check the spelling or perhaps run 'ipkg update'\n",
  1626. + arg);
  1627. + continue;
  1628. + }
  1629. +
  1630. + err = ipkg_download_pkg(conf, pkg, ".");
  1631. +
  1632. + if (err) {
  1633. + ipkg_message(conf, IPKG_ERROR,
  1634. + "Failed to download %s\n", pkg->name);
  1635. + } else {
  1636. + ipkg_message(conf, IPKG_NOTICE,
  1637. + "Downloaded %s as %s\n",
  1638. + pkg->name, pkg->local_filename);
  1639. + }
  1640. + }
  1641. +
  1642. + return 0;
  1643. +}
  1644. +
  1645. +
  1646. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1647. +{
  1648. + int i ;
  1649. + pkg_vec_t *available;
  1650. + pkg_t *pkg;
  1651. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1652. + char *newline;
  1653. + char *pkg_name = NULL;
  1654. + char *version_str;
  1655. +
  1656. + if (argc > 0) {
  1657. + pkg_name = argv[0];
  1658. + }
  1659. + available = pkg_vec_alloc();
  1660. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1661. + for (i=0; i < available->len; i++) {
  1662. + pkg = available->pkgs[i];
  1663. + /* if we have package name or pattern and pkg does not match, then skip it */
  1664. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1665. + continue;
  1666. + if (pkg->description) {
  1667. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1668. + } else {
  1669. + desc_short[0] = '\0';
  1670. + }
  1671. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1672. + newline = strchr(desc_short, '\n');
  1673. + if (newline) {
  1674. + *newline = '\0';
  1675. + }
  1676. +#ifndef IPKG_LIB
  1677. + printf("%s - %s\n", pkg->name, desc_short);
  1678. +#else
  1679. + if (ipkg_cb_list) {
  1680. + version_str = pkg_version_str_alloc(pkg);
  1681. + ipkg_cb_list(pkg->name,desc_short,
  1682. + version_str,
  1683. + pkg->state_status,
  1684. + p_userdata);
  1685. + free(version_str);
  1686. + }
  1687. +#endif
  1688. + }
  1689. + pkg_vec_free(available);
  1690. +
  1691. + return 0;
  1692. +}
  1693. +
  1694. +
  1695. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1696. +{
  1697. + int i ;
  1698. + pkg_vec_t *available;
  1699. + pkg_t *pkg;
  1700. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1701. + char *newline;
  1702. + char *pkg_name = NULL;
  1703. + char *version_str;
  1704. +
  1705. + if (argc > 0) {
  1706. + pkg_name = argv[0];
  1707. + }
  1708. + available = pkg_vec_alloc();
  1709. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1710. + for (i=0; i < available->len; i++) {
  1711. + pkg = available->pkgs[i];
  1712. + /* if we have package name or pattern and pkg does not match, then skip it */
  1713. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1714. + continue;
  1715. + if (pkg->description) {
  1716. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1717. + } else {
  1718. + desc_short[0] = '\0';
  1719. + }
  1720. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1721. + newline = strchr(desc_short, '\n');
  1722. + if (newline) {
  1723. + *newline = '\0';
  1724. + }
  1725. +#ifndef IPKG_LIB
  1726. + printf("%s - %s\n", pkg->name, desc_short);
  1727. +#else
  1728. + if (ipkg_cb_list) {
  1729. + version_str = pkg_version_str_alloc(pkg);
  1730. + ipkg_cb_list(pkg->name,desc_short,
  1731. + version_str,
  1732. + pkg->state_status,
  1733. + p_userdata);
  1734. + free(version_str);
  1735. + }
  1736. +#endif
  1737. + }
  1738. +
  1739. + return 0;
  1740. +}
  1741. +
  1742. +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
  1743. +{
  1744. + int i;
  1745. + pkg_vec_t *available;
  1746. + pkg_t *pkg;
  1747. + char *pkg_name = NULL;
  1748. + char **pkg_fields = NULL;
  1749. + int n_fields = 0;
  1750. + char *buff ; // = (char *)malloc(1);
  1751. +
  1752. + if (argc > 0) {
  1753. + pkg_name = argv[0];
  1754. + }
  1755. + if (argc > 1) {
  1756. + pkg_fields = &argv[1];
  1757. + n_fields = argc - 1;
  1758. + }
  1759. +
  1760. + available = pkg_vec_alloc();
  1761. + if (installed_only)
  1762. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1763. + else
  1764. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1765. + for (i=0; i < available->len; i++) {
  1766. + pkg = available->pkgs[i];
  1767. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1768. + continue;
  1769. + }
  1770. +#ifndef IPKG_LIB
  1771. + if (n_fields) {
  1772. + for (j = 0; j < n_fields; j++)
  1773. + pkg_print_field(pkg, stdout, pkg_fields[j]);
  1774. + } else {
  1775. + pkg_print_info(pkg, stdout);
  1776. + }
  1777. +#else
  1778. +
  1779. + buff = pkg_formatted_info(pkg);
  1780. + if ( buff ) {
  1781. + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
  1782. + pkg->state_status,
  1783. + buff,
  1784. + p_userdata);
  1785. +/*
  1786. + We should not forget that actually the pointer is allocated.
  1787. + We need to free it :) ( Thanks florian for seeing the error )
  1788. +*/
  1789. + free(buff);
  1790. + }
  1791. +#endif
  1792. + if (conf->verbosity > 1) {
  1793. + conffile_list_elt_t *iter;
  1794. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  1795. + conffile_t *cf = iter->data;
  1796. + int modified = conffile_has_been_modified(conf, cf);
  1797. + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
  1798. + cf->name, cf->value, modified);
  1799. + }
  1800. + }
  1801. + }
  1802. +#ifndef IPKG_LIB
  1803. + if (buff)
  1804. + free(buff);
  1805. +#endif
  1806. + pkg_vec_free(available);
  1807. +
  1808. + return 0;
  1809. +}
  1810. +
  1811. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1812. +{
  1813. + return ipkg_info_status_cmd(conf, argc, argv, 0);
  1814. +}
  1815. +
  1816. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1817. +{
  1818. + return ipkg_info_status_cmd(conf, argc, argv, 1);
  1819. +}
  1820. +
  1821. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1822. +{
  1823. +
  1824. + int err;
  1825. + if (argc > 0) {
  1826. + char *pkg_name = NULL;
  1827. +
  1828. + pkg_name = argv[0];
  1829. +
  1830. + err = ipkg_configure_packages (conf, pkg_name);
  1831. +
  1832. + } else {
  1833. + err = ipkg_configure_packages (conf, NULL);
  1834. + }
  1835. +
  1836. + write_status_files_if_changed(conf);
  1837. +
  1838. + return err;
  1839. +}
  1840. +
  1841. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf)
  1842. +{
  1843. + int i, err;
  1844. + char *globpattern;
  1845. + glob_t globbuf;
  1846. +
  1847. + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
  1848. + err = glob(globpattern, 0, NULL, &globbuf);
  1849. + free(globpattern);
  1850. + if (err) {
  1851. + return 0;
  1852. + }
  1853. +
  1854. + ipkg_message(conf, IPKG_NOTICE,
  1855. + "The following packages in %s will now be installed.\n",
  1856. + conf->pending_dir);
  1857. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1858. + ipkg_message(conf, IPKG_NOTICE,
  1859. + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
  1860. + }
  1861. + ipkg_message(conf, IPKG_NOTICE, "\n");
  1862. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1863. + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
  1864. + if (err == 0) {
  1865. + err = unlink(globbuf.gl_pathv[i]);
  1866. + if (err) {
  1867. + ipkg_message(conf, IPKG_ERROR,
  1868. + "%s: ERROR: failed to unlink %s: %s\n",
  1869. + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
  1870. + return err;
  1871. + }
  1872. + }
  1873. + }
  1874. + globfree(&globbuf);
  1875. +
  1876. + return err;
  1877. +}
  1878. +
  1879. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1880. +{
  1881. + int i,a,done;
  1882. + pkg_t *pkg;
  1883. + pkg_t *pkg_to_remove;
  1884. + pkg_vec_t *available;
  1885. + char *pkg_name = NULL;
  1886. + global_conf = conf;
  1887. + signal(SIGINT, sigint_handler);
  1888. +
  1889. +// ENH: Add the "no pkg removed" just in case.
  1890. +
  1891. + done = 0;
  1892. +
  1893. + available = pkg_vec_alloc();
  1894. + pkg_info_preinstall_check(conf);
  1895. + if ( argc > 0 ) {
  1896. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1897. + for (i=0; i < argc; i++) {
  1898. + pkg_name = malloc(strlen(argv[i])+2);
  1899. + strcpy(pkg_name,argv[i]);
  1900. + for (a=0; a < available->len; a++) {
  1901. + pkg = available->pkgs[a];
  1902. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1903. + continue;
  1904. + }
  1905. + if (conf->restrict_to_default_dest) {
  1906. + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1907. + pkg->name,
  1908. + conf->default_dest);
  1909. + } else {
  1910. + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
  1911. + }
  1912. +
  1913. + if (pkg == NULL) {
  1914. + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
  1915. + continue;
  1916. + }
  1917. + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
  1918. + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
  1919. + continue;
  1920. + }
  1921. + ipkg_remove_pkg(conf, pkg_to_remove,0);
  1922. + done = 1;
  1923. + }
  1924. + free (pkg_name);
  1925. + }
  1926. + pkg_vec_free(available);
  1927. + } else {
  1928. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  1929. + int flagged_pkg_count = 0;
  1930. + int removed;
  1931. +
  1932. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
  1933. +
  1934. + for (i = 0; i < installed_pkgs->len; i++) {
  1935. + pkg = installed_pkgs->pkgs[i];
  1936. + if (pkg->state_flag & SF_USER) {
  1937. + flagged_pkg_count++;
  1938. + } else {
  1939. + if (!pkg_has_installed_dependents(pkg, NULL))
  1940. + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
  1941. + }
  1942. + }
  1943. + if (!flagged_pkg_count) {
  1944. + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
  1945. + "so refusing to uninstall unflagged non-leaf packages\n");
  1946. + return 0;
  1947. + }
  1948. +
  1949. + /* find packages not flagged SF_USER (i.e., installed to
  1950. + * satisfy a dependence) and not having any dependents, and
  1951. + * remove them */
  1952. + do {
  1953. + removed = 0;
  1954. + for (i = 0; i < installed_pkgs->len; i++) {
  1955. + pkg = installed_pkgs->pkgs[i];
  1956. + if (!(pkg->state_flag & SF_USER)
  1957. + && !pkg_has_installed_dependents(pkg, NULL)) {
  1958. + removed++;
  1959. + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
  1960. + ipkg_remove_pkg(conf, pkg,0);
  1961. + done = 1;
  1962. + }
  1963. + }
  1964. + } while (removed);
  1965. + pkg_vec_free(installed_pkgs);
  1966. + }
  1967. +
  1968. + if ( done == 0 )
  1969. + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
  1970. +
  1971. + write_status_files_if_changed(conf);
  1972. + return 0;
  1973. +}
  1974. +
  1975. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1976. +{
  1977. + int i;
  1978. + pkg_t *pkg;
  1979. +
  1980. + global_conf = conf;
  1981. + signal(SIGINT, sigint_handler);
  1982. +
  1983. + pkg_info_preinstall_check(conf);
  1984. +
  1985. + for (i=0; i < argc; i++) {
  1986. + if (conf->restrict_to_default_dest) {
  1987. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1988. + argv[i],
  1989. + conf->default_dest);
  1990. + } else {
  1991. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1992. + }
  1993. +
  1994. + if (pkg == NULL) {
  1995. + ipkg_message(conf, IPKG_ERROR,
  1996. + "Package %s is not installed.\n", argv[i]);
  1997. + continue;
  1998. + }
  1999. + ipkg_purge_pkg(conf, pkg);
  2000. + }
  2001. +
  2002. + write_status_files_if_changed(conf);
  2003. + return 0;
  2004. +}
  2005. +
  2006. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2007. +{
  2008. + int i;
  2009. + pkg_t *pkg;
  2010. + char *flags = argv[0];
  2011. +
  2012. + global_conf = conf;
  2013. + signal(SIGINT, sigint_handler);
  2014. +
  2015. + for (i=1; i < argc; i++) {
  2016. + if (conf->restrict_to_default_dest) {
  2017. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  2018. + argv[i],
  2019. + conf->default_dest);
  2020. + } else {
  2021. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  2022. + }
  2023. +
  2024. + if (pkg == NULL) {
  2025. + ipkg_message(conf, IPKG_ERROR,
  2026. + "Package %s is not installed.\n", argv[i]);
  2027. + continue;
  2028. + }
  2029. + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
  2030. + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
  2031. + pkg->state_flag = pkg_state_flag_from_str(flags);
  2032. + }
  2033. +/* pb_ asked this feature 03292004 */
  2034. +/* Actually I will use only this two, but this is an open for various status */
  2035. + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
  2036. + pkg->state_status = pkg_state_status_from_str(flags);
  2037. + }
  2038. + ipkg_state_changed++;
  2039. + ipkg_message(conf, IPKG_NOTICE,
  2040. + "Setting flags for package %s to %s\n",
  2041. + pkg->name, flags);
  2042. + }
  2043. +
  2044. + write_status_files_if_changed(conf);
  2045. + return 0;
  2046. +}
  2047. +
  2048. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2049. +{
  2050. + pkg_t *pkg;
  2051. + str_list_t *installed_files;
  2052. + str_list_elt_t *iter;
  2053. + char *pkg_version;
  2054. + size_t buff_len = 8192;
  2055. + size_t used_len;
  2056. + char *buff ;
  2057. +
  2058. + buff = (char *)malloc(buff_len);
  2059. + if ( buff == NULL ) {
  2060. + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
  2061. + return ENOMEM;
  2062. + }
  2063. +
  2064. + if (argc < 1) {
  2065. + return EINVAL;
  2066. + }
  2067. +
  2068. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  2069. + argv[0]);
  2070. + if (pkg == NULL) {
  2071. + ipkg_message(conf, IPKG_ERROR,
  2072. + "Package %s not installed.\n", argv[0]);
  2073. + return 0;
  2074. + }
  2075. +
  2076. + installed_files = pkg_get_installed_files(pkg);
  2077. + pkg_version = pkg_version_str_alloc(pkg);
  2078. +
  2079. +#ifndef IPKG_LIB
  2080. + printf("Package %s (%s) is installed on %s and has the following files:\n",
  2081. + pkg->name, pkg_version, pkg->dest->name);
  2082. + for (iter = installed_files->head; iter; iter = iter->next) {
  2083. + puts(iter->data);
  2084. + }
  2085. +#else
  2086. + if (buff) {
  2087. + try_again:
  2088. + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
  2089. + pkg->name, pkg_version, pkg->dest->name) + 1;
  2090. + if (used_len > buff_len) {
  2091. + buff_len *= 2;
  2092. + buff = realloc (buff, buff_len);
  2093. + goto try_again;
  2094. + }
  2095. + for (iter = installed_files->head; iter; iter = iter->next) {
  2096. + used_len += strlen (iter->data) + 1;
  2097. + while (buff_len <= used_len) {
  2098. + buff_len *= 2;
  2099. + buff = realloc (buff, buff_len);
  2100. + }
  2101. + strncat(buff, iter->data, buff_len);
  2102. + strncat(buff, "\n", buff_len);
  2103. + }
  2104. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2105. + buff,
  2106. + pkg_version_str_alloc(pkg),
  2107. + pkg->state_status,
  2108. + p_userdata);
  2109. + free(buff);
  2110. + }
  2111. +#endif
  2112. +
  2113. + free(pkg_version);
  2114. + pkg_free_installed_files(pkg);
  2115. +
  2116. + return 0;
  2117. +}
  2118. +
  2119. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2120. +{
  2121. +
  2122. + if (argc > 0) {
  2123. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2124. + const char *rel_str = "depends on";
  2125. + int i;
  2126. +
  2127. + pkg_info_preinstall_check(conf);
  2128. +
  2129. + if (conf->query_all)
  2130. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2131. + else
  2132. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2133. + for (i = 0; i < argc; i++) {
  2134. + const char *target = argv[i];
  2135. + int j;
  2136. +
  2137. + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
  2138. +
  2139. + for (j = 0; j < available_pkgs->len; j++) {
  2140. + pkg_t *pkg = available_pkgs->pkgs[j];
  2141. + if (fnmatch(target, pkg->name, 0) == 0) {
  2142. + int k;
  2143. + int count = pkg->depends_count + pkg->pre_depends_count;
  2144. + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
  2145. + target, pkg->architecture, rel_str);
  2146. + for (k = 0; k < count; k++) {
  2147. + compound_depend_t *cdepend = &pkg->depends[k];
  2148. + int l;
  2149. + for (l = 0; l < cdepend->possibility_count; l++) {
  2150. + depend_t *possibility = cdepend->possibilities[l];
  2151. + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
  2152. + if (conf->verbosity > 0) {
  2153. + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
  2154. + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
  2155. + if (possibility->version) {
  2156. + const char *typestr = NULL;
  2157. + switch (possibility->constraint) {
  2158. + case NONE: typestr = "none"; break;
  2159. + case EARLIER: typestr = "<"; break;
  2160. + case EARLIER_EQUAL: typestr = "<="; break;
  2161. + case EQUAL: typestr = "="; break;
  2162. + case LATER_EQUAL: typestr = ">="; break;
  2163. + case LATER: typestr = ">"; break;
  2164. + }
  2165. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2166. + }
  2167. + // free(ver);
  2168. + }
  2169. + ipkg_message(conf, IPKG_ERROR, "\n");
  2170. + }
  2171. + }
  2172. + }
  2173. + }
  2174. + }
  2175. + pkg_vec_free(available_pkgs);
  2176. + }
  2177. + return 0;
  2178. +}
  2179. +
  2180. +enum what_field_type {
  2181. + WHATDEPENDS,
  2182. + WHATCONFLICTS,
  2183. + WHATPROVIDES,
  2184. + WHATREPLACES,
  2185. + WHATRECOMMENDS,
  2186. + WHATSUGGESTS
  2187. +};
  2188. +
  2189. +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
  2190. +{
  2191. +
  2192. + if (argc > 0) {
  2193. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2194. + const char *rel_str = NULL;
  2195. + int i;
  2196. + int changed;
  2197. +
  2198. + switch (what_field_type) {
  2199. + case WHATDEPENDS: rel_str = "depends on"; break;
  2200. + case WHATCONFLICTS: rel_str = "conflicts with"; break;
  2201. + case WHATSUGGESTS: rel_str = "suggests"; break;
  2202. + case WHATRECOMMENDS: rel_str = "recommends"; break;
  2203. + case WHATPROVIDES: rel_str = "provides"; break;
  2204. + case WHATREPLACES: rel_str = "replaces"; break;
  2205. + }
  2206. +
  2207. + if (conf->query_all)
  2208. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2209. + else
  2210. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2211. +
  2212. + /* mark the root set */
  2213. + pkg_vec_clear_marks(available_pkgs);
  2214. + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
  2215. + for (i = 0; i < argc; i++) {
  2216. + const char *dependee_pattern = argv[i];
  2217. + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
  2218. + }
  2219. + for (i = 0; i < available_pkgs->len; i++) {
  2220. + pkg_t *pkg = available_pkgs->pkgs[i];
  2221. + if (pkg->state_flag & SF_MARKED) {
  2222. + /* mark the parent (abstract) package */
  2223. + pkg_mark_provides(pkg);
  2224. + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
  2225. + }
  2226. + }
  2227. +
  2228. + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
  2229. + do {
  2230. + int j;
  2231. + changed = 0;
  2232. +
  2233. + for (j = 0; j < available_pkgs->len; j++) {
  2234. + pkg_t *pkg = available_pkgs->pkgs[j];
  2235. + int k;
  2236. + int count = ((what_field_type == WHATCONFLICTS)
  2237. + ? pkg->conflicts_count
  2238. + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
  2239. + /* skip this package if it is already marked */
  2240. + if (pkg->parent->state_flag & SF_MARKED) {
  2241. + continue;
  2242. + }
  2243. + for (k = 0; k < count; k++) {
  2244. + compound_depend_t *cdepend =
  2245. + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
  2246. + int l;
  2247. + for (l = 0; l < cdepend->possibility_count; l++) {
  2248. + depend_t *possibility = cdepend->possibilities[l];
  2249. + if (possibility->pkg->state_flag & SF_MARKED) {
  2250. + /* mark the depending package so we won't visit it again */
  2251. + pkg->state_flag |= SF_MARKED;
  2252. + pkg_mark_provides(pkg);
  2253. + changed++;
  2254. +
  2255. + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
  2256. + if (conf->verbosity > 0) {
  2257. + char *ver = pkg_version_str_alloc(pkg);
  2258. + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
  2259. + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
  2260. + if (possibility->version) {
  2261. + const char *typestr = NULL;
  2262. + switch (possibility->constraint) {
  2263. + case NONE: typestr = "none"; break;
  2264. + case EARLIER: typestr = "<"; break;
  2265. + case EARLIER_EQUAL: typestr = "<="; break;
  2266. + case EQUAL: typestr = "="; break;
  2267. + case LATER_EQUAL: typestr = ">="; break;
  2268. + case LATER: typestr = ">"; break;
  2269. + }
  2270. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2271. + }
  2272. + free(ver);
  2273. + if (!pkg_dependence_satisfiable(possibility))
  2274. + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
  2275. + }
  2276. + ipkg_message(conf, IPKG_NOTICE, "\n");
  2277. + goto next_package;
  2278. + }
  2279. + }
  2280. + }
  2281. + next_package:
  2282. + ;
  2283. + }
  2284. + } while (changed && recursive);
  2285. + pkg_vec_free(available_pkgs);
  2286. + }
  2287. +
  2288. + return 0;
  2289. +}
  2290. +
  2291. +int pkg_mark_provides(pkg_t *pkg)
  2292. +{
  2293. + int provides_count = pkg->provides_count;
  2294. + abstract_pkg_t **provides = pkg->provides;
  2295. + int i;
  2296. + pkg->parent->state_flag |= SF_MARKED;
  2297. + for (i = 0; i < provides_count; i++) {
  2298. + provides[i]->state_flag |= SF_MARKED;
  2299. + }
  2300. + return 0;
  2301. +}
  2302. +
  2303. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2304. +{
  2305. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
  2306. +}
  2307. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2308. +{
  2309. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
  2310. +}
  2311. +
  2312. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2313. +{
  2314. + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
  2315. +}
  2316. +
  2317. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2318. +{
  2319. + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
  2320. +}
  2321. +
  2322. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2323. +{
  2324. + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
  2325. +}
  2326. +
  2327. +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
  2328. +{
  2329. +
  2330. + if (argc > 0) {
  2331. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2332. + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
  2333. + int i;
  2334. +
  2335. + pkg_info_preinstall_check(conf);
  2336. +
  2337. + if (conf->query_all)
  2338. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2339. + else
  2340. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2341. + for (i = 0; i < argc; i++) {
  2342. + const char *target = argv[i];
  2343. + int j;
  2344. +
  2345. + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
  2346. + rel_str, target);
  2347. + for (j = 0; j < available_pkgs->len; j++) {
  2348. + pkg_t *pkg = available_pkgs->pkgs[j];
  2349. + int k;
  2350. + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
  2351. + for (k = 0; k < count; k++) {
  2352. + abstract_pkg_t *apkg =
  2353. + ((what_field_type == WHATPROVIDES)
  2354. + ? pkg->provides[k]
  2355. + : pkg->replaces[k]);
  2356. + if (fnmatch(target, apkg->name, 0) == 0) {
  2357. + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
  2358. + if (strcmp(target, apkg->name) != 0)
  2359. + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
  2360. + ipkg_message(conf, IPKG_ERROR, "\n");
  2361. + }
  2362. + }
  2363. + }
  2364. + }
  2365. + pkg_vec_free(available_pkgs);
  2366. + }
  2367. + return 0;
  2368. +}
  2369. +
  2370. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2371. +{
  2372. + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
  2373. +}
  2374. +
  2375. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2376. +{
  2377. + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
  2378. +}
  2379. +
  2380. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2381. +{
  2382. + int i;
  2383. +
  2384. + pkg_vec_t *installed;
  2385. + pkg_t *pkg;
  2386. + str_list_t *installed_files;
  2387. + str_list_elt_t *iter;
  2388. + char *installed_file;
  2389. +
  2390. + if (argc < 1) {
  2391. + return EINVAL;
  2392. + }
  2393. +
  2394. + installed = pkg_vec_alloc();
  2395. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  2396. +
  2397. + for (i=0; i < installed->len; i++) {
  2398. + pkg = installed->pkgs[i];
  2399. +
  2400. + installed_files = pkg_get_installed_files(pkg);
  2401. +
  2402. + for (iter = installed_files->head; iter; iter = iter->next) {
  2403. + installed_file = iter->data;
  2404. + if (fnmatch(argv[0], installed_file, 0)==0) {
  2405. +#ifndef IPKG_LIB
  2406. + printf("%s: %s\n", pkg->name, installed_file);
  2407. +#else
  2408. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2409. + installed_file,
  2410. + pkg_version_str_alloc(pkg),
  2411. + pkg->state_status, p_userdata);
  2412. +#endif
  2413. + }
  2414. + }
  2415. +
  2416. + pkg_free_installed_files(pkg);
  2417. + }
  2418. +
  2419. + /* XXX: CLEANUP: It's not obvious from the name of
  2420. + pkg_hash_fetch_all_installed that we need to call
  2421. + pkg_vec_free to avoid a memory leak. */
  2422. + pkg_vec_free(installed);
  2423. +
  2424. + return 0;
  2425. +}
  2426. +
  2427. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2428. +{
  2429. + if (argc == 3) {
  2430. + /* this is a bit gross */
  2431. + struct pkg p1, p2;
  2432. + parseVersion(&p1, argv[0]);
  2433. + parseVersion(&p2, argv[2]);
  2434. + return pkg_version_satisfied(&p1, &p2, argv[1]);
  2435. + } else {
  2436. + ipkg_message(conf, IPKG_ERROR,
  2437. + "ipkg compare_versions <v1> <op> <v2>\n"
  2438. + "<op> is one of <= >= << >> =\n");
  2439. + return -1;
  2440. + }
  2441. +}
  2442. +
  2443. +#ifndef HOST_CPU_STR
  2444. +#define HOST_CPU_STR__(X) #X
  2445. +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
  2446. +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
  2447. +#endif
  2448. +
  2449. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf)
  2450. +{
  2451. + nv_pair_list_elt_t *l;
  2452. +
  2453. + l = conf->arch_list.head;
  2454. + while (l) {
  2455. + nv_pair_t *nv = l->data;
  2456. + printf("arch %s %s\n", nv->name, nv->value);
  2457. + l = l->next;
  2458. + }
  2459. + return 0;
  2460. +}
  2461. +
  2462. +
  2463. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_cmd.h busybox-1.15.2/archival/libipkg/ipkg_cmd.h
  2464. --- busybox-1.15.2.orig/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
  2465. +++ busybox-1.15.2/archival/libipkg/ipkg_cmd.h 2009-11-26 11:10:13.403858760 +0100
  2466. @@ -0,0 +1,46 @@
  2467. +/* ipkg_cmd.h - the itsy package management system
  2468. +
  2469. + Carl D. Worth
  2470. +
  2471. + Copyright (C) 2001 University of Southern California
  2472. +
  2473. + This program is free software; you can redistribute it and/or
  2474. + modify it under the terms of the GNU General Public License as
  2475. + published by the Free Software Foundation; either version 2, or (at
  2476. + your option) any later version.
  2477. +
  2478. + This program is distributed in the hope that it will be useful, but
  2479. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2480. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2481. + General Public License for more details.
  2482. +*/
  2483. +
  2484. +#ifndef IPKG_CMD_H
  2485. +#define IPKG_CMD_H
  2486. +
  2487. +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
  2488. +
  2489. +struct ipkg_cmd
  2490. +{
  2491. + const char *name;
  2492. + int requires_args;
  2493. + ipkg_cmd_fun_t fun;
  2494. +};
  2495. +typedef struct ipkg_cmd ipkg_cmd_t;
  2496. +
  2497. +ipkg_cmd_t *ipkg_cmd_find(const char *name);
  2498. +#ifdef IPKG_LIB
  2499. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
  2500. + const char **argv, void *userdata);
  2501. +#else
  2502. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv);
  2503. +#endif
  2504. +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
  2505. +/* install any packges with state_want == SW_INSTALL */
  2506. +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
  2507. +/* ensure that all dependences are satisfied */
  2508. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
  2509. +
  2510. +int pkg_mark_provides(pkg_t *pkg);
  2511. +
  2512. +#endif
  2513. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_conf.c busybox-1.15.2/archival/libipkg/ipkg_conf.c
  2514. --- busybox-1.15.2.orig/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
  2515. +++ busybox-1.15.2/archival/libipkg/ipkg_conf.c 2009-11-26 11:10:13.459858355 +0100
  2516. @@ -0,0 +1,711 @@
  2517. +/* ipkg_conf.c - the itsy package management system
  2518. +
  2519. + Carl D. Worth
  2520. +
  2521. + Copyright (C) 2001 University of Southern California
  2522. +
  2523. + This program is free software; you can redistribute it and/or
  2524. + modify it under the terms of the GNU General Public License as
  2525. + published by the Free Software Foundation; either version 2, or (at
  2526. + your option) any later version.
  2527. +
  2528. + This program is distributed in the hope that it will be useful, but
  2529. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2530. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2531. + General Public License for more details.
  2532. +*/
  2533. +
  2534. +#include <glob.h>
  2535. +
  2536. +#include "ipkg.h"
  2537. +#include "ipkg_conf.h"
  2538. +
  2539. +#include "xregex.h"
  2540. +#include "sprintf_alloc.h"
  2541. +#include "ipkg_conf.h"
  2542. +#include "ipkg_message.h"
  2543. +#include "file_util.h"
  2544. +#include "str_util.h"
  2545. +#include "xsystem.h"
  2546. +
  2547. +
  2548. +ipkg_conf_t *global_conf;
  2549. +
  2550. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2551. + pkg_src_list_t *pkg_src_list,
  2552. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2553. + char **tmp_lists_dir);
  2554. +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
  2555. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  2556. + const char *name, const char *value);
  2557. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2558. + const char *default_dest_name);
  2559. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
  2560. + pkg_src_list_t *nv_pair_list);
  2561. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
  2562. + nv_pair_list_t *nv_pair_list, char * lists_dir);
  2563. +
  2564. +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
  2565. +{
  2566. + ipkg_option_t tmp[] = {
  2567. + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
  2568. + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
  2569. + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
  2570. + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
  2571. + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
  2572. + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
  2573. + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
  2574. + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
  2575. + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
  2576. + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
  2577. + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
  2578. + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
  2579. + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
  2580. + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
  2581. + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
  2582. + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
  2583. + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
  2584. + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
  2585. + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
  2586. + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
  2587. + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
  2588. + { NULL }
  2589. + };
  2590. +
  2591. + *options = (ipkg_option_t *)malloc(sizeof(tmp));
  2592. + if ( options == NULL ){
  2593. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  2594. + return -1;
  2595. + }
  2596. +
  2597. + memcpy(*options, tmp, sizeof(tmp));
  2598. + return 0;
  2599. +};
  2600. +
  2601. +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
  2602. +{
  2603. + if (arg_str) {
  2604. + if (*conf_str) {
  2605. + free(*conf_str);
  2606. + }
  2607. + *conf_str = strdup(arg_str);
  2608. + }
  2609. +}
  2610. +
  2611. +static void ipkg_conf_free_string(char **conf_str)
  2612. +{
  2613. + if (*conf_str) {
  2614. + free(*conf_str);
  2615. + *conf_str = NULL;
  2616. + }
  2617. +}
  2618. +
  2619. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
  2620. +{
  2621. + int err;
  2622. + char *tmp_dir_base;
  2623. + nv_pair_list_t tmp_dest_nv_pair_list;
  2624. + char * lists_dir =NULL;
  2625. + glob_t globbuf;
  2626. + const char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
  2627. + char *pending_dir =NULL;
  2628. +
  2629. + memset(conf, 0, sizeof(ipkg_conf_t));
  2630. +
  2631. + pkg_src_list_init(&conf->pkg_src_list);
  2632. +
  2633. + nv_pair_list_init(&tmp_dest_nv_pair_list);
  2634. + pkg_dest_list_init(&conf->pkg_dest_list);
  2635. +
  2636. + nv_pair_list_init(&conf->arch_list);
  2637. +
  2638. + conf->restrict_to_default_dest = 0;
  2639. + conf->default_dest = NULL;
  2640. +
  2641. +
  2642. + if (args->tmp_dir)
  2643. + tmp_dir_base = args->tmp_dir;
  2644. + else
  2645. + tmp_dir_base = getenv("TMPDIR");
  2646. + sprintf_alloc(&conf->tmp_dir, "%s/%s",
  2647. + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
  2648. + IPKG_CONF_TMP_DIR_SUFFIX);
  2649. + conf->tmp_dir = mkdtemp(conf->tmp_dir);
  2650. + if (conf->tmp_dir == NULL) {
  2651. + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
  2652. + __FUNCTION__, conf->tmp_dir, strerror(errno));
  2653. + return errno;
  2654. + }
  2655. +
  2656. + conf->force_depends = 0;
  2657. + conf->force_defaults = 0;
  2658. + conf->force_overwrite = 0;
  2659. + conf->force_downgrade = 0;
  2660. + conf->force_reinstall = 0;
  2661. + conf->force_space = 0;
  2662. + conf->force_removal_of_essential_packages = 0;
  2663. + conf->force_removal_of_dependent_packages = 0;
  2664. + conf->nodeps = 0;
  2665. + conf->verbose_wget = 0;
  2666. + conf->offline_root = NULL;
  2667. + conf->offline_root_pre_script_cmd = NULL;
  2668. + conf->offline_root_post_script_cmd = NULL;
  2669. + conf->multiple_providers = 0;
  2670. + conf->verbosity = 1;
  2671. + conf->noaction = 0;
  2672. +
  2673. + conf->http_proxy = NULL;
  2674. + conf->ftp_proxy = NULL;
  2675. + conf->no_proxy = NULL;
  2676. + conf->proxy_user = NULL;
  2677. + conf->proxy_passwd = NULL;
  2678. +
  2679. + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2680. + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2681. + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2682. + lists_dir=(char *)malloc(1);
  2683. + lists_dir[0]='\0';
  2684. + if (args->conf_file) {
  2685. + struct stat stat_buf;
  2686. + err = stat(args->conf_file, &stat_buf);
  2687. + if (err == 0)
  2688. + if (ipkg_conf_parse_file(conf, args->conf_file,
  2689. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2690. + /* Memory leakage from ipkg_conf_parse-file */
  2691. + return -1;
  2692. + }
  2693. +
  2694. + }
  2695. +
  2696. + /* if (!lists_dir ){*/
  2697. + if (strlen(lists_dir)<=1 ){
  2698. + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
  2699. + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
  2700. + }
  2701. +
  2702. + if (args->offline_root) {
  2703. + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
  2704. + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
  2705. + free(lists_dir);
  2706. + lists_dir = tmp;
  2707. + }
  2708. +
  2709. + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
  2710. + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
  2711. +
  2712. + conf->lists_dir = strdup(lists_dir);
  2713. + conf->pending_dir = strdup(pending_dir);
  2714. +
  2715. + if (args->offline_root)
  2716. + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
  2717. + memset(&globbuf, 0, sizeof(globbuf));
  2718. + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
  2719. + if (!err) {
  2720. + int i;
  2721. + for (i = 0; i < globbuf.gl_pathc; i++) {
  2722. + if (globbuf.gl_pathv[i])
  2723. + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
  2724. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2725. + /* Memory leakage from ipkg_conf_parse-file */
  2726. + return -1;
  2727. + }
  2728. + }
  2729. + }
  2730. + globfree(&globbuf);
  2731. +
  2732. + /* if no architectures were defined, then default all, noarch, and host architecture */
  2733. + if (nv_pair_list_empty(&conf->arch_list)) {
  2734. + nv_pair_list_append(&conf->arch_list, "all", "1");
  2735. + nv_pair_list_append(&conf->arch_list, "noarch", "1");
  2736. + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
  2737. + }
  2738. +
  2739. + /* Even if there is no conf file, we'll need at least one dest. */
  2740. + if (tmp_dest_nv_pair_list.head == NULL) {
  2741. + nv_pair_list_append(&tmp_dest_nv_pair_list,
  2742. + IPKG_CONF_DEFAULT_DEST_NAME,
  2743. + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
  2744. + }
  2745. +
  2746. + /* After parsing the file, set options from command-line, (so that
  2747. + command-line arguments take precedence) */
  2748. + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
  2749. + really needs to be cleaned up. There is so much duplication
  2750. + right now it is ridiculous. Maybe ipkg_conf_t should just save
  2751. + a pointer to args_t (which could then not be freed), rather
  2752. + than duplicating every field here? */
  2753. + if (args->force_depends) {
  2754. + conf->force_depends = 1;
  2755. + }
  2756. + if (args->force_defaults) {
  2757. + conf->force_defaults = 1;
  2758. + }
  2759. + if (args->force_overwrite) {
  2760. + conf->force_overwrite = 1;
  2761. + }
  2762. + if (args->force_downgrade) {
  2763. + conf->force_downgrade = 1;
  2764. + }
  2765. + if (args->force_reinstall) {
  2766. + conf->force_reinstall = 1;
  2767. + }
  2768. + if (args->force_removal_of_dependent_packages) {
  2769. + conf->force_removal_of_dependent_packages = 1;
  2770. + }
  2771. + if (args->force_removal_of_essential_packages) {
  2772. + conf->force_removal_of_essential_packages = 1;
  2773. + }
  2774. + if (args->nodeps) {
  2775. + conf->nodeps = 1;
  2776. + }
  2777. + if (args->noaction) {
  2778. + conf->noaction = 1;
  2779. + }
  2780. + if (args->query_all) {
  2781. + conf->query_all = 1;
  2782. + }
  2783. + if (args->verbose_wget) {
  2784. + conf->verbose_wget = 1;
  2785. + }
  2786. + if (args->multiple_providers) {
  2787. + conf->multiple_providers = 1;
  2788. + }
  2789. + if (args->verbosity != conf->verbosity) {
  2790. + conf->verbosity = args->verbosity;
  2791. + }
  2792. +
  2793. + ipkg_conf_override_string(&conf->offline_root,
  2794. + args->offline_root);
  2795. + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
  2796. + args->offline_root_pre_script_cmd);
  2797. + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
  2798. + args->offline_root_post_script_cmd);
  2799. +
  2800. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  2801. + read anything from there.
  2802. +*/
  2803. + if ( !(args->nocheckfordirorfile)){
  2804. + /* need to run load the source list before dest list -Jamey */
  2805. + if ( !(args->noreadfeedsfile))
  2806. + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
  2807. +
  2808. + /* Now that we have resolved conf->offline_root, we can commit to
  2809. + the directory names for the dests and load in all the package
  2810. + lists. */
  2811. + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
  2812. +
  2813. + if (args->dest) {
  2814. + err = ipkg_conf_set_default_dest(conf, args->dest);
  2815. + if (err) {
  2816. + return err;
  2817. + }
  2818. + }
  2819. + }
  2820. + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
  2821. + free(lists_dir);
  2822. + free(pending_dir);
  2823. +
  2824. + return 0;
  2825. +}
  2826. +
  2827. +void ipkg_conf_deinit(ipkg_conf_t *conf)
  2828. +{
  2829. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  2830. +#error
  2831. + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
  2832. + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  2833. + __FUNCTION__, conf->tmp_dir);
  2834. +#else
  2835. + int err;
  2836. +
  2837. + err = rmdir(conf->tmp_dir);
  2838. + if (err) {
  2839. + if (errno == ENOTEMPTY) {
  2840. + char *cmd;
  2841. + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
  2842. + err = xsystem(cmd);
  2843. + free(cmd);
  2844. + }
  2845. + if (err)
  2846. + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
  2847. + }
  2848. +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
  2849. +
  2850. + free(conf->tmp_dir); /*XXX*/
  2851. +
  2852. + pkg_src_list_deinit(&conf->pkg_src_list);
  2853. + pkg_dest_list_deinit(&conf->pkg_dest_list);
  2854. + nv_pair_list_deinit(&conf->arch_list);
  2855. + if (&conf->pkg_hash)
  2856. + pkg_hash_deinit(&conf->pkg_hash);
  2857. + if (&conf->file_hash)
  2858. + hash_table_deinit(&conf->file_hash);
  2859. + if (&conf->obs_file_hash)
  2860. + hash_table_deinit(&conf->obs_file_hash);
  2861. +
  2862. + ipkg_conf_free_string(&conf->offline_root);
  2863. + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
  2864. + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
  2865. +
  2866. + if (conf->verbosity > 1) {
  2867. + int i;
  2868. + hash_table_t *hashes[] = {
  2869. + &conf->pkg_hash,
  2870. + &conf->file_hash,
  2871. + &conf->obs_file_hash };
  2872. + for (i = 0; i < 3; i++) {
  2873. + hash_table_t *hash = hashes[i];
  2874. + int c = 0;
  2875. + int n_conflicts = 0;
  2876. + int j;
  2877. + for (j = 0; j < hash->n_entries; j++) {
  2878. + int len = 0;
  2879. + hash_entry_t *e = &hash->entries[j];
  2880. + if (e->next)
  2881. + n_conflicts++;
  2882. + while (e && e->key) {
  2883. + len++;
  2884. + e = e->next;
  2885. + }
  2886. + if (len > c)
  2887. + c = len;
  2888. + }
  2889. + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
  2890. + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
  2891. + hash_table_deinit(hash);
  2892. + }
  2893. + }
  2894. +}
  2895. +
  2896. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2897. + const char *default_dest_name)
  2898. +{
  2899. + pkg_dest_list_elt_t *iter;
  2900. + pkg_dest_t *dest;
  2901. +
  2902. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  2903. + dest = iter->data;
  2904. + if (strcmp(dest->name, default_dest_name) == 0) {
  2905. + conf->default_dest = dest;
  2906. + conf->restrict_to_default_dest = 1;
  2907. + return 0;
  2908. + }
  2909. + }
  2910. +
  2911. + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
  2912. +
  2913. + return 1;
  2914. +}
  2915. +
  2916. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
  2917. +{
  2918. + pkg_src_list_elt_t *iter;
  2919. + pkg_src_t *src;
  2920. + char *list_file;
  2921. +
  2922. + for (iter = pkg_src_list->head; iter; iter = iter->next) {
  2923. + src = iter->data;
  2924. + if (src == NULL) {
  2925. + continue;
  2926. + }
  2927. +
  2928. + sprintf_alloc(&list_file, "%s/%s",
  2929. + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
  2930. + src->name);
  2931. +
  2932. + if (file_exists(list_file)) {
  2933. + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
  2934. + }
  2935. + free(list_file);
  2936. + }
  2937. +
  2938. + return 0;
  2939. +}
  2940. +
  2941. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
  2942. +{
  2943. + nv_pair_list_elt_t *iter;
  2944. + nv_pair_t *nv_pair;
  2945. + pkg_dest_t *dest;
  2946. + char *root_dir;
  2947. +
  2948. + for (iter = nv_pair_list->head; iter; iter = iter->next) {
  2949. + nv_pair = iter->data;
  2950. +
  2951. + if (conf->offline_root) {
  2952. + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
  2953. + } else {
  2954. + root_dir = strdup(nv_pair->value);
  2955. + }
  2956. + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
  2957. + free(root_dir);
  2958. + if (dest == NULL) {
  2959. + continue;
  2960. + }
  2961. + if (conf->default_dest == NULL) {
  2962. + conf->default_dest = dest;
  2963. + }
  2964. + if (file_exists(dest->status_file_name)) {
  2965. + pkg_hash_add_from_file(conf, dest->status_file_name,
  2966. + NULL, dest, 1);
  2967. + }
  2968. + }
  2969. +
  2970. + return 0;
  2971. +}
  2972. +
  2973. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2974. + pkg_src_list_t *pkg_src_list,
  2975. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2976. + char **lists_dir)
  2977. +{
  2978. + ipkg_option_t * options;
  2979. + FILE *file = fopen(filename, "r");
  2980. + regex_t valid_line_re, comment_re;
  2981. +#define regmatch_size 12
  2982. + regmatch_t regmatch[regmatch_size];
  2983. +
  2984. + if (ipkg_init_options_array(conf, &options)<0)
  2985. + return ENOMEM;
  2986. +
  2987. + if (file == NULL) {
  2988. + fprintf(stderr, "%s: failed to open %s: %s\n",
  2989. + __FUNCTION__, filename, strerror(errno));
  2990. + free(options);
  2991. + return errno;
  2992. + }
  2993. + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
  2994. +
  2995. + xregcomp(&comment_re,
  2996. + "^[[:space:]]*(#.*|[[:space:]]*)$",
  2997. + REG_EXTENDED);
  2998. + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
  2999. +
  3000. + while(1) {
  3001. + int line_num = 0;
  3002. + char *line;
  3003. + char *type, *name, *value, *extra;
  3004. +
  3005. + line = file_read_line_alloc(file);
  3006. + line_num++;
  3007. + if (line == NULL) {
  3008. + break;
  3009. + }
  3010. +
  3011. + str_chomp(line);
  3012. +
  3013. + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
  3014. + goto NEXT_LINE;
  3015. + }
  3016. +
  3017. + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
  3018. + str_chomp(line);
  3019. + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
  3020. + filename, line_num, line);
  3021. + goto NEXT_LINE;
  3022. + }
  3023. +
  3024. + /* This has to be so ugly to deal with optional quotation marks */
  3025. + if (regmatch[2].rm_so > 0) {
  3026. + type = strndup(line + regmatch[2].rm_so,
  3027. + regmatch[2].rm_eo - regmatch[2].rm_so);
  3028. + } else {
  3029. + type = strndup(line + regmatch[3].rm_so,
  3030. + regmatch[3].rm_eo - regmatch[3].rm_so);
  3031. + }
  3032. + if (regmatch[5].rm_so > 0) {
  3033. + name = strndup(line + regmatch[5].rm_so,
  3034. + regmatch[5].rm_eo - regmatch[5].rm_so);
  3035. + } else {
  3036. + name = strndup(line + regmatch[6].rm_so,
  3037. + regmatch[6].rm_eo - regmatch[6].rm_so);
  3038. + }
  3039. + if (regmatch[8].rm_so > 0) {
  3040. + value = strndup(line + regmatch[8].rm_so,
  3041. + regmatch[8].rm_eo - regmatch[8].rm_so);
  3042. + } else {
  3043. + value = strndup(line + regmatch[9].rm_so,
  3044. + regmatch[9].rm_eo - regmatch[9].rm_so);
  3045. + }
  3046. + extra = NULL;
  3047. + if (regmatch[11].rm_so > 0) {
  3048. + extra = strndup (line + regmatch[11].rm_so,
  3049. + regmatch[11].rm_eo - regmatch[11].rm_so);
  3050. + }
  3051. +
  3052. + /* We use the tmp_dest_nv_pair_list below instead of
  3053. + conf->pkg_dest_list because we might encounter an
  3054. + offline_root option later and that would invalidate the
  3055. + directories we would have computed in
  3056. + pkg_dest_list_init. (We do a similar thing with
  3057. + tmp_src_nv_pair_list for sake of symmetry.) */
  3058. + if (strcmp(type, "option") == 0) {
  3059. + ipkg_conf_set_option(options, name, value);
  3060. + } else if (strcmp(type, "src") == 0) {
  3061. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3062. + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
  3063. + } else {
  3064. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3065. + name, value);
  3066. + }
  3067. + } else if (strcmp(type, "src/gz") == 0) {
  3068. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3069. + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
  3070. + } else {
  3071. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3072. + name, value);
  3073. + }
  3074. + } else if (strcmp(type, "dest") == 0) {
  3075. + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
  3076. + } else if (strcmp(type, "lists_dir") == 0) {
  3077. + *lists_dir = realloc(*lists_dir,strlen(value)+1);
  3078. + if (*lists_dir == NULL) {
  3079. + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
  3080. + free(options);
  3081. + return EINVAL;
  3082. + }
  3083. + sprintf (*lists_dir,"%s",value);
  3084. + } else if (strcmp(type, "arch") == 0) {
  3085. + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
  3086. + if (!value) {
  3087. + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
  3088. + value = strdup("10");
  3089. + }
  3090. + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
  3091. + } else {
  3092. + fprintf(stderr, "WARNING: Ignoring unknown configuration "
  3093. + "parameter: %s %s %s\n", type, name, value);
  3094. + free(options);
  3095. + return EINVAL;
  3096. + }
  3097. +
  3098. + free(type);
  3099. + free(name);
  3100. + free(value);
  3101. + if (extra)
  3102. + free (extra);
  3103. +
  3104. + NEXT_LINE:
  3105. + free(line);
  3106. + }
  3107. +
  3108. + free(options);
  3109. + regfree(&comment_re);
  3110. + regfree(&valid_line_re);
  3111. + fclose(file);
  3112. +
  3113. + return 0;
  3114. +}
  3115. +
  3116. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  3117. + const char *name, const char *value)
  3118. +{
  3119. + int i = 0;
  3120. + while (options[i].name) {
  3121. + if (strcmp(options[i].name, name) == 0) {
  3122. + switch (options[i].type) {
  3123. + case IPKG_OPT_TYPE_BOOL:
  3124. + *((int *)options[i].value) = 1;
  3125. + return 0;
  3126. + case IPKG_OPT_TYPE_INT:
  3127. + if (value) {
  3128. + *((int *)options[i].value) = atoi(value);
  3129. + return 0;
  3130. + } else {
  3131. + printf("%s: Option %s need an argument\n",
  3132. + __FUNCTION__, name);
  3133. + return EINVAL;
  3134. + }
  3135. + case IPKG_OPT_TYPE_STRING:
  3136. + if (value) {
  3137. + *((char **)options[i].value) = strdup(value);
  3138. + return 0;
  3139. + } else {
  3140. + printf("%s: Option %s need an argument\n",
  3141. + __FUNCTION__, name);
  3142. + return EINVAL;
  3143. + }
  3144. + }
  3145. + }
  3146. + i++;
  3147. + }
  3148. +
  3149. + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
  3150. + __FUNCTION__, name, value);
  3151. + return EINVAL;
  3152. +}
  3153. +
  3154. +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
  3155. +{
  3156. + pkg_dest_list_elt_t *iter;
  3157. + pkg_dest_t *dest;
  3158. + pkg_vec_t *all;
  3159. + pkg_t *pkg;
  3160. + register int i;
  3161. + int err;
  3162. +
  3163. + if (conf->noaction)
  3164. + return 0;
  3165. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3166. + dest = iter->data;
  3167. + dest->status_file = fopen(dest->status_file_tmp_name, "w");
  3168. + if (dest->status_file == NULL) {
  3169. + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
  3170. + __FUNCTION__, dest->status_file_name, strerror(errno));
  3171. + }
  3172. + }
  3173. +
  3174. + all = pkg_vec_alloc();
  3175. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  3176. +
  3177. + for(i = 0; i < all->len; i++) {
  3178. + pkg = all->pkgs[i];
  3179. + /* We don't need most uninstalled packages in the status file */
  3180. + if (pkg->state_status == SS_NOT_INSTALLED
  3181. + && (pkg->state_want == SW_UNKNOWN
  3182. + || pkg->state_want == SW_DEINSTALL
  3183. + || pkg->state_want == SW_PURGE)) {
  3184. + continue;
  3185. + }
  3186. + if (!pkg) {
  3187. + fprintf(stderr, "Null package\n");
  3188. + }
  3189. + if (pkg->dest == NULL) {
  3190. + fprintf(stderr, "%s: ERROR: Can't write status for "
  3191. + "package %s since it has a NULL dest\n",
  3192. + __FUNCTION__, pkg->name);
  3193. + continue;
  3194. + }
  3195. + if (pkg->dest->status_file) {
  3196. + pkg_print_status(pkg, pkg->dest->status_file);
  3197. + }
  3198. + }
  3199. +
  3200. + pkg_vec_free(all);
  3201. +
  3202. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3203. + dest = iter->data;
  3204. + if (dest->status_file) {
  3205. + err = ferror(dest->status_file);
  3206. + fclose(dest->status_file);
  3207. + dest->status_file = NULL;
  3208. + if (!err) {
  3209. + file_move(dest->status_file_tmp_name, dest->status_file_name);
  3210. + } else {
  3211. + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
  3212. + "retaining old %s\n", __FUNCTION__,
  3213. + dest->status_file_tmp_name, dest->status_file_name);
  3214. + }
  3215. + }
  3216. + }
  3217. +
  3218. + return 0;
  3219. +}
  3220. +
  3221. +
  3222. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
  3223. +{
  3224. + char *root_filename;
  3225. + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
  3226. + return root_filename;
  3227. +}
  3228. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_conf.h busybox-1.15.2/archival/libipkg/ipkg_conf.h
  3229. --- busybox-1.15.2.orig/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
  3230. +++ busybox-1.15.2/archival/libipkg/ipkg_conf.h 2009-11-26 11:10:13.463859703 +0100
  3231. @@ -0,0 +1,107 @@
  3232. +/* ipkg_conf.h - the itsy package management system
  3233. +
  3234. + Carl D. Worth
  3235. +
  3236. + Copyright (C) 2001 University of Southern California
  3237. +
  3238. + This program is free software; you can redistribute it and/or
  3239. + modify it under the terms of the GNU General Public License as
  3240. + published by the Free Software Foundation; either version 2, or (at
  3241. + your option) any later version.
  3242. +
  3243. + This program is distributed in the hope that it will be useful, but
  3244. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3245. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3246. + General Public License for more details.
  3247. +*/
  3248. +
  3249. +#ifndef IPKG_CONF_H
  3250. +#define IPKG_CONF_H
  3251. +
  3252. +typedef struct ipkg_conf ipkg_conf_t;
  3253. +
  3254. +#include "hash_table.h"
  3255. +#include "ipkg.h"
  3256. +#include "args.h"
  3257. +#include "pkg.h"
  3258. +#include "pkg_hash.h"
  3259. +#include "pkg_src_list.h"
  3260. +#include "pkg_dest_list.h"
  3261. +#include "nv_pair_list.h"
  3262. +
  3263. +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
  3264. +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
  3265. +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
  3266. +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
  3267. +
  3268. +/* In case the config file defines no dest */
  3269. +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
  3270. +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
  3271. +
  3272. +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
  3273. +
  3274. +struct ipkg_conf
  3275. +{
  3276. + pkg_src_list_t pkg_src_list;
  3277. + pkg_dest_list_t pkg_dest_list;
  3278. + nv_pair_list_t arch_list;
  3279. +
  3280. + int restrict_to_default_dest;
  3281. + pkg_dest_t *default_dest;
  3282. +
  3283. + char *tmp_dir;
  3284. + char *lists_dir;
  3285. + char *pending_dir;
  3286. +
  3287. + /* options */
  3288. + int force_depends;
  3289. + int force_defaults;
  3290. + int force_overwrite;
  3291. + int force_downgrade;
  3292. + int force_reinstall;
  3293. + int force_space;
  3294. + int force_removal_of_dependent_packages;
  3295. + int force_removal_of_essential_packages;
  3296. + int nodeps; /* do not follow dependences */
  3297. + int verbose_wget;
  3298. + int multiple_providers;
  3299. + char *offline_root;
  3300. + char *offline_root_pre_script_cmd;
  3301. + char *offline_root_post_script_cmd;
  3302. + int query_all;
  3303. + int verbosity;
  3304. + int noaction;
  3305. +
  3306. + /* proxy options */
  3307. + char *http_proxy;
  3308. + char *ftp_proxy;
  3309. + char *no_proxy;
  3310. + char *proxy_user;
  3311. + char *proxy_passwd;
  3312. +
  3313. + hash_table_t pkg_hash;
  3314. + hash_table_t file_hash;
  3315. + hash_table_t obs_file_hash;
  3316. +};
  3317. +
  3318. +enum ipkg_option_type {
  3319. + IPKG_OPT_TYPE_BOOL,
  3320. + IPKG_OPT_TYPE_INT,
  3321. + IPKG_OPT_TYPE_STRING
  3322. +};
  3323. +typedef enum ipkg_option_type ipkg_option_type_t;
  3324. +
  3325. +typedef struct ipkg_option ipkg_option_t;
  3326. +struct ipkg_option {
  3327. + const char *name;
  3328. + const ipkg_option_type_t type;
  3329. + const void *value;
  3330. +};
  3331. +
  3332. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
  3333. +void ipkg_conf_deinit(ipkg_conf_t *conf);
  3334. +
  3335. +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
  3336. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
  3337. +
  3338. +#endif
  3339. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_configure.c busybox-1.15.2/archival/libipkg/ipkg_configure.c
  3340. --- busybox-1.15.2.orig/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
  3341. +++ busybox-1.15.2/archival/libipkg/ipkg_configure.c 2009-11-26 11:10:13.463859703 +0100
  3342. @@ -0,0 +1,40 @@
  3343. +/* ipkg_configure.c - the itsy package management system
  3344. +
  3345. + Carl D. Worth
  3346. +
  3347. + Copyright (C) 2001 University of Southern California
  3348. +
  3349. + This program is free software; you can redistribute it and/or
  3350. + modify it under the terms of the GNU General Public License as
  3351. + published by the Free Software Foundation; either version 2, or (at
  3352. + your option) any later version.
  3353. +
  3354. + This program is distributed in the hope that it will be useful, but
  3355. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3356. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3357. + General Public License for more details.
  3358. +*/
  3359. +
  3360. +#include "ipkg.h"
  3361. +
  3362. +#include "ipkg_configure.h"
  3363. +
  3364. +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
  3365. +{
  3366. + int err;
  3367. +
  3368. + /* DPKG_INCOMPATIBILITY:
  3369. + dpkg actually does some conffile handling here, rather than at the
  3370. + end of ipkg_install(). Do we care? */
  3371. + /* DPKG_INCOMPATIBILITY:
  3372. + dpkg actually includes a version number to this script call */
  3373. + err = pkg_run_script(conf, pkg, "postinst", "configure");
  3374. + if (err) {
  3375. + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
  3376. + return err;
  3377. + }
  3378. +
  3379. + ipkg_state_changed++;
  3380. + return 0;
  3381. +}
  3382. +
  3383. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_configure.h busybox-1.15.2/archival/libipkg/ipkg_configure.h
  3384. --- busybox-1.15.2.orig/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
  3385. +++ busybox-1.15.2/archival/libipkg/ipkg_configure.h 2009-11-26 11:10:13.516657768 +0100
  3386. @@ -0,0 +1,25 @@
  3387. +/* ipkg_configure.h - the itsy package management system
  3388. +
  3389. + Carl D. Worth
  3390. +
  3391. + Copyright (C) 2001 University of Southern California
  3392. +
  3393. + This program is free software; you can redistribute it and/or
  3394. + modify it under the terms of the GNU General Public License as
  3395. + published by the Free Software Foundation; either version 2, or (at
  3396. + your option) any later version.
  3397. +
  3398. + This program is distributed in the hope that it will be useful, but
  3399. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3400. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3401. + General Public License for more details.
  3402. +*/
  3403. +
  3404. +#ifndef IPKG_CONFIGURE_H
  3405. +#define IPKG_CONFIGURE_H
  3406. +
  3407. +#include "ipkg_conf.h"
  3408. +
  3409. +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
  3410. +
  3411. +#endif
  3412. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_download.c busybox-1.15.2/archival/libipkg/ipkg_download.c
  3413. --- busybox-1.15.2.orig/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
  3414. +++ busybox-1.15.2/archival/libipkg/ipkg_download.c 2009-11-26 11:10:13.519859294 +0100
  3415. @@ -0,0 +1,195 @@
  3416. +/* ipkg_download.c - the itsy package management system
  3417. +
  3418. + Carl D. Worth
  3419. +
  3420. + Copyright (C) 2001 University of Southern California
  3421. +
  3422. + This program is free software; you can redistribute it and/or
  3423. + modify it under the terms of the GNU General Public License as
  3424. + published by the Free Software Foundation; either version 2, or (at
  3425. + your option) any later version.
  3426. +
  3427. + This program is distributed in the hope that it will be useful, but
  3428. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3429. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3430. + General Public License for more details.
  3431. +*/
  3432. +
  3433. +#include "ipkg.h"
  3434. +#include "ipkg_download.h"
  3435. +#include "ipkg_message.h"
  3436. +
  3437. +#include "sprintf_alloc.h"
  3438. +#include "xsystem.h"
  3439. +#include "file_util.h"
  3440. +#include "str_util.h"
  3441. +
  3442. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
  3443. +{
  3444. + int err = 0;
  3445. +
  3446. + char *src_basec = strdup(src);
  3447. + char *src_base = basename(src_basec);
  3448. + char *tmp_file_location;
  3449. + char *cmd;
  3450. +
  3451. + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
  3452. +
  3453. + fflush(stdout);
  3454. +
  3455. + if (str_starts_with(src, "file:")) {
  3456. + int ret;
  3457. + const char *file_src = src + 5;
  3458. + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
  3459. + ret = file_copy(src + 5, dest_file_name);
  3460. + ipkg_message(conf,IPKG_INFO,"Done.\n");
  3461. + return ret;
  3462. + }
  3463. +
  3464. + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
  3465. + err = unlink(tmp_file_location);
  3466. + if (err && errno != ENOENT) {
  3467. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
  3468. + __FUNCTION__, tmp_file_location, strerror(errno));
  3469. + free(tmp_file_location);
  3470. + return errno;
  3471. + }
  3472. +
  3473. + if (conf->http_proxy) {
  3474. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
  3475. + setenv("http_proxy", conf->http_proxy, 1);
  3476. + }
  3477. + if (conf->ftp_proxy) {
  3478. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
  3479. + setenv("ftp_proxy", conf->ftp_proxy, 1);
  3480. + }
  3481. + if (conf->no_proxy) {
  3482. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
  3483. + setenv("no_proxy", conf->no_proxy, 1);
  3484. + }
  3485. +
  3486. + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
  3487. + sprintf_alloc(&cmd, "wget %s %s%s %s%s %s -P %s %s",
  3488. + (conf->http_proxy || conf->ftp_proxy) ? "-Y on" : "",
  3489. + conf->proxy_user ? "--proxy-user=" : "",
  3490. + conf->proxy_user ? conf->proxy_user : "",
  3491. + conf->proxy_passwd ? "--proxy-passwd=" : "",
  3492. + conf->proxy_passwd ? conf->proxy_passwd : "",
  3493. + conf->verbose_wget ? "" : "-q",
  3494. + conf->tmp_dir,
  3495. + src);
  3496. + err = xsystem(cmd);
  3497. + if (err) {
  3498. + if (err != -1) {
  3499. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
  3500. + __FUNCTION__, err, cmd);
  3501. + }
  3502. + unlink(tmp_file_location);
  3503. + free(tmp_file_location);
  3504. + free(src_basec);
  3505. + free(cmd);
  3506. + return EINVAL;
  3507. + }
  3508. + free(cmd);
  3509. +
  3510. + err = file_move(tmp_file_location, dest_file_name);
  3511. +
  3512. + free(tmp_file_location);
  3513. + free(src_basec);
  3514. +
  3515. + if (err) {
  3516. + return err;
  3517. + }
  3518. +
  3519. + return 0;
  3520. +}
  3521. +
  3522. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
  3523. +{
  3524. + int err;
  3525. + char *url;
  3526. +
  3527. + if (pkg->src == NULL) {
  3528. + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
  3529. + pkg->name, pkg->parent->name);
  3530. + return -1;
  3531. + }
  3532. +
  3533. + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
  3534. +
  3535. + /* XXX: BUG: The pkg->filename might be something like
  3536. + "../../foo.ipk". While this is correct, and exactly what we
  3537. + want to use to construct url above, here we actually need to
  3538. + use just the filename part, without any directory. */
  3539. + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
  3540. +
  3541. + err = ipkg_download(conf, url, pkg->local_filename);
  3542. + free(url);
  3543. +
  3544. + return err;
  3545. +}
  3546. +
  3547. +/*
  3548. + * Downloads file from url, installs in package database, return package name.
  3549. + */
  3550. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
  3551. +{
  3552. + int err = 0;
  3553. + pkg_t *pkg;
  3554. + pkg = pkg_new();
  3555. + if (pkg == NULL)
  3556. + return ENOMEM;
  3557. +
  3558. + if (str_starts_with(url, "http://")
  3559. + || str_starts_with(url, "ftp://")) {
  3560. + char *tmp_file;
  3561. + char *file_basec = strdup(url);
  3562. + char *file_base = basename(file_basec);
  3563. +
  3564. + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
  3565. + err = ipkg_download(conf, url, tmp_file);
  3566. + if (err)
  3567. + return err;
  3568. +
  3569. + err = pkg_init_from_file(pkg, tmp_file);
  3570. + if (err)
  3571. + return err;
  3572. + pkg->local_filename = strdup(tmp_file);
  3573. +
  3574. + free(tmp_file);
  3575. + free(file_basec);
  3576. +
  3577. + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
  3578. + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
  3579. +
  3580. + err = pkg_init_from_file(pkg, url);
  3581. + if (err)
  3582. + return err;
  3583. + pkg->local_filename = strdup(url);
  3584. + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
  3585. + pkg->provided_by_hand = 1;
  3586. +
  3587. + } else {
  3588. + pkg_deinit(pkg);
  3589. + free(pkg);
  3590. + return 0;
  3591. + }
  3592. +
  3593. + if (!pkg->architecture) {
  3594. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3595. + return -EINVAL;
  3596. + }
  3597. +
  3598. + pkg->dest = conf->default_dest;
  3599. + pkg->state_want = SW_INSTALL;
  3600. + pkg->state_flag |= SF_PREFER;
  3601. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3602. + if ( pkg == NULL ){
  3603. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  3604. + return 0;
  3605. + }
  3606. + if (namep) {
  3607. + *namep = strdup(pkg->name);
  3608. + }
  3609. + return 0;
  3610. +}
  3611. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_download.h busybox-1.15.2/archival/libipkg/ipkg_download.h
  3612. --- busybox-1.15.2.orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
  3613. +++ busybox-1.15.2/archival/libipkg/ipkg_download.h 2009-11-26 11:10:13.519859294 +0100
  3614. @@ -0,0 +1,30 @@
  3615. +/* ipkg_download.h - the itsy package management system
  3616. +
  3617. + Carl D. Worth
  3618. +
  3619. + Copyright (C) 2001 University of Southern California
  3620. +
  3621. + This program is free software; you can redistribute it and/or
  3622. + modify it under the terms of the GNU General Public License as
  3623. + published by the Free Software Foundation; either version 2, or (at
  3624. + your option) any later version.
  3625. +
  3626. + This program is distributed in the hope that it will be useful, but
  3627. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3628. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3629. + General Public License for more details.
  3630. +*/
  3631. +
  3632. +#ifndef IPKG_DOWNLOAD_H
  3633. +#define IPKG_DOWNLOAD_H
  3634. +
  3635. +#include "ipkg_conf.h"
  3636. +
  3637. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
  3638. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
  3639. +/*
  3640. + * Downloads file from url, installs in package database, return package name.
  3641. + */
  3642. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
  3643. +
  3644. +#endif
  3645. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg.h busybox-1.15.2/archival/libipkg/ipkg.h
  3646. --- busybox-1.15.2.orig/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
  3647. +++ busybox-1.15.2/archival/libipkg/ipkg.h 2009-11-27 18:16:56.974265578 +0100
  3648. @@ -0,0 +1,68 @@
  3649. +/* ipkg.h - the itsy package management system
  3650. +
  3651. + Carl D. Worth
  3652. +
  3653. + Copyright (C) 2001 University of Southern California
  3654. +
  3655. + This program is free software; you can redistribute it and/or
  3656. + modify it under the terms of the GNU General Public License as
  3657. + published by the Free Software Foundation; either version 2, or (at
  3658. + your option) any later version.
  3659. +
  3660. + This program is distributed in the hope that it will be useful, but
  3661. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3662. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3663. + General Public License for more details.
  3664. +*/
  3665. +
  3666. +#ifndef IPKG_H
  3667. +#define IPKG_H
  3668. +
  3669. +#include "libbb.h"
  3670. +
  3671. +#include "ipkg_includes.h"
  3672. +#include "ipkg_conf.h"
  3673. +#include "ipkg_message.h"
  3674. +
  3675. +#define IPKG_PKG_EXTENSION ".ipk"
  3676. +#define DPKG_PKG_EXTENSION ".deb"
  3677. +
  3678. +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
  3679. +#define IPKG_PKG_VERSION_SEP_CHAR '_'
  3680. +
  3681. +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
  3682. +#define IPKG_LISTS_DIR_SUFFIX "lists"
  3683. +#define IPKG_INFO_DIR_SUFFIX "info"
  3684. +#define IPKG_STATUS_FILE_SUFFIX "status"
  3685. +
  3686. +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
  3687. +
  3688. +#define IPKG_LIST_DESCRIPTION_LENGTH 128
  3689. +
  3690. +#define IPKG_VERSION "1.00"
  3691. +
  3692. +
  3693. +enum ipkg_error {
  3694. + IPKG_SUCCESS = 0,
  3695. + IPKG_PKG_DEPS_UNSATISFIED,
  3696. + IPKG_PKG_IS_ESSENTIAL,
  3697. + IPKG_PKG_HAS_DEPENDENTS,
  3698. + IPKG_PKG_HAS_NO_CANDIDATE
  3699. +};
  3700. +typedef enum ipkg_error ipkg_error_t;
  3701. +
  3702. +extern int ipkg_state_changed;
  3703. +
  3704. +
  3705. +struct errlist {
  3706. + char * errmsg;
  3707. + struct errlist * next;
  3708. +} ;
  3709. +
  3710. +extern struct errlist* error_list;
  3711. +
  3712. +extern ipkg_conf_t *global_conf;
  3713. +
  3714. +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
  3715. +
  3716. +#endif
  3717. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_includes.h busybox-1.15.2/archival/libipkg/ipkg_includes.h
  3718. --- busybox-1.15.2.orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
  3719. +++ busybox-1.15.2/archival/libipkg/ipkg_includes.h 2009-11-26 11:10:13.635857588 +0100
  3720. @@ -0,0 +1,79 @@
  3721. +#ifndef IPKG_INCLUDES_H
  3722. +#define IPKG_INCLUDES_H
  3723. +
  3724. +/* Define to 1 if you have the <memory.h> header file. */
  3725. +#define HAVE_MEMORY_H 1
  3726. +
  3727. +/* Define to 1 if you have the <regex.h> header file. */
  3728. +#define HAVE_REGEX_H 1
  3729. +
  3730. +/* Define to 1 if you have the <stdlib.h> header file. */
  3731. +#define HAVE_STDLIB_H 1
  3732. +
  3733. +/* Define to 1 if you have the <strings.h> header file. */
  3734. +#define HAVE_STRINGS_H 1
  3735. +
  3736. +/* Define to 1 if you have the <string.h> header file. */
  3737. +#define HAVE_STRING_H 1
  3738. +
  3739. +/* Define to 1 if you have the <sys/stat.h> header file. */
  3740. +#define HAVE_SYS_STAT_H 1
  3741. +
  3742. +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
  3743. +#define HAVE_SYS_WAIT_H 1
  3744. +
  3745. +/* Define to 1 if you have the <unistd.h> header file. */
  3746. +#define HAVE_UNISTD_H 1
  3747. +
  3748. +/* Define to 1 if you have the ANSI C header files. */
  3749. +#define STDC_HEADERS 1
  3750. +
  3751. +
  3752. +#include <stdio.h>
  3753. +
  3754. +#if STDC_HEADERS
  3755. +# include <stdlib.h>
  3756. +# include <stdarg.h>
  3757. +# include <stddef.h>
  3758. +# include <ctype.h>
  3759. +# include <errno.h>
  3760. +#else
  3761. +# if HAVE_STDLIB_H
  3762. +# include <stdlib.h>
  3763. +# endif
  3764. +#endif
  3765. +
  3766. +#if HAVE_REGEX_H
  3767. +# include <regex.h>
  3768. +#endif
  3769. +
  3770. +#if HAVE_STRING_H
  3771. +# if !STDC_HEADERS && HAVE_MEMORY_H
  3772. +# include <memory.h>
  3773. +# endif
  3774. +/* XXX: What's the right way to pick up GNU's strndup declaration? */
  3775. +# if __GNUC__
  3776. +# define __USE_GNU 1
  3777. +# endif
  3778. +# include <string.h>
  3779. +# undef __USE_GNU
  3780. +#endif
  3781. +
  3782. +#if HAVE_STRINGS_H
  3783. +# include <strings.h>
  3784. +#endif
  3785. +
  3786. +#if HAVE_SYS_STAT_H
  3787. +# include <sys/stat.h>
  3788. +#endif
  3789. +
  3790. +#if HAVE_SYS_WAIT_H
  3791. +# include <sys/wait.h>
  3792. +#endif
  3793. +
  3794. +#if HAVE_UNISTD_H
  3795. +# include <sys/types.h>
  3796. +# include <unistd.h>
  3797. +#endif
  3798. +
  3799. +#endif /* IPKG_INCLUDES_H */
  3800. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_install.c busybox-1.15.2/archival/libipkg/ipkg_install.c
  3801. --- busybox-1.15.2.orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
  3802. +++ busybox-1.15.2/archival/libipkg/ipkg_install.c 2009-11-26 11:10:13.659857013 +0100
  3803. @@ -0,0 +1,1982 @@
  3804. +/* ipkg_install.c - the itsy package management system
  3805. +
  3806. + Carl D. Worth
  3807. +
  3808. + Copyright (C) 2001 University of Southern California
  3809. +
  3810. + This program is free software; you can redistribute it and/or
  3811. + modify it under the terms of the GNU General Public License as
  3812. + published by the Free Software Foundation; either version 2, or (at
  3813. + your option) any later version.
  3814. +
  3815. + This program is distributed in the hope that it will be useful, but
  3816. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3817. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3818. + General Public License for more details.
  3819. +*/
  3820. +
  3821. +#include "ipkg.h"
  3822. +#include <errno.h>
  3823. +#include <dirent.h>
  3824. +#include <glob.h>
  3825. +#include <time.h>
  3826. +#include <signal.h>
  3827. +typedef void (*sighandler_t)(int);
  3828. +
  3829. +#include "pkg.h"
  3830. +#include "pkg_hash.h"
  3831. +#include "pkg_extract.h"
  3832. +
  3833. +#include "ipkg_install.h"
  3834. +#include "ipkg_configure.h"
  3835. +#include "ipkg_download.h"
  3836. +#include "ipkg_remove.h"
  3837. +
  3838. +#include "ipkg_utils.h"
  3839. +#include "ipkg_message.h"
  3840. +
  3841. +#include "sprintf_alloc.h"
  3842. +#include "file_util.h"
  3843. +#include "str_util.h"
  3844. +#include "xsystem.h"
  3845. +#include "user.h"
  3846. +
  3847. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  3848. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
  3849. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
  3850. +
  3851. +/*
  3852. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3853. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3854. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3855. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3856. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3857. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3858. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3859. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
  3860. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3861. +*/
  3862. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3863. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3864. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg);
  3865. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3866. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg);
  3867. +
  3868. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3869. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3870. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
  3871. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
  3872. +
  3873. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
  3874. +
  3875. +static int user_prefers_old_conffile(const char *file, const char *backup);
  3876. +
  3877. +static char *backup_filename_alloc(const char *file_name);
  3878. +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
  3879. +static int backup_exists_for(const char *file_name);
  3880. +static int backup_remove(const char *file_name);
  3881. +
  3882. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees);
  3883. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3884. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3885. +
  3886. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
  3887. +{
  3888. + int err, cmp;
  3889. + pkg_t *pkg, *old;
  3890. + char *old_version, *new_version;
  3891. +
  3892. + pkg = pkg_new();
  3893. + if (pkg == NULL) {
  3894. + return ENOMEM;
  3895. + }
  3896. +
  3897. + err = pkg_init_from_file(pkg, filename);
  3898. + if (err) {
  3899. + return err;
  3900. + }
  3901. +
  3902. + if (!pkg->architecture) {
  3903. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3904. + return -EINVAL;
  3905. + }
  3906. +
  3907. + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
  3908. + freeing the pkg that we pass in. It might be nice to clean this up
  3909. + if possible. */
  3910. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3911. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  3912. +
  3913. + pkg->local_filename = strdup(filename);
  3914. +
  3915. + if (old) {
  3916. + old_version = pkg_version_str_alloc(old);
  3917. + new_version = pkg_version_str_alloc(pkg);
  3918. +
  3919. + cmp = pkg_compare_versions(old, pkg);
  3920. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3921. + cmp = -1 ; /* then we force ipkg to downgrade */
  3922. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3923. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3924. + }
  3925. + if (cmp > 0) {
  3926. + ipkg_message(conf, IPKG_NOTICE,
  3927. + "Not downgrading package %s on %s from %s to %s.\n",
  3928. + old->name, old->dest->name, old_version, new_version);
  3929. + pkg->state_want = SW_DEINSTALL;
  3930. + pkg->state_flag |= SF_OBSOLETE;
  3931. + free(old_version);
  3932. + free(new_version);
  3933. + return 0;
  3934. + } else {
  3935. + free(old_version);
  3936. + free(new_version);
  3937. + }
  3938. + }
  3939. +
  3940. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3941. + return ipkg_install_pkg(conf, pkg,0);
  3942. +}
  3943. +
  3944. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3945. +{
  3946. + int cmp;
  3947. + pkg_t *old, *new;
  3948. + char *old_version, *new_version;
  3949. +
  3950. + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
  3951. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  3952. + if ( old )
  3953. + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
  3954. +
  3955. + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
  3956. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  3957. + if ( new )
  3958. + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
  3959. +
  3960. +/* Pigi Basically here is broken the version stuff.
  3961. + What's happening is that nothing provide the version to differents
  3962. + functions, so the returned struct is always the latest.
  3963. + That's why the install by name don't work.
  3964. +*/
  3965. + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
  3966. +
  3967. + if ( old )
  3968. + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
  3969. + if ( new )
  3970. + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
  3971. + ipkg_message(conf, IPKG_DEBUG2, " \n");
  3972. +
  3973. + if (new == NULL) {
  3974. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3975. + }
  3976. +
  3977. + new->state_flag |= SF_USER;
  3978. + if (old) {
  3979. + old_version = pkg_version_str_alloc(old);
  3980. + new_version = pkg_version_str_alloc(new);
  3981. +
  3982. + cmp = pkg_compare_versions(old, new);
  3983. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3984. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
  3985. + cmp = -1 ; /* then we force ipkg to downgrade */
  3986. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3987. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3988. + }
  3989. + ipkg_message(conf, IPKG_DEBUG,
  3990. + "Comparing visible versions of pkg %s:"
  3991. + "\n\t%s is installed "
  3992. + "\n\t%s is available "
  3993. + "\n\t%d was comparison result\n",
  3994. + pkg_name, old_version, new_version, cmp);
  3995. + if (cmp == 0 && !conf->force_reinstall) {
  3996. + ipkg_message(conf, IPKG_NOTICE,
  3997. + "Package %s (%s) installed in %s is up to date.\n",
  3998. + old->name, old_version, old->dest->name);
  3999. + free(old_version);
  4000. + free(new_version);
  4001. + return 0;
  4002. + } else if (cmp > 0) {
  4003. + ipkg_message(conf, IPKG_NOTICE,
  4004. + "Not downgrading package %s on %s from %s to %s.\n",
  4005. + old->name, old->dest->name, old_version, new_version);
  4006. + free(old_version);
  4007. + free(new_version);
  4008. + return 0;
  4009. + } else if (cmp < 0) {
  4010. + new->dest = old->dest;
  4011. + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
  4012. + }
  4013. + }
  4014. +
  4015. + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
  4016. + supposed to be an ipkg_error_t, but ipkg_install_pkg could
  4017. + return any kind of integer, (might be errno from a syscall,
  4018. + etc.). This is a real mess and will need to be cleaned up if
  4019. + anyone ever wants to make a nice libipkg. */
  4020. +
  4021. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4022. + return ipkg_install_pkg(conf, new,0);
  4023. +}
  4024. +
  4025. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
  4026. +{
  4027. + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
  4028. + int i;
  4029. + ipkg_error_t err;
  4030. + abstract_pkg_t *ppkg ;
  4031. +
  4032. + if (providers == NULL)
  4033. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4034. +
  4035. + for (i = 0; i < providers->len; i++) {
  4036. + ppkg = abstract_pkg_vec_get(providers, i);
  4037. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
  4038. + err = ipkg_install_by_name(conf, ppkg->name);
  4039. + if (err)
  4040. + return err;
  4041. +/* XXX Maybe ppkg should be freed ? */
  4042. + }
  4043. + return 0;
  4044. +}
  4045. +
  4046. +/*
  4047. + * Walk dependence graph starting with pkg, collect packages to be
  4048. + * installed into pkgs_needed, in dependence order.
  4049. + */
  4050. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
  4051. +{
  4052. + int i, err;
  4053. + pkg_vec_t *depends = pkg_vec_alloc();
  4054. + char **unresolved = NULL;
  4055. + int ndepends;
  4056. +
  4057. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4058. + pkg, depends,
  4059. + &unresolved);
  4060. +
  4061. + if (unresolved) {
  4062. + ipkg_message(conf, IPKG_ERROR,
  4063. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4064. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4065. + while (*unresolved) {
  4066. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4067. + unresolved++;
  4068. + }
  4069. + ipkg_message(conf, IPKG_ERROR, "\n");
  4070. + if (! conf->force_depends) {
  4071. + ipkg_message(conf, IPKG_INFO,
  4072. + "This could mean that your package list is out of date or that the packages\n"
  4073. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4074. + "of this problem try again with the '-force-depends' option.\n");
  4075. + pkg_vec_free(depends);
  4076. + return IPKG_PKG_DEPS_UNSATISFIED;
  4077. + }
  4078. + }
  4079. +
  4080. + if (ndepends <= 0) {
  4081. + pkg_vec_free(depends);
  4082. + return 0;
  4083. + }
  4084. +
  4085. + for (i = 0; i < depends->len; i++) {
  4086. + pkg_t *dep = depends->pkgs[i];
  4087. + /* The package was uninstalled when we started, but another
  4088. + dep earlier in this loop may have depended on it and pulled
  4089. + it in, so check first. */
  4090. + if ((dep->state_status != SS_INSTALLED)
  4091. + && (dep->state_status != SS_UNPACKED)
  4092. + && (dep->state_want != SW_INSTALL)) {
  4093. +
  4094. + /* Mark packages as to-be-installed */
  4095. + dep->state_want = SW_INSTALL;
  4096. +
  4097. + /* Dependencies should be installed the same place as pkg */
  4098. + if (dep->dest == NULL) {
  4099. + dep->dest = pkg->dest;
  4100. + }
  4101. +
  4102. + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
  4103. + if (err) {
  4104. + pkg_vec_free(depends);
  4105. + return err;
  4106. + }
  4107. + }
  4108. + }
  4109. + if (pkgs_needed)
  4110. + pkg_vec_insert(pkgs_needed, pkg);
  4111. +
  4112. + pkg_vec_free(depends);
  4113. +
  4114. + return 0;
  4115. +}
  4116. +
  4117. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
  4118. +{
  4119. + int cmp;
  4120. + pkg_t *old, *new;
  4121. + char *old_version, *new_version;
  4122. +
  4123. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  4124. +
  4125. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  4126. + if (new == NULL) {
  4127. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4128. + }
  4129. + if (old) {
  4130. + old_version = pkg_version_str_alloc(old);
  4131. + new_version = pkg_version_str_alloc(new);
  4132. +
  4133. + cmp = pkg_compare_versions(old, new);
  4134. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4135. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
  4136. + cmp = -1 ; /* then we force ipkg to downgrade */
  4137. + /* We need to use a value < 0 because in the 0 case we are asking to */
  4138. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4139. + }
  4140. + ipkg_message(conf, IPKG_DEBUG,
  4141. + "comparing visible versions of pkg %s:"
  4142. + "\n\t%s is installed "
  4143. + "\n\t%s is available "
  4144. + "\n\t%d was comparison result\n",
  4145. + pkg_name, old_version, new_version, cmp);
  4146. + if (cmp == 0 && !conf->force_reinstall) {
  4147. + ipkg_message(conf, IPKG_NOTICE,
  4148. + "Package %s (%s) installed in %s is up to date.\n",
  4149. + old->name, old_version, old->dest->name);
  4150. + free(old_version);
  4151. + free(new_version);
  4152. + return 0;
  4153. + } else if (cmp > 0) {
  4154. + ipkg_message(conf, IPKG_NOTICE,
  4155. + "Not downgrading package %s on %s from %s to %s.\n",
  4156. + old->name, old->dest->name, old_version, new_version);
  4157. + free(old_version);
  4158. + free(new_version);
  4159. + return 0;
  4160. + } else if (cmp < 0) {
  4161. + new->dest = old->dest;
  4162. + old->state_want = SW_DEINSTALL;
  4163. + old->state_flag |= SF_OBSOLETE;
  4164. + }
  4165. + }
  4166. + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
  4167. +}
  4168. +
  4169. +
  4170. +
  4171. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
  4172. +{
  4173. + int i, err;
  4174. + pkg_vec_t *depends = pkg_vec_alloc();
  4175. + pkg_t *dep;
  4176. + char **unresolved = NULL;
  4177. + int ndepends;
  4178. +
  4179. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4180. + pkg, depends,
  4181. + &unresolved);
  4182. +
  4183. + if (unresolved) {
  4184. + ipkg_message(conf, IPKG_ERROR,
  4185. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4186. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4187. + while (*unresolved) {
  4188. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4189. + unresolved++;
  4190. + }
  4191. + ipkg_message(conf, IPKG_ERROR, "\n");
  4192. + if (! conf->force_depends) {
  4193. + ipkg_message(conf, IPKG_INFO,
  4194. + "This could mean that your package list is out of date or that the packages\n"
  4195. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4196. + "of this problem try again with the '-force-depends' option.\n");
  4197. + pkg_vec_free(depends);
  4198. + return IPKG_PKG_DEPS_UNSATISFIED;
  4199. + }
  4200. + }
  4201. +
  4202. + if (ndepends <= 0) {
  4203. + return 0;
  4204. + }
  4205. +
  4206. + /* Mark packages as to-be-installed */
  4207. + for (i=0; i < depends->len; i++) {
  4208. + /* Dependencies should be installed the same place as pkg */
  4209. + if (depends->pkgs[i]->dest == NULL) {
  4210. + depends->pkgs[i]->dest = pkg->dest;
  4211. + }
  4212. + depends->pkgs[i]->state_want = SW_INSTALL;
  4213. + }
  4214. +
  4215. + for (i = 0; i < depends->len; i++) {
  4216. + dep = depends->pkgs[i];
  4217. + /* The package was uninstalled when we started, but another
  4218. + dep earlier in this loop may have depended on it and pulled
  4219. + it in, so check first. */
  4220. + if ((dep->state_status != SS_INSTALLED)
  4221. + && (dep->state_status != SS_UNPACKED)) {
  4222. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4223. + err = ipkg_install_pkg(conf, dep,0);
  4224. + if (err) {
  4225. + pkg_vec_free(depends);
  4226. + return err;
  4227. + }
  4228. + }
  4229. + }
  4230. +
  4231. + pkg_vec_free(depends);
  4232. +
  4233. + return 0;
  4234. +}
  4235. +
  4236. +
  4237. +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
  4238. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
  4239. +{
  4240. + if (conf->nodeps == 0) {
  4241. + int i;
  4242. + pkg_vec_t *installed = pkg_vec_alloc();
  4243. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  4244. + for (i = 0; i < installed->len; i++) {
  4245. + pkg_t *pkg = installed->pkgs[i];
  4246. + satisfy_dependencies_for(conf, pkg);
  4247. + }
  4248. + pkg_vec_free(installed);
  4249. + }
  4250. + return 0;
  4251. +}
  4252. +
  4253. +
  4254. +
  4255. +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
  4256. +{
  4257. + int i;
  4258. + pkg_vec_t *conflicts = NULL;
  4259. + int level;
  4260. + const char *prefix;
  4261. + if (conf->force_depends) {
  4262. + level = IPKG_NOTICE;
  4263. + prefix = "Warning";
  4264. + } else {
  4265. + level = IPKG_ERROR;
  4266. + prefix = "ERROR";
  4267. + }
  4268. +
  4269. + if (!conf->force_depends)
  4270. + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(pkg);
  4271. +
  4272. + if (conflicts) {
  4273. + ipkg_message(conf, level,
  4274. + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
  4275. + i = 0;
  4276. + while (i < conflicts->len)
  4277. + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
  4278. + ipkg_message(conf, level, "\n");
  4279. + pkg_vec_free(conflicts);
  4280. + return IPKG_PKG_DEPS_UNSATISFIED;
  4281. + }
  4282. + return 0;
  4283. +}
  4284. +
  4285. +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
  4286. +{
  4287. + str_list_t *new_list = pkg_get_installed_files(new_pkg);
  4288. + str_list_elt_t *iter;
  4289. +
  4290. + for (iter = new_list->head; iter; iter = iter->next) {
  4291. + char *new_file = iter->data;
  4292. + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
  4293. + if (!new_file)
  4294. + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
  4295. + if (!owner || (owner == old_pkg))
  4296. + file_hash_set_file_owner(conf, new_file, new_pkg);
  4297. + }
  4298. + if (old_pkg) {
  4299. + str_list_t *old_list = pkg_get_installed_files(old_pkg);
  4300. + for (iter = old_list->head; iter; iter = iter->next) {
  4301. + char *old_file = iter->data;
  4302. + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
  4303. + if (owner == old_pkg) {
  4304. + /* obsolete */
  4305. + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
  4306. + }
  4307. + }
  4308. + }
  4309. + return 0;
  4310. +}
  4311. +
  4312. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
  4313. +{
  4314. + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
  4315. +
  4316. + /* sma 6.20.02: yup; here's the first bit */
  4317. + /*
  4318. + * XXX: BUG easy for cworth
  4319. + * 1) please point the call below to the correct current root destination
  4320. + * 2) we need to resolve how to check the required space for a pending pkg,
  4321. + * my diddling with the .ipk file size below isn't going to cut it.
  4322. + * 3) return a proper error code instead of 1
  4323. + */
  4324. + int comp_size, blocks_available;
  4325. +
  4326. + if (!conf->force_space && pkg->installed_size != NULL) {
  4327. + blocks_available = get_available_blocks(conf->default_dest->root_dir);
  4328. +
  4329. + comp_size = strtoul(pkg->installed_size, NULL, 0);
  4330. + /* round up a blocks count without doing fancy-but-slow casting jazz */
  4331. + comp_size = (int)((comp_size + 1023) / 1024);
  4332. +
  4333. + if (comp_size >= blocks_available) {
  4334. + ipkg_message(conf, IPKG_ERROR,
  4335. + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
  4336. + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
  4337. + return ENOSPC;
  4338. + }
  4339. + }
  4340. + return 0;
  4341. +}
  4342. +
  4343. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
  4344. +{
  4345. + int err;
  4346. + char *conffiles_file_name;
  4347. + char *root_dir;
  4348. + FILE *conffiles_file;
  4349. +
  4350. + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
  4351. +
  4352. + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
  4353. + if (pkg->tmp_unpack_dir == NULL) {
  4354. + ipkg_message(conf, IPKG_ERROR,
  4355. + "%s: Failed to create temporary directory '%s': %s\n",
  4356. + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
  4357. + return errno;
  4358. + }
  4359. +
  4360. + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
  4361. + if (err) {
  4362. + return err;
  4363. + }
  4364. +
  4365. + /* XXX: CLEANUP: There might be a cleaner place to read in the
  4366. + conffiles. Seems like I should be able to get everything to go
  4367. + through pkg_init_from_file. If so, maybe it would make sense to
  4368. + move all of unpack_pkg_control_files to that function. */
  4369. +
  4370. + /* Don't need to re-read conffiles if we already have it */
  4371. + if (pkg->conffiles.head) {
  4372. + return 0;
  4373. + }
  4374. +
  4375. + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
  4376. + if (! file_exists(conffiles_file_name)) {
  4377. + free(conffiles_file_name);
  4378. + return 0;
  4379. + }
  4380. +
  4381. + conffiles_file = fopen(conffiles_file_name, "r");
  4382. + if (conffiles_file == NULL) {
  4383. + fprintf(stderr, "%s: failed to open %s: %s\n",
  4384. + __FUNCTION__, conffiles_file_name, strerror(errno));
  4385. + free(conffiles_file_name);
  4386. + return errno;
  4387. + }
  4388. + free(conffiles_file_name);
  4389. +
  4390. + while (1) {
  4391. + char *cf_name;
  4392. + char *cf_name_in_dest;
  4393. +
  4394. + cf_name = file_read_line_alloc(conffiles_file);
  4395. + if (cf_name == NULL) {
  4396. + break;
  4397. + }
  4398. + str_chomp(cf_name);
  4399. + if (cf_name[0] == '\0') {
  4400. + continue;
  4401. + }
  4402. +
  4403. + /* Prepend dest->root_dir to conffile name.
  4404. + Take pains to avoid multiple slashes. */
  4405. + root_dir = pkg->dest->root_dir;
  4406. + if (conf->offline_root)
  4407. + /* skip the offline_root prefix */
  4408. + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
  4409. + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
  4410. + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
  4411. +
  4412. + /* Can't get an md5sum now, (file isn't extracted yet).
  4413. + We'll wait until resolve_conffiles */
  4414. + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
  4415. +
  4416. + free(cf_name);
  4417. + free(cf_name_in_dest);
  4418. + }
  4419. +
  4420. + fclose(conffiles_file);
  4421. +
  4422. + return 0;
  4423. +}
  4424. +
  4425. +/* returns number of installed replacees */
  4426. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees)
  4427. +{
  4428. + abstract_pkg_t **replaces = pkg->replaces;
  4429. + int replaces_count = pkg->replaces_count;
  4430. + int i, j;
  4431. + for (i = 0; i < replaces_count; i++) {
  4432. + abstract_pkg_t *ab_pkg = replaces[i];
  4433. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  4434. + if (pkg_vec) {
  4435. + for (j = 0; j < pkg_vec->len; j++) {
  4436. + pkg_t *replacee = pkg_vec->pkgs[j];
  4437. + if (!pkg_conflicts(pkg, replacee))
  4438. + continue;
  4439. + if (replacee->state_status == SS_INSTALLED) {
  4440. + pkg_vec_insert(installed_replacees, replacee);
  4441. + }
  4442. + }
  4443. + }
  4444. + }
  4445. + return installed_replacees->len;
  4446. +}
  4447. +
  4448. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4449. +{
  4450. + int i;
  4451. + int replaces_count = replacees->len;
  4452. + for (i = 0; i < replaces_count; i++) {
  4453. + pkg_t *replacee = replacees->pkgs[i];
  4454. + int err;
  4455. + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
  4456. + err = ipkg_remove_pkg(conf, replacee,0);
  4457. + if (err)
  4458. + return err;
  4459. + }
  4460. + return 0;
  4461. +}
  4462. +
  4463. +/* to unwind the removal: make sure they are installed */
  4464. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4465. +{
  4466. + int i, err;
  4467. + int replaces_count = replacees->len;
  4468. + for (i = 0; i < replaces_count; i++) {
  4469. + pkg_t *replacee = replacees->pkgs[i];
  4470. + if (replacee->state_status != SS_INSTALLED) {
  4471. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4472. + err = ipkg_install_pkg(conf, replacee,0);
  4473. + if (err)
  4474. + return err;
  4475. + }
  4476. + }
  4477. + return 0;
  4478. +}
  4479. +
  4480. +int caught_sigint = 0;
  4481. +static void ipkg_install_pkg_sigint_handler(int sig)
  4482. +{
  4483. + caught_sigint = sig;
  4484. +}
  4485. +
  4486. +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
  4487. +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
  4488. +{
  4489. + if (old_pkg) {
  4490. + char message_out[15];
  4491. + char *old_version = pkg_version_str_alloc(old_pkg);
  4492. + char *new_version = pkg_version_str_alloc(pkg);
  4493. + int cmp = pkg_compare_versions(old_pkg, pkg);
  4494. + int rc = 0;
  4495. +
  4496. + memset(message_out,'\x0',15);
  4497. + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
  4498. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4499. + cmp = -1 ; /* then we force ipkg to downgrade */
  4500. + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
  4501. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4502. + }
  4503. +
  4504. + if (cmp > 0) {
  4505. + ipkg_message(conf, IPKG_NOTICE,
  4506. + "Not downgrading package %s on %s from %s to %s.\n",
  4507. + old_pkg->name, old_pkg->dest->name, old_version, new_version);
  4508. + rc = 1;
  4509. + } else if (cmp < 0) {
  4510. + ipkg_message(conf, IPKG_NOTICE,
  4511. + "%s%s on %s from %s to %s...\n",
  4512. + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
  4513. + pkg->dest = old_pkg->dest;
  4514. + rc = 0;
  4515. + } else /* cmp == 0 */ {
  4516. + if (conf->force_reinstall) {
  4517. + ipkg_message(conf, IPKG_NOTICE,
  4518. + "Reinstalling %s (%s) on %s...\n",
  4519. + pkg->name, new_version, old_pkg->dest->name);
  4520. + pkg->dest = old_pkg->dest;
  4521. + rc = 0;
  4522. + } else {
  4523. + ipkg_message(conf, IPKG_NOTICE,
  4524. + "Not installing %s (%s) on %s -- already installed.\n",
  4525. + pkg->name, new_version, old_pkg->dest->name);
  4526. + rc = 1;
  4527. + }
  4528. + }
  4529. + free(old_version);
  4530. + free(new_version);
  4531. + return rc;
  4532. + } else {
  4533. + char message_out[15], *version ;
  4534. + memset(message_out,'\x0',15);
  4535. + if ( message )
  4536. + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
  4537. + else
  4538. + strncpy( message_out,"Installing ",strlen("Installing ") );
  4539. + version = pkg_version_str_alloc(pkg);
  4540. +
  4541. + ipkg_message(conf, IPKG_NOTICE,
  4542. + "%s%s (%s) to %s...\n", message_out,
  4543. + pkg->name, version, pkg->dest->name);
  4544. + free(version);
  4545. + return 0;
  4546. + }
  4547. +}
  4548. +
  4549. +/* and now the meat... */
  4550. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
  4551. +{
  4552. + int err = 0;
  4553. + int message = 0;
  4554. + pkg_t *old_pkg = NULL;
  4555. + pkg_vec_t *replacees;
  4556. + abstract_pkg_t *ab_pkg = NULL;
  4557. + int old_state_flag;
  4558. + uint8_t *file_md5;
  4559. +
  4560. +
  4561. + if ( from_upgrade )
  4562. + message = 1; /* Coming from an upgrade, and should change the output message */
  4563. +
  4564. + if (!pkg) {
  4565. + ipkg_message(conf, IPKG_ERROR,
  4566. + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
  4567. + return -EINVAL;
  4568. + }
  4569. +
  4570. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
  4571. +
  4572. + if (!pkg_arch_supported(conf, pkg)) {
  4573. + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
  4574. + pkg->architecture, pkg->name);
  4575. + return -EINVAL;
  4576. + }
  4577. + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
  4578. + err = satisfy_dependencies_for(conf, pkg);
  4579. + if (err) { return err; }
  4580. +
  4581. + ipkg_message(conf, IPKG_NOTICE,
  4582. + "Package %s is already installed in %s.\n",
  4583. + pkg->name, pkg->dest->name);
  4584. + return 0;
  4585. + }
  4586. +
  4587. + if (pkg->dest == NULL) {
  4588. + pkg->dest = conf->default_dest;
  4589. + }
  4590. +
  4591. + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  4592. +
  4593. + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
  4594. + if (err) { return err; }
  4595. +
  4596. + pkg->state_want = SW_INSTALL;
  4597. + if (old_pkg){
  4598. + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
  4599. + }
  4600. +
  4601. +
  4602. + /* Abhaya: conflicts check */
  4603. + err = check_conflicts_for(conf, pkg);
  4604. + if (err) { return err; }
  4605. +
  4606. + /* this setup is to remove the upgrade scenario in the end when
  4607. + installing pkg A, A deps B & B deps on A. So both B and A are
  4608. + installed. Then A's installation is started resulting in an
  4609. + uncecessary upgrade */
  4610. + if (pkg->state_status == SS_INSTALLED
  4611. + && conf->force_reinstall == 0) return 0;
  4612. +
  4613. + err = verify_pkg_installable(conf, pkg);
  4614. + if (err) { return err; }
  4615. +
  4616. + if (pkg->local_filename == NULL) {
  4617. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  4618. + if (err) {
  4619. + ipkg_message(conf, IPKG_ERROR,
  4620. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  4621. + pkg->name);
  4622. + return err;
  4623. + }
  4624. + }
  4625. +
  4626. +/* Check for md5 values */
  4627. + if (pkg->md5sum)
  4628. + {
  4629. + file_md5 = file_md5sum_alloc(pkg->local_filename);
  4630. + if (strcmp((char *)file_md5, pkg->md5sum))
  4631. + {
  4632. + ipkg_message(conf, IPKG_ERROR,
  4633. + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
  4634. + pkg->name);
  4635. + free(file_md5);
  4636. + return err;
  4637. + }
  4638. + free(file_md5);
  4639. + }
  4640. +
  4641. + if (pkg->tmp_unpack_dir == NULL) {
  4642. + unpack_pkg_control_files(conf, pkg);
  4643. + }
  4644. +
  4645. + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
  4646. +/* Pigi: check if it will pass from here when replacing. It seems to fail */
  4647. +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
  4648. + err = update_file_ownership(conf, pkg, old_pkg);
  4649. + if (err) { return err; }
  4650. +
  4651. + if (conf->nodeps == 0) {
  4652. + err = satisfy_dependencies_for(conf, pkg);
  4653. + if (err) { return err; }
  4654. + }
  4655. +
  4656. + replacees = pkg_vec_alloc();
  4657. + pkg_get_installed_replacees(pkg, replacees);
  4658. +
  4659. + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
  4660. + {
  4661. + sigset_t newset, oldset;
  4662. + sighandler_t old_handler = NULL;
  4663. + int use_signal = 0;
  4664. + caught_sigint = 0;
  4665. + if (use_signal) {
  4666. + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
  4667. + } else {
  4668. + sigemptyset(&newset);
  4669. + sigaddset(&newset, SIGINT);
  4670. + sigprocmask(SIG_BLOCK, &newset, &oldset);
  4671. + }
  4672. +
  4673. + ipkg_state_changed++;
  4674. + pkg->state_flag |= SF_FILELIST_CHANGED;
  4675. +
  4676. + /* XXX: BUG: we really should treat replacement more like an upgrade
  4677. + * Instead, we're going to remove the replacees
  4678. + */
  4679. + err = pkg_remove_installed_replacees(conf, replacees);
  4680. + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
  4681. +
  4682. + /*
  4683. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  4684. + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
  4685. +
  4686. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  4687. + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
  4688. + */
  4689. +
  4690. + err = preinst_configure(conf, pkg, old_pkg);
  4691. + /*
  4692. + if (err) goto UNWIND_PREINST_CONFIGURE;
  4693. + */
  4694. +
  4695. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  4696. + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
  4697. +
  4698. + err = check_data_file_clashes(conf, pkg, old_pkg);
  4699. + /*
  4700. + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
  4701. +
  4702. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  4703. + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
  4704. + */
  4705. +
  4706. + if (conf->noaction) return 0;
  4707. +
  4708. + /* point of no return: no unwinding after this */
  4709. + if (old_pkg && !conf->force_reinstall) {
  4710. + old_pkg->state_want = SW_DEINSTALL;
  4711. +
  4712. + if (old_pkg->state_flag & SF_NOPRUNE) {
  4713. + ipkg_message(conf, IPKG_INFO,
  4714. + " not removing obsolesced files because package marked noprune\n");
  4715. + } else {
  4716. + ipkg_message(conf, IPKG_INFO,
  4717. + " removing obsolesced files\n");
  4718. + remove_obsolesced_files(conf, pkg, old_pkg);
  4719. + }
  4720. + /* removing files from old package, to avoid ghost files */
  4721. + remove_data_files_and_list(conf, old_pkg);
  4722. +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
  4723. + remove_maintainer_scripts_except_postrm(conf, old_pkg);
  4724. + remove_postrm(conf, old_pkg);
  4725. +/* Pigi */
  4726. +
  4727. + }
  4728. +
  4729. +
  4730. + ipkg_message(conf, IPKG_INFO,
  4731. + " installing maintainer scripts\n");
  4732. + install_maintainer_scripts(conf, pkg, old_pkg);
  4733. +
  4734. + /* the following just returns 0
  4735. + remove_disappeared(conf, pkg);
  4736. + */
  4737. +
  4738. + ipkg_message(conf, IPKG_INFO,
  4739. + " installing data files\n");
  4740. + install_data_files(conf, pkg);
  4741. +
  4742. +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
  4743. + err = check_data_file_clashes_change(conf, pkg);
  4744. +
  4745. + ipkg_message(conf, IPKG_INFO,
  4746. + " resolving conf files\n");
  4747. + resolve_conffiles(conf, pkg);
  4748. +
  4749. + pkg->state_status = SS_UNPACKED;
  4750. + old_state_flag = pkg->state_flag;
  4751. + pkg->state_flag &= ~SF_PREFER;
  4752. + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
  4753. +
  4754. + if (old_pkg && !conf->force_reinstall) {
  4755. + old_pkg->state_status = SS_NOT_INSTALLED;
  4756. + }
  4757. +
  4758. + time(&pkg->installed_time);
  4759. +
  4760. + ipkg_message(conf, IPKG_INFO,
  4761. + " cleanup temp files\n");
  4762. + cleanup_temporary_files(conf, pkg);
  4763. +
  4764. + ab_pkg = pkg->parent;
  4765. + if (ab_pkg)
  4766. + ab_pkg->state_status = pkg->state_status;
  4767. +
  4768. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  4769. +
  4770. + if (use_signal)
  4771. + signal(SIGINT, old_handler);
  4772. + else
  4773. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4774. +
  4775. + return 0;
  4776. +
  4777. +
  4778. + /*
  4779. + UNWIND_POSTRM_UPGRADE_OLD_PKG:
  4780. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4781. + UNWIND_CHECK_DATA_FILE_CLASHES:
  4782. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  4783. + */
  4784. + UNWIND_BACKUP_MODIFIED_CONFFILES:
  4785. + backup_modified_conffiles_unwind(pkg, old_pkg);
  4786. + /*
  4787. + UNWIND_PREINST_CONFIGURE:
  4788. + preinst_configure_unwind(conf, pkg, old_pkg);
  4789. + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
  4790. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  4791. + UNWIND_PRERM_UPGRADE_OLD_PKG:
  4792. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4793. + */
  4794. + UNWIND_REMOVE_INSTALLED_REPLACEES:
  4795. + pkg_remove_installed_replacees_unwind(conf, replacees);
  4796. +
  4797. + ipkg_message(conf, IPKG_INFO,
  4798. + " cleanup temp files\n");
  4799. + cleanup_temporary_files(conf, pkg);
  4800. +
  4801. + ipkg_message(conf, IPKG_INFO,
  4802. + "Failed.\n");
  4803. + if (use_signal)
  4804. + signal(SIGINT, old_handler);
  4805. + else
  4806. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4807. +
  4808. + return err;
  4809. + }
  4810. +}
  4811. +
  4812. +/*
  4813. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4814. +{
  4815. + DPKG_INCOMPATIBILITY:
  4816. + dpkg does some things here that we don't do yet. Do we care?
  4817. +
  4818. + 1. If a version of the package is already installed, call
  4819. + old-prerm upgrade new-version
  4820. + 2. If the script runs but exits with a non-zero exit status
  4821. + new-prerm failed-upgrade old-version
  4822. + Error unwind, for both the above cases:
  4823. + old-postinst abort-upgrade new-version
  4824. + return 0;
  4825. +}
  4826. +*/
  4827. +
  4828. +/*
  4829. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4830. +{
  4831. + DPKG_INCOMPATIBILITY:
  4832. + dpkg does some things here that we don't do yet. Do we care?
  4833. + (See prerm_upgrade_old_package for details)
  4834. +
  4835. + return 0;
  4836. +}
  4837. +*/
  4838. +
  4839. +/*
  4840. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4841. +{
  4842. + DPKG_INCOMPATIBILITY:
  4843. + dpkg does some things here that we don't do yet. Do we care?
  4844. + 2. If a 'conflicting' package is being removed at the same time:
  4845. + 1. If any packages depended on that conflicting package and
  4846. + --auto-deconfigure is specified, call, for each such package:
  4847. + deconfigured's-prerm deconfigure \
  4848. + in-favour package-being-installed version \
  4849. + removing conflicting-package version
  4850. + Error unwind:
  4851. + deconfigured's-postinst abort-deconfigure \
  4852. + in-favour package-being-installed-but-failed version \
  4853. + removing conflicting-package version
  4854. +
  4855. + The deconfigured packages are marked as requiring
  4856. + configuration, so that if --install is used they will be
  4857. + configured again if possible.
  4858. + 2. To prepare for removal of the conflicting package, call:
  4859. + conflictor's-prerm remove in-favour package new-version
  4860. + Error unwind:
  4861. + conflictor's-postinst abort-remove in-favour package new-version
  4862. + return 0;
  4863. +}
  4864. +*/
  4865. +
  4866. +/*
  4867. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4868. +{
  4869. + DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
  4870. + do yet. Do we care? (See prerm_deconfigure_conflictors for
  4871. + details)
  4872. + return 0;
  4873. +}
  4874. +*/
  4875. +
  4876. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4877. +{
  4878. + int err;
  4879. + char *preinst_args;
  4880. +
  4881. + if (old_pkg) {
  4882. + char *old_version = pkg_version_str_alloc(old_pkg);
  4883. + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
  4884. + free(old_version);
  4885. + } else if (pkg->state_status == SS_CONFIG_FILES) {
  4886. + char *pkg_version = pkg_version_str_alloc(pkg);
  4887. + sprintf_alloc(&preinst_args, "install %s", pkg_version);
  4888. + free(pkg_version);
  4889. + } else {
  4890. + preinst_args = strdup("install");
  4891. + }
  4892. +
  4893. + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
  4894. + if (err) {
  4895. + ipkg_message(conf, IPKG_ERROR,
  4896. + "Aborting installation of %s\n", pkg->name);
  4897. + return 1;
  4898. + }
  4899. +
  4900. + free(preinst_args);
  4901. +
  4902. + return 0;
  4903. +}
  4904. +
  4905. +/*
  4906. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4907. +{
  4908. + DPKG_INCOMPATIBILITY:
  4909. + dpkg does the following error unwind, should we?
  4910. + pkg->postrm abort-upgrade old-version
  4911. + OR pkg->postrm abort-install old-version
  4912. + OR pkg->postrm abort-install
  4913. + return 0;
  4914. +}
  4915. +*/
  4916. +
  4917. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4918. +{
  4919. + int err;
  4920. + conffile_list_elt_t *iter;
  4921. + conffile_t *cf;
  4922. +
  4923. + if (conf->noaction) return 0;
  4924. +
  4925. + /* Backup all modified conffiles */
  4926. + if (old_pkg) {
  4927. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4928. + char *cf_name;
  4929. +
  4930. + cf = iter->data;
  4931. + cf_name = root_filename_alloc(conf, cf->name);
  4932. +
  4933. + /* Don't worry if the conffile is just plain gone */
  4934. + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
  4935. + err = backup_make_backup(conf, cf_name);
  4936. + if (err) {
  4937. + return err;
  4938. + }
  4939. + }
  4940. + free(cf_name);
  4941. + }
  4942. + }
  4943. +
  4944. + /* Backup all conffiles that were not conffiles in old_pkg */
  4945. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4946. + char *cf_name;
  4947. + cf = iter->data;
  4948. + cf_name = root_filename_alloc(conf, cf->name);
  4949. + /* Ignore if this was a conffile in old_pkg as well */
  4950. + if (pkg_get_conffile(old_pkg, cf->name)) {
  4951. + continue;
  4952. + }
  4953. +
  4954. + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
  4955. + err = backup_make_backup(conf, cf_name);
  4956. + if (err) {
  4957. + return err;
  4958. + }
  4959. + }
  4960. + free(cf_name);
  4961. + }
  4962. +
  4963. + return 0;
  4964. +}
  4965. +
  4966. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg)
  4967. +{
  4968. + conffile_list_elt_t *iter;
  4969. +
  4970. + if (old_pkg) {
  4971. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4972. + backup_remove(iter->data->name);
  4973. + }
  4974. + }
  4975. +
  4976. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4977. + backup_remove(iter->data->name);
  4978. + }
  4979. +
  4980. + return 0;
  4981. +}
  4982. +
  4983. +
  4984. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4985. +{
  4986. + /* DPKG_INCOMPATIBILITY:
  4987. + ipkg takes a slightly different approach than dpkg at this
  4988. + point. dpkg installs each file in the new package while
  4989. + creating a backup for any file that is replaced, (so that it
  4990. + can unwind if necessary). To avoid complexity and redundant
  4991. + storage, ipkg doesn't do any installation until later, (at the
  4992. + point at which dpkg removes the backups.
  4993. +
  4994. + But, we do have to check for data file clashes, since after
  4995. + installing a package with a file clash, removing either of the
  4996. + packages involved in the clash has the potential to break the
  4997. + other package.
  4998. + */
  4999. + str_list_t *files_list;
  5000. + str_list_elt_t *iter;
  5001. +
  5002. + int clashes = 0;
  5003. +
  5004. + files_list = pkg_get_installed_files(pkg);
  5005. + for (iter = files_list->head; iter; iter = iter->next) {
  5006. + char *root_filename;
  5007. + char *filename = iter->data;
  5008. + root_filename = root_filename_alloc(conf, filename);
  5009. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5010. + pkg_t *owner;
  5011. + pkg_t *obs;
  5012. + /* Pre-existing conffiles are OK */
  5013. + /* @@@@ should have way to check that it is a conffile -Jamey */
  5014. + if (backup_exists_for(root_filename)) {
  5015. + continue;
  5016. + }
  5017. +
  5018. + /* Pre-existing files are OK if force-overwrite was asserted. */
  5019. + if (conf->force_overwrite) {
  5020. + /* but we need to change who owns this file */
  5021. + file_hash_set_file_owner(conf, filename, pkg);
  5022. + continue;
  5023. + }
  5024. +
  5025. + owner = file_hash_get_file_owner(conf, filename);
  5026. +
  5027. + /* Pre-existing files are OK if owned by the pkg being upgraded. */
  5028. + if (owner && old_pkg) {
  5029. + if (strcmp(owner->name, old_pkg->name) == 0) {
  5030. + continue;
  5031. + }
  5032. + }
  5033. +
  5034. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5035. + if (owner) {
  5036. + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
  5037. + if (pkg_replaces(pkg, owner)) {
  5038. + continue;
  5039. + }
  5040. +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
  5041. + then it's ok to overwrite. */
  5042. + if (strcmp(owner->name,pkg->name)==0){
  5043. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5044. + continue;
  5045. + }
  5046. + }
  5047. +
  5048. + /* Pre-existing files are OK if they are obsolete */
  5049. + obs = hash_table_get(&conf->obs_file_hash, filename);
  5050. + if (obs) {
  5051. + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
  5052. + continue;
  5053. + }
  5054. +
  5055. + /* We have found a clash. */
  5056. + ipkg_message(conf, IPKG_ERROR,
  5057. + "Package %s wants to install file %s\n"
  5058. + "\tBut that file is already provided by package ",
  5059. + pkg->name, filename);
  5060. + if (owner) {
  5061. + ipkg_message(conf, IPKG_ERROR,
  5062. + "%s\n", owner->name);
  5063. + } else {
  5064. + ipkg_message(conf, IPKG_ERROR,
  5065. + "<no package>\nPlease move this file out of the way and try again.\n");
  5066. + }
  5067. + clashes++;
  5068. + }
  5069. + free(root_filename);
  5070. + }
  5071. + pkg_free_installed_files(pkg);
  5072. +
  5073. + return clashes;
  5074. +}
  5075. +
  5076. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg)
  5077. +{
  5078. + /* Basically that's the worst hack I could do to be able to change ownership of
  5079. + file list, but, being that we have no way to unwind the mods, due to structure
  5080. + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
  5081. + What we do here is change the ownership of file in hash if a replace ( or similar events
  5082. + happens )
  5083. + Only the action that are needed to change name should be considered.
  5084. + @@@ To change after 1.0 release.
  5085. + */
  5086. + str_list_t *files_list;
  5087. + str_list_elt_t *iter;
  5088. +
  5089. + int clashes = 0;
  5090. +
  5091. + files_list = pkg_get_installed_files(pkg);
  5092. + for (iter = files_list->head; iter; iter = iter->next) {
  5093. + char *root_filename;
  5094. + char *filename = iter->data;
  5095. + root_filename = root_filename_alloc(conf, filename);
  5096. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5097. + pkg_t *owner;
  5098. +
  5099. + if (conf->force_overwrite) {
  5100. + /* but we need to change who owns this file */
  5101. + file_hash_set_file_owner(conf, filename, pkg);
  5102. + continue;
  5103. + }
  5104. +
  5105. + owner = file_hash_get_file_owner(conf, filename);
  5106. +
  5107. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5108. + if (owner) {
  5109. + if (pkg_replaces(pkg, owner)) {
  5110. +/* It's now time to change the owner of that file.
  5111. + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
  5112. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5113. + file_hash_set_file_owner(conf, filename, pkg);
  5114. + continue;
  5115. + }
  5116. + }
  5117. +
  5118. + }
  5119. + free(root_filename);
  5120. + }
  5121. + pkg_free_installed_files(pkg);
  5122. +
  5123. + return clashes;
  5124. +}
  5125. +
  5126. +/*
  5127. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5128. +{
  5129. + Nothing to do since check_data_file_clashes doesn't change state
  5130. + return 0;
  5131. +}
  5132. +*/
  5133. +
  5134. +/*
  5135. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5136. +{
  5137. + DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
  5138. + 1. If the package is being upgraded, call
  5139. + old-postrm upgrade new-version
  5140. + 2. If this fails, attempt:
  5141. + new-postrm failed-upgrade old-version
  5142. + Error unwind, for both cases:
  5143. + old-preinst abort-upgrade new-version
  5144. + return 0;
  5145. +}
  5146. +*/
  5147. +
  5148. +/*
  5149. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5150. +{
  5151. + DPKG_INCOMPATIBILITY:
  5152. + dpkg does some things here that we don't do yet. Do we care?
  5153. + (See postrm_upgrade_old_pkg for details)
  5154. + return 0;
  5155. +}
  5156. +*/
  5157. +
  5158. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5159. +{
  5160. + int err;
  5161. + str_list_t *old_files;
  5162. + str_list_elt_t *of;
  5163. + str_list_t *new_files;
  5164. + str_list_elt_t *nf;
  5165. +
  5166. + if (old_pkg == NULL) {
  5167. + return 0;
  5168. + }
  5169. +
  5170. + old_files = pkg_get_installed_files(old_pkg);
  5171. + new_files = pkg_get_installed_files(pkg);
  5172. +
  5173. + for (of = old_files->head; of; of = of->next) {
  5174. + pkg_t *owner;
  5175. + char *old, *new;
  5176. + old = of->data;
  5177. + for (nf = new_files->head; nf; nf = nf->next) {
  5178. + new = nf->data;
  5179. + if (strcmp(old, new) == 0) {
  5180. + goto NOT_OBSOLETE;
  5181. + }
  5182. + }
  5183. + if (file_is_dir(old)) {
  5184. + continue;
  5185. + }
  5186. + owner = file_hash_get_file_owner(conf, old);
  5187. + if (owner != old_pkg) {
  5188. + /* in case obsolete file no longer belongs to old_pkg */
  5189. + continue;
  5190. + }
  5191. +
  5192. + /* old file is obsolete */
  5193. + ipkg_message(conf, IPKG_INFO,
  5194. + " removing obsolete file %s\n", old);
  5195. + if (!conf->noaction) {
  5196. + err = unlink(old);
  5197. + if (err) {
  5198. + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
  5199. + strerror(errno));
  5200. + }
  5201. + }
  5202. +
  5203. + NOT_OBSOLETE:
  5204. + ;
  5205. + }
  5206. +
  5207. + pkg_free_installed_files(old_pkg);
  5208. + pkg_free_installed_files(pkg);
  5209. +
  5210. + return 0;
  5211. +}
  5212. +
  5213. +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5214. +{
  5215. + int i;
  5216. + int err = 0;
  5217. + char *globpattern;
  5218. + glob_t globbuf;
  5219. + if (0) {
  5220. + if (!pkg->dest) {
  5221. + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
  5222. + return -1;
  5223. + }
  5224. + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
  5225. + err = glob(globpattern, 0, NULL, &globbuf);
  5226. + free(globpattern);
  5227. + if (err) {
  5228. + return err;
  5229. + }
  5230. + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
  5231. + for (i = 0; i < globbuf.gl_pathc; i++) {
  5232. + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
  5233. + globbuf.gl_pathv[i], old_pkg->name);
  5234. + if (!conf->noaction)
  5235. + unlink(globbuf.gl_pathv[i]);
  5236. + }
  5237. + globfree(&globbuf);
  5238. + }
  5239. + return err;
  5240. +}
  5241. +
  5242. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5243. +{
  5244. + int ret;
  5245. + char *prefix;
  5246. +
  5247. + if (old_pkg)
  5248. + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
  5249. + sprintf_alloc(&prefix, "%s.", pkg->name);
  5250. + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
  5251. + pkg->dest->info_dir,
  5252. + prefix);
  5253. + free(prefix);
  5254. + return ret;
  5255. +}
  5256. +
  5257. +/*
  5258. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
  5259. +{
  5260. + DPKG_INCOMPATIBILITY:
  5261. + This is a fairly sophisticated dpkg operation. Shall we
  5262. + skip it?
  5263. +
  5264. + Any packages all of whose files have been overwritten during the
  5265. + installation, and which aren't required for dependencies, are
  5266. + considered to have been removed. For each such package
  5267. + 1. disappearer's-postrm disappear overwriter overwriter-version
  5268. + 2. The package's maintainer scripts are removed
  5269. + 3. It is noted in the status database as being in a sane state,
  5270. + namely not installed (any conffiles it may have are ignored,
  5271. + rather than being removed by dpkg). Note that disappearing
  5272. + packages do not have their prerm called, because dpkg doesn't
  5273. + know in advance that the package is going to vanish.
  5274. +
  5275. +
  5276. + return 0;
  5277. +}
  5278. +*/
  5279. +
  5280. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
  5281. +{
  5282. + int err;
  5283. +
  5284. + /* ipkg takes a slightly different approach to data file backups
  5285. + than dpkg. Rather than removing backups at this point, we
  5286. + actually do the data file installation now. See comments in
  5287. + check_data_file_clashes() for more details. */
  5288. +
  5289. + ipkg_message(conf, IPKG_INFO,
  5290. + " extracting data files to %s\n", pkg->dest->root_dir);
  5291. + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
  5292. + if (err) {
  5293. + return err;
  5294. + }
  5295. +
  5296. + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
  5297. + so we can't save ourself from removing important packages
  5298. + At this point we (should) have extracted the .control file, so it
  5299. + would be a good idea to reload the data in it, and set the Essential
  5300. + state in *pkg. From now on the Essential is back in status file and
  5301. + we can protect again.
  5302. + We should operate this way:
  5303. + fopen the file ( pkg->dest->root_dir/pkg->name.control )
  5304. + check for "Essential" in it
  5305. + set the value in pkg->essential.
  5306. + This new routine could be useful also for every other flag
  5307. + Pigi: 16/03/2004 */
  5308. + set_flags_from_control(conf, pkg) ;
  5309. +
  5310. + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
  5311. + err = pkg_write_filelist(conf, pkg);
  5312. + if (err)
  5313. + return err;
  5314. +
  5315. + /* XXX: FEATURE: ipkg should identify any files which existed
  5316. + before installation and which were overwritten, (see
  5317. + check_data_file_clashes()). What it must do is remove any such
  5318. + files from the filelist of the old package which provided the
  5319. + file. Otherwise, if the old package were removed at some point
  5320. + it would break the new package. Removing the new package will
  5321. + also break the old one, but this cannot be helped since the old
  5322. + package's file has already been deleted. This is the importance
  5323. + of check_data_file_clashes(), and only allowing ipkg to install
  5324. + a clashing package with a user force. */
  5325. +
  5326. + return 0;
  5327. +}
  5328. +
  5329. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
  5330. +{
  5331. + conffile_list_elt_t *iter;
  5332. + conffile_t *cf;
  5333. + char *cf_backup;
  5334. + uint8_t *md5sum;
  5335. +
  5336. +
  5337. + if (conf->noaction) return 0;
  5338. +
  5339. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  5340. + char *root_filename;
  5341. + cf = iter->data;
  5342. + root_filename = root_filename_alloc(conf, cf->name);
  5343. +
  5344. + /* Might need to initialize the md5sum for each conffile */
  5345. + if (cf->value == NULL) {
  5346. + cf->value = (char *)file_md5sum_alloc(root_filename);
  5347. + }
  5348. +
  5349. + if (!file_exists(root_filename)) {
  5350. + free(root_filename);
  5351. + continue;
  5352. + }
  5353. +
  5354. + cf_backup = backup_filename_alloc(root_filename);
  5355. +
  5356. +
  5357. + if (file_exists(cf_backup)) {
  5358. + /* Let's compute md5 to test if files are changed */
  5359. + md5sum = file_md5sum_alloc(cf_backup);
  5360. + if (strcmp( cf->value, (char *)md5sum) != 0 ) {
  5361. + if (conf->force_defaults
  5362. + || user_prefers_old_conffile(cf->name, cf_backup) ) {
  5363. + rename(cf_backup, root_filename);
  5364. + }
  5365. + }
  5366. + unlink(cf_backup);
  5367. + free(md5sum);
  5368. + }
  5369. +
  5370. + free(cf_backup);
  5371. + free(root_filename);
  5372. + }
  5373. +
  5374. + return 0;
  5375. +}
  5376. +
  5377. +static int user_prefers_old_conffile(const char *file_name, const char *backup)
  5378. +{
  5379. + char *response;
  5380. + const char *short_file_name;
  5381. +
  5382. + short_file_name = strrchr(file_name, '/');
  5383. + if (short_file_name) {
  5384. + short_file_name++;
  5385. + } else {
  5386. + short_file_name = file_name;
  5387. + }
  5388. +
  5389. + while (1) {
  5390. + response = get_user_response(" Configuration file '%s'\n"
  5391. + " ==> File on system created by you or by a script.\n"
  5392. + " ==> File also in package provided by package maintainer.\n"
  5393. + " What would you like to do about it ? Your options are:\n"
  5394. + " Y or I : install the package maintainer's version\n"
  5395. + " N or O : keep your currently-installed version\n"
  5396. +#ifdef CONFIG_DIFF
  5397. + " D : show the differences between the versions\n"
  5398. +#endif
  5399. + " The default action is to keep your current version.\n"
  5400. + " *** %s (Y/I/N/O"
  5401. +#ifdef CONFIG_DIFF
  5402. + "/D"
  5403. +#endif
  5404. + ") [default=N] ? ", file_name, short_file_name);
  5405. + if (strcmp(response, "y") == 0
  5406. + || strcmp(response, "i") == 0
  5407. + || strcmp(response, "yes") == 0) {
  5408. + free(response);
  5409. + return 0;
  5410. + }
  5411. +
  5412. +#ifdef CONFIG_DIFF
  5413. + if (strcmp(response, "d") == 0) {
  5414. + char *cmd;
  5415. +
  5416. + free(response);
  5417. + /* XXX: BUG rewrite to use exec or busybox's internal diff */
  5418. + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
  5419. + xsystem(cmd);
  5420. + free(cmd);
  5421. + printf(" [Press ENTER to continue]\n");
  5422. + response = file_read_line_alloc(stdin);
  5423. + free(response);
  5424. + continue;
  5425. + }
  5426. +#endif
  5427. +
  5428. + free(response);
  5429. + return 1;
  5430. + }
  5431. +}
  5432. +
  5433. +/* XXX: CLEANUP: I'd like to move all of the code for
  5434. + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
  5435. + it would make sense to cleanup pkg->tmp_unpack_dir directly from
  5436. + pkg_deinit for example). */
  5437. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
  5438. +{
  5439. + DIR *tmp_dir;
  5440. + struct dirent *dirent;
  5441. + char *tmp_file;
  5442. +
  5443. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  5444. +#error
  5445. + ipkg_message(conf, IPKG_DEBUG,
  5446. + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  5447. + __FUNCTION__, pkg->tmp_unpack_dir);
  5448. + return 0;
  5449. +#endif
  5450. +
  5451. + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
  5452. + tmp_dir = opendir(pkg->tmp_unpack_dir);
  5453. + if (tmp_dir) {
  5454. + while (1) {
  5455. + dirent = readdir(tmp_dir);
  5456. + if (dirent == NULL) {
  5457. + break;
  5458. + }
  5459. + sprintf_alloc(&tmp_file, "%s/%s",
  5460. + pkg->tmp_unpack_dir, dirent->d_name);
  5461. + if (! file_is_dir(tmp_file)) {
  5462. + unlink(tmp_file);
  5463. + }
  5464. + free(tmp_file);
  5465. + }
  5466. + closedir(tmp_dir);
  5467. + rmdir(pkg->tmp_unpack_dir);
  5468. + free(pkg->tmp_unpack_dir);
  5469. + pkg->tmp_unpack_dir = NULL;
  5470. + }
  5471. + }
  5472. +
  5473. + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
  5474. + pkg->name, pkg->local_filename, conf->tmp_dir);
  5475. + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
  5476. + unlink(pkg->local_filename);
  5477. + free(pkg->local_filename);
  5478. + pkg->local_filename = NULL;
  5479. + }
  5480. +
  5481. + return 0;
  5482. +}
  5483. +
  5484. +static char *backup_filename_alloc(const char *file_name)
  5485. +{
  5486. + char *backup;
  5487. +
  5488. + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
  5489. +
  5490. + return backup;
  5491. +}
  5492. +
  5493. +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
  5494. +{
  5495. + int err;
  5496. + char *backup;
  5497. +
  5498. + backup = backup_filename_alloc(file_name);
  5499. + err = file_copy(file_name, backup);
  5500. + if (err) {
  5501. + ipkg_message(conf, IPKG_ERROR,
  5502. + "%s: Failed to copy %s to %s\n",
  5503. + __FUNCTION__, file_name, backup);
  5504. + }
  5505. +
  5506. + free(backup);
  5507. +
  5508. + return err;
  5509. +}
  5510. +
  5511. +static int backup_exists_for(const char *file_name)
  5512. +{
  5513. + int ret;
  5514. + char *backup;
  5515. +
  5516. + backup = backup_filename_alloc(file_name);
  5517. +
  5518. + ret = file_exists(backup);
  5519. +
  5520. + free(backup);
  5521. +
  5522. + return ret;
  5523. +}
  5524. +
  5525. +static int backup_remove(const char *file_name)
  5526. +{
  5527. + char *backup;
  5528. +
  5529. + backup = backup_filename_alloc(file_name);
  5530. + unlink(backup);
  5531. + free(backup);
  5532. +
  5533. + return 0;
  5534. +}
  5535. +
  5536. +
  5537. +
  5538. +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
  5539. +
  5540. +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
  5541. +{
  5542. + /* first, remove the packages that need removing */
  5543. + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
  5544. + pkg_t *pkg = pkgs_to_remove->pkgs[i];
  5545. + err = ipkg_remove_pkg(conf, pkg,0);
  5546. + if (err) return err;
  5547. + }
  5548. + return 0;
  5549. +}
  5550. +
  5551. +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)
  5552. +{
  5553. + int i;
  5554. + /* now one more pass checking on the ones that need to be installed */
  5555. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5556. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5557. + if (pkg->dest == NULL)
  5558. + pkg->dest = conf->default_dest;
  5559. +
  5560. + pkg->state_want = SW_INSTALL;
  5561. +
  5562. + /* Abhaya: conflicts check */
  5563. + err = check_conflicts_for(conf, pkg);
  5564. + if (err) { return err; }
  5565. + }
  5566. + return 0;
  5567. +}
  5568. +
  5569. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5570. +{
  5571. + int i;
  5572. + /* now one more pass checking on the ones that need to be installed */
  5573. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5574. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5575. +
  5576. + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
  5577. + pkg_vec_t *replacees = pkg_vec_alloc();
  5578. + pkg_get_installed_replacees(pkg, replacees);
  5579. +
  5580. + /* XXX: BUG: we really should treat replacement more like an upgrade
  5581. + * Instead, we're going to remove the replacees
  5582. + */
  5583. + err = pkg_remove_installed_replacees(conf, replacees);
  5584. + if (err) return err;
  5585. + pkg->state_flag |= SF_REMOVED_REPLACEES;
  5586. + }
  5587. + return 0;
  5588. +}
  5589. +
  5590. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5591. +{
  5592. + int i;
  5593. + /* now one more pass checking on the ones that need to be installed */
  5594. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5595. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5596. + if (pkg->local_filename == NULL) {
  5597. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  5598. + if (err) {
  5599. + ipkg_message(conf, IPKG_ERROR,
  5600. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  5601. + pkg->name);
  5602. + return err;
  5603. + }
  5604. + }
  5605. + if (pkg->tmp_unpack_dir == NULL) {
  5606. + err = unpack_pkg_control_files(conf, pkg);
  5607. + if (err) return err;
  5608. + }
  5609. + }
  5610. + return 0;
  5611. +}
  5612. +
  5613. +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5614. +{
  5615. + int i;
  5616. + /* now one more pass checking on the ones that need to be installed */
  5617. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5618. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5619. + pkg_t *old_pkg = pkg->old_pkg;
  5620. +
  5621. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  5622. + if (err) return err;
  5623. +
  5624. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  5625. + if (err) return err;
  5626. +
  5627. + err = preinst_configure(conf, pkg, old_pkg);
  5628. + if (err) return err;
  5629. +
  5630. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  5631. + if (err) return err;
  5632. +
  5633. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  5634. + if (err) return err;
  5635. + }
  5636. + return 0;
  5637. +}
  5638. +
  5639. +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5640. +{
  5641. + int i;
  5642. + /* now one more pass checking on the ones that need to be installed */
  5643. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5644. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5645. + pkg_t *old_pkg = pkg->old_pkg;
  5646. +
  5647. + if (old_pkg) {
  5648. + old_pkg->state_want = SW_DEINSTALL;
  5649. +
  5650. + if (old_pkg->state_flag & SF_NOPRUNE) {
  5651. + ipkg_message(conf, IPKG_INFO,
  5652. + " not removing obsolesced files because package marked noprune\n");
  5653. + } else {
  5654. + ipkg_message(conf, IPKG_INFO,
  5655. + " removing obsolesced files\n");
  5656. + remove_obsolesced_files(conf, pkg, old_pkg);
  5657. + }
  5658. + }
  5659. +
  5660. + ipkg_message(conf, IPKG_INFO,
  5661. + " installing maintainer scripts\n");
  5662. + install_maintainer_scripts(conf, pkg, old_pkg);
  5663. +
  5664. + /* the following just returns 0 */
  5665. + remove_disappeared(conf, pkg);
  5666. +
  5667. + ipkg_message(conf, IPKG_INFO,
  5668. + " installing data files\n");
  5669. + install_data_files(conf, pkg);
  5670. +
  5671. + ipkg_message(conf, IPKG_INFO,
  5672. + " resolving conf files\n");
  5673. + resolve_conffiles(conf, pkg);
  5674. +
  5675. + pkg->state_status = SS_UNPACKED;
  5676. +
  5677. + if (old_pkg) {
  5678. + old_pkg->state_status = SS_NOT_INSTALLED;
  5679. + }
  5680. +
  5681. + time(&pkg->installed_time);
  5682. +
  5683. + ipkg_message(conf, IPKG_INFO,
  5684. + " cleanup temp files\n");
  5685. + cleanup_temporary_files(conf, pkg);
  5686. +
  5687. + if (pkg->parent)
  5688. + pkg->parent->state_status = pkg->state_status;
  5689. + }
  5690. + return 0;
  5691. +}
  5692. +
  5693. +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5694. +{
  5695. + int i;
  5696. + /* now one more pass checking on the ones that need to be installed */
  5697. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5698. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5699. + pkg_t *old_pkg = pkg->old_pkg;
  5700. +
  5701. + if (old_pkg) {
  5702. + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
  5703. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5704. + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
  5705. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  5706. + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
  5707. + backup_modified_conffiles_unwind(pkg, old_pkg);
  5708. + */
  5709. + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
  5710. + preinst_configure_unwind(conf, pkg, old_pkg);
  5711. + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
  5712. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  5713. + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
  5714. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5715. + */
  5716. +
  5717. + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
  5718. + remove_installed_replacees_unwind(conf, pkg, old_pkg);
  5719. +
  5720. + }
  5721. + }
  5722. + return 0;
  5723. +}
  5724. +
  5725. +/*
  5726. + * Perform all the actions.
  5727. + *
  5728. + * pkgs_to_remove are packages marked for removal.
  5729. + * pkgs_superseded are the old packages being replaced by upgrades.
  5730. + *
  5731. + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
  5732. + */
  5733. +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)
  5734. +{
  5735. + int err;
  5736. + int i;
  5737. +
  5738. + err = ipkg_remove_packages(conf, pkgs_to_remove);
  5739. + if (err) return err;
  5740. +
  5741. + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
  5742. + if (err) return err;
  5743. +
  5744. + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
  5745. + if (err) goto UNWIND;
  5746. +
  5747. + /* @@@@ look at ipkg_install_pkg for handling replacements */
  5748. + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
  5749. + if (err) goto UNWIND;
  5750. +
  5751. + /*
  5752. + * Now that we have the packages unpacked, we can look for data
  5753. + * file clashes. First, we mark the files from the superseded
  5754. + * packages as obsolete. Then we scan the files in
  5755. + * pkgs_to_install, and only complain about clashes with
  5756. + * non-obsolete files.
  5757. + */
  5758. +
  5759. + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
  5760. + if (err) goto UNWIND;
  5761. +
  5762. + /* this was before checking data file clashes */
  5763. + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
  5764. + if (err) goto UNWIND;
  5765. +
  5766. + /* point of no return: no unwinding after this */
  5767. + err = ipkg_process_actions_install(conf, pkgs_to_install);
  5768. + if (err) return err;
  5769. +
  5770. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  5771. + return 0;
  5772. +
  5773. + UNWIND:
  5774. + ipkg_process_actions_unwind(conf, pkgs_to_install);
  5775. +
  5776. + ipkg_message(conf, IPKG_INFO,
  5777. + " cleanup temp files\n");
  5778. + cleanup_temporary_files(conf, pkg);
  5779. +
  5780. + ipkg_message(conf, IPKG_INFO,
  5781. + "Failed.\n");
  5782. + return err;
  5783. +}
  5784. +
  5785. +#endif
  5786. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_install.h busybox-1.15.2/archival/libipkg/ipkg_install.h
  5787. --- busybox-1.15.2.orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
  5788. +++ busybox-1.15.2/archival/libipkg/ipkg_install.h 2009-11-26 11:10:13.699857638 +0100
  5789. @@ -0,0 +1,35 @@
  5790. +/* ipkg_install.h - the itsy package management system
  5791. +
  5792. + Carl D. Worth
  5793. +
  5794. + Copyright (C) 2001 University of Southern California
  5795. +
  5796. + This program is free software; you can redistribute it and/or
  5797. + modify it under the terms of the GNU General Public License as
  5798. + published by the Free Software Foundation; either version 2, or (at
  5799. + your option) any later version.
  5800. +
  5801. + This program is distributed in the hope that it will be useful, but
  5802. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5803. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5804. + General Public License for more details.
  5805. +*/
  5806. +
  5807. +#ifndef IPKG_INSTALL_H
  5808. +#define IPKG_INSTALL_H
  5809. +
  5810. +#include "pkg.h"
  5811. +#include "ipkg_conf.h"
  5812. +
  5813. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5814. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5815. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
  5816. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
  5817. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  5818. +
  5819. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
  5820. +
  5821. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
  5822. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
  5823. +
  5824. +#endif
  5825. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_message.c busybox-1.15.2/archival/libipkg/ipkg_message.c
  5826. --- busybox-1.15.2.orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
  5827. +++ busybox-1.15.2/archival/libipkg/ipkg_message.c 2009-11-26 11:10:13.699857638 +0100
  5828. @@ -0,0 +1,61 @@
  5829. +/* ipkg_message.c - the itsy package management system
  5830. +
  5831. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5832. +
  5833. + This program is free software; you can redistribute it and/or
  5834. + modify it under the terms of the GNU General Public License as
  5835. + published by the Free Software Foundation; either version 2, or (at
  5836. + your option) any later version.
  5837. +
  5838. + This program is distributed in the hope that it will be useful, but
  5839. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5840. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5841. + General Public License for more details.
  5842. +*/
  5843. +
  5844. +
  5845. +#include "ipkg.h"
  5846. +#include "ipkg_conf.h"
  5847. +#include "ipkg_message.h"
  5848. +
  5849. +#ifndef IPKG_LIB
  5850. +
  5851. +void
  5852. +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
  5853. +{
  5854. + va_list ap;
  5855. +
  5856. + if (conf && (conf->verbosity < level))
  5857. + {
  5858. + return;
  5859. + }
  5860. + else
  5861. + {
  5862. +
  5863. + va_start (ap, fmt);
  5864. + vprintf (fmt, ap);
  5865. + va_end (ap);
  5866. + }
  5867. +}
  5868. +
  5869. +#else
  5870. +
  5871. +#include "libipkg.h"
  5872. +
  5873. +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
  5874. +
  5875. +void
  5876. +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
  5877. +{
  5878. + va_list ap;
  5879. + char ts[256];
  5880. +
  5881. + if (ipkg_cb_message)
  5882. + {
  5883. + va_start (ap, fmt);
  5884. + vsnprintf (ts,256,fmt, ap);
  5885. + va_end (ap);
  5886. + ipkg_cb_message(conf,level,ts);
  5887. + }
  5888. +}
  5889. +#endif
  5890. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_message.h busybox-1.15.2/archival/libipkg/ipkg_message.h
  5891. --- busybox-1.15.2.orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
  5892. +++ busybox-1.15.2/archival/libipkg/ipkg_message.h 2009-11-26 11:10:13.795857012 +0100
  5893. @@ -0,0 +1,32 @@
  5894. +/* ipkg_message.h - the itsy package management system
  5895. +
  5896. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5897. +
  5898. + This program is free software; you can redistribute it and/or
  5899. + modify it under the terms of the GNU General Public License as
  5900. + published by the Free Software Foundation; either version 2, or (at
  5901. + your option) any later version.
  5902. +
  5903. + This program is distributed in the hope that it will be useful, but
  5904. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5905. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5906. + General Public License for more details.
  5907. +*/
  5908. +
  5909. +#ifndef _IPKG_MESSAGE_H_
  5910. +#define _IPKG_MESSAGE_H_
  5911. +
  5912. +#include "ipkg.h"
  5913. +#include "ipkg_conf.h"
  5914. +
  5915. +typedef enum {
  5916. + IPKG_ERROR, /* error conditions */
  5917. + IPKG_NOTICE, /* normal but significant condition */
  5918. + IPKG_INFO, /* informational message */
  5919. + IPKG_DEBUG, /* debug level message */
  5920. + IPKG_DEBUG2, /* more debug level message */
  5921. +} message_level_t;
  5922. +
  5923. +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
  5924. +
  5925. +#endif /* _IPKG_MESSAGE_H_ */
  5926. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_remove.c busybox-1.15.2/archival/libipkg/ipkg_remove.c
  5927. --- busybox-1.15.2.orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
  5928. +++ busybox-1.15.2/archival/libipkg/ipkg_remove.c 2009-11-26 11:10:13.795857012 +0100
  5929. @@ -0,0 +1,385 @@
  5930. +/* ipkg_remove.c - the itsy package management system
  5931. +
  5932. + Carl D. Worth
  5933. +
  5934. + Copyright (C) 2001 University of Southern California
  5935. +
  5936. + This program is free software; you can redistribute it and/or
  5937. + modify it under the terms of the GNU General Public License as
  5938. + published by the Free Software Foundation; either version 2, or (at
  5939. + your option) any later version.
  5940. +
  5941. + This program is distributed in the hope that it will be useful, but
  5942. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5943. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5944. + General Public License for more details.
  5945. +*/
  5946. +
  5947. +#include "ipkg.h"
  5948. +#include "ipkg_message.h"
  5949. +
  5950. +#include <glob.h>
  5951. +
  5952. +#include "ipkg_remove.h"
  5953. +
  5954. +#include "file_util.h"
  5955. +#include "sprintf_alloc.h"
  5956. +#include "str_util.h"
  5957. +
  5958. +#include "ipkg_cmd.h"
  5959. +
  5960. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents);
  5961. +
  5962. +/*
  5963. + * Returns number of the number of packages depending on the packages provided by this package.
  5964. + * Every package implicitly provides itself.
  5965. + */
  5966. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents)
  5967. +{
  5968. + int nprovides = pkg->provides_count;
  5969. + abstract_pkg_t **provides = pkg->provides;
  5970. + int n_installed_dependents = 0;
  5971. + int i;
  5972. + for (i = 0; i <= nprovides; i++) {
  5973. + abstract_pkg_t *providee = provides[i];
  5974. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5975. + abstract_pkg_t *dep_ab_pkg;
  5976. + if (dependers == NULL)
  5977. + continue;
  5978. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5979. + if (dep_ab_pkg->state_status == SS_INSTALLED){
  5980. + n_installed_dependents++;
  5981. + }
  5982. + }
  5983. +
  5984. + }
  5985. + /* if caller requested the set of installed dependents */
  5986. + if (pdependents) {
  5987. + int p = 0;
  5988. + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
  5989. +
  5990. + if ( dependents == NULL ){
  5991. + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
  5992. + return -1;
  5993. + }
  5994. +
  5995. + *pdependents = dependents;
  5996. + for (i = 0; i <= nprovides; i++) {
  5997. + abstract_pkg_t *providee = provides[i];
  5998. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5999. + abstract_pkg_t *dep_ab_pkg;
  6000. + if (dependers == NULL)
  6001. + continue;
  6002. + while ((dep_ab_pkg = *dependers++) != NULL) {
  6003. + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
  6004. + dependents[p++] = dep_ab_pkg;
  6005. + dep_ab_pkg->state_flag |= SF_MARKED;
  6006. + }
  6007. + }
  6008. + }
  6009. + dependents[p] = NULL;
  6010. + /* now clear the marks */
  6011. + for (i = 0; i < p; i++) {
  6012. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  6013. + dep_ab_pkg->state_flag &= ~SF_MARKED;
  6014. + }
  6015. + }
  6016. + return n_installed_dependents;
  6017. +}
  6018. +
  6019. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  6020. +{
  6021. + int i;
  6022. + int a;
  6023. + int count;
  6024. + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
  6025. + abstract_pkg_t * ab_pkg;
  6026. +
  6027. + if((ab_pkg = pkg->parent) == NULL){
  6028. + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
  6029. + __FUNCTION__, pkg->name);
  6030. + return 0;
  6031. + }
  6032. +
  6033. + if (dependents == NULL)
  6034. + return 0;
  6035. +
  6036. + // here i am using the dependencies_checked
  6037. + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
  6038. + return 0; // has already been encountered in the process
  6039. + // of marking packages for removal - Karthik
  6040. + ab_pkg->dependencies_checked = 2;
  6041. +
  6042. + i = 0;
  6043. + count = 1;
  6044. + while (dependents [i] != NULL) {
  6045. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  6046. +
  6047. + if (dep_ab_pkg->dependencies_checked == 2){
  6048. + i++;
  6049. + continue;
  6050. + }
  6051. + if (dep_ab_pkg->state_status == SS_INSTALLED) {
  6052. + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
  6053. + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
  6054. + if (dep_pkg->state_status == SS_INSTALLED) {
  6055. + pkg_vec_insert(dependent_pkgs, dep_pkg);
  6056. + count++;
  6057. + }
  6058. + }
  6059. + }
  6060. + i++;
  6061. + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
  6062. + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
  6063. + }
  6064. +
  6065. + if (count == 1)
  6066. + return 0;
  6067. +
  6068. +
  6069. + for (i = 0; i < dependent_pkgs->len; i++) {
  6070. + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
  6071. + if (err)
  6072. + return err;
  6073. + }
  6074. + return 0;
  6075. +}
  6076. +
  6077. +static int user_prefers_removing_dependents(ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  6078. +{
  6079. + abstract_pkg_t *dep_ab_pkg;
  6080. + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
  6081. + while ((dep_ab_pkg = *dependents++) != NULL) {
  6082. + if (dep_ab_pkg->state_status == SS_INSTALLED)
  6083. + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
  6084. + }
  6085. + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
  6086. + ipkg_message(conf, IPKG_ERROR, "");
  6087. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
  6088. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
  6089. + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
  6090. + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
  6091. + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
  6092. + return 0;
  6093. +}
  6094. +
  6095. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
  6096. +{
  6097. +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
  6098. + thus I wan't check for essential, as I'm upgrading.
  6099. + I hope it won't break anything :)
  6100. +*/
  6101. + int err;
  6102. + abstract_pkg_t *parent_pkg = NULL;
  6103. +
  6104. + if (pkg->essential && !message) {
  6105. + if (conf->force_removal_of_essential_packages) {
  6106. + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
  6107. + "\tIf your system breaks, you get to keep both pieces\n",
  6108. + pkg->name);
  6109. + } else {
  6110. + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
  6111. + "\tRemoving an essential package may lead to an unusable system, but if\n"
  6112. + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
  6113. + "\tits will with the option: -force-removal-of-essential-packages\n",
  6114. + pkg->name);
  6115. + return IPKG_PKG_IS_ESSENTIAL;
  6116. + }
  6117. + }
  6118. +
  6119. + if ((parent_pkg = pkg->parent) == NULL)
  6120. + return 0;
  6121. +
  6122. + /* only attempt to remove dependent installed packages if
  6123. + * force_depends is not specified or the package is being
  6124. + * replaced.
  6125. + */
  6126. + if (!conf->force_depends
  6127. + && !(pkg->state_flag & SF_REPLACE)) {
  6128. + abstract_pkg_t **dependents;
  6129. + int has_installed_dependents =
  6130. + pkg_has_installed_dependents(pkg, &dependents);
  6131. +
  6132. + if (has_installed_dependents) {
  6133. + /*
  6134. + * if this package is depended up by others, then either we should
  6135. + * not remove it or we should remove it and all of its dependents
  6136. + */
  6137. +
  6138. + if (!conf->force_removal_of_dependent_packages
  6139. + && !user_prefers_removing_dependents(conf, pkg, dependents)) {
  6140. + return IPKG_PKG_HAS_DEPENDENTS;
  6141. + }
  6142. +
  6143. + /* remove packages depending on this package - Karthik */
  6144. + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
  6145. + free(dependents);
  6146. + if (err) return err;
  6147. + }
  6148. + }
  6149. +
  6150. + if ( message==0 ){
  6151. + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
  6152. + fflush(stdout);
  6153. + }
  6154. + pkg->state_flag |= SF_FILELIST_CHANGED;
  6155. +
  6156. + pkg->state_want = SW_DEINSTALL;
  6157. + ipkg_state_changed++;
  6158. +
  6159. + pkg_run_script(conf, pkg, "prerm", "remove");
  6160. +
  6161. + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
  6162. + maintains an empty filelist rather than deleting it. That seems
  6163. + like a big pain, and I don't see that that should make a big
  6164. + difference, but for anyone who wants tighter compatibility,
  6165. + feel free to fix this. */
  6166. + remove_data_files_and_list(conf, pkg);
  6167. +
  6168. + pkg_run_script(conf, pkg, "postrm", "remove");
  6169. +
  6170. + remove_maintainer_scripts_except_postrm(conf, pkg);
  6171. +
  6172. + /* Aman Gupta - Since ipkg is made for handheld devices with limited
  6173. + * space, it doesn't make sense to leave extra configurations, files,
  6174. + * and maintainer scripts left around. So, we make remove like purge,
  6175. + * and take out all the crap :) */
  6176. +
  6177. + remove_postrm(conf, pkg);
  6178. + pkg->state_status = SS_NOT_INSTALLED;
  6179. +
  6180. + if (parent_pkg)
  6181. + parent_pkg->state_status = SS_NOT_INSTALLED;
  6182. +
  6183. + return 0;
  6184. +}
  6185. +
  6186. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
  6187. +{
  6188. + ipkg_remove_pkg(conf, pkg,0);
  6189. + return 0;
  6190. +}
  6191. +
  6192. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
  6193. +{
  6194. + str_list_t installed_dirs;
  6195. + str_list_t *installed_files;
  6196. + str_list_elt_t *iter;
  6197. + char *file_name;
  6198. + conffile_t *conffile;
  6199. + int removed_a_dir;
  6200. + pkg_t *owner;
  6201. +
  6202. + str_list_init(&installed_dirs);
  6203. + installed_files = pkg_get_installed_files(pkg);
  6204. +
  6205. + for (iter = installed_files->head; iter; iter = iter->next) {
  6206. + file_name = iter->data;
  6207. +
  6208. + if (file_is_dir(file_name)) {
  6209. + str_list_append(&installed_dirs, strdup(file_name));
  6210. + continue;
  6211. + }
  6212. +
  6213. + conffile = pkg_get_conffile(pkg, file_name);
  6214. + if (conffile) {
  6215. + /* XXX: QUESTION: Is this right? I figure we only need to
  6216. + save the conffile if it has been modified. Is that what
  6217. + dpkg does? Or does dpkg preserve all conffiles? If so,
  6218. + this seems like a better thing to do to conserve
  6219. + space. */
  6220. + if (conffile_has_been_modified(conf, conffile)) {
  6221. + printf(" not deleting modified conffile %s\n", file_name);
  6222. + fflush(stdout);
  6223. + continue;
  6224. + }
  6225. + }
  6226. +
  6227. + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
  6228. + if (!conf->noaction)
  6229. + unlink(file_name);
  6230. + }
  6231. +
  6232. + if (!conf->noaction) {
  6233. + do {
  6234. + removed_a_dir = 0;
  6235. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6236. + file_name = iter->data;
  6237. +
  6238. + if (rmdir(file_name) == 0) {
  6239. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
  6240. + removed_a_dir = 1;
  6241. + str_list_remove(&installed_dirs, &iter);
  6242. + }
  6243. + }
  6244. + } while (removed_a_dir);
  6245. + }
  6246. +
  6247. + pkg_free_installed_files(pkg);
  6248. + /* We have to remove the file list now, so that
  6249. + find_pkg_owning_file does not always just report this package */
  6250. + pkg_remove_installed_files_list(conf, pkg);
  6251. +
  6252. + /* Don't print warning for dirs that are provided by other packages */
  6253. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6254. + file_name = iter->data;
  6255. +
  6256. + owner = file_hash_get_file_owner(conf, file_name);
  6257. + if (owner) {
  6258. + free(iter->data);
  6259. + iter->data = NULL;
  6260. + str_list_remove(&installed_dirs, &iter);
  6261. + }
  6262. + }
  6263. +
  6264. + /* cleanup */
  6265. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6266. + free(iter->data);
  6267. + iter->data = NULL;
  6268. + }
  6269. + str_list_deinit(&installed_dirs);
  6270. +
  6271. + return 0;
  6272. +}
  6273. +
  6274. +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6275. +{
  6276. + int i, err;
  6277. + char *globpattern;
  6278. + glob_t globbuf;
  6279. +
  6280. + if (conf->noaction) return 0;
  6281. +
  6282. + sprintf_alloc(&globpattern, "%s/%s.*",
  6283. + pkg->dest->info_dir, pkg->name);
  6284. + err = glob(globpattern, 0, NULL, &globbuf);
  6285. + free(globpattern);
  6286. + if (err) {
  6287. + return 0;
  6288. + }
  6289. +
  6290. + for (i = 0; i < globbuf.gl_pathc; i++) {
  6291. + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
  6292. + continue;
  6293. + }
  6294. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
  6295. + unlink(globbuf.gl_pathv[i]);
  6296. + }
  6297. + globfree(&globbuf);
  6298. +
  6299. + return 0;
  6300. +}
  6301. +
  6302. +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6303. +{
  6304. + char *postrm_file_name;
  6305. +
  6306. + if (conf->noaction) return 0;
  6307. +
  6308. + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
  6309. + pkg->dest->info_dir, pkg->name);
  6310. + unlink(postrm_file_name);
  6311. + free(postrm_file_name);
  6312. +
  6313. + return 0;
  6314. +}
  6315. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_remove.h busybox-1.15.2/archival/libipkg/ipkg_remove.h
  6316. --- busybox-1.15.2.orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
  6317. +++ busybox-1.15.2/archival/libipkg/ipkg_remove.h 2009-11-26 11:10:13.855859353 +0100
  6318. @@ -0,0 +1,33 @@
  6319. +/* ipkg_remove.h - the itsy package management system
  6320. +
  6321. + Carl D. Worth
  6322. +
  6323. + Copyright (C) 2001 University of Southern California
  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. +#ifndef IPKG_REMOVE_H
  6337. +#define IPKG_REMOVE_H
  6338. +
  6339. +#include "pkg.h"
  6340. +#include "ipkg_conf.h"
  6341. +
  6342. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
  6343. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
  6344. +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
  6345. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents);
  6346. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
  6347. +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6348. +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6349. +
  6350. +
  6351. +#endif
  6352. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_upgrade.c busybox-1.15.2/archival/libipkg/ipkg_upgrade.c
  6353. --- busybox-1.15.2.orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
  6354. +++ busybox-1.15.2/archival/libipkg/ipkg_upgrade.c 2009-11-26 11:10:13.863859535 +0100
  6355. @@ -0,0 +1,79 @@
  6356. +/* ipkg_upgrade.c - the itsy package management system
  6357. +
  6358. + Carl D. Worth
  6359. + Copyright (C) 2001 University of Southern California
  6360. +
  6361. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6362. +
  6363. + This program is free software; you can redistribute it and/or
  6364. + modify it under the terms of the GNU General Public License as
  6365. + published by the Free Software Foundation; either version 2, or (at
  6366. + your option) any later version.
  6367. +
  6368. + This program is distributed in the hope that it will be useful, but
  6369. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6370. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6371. + General Public License for more details.
  6372. +*/
  6373. +
  6374. +#include "ipkg.h"
  6375. +#include "ipkg_install.h"
  6376. +#include "ipkg_message.h"
  6377. +
  6378. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6379. +
  6380. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
  6381. +{
  6382. + pkg_t *new;
  6383. + int cmp;
  6384. + char *old_version, *new_version;
  6385. +
  6386. + if (old->state_flag & SF_HOLD) {
  6387. + ipkg_message(conf, IPKG_NOTICE,
  6388. + "Not upgrading package %s which is marked "
  6389. + "hold (flags=%#x)\n", old->name, old->state_flag);
  6390. + return 0;
  6391. + }
  6392. +
  6393. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
  6394. + if (new == NULL) {
  6395. + old_version = pkg_version_str_alloc(old);
  6396. + ipkg_message(conf, IPKG_NOTICE,
  6397. + "Assuming locally installed package %s (%s) "
  6398. + "is up to date.\n", old->name, old_version);
  6399. + free(old_version);
  6400. + return 0;
  6401. + }
  6402. +
  6403. + old_version = pkg_version_str_alloc(old);
  6404. + new_version = pkg_version_str_alloc(new);
  6405. +
  6406. + cmp = pkg_compare_versions(old, new);
  6407. + ipkg_message(conf, IPKG_DEBUG,
  6408. + "comparing visible versions of pkg %s:"
  6409. + "\n\t%s is installed "
  6410. + "\n\t%s is available "
  6411. + "\n\t%d was comparison result\n",
  6412. + old->name, old_version, new_version, cmp);
  6413. + if (cmp == 0) {
  6414. + ipkg_message(conf, IPKG_INFO,
  6415. + "Package %s (%s) installed in %s is up to date.\n",
  6416. + old->name, old_version, old->dest->name);
  6417. + free(old_version);
  6418. + free(new_version);
  6419. + return 0;
  6420. + } else if (cmp > 0) {
  6421. + ipkg_message(conf, IPKG_NOTICE,
  6422. + "Not downgrading package %s on %s from %s to %s.\n",
  6423. + old->name, old->dest->name, old_version, new_version);
  6424. + free(old_version);
  6425. + free(new_version);
  6426. + return 0;
  6427. + } else if (cmp < 0) {
  6428. + new->dest = old->dest;
  6429. + old->state_want = SW_DEINSTALL;
  6430. + }
  6431. +
  6432. + new->state_flag |= SF_USER;
  6433. + return ipkg_install_pkg(conf, new,1);
  6434. +}
  6435. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_upgrade.h busybox-1.15.2/archival/libipkg/ipkg_upgrade.h
  6436. --- busybox-1.15.2.orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
  6437. +++ busybox-1.15.2/archival/libipkg/ipkg_upgrade.h 2009-11-26 11:10:13.863859535 +0100
  6438. @@ -0,0 +1,18 @@
  6439. +/* ipkg_upgrade.c - the itsy package management system
  6440. +
  6441. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6442. +
  6443. + This program is free software; you can redistribute it and/or
  6444. + modify it under the terms of the GNU General Public License as
  6445. + published by the Free Software Foundation; either version 2, or (at
  6446. + your option) any later version.
  6447. +
  6448. + This program is distributed in the hope that it will be useful, but
  6449. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6450. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6451. + General Public License for more details.
  6452. +*/
  6453. +
  6454. +#include "ipkg.h"
  6455. +
  6456. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6457. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_utils.c busybox-1.15.2/archival/libipkg/ipkg_utils.c
  6458. --- busybox-1.15.2.orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
  6459. +++ busybox-1.15.2/archival/libipkg/ipkg_utils.c 2009-11-26 11:10:13.863859535 +0100
  6460. @@ -0,0 +1,185 @@
  6461. +/* ipkg_utils.c - the itsy package management system
  6462. +
  6463. + Steven M. Ayer
  6464. +
  6465. + Copyright (C) 2002 Compaq Computer Corporation
  6466. +
  6467. + This program is free software; you can redistribute it and/or
  6468. + modify it under the terms of the GNU General Public License as
  6469. + published by the Free Software Foundation; either version 2, or (at
  6470. + your option) any later version.
  6471. +
  6472. + This program is distributed in the hope that it will be useful, but
  6473. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6474. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6475. + General Public License for more details.
  6476. +*/
  6477. +
  6478. +#include "ipkg.h"
  6479. +#include <errno.h>
  6480. +#include <ctype.h>
  6481. +#include <sys/vfs.h>
  6482. +
  6483. +#include "ipkg_utils.h"
  6484. +#include "pkg.h"
  6485. +#include "pkg_hash.h"
  6486. +
  6487. +void push_error_list(struct errlist ** errors, char * msg);
  6488. +void reverse_error_list(struct errlist **errors);
  6489. +void free_error_list(struct errlist **errors);
  6490. +
  6491. +struct errlist* error_list;
  6492. +
  6493. +int get_available_blocks(char * filesystem)
  6494. +{
  6495. + struct statfs sfs;
  6496. +
  6497. + if(statfs(filesystem, &sfs)){
  6498. + fprintf(stderr, "bad statfs\n");
  6499. + return 0;
  6500. + }
  6501. + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
  6502. + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
  6503. +}
  6504. +
  6505. +char **read_raw_pkgs_from_file(const char *file_name)
  6506. +{
  6507. + FILE *fp;
  6508. + char **ret;
  6509. +
  6510. + if(!(fp = fopen(file_name, "r"))){
  6511. + fprintf(stderr, "can't get %s open for read\n", file_name);
  6512. + return NULL;
  6513. + }
  6514. +
  6515. + ret = read_raw_pkgs_from_stream(fp);
  6516. +
  6517. + fclose(fp);
  6518. +
  6519. + return ret;
  6520. +}
  6521. +
  6522. +char **read_raw_pkgs_from_stream(FILE *fp)
  6523. +{
  6524. + char **raw = NULL, *buf, *scout;
  6525. + int count = 0;
  6526. + size_t size = 512;
  6527. +
  6528. + buf = malloc (size);
  6529. +
  6530. + while (fgets(buf, size, fp)) {
  6531. + while (strlen (buf) == (size - 1)
  6532. + && buf[size-2] != '\n') {
  6533. + size_t o = size - 1;
  6534. + size *= 2;
  6535. + buf = realloc (buf, size);
  6536. + if (fgets (buf + o, size - o, fp) == NULL)
  6537. + break;
  6538. + }
  6539. +
  6540. + if(!(count % 50))
  6541. + raw = realloc(raw, (count + 50) * sizeof(char *));
  6542. +
  6543. + if((scout = strchr(buf, '\n')))
  6544. + *scout = '\0';
  6545. +
  6546. + raw[count++] = strdup(buf);
  6547. + }
  6548. +
  6549. + raw = realloc(raw, (count + 1) * sizeof(char *));
  6550. + raw[count] = NULL;
  6551. +
  6552. + free (buf);
  6553. +
  6554. + return raw;
  6555. +}
  6556. +
  6557. +/* something to remove whitespace, a hash pooper */
  6558. +char *trim_alloc(char *line)
  6559. +{
  6560. + char *new;
  6561. + char *dest, *src, *end;
  6562. +
  6563. + new = malloc(strlen(line) + 1);
  6564. + if ( new == NULL ){
  6565. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  6566. + return NULL;
  6567. + }
  6568. + dest = new, src = line, end = line + (strlen(line) - 1);
  6569. +
  6570. + /* remove it from the front */
  6571. + while(src &&
  6572. + isspace(*src) &&
  6573. + *src)
  6574. + src++;
  6575. + /* and now from the back */
  6576. + while((end > src) &&
  6577. + isspace(*end))
  6578. + end--;
  6579. + end++;
  6580. + *end = '\0';
  6581. + strcpy(new, src);
  6582. + /* this does from the first space
  6583. + * blasting away any versions stuff in depends
  6584. + while(src &&
  6585. + !isspace(*src) &&
  6586. + *src)
  6587. + *dest++ = *src++;
  6588. + *dest = '\0';
  6589. + */
  6590. +
  6591. + return new;
  6592. +}
  6593. +
  6594. +int line_is_blank(const char *line)
  6595. +{
  6596. + const char *s;
  6597. +
  6598. + for (s = line; *s; s++) {
  6599. + if (!isspace(*s))
  6600. + return 0;
  6601. + }
  6602. + return 1;
  6603. +}
  6604. +
  6605. +void push_error_list(struct errlist ** errors, char * msg){
  6606. + struct errlist *err_lst_tmp;
  6607. +
  6608. +
  6609. + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
  6610. + err_lst_tmp->errmsg=strdup(msg) ;
  6611. + err_lst_tmp->next = *errors;
  6612. + *errors = err_lst_tmp;
  6613. +}
  6614. +
  6615. +
  6616. +void reverse_error_list(struct errlist **errors){
  6617. + struct errlist *result=NULL;
  6618. + struct errlist *current= *errors;
  6619. + struct errlist *next;
  6620. +
  6621. + while ( current != NULL ) {
  6622. + next = current->next;
  6623. + current->next=result;
  6624. + result=current;
  6625. + current=next;
  6626. + }
  6627. + *errors=result;
  6628. +
  6629. +}
  6630. +
  6631. +
  6632. +void free_error_list(struct errlist **errors){
  6633. + struct errlist *current = *errors;
  6634. +
  6635. + while (current != NULL) {
  6636. + free(current->errmsg);
  6637. + current = (*errors)->next;
  6638. + free(*errors);
  6639. + *errors = current;
  6640. + }
  6641. +
  6642. +
  6643. +}
  6644. +
  6645. +
  6646. diff -Nur busybox-1.15.2.orig/archival/libipkg/ipkg_utils.h busybox-1.15.2/archival/libipkg/ipkg_utils.h
  6647. --- busybox-1.15.2.orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
  6648. +++ busybox-1.15.2/archival/libipkg/ipkg_utils.h 2009-11-26 11:10:13.912271293 +0100
  6649. @@ -0,0 +1,29 @@
  6650. +/* ipkg_utils.h - the itsy package management system
  6651. +
  6652. + Steven M. Ayer
  6653. +
  6654. + Copyright (C) 2002 Compaq Computer Corporation
  6655. +
  6656. + This program is free software; you can redistribute it and/or
  6657. + modify it under the terms of the GNU General Public License as
  6658. + published by the Free Software Foundation; either version 2, or (at
  6659. + your option) any later version.
  6660. +
  6661. + This program is distributed in the hope that it will be useful, but
  6662. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6663. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6664. + General Public License for more details.
  6665. +*/
  6666. +
  6667. +#ifndef IPKG_UTILS_H
  6668. +#define IPKG_UTILS_H
  6669. +
  6670. +#include "pkg.h"
  6671. +
  6672. +int get_available_blocks(char * filesystem);
  6673. +char **read_raw_pkgs_from_file(const char *file_name);
  6674. +char **read_raw_pkgs_from_stream(FILE *fp);
  6675. +char *trim_alloc(char * line);
  6676. +int line_is_blank(const char *line);
  6677. +
  6678. +#endif
  6679. diff -Nur busybox-1.15.2.orig/archival/libipkg/Kbuild busybox-1.15.2/archival/libipkg/Kbuild
  6680. --- busybox-1.15.2.orig/archival/libipkg/Kbuild 1970-01-01 01:00:00.000000000 +0100
  6681. +++ busybox-1.15.2/archival/libipkg/Kbuild 2009-11-26 11:10:13.027859475 +0100
  6682. @@ -0,0 +1,60 @@
  6683. +# Makefile for busybox
  6684. +#
  6685. +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  6686. +# Copyright (C) 2006 OpenWrt.org
  6687. +#
  6688. +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  6689. +
  6690. +LIBIPKG_CORE_OBJS:= \
  6691. + args.o \
  6692. + libipkg.o \
  6693. + user.o \
  6694. +
  6695. +LIBIPKG_CMD_OBJS:= \
  6696. + ipkg_cmd.o \
  6697. + ipkg_configure.o \
  6698. + ipkg_download.o \
  6699. + ipkg_install.o \
  6700. + ipkg_remove.o \
  6701. + ipkg_upgrade.o \
  6702. +
  6703. +LIBIPKG_DB_OBJS:= \
  6704. + hash_table.o \
  6705. + ipkg_conf.o \
  6706. + ipkg_utils.o \
  6707. + pkg.o \
  6708. + pkg_depends.o \
  6709. + pkg_extract.o \
  6710. + pkg_hash.o \
  6711. + pkg_parse.o \
  6712. + pkg_vec.o \
  6713. +
  6714. +LIBIPKG_LIST_OBJS:= \
  6715. + conffile.o \
  6716. + conffile_list.o \
  6717. + nv_pair.o \
  6718. + nv_pair_list.o \
  6719. + pkg_dest.o \
  6720. + pkg_dest_list.o \
  6721. + pkg_src.o \
  6722. + pkg_src_list.o \
  6723. + str_list.o \
  6724. + void_list.o \
  6725. +
  6726. +LIBIPKG_UTIL_OBJS:= \
  6727. + file_util.o \
  6728. + ipkg_message.o \
  6729. + str_util.o \
  6730. + xsystem.o \
  6731. +
  6732. +lib-y :=
  6733. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
  6734. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
  6735. +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
  6736. +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
  6737. +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
  6738. +
  6739. +ifeq ($(strip $(IPKG_ARCH)),)
  6740. +IPKG_ARCH:=$(TARGET_ARCH)
  6741. +endif
  6742. +CFLAGS += -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
  6743. diff -Nur busybox-1.15.2.orig/archival/libipkg/libipkg.c busybox-1.15.2/archival/libipkg/libipkg.c
  6744. --- busybox-1.15.2.orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
  6745. +++ busybox-1.15.2/archival/libipkg/libipkg.c 2009-11-26 11:10:13.915860298 +0100
  6746. @@ -0,0 +1,532 @@
  6747. +/* ipkglib.c - the itsy package management system
  6748. +
  6749. + Florina Boor
  6750. +
  6751. + Copyright (C) 2003 kernel concepts
  6752. +
  6753. + This program is free software; you can redistribute it and/or
  6754. + modify it under the terms of the GNU General Public License as
  6755. + published by the Free Software Foundation; either version 2, or (at
  6756. + your option) any later version.
  6757. +
  6758. + This program is distributed in the hope that it will be useful, but
  6759. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6760. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6761. + General Public License for more details.
  6762. +*/
  6763. +
  6764. +#ifdef IPKG_LIB
  6765. +
  6766. +#include "ipkg.h"
  6767. +#include "ipkg_includes.h"
  6768. +#include "libipkg.h"
  6769. +
  6770. +#include "args.h"
  6771. +#include "ipkg_conf.h"
  6772. +#include "ipkg_cmd.h"
  6773. +#include "file_util.h"
  6774. +
  6775. +int ipkg_file_what(args_t *args, const char *file, const char* command);
  6776. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  6777. + char *msg);
  6778. +int default_ipkg_list_callback(char *name, char *desc, char *version);
  6779. +int default_ipkg_files_callback(char *desc);
  6780. +int default_ipkg_status_callback(char *desc);
  6781. +char* default_ipkg_response_callback(char *question);
  6782. +
  6783. +
  6784. +ipkg_message_callback ipkg_cb_message = NULL;
  6785. +ipkg_response_callback ipkg_cb_response = NULL;
  6786. +ipkg_status_callback ipkg_cb_status = NULL;
  6787. +ipkg_list_callback ipkg_cb_list = NULL;
  6788. +
  6789. +
  6790. +int
  6791. +ipkg_init (ipkg_message_callback mcall,
  6792. + ipkg_response_callback rcall,
  6793. + args_t * args)
  6794. +{
  6795. + ipkg_cb_message = mcall;
  6796. + ipkg_cb_response = rcall;
  6797. +
  6798. + args_init (args);
  6799. +
  6800. + return 0;
  6801. +}
  6802. +
  6803. +
  6804. +int
  6805. +ipkg_deinit (args_t * args)
  6806. +{
  6807. + args_deinit (args);
  6808. + ipkg_cb_message = NULL;
  6809. + ipkg_cb_response = NULL;
  6810. +
  6811. + /* place other cleanup stuff here */
  6812. +
  6813. + return 0;
  6814. +}
  6815. +
  6816. +
  6817. +int
  6818. +ipkg_packages_list(args_t *args,
  6819. + const char *packages,
  6820. + ipkg_list_callback cblist,
  6821. + void *userdata)
  6822. +{
  6823. + ipkg_cmd_t *cmd;
  6824. + ipkg_conf_t ipkg_conf;
  6825. + int err;
  6826. +
  6827. + err = ipkg_conf_init (&ipkg_conf, args);
  6828. + if (err)
  6829. + {
  6830. + return err;
  6831. + }
  6832. +
  6833. + ipkg_cb_list = cblist;
  6834. + /* we need to do this because of static declarations,
  6835. + * maybe a good idea to change */
  6836. + cmd = ipkg_cmd_find ("list");
  6837. + if (packages)
  6838. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6839. + else
  6840. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6841. + ipkg_cb_list = NULL;
  6842. + ipkg_conf_deinit (&ipkg_conf);
  6843. + return (err);
  6844. +}
  6845. +
  6846. +
  6847. +int
  6848. +ipkg_packages_status(args_t *args,
  6849. + const char *packages,
  6850. + ipkg_status_callback cbstatus,
  6851. + void *userdata)
  6852. +{
  6853. + ipkg_cmd_t *cmd;
  6854. + ipkg_conf_t ipkg_conf;
  6855. + int err;
  6856. +
  6857. + err = ipkg_conf_init (&ipkg_conf, args);
  6858. + if (err)
  6859. + {
  6860. + return err;
  6861. + }
  6862. +
  6863. + ipkg_cb_status = cbstatus;
  6864. +
  6865. + /* we need to do this because of static declarations,
  6866. + * maybe a good idea to change */
  6867. + cmd = ipkg_cmd_find ("status");
  6868. + if (packages)
  6869. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6870. + else
  6871. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6872. +
  6873. + ipkg_cb_status = NULL;
  6874. + ipkg_conf_deinit (&ipkg_conf);
  6875. + return (err);
  6876. +}
  6877. +
  6878. +
  6879. +int
  6880. +ipkg_packages_info(args_t *args,
  6881. + const char *packages,
  6882. + ipkg_status_callback cbstatus,
  6883. + void *userdata)
  6884. +{
  6885. + ipkg_cmd_t *cmd;
  6886. + ipkg_conf_t ipkg_conf;
  6887. + int err;
  6888. +
  6889. + err = ipkg_conf_init (&ipkg_conf, args);
  6890. + if (err)
  6891. + {
  6892. + return err;
  6893. + }
  6894. +
  6895. + ipkg_cb_status = cbstatus;
  6896. +
  6897. + /* we need to do this because of static declarations,
  6898. + * maybe a good idea to change */
  6899. + cmd = ipkg_cmd_find ("info");
  6900. + if (packages)
  6901. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6902. + else
  6903. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6904. +
  6905. + ipkg_cb_status = NULL;
  6906. + ipkg_conf_deinit (&ipkg_conf);
  6907. + return (err);
  6908. +}
  6909. +
  6910. +
  6911. +int
  6912. +ipkg_packages_install (args_t * args, const char *name)
  6913. +{
  6914. + ipkg_cmd_t *cmd;
  6915. + ipkg_conf_t ipkg_conf;
  6916. + int err;
  6917. +
  6918. + /* this error should be handled in application */
  6919. + if (!name || !strlen (name))
  6920. + return (-1);
  6921. +
  6922. + err = ipkg_conf_init (&ipkg_conf, args);
  6923. + if (err)
  6924. + {
  6925. + return err;
  6926. + }
  6927. +
  6928. + /* we need to do this because of static declarations,
  6929. + * maybe a good idea to change */
  6930. + cmd = ipkg_cmd_find ("install");
  6931. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6932. +
  6933. + ipkg_conf_deinit(&ipkg_conf);
  6934. + return (err);
  6935. +}
  6936. +
  6937. +
  6938. +int
  6939. +ipkg_packages_remove(args_t *args, const char *name, int purge)
  6940. +{
  6941. + ipkg_cmd_t *cmd;
  6942. + ipkg_conf_t ipkg_conf;
  6943. + int err;
  6944. +
  6945. + /* this error should be handled in application */
  6946. + if (!name || !strlen (name))
  6947. + return (-1);
  6948. +
  6949. + err = ipkg_conf_init (&ipkg_conf, args);
  6950. + if (err)
  6951. + {
  6952. + return err;
  6953. + }
  6954. +
  6955. + /* we need to do this because of static declarations,
  6956. + * maybe a good idea to change */
  6957. + if (purge)
  6958. + cmd = ipkg_cmd_find ("purge");
  6959. + else
  6960. + cmd = ipkg_cmd_find ("remove");
  6961. +
  6962. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6963. +
  6964. + ipkg_conf_deinit(&ipkg_conf);
  6965. + return (err);
  6966. +}
  6967. +
  6968. +
  6969. +int
  6970. +ipkg_lists_update(args_t *args)
  6971. +{
  6972. + ipkg_cmd_t *cmd;
  6973. + ipkg_conf_t ipkg_conf;
  6974. + int err;
  6975. +
  6976. + err = ipkg_conf_init (&ipkg_conf, args);
  6977. + if (err)
  6978. + {
  6979. + return err;
  6980. + }
  6981. +
  6982. + /* we need to do this because of static declarations,
  6983. + * maybe a good idea to change */
  6984. + cmd = ipkg_cmd_find ("update");
  6985. +
  6986. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6987. +
  6988. + ipkg_conf_deinit(&ipkg_conf);
  6989. + return (err);
  6990. +}
  6991. +
  6992. +
  6993. +int
  6994. +ipkg_packages_upgrade(args_t *args)
  6995. +{
  6996. + ipkg_cmd_t *cmd;
  6997. + ipkg_conf_t ipkg_conf;
  6998. + int err;
  6999. +
  7000. + err = ipkg_conf_init (&ipkg_conf, args);
  7001. + if (err)
  7002. + {
  7003. + return err;
  7004. + }
  7005. +
  7006. + /* we need to do this because of static declarations,
  7007. + * maybe a good idea to change */
  7008. + cmd = ipkg_cmd_find ("upgrade");
  7009. +
  7010. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  7011. +
  7012. + ipkg_conf_deinit(&ipkg_conf);
  7013. + return (err);
  7014. +}
  7015. +
  7016. +
  7017. +int
  7018. +ipkg_packages_download (args_t * args, const char *name)
  7019. +{
  7020. + ipkg_cmd_t *cmd;
  7021. + ipkg_conf_t ipkg_conf;
  7022. + int err;
  7023. +
  7024. + /* this error should be handled in application */
  7025. + if (!name || !strlen (name))
  7026. + return (-1);
  7027. +
  7028. + err = ipkg_conf_init (&ipkg_conf, args);
  7029. + if (err)
  7030. + {
  7031. + return err;
  7032. + }
  7033. +
  7034. + /* we need to do this because of static declarations,
  7035. + * maybe a good idea to change */
  7036. + cmd = ipkg_cmd_find ("download");
  7037. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  7038. +
  7039. + ipkg_conf_deinit(&ipkg_conf);
  7040. + return (err);
  7041. +}
  7042. +
  7043. +
  7044. +int
  7045. +ipkg_package_files(args_t *args,
  7046. + const char *name,
  7047. + ipkg_list_callback cblist,
  7048. + void *userdata)
  7049. +{
  7050. + ipkg_cmd_t *cmd;
  7051. + ipkg_conf_t ipkg_conf;
  7052. + int err;
  7053. +
  7054. + /* this error should be handled in application */
  7055. + if (!name || !strlen (name))
  7056. + return (-1);
  7057. +
  7058. + err = ipkg_conf_init (&ipkg_conf, args);
  7059. + if (err)
  7060. + {
  7061. + return err;
  7062. + }
  7063. +
  7064. + ipkg_cb_list = cblist;
  7065. +
  7066. + /* we need to do this because of static declarations,
  7067. + * maybe a good idea to change */
  7068. + cmd = ipkg_cmd_find ("files");
  7069. +
  7070. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
  7071. +
  7072. + ipkg_cb_list = NULL;
  7073. + ipkg_conf_deinit(&ipkg_conf);
  7074. + return (err);
  7075. +}
  7076. +
  7077. +
  7078. +int
  7079. +ipkg_file_search(args_t *args,
  7080. + const char *file,
  7081. + ipkg_list_callback cblist,
  7082. + void *userdata)
  7083. +{
  7084. + ipkg_cmd_t *cmd;
  7085. + ipkg_conf_t ipkg_conf;
  7086. + int err;
  7087. +
  7088. + /* this error should be handled in application */
  7089. + if (!file || !strlen (file))
  7090. + return (-1);
  7091. +
  7092. + err = ipkg_conf_init (&ipkg_conf, args);
  7093. + if (err)
  7094. + {
  7095. + return err;
  7096. + }
  7097. +
  7098. + ipkg_cb_list = cblist;
  7099. +
  7100. + /* we need to do this because of static declarations,
  7101. + * maybe a good idea to change */
  7102. + cmd = ipkg_cmd_find ("search");
  7103. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
  7104. +
  7105. + ipkg_cb_list = NULL;
  7106. + ipkg_conf_deinit(&ipkg_conf);
  7107. + return(err);
  7108. +}
  7109. +
  7110. +
  7111. +int
  7112. +ipkg_file_what(args_t *args, const char *file, const char* command)
  7113. +{
  7114. + ipkg_cmd_t *cmd;
  7115. + ipkg_conf_t ipkg_conf;
  7116. + int err;
  7117. +
  7118. + /* this error should be handled in application */
  7119. + if (!file || !strlen (file))
  7120. + return (-1);
  7121. +
  7122. + err = ipkg_conf_init (&ipkg_conf, args);
  7123. + if (err)
  7124. + {
  7125. + return err;
  7126. + }
  7127. +
  7128. + /* we need to do this because of static declarations,
  7129. + * maybe a good idea to change */
  7130. + cmd = ipkg_cmd_find (command);
  7131. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
  7132. +
  7133. + ipkg_conf_deinit(&ipkg_conf);
  7134. + return(err);
  7135. +}
  7136. +
  7137. +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
  7138. +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
  7139. +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
  7140. +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
  7141. +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
  7142. +
  7143. +
  7144. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  7145. + char *msg)
  7146. +{
  7147. + if (conf && (conf->verbosity < level)) {
  7148. + return 0;
  7149. + } else {
  7150. +#ifdef IPKG_LIB
  7151. + if ( level == IPKG_ERROR ){
  7152. + push_error_list(&error_list, msg);
  7153. +// printf(msg);
  7154. + } else
  7155. +#endif
  7156. + printf(msg);
  7157. + }
  7158. + return 0;
  7159. +}
  7160. +
  7161. +int default_ipkg_list_callback(char *name, char *desc, char *version)
  7162. +{
  7163. + if (desc)
  7164. + printf("%s - %s - %s\n", name, version, desc);
  7165. + else
  7166. + printf("%s - %s\n", name, version);
  7167. + return 0;
  7168. +}
  7169. +
  7170. +int default_ipkg_files_callback(char *desc)
  7171. +{
  7172. + if (desc)
  7173. + printf("%s\n", desc);
  7174. + return 0;
  7175. +}
  7176. +
  7177. +int default_ipkg_status_callback(char *desc)
  7178. +{
  7179. + printf("%s\n", desc);
  7180. + return 0;
  7181. +}
  7182. +
  7183. +char* default_ipkg_response_callback(char *question)
  7184. +{
  7185. + char *response = NULL;
  7186. + printf(question);
  7187. + fflush(stdout);
  7188. + do {
  7189. + response = (char *)file_read_line_alloc(stdin);
  7190. + } while (response == NULL);
  7191. + return response;
  7192. +}
  7193. +
  7194. +/* This is used for backward compatibility */
  7195. +int
  7196. +ipkg_op (int argc, char *argv[])
  7197. +{
  7198. + int err, optind_;
  7199. + args_t args;
  7200. + char *cmd_name;
  7201. + ipkg_cmd_t *cmd;
  7202. + ipkg_conf_t ipkg_conf;
  7203. + const char *message = "ipkg must have one sub-command argument";
  7204. +
  7205. + args_init (&args);
  7206. +
  7207. + optind_ = args_parse (&args, argc, argv);
  7208. + if (optind_ == argc || optind_ < 0)
  7209. + {
  7210. + args_usage(message);
  7211. + }
  7212. +
  7213. + cmd_name = argv[optind_++];
  7214. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  7215. + read anything from there.
  7216. +*/
  7217. + if ( !strcmp(cmd_name,"print-architecture") ||
  7218. + !strcmp(cmd_name,"print_architecture") ||
  7219. + !strcmp(cmd_name,"print-installation-architecture") ||
  7220. + !strcmp(cmd_name,"print_installation_architecture") )
  7221. + args.nocheckfordirorfile = 1;
  7222. +
  7223. +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
  7224. + read anything from there.
  7225. +*/
  7226. + if ( !strcmp(cmd_name,"flag") ||
  7227. + !strcmp(cmd_name,"configure") ||
  7228. + !strcmp(cmd_name,"remove") ||
  7229. + !strcmp(cmd_name,"files") ||
  7230. + !strcmp(cmd_name,"search") ||
  7231. + !strcmp(cmd_name,"compare_versions") ||
  7232. + !strcmp(cmd_name,"compare-versions") ||
  7233. + !strcmp(cmd_name,"list_installed") ||
  7234. + !strcmp(cmd_name,"list-installed") ||
  7235. + !strcmp(cmd_name,"status") )
  7236. + args.noreadfeedsfile = 1;
  7237. +
  7238. +
  7239. + err = ipkg_conf_init (&ipkg_conf, &args);
  7240. + if (err)
  7241. + {
  7242. + return err;
  7243. + }
  7244. +
  7245. + args_deinit (&args);
  7246. +
  7247. + ipkg_cb_message = default_ipkg_message_callback;
  7248. + ipkg_cb_response = default_ipkg_response_callback;
  7249. + ipkg_cb_status = (ipkg_status_callback)default_ipkg_status_callback;
  7250. + if ( strcmp(cmd_name, "files")==0)
  7251. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_files_callback;
  7252. + else
  7253. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_list_callback;
  7254. +
  7255. + cmd = ipkg_cmd_find (cmd_name);
  7256. + if (cmd == NULL)
  7257. + {
  7258. + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
  7259. + cmd_name);
  7260. + args_usage (NULL);
  7261. + }
  7262. +
  7263. + if (cmd->requires_args && optind_ == argc)
  7264. + {
  7265. + fprintf (stderr,
  7266. + "%s: the ``%s'' command requires at least one argument\n",
  7267. + __FUNCTION__, cmd_name);
  7268. + args_usage (NULL);
  7269. + }
  7270. +
  7271. + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind_, (const char **) (argv + optind_), NULL);
  7272. +
  7273. + ipkg_conf_deinit (&ipkg_conf);
  7274. +
  7275. + return err;
  7276. +}
  7277. +
  7278. +#endif /* IPKG_LIB */
  7279. diff -Nur busybox-1.15.2.orig/archival/libipkg/libipkg.h busybox-1.15.2/archival/libipkg/libipkg.h
  7280. --- busybox-1.15.2.orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
  7281. +++ busybox-1.15.2/archival/libipkg/libipkg.h 2009-11-26 11:10:13.923858524 +0100
  7282. @@ -0,0 +1,87 @@
  7283. +/* ipkglib.h - the itsy package management system
  7284. +
  7285. + Florian Boor <florian.boor@kernelconcepts.de>
  7286. +
  7287. + This program is free software; you can redistribute it and/or
  7288. + modify it under the terms of the GNU General Public License as
  7289. + published by the Free Software Foundation; either version 2, or (at
  7290. + your option) any later version.
  7291. +
  7292. + This program is distributed in the hope that it will be useful, but
  7293. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7294. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7295. + General Public License for more details.
  7296. +*/
  7297. +
  7298. +#ifndef IPKGLIB_H
  7299. +#define IPKGLIB_H
  7300. +
  7301. +#ifdef IPKG_LIB
  7302. +
  7303. +#include "ipkg_conf.h"
  7304. +#include "ipkg_message.h"
  7305. +
  7306. +#include "args.h"
  7307. +#include "pkg.h"
  7308. +
  7309. +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
  7310. + char *msg);
  7311. +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
  7312. + pkg_state_status_t status, void *userdata);
  7313. +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
  7314. + void *userdata);
  7315. +typedef char* (*ipkg_response_callback)(char *question);
  7316. +
  7317. +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
  7318. +extern int ipkg_init (ipkg_message_callback mcall,
  7319. + ipkg_response_callback rcall,
  7320. + args_t * args);
  7321. +
  7322. +extern int ipkg_deinit (args_t *args);
  7323. +extern int ipkg_packages_list(args_t *args,
  7324. + const char *packages,
  7325. + ipkg_list_callback cblist,
  7326. + void *userdata);
  7327. +extern int ipkg_packages_status(args_t *args,
  7328. + const char *packages,
  7329. + ipkg_status_callback cbstatus,
  7330. + void *userdata);
  7331. +extern int ipkg_packages_info(args_t *args,
  7332. + const char *packages,
  7333. + ipkg_status_callback cbstatus,
  7334. + void *userdata);
  7335. +extern int ipkg_packages_install(args_t *args, const char *name);
  7336. +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
  7337. +extern int ipkg_lists_update(args_t *args);
  7338. +extern int ipkg_packages_upgrade(args_t *args);
  7339. +extern int ipkg_packages_download(args_t *args, const char *name);
  7340. +extern int ipkg_package_files(args_t *args,
  7341. + const char *name,
  7342. + ipkg_list_callback cblist,
  7343. + void *userdata);
  7344. +extern int ipkg_file_search(args_t *args,
  7345. + const char *file,
  7346. + ipkg_list_callback cblist,
  7347. + void *userdata);
  7348. +extern int ipkg_package_whatdepends(args_t *args, const char *file);
  7349. +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
  7350. +extern int ipkg_package_whatprovides(args_t *args, const char *file);
  7351. +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
  7352. +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
  7353. +
  7354. +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
  7355. +extern ipkg_response_callback ipkg_cb_response;
  7356. +extern ipkg_status_callback ipkg_cb_status;
  7357. +extern ipkg_list_callback ipkg_cb_list;
  7358. +extern void push_error_list(struct errlist **errors,char * msg);
  7359. +extern void reverse_error_list(struct errlist **errors);
  7360. +extern void free_error_list(struct errlist **errors);
  7361. +
  7362. +#else
  7363. +
  7364. +extern int ipkg_op(int argc, char *argv[]);
  7365. +
  7366. +#endif
  7367. +
  7368. +
  7369. +#endif
  7370. diff -Nur busybox-1.15.2.orig/archival/libipkg/nv_pair.c busybox-1.15.2/archival/libipkg/nv_pair.c
  7371. --- busybox-1.15.2.orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
  7372. +++ busybox-1.15.2/archival/libipkg/nv_pair.c 2009-11-26 11:10:13.987858580 +0100
  7373. @@ -0,0 +1,40 @@
  7374. +/* nv_pair.c - the itsy package management system
  7375. +
  7376. + Carl D. Worth
  7377. +
  7378. + Copyright (C) 2001 University of Southern California
  7379. +
  7380. + This program is free software; you can redistribute it and/or
  7381. + modify it under the terms of the GNU General Public License as
  7382. + published by the Free Software Foundation; either version 2, or (at
  7383. + your option) any later version.
  7384. +
  7385. + This program is distributed in the hope that it will be useful, but
  7386. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7387. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7388. + General Public License for more details.
  7389. +*/
  7390. +
  7391. +#include "ipkg.h"
  7392. +
  7393. +#include "nv_pair.h"
  7394. +#include "str_util.h"
  7395. +
  7396. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
  7397. +{
  7398. + nv_pair->name = str_dup_safe(name);
  7399. + nv_pair->value = str_dup_safe(value);
  7400. +
  7401. + return 0;
  7402. +}
  7403. +
  7404. +void nv_pair_deinit(nv_pair_t *nv_pair)
  7405. +{
  7406. + free(nv_pair->name);
  7407. + nv_pair->name = NULL;
  7408. +
  7409. + free(nv_pair->value);
  7410. + nv_pair->value = NULL;
  7411. +}
  7412. +
  7413. +
  7414. diff -Nur busybox-1.15.2.orig/archival/libipkg/nv_pair.h busybox-1.15.2/archival/libipkg/nv_pair.h
  7415. --- busybox-1.15.2.orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
  7416. +++ busybox-1.15.2/archival/libipkg/nv_pair.h 2009-11-26 11:10:13.987858580 +0100
  7417. @@ -0,0 +1,32 @@
  7418. +/* nv_pair.h - the itsy package management system
  7419. +
  7420. + Carl D. Worth
  7421. +
  7422. + Copyright (C) 2001 University of Southern California
  7423. +
  7424. + This program is free software; you can redistribute it and/or
  7425. + modify it under the terms of the GNU General Public License as
  7426. + published by the Free Software Foundation; either version 2, or (at
  7427. + your option) any later version.
  7428. +
  7429. + This program is distributed in the hope that it will be useful, but
  7430. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7431. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7432. + General Public License for more details.
  7433. +*/
  7434. +
  7435. +#ifndef NV_PAIR_H
  7436. +#define NV_PAIR_H
  7437. +
  7438. +typedef struct nv_pair nv_pair_t;
  7439. +struct nv_pair
  7440. +{
  7441. + char *name;
  7442. + char *value;
  7443. +};
  7444. +
  7445. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
  7446. +void nv_pair_deinit(nv_pair_t *nv_pair);
  7447. +
  7448. +#endif
  7449. +
  7450. diff -Nur busybox-1.15.2.orig/archival/libipkg/nv_pair_list.c busybox-1.15.2/archival/libipkg/nv_pair_list.c
  7451. --- busybox-1.15.2.orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
  7452. +++ busybox-1.15.2/archival/libipkg/nv_pair_list.c 2009-11-26 11:10:14.043859011 +0100
  7453. @@ -0,0 +1,98 @@
  7454. +/* nv_pair_list.c - the itsy package management system
  7455. +
  7456. + Carl D. Worth
  7457. +
  7458. + Copyright (C) 2001 University of Southern California
  7459. +
  7460. + This program is free software; you can redistribute it and/or
  7461. + modify it under the terms of the GNU General Public License as
  7462. + published by the Free Software Foundation; either version 2, or (at
  7463. + your option) any later version.
  7464. +
  7465. + This program is distributed in the hope that it will be useful, but
  7466. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7467. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7468. + General Public License for more details.
  7469. +*/
  7470. +
  7471. +#include "ipkg.h"
  7472. +
  7473. +#include "nv_pair.h"
  7474. +#include "void_list.h"
  7475. +#include "nv_pair_list.h"
  7476. +
  7477. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
  7478. +{
  7479. + return void_list_elt_init((void_list_elt_t *) elt, data);
  7480. +}
  7481. +
  7482. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
  7483. +{
  7484. + void_list_elt_deinit((void_list_elt_t *) elt);
  7485. +}
  7486. +
  7487. +int nv_pair_list_init(nv_pair_list_t *list)
  7488. +{
  7489. + return void_list_init((void_list_t *) list);
  7490. +}
  7491. +
  7492. +void nv_pair_list_deinit(nv_pair_list_t *list)
  7493. +{
  7494. + nv_pair_list_elt_t *iter;
  7495. + nv_pair_t *nv_pair;
  7496. +
  7497. + for (iter = list->head; iter; iter = iter->next) {
  7498. + nv_pair = iter->data;
  7499. + nv_pair_deinit(nv_pair);
  7500. +
  7501. + /* malloced in nv_pair_list_append */
  7502. + free(nv_pair);
  7503. + iter->data = NULL;
  7504. + }
  7505. + void_list_deinit((void_list_t *) list);
  7506. +}
  7507. +
  7508. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
  7509. +{
  7510. + int err;
  7511. +
  7512. + /* freed in nv_pair_list_deinit */
  7513. + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
  7514. +
  7515. + if (nv_pair == NULL) {
  7516. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7517. + return NULL;
  7518. + }
  7519. + nv_pair_init(nv_pair, name, value);
  7520. +
  7521. + err = void_list_append((void_list_t *) list, nv_pair);
  7522. + if (err) {
  7523. + return NULL;
  7524. + }
  7525. +
  7526. + return nv_pair;
  7527. +}
  7528. +
  7529. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
  7530. +{
  7531. + return void_list_push((void_list_t *) list, data);
  7532. +}
  7533. +
  7534. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
  7535. +{
  7536. + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
  7537. +}
  7538. +
  7539. +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
  7540. +{
  7541. + nv_pair_list_elt_t *iter;
  7542. + nv_pair_t *nv_pair;
  7543. +
  7544. + for (iter = list->head; iter; iter = iter->next) {
  7545. + nv_pair = iter->data;
  7546. + if (strcmp(nv_pair->name, name) == 0) {
  7547. + return nv_pair->value;
  7548. + }
  7549. + }
  7550. + return NULL;
  7551. +}
  7552. diff -Nur busybox-1.15.2.orig/archival/libipkg/nv_pair_list.h busybox-1.15.2/archival/libipkg/nv_pair_list.h
  7553. --- busybox-1.15.2.orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
  7554. +++ busybox-1.15.2/archival/libipkg/nv_pair_list.h 2009-11-26 11:10:14.047859242 +0100
  7555. @@ -0,0 +1,60 @@
  7556. +/* nv_pair_list.h - the itsy package management system
  7557. +
  7558. + Carl D. Worth
  7559. +
  7560. + Copyright (C) 2001 University of Southern California
  7561. +
  7562. + This program is free software; you can redistribute it and/or
  7563. + modify it under the terms of the GNU General Public License as
  7564. + published by the Free Software Foundation; either version 2, or (at
  7565. + your option) any later version.
  7566. +
  7567. + This program is distributed in the hope that it will be useful, but
  7568. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7569. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7570. + General Public License for more details.
  7571. +*/
  7572. +
  7573. +#ifndef NV_PAIR_LIST_H
  7574. +#define NV_PAIR_LIST_H
  7575. +
  7576. +#include "nv_pair.h"
  7577. +#include "void_list.h"
  7578. +
  7579. +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
  7580. +struct nv_pair_list_elt
  7581. +{
  7582. + nv_pair_list_elt_t *next;
  7583. + nv_pair_t *data;
  7584. +};
  7585. +
  7586. +typedef struct nv_pair_list nv_pair_list_t;
  7587. +struct nv_pair_list
  7588. +{
  7589. + nv_pair_list_elt_t pre_head;
  7590. + nv_pair_list_elt_t *head;
  7591. + nv_pair_list_elt_t *tail;
  7592. +};
  7593. +
  7594. +static inline int nv_pair_list_empty(nv_pair_list_t *list)
  7595. +{
  7596. + if (list->head == NULL)
  7597. + return 1;
  7598. + else
  7599. + return 0;
  7600. +}
  7601. +
  7602. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
  7603. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
  7604. +
  7605. +int nv_pair_list_init(nv_pair_list_t *list);
  7606. +void nv_pair_list_deinit(nv_pair_list_t *list);
  7607. +
  7608. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
  7609. + const char *name, const char *value);
  7610. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
  7611. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
  7612. +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
  7613. +
  7614. +#endif
  7615. +
  7616. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg.c busybox-1.15.2/archival/libipkg/pkg.c
  7617. --- busybox-1.15.2.orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
  7618. +++ busybox-1.15.2/archival/libipkg/pkg.c 2009-11-26 11:10:14.055858306 +0100
  7619. @@ -0,0 +1,1757 @@
  7620. +/* pkg.c - the itsy package management system
  7621. +
  7622. + Carl D. Worth
  7623. +
  7624. + Copyright (C) 2001 University of Southern California
  7625. +
  7626. + This program is free software; you can redistribute it and/or
  7627. + modify it under the terms of the GNU General Public License as
  7628. + published by the Free Software Foundation; either version 2, or (at
  7629. + your option) any later version.
  7630. +
  7631. + This program is distributed in the hope that it will be useful, but
  7632. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7633. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7634. + General Public License for more details.
  7635. +*/
  7636. +
  7637. +#include "ipkg.h"
  7638. +#include <ctype.h>
  7639. +#include <string.h>
  7640. +#include <errno.h>
  7641. +
  7642. +#include "pkg.h"
  7643. +
  7644. +#include "pkg_parse.h"
  7645. +#include "pkg_extract.h"
  7646. +#include "ipkg_message.h"
  7647. +#include "ipkg_utils.h"
  7648. +
  7649. +#include "sprintf_alloc.h"
  7650. +#include "file_util.h"
  7651. +#include "str_util.h"
  7652. +#include "xsystem.h"
  7653. +#include "ipkg_conf.h"
  7654. +
  7655. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname);
  7656. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_);
  7657. +
  7658. +typedef struct enum_map enum_map_t;
  7659. +struct enum_map
  7660. +{
  7661. + int value;
  7662. + const char *str;
  7663. +};
  7664. +
  7665. +static const enum_map_t pkg_state_want_map[] = {
  7666. + { SW_UNKNOWN, "unknown"},
  7667. + { SW_INSTALL, "install"},
  7668. + { SW_DEINSTALL, "deinstall"},
  7669. + { SW_PURGE, "purge"}
  7670. +};
  7671. +
  7672. +static const enum_map_t pkg_state_flag_map[] = {
  7673. + { SF_OK, "ok"},
  7674. + { SF_REINSTREQ, "reinstreq"},
  7675. + { SF_HOLD, "hold"},
  7676. + { SF_REPLACE, "replace"},
  7677. + { SF_NOPRUNE, "noprune"},
  7678. + { SF_PREFER, "prefer"},
  7679. + { SF_OBSOLETE, "obsolete"},
  7680. + { SF_USER, "user"},
  7681. +};
  7682. +
  7683. +static const enum_map_t pkg_state_status_map[] = {
  7684. + { SS_NOT_INSTALLED, "not-installed" },
  7685. + { SS_UNPACKED, "unpacked" },
  7686. + { SS_HALF_CONFIGURED, "half-configured" },
  7687. + { SS_INSTALLED, "installed" },
  7688. + { SS_HALF_INSTALLED, "half-installed" },
  7689. + { SS_CONFIG_FILES, "config-files" },
  7690. + { SS_POST_INST_FAILED, "post-inst-failed" },
  7691. + { SS_REMOVAL_FAILED, "removal-failed" }
  7692. +};
  7693. +
  7694. +static int verrevcmp(const char *val, const char *ref);
  7695. +
  7696. +
  7697. +pkg_t *pkg_new(void)
  7698. +{
  7699. + pkg_t *pkg;
  7700. +
  7701. + pkg = malloc(sizeof(pkg_t));
  7702. + if (pkg == NULL) {
  7703. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7704. + return NULL;
  7705. + }
  7706. +
  7707. + pkg_init(pkg);
  7708. +
  7709. + return pkg;
  7710. +}
  7711. +
  7712. +int pkg_init(pkg_t *pkg)
  7713. +{
  7714. + memset(pkg, 0, sizeof(pkg_t));
  7715. + pkg->name = NULL;
  7716. + pkg->epoch = 0;
  7717. + pkg->version = NULL;
  7718. + pkg->revision = NULL;
  7719. + pkg->familiar_revision = NULL;
  7720. + pkg->dest = NULL;
  7721. + pkg->src = NULL;
  7722. + pkg->architecture = NULL;
  7723. + pkg->maintainer = NULL;
  7724. + pkg->section = NULL;
  7725. + pkg->description = NULL;
  7726. + pkg->state_want = SW_UNKNOWN;
  7727. + pkg->state_flag = SF_OK;
  7728. + pkg->state_status = SS_NOT_INSTALLED;
  7729. + pkg->depends_str = NULL;
  7730. + pkg->provides_str = NULL;
  7731. + pkg->depends_count = 0;
  7732. + pkg->depends = NULL;
  7733. + pkg->suggests_str = NULL;
  7734. + pkg->recommends_str = NULL;
  7735. + pkg->suggests_count = 0;
  7736. + pkg->recommends_count = 0;
  7737. +
  7738. + /* Abhaya: added init for conflicts fields */
  7739. + pkg->conflicts = NULL;
  7740. + pkg->conflicts_count = 0;
  7741. +
  7742. + /* added for replaces. Jamey 7/23/2002 */
  7743. + pkg->replaces = NULL;
  7744. + pkg->replaces_count = 0;
  7745. +
  7746. + pkg->pre_depends_count = 0;
  7747. + pkg->pre_depends_str = NULL;
  7748. + pkg->provides_count = 0;
  7749. + pkg->provides = NULL;
  7750. + pkg->filename = NULL;
  7751. + pkg->local_filename = NULL;
  7752. + pkg->tmp_unpack_dir = NULL;
  7753. + pkg->md5sum = NULL;
  7754. + pkg->size = NULL;
  7755. + pkg->installed_size = NULL;
  7756. + pkg->priority = NULL;
  7757. + pkg->source = NULL;
  7758. + conffile_list_init(&pkg->conffiles);
  7759. + pkg->installed_files = NULL;
  7760. + pkg->installed_files_ref_cnt = 0;
  7761. + pkg->essential = 0;
  7762. + pkg->provided_by_hand = 0;
  7763. +
  7764. + return 0;
  7765. +}
  7766. +
  7767. +void pkg_deinit(pkg_t *pkg)
  7768. +{
  7769. + free(pkg->name);
  7770. + pkg->name = NULL;
  7771. + pkg->epoch = 0;
  7772. + free(pkg->version);
  7773. + pkg->version = NULL;
  7774. + /* revision and familiar_revision share storage with version, so
  7775. + don't free */
  7776. + pkg->revision = NULL;
  7777. + pkg->familiar_revision = NULL;
  7778. + /* owned by ipkg_conf_t */
  7779. + pkg->dest = NULL;
  7780. + /* owned by ipkg_conf_t */
  7781. + pkg->src = NULL;
  7782. + free(pkg->architecture);
  7783. + pkg->architecture = NULL;
  7784. + free(pkg->maintainer);
  7785. + pkg->maintainer = NULL;
  7786. + free(pkg->section);
  7787. + pkg->section = NULL;
  7788. + free(pkg->description);
  7789. + pkg->description = NULL;
  7790. + pkg->state_want = SW_UNKNOWN;
  7791. + pkg->state_flag = SF_OK;
  7792. + pkg->state_status = SS_NOT_INSTALLED;
  7793. + free(pkg->depends_str);
  7794. + pkg->depends_str = NULL;
  7795. + free(pkg->provides_str);
  7796. + pkg->provides_str = NULL;
  7797. + pkg->depends_count = 0;
  7798. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
  7799. + pkg->pre_depends_count = 0;
  7800. + free(pkg->pre_depends_str);
  7801. + pkg->pre_depends_str = NULL;
  7802. + pkg->provides_count = 0;
  7803. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
  7804. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
  7805. + free(pkg->filename);
  7806. + pkg->filename = NULL;
  7807. + free(pkg->local_filename);
  7808. + pkg->local_filename = NULL;
  7809. + /* CLEANUP: It'd be nice to pullin the cleanup function from
  7810. + ipkg_install.c here. See comment in
  7811. + ipkg_install.c:cleanup_temporary_files */
  7812. + free(pkg->tmp_unpack_dir);
  7813. + pkg->tmp_unpack_dir = NULL;
  7814. + free(pkg->md5sum);
  7815. + pkg->md5sum = NULL;
  7816. + free(pkg->size);
  7817. + pkg->size = NULL;
  7818. + free(pkg->installed_size);
  7819. + pkg->installed_size = NULL;
  7820. + free(pkg->priority);
  7821. + pkg->priority = NULL;
  7822. + free(pkg->source);
  7823. + pkg->source = NULL;
  7824. + conffile_list_deinit(&pkg->conffiles);
  7825. + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
  7826. + since if they are calling deinit, they should know. Maybe do an
  7827. + assertion here instead? */
  7828. + pkg->installed_files_ref_cnt = 1;
  7829. + pkg_free_installed_files(pkg);
  7830. + pkg->essential = 0;
  7831. +}
  7832. +
  7833. +int pkg_init_from_file(pkg_t *pkg, const char *filename)
  7834. +{
  7835. + int err;
  7836. + char **raw;
  7837. + FILE *control_file;
  7838. +
  7839. + err = pkg_init(pkg);
  7840. + if (err) { return err; }
  7841. +
  7842. + pkg->local_filename = strdup(filename);
  7843. +
  7844. + control_file = tmpfile();
  7845. + err = pkg_extract_control_file_to_stream(pkg, control_file);
  7846. + if (err) { return err; }
  7847. +
  7848. + rewind(control_file);
  7849. + raw = read_raw_pkgs_from_stream(control_file);
  7850. + pkg_parse_raw(pkg, &raw, NULL, NULL);
  7851. +
  7852. + fclose(control_file);
  7853. +
  7854. + return 0;
  7855. +}
  7856. +
  7857. +/* Merge any new information in newpkg into oldpkg */
  7858. +/* XXX: CLEANUP: This function shouldn't actually modify anything in
  7859. + newpkg, but should leave it usable. This rework is so that
  7860. + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
  7861. +/*
  7862. + * uh, i thought that i had originally written this so that it took
  7863. + * two pkgs and returned a new one? we can do that again... -sma
  7864. + */
  7865. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
  7866. +{
  7867. + if (oldpkg == newpkg) {
  7868. + return 0;
  7869. + }
  7870. +
  7871. + if (!oldpkg->src)
  7872. + oldpkg->src = newpkg->src;
  7873. + if (!oldpkg->dest)
  7874. + oldpkg->dest = newpkg->dest;
  7875. + if (!oldpkg->architecture)
  7876. + oldpkg->architecture = str_dup_safe(newpkg->architecture);
  7877. + if (!oldpkg->arch_priority)
  7878. + oldpkg->arch_priority = newpkg->arch_priority;
  7879. + if (!oldpkg->section)
  7880. + oldpkg->section = str_dup_safe(newpkg->section);
  7881. + if(!oldpkg->maintainer)
  7882. + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
  7883. + if(!oldpkg->description)
  7884. + oldpkg->description = str_dup_safe(newpkg->description);
  7885. + if (set_status) {
  7886. + /* merge the state_flags from the new package */
  7887. + oldpkg->state_want = newpkg->state_want;
  7888. + oldpkg->state_status = newpkg->state_status;
  7889. + oldpkg->state_flag = newpkg->state_flag;
  7890. + } else {
  7891. + if (oldpkg->state_want == SW_UNKNOWN)
  7892. + oldpkg->state_want = newpkg->state_want;
  7893. + if (oldpkg->state_status == SS_NOT_INSTALLED)
  7894. + oldpkg->state_status = newpkg->state_status;
  7895. + oldpkg->state_flag |= newpkg->state_flag;
  7896. + }
  7897. +
  7898. + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
  7899. + oldpkg->depends_str = newpkg->depends_str;
  7900. + newpkg->depends_str = NULL;
  7901. + oldpkg->depends_count = newpkg->depends_count;
  7902. + newpkg->depends_count = 0;
  7903. +
  7904. + oldpkg->depends = newpkg->depends;
  7905. + newpkg->depends = NULL;
  7906. +
  7907. + oldpkg->pre_depends_str = newpkg->pre_depends_str;
  7908. + newpkg->pre_depends_str = NULL;
  7909. + oldpkg->pre_depends_count = newpkg->pre_depends_count;
  7910. + newpkg->pre_depends_count = 0;
  7911. +
  7912. + oldpkg->recommends_str = newpkg->recommends_str;
  7913. + newpkg->recommends_str = NULL;
  7914. + oldpkg->recommends_count = newpkg->recommends_count;
  7915. + newpkg->recommends_count = 0;
  7916. +
  7917. + oldpkg->suggests_str = newpkg->suggests_str;
  7918. + newpkg->suggests_str = NULL;
  7919. + oldpkg->suggests_count = newpkg->suggests_count;
  7920. + newpkg->suggests_count = 0;
  7921. + }
  7922. +
  7923. + if (!oldpkg->provides_str) {
  7924. + oldpkg->provides_str = newpkg->provides_str;
  7925. + newpkg->provides_str = NULL;
  7926. + oldpkg->provides_count = newpkg->provides_count;
  7927. + newpkg->provides_count = 0;
  7928. +
  7929. + oldpkg->provides = newpkg->provides;
  7930. + newpkg->provides = NULL;
  7931. + }
  7932. +
  7933. + if (!oldpkg->conflicts_str) {
  7934. + oldpkg->conflicts_str = newpkg->conflicts_str;
  7935. + newpkg->conflicts_str = NULL;
  7936. + oldpkg->conflicts_count = newpkg->conflicts_count;
  7937. + newpkg->conflicts_count = 0;
  7938. +
  7939. + oldpkg->conflicts = newpkg->conflicts;
  7940. + newpkg->conflicts = NULL;
  7941. + }
  7942. +
  7943. + if (!oldpkg->replaces_str) {
  7944. + oldpkg->replaces_str = newpkg->replaces_str;
  7945. + newpkg->replaces_str = NULL;
  7946. + oldpkg->replaces_count = newpkg->replaces_count;
  7947. + newpkg->replaces_count = 0;
  7948. +
  7949. + oldpkg->replaces = newpkg->replaces;
  7950. + newpkg->replaces = NULL;
  7951. + }
  7952. +
  7953. + if (!oldpkg->filename)
  7954. + oldpkg->filename = str_dup_safe(newpkg->filename);
  7955. + if (0)
  7956. + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
  7957. + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
  7958. + if (!oldpkg->local_filename)
  7959. + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
  7960. + if (!oldpkg->tmp_unpack_dir)
  7961. + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
  7962. + if (!oldpkg->md5sum)
  7963. + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
  7964. + if (!oldpkg->size)
  7965. + oldpkg->size = str_dup_safe(newpkg->size);
  7966. + if (!oldpkg->installed_size)
  7967. + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
  7968. + if (!oldpkg->priority)
  7969. + oldpkg->priority = str_dup_safe(newpkg->priority);
  7970. + if (!oldpkg->source)
  7971. + oldpkg->source = str_dup_safe(newpkg->source);
  7972. + if (oldpkg->conffiles.head == NULL){
  7973. + oldpkg->conffiles = newpkg->conffiles;
  7974. + conffile_list_init(&newpkg->conffiles);
  7975. + }
  7976. + if (!oldpkg->installed_files){
  7977. + oldpkg->installed_files = newpkg->installed_files;
  7978. + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
  7979. + newpkg->installed_files = NULL;
  7980. + }
  7981. + if (!oldpkg->essential)
  7982. + oldpkg->essential = newpkg->essential;
  7983. +
  7984. + return 0;
  7985. +}
  7986. +
  7987. +abstract_pkg_t *abstract_pkg_new(void)
  7988. +{
  7989. + abstract_pkg_t * ab_pkg;
  7990. +
  7991. + ab_pkg = malloc(sizeof(abstract_pkg_t));
  7992. +
  7993. + if (ab_pkg == NULL) {
  7994. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7995. + return NULL;
  7996. + }
  7997. +
  7998. + if ( abstract_pkg_init(ab_pkg) < 0 )
  7999. + return NULL;
  8000. +
  8001. + return ab_pkg;
  8002. +}
  8003. +
  8004. +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
  8005. +{
  8006. + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
  8007. +
  8008. + ab_pkg->provided_by = abstract_pkg_vec_alloc();
  8009. + if (ab_pkg->provided_by==NULL){
  8010. + return -1;
  8011. + }
  8012. + ab_pkg->dependencies_checked = 0;
  8013. + ab_pkg->state_status = SS_NOT_INSTALLED;
  8014. +
  8015. + return 0;
  8016. +}
  8017. +
  8018. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
  8019. + char * temp_str;
  8020. + char **raw =NULL;
  8021. + char **raw_start=NULL;
  8022. +
  8023. + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
  8024. + if (temp_str == NULL ){
  8025. + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
  8026. + return;
  8027. + }
  8028. + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
  8029. +
  8030. + raw = raw_start = read_raw_pkgs_from_file(temp_str);
  8031. + if (raw == NULL ){
  8032. + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
  8033. + return;
  8034. + }
  8035. +
  8036. + while(*raw){
  8037. + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
  8038. + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
  8039. + }
  8040. + }
  8041. + raw = raw_start;
  8042. + while (*raw) {
  8043. + if (raw!=NULL)
  8044. + free(*raw++);
  8045. + }
  8046. +
  8047. + free(raw_start);
  8048. + free(temp_str);
  8049. +
  8050. + return ;
  8051. +
  8052. +}
  8053. +
  8054. +char * pkg_formatted_info(pkg_t *pkg )
  8055. +{
  8056. + char *line;
  8057. + char * buff;
  8058. +
  8059. + buff = malloc(8192);
  8060. + if (buff == NULL) {
  8061. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8062. + return NULL;
  8063. + }
  8064. +
  8065. + buff[0] = '\0';
  8066. +
  8067. + line = pkg_formatted_field(pkg, "Package");
  8068. + strncat(buff ,line, strlen(line));
  8069. + free(line);
  8070. +
  8071. + line = pkg_formatted_field(pkg, "Version");
  8072. + strncat(buff ,line, strlen(line));
  8073. + free(line);
  8074. +
  8075. + line = pkg_formatted_field(pkg, "Depends");
  8076. + strncat(buff ,line, strlen(line));
  8077. + free(line);
  8078. +
  8079. + line = pkg_formatted_field(pkg, "Recommends");
  8080. + strncat(buff ,line, strlen(line));
  8081. + free(line);
  8082. +
  8083. + line = pkg_formatted_field(pkg, "Suggests");
  8084. + strncat(buff ,line, strlen(line));
  8085. + free(line);
  8086. +
  8087. + line = pkg_formatted_field(pkg, "Provides");
  8088. + strncat(buff ,line, strlen(line));
  8089. + free(line);
  8090. +
  8091. + line = pkg_formatted_field(pkg, "Replaces");
  8092. + strncat(buff ,line, strlen(line));
  8093. + free(line);
  8094. +
  8095. + line = pkg_formatted_field(pkg, "Conflicts");
  8096. + strncat(buff ,line, strlen(line));
  8097. + free(line);
  8098. +
  8099. + line = pkg_formatted_field(pkg, "Status");
  8100. + strncat(buff ,line, strlen(line));
  8101. + free(line);
  8102. +
  8103. + line = pkg_formatted_field(pkg, "Section");
  8104. + strncat(buff ,line, strlen(line));
  8105. + free(line);
  8106. +
  8107. + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
  8108. + strncat(buff ,line, strlen(line));
  8109. + free(line);
  8110. +
  8111. + line = pkg_formatted_field(pkg, "Architecture");
  8112. + strncat(buff ,line, strlen(line));
  8113. + free(line);
  8114. +
  8115. + line = pkg_formatted_field(pkg, "Maintainer");
  8116. + strncat(buff ,line, strlen(line));
  8117. + free(line);
  8118. +
  8119. + line = pkg_formatted_field(pkg, "MD5sum");
  8120. + strncat(buff ,line, strlen(line));
  8121. + free(line);
  8122. +
  8123. + line = pkg_formatted_field(pkg, "Size");
  8124. + strncat(buff ,line, strlen(line));
  8125. + free(line);
  8126. +
  8127. + line = pkg_formatted_field(pkg, "Filename");
  8128. + strncat(buff ,line, strlen(line));
  8129. + free(line);
  8130. +
  8131. + line = pkg_formatted_field(pkg, "Conffiles");
  8132. + strncat(buff ,line, strlen(line));
  8133. + free(line);
  8134. +
  8135. + line = pkg_formatted_field(pkg, "Source");
  8136. + strncat(buff ,line, strlen(line));
  8137. + free(line);
  8138. +
  8139. + line = pkg_formatted_field(pkg, "Description");
  8140. + strncat(buff ,line, strlen(line));
  8141. + free(line);
  8142. +
  8143. + line = pkg_formatted_field(pkg, "Installed-Time");
  8144. + strncat(buff ,line, strlen(line));
  8145. + free(line);
  8146. +
  8147. + return buff;
  8148. +}
  8149. +
  8150. +char * pkg_formatted_field(pkg_t *pkg, const char *field )
  8151. +{
  8152. + static size_t LINE_LEN = 128;
  8153. + char * temp = (char *)malloc(1);
  8154. + int len = 0;
  8155. + int flag_provide_false = 0;
  8156. +
  8157. +/*
  8158. + Pigi: After some discussion with Florian we decided to modify the full procedure in
  8159. + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
  8160. +*/
  8161. +
  8162. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8163. + goto UNKNOWN_FMT_FIELD;
  8164. + }
  8165. +
  8166. + temp[0]='\0';
  8167. +
  8168. + switch (field[0])
  8169. + {
  8170. + case 'a':
  8171. + case 'A':
  8172. + if (strcasecmp(field, "Architecture") == 0) {
  8173. + /* Architecture */
  8174. + if (pkg->architecture) {
  8175. + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
  8176. + if ( temp == NULL ){
  8177. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8178. + return NULL;
  8179. + }
  8180. + temp[0]='\0';
  8181. + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
  8182. + }
  8183. + } else {
  8184. + goto UNKNOWN_FMT_FIELD;
  8185. + }
  8186. + break;
  8187. + case 'c':
  8188. + case 'C':
  8189. + if (strcasecmp(field, "Conffiles") == 0) {
  8190. + /* Conffiles */
  8191. + conffile_list_elt_t *iter;
  8192. + char confstr_[LINE_LEN];
  8193. +
  8194. + if (pkg->conffiles.head == NULL) {
  8195. + return temp;
  8196. + }
  8197. +
  8198. + len = 14 ;
  8199. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8200. + if (iter->data->name && iter->data->value) {
  8201. + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
  8202. + }
  8203. + }
  8204. + temp = (char *)realloc(temp,len);
  8205. + if ( temp == NULL ){
  8206. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8207. + return NULL;
  8208. + }
  8209. + temp[0]='\0';
  8210. + strncpy(temp, "Conffiles:\n", 12);
  8211. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8212. + if (iter->data->name && iter->data->value) {
  8213. + snprintf(confstr_, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
  8214. + strncat(temp, confstr_, strlen(confstr_));
  8215. + }
  8216. + }
  8217. + } else if (strcasecmp(field, "Conflicts") == 0) {
  8218. + int i;
  8219. +
  8220. + if (pkg->conflicts_count) {
  8221. + char conflictstr[LINE_LEN];
  8222. + len = 14 ;
  8223. + for(i = 0; i < pkg->conflicts_count; i++) {
  8224. + len = len + (strlen(pkg->conflicts_str[i])+5);
  8225. + }
  8226. + temp = (char *)realloc(temp,len);
  8227. + if ( temp == NULL ){
  8228. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8229. + return NULL;
  8230. + }
  8231. + temp[0]='\0';
  8232. + strncpy(temp, "Conflicts:", 11);
  8233. + for(i = 0; i < pkg->conflicts_count; i++) {
  8234. + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
  8235. + strncat(temp, conflictstr, strlen(conflictstr));
  8236. + }
  8237. + strncat(temp, "\n", strlen("\n"));
  8238. + }
  8239. + } else {
  8240. + goto UNKNOWN_FMT_FIELD;
  8241. + }
  8242. + break;
  8243. + case 'd':
  8244. + case 'D':
  8245. + if (strcasecmp(field, "Depends") == 0) {
  8246. + /* Depends */
  8247. + int i;
  8248. +
  8249. + if (pkg->depends_count) {
  8250. + char depstr[LINE_LEN];
  8251. + len = 14 ;
  8252. + for(i = 0; i < pkg->depends_count; i++) {
  8253. + len = len + (strlen(pkg->depends_str[i])+4);
  8254. + }
  8255. + temp = (char *)realloc(temp,len);
  8256. + if ( temp == NULL ){
  8257. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8258. + return NULL;
  8259. + }
  8260. + temp[0]='\0';
  8261. + strncpy(temp, "Depends:", 10);
  8262. + for(i = 0; i < pkg->depends_count; i++) {
  8263. + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
  8264. + strncat(temp, depstr, strlen(depstr));
  8265. + }
  8266. + strncat(temp, "\n", strlen("\n"));
  8267. + }
  8268. + } else if (strcasecmp(field, "Description") == 0) {
  8269. + /* Description */
  8270. + if (pkg->description) {
  8271. + temp = (char *)realloc(temp,strlen(pkg->description)+16);
  8272. + if ( temp == NULL ){
  8273. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8274. + return NULL;
  8275. + }
  8276. + temp[0]='\0';
  8277. + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
  8278. + }
  8279. + } else {
  8280. + goto UNKNOWN_FMT_FIELD;
  8281. + }
  8282. + break;
  8283. + case 'e':
  8284. + case 'E': {
  8285. + /* Essential */
  8286. + if (pkg->essential) {
  8287. + temp = (char *)realloc(temp,16);
  8288. + if ( temp == NULL ){
  8289. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8290. + return NULL;
  8291. + }
  8292. + temp[0]='\0';
  8293. + snprintf(temp, (16), "Essential: yes\n");
  8294. + }
  8295. + }
  8296. + break;
  8297. + case 'f':
  8298. + case 'F': {
  8299. + /* Filename */
  8300. + if (pkg->filename) {
  8301. + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
  8302. + if ( temp == NULL ){
  8303. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8304. + return NULL;
  8305. + }
  8306. + temp[0]='\0';
  8307. + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
  8308. + }
  8309. + }
  8310. + break;
  8311. + case 'i':
  8312. + case 'I': {
  8313. + if (strcasecmp(field, "Installed-Size") == 0) {
  8314. + /* Installed-Size */
  8315. + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
  8316. + if ( temp == NULL ){
  8317. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8318. + return NULL;
  8319. + }
  8320. + temp[0]='\0';
  8321. + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
  8322. + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
  8323. + temp = (char *)realloc(temp,29);
  8324. + if ( temp == NULL ){
  8325. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8326. + return NULL;
  8327. + }
  8328. + temp[0]='\0';
  8329. + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
  8330. + }
  8331. + }
  8332. + break;
  8333. + case 'm':
  8334. + case 'M': {
  8335. + /* Maintainer | MD5sum */
  8336. + if (strcasecmp(field, "Maintainer") == 0) {
  8337. + /* Maintainer */
  8338. + if (pkg->maintainer) {
  8339. + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
  8340. + if ( temp == NULL ){
  8341. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8342. + return NULL;
  8343. + }
  8344. + temp[0]='\0';
  8345. + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
  8346. + }
  8347. + } else if (strcasecmp(field, "MD5sum") == 0) {
  8348. + /* MD5sum */
  8349. + if (pkg->md5sum) {
  8350. + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
  8351. + if ( temp == NULL ){
  8352. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8353. + return NULL;
  8354. + }
  8355. + temp[0]='\0';
  8356. + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
  8357. + }
  8358. + } else {
  8359. + goto UNKNOWN_FMT_FIELD;
  8360. + }
  8361. + }
  8362. + break;
  8363. + case 'p':
  8364. + case 'P': {
  8365. + if (strcasecmp(field, "Package") == 0) {
  8366. + /* Package */
  8367. + temp = (char *)realloc(temp,strlen(pkg->name)+11);
  8368. + if ( temp == NULL ){
  8369. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8370. + return NULL;
  8371. + }
  8372. + temp[0]='\0';
  8373. + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
  8374. + } else if (strcasecmp(field, "Priority") == 0) {
  8375. + /* Priority */
  8376. + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
  8377. + if ( temp == NULL ){
  8378. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8379. + return NULL;
  8380. + }
  8381. + temp[0]='\0';
  8382. + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
  8383. + } else if (strcasecmp(field, "Provides") == 0) {
  8384. + /* Provides */
  8385. + int i;
  8386. +
  8387. + if (pkg->provides_count) {
  8388. + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
  8389. + for ( i=0; i < pkg->provides_count; i++ ){
  8390. + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
  8391. + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
  8392. + flag_provide_false = 1;
  8393. + }
  8394. + }
  8395. + if ( !flag_provide_false || /* Pigi there is not my trick flag */
  8396. + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
  8397. + char provstr[LINE_LEN];
  8398. + len = 15;
  8399. + for(i = 0; i < pkg->provides_count; i++) {
  8400. + len = len + (strlen(pkg->provides_str[i])+5);
  8401. + }
  8402. + temp = (char *)realloc(temp,len);
  8403. + if ( temp == NULL ){
  8404. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8405. + return NULL;
  8406. + }
  8407. + temp[0]='\0';
  8408. + strncpy(temp, "Provides:", 12);
  8409. + for(i = 0; i < pkg->provides_count; i++) {
  8410. + if (strlen(pkg->provides_str[i])>0){;
  8411. + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
  8412. + strncat(temp, provstr, strlen(provstr));
  8413. + }
  8414. + }
  8415. + strncat(temp, "\n", strlen("\n"));
  8416. + }
  8417. + }
  8418. + } else {
  8419. + goto UNKNOWN_FMT_FIELD;
  8420. + }
  8421. + }
  8422. + break;
  8423. + case 'r':
  8424. + case 'R': {
  8425. + int i;
  8426. + /* Replaces | Recommends*/
  8427. + if (strcasecmp (field, "Replaces") == 0) {
  8428. + if (pkg->replaces_count) {
  8429. + char replstr[LINE_LEN];
  8430. + len = 14;
  8431. + for (i = 0; i < pkg->replaces_count; i++) {
  8432. + len = len + (strlen(pkg->replaces_str[i])+5);
  8433. + }
  8434. + temp = (char *)realloc(temp,len);
  8435. + if ( temp == NULL ){
  8436. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8437. + return NULL;
  8438. + }
  8439. + temp[0]='\0';
  8440. + strncpy(temp, "Replaces:", 12);
  8441. + for (i = 0; i < pkg->replaces_count; i++) {
  8442. + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
  8443. + strncat(temp, replstr, strlen(replstr));
  8444. + }
  8445. + strncat(temp, "\n", strlen("\n"));
  8446. + }
  8447. + } else if (strcasecmp (field, "Recommends") == 0) {
  8448. + if (pkg->recommends_count) {
  8449. + char recstr[LINE_LEN];
  8450. + len = 15;
  8451. + for(i = 0; i < pkg->recommends_count; i++) {
  8452. + len = len + (strlen( pkg->recommends_str[i])+5);
  8453. + }
  8454. + temp = (char *)realloc(temp,len);
  8455. + if ( temp == NULL ){
  8456. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8457. + return NULL;
  8458. + }
  8459. + temp[0]='\0';
  8460. + strncpy(temp, "Recommends:", 13);
  8461. + for(i = 0; i < pkg->recommends_count; i++) {
  8462. + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
  8463. + strncat(temp, recstr, strlen(recstr));
  8464. + }
  8465. + strncat(temp, "\n", strlen("\n"));
  8466. + }
  8467. + } else {
  8468. + goto UNKNOWN_FMT_FIELD;
  8469. + }
  8470. + }
  8471. + break;
  8472. + case 's':
  8473. + case 'S': {
  8474. + /* Section | Size | Source | Status | Suggests */
  8475. + if (strcasecmp(field, "Section") == 0) {
  8476. + /* Section */
  8477. + if (pkg->section) {
  8478. + temp = (char *)realloc(temp,strlen(pkg->section)+11);
  8479. + if ( temp == NULL ){
  8480. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8481. + return NULL;
  8482. + }
  8483. + temp[0]='\0';
  8484. + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
  8485. + }
  8486. + } else if (strcasecmp(field, "Size") == 0) {
  8487. + /* Size */
  8488. + if (pkg->size) {
  8489. + temp = (char *)realloc(temp,strlen(pkg->size)+8);
  8490. + if ( temp == NULL ){
  8491. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8492. + return NULL;
  8493. + }
  8494. + temp[0]='\0';
  8495. + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
  8496. + }
  8497. + } else if (strcasecmp(field, "Source") == 0) {
  8498. + /* Source */
  8499. + if (pkg->source) {
  8500. + temp = (char *)realloc(temp,strlen(pkg->source)+10);
  8501. + if ( temp == NULL ){
  8502. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8503. + return NULL;
  8504. + }
  8505. + temp[0]='\0';
  8506. + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
  8507. + }
  8508. + } else if (strcasecmp(field, "Status") == 0) {
  8509. + /* Status */
  8510. + /* Benjamin Pineau note: we should avoid direct usage of
  8511. + * strlen(arg) without keeping "arg" for later free()
  8512. + */
  8513. + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
  8514. + char *pstat=pkg_state_status_to_str(pkg->state_status);
  8515. + char *pwant=pkg_state_want_to_str(pkg->state_want);
  8516. +
  8517. + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
  8518. + temp = (char *)realloc(temp,sum_of_sizes);
  8519. + if ( temp == NULL ){
  8520. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8521. + return NULL;
  8522. + }
  8523. + temp[0]='\0';
  8524. + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
  8525. + free(pflag);
  8526. + free(pwant);
  8527. + if(pstat) /* pfstat can be NULL if ENOMEM */
  8528. + free(pstat);
  8529. + } else if (strcasecmp(field, "Suggests") == 0) {
  8530. + if (pkg->suggests_count) {
  8531. + int i;
  8532. + char sugstr[LINE_LEN];
  8533. + len = 13;
  8534. + for(i = 0; i < pkg->suggests_count; i++) {
  8535. + len = len + (strlen(pkg->suggests_str[i])+5);
  8536. + }
  8537. + temp = (char *)realloc(temp,len);
  8538. + if ( temp == NULL ){
  8539. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8540. + return NULL;
  8541. + }
  8542. + temp[0]='\0';
  8543. + strncpy(temp, "Suggests:", 10);
  8544. + for(i = 0; i < pkg->suggests_count; i++) {
  8545. + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
  8546. + strncat(temp, sugstr, strlen(sugstr));
  8547. + }
  8548. + strncat(temp, "\n", strlen("\n"));
  8549. + }
  8550. + } else {
  8551. + goto UNKNOWN_FMT_FIELD;
  8552. + }
  8553. + }
  8554. + break;
  8555. + case 'v':
  8556. + case 'V': {
  8557. + /* Version */
  8558. + char *version = pkg_version_str_alloc(pkg);
  8559. + temp = (char *)realloc(temp,strlen(version)+14);
  8560. + if ( temp == NULL ){
  8561. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8562. + return NULL;
  8563. + }
  8564. + temp[0]='\0';
  8565. + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
  8566. + free(version);
  8567. + }
  8568. + break;
  8569. + default:
  8570. + goto UNKNOWN_FMT_FIELD;
  8571. + }
  8572. +
  8573. + if ( strlen(temp)<2 ) {
  8574. + temp[0]='\0';
  8575. + }
  8576. + return temp;
  8577. +
  8578. + UNKNOWN_FMT_FIELD:
  8579. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
  8580. + if ( strlen(temp)<2 ) {
  8581. + temp[0]='\0';
  8582. + }
  8583. +
  8584. + return temp;
  8585. +}
  8586. +
  8587. +void pkg_print_info(pkg_t *pkg, FILE *file)
  8588. +{
  8589. + char * buff;
  8590. + if (pkg == NULL) {
  8591. + return;
  8592. + }
  8593. +
  8594. + buff = pkg_formatted_info(pkg);
  8595. + if ( buff == NULL )
  8596. + return;
  8597. + if (strlen(buff)>2){
  8598. + fwrite(buff, 1, strlen(buff), file);
  8599. + }
  8600. + free(buff);
  8601. +}
  8602. +
  8603. +void pkg_print_status(pkg_t * pkg, FILE * file)
  8604. +{
  8605. + if (pkg == NULL) {
  8606. + return;
  8607. + }
  8608. +
  8609. + /* XXX: QUESTION: Do we actually want more fields here? The
  8610. + original idea was to save space by installing only what was
  8611. + needed for actual computation, (package, version, status,
  8612. + essential, conffiles). The assumption is that all other fields
  8613. + can be found in th available file.
  8614. +
  8615. + But, someone proposed the idea to make it possible to
  8616. + reconstruct a .ipk from an installed package, (ie. for beaming
  8617. + from one handheld to another). So, maybe we actually want a few
  8618. + more fields here, (depends, suggests, etc.), so that that would
  8619. + be guaranteed to work even in the absence of more information
  8620. + from the available file.
  8621. +
  8622. + 28-MAR-03: kergoth and I discussed this yesterday. We think
  8623. + the essential info needs to be here for all installed packages
  8624. + because they may not appear in the Packages files on various
  8625. + feeds. Furthermore, one should be able to install from URL or
  8626. + local storage without requiring a Packages file from any feed.
  8627. + -Jamey
  8628. + */
  8629. + pkg_print_field(pkg, file, "Package");
  8630. + pkg_print_field(pkg, file, "Version");
  8631. + pkg_print_field(pkg, file, "Depends");
  8632. + pkg_print_field(pkg, file, "Recommends");
  8633. + pkg_print_field(pkg, file, "Suggests");
  8634. + pkg_print_field(pkg, file, "Provides");
  8635. + pkg_print_field(pkg, file, "Replaces");
  8636. + pkg_print_field(pkg, file, "Conflicts");
  8637. + pkg_print_field(pkg, file, "Status");
  8638. + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
  8639. + pkg_print_field(pkg, file, "Architecture");
  8640. + pkg_print_field(pkg, file, "Conffiles");
  8641. + pkg_print_field(pkg, file, "Installed-Time");
  8642. + fputs("\n", file);
  8643. +}
  8644. +
  8645. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
  8646. +{
  8647. + char *buff;
  8648. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8649. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
  8650. + __FUNCTION__, field);
  8651. + }
  8652. + buff = pkg_formatted_field(pkg, field);
  8653. + if (strlen(buff)>2) {
  8654. + fprintf(file, "%s", buff);
  8655. + fflush(file);
  8656. + }
  8657. + free(buff);
  8658. + return;
  8659. +}
  8660. +
  8661. +/*
  8662. + * libdpkg - Debian packaging suite library routines
  8663. + * vercmp.c - comparison of version numbers
  8664. + *
  8665. + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  8666. + */
  8667. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
  8668. +{
  8669. + int r;
  8670. +
  8671. + if (pkg->epoch > ref_pkg->epoch) {
  8672. + return 1;
  8673. + }
  8674. +
  8675. + if (pkg->epoch < ref_pkg->epoch) {
  8676. + return -1;
  8677. + }
  8678. +
  8679. + r = verrevcmp(pkg->version, ref_pkg->version);
  8680. + if (r) {
  8681. + return r;
  8682. + }
  8683. +
  8684. +#ifdef USE_DEBVERSION
  8685. + r = verrevcmp(pkg->revision, ref_pkg->revision);
  8686. + if (r) {
  8687. + return r;
  8688. + }
  8689. +
  8690. + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
  8691. +#endif
  8692. +
  8693. + return r;
  8694. +}
  8695. +
  8696. +int verrevcmp(const char *val, const char *ref)
  8697. +{
  8698. + int vc, rc;
  8699. + long vl, rl;
  8700. + const char *vp, *rp;
  8701. + const char *vsep, *rsep;
  8702. +
  8703. + if (!val) val= "";
  8704. + if (!ref) ref= "";
  8705. + for (;;) {
  8706. + vp= val; while (*vp && !isdigit(*vp)) vp++;
  8707. + rp= ref; while (*rp && !isdigit(*rp)) rp++;
  8708. + for (;;) {
  8709. + vc= (val == vp) ? 0 : *val++;
  8710. + rc= (ref == rp) ? 0 : *ref++;
  8711. + if (!rc && !vc) break;
  8712. + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
  8713. + if (rc && !isalpha(rc)) rc += 256;
  8714. + if (vc != rc) return vc - rc;
  8715. + }
  8716. + val= vp;
  8717. + ref= rp;
  8718. + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
  8719. + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
  8720. + if (vl != rl) return vl - rl;
  8721. +
  8722. + vc = *val;
  8723. + rc = *ref;
  8724. + vsep = strchr(".-", vc);
  8725. + rsep = strchr(".-", rc);
  8726. + if (vsep && !rsep) return -1;
  8727. + if (!vsep && rsep) return +1;
  8728. +
  8729. + if (!*val && !*ref) return 0;
  8730. + if (!*val) return -1;
  8731. + if (!*ref) return +1;
  8732. + }
  8733. +}
  8734. +
  8735. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
  8736. +{
  8737. + int r;
  8738. +
  8739. + r = pkg_compare_versions(it, ref);
  8740. +
  8741. + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
  8742. + return r <= 0;
  8743. + }
  8744. +
  8745. + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
  8746. + return r >= 0;
  8747. + }
  8748. +
  8749. + if (strcmp(op, "<<") == 0) {
  8750. + return r < 0;
  8751. + }
  8752. +
  8753. + if (strcmp(op, ">>") == 0) {
  8754. + return r > 0;
  8755. + }
  8756. +
  8757. + if (strcmp(op, "=") == 0) {
  8758. + return r == 0;
  8759. + }
  8760. +
  8761. + fprintf(stderr, "unknown operator: %s", op);
  8762. + return 0;
  8763. +}
  8764. +
  8765. +int pkg_name_version_and_architecture_compare(pkg_t *p1, pkg_t *p2)
  8766. +{
  8767. + const pkg_t *a = *(const pkg_t **)p1;
  8768. + const pkg_t *b = *(const pkg_t **)p2;
  8769. + int namecmp;
  8770. + int vercmp;
  8771. + if (!a->name || !b->name) {
  8772. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8773. + a, a->name, b, b->name);
  8774. + return 0;
  8775. + }
  8776. +
  8777. + namecmp = strcmp(a->name, b->name);
  8778. + if (namecmp)
  8779. + return namecmp;
  8780. + vercmp = pkg_compare_versions(a, b);
  8781. + if (vercmp)
  8782. + return vercmp;
  8783. + if (!a->arch_priority || !b->arch_priority) {
  8784. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
  8785. + a, a->arch_priority, b, b->arch_priority);
  8786. + return 0;
  8787. + }
  8788. + if (a->arch_priority > b->arch_priority)
  8789. + return 1;
  8790. + if (a->arch_priority < b->arch_priority)
  8791. + return -1;
  8792. + return 0;
  8793. +}
  8794. +
  8795. +int abstract_pkg_name_compare(abstract_pkg_t *p1, abstract_pkg_t *p2)
  8796. +{
  8797. + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
  8798. + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
  8799. + if (!a->name || !b->name) {
  8800. + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8801. + a, a->name, b, b->name);
  8802. + return 0;
  8803. + }
  8804. + return strcmp(a->name, b->name);
  8805. +}
  8806. +
  8807. +
  8808. +char *pkg_version_str_alloc(pkg_t *pkg)
  8809. +{
  8810. + char *complete_version;
  8811. + char *epoch_str;
  8812. +#ifdef USE_DEBVERSION
  8813. + char *revision_str;
  8814. + char *familiar_revision_str;
  8815. +#endif
  8816. +
  8817. + if (pkg->epoch) {
  8818. + sprintf_alloc(&epoch_str, "%lu:", (unsigned long)pkg->epoch);
  8819. + } else {
  8820. + epoch_str = strdup("");
  8821. + }
  8822. +
  8823. +#ifdef USE_DEBVERSION
  8824. + if (pkg->revision && strlen(pkg->revision)) {
  8825. + sprintf_alloc(&revision_str, "-%s", pkg->revision);
  8826. + } else {
  8827. + revision_str = strdup("");
  8828. + }
  8829. +
  8830. + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
  8831. + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
  8832. + } else {
  8833. + familiar_revision_str = strdup("");
  8834. + }
  8835. +#endif
  8836. +
  8837. +#ifdef USE_DEBVERSION
  8838. + sprintf_alloc(&complete_version, "%s%s%s%s",
  8839. + epoch_str, pkg->version, revision_str, familiar_revision_str);
  8840. +#else
  8841. + sprintf_alloc(&complete_version, "%s%s",
  8842. + epoch_str, pkg->version);
  8843. +#endif
  8844. +
  8845. + free(epoch_str);
  8846. +#ifdef USE_DEBVERSION
  8847. + free(revision_str);
  8848. + free(familiar_revision_str);
  8849. +#endif
  8850. +
  8851. + return complete_version;
  8852. +}
  8853. +
  8854. +str_list_t *pkg_get_installed_files(pkg_t *pkg)
  8855. +{
  8856. + int err;
  8857. + char *list_file_name = NULL;
  8858. + FILE *list_file = NULL;
  8859. + char *line;
  8860. + char *installed_file_name;
  8861. + int rootdirlen;
  8862. +
  8863. + pkg->installed_files_ref_cnt++;
  8864. +
  8865. + if (pkg->installed_files) {
  8866. + return pkg->installed_files;
  8867. + }
  8868. +
  8869. + pkg->installed_files = str_list_alloc();
  8870. + if (pkg->installed_files == NULL) {
  8871. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8872. + return NULL;
  8873. + }
  8874. +
  8875. + /* For uninstalled packages, get the file list firectly from the package.
  8876. + For installed packages, look at the package.list file in the database.
  8877. + */
  8878. + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
  8879. + if (pkg->local_filename == NULL) {
  8880. + return pkg->installed_files;
  8881. + }
  8882. + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
  8883. + file. In other words, change deb_extract so that it can
  8884. + simply return the file list as a char *[] rather than
  8885. + insisting on writing in to a FILE * as it does now. */
  8886. + list_file = tmpfile();
  8887. + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
  8888. + if (err) {
  8889. + fclose(list_file);
  8890. + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
  8891. + __FUNCTION__, pkg->local_filename, strerror(err));
  8892. + return pkg->installed_files;
  8893. + }
  8894. + rewind(list_file);
  8895. + } else {
  8896. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8897. + pkg->dest->info_dir, pkg->name);
  8898. + if (! file_exists(list_file_name)) {
  8899. + free(list_file_name);
  8900. + return pkg->installed_files;
  8901. + }
  8902. +
  8903. + list_file = fopen(list_file_name, "r");
  8904. + if (list_file == NULL) {
  8905. + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
  8906. + list_file_name, strerror(errno));
  8907. + free(list_file_name);
  8908. + return pkg->installed_files;
  8909. + }
  8910. + free(list_file_name);
  8911. + }
  8912. +
  8913. + rootdirlen = strlen( pkg->dest->root_dir );
  8914. + while (1) {
  8915. + char *file_name;
  8916. +
  8917. + line = file_read_line_alloc(list_file);
  8918. + if (line == NULL) {
  8919. + break;
  8920. + }
  8921. + str_chomp(line);
  8922. + file_name = line;
  8923. +
  8924. + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
  8925. + if( strncmp( pkg->dest->root_dir,
  8926. + file_name,
  8927. + rootdirlen ) ) {
  8928. + if (*file_name == '.') {
  8929. + file_name++;
  8930. + }
  8931. + if (*file_name == '/') {
  8932. + file_name++;
  8933. + }
  8934. +
  8935. + /* Freed in pkg_free_installed_files */
  8936. + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
  8937. + } else {
  8938. + // already contains root_dir as header -> ABSOLUTE
  8939. + sprintf_alloc(&installed_file_name, "%s", file_name);
  8940. + }
  8941. + str_list_append(pkg->installed_files, installed_file_name);
  8942. + free(line);
  8943. + }
  8944. +
  8945. + fclose(list_file);
  8946. +
  8947. + return pkg->installed_files;
  8948. +}
  8949. +
  8950. +/* XXX: CLEANUP: This function and it's counterpart,
  8951. + (pkg_get_installed_files), do not match our init/deinit naming
  8952. + convention. Nor the alloc/free convention. But, then again, neither
  8953. + of these conventions currrently fit the way these two functions
  8954. + work. */
  8955. +int pkg_free_installed_files(pkg_t *pkg)
  8956. +{
  8957. + str_list_elt_t *iter;
  8958. +
  8959. + pkg->installed_files_ref_cnt--;
  8960. + if (pkg->installed_files_ref_cnt > 0) {
  8961. + return 0;
  8962. + }
  8963. +
  8964. + if (pkg->installed_files) {
  8965. +
  8966. + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
  8967. + /* malloced in pkg_get_installed_files */
  8968. + free (iter->data);
  8969. + iter->data = NULL;
  8970. + }
  8971. +
  8972. + str_list_deinit(pkg->installed_files);
  8973. + }
  8974. +
  8975. + pkg->installed_files = NULL;
  8976. +
  8977. + return 0;
  8978. +}
  8979. +
  8980. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
  8981. +{
  8982. + int err;
  8983. + char *list_file_name;
  8984. +
  8985. + //I don't think pkg_free_installed_files should be called here. Jamey
  8986. + //pkg_free_installed_files(pkg);
  8987. +
  8988. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8989. + pkg->dest->info_dir, pkg->name);
  8990. + if (!conf->noaction) {
  8991. + err = unlink(list_file_name);
  8992. + free(list_file_name);
  8993. +
  8994. + if (err) {
  8995. + return errno;
  8996. + }
  8997. + }
  8998. + return 0;
  8999. +}
  9000. +
  9001. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
  9002. +{
  9003. + conffile_list_elt_t *iter;
  9004. + conffile_t *conffile;
  9005. +
  9006. + if (pkg == NULL) {
  9007. + return NULL;
  9008. + }
  9009. +
  9010. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  9011. + conffile = iter->data;
  9012. +
  9013. + if (strcmp(conffile->name, file_name) == 0) {
  9014. + return conffile;
  9015. + }
  9016. + }
  9017. +
  9018. + return NULL;
  9019. +}
  9020. +
  9021. +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
  9022. + const char *script, const char *args)
  9023. +{
  9024. + int err;
  9025. + char *path;
  9026. + char *cmd;
  9027. +
  9028. + /* XXX: FEATURE: When conf->offline_root is set, we should run the
  9029. + maintainer script within a chroot environment. */
  9030. +
  9031. + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
  9032. + have scripts in pkg->tmp_unpack_dir. */
  9033. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  9034. + if (pkg->dest == NULL) {
  9035. + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
  9036. + __FUNCTION__, pkg->name);
  9037. + return EINVAL;
  9038. + }
  9039. + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
  9040. + } else {
  9041. + if (pkg->tmp_unpack_dir == NULL) {
  9042. + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
  9043. + __FUNCTION__, pkg->name);
  9044. + return EINVAL;
  9045. + }
  9046. + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
  9047. + }
  9048. +
  9049. + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
  9050. + if (conf->noaction) return 0;
  9051. +
  9052. + /* XXX: CLEANUP: There must be a better way to handle maintainer
  9053. + scripts when running with offline_root mode and/or a dest other
  9054. + than '/'. I've been playing around with some clever chroot
  9055. + tricks and I might come up with something workable. */
  9056. + if (conf->offline_root) {
  9057. + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
  9058. + }
  9059. +
  9060. + setenv("PKG_ROOT",
  9061. + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
  9062. +
  9063. + if (! file_exists(path)) {
  9064. + free(path);
  9065. + return 0;
  9066. + }
  9067. +
  9068. + if (conf->offline_root) {
  9069. + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
  9070. + free(path);
  9071. + return 0;
  9072. + }
  9073. +
  9074. + sprintf_alloc(&cmd, "%s %s", path, args);
  9075. + free(path);
  9076. +
  9077. + err = xsystem(cmd);
  9078. + free(cmd);
  9079. +
  9080. + if (err) {
  9081. + fprintf(stderr, "%s script returned status %d\n", script, err);
  9082. + return err;
  9083. + }
  9084. +
  9085. + return 0;
  9086. +}
  9087. +
  9088. +char *pkg_state_want_to_str(pkg_state_want_t sw)
  9089. +{
  9090. + int i;
  9091. +
  9092. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9093. + if (pkg_state_want_map[i].value == sw) {
  9094. + return strdup(pkg_state_want_map[i].str);
  9095. + }
  9096. + }
  9097. +
  9098. + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
  9099. + __FUNCTION__, sw);
  9100. + return strdup("<STATE_WANT_UNKNOWN>");
  9101. +}
  9102. +
  9103. +pkg_state_want_t pkg_state_want_from_str(char *str)
  9104. +{
  9105. + int i;
  9106. +
  9107. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9108. + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
  9109. + return pkg_state_want_map[i].value;
  9110. + }
  9111. + }
  9112. +
  9113. + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
  9114. + __FUNCTION__, str);
  9115. + return SW_UNKNOWN;
  9116. +}
  9117. +
  9118. +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
  9119. +{
  9120. + int i;
  9121. + int len = 3; /* ok\000 is minimum */
  9122. + char *str = NULL;
  9123. +
  9124. + /* clear the temporary flags before converting to string */
  9125. + sf &= SF_NONVOLATILE_FLAGS;
  9126. +
  9127. + if (sf == 0) {
  9128. + return strdup("ok");
  9129. + } else {
  9130. +
  9131. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9132. + if (sf & pkg_state_flag_map[i].value) {
  9133. + len += strlen(pkg_state_flag_map[i].str) + 1;
  9134. + }
  9135. + }
  9136. + str = malloc(len);
  9137. + if ( str == NULL ) {
  9138. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9139. + return NULL;
  9140. + }
  9141. + str[0] = 0;
  9142. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9143. + if (sf & pkg_state_flag_map[i].value) {
  9144. + strcat(str, pkg_state_flag_map[i].str);
  9145. + strcat(str, ",");
  9146. + }
  9147. + }
  9148. + len = strlen(str);
  9149. + str[len-1] = 0; /* squash last comma */
  9150. + return str;
  9151. + }
  9152. +}
  9153. +
  9154. +pkg_state_flag_t pkg_state_flag_from_str(char *str)
  9155. +{
  9156. + int i;
  9157. + int sf = SF_OK;
  9158. +
  9159. + if (strcmp(str, "ok") == 0) {
  9160. + return SF_OK;
  9161. + }
  9162. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9163. + const char *sfname = pkg_state_flag_map[i].str;
  9164. + int sfname_len = strlen(sfname);
  9165. + if (strncmp(str, sfname, sfname_len) == 0) {
  9166. + sf |= pkg_state_flag_map[i].value;
  9167. + str += sfname_len;
  9168. + if (str[0] == ',') {
  9169. + str++;
  9170. + } else {
  9171. + break;
  9172. + }
  9173. + }
  9174. + }
  9175. +
  9176. + return sf;
  9177. +}
  9178. +
  9179. +char *pkg_state_status_to_str(pkg_state_status_t ss)
  9180. +{
  9181. + int i;
  9182. +
  9183. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9184. + if (pkg_state_status_map[i].value == ss) {
  9185. + return strdup(pkg_state_status_map[i].str);
  9186. + }
  9187. + }
  9188. +
  9189. + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
  9190. + __FUNCTION__, ss);
  9191. + return strdup("<STATE_STATUS_UNKNOWN>");
  9192. +}
  9193. +
  9194. +pkg_state_status_t pkg_state_status_from_str(char *str)
  9195. +{
  9196. + int i;
  9197. +
  9198. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9199. + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
  9200. + return pkg_state_status_map[i].value;
  9201. + }
  9202. + }
  9203. +
  9204. + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
  9205. + __FUNCTION__, str);
  9206. + return SS_NOT_INSTALLED;
  9207. +}
  9208. +
  9209. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
  9210. +{
  9211. + nv_pair_list_elt_t *l;
  9212. +
  9213. + if (!pkg->architecture)
  9214. + return 1;
  9215. +
  9216. + l = conf->arch_list.head;
  9217. +
  9218. + while (l) {
  9219. + nv_pair_t *nv = l->data;
  9220. + if (strcmp(nv->name, pkg->architecture) == 0) {
  9221. + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
  9222. + return 1;
  9223. + }
  9224. + l = l->next;
  9225. + }
  9226. +
  9227. + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
  9228. + return 0;
  9229. +}
  9230. +
  9231. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
  9232. +{
  9233. + nv_pair_list_elt_t *l;
  9234. +
  9235. + l = conf->arch_list.head;
  9236. +
  9237. + while (l) {
  9238. + nv_pair_t *nv = l->data;
  9239. + if (strcmp(nv->name, archname) == 0) {
  9240. + int priority = strtol(nv->value, NULL, 0);
  9241. + return priority;
  9242. + }
  9243. + l = l->next;
  9244. + }
  9245. + return 0;
  9246. +}
  9247. +
  9248. +int pkg_info_preinstall_check(ipkg_conf_t *conf)
  9249. +{
  9250. + int i;
  9251. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9252. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  9253. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9254. +
  9255. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
  9256. + pkg_hash_fetch_available(pkg_hash, available_pkgs);
  9257. + /* update arch_priority for each package */
  9258. + for (i = 0; i < available_pkgs->len; i++) {
  9259. + pkg_t *pkg = available_pkgs->pkgs[i];
  9260. + int arch_priority = 1;
  9261. + if (!pkg)
  9262. + continue;
  9263. + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
  9264. + if (pkg->architecture)
  9265. + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
  9266. + else
  9267. + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
  9268. + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
  9269. + pkg->arch_priority = arch_priority;
  9270. + }
  9271. +
  9272. + for (i = 0; i < available_pkgs->len; i++) {
  9273. + pkg_t *pkg = available_pkgs->pkgs[i];
  9274. + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
  9275. + /* clear flags and want for any uninstallable package */
  9276. + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
  9277. + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
  9278. + pkg->state_want = SW_UNKNOWN;
  9279. + pkg->state_flag = 0;
  9280. + }
  9281. + }
  9282. + pkg_vec_free(available_pkgs);
  9283. +
  9284. + /* update the file owner data structure */
  9285. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
  9286. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9287. + for (i = 0; i < installed_pkgs->len; i++) {
  9288. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9289. + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
  9290. + str_list_elt_t *iter;
  9291. + if (installed_files == NULL) {
  9292. + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
  9293. + break;
  9294. + }
  9295. + for (iter = installed_files->head; iter; iter = iter->next) {
  9296. + char *installed_file = iter->data;
  9297. + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
  9298. + file_hash_set_file_owner(conf, installed_file, pkg);
  9299. + }
  9300. + }
  9301. + pkg_vec_free(installed_pkgs);
  9302. +
  9303. + return 0;
  9304. +}
  9305. +
  9306. +struct pkg_write_filelist_data {
  9307. + ipkg_conf_t *conf;
  9308. + pkg_t *pkg;
  9309. + FILE *stream;
  9310. +};
  9311. +
  9312. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
  9313. +{
  9314. + struct pkg_write_filelist_data *data = data_;
  9315. + pkg_t *entry = entry_;
  9316. + if (entry == data->pkg) {
  9317. + fprintf(data->stream, "%s\n", key);
  9318. + }
  9319. +}
  9320. +
  9321. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
  9322. +{
  9323. + struct pkg_write_filelist_data data;
  9324. + char *list_file_name = NULL;
  9325. + int err = 0;
  9326. +
  9327. + if (!pkg) {
  9328. + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
  9329. + return -EINVAL;
  9330. + }
  9331. + ipkg_message(conf, IPKG_INFO,
  9332. + " creating %s.list file\n", pkg->name);
  9333. + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
  9334. + if (!list_file_name) {
  9335. + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
  9336. + return -ENOMEM;
  9337. + }
  9338. + ipkg_message(conf, IPKG_INFO,
  9339. + " creating %s file for pkg %s\n", list_file_name, pkg->name);
  9340. + data.stream = fopen(list_file_name, "w");
  9341. + if (!data.stream) {
  9342. + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
  9343. + list_file_name, strerror(errno));
  9344. + return errno;
  9345. + }
  9346. + data.pkg = pkg;
  9347. + data.conf = conf;
  9348. + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
  9349. + fclose(data.stream);
  9350. + free(list_file_name);
  9351. +
  9352. + return err;
  9353. +}
  9354. +
  9355. +int pkg_write_changed_filelists(ipkg_conf_t *conf)
  9356. +{
  9357. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9358. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9359. + int i;
  9360. + int err;
  9361. + if (conf->noaction)
  9362. + return 0;
  9363. +
  9364. + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
  9365. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9366. + for (i = 0; i < installed_pkgs->len; i++) {
  9367. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9368. + if (pkg->state_flag & SF_FILELIST_CHANGED) {
  9369. + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
  9370. + err = pkg_write_filelist(conf, pkg);
  9371. + if (err)
  9372. + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
  9373. + }
  9374. + }
  9375. + return 0;
  9376. +}
  9377. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_depends.c busybox-1.15.2/archival/libipkg/pkg_depends.c
  9378. --- busybox-1.15.2.orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
  9379. +++ busybox-1.15.2/archival/libipkg/pkg_depends.c 2009-11-26 11:10:14.115858127 +0100
  9380. @@ -0,0 +1,1032 @@
  9381. +/* pkg_depends.c - the itsy package management system
  9382. +
  9383. + Steven M. Ayer
  9384. +
  9385. + Copyright (C) 2002 Compaq Computer Corporation
  9386. +
  9387. + This program is free software; you can redistribute it and/or
  9388. + modify it under the terms of the GNU General Public License as
  9389. + published by the Free Software Foundation; either version 2, or (at
  9390. + your option) any later version.
  9391. +
  9392. + This program is distributed in the hope that it will be useful, but
  9393. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9394. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9395. + General Public License for more details.
  9396. +*/
  9397. +
  9398. +#include "ipkg.h"
  9399. +#include <errno.h>
  9400. +#include <ctype.h>
  9401. +
  9402. +#include "pkg.h"
  9403. +#include "ipkg_utils.h"
  9404. +#include "pkg_hash.h"
  9405. +#include "ipkg_message.h"
  9406. +#include "pkg_parse.h"
  9407. +#include "hash_table.h"
  9408. +
  9409. +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
  9410. +static depend_t * depend_init(void);
  9411. +static void depend_deinit(depend_t *d);
  9412. +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
  9413. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
  9414. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
  9415. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg);
  9416. +
  9417. +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
  9418. +{
  9419. + depend_t *depend = (depend_t *)cdata;
  9420. + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
  9421. + return 1;
  9422. + else
  9423. + return 0;
  9424. +}
  9425. +
  9426. +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
  9427. +{
  9428. + depend_t *depend = (depend_t *)cdata;
  9429. +#if 0
  9430. + pkg_t * temp = pkg_new();
  9431. + int comparison;
  9432. + parseVersion(temp, depend->version);
  9433. + comparison = pkg_compare_versions(pkg, temp);
  9434. + free(temp);
  9435. +
  9436. + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
  9437. + __FUNCTION__, pkg->name, pkg->version,
  9438. + depend, depend->constraint, depend->version,
  9439. + comparison, version_constraints_satisfied(depend, pkg));
  9440. +#endif
  9441. + if (version_constraints_satisfied(depend, pkg))
  9442. + return 1;
  9443. + else
  9444. + return 0;
  9445. +}
  9446. +
  9447. +/* returns ndependences or negative error value */
  9448. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
  9449. + pkg_vec_t *unsatisfied, char *** unresolved)
  9450. +{
  9451. + pkg_t * satisfier_entry_pkg;
  9452. + register int i, j, k, l;
  9453. + int count, found;
  9454. + char ** the_lost;
  9455. + abstract_pkg_t * ab_pkg;
  9456. +
  9457. + /*
  9458. + * this is a setup to check for redundant/cyclic dependency checks,
  9459. + * which are marked at the abstract_pkg level
  9460. + */
  9461. + if (!(ab_pkg = pkg->parent)) {
  9462. + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
  9463. + *unresolved = NULL;
  9464. + return 0;
  9465. + }
  9466. + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
  9467. + *unresolved = NULL;
  9468. + return 0;
  9469. + } else {
  9470. + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
  9471. + }
  9472. + /**/
  9473. +
  9474. + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
  9475. + if (!count){
  9476. + *unresolved = NULL;
  9477. + return 0;
  9478. + }
  9479. +
  9480. + the_lost = NULL;
  9481. +
  9482. + /* foreach dependency */
  9483. + for (i = 0; i < count; i++) {
  9484. + compound_depend_t * compound_depend = &pkg->depends[i];
  9485. + depend_t ** possible_satisfiers = compound_depend->possibilities;;
  9486. + found = 0;
  9487. + satisfier_entry_pkg = NULL;
  9488. +
  9489. + if (compound_depend->type == GREEDY_DEPEND) {
  9490. + /* foreach possible satisfier */
  9491. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9492. + /* foreach provided_by, which includes the abstract_pkg itself */
  9493. + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
  9494. + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
  9495. + int nposs = ab_provider_vec->len;
  9496. + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
  9497. + for (l = 0; l < nposs; l++) {
  9498. + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
  9499. + /* if no depends on this one, try the first package that Provides this one */
  9500. + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
  9501. + continue;
  9502. + }
  9503. +
  9504. + /* cruise this possiblity's pkg_vec looking for an installed version */
  9505. + for (k = 0; k < test_vec->len; k++) {
  9506. + pkg_t *pkg_scout = test_vec->pkgs[k];
  9507. + /* not installed, and not already known about? */
  9508. + if ((pkg_scout->state_want != SW_INSTALL)
  9509. + && !pkg_scout->parent->dependencies_checked
  9510. + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
  9511. + char ** newstuff = NULL;
  9512. + int rc;
  9513. + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
  9514. + /* check for not-already-installed dependencies */
  9515. + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
  9516. + pkg_scout,
  9517. + tmp_vec,
  9518. + &newstuff);
  9519. + if (newstuff == NULL) {
  9520. + int ok = 1;
  9521. + for (i = 0; i < rc; i++) {
  9522. + pkg_t *p = tmp_vec->pkgs[i];
  9523. + if (p->state_want == SW_INSTALL)
  9524. + continue;
  9525. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
  9526. + ok = 0;
  9527. + break;
  9528. + }
  9529. + pkg_vec_free (tmp_vec);
  9530. + if (ok) {
  9531. + /* mark this one for installation */
  9532. + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
  9533. + pkg_vec_insert(unsatisfied, pkg_scout);
  9534. + }
  9535. + } else {
  9536. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
  9537. + free (newstuff);
  9538. + }
  9539. + }
  9540. + }
  9541. + }
  9542. + }
  9543. +
  9544. + continue;
  9545. + }
  9546. +
  9547. + /* foreach possible satisfier, look for installed package */
  9548. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9549. + /* foreach provided_by, which includes the abstract_pkg itself */
  9550. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9551. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9552. + pkg_t *satisfying_pkg =
  9553. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9554. + pkg_installed_and_constraint_satisfied,
  9555. + dependence_to_satisfy, 1);
  9556. + /* Being that I can't test constraing in pkg_hash, I will test it here */
  9557. + if (satisfying_pkg != NULL) {
  9558. + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9559. + satisfying_pkg = NULL;
  9560. + }
  9561. + }
  9562. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
  9563. + if (satisfying_pkg != NULL) {
  9564. + found = 1;
  9565. + break;
  9566. + }
  9567. +
  9568. + }
  9569. + /* if nothing installed matches, then look for uninstalled satisfier */
  9570. + if (!found) {
  9571. + /* foreach possible satisfier, look for installed package */
  9572. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9573. + /* foreach provided_by, which includes the abstract_pkg itself */
  9574. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9575. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9576. + pkg_t *satisfying_pkg =
  9577. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9578. + pkg_constraint_satisfied,
  9579. + dependence_to_satisfy, 1);
  9580. + /* Being that I can't test constraing in pkg_hash, I will test it here too */
  9581. + if (satisfying_pkg != NULL) {
  9582. + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9583. + satisfying_pkg = NULL;
  9584. + }
  9585. + }
  9586. +
  9587. + /* user request overrides package recommendation */
  9588. + if (satisfying_pkg != NULL
  9589. + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
  9590. + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
  9591. + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
  9592. + pkg->name, satisfying_pkg->name);
  9593. + continue;
  9594. + }
  9595. +
  9596. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
  9597. + if (satisfying_pkg != NULL) {
  9598. + satisfier_entry_pkg = satisfying_pkg;
  9599. + break;
  9600. + }
  9601. + }
  9602. + }
  9603. +
  9604. + /* we didn't find one, add something to the unsatisfied vector */
  9605. + if (!found) {
  9606. + if (!satisfier_entry_pkg) {
  9607. + /* failure to meet recommendations is not an error */
  9608. + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
  9609. + the_lost = add_unresolved_dep(pkg, the_lost, i);
  9610. + else
  9611. + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
  9612. + pkg->name, compound_depend->possibilities[0]->pkg->name);
  9613. + }
  9614. + else {
  9615. + if (compound_depend->type == SUGGEST) {
  9616. + /* just mention it politely */
  9617. + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
  9618. + pkg->name, satisfier_entry_pkg->name);
  9619. + } else {
  9620. + char ** newstuff = NULL;
  9621. +
  9622. + if (satisfier_entry_pkg != pkg &&
  9623. + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
  9624. + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
  9625. + pkg_hash_fetch_unsatisfied_dependencies(conf,
  9626. + satisfier_entry_pkg,
  9627. + unsatisfied,
  9628. + &newstuff);
  9629. + the_lost = merge_unresolved(the_lost, newstuff);
  9630. + }
  9631. + }
  9632. + }
  9633. + }
  9634. + }
  9635. + *unresolved = the_lost;
  9636. +
  9637. + return unsatisfied->len;
  9638. +}
  9639. +
  9640. +/*checking for conflicts !in replaces
  9641. + If a packages conflicts with another but is also replacing it, I should not consider it a
  9642. + really conflicts
  9643. + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
  9644. +*/
  9645. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
  9646. +{
  9647. + int i ;
  9648. + int replaces_count = pkg->replaces_count;
  9649. + abstract_pkg_t **replaces;
  9650. +
  9651. + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
  9652. + return 0;
  9653. +
  9654. + replaces = pkg->replaces;
  9655. +
  9656. + for (i = 0; i < replaces_count; i++) {
  9657. + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
  9658. + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
  9659. + return 1;
  9660. + }
  9661. + }
  9662. + return 0;
  9663. +
  9664. +}
  9665. +
  9666. +
  9667. +/* Abhaya: added support for conflicts */
  9668. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg)
  9669. +{
  9670. + pkg_vec_t * installed_conflicts, * test_vec;
  9671. + compound_depend_t * conflicts;
  9672. + depend_t ** possible_satisfiers;
  9673. + depend_t * possible_satisfier;
  9674. + register int i, j, k;
  9675. + int count;
  9676. + abstract_pkg_t * ab_pkg;
  9677. + pkg_t **pkg_scouts;
  9678. + pkg_t *pkg_scout;
  9679. +
  9680. + /*
  9681. + * this is a setup to check for redundant/cyclic dependency checks,
  9682. + * which are marked at the abstract_pkg level
  9683. + */
  9684. + if(!(ab_pkg = pkg->parent)){
  9685. + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
  9686. + return (pkg_vec_t *)NULL;
  9687. + }
  9688. +
  9689. + conflicts = pkg->conflicts;
  9690. + if(!conflicts){
  9691. + return (pkg_vec_t *)NULL;
  9692. + }
  9693. + installed_conflicts = pkg_vec_alloc();
  9694. +
  9695. + count = pkg->conflicts_count;
  9696. +
  9697. +
  9698. +
  9699. + /* foreach conflict */
  9700. + for(i = 0; i < pkg->conflicts_count; i++){
  9701. +
  9702. + possible_satisfiers = conflicts->possibilities;
  9703. +
  9704. + /* foreach possible satisfier */
  9705. + for(j = 0; j < conflicts->possibility_count; j++){
  9706. + possible_satisfier = possible_satisfiers[j];
  9707. + if (!possible_satisfier)
  9708. + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
  9709. + if (!possible_satisfier->pkg)
  9710. + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
  9711. + test_vec = possible_satisfier->pkg->pkgs;
  9712. + if (test_vec) {
  9713. + /* pkg_vec found, it is an actual package conflict
  9714. + * cruise this possiblity's pkg_vec looking for an installed version */
  9715. + pkg_scouts = test_vec->pkgs;
  9716. + for(k = 0; k < test_vec->len; k++){
  9717. + pkg_scout = pkg_scouts[k];
  9718. + if (!pkg_scout) {
  9719. + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
  9720. + continue;
  9721. + }
  9722. + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
  9723. + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
  9724. + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
  9725. + pkg_vec_insert(installed_conflicts, pkg_scout);
  9726. + }
  9727. + }
  9728. + }
  9729. + }
  9730. + }
  9731. + conflicts++;
  9732. + }
  9733. +
  9734. + if (installed_conflicts->len)
  9735. + return installed_conflicts;
  9736. + pkg_vec_free(installed_conflicts);
  9737. + return (pkg_vec_t *)NULL;
  9738. +}
  9739. +
  9740. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
  9741. +{
  9742. + pkg_t * temp;
  9743. + int comparison;
  9744. +
  9745. + if(depends->constraint == NONE)
  9746. + return 1;
  9747. +
  9748. + temp = pkg_new();
  9749. +
  9750. + parseVersion(temp, depends->version);
  9751. +
  9752. + comparison = pkg_compare_versions(pkg, temp);
  9753. +
  9754. + free(temp);
  9755. +
  9756. + if((depends->constraint == EARLIER) &&
  9757. + (comparison < 0))
  9758. + return 1;
  9759. + else if((depends->constraint == LATER) &&
  9760. + (comparison > 0))
  9761. + return 1;
  9762. + else if(comparison == 0)
  9763. + return 1;
  9764. + else if((depends->constraint == LATER_EQUAL) &&
  9765. + (comparison >= 0))
  9766. + return 1;
  9767. + else if((depends->constraint == EARLIER_EQUAL) &&
  9768. + (comparison <= 0))
  9769. + return 1;
  9770. +
  9771. + return 0;
  9772. +}
  9773. +
  9774. +int pkg_dependence_satisfiable(depend_t *depend)
  9775. +{
  9776. + abstract_pkg_t *apkg = depend->pkg;
  9777. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9778. + int n_providers = provider_apkgs->len;
  9779. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9780. + pkg_vec_t *pkg_vec;
  9781. + int n_pkgs ;
  9782. + int i;
  9783. + int j;
  9784. +
  9785. + for (i = 0; i < n_providers; i++) {
  9786. + abstract_pkg_t *papkg = apkgs[i];
  9787. + pkg_vec = papkg->pkgs;
  9788. + if (pkg_vec) {
  9789. + n_pkgs = pkg_vec->len;
  9790. + for (j = 0; j < n_pkgs; j++) {
  9791. + pkg_t *pkg = pkg_vec->pkgs[j];
  9792. + if (version_constraints_satisfied(depend, pkg)) {
  9793. + return 1;
  9794. + }
  9795. + }
  9796. + }
  9797. + }
  9798. + return 0;
  9799. +}
  9800. +
  9801. +int pkg_dependence_satisfied(depend_t *depend)
  9802. +{
  9803. + abstract_pkg_t *apkg = depend->pkg;
  9804. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9805. + int n_providers = provider_apkgs->len;
  9806. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9807. + int i;
  9808. + int n_pkgs;
  9809. + int j;
  9810. +
  9811. + for (i = 0; i < n_providers; i++) {
  9812. + abstract_pkg_t *papkg = apkgs[i];
  9813. + pkg_vec_t *pkg_vec = papkg->pkgs;
  9814. + if (pkg_vec) {
  9815. + n_pkgs = pkg_vec->len;
  9816. + for (j = 0; j < n_pkgs; j++) {
  9817. + pkg_t *pkg = pkg_vec->pkgs[j];
  9818. + if (version_constraints_satisfied(depend, pkg)) {
  9819. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
  9820. + return 1;
  9821. + }
  9822. + }
  9823. + }
  9824. + }
  9825. + return 0;
  9826. +}
  9827. +
  9828. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
  9829. +{
  9830. + register int i;
  9831. + pkg_t ** pkgs = vec->pkgs;
  9832. +
  9833. + for(i = 0; i < vec->len; i++)
  9834. + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
  9835. + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
  9836. + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
  9837. + return 1;
  9838. + return 0;
  9839. +}
  9840. +
  9841. +
  9842. +#ifdef DeadCode
  9843. +/**
  9844. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  9845. + * the same abstract package and 0 otherwise.
  9846. + */
  9847. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
  9848. +{
  9849. + abstract_pkg_t **provides = pkg->provides;
  9850. + int provides_count = pkg->provides_count;
  9851. + abstract_pkg_t **replacee_provides = replacee->provides;
  9852. + int replacee_provides_count = replacee->provides_count;
  9853. + int i, j;
  9854. + for (i = 0; i < provides_count; i++) {
  9855. + abstract_pkg_t *apkg = provides[i];
  9856. + for (j = 0; j < replacee_provides_count; j++) {
  9857. + abstract_pkg_t *replacee_apkg = replacee_provides[i];
  9858. + if (apkg == replacee_apkg)
  9859. + return 1;
  9860. + }
  9861. + }
  9862. + return 0;
  9863. +}
  9864. +#endif
  9865. +
  9866. +/**
  9867. + * pkg_provides_abstract returns 1 if pkg->provides contains providee
  9868. + * and 0 otherwise.
  9869. + */
  9870. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
  9871. +{
  9872. + abstract_pkg_t **provides = pkg->provides;
  9873. + int provides_count = pkg->provides_count;
  9874. + int i;
  9875. + for (i = 0; i < provides_count; i++) {
  9876. + if (provides[i] == providee)
  9877. + return 1;
  9878. + }
  9879. + return 0;
  9880. +}
  9881. +
  9882. +/**
  9883. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  9884. + * otherwise.
  9885. + */
  9886. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
  9887. +{
  9888. + abstract_pkg_t **replaces = pkg->replaces;
  9889. + int replaces_count = pkg->replaces_count;
  9890. + /* abstract_pkg_t **replacee_provides = pkg->provides;
  9891. + int replacee_provides_count = pkg->provides_count; */
  9892. + int i, j;
  9893. + for (i = 0; i < replaces_count; i++) {
  9894. + abstract_pkg_t *abstract_replacee = replaces[i];
  9895. + for (j = 0; j < replaces_count; j++) {
  9896. + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
  9897. + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
  9898. + if (replacee->provides[j] == abstract_replacee)
  9899. + return 1;
  9900. + }
  9901. + }
  9902. + return 0;
  9903. +}
  9904. +
  9905. +
  9906. +/**
  9907. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
  9908. + * otherwise.
  9909. + */
  9910. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
  9911. +{
  9912. + compound_depend_t *conflicts = pkg->conflicts;
  9913. + int conflicts_count = pkg->conflicts_count;
  9914. + int i, j;
  9915. + for (i = 0; i < conflicts_count; i++) {
  9916. + int possibility_count = conflicts[i].possibility_count;
  9917. + struct depend **possibilities = conflicts[i].possibilities;
  9918. + for (j = 0; j < possibility_count; j++) {
  9919. + if (possibilities[j]->pkg == conflictee) {
  9920. + return 1;
  9921. + }
  9922. + }
  9923. + }
  9924. + return 0;
  9925. +}
  9926. +
  9927. +/**
  9928. + * pkg_conflicts returns 1 if pkg->conflicts contains one of
  9929. + * conflictee's provides and 0 otherwise.
  9930. + */
  9931. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
  9932. +{
  9933. + compound_depend_t *conflicts = pkg->conflicts;
  9934. + int conflicts_count = pkg->conflicts_count;
  9935. + abstract_pkg_t **conflictee_provides = conflictee->provides;
  9936. + int conflictee_provides_count = conflictee->provides_count;
  9937. + int i, j, k;
  9938. + int possibility_count;
  9939. + struct depend **possibilities;
  9940. + abstract_pkg_t *possibility ;
  9941. +
  9942. + for (i = 0; i < conflicts_count; i++) {
  9943. + possibility_count = conflicts[i].possibility_count;
  9944. + possibilities = conflicts[i].possibilities;
  9945. + for (j = 0; j < possibility_count; j++) {
  9946. + possibility = possibilities[j]->pkg;
  9947. + for (k = 0; k < conflictee_provides_count; k++) {
  9948. + if (possibility == conflictee_provides[k]) {
  9949. + return 1;
  9950. + }
  9951. + }
  9952. + }
  9953. + }
  9954. + return 0;
  9955. +}
  9956. +
  9957. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
  9958. +{
  9959. + int oldlen = 0, newlen = 0;
  9960. + char ** result;
  9961. + register int i, j;
  9962. +
  9963. + if(!newstuff)
  9964. + return oldstuff;
  9965. +
  9966. + while(oldstuff && oldstuff[oldlen]) oldlen++;
  9967. + while(newstuff && newstuff[newlen]) newlen++;
  9968. +
  9969. + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
  9970. + if (result == NULL) {
  9971. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9972. + return NULL;
  9973. + }
  9974. +
  9975. + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
  9976. + *(result + i) = *(newstuff + j);
  9977. +
  9978. + *(result + i) = NULL;
  9979. +
  9980. + return result;
  9981. +}
  9982. +
  9983. +/*
  9984. + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
  9985. + * this is null terminated, no count is carried around
  9986. + */
  9987. +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
  9988. +{
  9989. + int count;
  9990. + char ** resized;
  9991. + char *depend_str = pkg_depend_str(pkg, ref_ndx);
  9992. +
  9993. + count = 0;
  9994. + while(the_lost && the_lost[count]) count++;
  9995. +
  9996. + count++; /* need one to hold the null */
  9997. + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
  9998. + if (resized == NULL) {
  9999. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10000. + return NULL;
  10001. + }
  10002. + resized[count - 1] = strdup(depend_str);
  10003. + resized[count] = NULL;
  10004. +
  10005. + return resized;
  10006. +}
  10007. +
  10008. +void printDepends(pkg_t * pkg)
  10009. +{
  10010. + register int i, j;
  10011. + compound_depend_t * depend;
  10012. + int count;
  10013. +
  10014. + count = pkg->pre_depends_count + pkg->depends_count;
  10015. +
  10016. + depend = pkg->depends;
  10017. + if(!depend){
  10018. + fprintf(stderr, "Depends pointer is NULL\n");
  10019. + return;
  10020. + }
  10021. + for(i = 0; i < count; i++){
  10022. + fprintf(stderr, "%s has %d possibilities:\n",
  10023. + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
  10024. + depend->possibility_count);
  10025. + for(j = 0; j < depend->possibility_count; j++)
  10026. + fprintf(stderr, "\t%s version %s (%d)\n",
  10027. + depend->possibilities[j]->pkg->name,
  10028. + depend->possibilities[j]->version,
  10029. + depend->possibilities[j]->constraint);
  10030. + depend++;
  10031. + }
  10032. +}
  10033. +
  10034. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10035. +{
  10036. + register int i, j;
  10037. +
  10038. + /* every pkg provides itself */
  10039. + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
  10040. +
  10041. + if (!pkg->provides_count)
  10042. + return 0;
  10043. +
  10044. + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
  10045. + if (pkg->provides == NULL) {
  10046. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10047. + return -1 ;
  10048. + }
  10049. + pkg->provides[0] = ab_pkg;
  10050. +
  10051. + // if (strcmp(ab_pkg->name, pkg->name))
  10052. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10053. +
  10054. + for(i = 0; i < pkg->provides_count; i++){
  10055. + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
  10056. +
  10057. + pkg->provides[i+1] = provided_abpkg;
  10058. +
  10059. + j = 0;
  10060. + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
  10061. + }
  10062. + return 0;
  10063. +}
  10064. +
  10065. +/* Abhaya: added conflicts support */
  10066. +int buildConflicts(hash_table_t * hash, pkg_t * pkg)
  10067. +{
  10068. + register int i;
  10069. + compound_depend_t * conflicts;
  10070. +
  10071. + if (!pkg->conflicts_count)
  10072. + return 0;
  10073. +
  10074. + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
  10075. + pkg->conflicts_count);
  10076. + if (conflicts == NULL) {
  10077. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10078. + return -1;
  10079. + }
  10080. + for (i = 0; i < pkg->conflicts_count; i++) {
  10081. + conflicts->type = CONFLICTS;
  10082. + parseDepends(conflicts, hash,
  10083. + pkg->conflicts_str[i]);
  10084. +#if 0
  10085. + for (j = 0; j < conflicts->possibility_count; j++) {
  10086. + depend_t *possibility = conflicts->possibilities[j];
  10087. + abstract_pkg_t *conflicting_apkg = possibility->pkg;
  10088. + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
  10089. + }
  10090. +#endif
  10091. + conflicts++;
  10092. + }
  10093. + return 0;
  10094. +}
  10095. +
  10096. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10097. +{
  10098. + register int i, j;
  10099. +
  10100. + if (!pkg->replaces_count)
  10101. + return 0;
  10102. +
  10103. + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
  10104. + if (pkg->replaces == NULL) {
  10105. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10106. + return -1;
  10107. + }
  10108. +
  10109. + // if (strcmp(ab_pkg->name, pkg->name))
  10110. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10111. +
  10112. + for(i = 0; i < pkg->replaces_count; i++){
  10113. + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
  10114. +
  10115. + pkg->replaces[i] = old_abpkg;
  10116. +
  10117. + j = 0;
  10118. + if (!old_abpkg->replaced_by)
  10119. + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
  10120. + if ( old_abpkg->replaced_by == NULL ){
  10121. + return -1;
  10122. + }
  10123. + /* if a package pkg both replaces and conflicts old_abpkg,
  10124. + * then add it to the replaced_by vector so that old_abpkg
  10125. + * will be upgraded to ab_pkg automatically */
  10126. + if (pkg_conflicts_abstract(pkg, old_abpkg))
  10127. + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
  10128. + }
  10129. + return 0;
  10130. +}
  10131. +
  10132. +int buildDepends(hash_table_t * hash, pkg_t * pkg)
  10133. +{
  10134. + int count;
  10135. + register int i;
  10136. + compound_depend_t * depends;
  10137. +
  10138. + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
  10139. + return 0;
  10140. +
  10141. + if (0 && pkg->pre_depends_count)
  10142. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10143. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10144. + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
  10145. + if (depends == NULL) {
  10146. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10147. + return -1;
  10148. + }
  10149. +
  10150. +
  10151. + for(i = 0; i < pkg->pre_depends_count; i++){
  10152. + parseDepends(depends, hash, pkg->pre_depends_str[i]);
  10153. + if (0 && pkg->pre_depends_count)
  10154. + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
  10155. + pkg->pre_depends_str[i], depends, depends->possibility_count);
  10156. + depends->type = PREDEPEND;
  10157. + depends++;
  10158. + }
  10159. +
  10160. + for(i = 0; i < pkg->recommends_count; i++){
  10161. + parseDepends(depends, hash, pkg->recommends_str[i]);
  10162. + if (0 && pkg->recommends_count)
  10163. + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
  10164. + pkg->recommends_str[i], depends, depends->possibility_count);
  10165. + depends->type = RECOMMEND;
  10166. + depends++;
  10167. + }
  10168. +
  10169. + for(i = 0; i < pkg->suggests_count; i++){
  10170. + parseDepends(depends, hash, pkg->suggests_str[i]);
  10171. + if (0 && pkg->suggests_count)
  10172. + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
  10173. + pkg->suggests_str[i], depends, depends->possibility_count);
  10174. + depends->type = SUGGEST;
  10175. + depends++;
  10176. + }
  10177. +
  10178. + for(i = 0; i < pkg->depends_count; i++){
  10179. + parseDepends(depends, hash, pkg->depends_str[i]);
  10180. + if (0 && pkg->depends_count)
  10181. + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
  10182. + pkg->depends_str[i], depends, depends->possibility_count);
  10183. + depends++;
  10184. + }
  10185. + return 0;
  10186. +}
  10187. +
  10188. +/*
  10189. + * pkg_depend_string: returns the depends string specified by index_.
  10190. + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
  10191. + * [0,npredepends) -> returns pre_depends_str[index_]
  10192. + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index_]
  10193. + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index_]
  10194. + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index_]
  10195. + */
  10196. +char *pkg_depend_str(pkg_t *pkg, int index_)
  10197. +{
  10198. + if (index_ < pkg->pre_depends_count) {
  10199. + return pkg->pre_depends_str[index_];
  10200. + }
  10201. + index_ -= pkg->pre_depends_count;
  10202. +
  10203. + if (index_ < pkg->recommends_count) {
  10204. + return pkg->recommends_str[index_];
  10205. + }
  10206. + index_ -= pkg->recommends_count;
  10207. +
  10208. + if (index_ < pkg->suggests_count) {
  10209. + return pkg->suggests_str[index_];
  10210. + }
  10211. + index_ -= pkg->suggests_count;
  10212. +
  10213. + if (index_ < pkg->depends_count) {
  10214. + return pkg->depends_str[index_];
  10215. + }
  10216. + fprintf(stderr, "pkg_depend_str: index_ %d out of range for pkg=%s\n", index_, pkg->name);
  10217. + return NULL;
  10218. +}
  10219. +
  10220. +void freeDepends(pkg_t *pkg)
  10221. +{
  10222. + int i;
  10223. +
  10224. + if (pkg == NULL || pkg->depends == NULL) {
  10225. + return;
  10226. + }
  10227. +
  10228. + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
  10229. + for (i=0; i < pkg->depends->possibility_count; i++) {
  10230. + depend_deinit(pkg->depends->possibilities[i]);
  10231. + }
  10232. + free(pkg->depends->possibilities);
  10233. + free(pkg->depends);
  10234. + pkg->depends = NULL;
  10235. +}
  10236. +
  10237. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
  10238. +{
  10239. + compound_depend_t * depends;
  10240. + int count, othercount;
  10241. + register int i, j;
  10242. + abstract_pkg_t * ab_depend;
  10243. + abstract_pkg_t ** temp;
  10244. +
  10245. + count = pkg->pre_depends_count + pkg->depends_count;
  10246. + depends = pkg->depends;
  10247. +
  10248. + if (0 && pkg->pre_depends_count)
  10249. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10250. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10251. + for (i = 0; i < count; i++) {
  10252. + if (0 && pkg->pre_depends_count)
  10253. + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
  10254. + for (j = 0; j < depends->possibility_count; j++){
  10255. + ab_depend = depends->possibilities[j]->pkg;
  10256. + if(!ab_depend->depended_upon_by)
  10257. + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
  10258. +
  10259. + temp = ab_depend->depended_upon_by;
  10260. + othercount = 1;
  10261. + while(*temp){
  10262. + temp++;
  10263. + othercount++;
  10264. + }
  10265. + *temp = ab_pkg;
  10266. +
  10267. + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
  10268. + (othercount + 1) * sizeof(abstract_pkg_t *));
  10269. + /* the array may have moved */
  10270. + temp = ab_depend->depended_upon_by + othercount;
  10271. + *temp = NULL;
  10272. + }
  10273. + depends++;
  10274. + }
  10275. +}
  10276. +
  10277. +static depend_t * depend_init(void)
  10278. +{
  10279. + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
  10280. + if ( d==NULL ){
  10281. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10282. + return NULL;
  10283. + }
  10284. + d->constraint = NONE;
  10285. + d->version = NULL;
  10286. + d->pkg = NULL;
  10287. +
  10288. + return d;
  10289. +}
  10290. +
  10291. +static void depend_deinit(depend_t *d)
  10292. +{
  10293. + free(d);
  10294. +}
  10295. +
  10296. +static int parseDepends(compound_depend_t *compound_depend,
  10297. + hash_table_t * hash, char * depend_str)
  10298. +{
  10299. + char * pkg_name, buffer[2048];
  10300. + int num_of_ors = 0;
  10301. + register int i;
  10302. + register char * src, * dest;
  10303. + depend_t ** possibilities;
  10304. +
  10305. + /* first count the number of ored possibilities for satisfying dependency */
  10306. + src = depend_str;
  10307. + while(*src)
  10308. + if(*src++ == '|')
  10309. + num_of_ors++;
  10310. +
  10311. + compound_depend->type = DEPEND;
  10312. +
  10313. + compound_depend->possibility_count = num_of_ors + 1;
  10314. + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
  10315. + if (!possibilities)
  10316. + return -ENOMEM;
  10317. + compound_depend->possibilities = possibilities;
  10318. +
  10319. + src = depend_str;
  10320. + for(i = 0; i < num_of_ors + 1; i++){
  10321. + possibilities[i] = depend_init();
  10322. + if (!possibilities[i])
  10323. + return -ENOMEM;
  10324. + /* gobble up just the name first */
  10325. + dest = buffer;
  10326. + while(*src &&
  10327. + !isspace(*src) &&
  10328. + (*src != '(') &&
  10329. + (*src != '*') &&
  10330. + (*src != '|'))
  10331. + *dest++ = *src++;
  10332. + *dest = '\0';
  10333. + pkg_name = trim_alloc(buffer);
  10334. + if (pkg_name == NULL )
  10335. + return -ENOMEM;
  10336. +
  10337. + /* now look at possible version info */
  10338. +
  10339. + /* skip to next chars */
  10340. + if(isspace(*src))
  10341. + while(*src && isspace(*src)) src++;
  10342. +
  10343. + /* extract constraint and version */
  10344. + if(*src == '('){
  10345. + src++;
  10346. + if(!strncmp(src, "<<", 2)){
  10347. + possibilities[i]->constraint = EARLIER;
  10348. + src += 2;
  10349. + }
  10350. + else if(!strncmp(src, "<=", 2)){
  10351. + possibilities[i]->constraint = EARLIER_EQUAL;
  10352. + src += 2;
  10353. + }
  10354. + else if(!strncmp(src, ">=", 2)){
  10355. + possibilities[i]->constraint = LATER_EQUAL;
  10356. + src += 2;
  10357. + }
  10358. + else if(!strncmp(src, ">>", 2)){
  10359. + possibilities[i]->constraint = LATER;
  10360. + src += 2;
  10361. + }
  10362. + else if(!strncmp(src, "=", 1)){
  10363. + possibilities[i]->constraint = EQUAL;
  10364. + src++;
  10365. + }
  10366. + /* should these be here to support deprecated designations; dpkg does */
  10367. + else if(!strncmp(src, "<", 1)){
  10368. + possibilities[i]->constraint = EARLIER_EQUAL;
  10369. + src++;
  10370. + }
  10371. + else if(!strncmp(src, ">", 1)){
  10372. + possibilities[i]->constraint = LATER_EQUAL;
  10373. + src++;
  10374. + }
  10375. +
  10376. + /* now we have any constraint, pass space to version string */
  10377. + while(isspace(*src)) src++;
  10378. +
  10379. + /* this would be the version string */
  10380. + dest = buffer;
  10381. + while(*src && *src != ')')
  10382. + *dest++ = *src++;
  10383. + *dest = '\0';
  10384. +
  10385. + possibilities[i]->version = trim_alloc(buffer);
  10386. + /* fprintf(stderr, "let's print the depends version string:");
  10387. + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
  10388. + if (possibilities[i]->version == NULL )
  10389. + return -ENOMEM;
  10390. +
  10391. +
  10392. + }
  10393. + /* hook up the dependency to its abstract pkg */
  10394. + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
  10395. +
  10396. + free(pkg_name);
  10397. +
  10398. + /* now get past the ) and any possible | chars */
  10399. + while(*src &&
  10400. + (isspace(*src) ||
  10401. + (*src == ')') ||
  10402. + (*src == '|')))
  10403. + src++;
  10404. + if (*src == '*')
  10405. + {
  10406. + compound_depend->type = GREEDY_DEPEND;
  10407. + src++;
  10408. + }
  10409. + }
  10410. +
  10411. + return 0;
  10412. +}
  10413. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_depends.h busybox-1.15.2/archival/libipkg/pkg_depends.h
  10414. --- busybox-1.15.2.orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
  10415. +++ busybox-1.15.2/archival/libipkg/pkg_depends.h 2009-11-26 11:10:14.177333554 +0100
  10416. @@ -0,0 +1,105 @@
  10417. +/* pkg_depends.h - the itsy package management system
  10418. +
  10419. + Steven M. Ayer
  10420. +
  10421. + Copyright (C) 2002 Compaq Computer Corporation
  10422. +
  10423. + This program is free software; you can redistribute it and/or
  10424. + modify it under the terms of the GNU General Public License as
  10425. + published by the Free Software Foundation; either version 2, or (at
  10426. + your option) any later version.
  10427. +
  10428. + This program is distributed in the hope that it will be useful, but
  10429. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10430. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10431. + General Public License for more details.
  10432. +*/
  10433. +
  10434. +#ifndef PKG_DEPENDS_H
  10435. +#define PKG_DEPENDS_H
  10436. +
  10437. +#include "pkg.h"
  10438. +#include "pkg_hash.h"
  10439. +
  10440. +enum depend_type {
  10441. + PREDEPEND,
  10442. + DEPEND,
  10443. + CONFLICTS,
  10444. + GREEDY_DEPEND,
  10445. + RECOMMEND,
  10446. + SUGGEST
  10447. +};
  10448. +typedef enum depend_type depend_type_t;
  10449. +
  10450. +enum version_constraint {
  10451. + NONE,
  10452. + EARLIER,
  10453. + EARLIER_EQUAL,
  10454. + EQUAL,
  10455. + LATER_EQUAL,
  10456. + LATER
  10457. +};
  10458. +typedef enum version_constraint version_constraint_t;
  10459. +
  10460. +struct depend{
  10461. + version_constraint_t constraint;
  10462. + char * version;
  10463. + abstract_pkg_t * pkg;
  10464. +};
  10465. +typedef struct depend depend_t;
  10466. +
  10467. +struct compound_depend{
  10468. + depend_type_t type;
  10469. + int possibility_count;
  10470. + struct depend ** possibilities;
  10471. +};
  10472. +typedef struct compound_depend compound_depend_t;
  10473. +
  10474. +#include "hash_table.h"
  10475. +
  10476. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10477. +int buildConflicts(hash_table_t * hash, pkg_t * pkg);
  10478. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10479. +int buildDepends(hash_table_t * hash, pkg_t * pkg);
  10480. +
  10481. +/**
  10482. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10483. + * the same abstract package and 0 otherwise.
  10484. + */
  10485. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
  10486. +
  10487. +/**
  10488. + * pkg_provides returns 1 if pkg->provides contains providee and 0
  10489. + * otherwise.
  10490. + */
  10491. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
  10492. +
  10493. +/**
  10494. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10495. + * otherwise.
  10496. + */
  10497. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
  10498. +
  10499. +/**
  10500. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
  10501. + * otherwise.
  10502. + */
  10503. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
  10504. +
  10505. +/**
  10506. + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
  10507. + * otherwise.
  10508. + */
  10509. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
  10510. +
  10511. +char *pkg_depend_str(pkg_t *pkg, int index_);
  10512. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
  10513. +void freeDepends(pkg_t *pkg);
  10514. +void printDepends(pkg_t * pkg);
  10515. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
  10516. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
  10517. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
  10518. +int pkg_dependence_satisfiable(depend_t *depend);
  10519. +int pkg_dependence_satisfied(depend_t *depend);
  10520. +
  10521. +#endif
  10522. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_dest.c busybox-1.15.2/archival/libipkg/pkg_dest.c
  10523. --- busybox-1.15.2.orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
  10524. +++ busybox-1.15.2/archival/libipkg/pkg_dest.c 2009-11-26 11:10:14.177333554 +0100
  10525. @@ -0,0 +1,92 @@
  10526. +/* pkg_dest.c - the itsy package management system
  10527. +
  10528. + Carl D. Worth
  10529. +
  10530. + Copyright (C) 2001 University of Southern California
  10531. +
  10532. + This program is free software; you can redistribute it and/or
  10533. + modify it under the terms of the GNU General Public License as
  10534. + published by the Free Software Foundation; either version 2, or (at
  10535. + your option) any later version.
  10536. +
  10537. + This program is distributed in the hope that it will be useful, but
  10538. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10539. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10540. + General Public License for more details.
  10541. +*/
  10542. +
  10543. +#include "ipkg.h"
  10544. +
  10545. +#include "pkg_dest.h"
  10546. +#include "file_util.h"
  10547. +#include "str_util.h"
  10548. +#include "sprintf_alloc.h"
  10549. +
  10550. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
  10551. +{
  10552. + dest->name = strdup(name);
  10553. +
  10554. + /* Guarantee that dest->root_dir ends with a '/' */
  10555. + if (str_ends_with(root_dir, "/")) {
  10556. + dest->root_dir = strdup(root_dir);
  10557. + } else {
  10558. + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
  10559. + }
  10560. + file_mkdir_hier(dest->root_dir, 0755);
  10561. +
  10562. + sprintf_alloc(&dest->ipkg_dir, "%s%s",
  10563. + dest->root_dir, IPKG_STATE_DIR_PREFIX);
  10564. + file_mkdir_hier(dest->ipkg_dir, 0755);
  10565. +
  10566. + if (str_starts_with (lists_dir, "/"))
  10567. + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
  10568. + else
  10569. + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
  10570. +
  10571. + file_mkdir_hier(dest->lists_dir, 0755);
  10572. +
  10573. + sprintf_alloc(&dest->info_dir, "%s/%s",
  10574. + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
  10575. + file_mkdir_hier(dest->info_dir, 0755);
  10576. +
  10577. + sprintf_alloc(&dest->status_file_name, "%s/%s",
  10578. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10579. +
  10580. + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
  10581. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10582. +
  10583. + dest->status_file = NULL;
  10584. +
  10585. + return 0;
  10586. +}
  10587. +
  10588. +void pkg_dest_deinit(pkg_dest_t *dest)
  10589. +{
  10590. + free(dest->name);
  10591. + dest->name = NULL;
  10592. +
  10593. + free(dest->root_dir);
  10594. + dest->root_dir = NULL;
  10595. +
  10596. + free(dest->ipkg_dir);
  10597. + dest->ipkg_dir = NULL;
  10598. +
  10599. + free(dest->lists_dir);
  10600. + dest->lists_dir = NULL;
  10601. +
  10602. + free(dest->info_dir);
  10603. + dest->info_dir = NULL;
  10604. +
  10605. + free(dest->status_file_name);
  10606. + dest->status_file_name = NULL;
  10607. +
  10608. + free(dest->status_file_tmp_name);
  10609. + dest->status_file_tmp_name = NULL;
  10610. +
  10611. + if (dest->status_file) {
  10612. + fclose(dest->status_file);
  10613. + }
  10614. + dest->status_file = NULL;
  10615. +
  10616. + dest->root_dir = NULL;
  10617. +}
  10618. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_dest.h busybox-1.15.2/archival/libipkg/pkg_dest.h
  10619. --- busybox-1.15.2.orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
  10620. +++ busybox-1.15.2/archival/libipkg/pkg_dest.h 2009-11-26 11:10:14.177333554 +0100
  10621. @@ -0,0 +1,38 @@
  10622. +/* pkg_dest.h - the itsy package management system
  10623. +
  10624. + Carl D. Worth
  10625. +
  10626. + Copyright (C) 2001 University of Southern California
  10627. +
  10628. + This program is free software; you can redistribute it and/or
  10629. + modify it under the terms of the GNU General Public License as
  10630. + published by the Free Software Foundation; either version 2, or (at
  10631. + your option) any later version.
  10632. +
  10633. + This program is distributed in the hope that it will be useful, but
  10634. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10635. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10636. + General Public License for more details.
  10637. +*/
  10638. +
  10639. +#ifndef PKG_DEST_H
  10640. +#define PKG_DEST_H
  10641. +
  10642. +typedef struct pkg_dest pkg_dest_t;
  10643. +struct pkg_dest
  10644. +{
  10645. + char *name;
  10646. + char *root_dir;
  10647. + char *ipkg_dir;
  10648. + char *lists_dir;
  10649. + char *info_dir;
  10650. + char *status_file_name;
  10651. + char *status_file_tmp_name;
  10652. + FILE *status_file;
  10653. +};
  10654. +
  10655. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
  10656. +void pkg_dest_deinit(pkg_dest_t *dest);
  10657. +
  10658. +#endif
  10659. +
  10660. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_dest_list.c busybox-1.15.2/archival/libipkg/pkg_dest_list.c
  10661. --- busybox-1.15.2.orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
  10662. +++ busybox-1.15.2/archival/libipkg/pkg_dest_list.c 2009-11-26 11:10:14.251858126 +0100
  10663. @@ -0,0 +1,85 @@
  10664. +/* pkg_dest_list.c - the itsy package management system
  10665. +
  10666. + Carl D. Worth
  10667. +
  10668. + Copyright (C) 2001 University of Southern California
  10669. +
  10670. + This program is free software; you can redistribute it and/or
  10671. + modify it under the terms of the GNU General Public License as
  10672. + published by the Free Software Foundation; either version 2, or (at
  10673. + your option) any later version.
  10674. +
  10675. + This program is distributed in the hope that it will be useful, but
  10676. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10677. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10678. + General Public License for more details.
  10679. +*/
  10680. +
  10681. +#include "ipkg.h"
  10682. +
  10683. +#include "pkg_dest.h"
  10684. +#include "void_list.h"
  10685. +#include "pkg_dest_list.h"
  10686. +
  10687. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
  10688. +{
  10689. + return void_list_elt_init((void_list_elt_t *) elt, data);
  10690. +}
  10691. +
  10692. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
  10693. +{
  10694. + void_list_elt_deinit((void_list_elt_t *) elt);
  10695. +}
  10696. +
  10697. +int pkg_dest_list_init(pkg_dest_list_t *list)
  10698. +{
  10699. + return void_list_init((void_list_t *) list);
  10700. +}
  10701. +
  10702. +void pkg_dest_list_deinit(pkg_dest_list_t *list)
  10703. +{
  10704. + pkg_dest_list_elt_t *iter;
  10705. + pkg_dest_t *pkg_dest;
  10706. +
  10707. + for (iter = list->head; iter; iter = iter->next) {
  10708. + pkg_dest = iter->data;
  10709. + pkg_dest_deinit(pkg_dest);
  10710. +
  10711. + /* malloced in pkg_dest_list_append */
  10712. + free(pkg_dest);
  10713. + iter->data = NULL;
  10714. + }
  10715. + void_list_deinit((void_list_t *) list);
  10716. +}
  10717. +
  10718. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10719. + const char *root_dir,const char *lists_dir)
  10720. +{
  10721. + int err;
  10722. + pkg_dest_t *pkg_dest;
  10723. +
  10724. + /* freed in plg_dest_list_deinit */
  10725. + pkg_dest = malloc(sizeof(pkg_dest_t));
  10726. + if (pkg_dest == NULL) {
  10727. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10728. + return NULL;
  10729. + }
  10730. +
  10731. + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
  10732. + err = void_list_append((void_list_t *) list, pkg_dest);
  10733. + if (err) {
  10734. + return NULL;
  10735. + }
  10736. +
  10737. + return pkg_dest;
  10738. +}
  10739. +
  10740. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
  10741. +{
  10742. + return void_list_push((void_list_t *) list, data);
  10743. +}
  10744. +
  10745. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
  10746. +{
  10747. + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
  10748. +}
  10749. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_dest_list.h busybox-1.15.2/archival/libipkg/pkg_dest_list.h
  10750. --- busybox-1.15.2.orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
  10751. +++ busybox-1.15.2/archival/libipkg/pkg_dest_list.h 2009-11-26 11:10:14.255858914 +0100
  10752. @@ -0,0 +1,50 @@
  10753. +/* pkg_dest_list.h - the itsy package management system
  10754. +
  10755. + Carl D. Worth
  10756. +
  10757. + Copyright (C) 2001 University of Southern California
  10758. +
  10759. + This program is free software; you can redistribute it and/or
  10760. + modify it under the terms of the GNU General Public License as
  10761. + published by the Free Software Foundation; either version 2, or (at
  10762. + your option) any later version.
  10763. +
  10764. + This program is distributed in the hope that it will be useful, but
  10765. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10766. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10767. + General Public License for more details.
  10768. +*/
  10769. +
  10770. +#ifndef PKG_DEST_LIST_H
  10771. +#define PKG_DEST_LIST_H
  10772. +
  10773. +#include "pkg_dest.h"
  10774. +
  10775. +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
  10776. +struct pkg_dest_list_elt
  10777. +{
  10778. + pkg_dest_list_elt_t *next;
  10779. + pkg_dest_t *data;
  10780. +};
  10781. +
  10782. +typedef struct pkg_dest_list pkg_dest_list_t;
  10783. +struct pkg_dest_list
  10784. +{
  10785. + pkg_dest_list_elt_t pre_head;
  10786. + pkg_dest_list_elt_t *head;
  10787. + pkg_dest_list_elt_t *tail;
  10788. +};
  10789. +
  10790. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
  10791. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
  10792. +
  10793. +int pkg_dest_list_init(pkg_dest_list_t *list);
  10794. +void pkg_dest_list_deinit(pkg_dest_list_t *list);
  10795. +
  10796. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10797. + const char *root_dir,const char* lists_dir);
  10798. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
  10799. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
  10800. +
  10801. +#endif
  10802. +
  10803. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_extract.c busybox-1.15.2/archival/libipkg/pkg_extract.c
  10804. --- busybox-1.15.2.orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
  10805. +++ busybox-1.15.2/archival/libipkg/pkg_extract.c 2009-11-26 11:10:14.259859982 +0100
  10806. @@ -0,0 +1,225 @@
  10807. +/* pkg_extract.c - the itsy package management system
  10808. +
  10809. + Carl D. Worth
  10810. +
  10811. + Copyright (C) 2001 University of Southern California
  10812. +
  10813. + This program is free software; you can redistribute it and/or
  10814. + modify it under the terms of the GNU General Public License as
  10815. + published by the Free Software Foundation; either version 2, or (at
  10816. + your option) any later version.
  10817. +
  10818. + This program is distributed in the hope that it will be useful, but
  10819. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10820. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10821. + General Public License for more details.
  10822. +*/
  10823. +
  10824. +#include "ipkg.h"
  10825. +#include <errno.h>
  10826. +#include <fcntl.h>
  10827. +#include <stdio.h>
  10828. +
  10829. +#include "pkg_extract.h"
  10830. +
  10831. +#include "libbb.h"
  10832. +#include "file_util.h"
  10833. +#include "sprintf_alloc.h"
  10834. +#include "unarchive.h"
  10835. +
  10836. +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
  10837. +#define IPKG_DATA_ARCHIVE "data.tar.gz"
  10838. +#define IPKG_CONTROL_FILE "control"
  10839. +
  10840. +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
  10841. +{
  10842. + archive_handle_t *archive;
  10843. + char *path;
  10844. +
  10845. + sprintf_alloc(&path, "%s/", dir);
  10846. + archive = init_handle();
  10847. + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
  10848. + archive->filter = filter_accept_list;
  10849. + llist_add_to(&(archive->accept), (char *)filename);
  10850. + archive->buffer = path;
  10851. + archive->action_data = data_extract_all_prefix;
  10852. + archive->ah_flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
  10853. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10854. + close(archive->src_fd);
  10855. + free(archive->accept);
  10856. + free(archive);
  10857. + free(path);
  10858. +}
  10859. +
  10860. +static void FAST_FUNC data_extract_file_name_to_buffer(archive_handle_t *archive)
  10861. +{
  10862. + unsigned int size = strlen(archive->file_header->name) + 2;
  10863. +
  10864. + if (archive->buffer == NULL) {
  10865. + archive->buffer = xmalloc(size);
  10866. + strcpy(archive->buffer, archive->file_header->name);
  10867. + } else {
  10868. + size += strlen(archive->buffer);
  10869. + archive->buffer = xrealloc(archive->buffer, size);
  10870. + strcat(archive->buffer, archive->file_header->name);
  10871. + }
  10872. + strcat(archive->buffer, "\n");
  10873. + data_skip(archive);
  10874. +}
  10875. +
  10876. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
  10877. +{
  10878. + archive_handle_t *archive;
  10879. + char *name;
  10880. + const char *filename = "./" IPKG_CONTROL_FILE;
  10881. +
  10882. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10883. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10884. + archive = init_handle();
  10885. + archive->src_fd = xopen(name, O_RDONLY);
  10886. + archive->filter = filter_accept_list;
  10887. + llist_add_to(&(archive->accept), (char *)filename);
  10888. + archive->action_data = data_extract_to_buffer;
  10889. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10890. + close(archive->src_fd);
  10891. + fputs(archive->buffer, stream);
  10892. + free(archive->buffer);
  10893. + free(archive->accept);
  10894. + free(archive);
  10895. + free(name);
  10896. +
  10897. + return 0;
  10898. +}
  10899. +
  10900. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
  10901. +{
  10902. + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
  10903. +}
  10904. +
  10905. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
  10906. +{
  10907. + archive_handle_t *archive;
  10908. + char *name;
  10909. + char *path;
  10910. +
  10911. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10912. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10913. + sprintf_alloc(&path, "%s/%s", dir, prefix);
  10914. + archive = init_handle();
  10915. + archive->src_fd = xopen(name, O_RDONLY);
  10916. + archive->filter = filter_accept_all;
  10917. + archive->buffer = path;
  10918. + archive->action_data = data_extract_all_prefix;
  10919. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
  10920. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10921. + close(archive->src_fd);
  10922. + free(archive);
  10923. + free(path);
  10924. + free(name);
  10925. +
  10926. + return 0;
  10927. +}
  10928. +
  10929. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
  10930. +{
  10931. + archive_handle_t *archive;
  10932. + char *name;
  10933. + char *path;
  10934. +
  10935. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  10936. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  10937. + sprintf_alloc(&path, "%s/", dir);
  10938. + archive = init_handle();
  10939. + archive->src_fd = xopen(name, O_RDONLY);
  10940. + archive->filter = filter_accept_all;
  10941. + archive->buffer = path;
  10942. + archive->action_data = data_extract_all_prefix;
  10943. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
  10944. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10945. + close(archive->src_fd);
  10946. + free(archive);
  10947. + free(path);
  10948. + free(name);
  10949. +
  10950. + return 0;
  10951. +}
  10952. +
  10953. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
  10954. +{
  10955. + int err=0;
  10956. + char *line, *data_file;
  10957. + FILE *file;
  10958. + FILE *tmp;
  10959. +
  10960. + file = fopen(file_name, "w");
  10961. + if (file == NULL) {
  10962. + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
  10963. + __FUNCTION__, file_name);
  10964. + return EINVAL;
  10965. + }
  10966. +
  10967. + tmp = tmpfile();
  10968. + if (pkg->installed_files) {
  10969. + str_list_elt_t *elt;
  10970. + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
  10971. + fprintf(file, "%s\n", elt->data);
  10972. + }
  10973. + } else {
  10974. + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
  10975. + if (err) {
  10976. + fclose(file);
  10977. + fclose(tmp);
  10978. + return err;
  10979. + }
  10980. +
  10981. + /* Fixup data file names by removing the initial '.' */
  10982. + rewind(tmp);
  10983. + while (1) {
  10984. + line = file_read_line_alloc(tmp);
  10985. + if (line == NULL) {
  10986. + break;
  10987. + }
  10988. +
  10989. + data_file = line;
  10990. + if (*data_file == '.') {
  10991. + data_file++;
  10992. + }
  10993. +
  10994. + if (*data_file != '/') {
  10995. + fputs("/", file);
  10996. + }
  10997. +
  10998. + /* I have no idea why, but this is what dpkg does */
  10999. + if (strcmp(data_file, "/\n") == 0) {
  11000. + fputs("/.\n", file);
  11001. + } else {
  11002. + fputs(data_file, file);
  11003. + }
  11004. + }
  11005. + }
  11006. + fclose(tmp);
  11007. + fclose(file);
  11008. +
  11009. + return err;
  11010. +}
  11011. +
  11012. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
  11013. +{
  11014. + archive_handle_t *archive;
  11015. + char *name;
  11016. +
  11017. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  11018. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  11019. + archive = init_handle();
  11020. + archive->src_fd = xopen(name, O_RDONLY);
  11021. + archive->filter = filter_accept_all;
  11022. + archive->action_data = data_extract_file_name_to_buffer;
  11023. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11024. + close(archive->src_fd);
  11025. + fputs(archive->buffer, file);
  11026. + free(archive->buffer);
  11027. + free(archive);
  11028. + free(name);
  11029. +
  11030. + return 0;
  11031. +}
  11032. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_extract.h busybox-1.15.2/archival/libipkg/pkg_extract.h
  11033. --- busybox-1.15.2.orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
  11034. +++ busybox-1.15.2/archival/libipkg/pkg_extract.h 2009-11-26 11:10:14.323857515 +0100
  11035. @@ -0,0 +1,32 @@
  11036. +/* pkg_extract.c - the itsy package management system
  11037. +
  11038. + Carl D. Worth
  11039. +
  11040. + Copyright (C) 2001 University of Southern California
  11041. +
  11042. + This program is free software; you can redistribute it and/or
  11043. + modify it under the terms of the GNU General Public License as
  11044. + published by the Free Software Foundation; either version 2, or (at
  11045. + your option) any later version.
  11046. +
  11047. + This program is distributed in the hope that it will be useful, but
  11048. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11049. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11050. + General Public License for more details.
  11051. +*/
  11052. +
  11053. +#ifndef PKG_EXTRACT_H
  11054. +#define PKG_EXTRACT_H
  11055. +
  11056. +#include "pkg.h"
  11057. +
  11058. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
  11059. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
  11060. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
  11061. + const char *dir,
  11062. + const char *prefix);
  11063. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
  11064. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
  11065. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
  11066. +
  11067. +#endif
  11068. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg.h busybox-1.15.2/archival/libipkg/pkg.h
  11069. --- busybox-1.15.2.orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
  11070. +++ busybox-1.15.2/archival/libipkg/pkg.h 2009-11-26 11:10:14.107861019 +0100
  11071. @@ -0,0 +1,229 @@
  11072. +/* pkg.h - the itsy package management system
  11073. +
  11074. + Carl D. Worth
  11075. +
  11076. + Copyright (C) 2001 University of Southern California
  11077. +
  11078. + This program is free software; you can redistribute it and/or
  11079. + modify it under the terms of the GNU General Public License as
  11080. + published by the Free Software Foundation; either version 2, or (at
  11081. + your option) any later version.
  11082. +
  11083. + This program is distributed in the hope that it will be useful, but
  11084. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11085. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11086. + General Public License for more details.
  11087. +*/
  11088. +
  11089. +#ifndef PKG_H
  11090. +#define PKG_H
  11091. +
  11092. +#include <sys/types.h>
  11093. +#include <sys/stat.h>
  11094. +#include <unistd.h>
  11095. +
  11096. +#include "pkg_vec.h"
  11097. +#include "str_list.h"
  11098. +#include "pkg_src.h"
  11099. +#include "pkg_dest.h"
  11100. +#include "ipkg_conf.h"
  11101. +#include "conffile_list.h"
  11102. +
  11103. +struct ipkg_conf;
  11104. +
  11105. +/* I think "Size" is currently the shortest field name */
  11106. +#define PKG_MINIMUM_FIELD_NAME_LEN 4
  11107. +
  11108. +enum pkg_state_want
  11109. +{
  11110. + SW_UNKNOWN = 1,
  11111. + SW_INSTALL,
  11112. + SW_DEINSTALL,
  11113. + SW_PURGE,
  11114. + SW_LAST_STATE_WANT
  11115. +};
  11116. +typedef enum pkg_state_want pkg_state_want_t;
  11117. +
  11118. +enum pkg_state_flag
  11119. +{
  11120. + SF_OK = 0,
  11121. + SF_REINSTREQ = 1,
  11122. + SF_HOLD = 2, /* do not upgrade version */
  11123. + SF_REPLACE = 4, /* replace this package */
  11124. + SF_NOPRUNE = 8, /* do not remove obsolete files */
  11125. + SF_PREFER = 16, /* prefer this version */
  11126. + SF_OBSOLETE = 32, /* old package in upgrade pair */
  11127. + SF_MARKED = 64, /* temporary mark */
  11128. + SF_FILELIST_CHANGED = 128, /* needs filelist written */
  11129. + SF_USER = 256,
  11130. + SF_LAST_STATE_FLAG
  11131. +};
  11132. +typedef enum pkg_state_flag pkg_state_flag_t;
  11133. +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
  11134. +
  11135. +enum pkg_state_status
  11136. +{
  11137. + SS_NOT_INSTALLED = 1,
  11138. + SS_UNPACKED,
  11139. + SS_HALF_CONFIGURED,
  11140. + SS_INSTALLED,
  11141. + SS_HALF_INSTALLED,
  11142. + SS_CONFIG_FILES,
  11143. + SS_POST_INST_FAILED,
  11144. + SS_REMOVAL_FAILED,
  11145. + SS_LAST_STATE_STATUS
  11146. +};
  11147. +typedef enum pkg_state_status pkg_state_status_t;
  11148. +
  11149. +struct abstract_pkg{
  11150. + char * name;
  11151. + int dependencies_checked;
  11152. + pkg_vec_t * pkgs;
  11153. + pkg_state_status_t state_status;
  11154. + pkg_state_flag_t state_flag;
  11155. + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
  11156. + abstract_pkg_vec_t * provided_by;
  11157. + abstract_pkg_vec_t * replaced_by;
  11158. +};
  11159. +
  11160. +#include "pkg_depends.h"
  11161. +
  11162. +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
  11163. +
  11164. + The 3 version fields should go into a single version struct. (This
  11165. + is especially important since, currently, pkg->version can easily
  11166. + be mistaken for pkg_verson_str_alloc(pkg) although they are very
  11167. + distinct. This has been the source of multiple bugs.
  11168. +
  11169. + The 3 state fields could possibly also go into their own struct.
  11170. +
  11171. + All fields which deal with lists of packages, (Depends,
  11172. + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
  11173. + be handled by a single struct in pkg_t
  11174. +
  11175. + All string fields for which there is a small set of possible
  11176. + values, (section, maintainer, architecture, maybe version?), that
  11177. + are reused among different packages -- for all such packages we
  11178. + should move from "char *"s to some atom datatype to share data
  11179. + storage and use less memory. We might even do reference counting,
  11180. + but probably not since most often we only create new pkg_t structs,
  11181. + we don't often free them. */
  11182. +struct pkg
  11183. +{
  11184. + char *name;
  11185. + unsigned long epoch;
  11186. + char *version;
  11187. + char *revision;
  11188. + char *familiar_revision;
  11189. + pkg_src_t *src;
  11190. + pkg_dest_t *dest;
  11191. + char *architecture;
  11192. + char *section;
  11193. + char *maintainer;
  11194. + char *description;
  11195. + pkg_state_want_t state_want;
  11196. + pkg_state_flag_t state_flag;
  11197. + pkg_state_status_t state_status;
  11198. + char **depends_str;
  11199. + int depends_count;
  11200. + char **pre_depends_str;
  11201. + int pre_depends_count;
  11202. + char **recommends_str;
  11203. + int recommends_count;
  11204. + char **suggests_str;
  11205. + int suggests_count;
  11206. + compound_depend_t * depends;
  11207. +
  11208. + /* Abhaya: new conflicts */
  11209. + char **conflicts_str;
  11210. + compound_depend_t * conflicts;
  11211. + int conflicts_count;
  11212. +
  11213. + char **replaces_str;
  11214. + int replaces_count;
  11215. + abstract_pkg_t ** replaces;
  11216. +
  11217. + char **provides_str;
  11218. + int provides_count;
  11219. + abstract_pkg_t ** provides;
  11220. +
  11221. + abstract_pkg_t *parent;
  11222. +
  11223. + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
  11224. +
  11225. + char *filename;
  11226. + char *local_filename;
  11227. + char *url;
  11228. + char *tmp_unpack_dir;
  11229. + char *md5sum;
  11230. + char *size;
  11231. + char *installed_size;
  11232. + char *priority;
  11233. + char *source;
  11234. + conffile_list_t conffiles;
  11235. + time_t installed_time;
  11236. + /* As pointer for lazy evaluation */
  11237. + str_list_t *installed_files;
  11238. + /* XXX: CLEANUP: I'd like to perhaps come up with a better
  11239. + mechanism to avoid the problem here, (which is that the
  11240. + installed_files list was being freed from an inner loop while
  11241. + still being used within an outer loop. */
  11242. + int installed_files_ref_cnt;
  11243. + int essential;
  11244. + int arch_priority;
  11245. +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
  11246. + int provided_by_hand;
  11247. +};
  11248. +
  11249. +pkg_t *pkg_new(void);
  11250. +int pkg_init(pkg_t *pkg);
  11251. +void pkg_deinit(pkg_t *pkg);
  11252. +int pkg_init_from_file(pkg_t *pkg, const char *filename);
  11253. +abstract_pkg_t *abstract_pkg_new(void);
  11254. +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
  11255. +
  11256. +/*
  11257. + * merges fields from newpkg into oldpkg.
  11258. + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
  11259. + */
  11260. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
  11261. +
  11262. +char *pkg_version_str_alloc(pkg_t *pkg);
  11263. +
  11264. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
  11265. +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
  11266. +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
  11267. +
  11268. +char * pkg_formatted_info(pkg_t *pkg );
  11269. +char * pkg_formatted_field(pkg_t *pkg, const char *field );
  11270. +
  11271. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
  11272. +
  11273. +void pkg_print_info(pkg_t *pkg, FILE *file);
  11274. +void pkg_print_status(pkg_t * pkg, FILE * file);
  11275. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
  11276. +str_list_t *pkg_get_installed_files(pkg_t *pkg);
  11277. +int pkg_free_installed_files(pkg_t *pkg);
  11278. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
  11279. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
  11280. +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
  11281. + const char *script, const char *args);
  11282. +
  11283. +/* enum mappings */
  11284. +char *pkg_state_want_to_str(pkg_state_want_t sw);
  11285. +pkg_state_want_t pkg_state_want_from_str(char *str);
  11286. +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
  11287. +pkg_state_flag_t pkg_state_flag_from_str(char *str);
  11288. +char *pkg_state_status_to_str(pkg_state_status_t ss);
  11289. +pkg_state_status_t pkg_state_status_from_str(char *str);
  11290. +
  11291. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
  11292. +
  11293. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
  11294. +int pkg_info_preinstall_check(ipkg_conf_t *conf);
  11295. +int pkg_free_installed_files(pkg_t *pkg);
  11296. +
  11297. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
  11298. +int pkg_write_changed_filelists(ipkg_conf_t *conf);
  11299. +
  11300. +#endif
  11301. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_hash.c busybox-1.15.2/archival/libipkg/pkg_hash.c
  11302. --- busybox-1.15.2.orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
  11303. +++ busybox-1.15.2/archival/libipkg/pkg_hash.c 2009-11-26 11:10:14.327858863 +0100
  11304. @@ -0,0 +1,623 @@
  11305. +/* ipkg_hash.c - the itsy package management system
  11306. +
  11307. + Steven M. Ayer
  11308. +
  11309. + Copyright (C) 2002 Compaq Computer Corporation
  11310. +
  11311. + This program is free software; you can redistribute it and/or
  11312. + modify it under the terms of the GNU General Public License as
  11313. + published by the Free Software Foundation; either version 2, or (at
  11314. + your option) any later version.
  11315. +
  11316. + This program is distributed in the hope that it will be useful, but
  11317. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11318. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11319. + General Public License for more details.
  11320. +*/
  11321. +
  11322. +#include "ipkg.h"
  11323. +#include <errno.h>
  11324. +#include <ctype.h>
  11325. +#include <stdlib.h>
  11326. +#include <string.h>
  11327. +
  11328. +#include "hash_table.h"
  11329. +#include "pkg.h"
  11330. +#include "ipkg_message.h"
  11331. +#include "pkg_vec.h"
  11332. +#include "pkg_hash.h"
  11333. +#include "pkg_parse.h"
  11334. +#include "ipkg_utils.h"
  11335. +
  11336. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11337. +
  11338. +/*
  11339. + * this will talk to both feeds-lists files and installed status files
  11340. + * example api:
  11341. + *
  11342. + * hash_table_t hash;
  11343. + * pkg_hash_init(name, &hash, 1000);
  11344. + * pkg_hash_add_from_file(<feed filename>);
  11345. + *
  11346. + * the query function is just there as a shell to prove to me that this
  11347. + * sort of works, but isn't far from doing something useful
  11348. + *
  11349. + * -sma, 12/21/01
  11350. + * modified: CDW 3 Jan. 2002
  11351. + */
  11352. +
  11353. +
  11354. +
  11355. +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
  11356. +{
  11357. + return hash_table_init(name, hash, len);
  11358. +}
  11359. +
  11360. +void pkg_hash_deinit(hash_table_t *hash)
  11361. +{
  11362. + hash_table_deinit(hash);
  11363. +}
  11364. +
  11365. +
  11366. +/* Find the default arch for a given package status file if none is given. */
  11367. +static char *pkg_get_default_arch(ipkg_conf_t *conf)
  11368. +{
  11369. + nv_pair_list_elt_t *l;
  11370. + const char *def_arch = HOST_CPU_STR; /* Default arch */
  11371. + int def_prio = 0; /* Other archs override this */
  11372. +
  11373. + l = conf->arch_list.head;
  11374. +
  11375. + while (l) {
  11376. + nv_pair_t *nv = l->data;
  11377. + int priority = strtol(nv->value, NULL, 0);
  11378. +
  11379. + /* Check if this arch has higher priority, and is valid */
  11380. + if ((priority > def_prio) &&
  11381. + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
  11382. + /* Our new default */
  11383. + def_prio = priority;
  11384. + def_arch = nv->name;
  11385. + }
  11386. + l = l->next;
  11387. + }
  11388. +
  11389. + return strdup(def_arch);
  11390. +}
  11391. +
  11392. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11393. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
  11394. +{
  11395. + hash_table_t *hash = &conf->pkg_hash;
  11396. + char **raw;
  11397. + char **raw_start;
  11398. + pkg_t *pkg;
  11399. +
  11400. + raw = raw_start = read_raw_pkgs_from_file(file_name);
  11401. + if (!raw)
  11402. + return -ENOMEM;
  11403. +
  11404. + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
  11405. + pkg = pkg_new();
  11406. + if (!pkg)
  11407. + return -ENOMEM;
  11408. +
  11409. + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
  11410. + if (!pkg->architecture) {
  11411. + char *version_str = pkg_version_str_alloc(pkg);
  11412. + pkg->architecture = pkg_get_default_arch(conf);
  11413. + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
  11414. + pkg->name, version_str, pkg->architecture);
  11415. + free(version_str);
  11416. + }
  11417. + hash_insert_pkg(hash, pkg, is_status_file,conf);
  11418. + } else {
  11419. + free(pkg);
  11420. + }
  11421. + }
  11422. +
  11423. + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
  11424. + memory after read_raw_pkgs_from_file */
  11425. + raw = raw_start;
  11426. + while (*raw) {
  11427. + free(*raw++);
  11428. + }
  11429. + free(raw_start);
  11430. + return 0;
  11431. +}
  11432. +
  11433. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
  11434. +{
  11435. + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
  11436. +}
  11437. +
  11438. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
  11439. +{
  11440. + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
  11441. + if (apkg)
  11442. + return NULL;
  11443. + return apkg->provided_by;
  11444. +}
  11445. +
  11446. +
  11447. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11448. + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
  11449. +{
  11450. + int i;
  11451. + int nprovides = 0;
  11452. + int nmatching = 0;
  11453. + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
  11454. + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
  11455. + abstract_pkg_vec_t *provided_apkg_vec;
  11456. + abstract_pkg_t **provided_apkgs;
  11457. + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
  11458. + pkg_t *latest_installed_parent = NULL;
  11459. + pkg_t *latest_matching = NULL;
  11460. + pkg_t *held_pkg = NULL;
  11461. + pkg_t *good_pkg_by_name = NULL;
  11462. +
  11463. + if (matching_apkgs == NULL || providers == NULL ||
  11464. + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
  11465. + return NULL;
  11466. +
  11467. + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
  11468. +
  11469. + provided_apkg_vec = apkg->provided_by;
  11470. + nprovides = provided_apkg_vec->len;
  11471. + provided_apkgs = provided_apkg_vec->pkgs;
  11472. + if (nprovides > 1)
  11473. + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
  11474. +
  11475. + /* accumulate all the providers */
  11476. + for (i = 0; i < nprovides; i++) {
  11477. + abstract_pkg_t *provider_apkg = provided_apkgs[i];
  11478. + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
  11479. + abstract_pkg_vec_insert(providers, provider_apkg);
  11480. + }
  11481. + nprovides = providers->len;
  11482. +
  11483. + for (i = 0; i < nprovides; i++) {
  11484. + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
  11485. + abstract_pkg_t *replacement_apkg = NULL;
  11486. + pkg_vec_t *vec;
  11487. +
  11488. + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
  11489. + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
  11490. + if (provider_apkg->replaced_by->len > 1) {
  11491. + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
  11492. + provider_apkg->name, replacement_apkg->name);
  11493. + }
  11494. + }
  11495. +
  11496. + if (replacement_apkg)
  11497. + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
  11498. + replacement_apkg->name, provider_apkg->name);
  11499. +
  11500. + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
  11501. + if (abstract_pkg_vec_contains(providers, replacement_apkg))
  11502. + continue;
  11503. + else
  11504. + provider_apkg = replacement_apkg;
  11505. + }
  11506. +
  11507. + if (!(vec = provider_apkg->pkgs)) {
  11508. + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
  11509. + continue;
  11510. + }
  11511. +
  11512. +
  11513. + /* now check for supported architecture */
  11514. + {
  11515. + int max_count = 0;
  11516. + int j;
  11517. +
  11518. + /* count packages matching max arch priority and keep track of last one */
  11519. + for (j = 0; j < vec->len; j++) {
  11520. + pkg_t *maybe = vec->pkgs[j];
  11521. + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
  11522. + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
  11523. + if (maybe->arch_priority > 0) {
  11524. + max_count++;
  11525. + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
  11526. + pkg_vec_insert(matching_pkgs, maybe);
  11527. + }
  11528. + }
  11529. + }
  11530. + }
  11531. +
  11532. + if (matching_pkgs->len > 1)
  11533. + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
  11534. + if (matching_apkgs->len > 1)
  11535. + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
  11536. +
  11537. +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
  11538. + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
  11539. +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
  11540. + Until now I always got the latest, but that breaks the downgrade option.
  11541. + If I stop at the first one, I would probably miss the new ones
  11542. + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
  11543. + or from a Packages feed.
  11544. + 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*/
  11545. +/*Pigi*/
  11546. +
  11547. + for (i = 0; i < matching_pkgs->len; i++) {
  11548. + pkg_t *matching = matching_pkgs->pkgs[i];
  11549. + if (constraint_fcn(matching, cdata)) { /* We found it */
  11550. + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
  11551. + good_pkg_by_name = matching;
  11552. + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
  11553. + break;
  11554. + }
  11555. + }
  11556. +
  11557. +
  11558. + for (i = 0; i < matching_pkgs->len; i++) {
  11559. + pkg_t *matching = matching_pkgs->pkgs[i];
  11560. + latest_matching = matching;
  11561. + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
  11562. + latest_installed_parent = matching;
  11563. + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
  11564. + if (held_pkg)
  11565. + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
  11566. + held_pkg->name, matching->name);
  11567. + held_pkg = matching;
  11568. + }
  11569. + }
  11570. +
  11571. + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
  11572. + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
  11573. + apkg->name, matching_apkgs->len);
  11574. + for (i = 0; i < matching_apkgs->len; i++) {
  11575. + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
  11576. + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
  11577. + }
  11578. + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
  11579. + }
  11580. +
  11581. + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
  11582. + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
  11583. + __FUNCTION__, apkg->name, matching_pkgs->len);
  11584. + for (i = 0; i < matching_pkgs->len; i++) {
  11585. + pkg_t *matching = matching_pkgs->pkgs[i];
  11586. + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
  11587. + matching->name, matching->version, matching->architecture);
  11588. + }
  11589. + }
  11590. +
  11591. + nmatching = matching_apkgs->len;
  11592. +
  11593. + pkg_vec_free(matching_pkgs);
  11594. + abstract_pkg_vec_free(matching_apkgs);
  11595. + abstract_pkg_vec_free(providers);
  11596. +
  11597. + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
  11598. + return good_pkg_by_name;
  11599. + }
  11600. + if (held_pkg) {
  11601. + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
  11602. + return held_pkg;
  11603. + }
  11604. + if (latest_installed_parent) {
  11605. + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
  11606. + return latest_installed_parent;
  11607. + }
  11608. + if (nmatching > 1) {
  11609. + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
  11610. + return NULL;
  11611. + }
  11612. + if (latest_matching) {
  11613. + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
  11614. + latest_matching->name, latest_matching->version, latest_matching->architecture);
  11615. + return latest_matching;
  11616. + }
  11617. + return NULL;
  11618. +}
  11619. +
  11620. +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
  11621. +{
  11622. + const char *name = (const char *)cdata;
  11623. + if (strcmp(pkg->name, name) == 0)
  11624. + return 1;
  11625. + else
  11626. + return 0;
  11627. +}
  11628. +
  11629. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
  11630. +{
  11631. + hash_table_t *hash = &conf->pkg_hash;
  11632. + abstract_pkg_t *apkg = NULL;
  11633. +
  11634. + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
  11635. + return NULL;
  11636. +
  11637. + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
  11638. +}
  11639. +
  11640. +
  11641. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11642. + const char *pkg_name,
  11643. + const char * version)
  11644. +{
  11645. + pkg_vec_t * vec;
  11646. + register int i;
  11647. + char *version_str = NULL;
  11648. +
  11649. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
  11650. + return NULL;
  11651. +
  11652. + for(i = 0; i < vec->len; i++) {
  11653. + version_str = pkg_version_str_alloc(vec->pkgs[i]);
  11654. + if(!strcmp(version_str, version)) {
  11655. + free(version_str);
  11656. + break;
  11657. + }
  11658. + free(version_str);
  11659. + }
  11660. +
  11661. + if(i == vec->len)
  11662. + return NULL;
  11663. +
  11664. + return vec->pkgs[i];
  11665. +}
  11666. +
  11667. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11668. + const char *pkg_name,
  11669. + pkg_dest_t *dest)
  11670. +{
  11671. + pkg_vec_t * vec;
  11672. + register int i;
  11673. +
  11674. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
  11675. + return NULL;
  11676. + }
  11677. +
  11678. + for(i = 0; i < vec->len; i++)
  11679. + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
  11680. + return vec->pkgs[i];
  11681. + }
  11682. + return NULL;
  11683. +}
  11684. +
  11685. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11686. + const char *pkg_name)
  11687. +{
  11688. + pkg_vec_t * vec;
  11689. + register int i;
  11690. +
  11691. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
  11692. + return NULL;
  11693. + }
  11694. +
  11695. + for(i = 0; i < vec->len; i++)
  11696. + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
  11697. + return vec->pkgs[i];
  11698. + }
  11699. +
  11700. + return NULL;
  11701. +}
  11702. +
  11703. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
  11704. +{
  11705. + abstract_pkg_t * ab_pkg;
  11706. +
  11707. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
  11708. + return NULL;
  11709. + }
  11710. +
  11711. + if (ab_pkg->pkgs) {
  11712. + return ab_pkg->pkgs;
  11713. + } else if (ab_pkg->provided_by) {
  11714. + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
  11715. + if (abpkg != NULL){
  11716. + return abpkg->pkgs;
  11717. + } else {
  11718. + return ab_pkg->pkgs;
  11719. + }
  11720. + } else {
  11721. + return NULL;
  11722. + }
  11723. +}
  11724. +
  11725. +static int pkg_compare_names(const void *p1, const void *p2)
  11726. +{
  11727. + const pkg_t *pkg1 = *(const pkg_t **)p1;
  11728. + const pkg_t *pkg2 = *(const pkg_t **)p2;
  11729. + if (pkg1->name == NULL)
  11730. + return 1;
  11731. + if (pkg2->name == NULL)
  11732. + return -1;
  11733. + return(strcmp(pkg1->name, pkg2->name));
  11734. +}
  11735. +
  11736. +
  11737. +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
  11738. +{
  11739. + int j;
  11740. + const char *name;
  11741. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11742. + pkg_vec_t *all = (pkg_vec_t *)data;
  11743. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11744. + name = pkg_name;
  11745. + if (pkg_vec) {
  11746. + for (j = 0; j < pkg_vec->len; j++) {
  11747. + pkg_t *pkg = pkg_vec->pkgs[j];
  11748. + pkg_vec_insert(all, pkg);
  11749. + }
  11750. + }
  11751. +}
  11752. +
  11753. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
  11754. +{
  11755. + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
  11756. + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
  11757. +}
  11758. +
  11759. +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
  11760. +{
  11761. + const char *name;
  11762. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11763. + pkg_vec_t *all = (pkg_vec_t *)data;
  11764. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11765. + int j;
  11766. + name = pkg_name;
  11767. + if (pkg_vec) {
  11768. + for (j = 0; j < pkg_vec->len; j++) {
  11769. + pkg_t *pkg = pkg_vec->pkgs[j];
  11770. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  11771. + pkg_vec_insert(all, pkg);
  11772. + }
  11773. + }
  11774. + }
  11775. +}
  11776. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
  11777. +{
  11778. + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
  11779. + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
  11780. +}
  11781. +
  11782. +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
  11783. +{
  11784. + int i;
  11785. + pkg_t *pkg;
  11786. + const char *name;
  11787. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11788. + ipkg_conf_t *conf = (ipkg_conf_t *)data;
  11789. + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
  11790. + name = pkg_name;
  11791. + fprintf(stdout, "%s\n", ab_pkg->name);
  11792. + i = 0;
  11793. + if (dependents != NULL)
  11794. + while (dependents [i] != NULL)
  11795. + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
  11796. + dependents = ab_pkg->provided_by->pkgs;
  11797. + i = 0;
  11798. + if (dependents != NULL)
  11799. + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
  11800. + printf ("\tprovided by - %s\n", dependents [i ++]->name);
  11801. + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
  11802. + if (pkg) {
  11803. + i = 0;
  11804. + while (i < pkg->depends_count)
  11805. + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
  11806. + }
  11807. +}
  11808. +void pkg_hash_dump(hash_table_t *hash, void *data)
  11809. +{
  11810. +
  11811. + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
  11812. + hash_table_foreach(hash, pkg_hash_dump_helper, data);
  11813. + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
  11814. +}
  11815. +
  11816. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11817. +{
  11818. + abstract_pkg_t * ab_pkg;
  11819. +
  11820. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
  11821. + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
  11822. +
  11823. + return ab_pkg;
  11824. +}
  11825. +
  11826. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  11827. +{
  11828. + abstract_pkg_t * ab_pkg;
  11829. + int arch_priority;
  11830. +
  11831. + if(!pkg)
  11832. + return pkg;
  11833. +
  11834. + arch_priority = pkg->arch_priority;
  11835. +
  11836. + if (buildDepends(hash, pkg)<0){
  11837. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11838. + return NULL;
  11839. + }
  11840. + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
  11841. +
  11842. + if (set_status) {
  11843. + if (pkg->state_status == SS_INSTALLED) {
  11844. + ab_pkg->state_status = SS_INSTALLED;
  11845. + } else if (pkg->state_status == SS_UNPACKED) {
  11846. + ab_pkg->state_status = SS_UNPACKED;
  11847. + }
  11848. + }
  11849. +
  11850. + if(!ab_pkg->pkgs)
  11851. + ab_pkg->pkgs = pkg_vec_alloc();
  11852. +
  11853. + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
  11854. + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
  11855. + pkg->parent = ab_pkg;
  11856. +
  11857. + if (buildProvides(hash, ab_pkg, pkg)<0){
  11858. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11859. + return NULL;
  11860. + }
  11861. + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
  11862. + if (buildConflicts(hash, pkg)<0){
  11863. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11864. + return NULL;
  11865. + }
  11866. + if (buildReplaces(hash, ab_pkg, pkg)<0) {
  11867. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11868. + return NULL;
  11869. + }
  11870. +
  11871. + buildDependedUponBy(pkg, ab_pkg);
  11872. + return pkg;
  11873. +}
  11874. +
  11875. +/*
  11876. + * this will assume that we've already determined that
  11877. + * the abstract pkg doesn't exist, 'cause we should know these things...
  11878. + */
  11879. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11880. +{
  11881. + abstract_pkg_t * ab_pkg;
  11882. +
  11883. + ab_pkg = abstract_pkg_new();
  11884. + if (ab_pkg == NULL) { return NULL; }
  11885. +
  11886. + ab_pkg->name = strdup(pkg_name);
  11887. + hash_table_insert(hash, pkg_name, ab_pkg);
  11888. +
  11889. + return ab_pkg;
  11890. +}
  11891. +
  11892. +
  11893. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
  11894. +{
  11895. + hash_table_t *file_hash = &conf->file_hash;
  11896. +
  11897. + return hash_table_get(file_hash, file_name);
  11898. +}
  11899. +
  11900. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
  11901. +{
  11902. + hash_table_t *file_hash = &conf->file_hash;
  11903. + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
  11904. + int file_name_len = strlen(file_name);
  11905. +
  11906. + if (file_name[file_name_len -1] == '/')
  11907. + return 0;
  11908. +
  11909. + if (conf->offline_root) {
  11910. + int len = strlen(conf->offline_root);
  11911. + if (strncmp(file_name, conf->offline_root, len) == 0) {
  11912. + file_name += len;
  11913. + }
  11914. + }
  11915. +
  11916. + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
  11917. + hash_table_insert(file_hash, file_name, owning_pkg);
  11918. + if (old_owning_pkg) {
  11919. + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
  11920. + /* mark this package to have its filelist written */
  11921. + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11922. + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11923. + }
  11924. + return 0;
  11925. +}
  11926. +
  11927. +
  11928. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_hash.h busybox-1.15.2/archival/libipkg/pkg_hash.h
  11929. --- busybox-1.15.2.orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
  11930. +++ busybox-1.15.2/archival/libipkg/pkg_hash.h 2009-11-26 11:10:14.331859652 +0100
  11931. @@ -0,0 +1,61 @@
  11932. +/* pkg_hash.h - the itsy package management system
  11933. +
  11934. + Steven M. Ayer
  11935. +
  11936. + Copyright (C) 2002 Compaq Computer Corporation
  11937. +
  11938. + This program is free software; you can redistribute it and/or
  11939. + modify it under the terms of the GNU General Public License as
  11940. + published by the Free Software Foundation; either version 2, or (at
  11941. + your option) any later version.
  11942. +
  11943. + This program is distributed in the hope that it will be useful, but
  11944. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11945. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11946. + General Public License for more details.
  11947. +*/
  11948. +
  11949. +#ifndef PKG_HASH_H
  11950. +#define PKG_HASH_H
  11951. +
  11952. +#include "pkg.h"
  11953. +#include "pkg_vec.h"
  11954. +#include "hash_table.h"
  11955. +
  11956. +
  11957. +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
  11958. +void pkg_hash_deinit(hash_table_t *hash);
  11959. +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
  11960. +
  11961. +void pkg_hash_dump(hash_table_t *hash, void *data);
  11962. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
  11963. +
  11964. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11965. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
  11966. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
  11967. +
  11968. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11969. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
  11970. +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11971. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
  11972. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11973. + const char *pkg_name,
  11974. + const char * version);
  11975. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
  11976. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11977. + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
  11978. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
  11979. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11980. + const char *pkg_name);
  11981. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11982. + const char *pkg_name,
  11983. + pkg_dest_t *dest);
  11984. +
  11985. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
  11986. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
  11987. +
  11988. +/* XXX: shouldn't this go in pkg_vec.[ch]? */
  11989. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11990. +
  11991. +#endif
  11992. +
  11993. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_parse.c busybox-1.15.2/archival/libipkg/pkg_parse.c
  11994. --- busybox-1.15.2.orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
  11995. +++ busybox-1.15.2/archival/libipkg/pkg_parse.c 2009-11-26 11:10:14.855857952 +0100
  11996. @@ -0,0 +1,368 @@
  11997. +/* pkg_parse.c - the itsy package management system
  11998. +
  11999. + Steven M. Ayer
  12000. +
  12001. + Copyright (C) 2002 Compaq Computer Corporation
  12002. +
  12003. + This program is free software; you can redistribute it and/or
  12004. + modify it under the terms of the GNU General Public License as
  12005. + published by the Free Software Foundation; either version 2, or (at
  12006. + your option) any later version.
  12007. +
  12008. + This program is distributed in the hope that it will be useful, but
  12009. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12010. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12011. + General Public License for more details.
  12012. +*/
  12013. +
  12014. +#include "ipkg.h"
  12015. +#include <errno.h>
  12016. +#include <ctype.h>
  12017. +
  12018. +#include "pkg.h"
  12019. +#include "ipkg_utils.h"
  12020. +#include "pkg_parse.h"
  12021. +
  12022. +int alterProvidesLine(char *raw, char *temp);
  12023. +
  12024. +int isGenericFieldType(char * type, char * line)
  12025. +{
  12026. + if(!strncmp(line, type, strlen(type)))
  12027. + return 1;
  12028. + return 0;
  12029. +}
  12030. +
  12031. +char * parseGenericFieldType(char * type, char * raw)
  12032. +{
  12033. + char * field_value = raw + (strlen(type) + 1);
  12034. + return trim_alloc(field_value);
  12035. +}
  12036. +
  12037. +void parseStatus(pkg_t *pkg, char * raw)
  12038. +{
  12039. + char sw_str[64], sf_str[64], ss_str[64];
  12040. +
  12041. + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
  12042. + pkg->state_want = pkg_state_want_from_str(sw_str);
  12043. + pkg->state_flag = pkg_state_flag_from_str(sf_str);
  12044. + pkg->state_status = pkg_state_status_from_str(ss_str);
  12045. +}
  12046. +
  12047. +char ** parseDependsString(char * raw, int * depends_count)
  12048. +{
  12049. + char ** depends = NULL;
  12050. + int line_count = 0;
  12051. + char buff[2048], * dest;
  12052. +
  12053. + while(raw && *raw && !isspace(*raw)) {
  12054. + raw++;
  12055. + }
  12056. +
  12057. + if(line_is_blank(raw)){
  12058. + *depends_count = line_count;
  12059. + return NULL;
  12060. + }
  12061. + while(raw && *raw){
  12062. + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
  12063. +
  12064. + while(isspace(*raw)) raw++;
  12065. +
  12066. + dest = buff;
  12067. + while((*raw != ',') && *raw)
  12068. + *dest++ = *raw++;
  12069. +
  12070. + *dest = '\0';
  12071. + depends[line_count] = trim_alloc(buff);
  12072. + if(depends[line_count] ==NULL)
  12073. + return NULL;
  12074. + line_count++;
  12075. + if(*raw == ',')
  12076. + raw++;
  12077. + }
  12078. + *depends_count = line_count;
  12079. + return depends;
  12080. +}
  12081. +
  12082. +void parseConffiles(pkg_t * pkg, char * raw)
  12083. +{
  12084. + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
  12085. +
  12086. + if(!strncmp(raw, "Conffiles:", 10))
  12087. + raw += strlen("Conffiles:");
  12088. +
  12089. + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
  12090. + conffile_list_append(&pkg->conffiles, file_name, md5sum);
  12091. + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
  12092. + while (*raw && isspace(*raw)) {
  12093. + raw++;
  12094. + }
  12095. + raw += strlen(file_name);
  12096. + while (*raw && isspace(*raw)) {
  12097. + raw++;
  12098. + }
  12099. + raw += strlen(md5sum);
  12100. + }
  12101. +}
  12102. +
  12103. +int parseVersion(pkg_t *pkg, char *raw)
  12104. +{
  12105. + char *colon, *eepochcolon;
  12106. +#ifdef USE_DEBVERSION
  12107. + char *hyphen;
  12108. +#endif
  12109. + unsigned long epoch;
  12110. +
  12111. + if (!*raw) {
  12112. + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
  12113. + return EINVAL;
  12114. + }
  12115. +
  12116. + if (strncmp(raw, "Version:", 8) == 0) {
  12117. + raw += 8;
  12118. + }
  12119. + while (*raw && isspace(*raw)) {
  12120. + raw++;
  12121. + }
  12122. +
  12123. + colon= strchr(raw,':');
  12124. + if (colon) {
  12125. + epoch= strtoul(raw,&eepochcolon,10);
  12126. + if (colon != eepochcolon) {
  12127. + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
  12128. + return EINVAL;
  12129. + }
  12130. + if (!*++colon) {
  12131. + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
  12132. + return EINVAL;
  12133. + }
  12134. + raw= colon;
  12135. + pkg->epoch= epoch;
  12136. + } else {
  12137. + pkg->epoch= 0;
  12138. + }
  12139. +
  12140. + pkg->revision = (char *)"";
  12141. + pkg->familiar_revision = (char *)"";
  12142. +
  12143. + pkg->version= malloc(strlen(raw)+1);
  12144. + if ( pkg->version == NULL ) {
  12145. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12146. + return ENOMEM;
  12147. + }
  12148. + strcpy(pkg->version, raw);
  12149. +
  12150. +#ifdef USE_DEBVERSION
  12151. + hyphen= strrchr(pkg->version,'-');
  12152. +
  12153. + if (hyphen) {
  12154. + *hyphen++= 0;
  12155. + if (strncmp("fam", hyphen, 3) == 0) {
  12156. + pkg->familiar_revision=hyphen+3;
  12157. + hyphen= strrchr(pkg->version,'-');
  12158. + if (hyphen) {
  12159. + *hyphen++= 0;
  12160. + pkg->revision = hyphen;
  12161. + }
  12162. + } else {
  12163. + pkg->revision = hyphen;
  12164. + }
  12165. + }
  12166. +#endif
  12167. +
  12168. +/*
  12169. + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
  12170. + pkg->epoch,
  12171. + pkg->version,
  12172. + pkg->revision,
  12173. + pkg->familiar_revision);
  12174. +*/
  12175. +
  12176. + return 0;
  12177. +}
  12178. +
  12179. +
  12180. +/* This code is needed to insert in first position the keyword for the aligning bug */
  12181. +
  12182. +int alterProvidesLine(char *raw, char *temp)
  12183. +{
  12184. +
  12185. +
  12186. + if (!*raw) {
  12187. + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
  12188. + return -EINVAL;
  12189. + }
  12190. +
  12191. + if ( temp == NULL ) {
  12192. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12193. + return -ENOMEM;
  12194. + }
  12195. +
  12196. + if (strncmp(raw, "Provides:", 9) == 0) {
  12197. + raw += 9;
  12198. + }
  12199. + while (*raw && isspace(*raw)) {
  12200. + raw++;
  12201. + }
  12202. +
  12203. + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
  12204. + while (*raw) {
  12205. + strncat( temp, raw++, 1);
  12206. + }
  12207. + return 0;
  12208. +
  12209. +}
  12210. +
  12211. +/* Some random thoughts from Carl:
  12212. +
  12213. + This function could be considerably simplified if we just kept
  12214. + an array of all the generic string-valued field names, and looped
  12215. + through those looking for a match. Also, these fields could perhaps
  12216. + be stored in the package as an array as well, (or, probably better,
  12217. + as an nv_pair_list_t).
  12218. +
  12219. + Fields which require special parsing or storage, (such as Depends:
  12220. + and Status:) could be handled as they are now.
  12221. +*/
  12222. +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
  12223. + to a dependency list. And, since we already have
  12224. + Depends/Pre-Depends and need to add Conflicts, Recommends, and
  12225. + Enhances, perhaps we could generalize all of these and save some
  12226. + code duplication.
  12227. +*/
  12228. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
  12229. +{
  12230. + int reading_conffiles, reading_description;
  12231. + int pkg_false_provides=1;
  12232. + char ** lines;
  12233. + char * provide=NULL;
  12234. +
  12235. + pkg->src = src;
  12236. + pkg->dest = dest;
  12237. +
  12238. + reading_conffiles = reading_description = 0;
  12239. +
  12240. + for (lines = *raw; *lines; lines++) {
  12241. + /* fprintf(stderr, "PARSING %s\n", *lines);*/
  12242. + if(isGenericFieldType((char *)"Package:", *lines))
  12243. + pkg->name = parseGenericFieldType((char *)"Package", *lines);
  12244. + else if(isGenericFieldType((char *)"Architecture:", *lines))
  12245. + pkg->architecture = parseGenericFieldType((char *)"Architecture", *lines);
  12246. + else if(isGenericFieldType((char *)"Filename:", *lines))
  12247. + pkg->filename = parseGenericFieldType((char *)"Filename", *lines);
  12248. + else if(isGenericFieldType((char *)"Section:", *lines))
  12249. + pkg->section = parseGenericFieldType((char *)"Section", *lines);
  12250. + else if(isGenericFieldType((char *)"MD5sum:", *lines))
  12251. + pkg->md5sum = parseGenericFieldType((char *)"MD5sum", *lines);
  12252. + /* The old ipkg wrote out status files with the wrong case for MD5sum,
  12253. + let's parse it either way */
  12254. + else if(isGenericFieldType((char *)"MD5Sum:", *lines))
  12255. + pkg->md5sum = parseGenericFieldType((char *)"MD5Sum", *lines);
  12256. + else if(isGenericFieldType((char *)"Size:", *lines))
  12257. + pkg->size = parseGenericFieldType((char *)"Size", *lines);
  12258. + else if(isGenericFieldType((char *)"Source:", *lines))
  12259. + pkg->source = parseGenericFieldType((char *)"Source", *lines);
  12260. + else if(isGenericFieldType((char *)"Installed-Size:", *lines))
  12261. + pkg->installed_size = parseGenericFieldType((char *)"Installed-Size", *lines);
  12262. + else if(isGenericFieldType((char *)"Installed-Time:", *lines)) {
  12263. + char *time_str = parseGenericFieldType((char *)"Installed-Time", *lines);
  12264. + pkg->installed_time = strtoul(time_str, NULL, 0);
  12265. + } else if(isGenericFieldType((char *)"Priority:", *lines))
  12266. + pkg->priority = parseGenericFieldType((char *)"Priority", *lines);
  12267. + else if(isGenericFieldType((char *)"Essential:", *lines)) {
  12268. + char *essential_value;
  12269. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12270. + if (strcmp(essential_value, "yes") == 0) {
  12271. + pkg->essential = 1;
  12272. + }
  12273. + free(essential_value);
  12274. + }
  12275. + else if(isGenericFieldType((char *)"Status", *lines))
  12276. + parseStatus(pkg, *lines);
  12277. + else if(isGenericFieldType((char *)"Version", *lines))
  12278. + parseVersion(pkg, *lines);
  12279. + else if(isGenericFieldType((char *)"Maintainer", *lines))
  12280. + pkg->maintainer = parseGenericFieldType((char *)"Maintainer", *lines);
  12281. + else if(isGenericFieldType((char *)"Conffiles", *lines)){
  12282. + parseConffiles(pkg, *lines);
  12283. + reading_conffiles = 1;
  12284. + }
  12285. + else if(isGenericFieldType((char *)"Description", *lines)) {
  12286. + pkg->description = parseGenericFieldType((char *)"Description", *lines);
  12287. + reading_conffiles = 0;
  12288. + reading_description = 1;
  12289. + }
  12290. +
  12291. + else if(isGenericFieldType((char *)"Provides", *lines)){
  12292. +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
  12293. + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
  12294. + if ( alterProvidesLine(*lines,provide) ){
  12295. + return EINVAL;
  12296. + }
  12297. + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
  12298. +/* Let's try to hack a bit here.
  12299. + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
  12300. + in alot of other places. We will remove it before writing down the status database */
  12301. + pkg_false_provides=0;
  12302. + free(provide);
  12303. + }
  12304. +
  12305. + else if(isGenericFieldType((char *)"Depends", *lines))
  12306. + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
  12307. + else if(isGenericFieldType((char *)"Pre-Depends", *lines))
  12308. + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
  12309. + else if(isGenericFieldType((char *)"Recommends", *lines))
  12310. + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
  12311. + else if(isGenericFieldType((char *)"Suggests", *lines))
  12312. + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
  12313. + /* Abhaya: support for conflicts */
  12314. + else if(isGenericFieldType((char *)"Conflicts", *lines))
  12315. + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
  12316. + else if(isGenericFieldType((char *)"Replaces", *lines))
  12317. + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
  12318. + else if(line_is_blank(*lines)) {
  12319. + lines++;
  12320. + break;
  12321. + }
  12322. + else if(**lines == ' '){
  12323. + if(reading_description) {
  12324. + /* we already know it's not blank, so the rest of description */
  12325. + pkg->description = realloc(pkg->description,
  12326. + strlen(pkg->description)
  12327. + + 1 + strlen(*lines) + 1);
  12328. + strcat(pkg->description, "\n");
  12329. + strcat(pkg->description, (*lines));
  12330. + }
  12331. + else if(reading_conffiles)
  12332. + parseConffiles(pkg, *lines);
  12333. + }
  12334. + }
  12335. + *raw = lines;
  12336. +/* If the ipk has not a Provides line, we insert our false line */
  12337. + if ( pkg_false_provides==1)
  12338. + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
  12339. +
  12340. + if (pkg->name) {
  12341. + return 0;
  12342. + } else {
  12343. + return EINVAL;
  12344. + }
  12345. +}
  12346. +
  12347. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
  12348. +{
  12349. + char ** lines;
  12350. +
  12351. + for (lines = *raw; *lines; lines++) {
  12352. + if(isGenericFieldType((char *)"Essential:", *lines)) {
  12353. + char *essential_value;
  12354. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12355. + if (strcmp(essential_value, "yes") == 0) {
  12356. + pkg->essential = 1;
  12357. + }
  12358. + free(essential_value);
  12359. + }
  12360. + }
  12361. + *raw = lines;
  12362. +
  12363. + return 0;
  12364. +}
  12365. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_parse.h busybox-1.15.2/archival/libipkg/pkg_parse.h
  12366. --- busybox-1.15.2.orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
  12367. +++ busybox-1.15.2/archival/libipkg/pkg_parse.h 2009-11-26 11:10:14.855857952 +0100
  12368. @@ -0,0 +1,31 @@
  12369. +/* pkg_parse.h - the itsy package management system
  12370. +
  12371. + Steven M. Ayer
  12372. +
  12373. + Copyright (C) 2002 Compaq Computer Corporation
  12374. +
  12375. + This program is free software; you can redistribute it and/or
  12376. + modify it under the terms of the GNU General Public License as
  12377. + published by the Free Software Foundation; either version 2, or (at
  12378. + your option) any later version.
  12379. +
  12380. + This program is distributed in the hope that it will be useful, but
  12381. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12382. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12383. + General Public License for more details.
  12384. +*/
  12385. +
  12386. +#ifndef PKG_PARSE_H
  12387. +#define PKG_PARSE_H
  12388. +
  12389. +int isGenericFieldType(char * type, char * line);
  12390. +char * parseGenericFieldType(char * type, char * raw);
  12391. +void parseStatus(pkg_t *pkg, char * raw);
  12392. +int parseVersion(pkg_t *pkg, char *raw);
  12393. +char ** parseDependsString(char * raw, int * depends_count);
  12394. +int parseVersion(pkg_t *pkg, char *raw);
  12395. +void parseConffiles(pkg_t * pkg, char * raw);
  12396. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
  12397. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
  12398. +
  12399. +#endif
  12400. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_src.c busybox-1.15.2/archival/libipkg/pkg_src.c
  12401. --- busybox-1.15.2.orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
  12402. +++ busybox-1.15.2/archival/libipkg/pkg_src.c 2009-11-26 11:10:14.859859580 +0100
  12403. @@ -0,0 +1,43 @@
  12404. +/* pkg_src.c - the itsy package management system
  12405. +
  12406. + Carl D. Worth
  12407. +
  12408. + Copyright (C) 2001 University of Southern California
  12409. +
  12410. + This program is free software; you can redistribute it and/or
  12411. + modify it under the terms of the GNU General Public License as
  12412. + published by the Free Software Foundation; either version 2, or (at
  12413. + your option) any later version.
  12414. +
  12415. + This program is distributed in the hope that it will be useful, but
  12416. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12417. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12418. + General Public License for more details.
  12419. +*/
  12420. +
  12421. +#include "ipkg.h"
  12422. +
  12423. +#include "pkg_src.h"
  12424. +#include "str_util.h"
  12425. +
  12426. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
  12427. +{
  12428. + src->gzip = gzip;
  12429. + src->name = str_dup_safe (name);
  12430. + src->value = str_dup_safe (base_url);
  12431. + if (extra_data)
  12432. + src->extra_data = str_dup_safe (extra_data);
  12433. + else
  12434. + src->extra_data = NULL;
  12435. + return 0;
  12436. +}
  12437. +
  12438. +void pkg_src_deinit(pkg_src_t *src)
  12439. +{
  12440. + free (src->name);
  12441. + free (src->value);
  12442. + if (src->extra_data)
  12443. + free (src->extra_data);
  12444. +}
  12445. +
  12446. +
  12447. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_src.h busybox-1.15.2/archival/libipkg/pkg_src.h
  12448. --- busybox-1.15.2.orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
  12449. +++ busybox-1.15.2/archival/libipkg/pkg_src.h 2009-11-26 11:10:14.859859580 +0100
  12450. @@ -0,0 +1,34 @@
  12451. +/* pkg_src.h - the itsy package management system
  12452. +
  12453. + Carl D. Worth
  12454. +
  12455. + Copyright (C) 2001 University of Southern California
  12456. +
  12457. + This program is free software; you can redistribute it and/or
  12458. + modify it under the terms of the GNU General Public License as
  12459. + published by the Free Software Foundation; either version 2, or (at
  12460. + your option) any later version.
  12461. +
  12462. + This program is distributed in the hope that it will be useful, but
  12463. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12464. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12465. + General Public License for more details.
  12466. +*/
  12467. +
  12468. +#ifndef PKG_SRC_H
  12469. +#define PKG_SRC_H
  12470. +
  12471. +#include "nv_pair.h"
  12472. +
  12473. +typedef struct
  12474. +{
  12475. + char *name;
  12476. + char *value;
  12477. + char *extra_data;
  12478. + int gzip;
  12479. +} pkg_src_t;
  12480. +
  12481. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
  12482. +void pkg_src_deinit(pkg_src_t *src);
  12483. +
  12484. +#endif
  12485. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_src_list.c busybox-1.15.2/archival/libipkg/pkg_src_list.c
  12486. --- busybox-1.15.2.orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
  12487. +++ busybox-1.15.2/archival/libipkg/pkg_src_list.c 2009-11-26 11:10:14.931856745 +0100
  12488. @@ -0,0 +1,75 @@
  12489. +/* pkg_src_list.c - the itsy package management system
  12490. +
  12491. + Carl D. Worth
  12492. +
  12493. + Copyright (C) 2001 University of Southern California
  12494. +
  12495. + This program is free software; you can redistribute it and/or
  12496. + modify it under the terms of the GNU General Public License as
  12497. + published by the Free Software Foundation; either version 2, or (at
  12498. + your option) any later version.
  12499. +
  12500. + This program is distributed in the hope that it will be useful, but
  12501. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12502. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12503. + General Public License for more details.
  12504. +*/
  12505. +
  12506. +#include "ipkg.h"
  12507. +
  12508. +#include "pkg_src_list.h"
  12509. +#include "void_list.h"
  12510. +
  12511. +int pkg_src_list_init(pkg_src_list_t *list)
  12512. +{
  12513. + return void_list_init((void_list_t *) list);
  12514. +}
  12515. +
  12516. +void pkg_src_list_deinit(pkg_src_list_t *list)
  12517. +{
  12518. + pkg_src_list_elt_t *iter;
  12519. + pkg_src_t *pkg_src;
  12520. +
  12521. + for (iter = list->head; iter; iter = iter->next) {
  12522. + pkg_src = iter->data;
  12523. + pkg_src_deinit(pkg_src);
  12524. +
  12525. + /* malloced in pkg_src_list_append */
  12526. + free(pkg_src);
  12527. + iter->data = NULL;
  12528. + }
  12529. + void_list_deinit((void_list_t *) list);
  12530. +}
  12531. +
  12532. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
  12533. + const char *name, const char *base_url, const char *extra_data,
  12534. + int gzip)
  12535. +{
  12536. + int err;
  12537. +
  12538. + /* freed in pkg_src_list_deinit */
  12539. + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
  12540. +
  12541. + if (pkg_src == NULL) {
  12542. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12543. + return NULL;
  12544. + }
  12545. + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
  12546. +
  12547. + err = void_list_append((void_list_t *) list, pkg_src);
  12548. + if (err) {
  12549. + return NULL;
  12550. + }
  12551. +
  12552. + return pkg_src;
  12553. +}
  12554. +
  12555. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
  12556. +{
  12557. + return void_list_push((void_list_t *) list, data);
  12558. +}
  12559. +
  12560. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
  12561. +{
  12562. + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
  12563. +}
  12564. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_src_list.h busybox-1.15.2/archival/libipkg/pkg_src_list.h
  12565. --- busybox-1.15.2.orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
  12566. +++ busybox-1.15.2/archival/libipkg/pkg_src_list.h 2009-11-26 11:10:14.931856745 +0100
  12567. @@ -0,0 +1,57 @@
  12568. +/* pkg_src_list.h - the itsy package management system
  12569. +
  12570. + Carl D. Worth
  12571. +
  12572. + Copyright (C) 2001 University of Southern California
  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. +#ifndef PKG_SRC_LIST_H
  12586. +#define PKG_SRC_LIST_H
  12587. +
  12588. +#include "pkg_src.h"
  12589. +
  12590. +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
  12591. +struct pkg_src_list_elt
  12592. +{
  12593. + pkg_src_list_elt_t *next;
  12594. + pkg_src_t *data;
  12595. +};
  12596. +
  12597. +typedef struct pkg_src_list pkg_src_list_t;
  12598. +struct pkg_src_list
  12599. +{
  12600. + pkg_src_list_elt_t pre_head;
  12601. + pkg_src_list_elt_t *head;
  12602. + pkg_src_list_elt_t *tail;
  12603. +};
  12604. +
  12605. +static inline int pkg_src_list_empty(pkg_src_list_t *list)
  12606. +{
  12607. + if (list->head == NULL)
  12608. + return 1;
  12609. + else
  12610. + return 0;
  12611. +}
  12612. +
  12613. +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
  12614. +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
  12615. +
  12616. +int pkg_src_list_init(pkg_src_list_t *list);
  12617. +void pkg_src_list_deinit(pkg_src_list_t *list);
  12618. +
  12619. +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);
  12620. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
  12621. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
  12622. +
  12623. +#endif
  12624. +
  12625. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_vec.c busybox-1.15.2/archival/libipkg/pkg_vec.c
  12626. --- busybox-1.15.2.orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
  12627. +++ busybox-1.15.2/archival/libipkg/pkg_vec.c 2009-11-26 11:10:14.935859211 +0100
  12628. @@ -0,0 +1,231 @@
  12629. +/* pkg_vec.c - the itsy package management system
  12630. +
  12631. + Steven M. Ayer
  12632. +
  12633. + Copyright (C) 2002 Compaq Computer Corporation
  12634. +
  12635. + This program is free software; you can redistribute it and/or
  12636. + modify it under the terms of the GNU General Public License as
  12637. + published by the Free Software Foundation; either version 2, or (at
  12638. + your option) any later version.
  12639. +
  12640. + This program is distributed in the hope that it will be useful, but
  12641. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12642. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12643. + General Public License for more details.
  12644. +*/
  12645. +
  12646. +#include <stdlib.h>
  12647. +#include <fnmatch.h>
  12648. +#include "libbb.h"
  12649. +#include "xregex.h"
  12650. +#include "ipkg.h"
  12651. +#include "pkg.h"
  12652. +
  12653. +pkg_vec_t * pkg_vec_alloc(void)
  12654. +{
  12655. + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
  12656. + if (!vec) {
  12657. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12658. + return NULL;
  12659. + }
  12660. + vec->pkgs = NULL;
  12661. + vec->len = 0;
  12662. +
  12663. + return vec;
  12664. +}
  12665. +
  12666. +void pkg_vec_free(pkg_vec_t *vec)
  12667. +{
  12668. + free(vec->pkgs);
  12669. + free(vec);
  12670. +}
  12671. +
  12672. +/*
  12673. + * assumption: all names in a vector are identical
  12674. + * assumption: all version strings are trimmed,
  12675. + * so identical versions have identical version strings,
  12676. + * implying identical packages; let's marry these
  12677. + */
  12678. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  12679. +{
  12680. + int i;
  12681. + int found = 0;
  12682. +
  12683. + /* look for a duplicate pkg by name, version, and architecture */
  12684. + for (i = 0; i < vec->len; i++){
  12685. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
  12686. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
  12687. + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
  12688. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12689. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12690. + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
  12691. + found = 1;
  12692. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
  12693. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12694. + break;
  12695. + }
  12696. + }
  12697. +
  12698. + /* we didn't find one, add it */
  12699. + if (!found){
  12700. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
  12701. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12702. +
  12703. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12704. + vec->pkgs[vec->len] = pkg;
  12705. + vec->len++;
  12706. + return pkg;
  12707. + }
  12708. + /* update the one that we have */
  12709. + else {
  12710. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
  12711. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12712. + if (set_status) {
  12713. + /* this is from the status file, so need to merge with existing database */
  12714. + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
  12715. + pkg_merge(vec->pkgs[i], pkg, set_status);
  12716. + /* XXX: CLEANUP: It's not so polite to free something here
  12717. + that was passed in from above. */
  12718. + pkg_deinit(pkg);
  12719. + free(pkg);
  12720. + } else {
  12721. + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
  12722. + /* just overwrite the old one */
  12723. + pkg_deinit(vec->pkgs[i]);
  12724. + free(vec->pkgs[i]);
  12725. + vec->pkgs[i] = pkg;
  12726. + }
  12727. + return vec->pkgs[i];
  12728. + }
  12729. +}
  12730. +
  12731. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
  12732. +{
  12733. + int i;
  12734. + int found = 0;
  12735. +
  12736. + /* look for a duplicate pkg by name, version, and architecture */
  12737. + for (i = 0; i < vec->len; i++)
  12738. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12739. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12740. + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
  12741. + found = 1;
  12742. + break;
  12743. + }
  12744. +
  12745. + /* we didn't find one, add it */
  12746. + if(!found){
  12747. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12748. + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
  12749. + vec->len++;
  12750. + }
  12751. +}
  12752. +
  12753. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
  12754. +{
  12755. + int i;
  12756. + for (i = 0; i < vec->len; i++)
  12757. + if (vec->pkgs[i] == apkg)
  12758. + return 1;
  12759. + return 0;
  12760. +}
  12761. +
  12762. +typedef int (*compare_fcn_t)(const void *, const void *);
  12763. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
  12764. +{
  12765. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12766. +}
  12767. +
  12768. +int pkg_vec_clear_marks(pkg_vec_t *vec)
  12769. +{
  12770. + int npkgs = vec->len;
  12771. + int i;
  12772. + for (i = 0; i < npkgs; i++) {
  12773. + pkg_t *pkg = vec->pkgs[i];
  12774. + pkg->state_flag &= ~SF_MARKED;
  12775. + }
  12776. + return 0;
  12777. +}
  12778. +
  12779. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
  12780. +{
  12781. + int matching_count = 0;
  12782. + pkg_t **pkgs = vec->pkgs;
  12783. + int npkgs = vec->len;
  12784. + int i;
  12785. + for (i = 0; i < npkgs; i++) {
  12786. + pkg_t *pkg = pkgs[i];
  12787. + if (fnmatch(pattern, pkg->name, 0)==0) {
  12788. + pkg->state_flag |= SF_MARKED;
  12789. + matching_count++;
  12790. + }
  12791. + }
  12792. + return matching_count;
  12793. +}
  12794. +
  12795. +
  12796. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
  12797. +{
  12798. + abstract_pkg_vec_t * vec ;
  12799. + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
  12800. + if (!vec) {
  12801. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12802. + return NULL;
  12803. + }
  12804. + vec->pkgs = NULL;
  12805. + vec->len = 0;
  12806. +
  12807. + return vec;
  12808. +}
  12809. +
  12810. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
  12811. +{
  12812. + free(vec->pkgs);
  12813. + free(vec);
  12814. +}
  12815. +
  12816. +/*
  12817. + * assumption: all names in a vector are unique
  12818. + */
  12819. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
  12820. +{
  12821. + int i;
  12822. +
  12823. + /* look for a duplicate pkg by name */
  12824. + for(i = 0; i < vec->len; i++)
  12825. + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12826. + break;
  12827. +
  12828. + /* we didn't find one, add it */
  12829. + if(i == vec->len){
  12830. + vec->pkgs =
  12831. + (abstract_pkg_t **)
  12832. + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
  12833. + vec->pkgs[vec->len] = pkg;
  12834. + vec->len++;
  12835. + }
  12836. +}
  12837. +
  12838. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
  12839. +{
  12840. + if (vec->len > i)
  12841. + return vec->pkgs[i];
  12842. + else
  12843. + return NULL;
  12844. +}
  12845. +
  12846. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
  12847. +{
  12848. + int i;
  12849. + for (i = 0; i < vec->len; i++)
  12850. + if (vec->pkgs[i] == apkg)
  12851. + return 1;
  12852. + return 0;
  12853. +}
  12854. +
  12855. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
  12856. +{
  12857. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12858. +}
  12859. +
  12860. diff -Nur busybox-1.15.2.orig/archival/libipkg/pkg_vec.h busybox-1.15.2/archival/libipkg/pkg_vec.h
  12861. --- busybox-1.15.2.orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
  12862. +++ busybox-1.15.2/archival/libipkg/pkg_vec.h 2009-11-26 11:10:14.939859721 +0100
  12863. @@ -0,0 +1,62 @@
  12864. +/* pkg_vec.h - the itsy package management system
  12865. +
  12866. + Steven M. Ayer
  12867. +
  12868. + Copyright (C) 2002 Compaq Computer Corporation
  12869. +
  12870. + This program is free software; you can redistribute it and/or
  12871. + modify it under the terms of the GNU General Public License as
  12872. + published by the Free Software Foundation; either version 2, or (at
  12873. + your option) any later version.
  12874. +
  12875. + This program is distributed in the hope that it will be useful, but
  12876. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12877. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12878. + General Public License for more details.
  12879. +*/
  12880. +
  12881. +#ifndef PKG_VEC_H
  12882. +#define PKG_VEC_H
  12883. +
  12884. +typedef struct pkg pkg_t;
  12885. +typedef struct abstract_pkg abstract_pkg_t;
  12886. +
  12887. +struct pkg_vec
  12888. +{
  12889. + pkg_t **pkgs;
  12890. + int len;
  12891. +};
  12892. +typedef struct pkg_vec pkg_vec_t;
  12893. +
  12894. +struct abstract_pkg_vec
  12895. +{
  12896. + abstract_pkg_t **pkgs;
  12897. + int len;
  12898. +};
  12899. +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
  12900. +
  12901. +
  12902. +pkg_vec_t * pkg_vec_alloc(void);
  12903. +void pkg_vec_free(pkg_vec_t *vec);
  12904. +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
  12905. +
  12906. +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
  12907. +/* pkg_vec_insert_merge: might munge pkg.
  12908. +* returns the pkg that is in the pkg graph */
  12909. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
  12910. +/* this one never munges pkg */
  12911. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
  12912. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
  12913. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
  12914. +
  12915. +int pkg_vec_clear_marks(pkg_vec_t *vec);
  12916. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
  12917. +
  12918. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
  12919. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
  12920. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
  12921. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
  12922. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
  12923. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
  12924. +#endif
  12925. +
  12926. diff -Nur busybox-1.15.2.orig/archival/libipkg/sprintf_alloc.h busybox-1.15.2/archival/libipkg/sprintf_alloc.h
  12927. --- busybox-1.15.2.orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
  12928. +++ busybox-1.15.2/archival/libipkg/sprintf_alloc.h 2009-11-26 11:10:14.999857591 +0100
  12929. @@ -0,0 +1,25 @@
  12930. +/* sprintf_alloca.c -- like sprintf with memory allocation
  12931. +
  12932. + Carl D. Worth
  12933. +
  12934. + Copyright (C) 2001 University of Southern California
  12935. +
  12936. + This program is free software; you can redistribute it and/or modify
  12937. + it under the terms of the GNU General Public License as published by
  12938. + the Free Software Foundation; either version 2, or (at your option)
  12939. + any later version.
  12940. +
  12941. + This program is distributed in the hope that it will be useful,
  12942. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  12943. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12944. + GNU General Public License for more details.
  12945. +*/
  12946. +
  12947. +#ifndef SPRINTF_ALLOC_H
  12948. +#define SPRINTF_ALLOC_H
  12949. +
  12950. +#include "libbb.h"
  12951. +
  12952. +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
  12953. +
  12954. +#endif
  12955. diff -Nur busybox-1.15.2.orig/archival/libipkg/str_list.c busybox-1.15.2/archival/libipkg/str_list.c
  12956. --- busybox-1.15.2.orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
  12957. +++ busybox-1.15.2/archival/libipkg/str_list.c 2009-11-26 11:10:14.999857591 +0100
  12958. @@ -0,0 +1,76 @@
  12959. +/* str_list.c - the itsy package management system
  12960. +
  12961. + Carl D. Worth
  12962. +
  12963. + Copyright (C) 2001 University of Southern California
  12964. +
  12965. + This program is free software; you can redistribute it and/or
  12966. + modify it under the terms of the GNU General Public License as
  12967. + published by the Free Software Foundation; either version 2, or (at
  12968. + your option) any later version.
  12969. +
  12970. + This program is distributed in the hope that it will be useful, but
  12971. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12972. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12973. + General Public License for more details.
  12974. +*/
  12975. +
  12976. +#include "ipkg.h"
  12977. +
  12978. +#include "str_list.h"
  12979. +
  12980. +int str_list_elt_init(str_list_elt_t *elt, char *data)
  12981. +{
  12982. + return void_list_elt_init((void_list_elt_t *) elt, data);
  12983. +}
  12984. +
  12985. +void str_list_elt_deinit(str_list_elt_t *elt)
  12986. +{
  12987. + void_list_elt_deinit((void_list_elt_t *) elt);
  12988. +}
  12989. +
  12990. +str_list_t *str_list_alloc(void)
  12991. +{
  12992. + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
  12993. + if (list)
  12994. + str_list_init(list);
  12995. + return list;
  12996. +}
  12997. +
  12998. +int str_list_init(str_list_t *list)
  12999. +{
  13000. + return void_list_init((void_list_t *) list);
  13001. +}
  13002. +
  13003. +void str_list_deinit(str_list_t *list)
  13004. +{
  13005. + void_list_deinit((void_list_t *) list);
  13006. +}
  13007. +
  13008. +int str_list_append(str_list_t *list, char *data)
  13009. +{
  13010. + return void_list_append((void_list_t *) list, data);
  13011. +}
  13012. +
  13013. +int str_list_push(str_list_t *list, char *data)
  13014. +{
  13015. + return void_list_push((void_list_t *) list, data);
  13016. +}
  13017. +
  13018. +str_list_elt_t *str_list_pop(str_list_t *list)
  13019. +{
  13020. + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
  13021. +}
  13022. +
  13023. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
  13024. +{
  13025. + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
  13026. + (void_list_elt_t **) iter);
  13027. +}
  13028. +
  13029. +char *str_list_remove_elt(str_list_t *list, const char *target_str)
  13030. +{
  13031. + return (char *)void_list_remove_elt((void_list_t *) list,
  13032. + (void *)target_str,
  13033. + (void_list_cmp_t)strcmp);
  13034. +}
  13035. diff -Nur busybox-1.15.2.orig/archival/libipkg/str_list.h busybox-1.15.2/archival/libipkg/str_list.h
  13036. --- busybox-1.15.2.orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
  13037. +++ busybox-1.15.2/archival/libipkg/str_list.h 2009-11-26 11:10:15.071857267 +0100
  13038. @@ -0,0 +1,51 @@
  13039. +/* str_list.h - the itsy package management system
  13040. +
  13041. + Carl D. Worth
  13042. +
  13043. + Copyright (C) 2001 University of Southern California
  13044. +
  13045. + This program is free software; you can redistribute it and/or
  13046. + modify it under the terms of the GNU General Public License as
  13047. + published by the Free Software Foundation; either version 2, or (at
  13048. + your option) any later version.
  13049. +
  13050. + This program is distributed in the hope that it will be useful, but
  13051. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13052. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13053. + General Public License for more details.
  13054. +*/
  13055. +
  13056. +#ifndef STR_LIST_H
  13057. +#define STR_LIST_H
  13058. +
  13059. +#include "void_list.h"
  13060. +
  13061. +typedef struct str_list_elt str_list_elt_t;
  13062. +struct str_list_elt
  13063. +{
  13064. + str_list_elt_t *next;
  13065. + char *data;
  13066. +};
  13067. +
  13068. +typedef struct xstr_list str_list_t;
  13069. +struct xstr_list
  13070. +{
  13071. + str_list_elt_t pre_head;
  13072. + str_list_elt_t *head;
  13073. + str_list_elt_t *tail;
  13074. +};
  13075. +
  13076. +int str_list_elt_init(str_list_elt_t *elt, char *data);
  13077. +void str_list_elt_deinit(str_list_elt_t *elt);
  13078. +
  13079. +str_list_t *str_list_alloc(void);
  13080. +int str_list_init(str_list_t *list);
  13081. +void str_list_deinit(str_list_t *list);
  13082. +
  13083. +int str_list_append(str_list_t *list, char *data);
  13084. +int str_list_push(str_list_t *list, char *data);
  13085. +str_list_elt_t *str_list_pop(str_list_t *list);
  13086. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
  13087. +char *str_list_remove_elt(str_list_t *list, const char *target_str);
  13088. +
  13089. +#endif
  13090. diff -Nur busybox-1.15.2.orig/archival/libipkg/str_util.c busybox-1.15.2/archival/libipkg/str_util.c
  13091. --- busybox-1.15.2.orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
  13092. +++ busybox-1.15.2/archival/libipkg/str_util.c 2009-11-26 11:10:15.075858615 +0100
  13093. @@ -0,0 +1,69 @@
  13094. +/* str_utils.c - the itsy package management system
  13095. +
  13096. + Carl D. Worth
  13097. +
  13098. + Copyright (C) 2001 University of Southern California
  13099. +
  13100. + This program is free software; you can redistribute it and/or
  13101. + modify it under the terms of the GNU General Public License as
  13102. + published by the Free Software Foundation; either version 2, or (at
  13103. + your option) any later version.
  13104. +
  13105. + This program is distributed in the hope that it will be useful, but
  13106. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13107. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13108. + General Public License for more details.
  13109. +*/
  13110. +
  13111. +#include "ipkg.h"
  13112. +
  13113. +int str_starts_with(const char *str, const char *prefix);
  13114. +int str_ends_with(const char *str, const char *suffix);
  13115. +int str_chomp(char *str);
  13116. +int str_toupper(char *str);
  13117. +char *str_dup_safe(const char *str);
  13118. +
  13119. +int str_starts_with(const char *str, const char *prefix)
  13120. +{
  13121. + return (strncmp(str, prefix, strlen(prefix)) == 0);
  13122. +}
  13123. +
  13124. +int str_ends_with(const char *str, const char *suffix)
  13125. +{
  13126. + int suffix_len;
  13127. + int str_len;
  13128. +
  13129. + str_len = strlen(str);
  13130. + suffix_len = strlen(suffix);
  13131. +
  13132. + if (str_len < suffix_len) {
  13133. + return 0;
  13134. + }
  13135. +
  13136. + return (strcmp(str + str_len - suffix_len, suffix) == 0);
  13137. +}
  13138. +
  13139. +int str_chomp(char *str)
  13140. +{
  13141. + if (str[strlen(str) - 1] == '\n') {
  13142. + str[strlen(str) - 1] = '\0';
  13143. + return 1;
  13144. + }
  13145. + return 0;
  13146. +}
  13147. +
  13148. +int str_toupper(char *str)
  13149. +{
  13150. + while (*str) {
  13151. + *str = toupper(*str);
  13152. + str++;
  13153. + }
  13154. +
  13155. + return 0;
  13156. +}
  13157. +
  13158. +char *str_dup_safe(const char *str)
  13159. +{
  13160. + return str ? strdup(str) : NULL;
  13161. +}
  13162. +
  13163. diff -Nur busybox-1.15.2.orig/archival/libipkg/str_util.h busybox-1.15.2/archival/libipkg/str_util.h
  13164. --- busybox-1.15.2.orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
  13165. +++ busybox-1.15.2/archival/libipkg/str_util.h 2009-11-26 11:10:15.075858615 +0100
  13166. @@ -0,0 +1,27 @@
  13167. +/* str_utils.h - the itsy package management system
  13168. +
  13169. + Carl D. Worth
  13170. +
  13171. + Copyright (C) 2001 University of Southern California
  13172. +
  13173. + This program is free software; you can redistribute it and/or
  13174. + modify it under the terms of the GNU General Public License as
  13175. + published by the Free Software Foundation; either version 2, or (at
  13176. + your option) any later version.
  13177. +
  13178. + This program is distributed in the hope that it will be useful, but
  13179. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13180. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13181. + General Public License for more details.
  13182. +*/
  13183. +
  13184. +#ifndef STR_UTILS_H
  13185. +#define STR_UTILS_H
  13186. +
  13187. +int str_starts_with(const char *str, const char *prefix);
  13188. +int str_ends_with(const char *str, const char *suffix);
  13189. +int str_chomp(char *str);
  13190. +int str_toupper(char *str);
  13191. +char *str_dup_safe(const char *str);
  13192. +
  13193. +#endif
  13194. diff -Nur busybox-1.15.2.orig/archival/libipkg/user.c busybox-1.15.2/archival/libipkg/user.c
  13195. --- busybox-1.15.2.orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
  13196. +++ busybox-1.15.2/archival/libipkg/user.c 2009-11-26 11:10:15.147857730 +0100
  13197. @@ -0,0 +1,61 @@
  13198. +/* user.c - the itsy package management system
  13199. +
  13200. + Jamey Hicks
  13201. +
  13202. + Copyright (C) 2002 Hewlett Packard Company
  13203. + Copyright (C) 2001 University of Southern California
  13204. +
  13205. + This program is free software; you can redistribute it and/or
  13206. + modify it under the terms of the GNU General Public License as
  13207. + published by the Free Software Foundation; either version 2, or (at
  13208. + your option) any later version.
  13209. +
  13210. + This program is distributed in the hope that it will be useful, but
  13211. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13212. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13213. + General Public License for more details.
  13214. +*/
  13215. +
  13216. +#include <stdio.h>
  13217. +#include <stdarg.h>
  13218. +#include "libbb.h"
  13219. +#include "file_util.h"
  13220. +#include "str_util.h"
  13221. +#ifdef IPKG_LIB
  13222. +#include "libipkg.h"
  13223. +#endif
  13224. +
  13225. +char *get_user_response(const char *format, ...);
  13226. +
  13227. +
  13228. +#ifdef IPKG_LIB
  13229. +static char *question = NULL;
  13230. +static int question_len = 255;
  13231. +#endif
  13232. +char *get_user_response(const char *format, ...)
  13233. +{
  13234. + int len = question_len;
  13235. + va_list ap;
  13236. + char *response;
  13237. + va_start(ap, format);
  13238. +
  13239. +#ifndef IPKG_LIB
  13240. + vprintf(format, ap);
  13241. + do {
  13242. + response = file_read_line_alloc(stdin);
  13243. + } while (response == NULL);
  13244. +#else
  13245. + do {
  13246. + if (question == NULL || len > question_len) {
  13247. + question = realloc(question, len + 1);
  13248. + question_len = len;
  13249. + }
  13250. + len = vsnprintf(question,question_len,format,ap);
  13251. + } while (len > question_len);
  13252. + response = strdup(ipkg_cb_response(question));
  13253. +#endif
  13254. + str_chomp(response);
  13255. + str_tolower(response);
  13256. +
  13257. + return response;
  13258. +}
  13259. diff -Nur busybox-1.15.2.orig/archival/libipkg/user.h busybox-1.15.2/archival/libipkg/user.h
  13260. --- busybox-1.15.2.orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
  13261. +++ busybox-1.15.2/archival/libipkg/user.h 2009-11-26 11:10:15.147857730 +0100
  13262. @@ -0,0 +1,23 @@
  13263. +/* user.c - the itsy package management system
  13264. +
  13265. + Jamey Hicks
  13266. +
  13267. + Copyright (C) 2002 Hewlett Packard Company
  13268. + Copyright (C) 2001 University of Southern California
  13269. +
  13270. + This program is free software; you can redistribute it and/or
  13271. + modify it under the terms of the GNU General Public License as
  13272. + published by the Free Software Foundation; either version 2, or (at
  13273. + your option) any later version.
  13274. +
  13275. + This program is distributed in the hope that it will be useful, but
  13276. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13277. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13278. + General Public License for more details.
  13279. +*/
  13280. +
  13281. +#include <stdio.h>
  13282. +#include <stdarg.h>
  13283. +
  13284. +char *get_user_response(const char *format, ...);
  13285. +
  13286. diff -Nur busybox-1.15.2.orig/archival/libipkg/void_list.c busybox-1.15.2/archival/libipkg/void_list.c
  13287. --- busybox-1.15.2.orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
  13288. +++ busybox-1.15.2/archival/libipkg/void_list.c 2009-11-26 11:10:15.151858798 +0100
  13289. @@ -0,0 +1,194 @@
  13290. +/* void_list.c - the itsy package management system
  13291. +
  13292. + Carl D. Worth
  13293. +
  13294. + Copyright (C) 2001 University of Southern California
  13295. +
  13296. + This program is free software; you can redistribute it and/or
  13297. + modify it under the terms of the GNU General Public License as
  13298. + published by the Free Software Foundation; either version 2, or (at
  13299. + your option) any later version.
  13300. +
  13301. + This program is distributed in the hope that it will be useful, but
  13302. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13303. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13304. + General Public License for more details.
  13305. +*/
  13306. +
  13307. +#include "ipkg.h"
  13308. +#include <errno.h>
  13309. +
  13310. +#include "void_list.h"
  13311. +
  13312. +int void_list_elt_init(void_list_elt_t *elt, void *data)
  13313. +{
  13314. + elt->next = NULL;
  13315. + elt->data = data;
  13316. +
  13317. + return 0;
  13318. +}
  13319. +
  13320. +void void_list_elt_deinit(void_list_elt_t *elt)
  13321. +{
  13322. + void_list_elt_init(elt, NULL);
  13323. +}
  13324. +
  13325. +int void_list_init(void_list_t *list)
  13326. +{
  13327. + void_list_elt_init(&list->pre_head, NULL);
  13328. + list->head = NULL;
  13329. + list->pre_head.next = list->head;
  13330. + list->tail = NULL;
  13331. +
  13332. + return 0;
  13333. +}
  13334. +
  13335. +void void_list_deinit(void_list_t *list)
  13336. +{
  13337. + void_list_elt_t *elt;
  13338. +
  13339. + while (list->head) {
  13340. + elt = void_list_pop(list);
  13341. + void_list_elt_deinit(elt);
  13342. + /* malloced in void_list_append */
  13343. + free(elt);
  13344. + }
  13345. +}
  13346. +
  13347. +int void_list_append(void_list_t *list, void *data)
  13348. +{
  13349. + void_list_elt_t *elt;
  13350. +
  13351. + /* freed in void_list_deinit */
  13352. + elt = malloc(sizeof(void_list_elt_t));
  13353. + if (elt == NULL) {
  13354. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13355. + return ENOMEM;
  13356. + }
  13357. +
  13358. + void_list_elt_init(elt, data);
  13359. +
  13360. + if (list->tail) {
  13361. + list->tail->next = elt;
  13362. + list->tail = elt;
  13363. + } else {
  13364. + list->head = elt;
  13365. + list->pre_head.next = list->head;
  13366. + list->tail = elt;
  13367. + }
  13368. +
  13369. + return 0;
  13370. +}
  13371. +
  13372. +int void_list_push(void_list_t *list, void *data)
  13373. +{
  13374. + void_list_elt_t *elt;
  13375. +
  13376. + elt = malloc(sizeof(void_list_elt_t));
  13377. + if (elt == NULL) {
  13378. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13379. + return ENOMEM;
  13380. + }
  13381. +
  13382. + void_list_elt_init(elt, data);
  13383. +
  13384. + elt->next = list->head;
  13385. + list->head->next = elt;
  13386. + if (list->tail == NULL) {
  13387. + list->tail = list->head;
  13388. + }
  13389. +
  13390. + return 0;
  13391. +}
  13392. +
  13393. +void_list_elt_t *void_list_pop(void_list_t *list)
  13394. +{
  13395. + void_list_elt_t *elt;
  13396. +
  13397. + elt = list->head;
  13398. +
  13399. + if (list->head) {
  13400. + list->head = list->head->next;
  13401. + list->pre_head.next = list->head;
  13402. + if (list->head == NULL) {
  13403. + list->tail = NULL;
  13404. + }
  13405. + }
  13406. +
  13407. + return elt;
  13408. +}
  13409. +
  13410. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
  13411. +{
  13412. + void_list_elt_t *prior;
  13413. + void_list_elt_t *old_elt;
  13414. + void *old_data;
  13415. +
  13416. + old_elt = *iter;
  13417. + old_data = old_elt->data;
  13418. +
  13419. + if (old_elt == list->head) {
  13420. + prior = &list->pre_head;
  13421. + void_list_pop(list);
  13422. + } else {
  13423. + for (prior = list->head; prior; prior = prior->next) {
  13424. + if (prior->next == old_elt) {
  13425. + break;
  13426. + }
  13427. + }
  13428. + if (prior == NULL || prior->next != old_elt) {
  13429. + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
  13430. + return NULL;
  13431. + }
  13432. + prior->next = old_elt->next;
  13433. +
  13434. + if (old_elt == list->tail) {
  13435. + list->tail = prior;
  13436. + }
  13437. + }
  13438. +
  13439. + void_list_elt_deinit(old_elt);
  13440. + *iter = prior;
  13441. +
  13442. + return old_data;
  13443. +}
  13444. +
  13445. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13446. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
  13447. +{
  13448. + void_list_elt_t *prior;
  13449. + void_list_elt_t *old_elt = NULL;
  13450. + void *old_data = NULL;
  13451. +
  13452. + /* first element */
  13453. + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
  13454. + old_elt = list->head;
  13455. + old_data = list->head->data;
  13456. + void_list_pop(list);
  13457. + } else {
  13458. + int found = 0;
  13459. + for (prior = list->head; prior && prior->next; prior = prior->next) {
  13460. + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
  13461. + old_elt = prior->next;
  13462. + old_data = old_elt->data;
  13463. + found = 1;
  13464. + break;
  13465. + }
  13466. + }
  13467. + if (!found) {
  13468. + return NULL;
  13469. + }
  13470. + prior->next = old_elt->next;
  13471. +
  13472. + if (old_elt == list->tail) {
  13473. + list->tail = prior;
  13474. + }
  13475. + }
  13476. + if (old_elt)
  13477. + void_list_elt_deinit(old_elt);
  13478. +
  13479. + if (old_data)
  13480. + return old_data;
  13481. + else
  13482. + return NULL;
  13483. +}
  13484. diff -Nur busybox-1.15.2.orig/archival/libipkg/void_list.h busybox-1.15.2/archival/libipkg/void_list.h
  13485. --- busybox-1.15.2.orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
  13486. +++ busybox-1.15.2/archival/libipkg/void_list.h 2009-11-26 11:10:15.251858401 +0100
  13487. @@ -0,0 +1,59 @@
  13488. +/* void_list.h - the itsy package management system
  13489. +
  13490. + Carl D. Worth
  13491. +
  13492. + Copyright (C) 2001 University of Southern California
  13493. +
  13494. + This program is free software; you can redistribute it and/or
  13495. + modify it under the terms of the GNU General Public License as
  13496. + published by the Free Software Foundation; either version 2, or (at
  13497. + your option) any later version.
  13498. +
  13499. + This program is distributed in the hope that it will be useful, but
  13500. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13501. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13502. + General Public License for more details.
  13503. +*/
  13504. +
  13505. +#ifndef VOID_LIST_H
  13506. +#define VOID_LIST_H
  13507. +
  13508. +typedef struct void_list_elt void_list_elt_t;
  13509. +struct void_list_elt
  13510. +{
  13511. + void_list_elt_t *next;
  13512. + void *data;
  13513. +};
  13514. +
  13515. +typedef struct void_list void_list_t;
  13516. +struct void_list
  13517. +{
  13518. + void_list_elt_t pre_head;
  13519. + void_list_elt_t *head;
  13520. + void_list_elt_t *tail;
  13521. +};
  13522. +
  13523. +static inline int void_list_empty(void_list_t *list)
  13524. +{
  13525. + if (list->head == NULL)
  13526. + return 1;
  13527. + else
  13528. + return 0;
  13529. +}
  13530. +
  13531. +int void_list_elt_init(void_list_elt_t *elt, void *data);
  13532. +void void_list_elt_deinit(void_list_elt_t *elt);
  13533. +
  13534. +int void_list_init(void_list_t *list);
  13535. +void void_list_deinit(void_list_t *list);
  13536. +
  13537. +int void_list_append(void_list_t *list, void *data);
  13538. +int void_list_push(void_list_t *list, void *data);
  13539. +void_list_elt_t *void_list_pop(void_list_t *list);
  13540. +
  13541. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
  13542. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13543. +typedef int (*void_list_cmp_t)(const void *, const void *);
  13544. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
  13545. +
  13546. +#endif
  13547. diff -Nur busybox-1.15.2.orig/archival/libipkg/xsystem.c busybox-1.15.2/archival/libipkg/xsystem.c
  13548. --- busybox-1.15.2.orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
  13549. +++ busybox-1.15.2/archival/libipkg/xsystem.c 2009-11-26 11:10:15.251858401 +0100
  13550. @@ -0,0 +1,64 @@
  13551. +/* xsystem.c - system(3) with error messages
  13552. +
  13553. + Carl D. Worth
  13554. +
  13555. + Copyright (C) 2001 University of Southern California
  13556. +
  13557. + This program is free software; you can redistribute it and/or
  13558. + modify it under the terms of the GNU General Public License as
  13559. + published by the Free Software Foundation; either version 2, or (at
  13560. + your option) any later version.
  13561. +
  13562. + This program is distributed in the hope that it will be useful, but
  13563. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13564. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13565. + General Public License for more details.
  13566. +*/
  13567. +
  13568. +#include "ipkg.h"
  13569. +#include <sys/wait.h>
  13570. +
  13571. +#include "xsystem.h"
  13572. +
  13573. +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
  13574. + really need the /bin/sh invocation which takes resources and
  13575. + introduces security problems. I should switch all of this to a sort
  13576. + of execl() or execv() interface/implementation.
  13577. +*/
  13578. +
  13579. +/* Like system(3), but with error messages printed if the fork fails
  13580. + or if the child process dies due to an uncaught signal. Also, the
  13581. + return value is a bit simpler:
  13582. +
  13583. + -1 if there was any problem
  13584. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13585. + as defined in <sys/wait.h>.
  13586. +*/
  13587. +int xsystem(const char *cmd)
  13588. +{
  13589. + int err;
  13590. +
  13591. + err = system(cmd);
  13592. +
  13593. + if (err == -1) {
  13594. + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
  13595. + __FUNCTION__, cmd);
  13596. + return -1;
  13597. + }
  13598. +
  13599. + if (WIFSIGNALED(err)) {
  13600. + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
  13601. + __FUNCTION__, WTERMSIG(err), cmd);
  13602. + return -1;
  13603. + }
  13604. +
  13605. + if (WIFEXITED(err)) {
  13606. + /* Normal child exit */
  13607. + return WEXITSTATUS(err);
  13608. + }
  13609. +
  13610. + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
  13611. + __FUNCTION__, err);
  13612. + return -1;
  13613. +}
  13614. +
  13615. diff -Nur busybox-1.15.2.orig/archival/libipkg/xsystem.h busybox-1.15.2/archival/libipkg/xsystem.h
  13616. --- busybox-1.15.2.orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
  13617. +++ busybox-1.15.2/archival/libipkg/xsystem.h 2009-11-26 11:10:15.323857513 +0100
  13618. @@ -0,0 +1,34 @@
  13619. +/* xsystem.h - system(3) with error messages
  13620. +
  13621. + Carl D. Worth
  13622. +
  13623. + Copyright (C) 2001 University of Southern California
  13624. +
  13625. + This program is free software; you can redistribute it and/or
  13626. + modify it under the terms of the GNU General Public License as
  13627. + published by the Free Software Foundation; either version 2, or (at
  13628. + your option) any later version.
  13629. +
  13630. + This program is distributed in the hope that it will be useful, but
  13631. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13632. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13633. + General Public License for more details.
  13634. +*/
  13635. +
  13636. +#ifndef XSYSTEM_H
  13637. +#define XSYSTEM_H
  13638. +
  13639. +#include <stdlib.h>
  13640. +
  13641. +/* Like system(3), but with error messages printed if the fork fails
  13642. + or if the child process dies due to an uncaught signal. Also, the
  13643. + return value is a bit simpler:
  13644. +
  13645. + -1 if there was any problem
  13646. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13647. + as defined in <sys/wait.h>.
  13648. +*/
  13649. +int xsystem(const char *cmd);
  13650. +
  13651. +#endif
  13652. +
  13653. diff -Nur busybox-1.15.2.orig/archival/libunarchive/data_extract_all.c busybox-1.15.2/archival/libunarchive/data_extract_all.c
  13654. --- busybox-1.15.2.orig/archival/libunarchive/data_extract_all.c 2009-10-08 02:59:09.000000000 +0200
  13655. +++ busybox-1.15.2/archival/libunarchive/data_extract_all.c 2009-11-26 11:10:15.327858023 +0100
  13656. @@ -147,3 +147,16 @@
  13657. }
  13658. }
  13659. }
  13660. +
  13661. +extern void FAST_FUNC data_extract_all_prefix(archive_handle_t *archive_handle)
  13662. +{
  13663. + char *name_ptr = archive_handle->file_header->name;
  13664. +
  13665. + name_ptr += strspn(name_ptr, "./");
  13666. + if (name_ptr[0] != '\0') {
  13667. + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
  13668. + strcpy(archive_handle->file_header->name, archive_handle->buffer);
  13669. + strcat(archive_handle->file_header->name, name_ptr);
  13670. + data_extract_all(archive_handle);
  13671. + }
  13672. +}
  13673. diff -Nur busybox-1.15.2.orig/archival/libunarchive/Kbuild busybox-1.15.2/archival/libunarchive/Kbuild
  13674. --- busybox-1.15.2.orig/archival/libunarchive/Kbuild 2009-09-26 15:14:57.000000000 +0200
  13675. +++ busybox-1.15.2/archival/libunarchive/Kbuild 2009-11-26 11:10:15.323857513 +0100
  13676. @@ -41,6 +41,7 @@
  13677. lib-$(CONFIG_DPKG) += $(DPKG_FILES)
  13678. lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
  13679. lib-$(CONFIG_GUNZIP) += decompress_unzip.o
  13680. +lib-$(CONFIG_IPKG) += open_transformer.o get_header_tar.o get_header_tar_gz.o
  13681. lib-$(CONFIG_RPM2CPIO) += decompress_unzip.o get_header_cpio.o
  13682. lib-$(CONFIG_RPM) += open_transformer.o decompress_unzip.o get_header_cpio.o
  13683. lib-$(CONFIG_TAR) += get_header_tar.o
  13684. diff -Nur busybox-1.15.2.orig/include/applets.h busybox-1.15.2/include/applets.h
  13685. --- busybox-1.15.2.orig/include/applets.h 2009-09-26 15:14:57.000000000 +0200
  13686. +++ busybox-1.15.2/include/applets.h 2009-11-26 11:32:09.719980839 +0100
  13687. @@ -213,6 +213,7 @@
  13688. IF_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_DROP))
  13689. IF_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
  13690. IF_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
  13691. +IF_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_DROP))
  13692. IF_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_DROP))
  13693. IF_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_DROP))
  13694. IF_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_DROP))
  13695. diff -Nur busybox-1.15.2.orig/include/unarchive.h busybox-1.15.2/include/unarchive.h
  13696. --- busybox-1.15.2.orig/include/unarchive.h 2009-10-08 02:59:09.000000000 +0200
  13697. +++ busybox-1.15.2/include/unarchive.h 2009-11-26 11:10:15.547858684 +0100
  13698. @@ -93,6 +93,7 @@
  13699. extern void data_skip(archive_handle_t *archive_handle) FAST_FUNC;
  13700. extern void data_extract_all(archive_handle_t *archive_handle) FAST_FUNC;
  13701. +extern void data_extract_all_prefix(archive_handle_t *archive_handle) FAST_FUNC;
  13702. extern void data_extract_to_stdout(archive_handle_t *archive_handle) FAST_FUNC;
  13703. extern void data_extract_to_buffer(archive_handle_t *archive_handle) FAST_FUNC;
  13704. diff -Nur busybox-1.15.2.orig/include/usage.h busybox-1.15.2/include/usage.h
  13705. --- busybox-1.15.2.orig/include/usage.h 2009-10-08 02:59:09.000000000 +0200
  13706. +++ busybox-1.15.2/include/usage.h 2009-11-26 11:10:15.551859473 +0100
  13707. @@ -1557,6 +1557,82 @@
  13708. "$ ls -la /tmp/busybox*\n" \
  13709. "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
  13710. +#define ipkg_trivial_usage \
  13711. + "[options]... sub-command [arguments]..."
  13712. +#define ipkg_full_usage \
  13713. + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
  13714. + "\n" \
  13715. + "Sub-commands:\n" \
  13716. + "\nPackage Manipulation:\n" \
  13717. + "\tupdate Update list of available packages\n" \
  13718. + "\tupgrade Upgrade all installed packages to latest version\n" \
  13719. + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
  13720. + "\tinstall <file.ipk> Install package <file.ipk>\n" \
  13721. + "\tconfigure [<pkg>] Configure unpacked packages\n" \
  13722. + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
  13723. + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
  13724. + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
  13725. + "\n" \
  13726. + "Informational Commands:\n" \
  13727. + "\tlist List available packages and descriptions\n" \
  13728. + "\tlist_installed List all and only the installed packages and description \n" \
  13729. + "\tfiles <pkg> List all files belonging to <pkg>\n" \
  13730. + "\tsearch <file|regexp> Search for a package providing <file>\n" \
  13731. + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
  13732. + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
  13733. + "\tdownload <pkg> Download <pkg> to current directory.\n" \
  13734. + "\tcompare_versions <v1> <op> <v2>\n" \
  13735. + "\t compare versions using <= < > >= = << >>\n" \
  13736. + "\tprint_architecture prints the architecture.\n" \
  13737. + "\tprint_installation_architecture\n" \
  13738. + "\twhatdepends [-A] [pkgname|pat]+\n" \
  13739. + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
  13740. + "\twhatprovides [-A] [pkgname|pat]+\n" \
  13741. + "\twhatconflicts [-A] [pkgname|pat]+\n" \
  13742. + "\twhatreplaces [-A] [pkgname|pat]+\n" \
  13743. + "\t prints the installation architecture.\n" \
  13744. + "\n" \
  13745. + "\nOptions:\n" \
  13746. + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
  13747. + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
  13748. + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
  13749. + "\t 0 errors only\n" \
  13750. + "\t 1 normal messages (default)\n" \
  13751. + "\t 2 informative messages\n" \
  13752. + "\t 3 debug output\n" \
  13753. + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
  13754. + "\t-conf <conf_file> Default configuration file location\n" \
  13755. + " is /etc/ipkg.conf\n" \
  13756. + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
  13757. + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
  13758. + " <dest_name> should be a defined dest name from\n" \
  13759. + " the configuration file, (but can also be a\n" \
  13760. + " directory name in a pinch).\n" \
  13761. + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
  13762. + "\t-offline <offline_root> offline installation of packages.\n" \
  13763. + "\t-verbose_wget more wget messages\n" \
  13764. + "\n" \
  13765. + "Force Options (use when ipkg is too smart for its own good):\n" \
  13766. + "\t-force-depends Make dependency checks warnings instead of errors\n" \
  13767. + "\t Install/remove package in spite of failed dependences\n" \
  13768. + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
  13769. + " (no prompts). Note that this will not prevent\n" \
  13770. + " package installation scripts from prompting.\n" \
  13771. + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
  13772. + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
  13773. + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
  13774. + "\t-force_space Install even if there does not seem to be enough space.\n" \
  13775. + "\t-noaction No action -- test only\n" \
  13776. + "\t-nodeps Do not follow dependences\n" \
  13777. + "\t-force-removal-of-dependent-packages\n" \
  13778. + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
  13779. + "\t-test No action -- test only\n" \
  13780. + "\t-t Specify tmp-dir.\n" \
  13781. + "\t--tmp-dir Specify tmp-dir.\n" \
  13782. + "\n" \
  13783. + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
  13784. + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
  13785. +
  13786. #define halt_trivial_usage \
  13787. "[-d delay] [-n] [-f]" IF_FEATURE_WTMP(" [-w]")
  13788. #define halt_full_usage "\n\n" \
  13789. diff -Nur busybox-1.15.2.orig/Makefile busybox-1.15.2/Makefile
  13790. --- busybox-1.15.2.orig/Makefile 2009-10-08 03:06:38.000000000 +0200
  13791. +++ busybox-1.15.2/Makefile 2009-11-26 11:10:12.791856498 +0100
  13792. @@ -445,6 +445,7 @@
  13793. libs-y := \
  13794. archival/ \
  13795. + archival/libipkg/ \
  13796. archival/libunarchive/ \
  13797. console-tools/ \
  13798. coreutils/ \