-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.json
2 lines (1 loc) · 8.76 KB
/
index.json
1
2
[{"content":" Welcome to my blog! # I\u0026rsquo;m working on tons of awesome projects all the time! Check them out in my posts or on my github\nQuestions? Comments? Job offers? # Email me at [email protected]!\n","date":"2 January 2025","externalUrl":null,"permalink":"/","section":"","summary":"","title":"","type":"page"},{"content":" Package managers are the heroes of modern software development. They handle the complex web of dependencies that power our applications, but how do they actually work? Join me on my journey to build jpkg, a package manager from scratch, and discover why this task that I assumed to be fairly easy turned out to be a fascinating challenge. The Challenge # The answer? Really hard. Really, really hard. This post is dedicated to explaining the most important things I\u0026rsquo;ve learned from this long journey to building my very own package manager, jpkg.\njharlan-hash/jpkg A small, portable package manager written in Java. Java 0 0 System Design # The architecture of jpkg follows a classic client-server model, designed with simplicity and extensibility in mind.\nCore Components # Client Interface\njpkg install \u0026lt;packagename\u0026gt; Package List Management\nA simple way of keeping track of which packages are available in the repository\nServer-Side Components\nThe server handles many aspects of this project, including storing and serving the packages, containing the repository listing, and routing incoming traffic.\nClient Functionality # The client\u0026rsquo;s job is simple in theory: Figure out what package the user is talking about and request it from the server. In practice, this requires several additional steps that were surprisingly difficult for me to implement.\nPackage List Handling # The first time the client connects to the server, the client receives a package list.\nThe packagelist will be saved in ~/.local/share/jpkg/jpkglist\nFor now, this package list is simply a java array containing Package objects.\nHowever, in the future, I want to use a SQLite database to store these packages. Using a database will relieve tons of issues that a normal array will not. For example, the database will store file paths, checksums, ownership, and installation timestamps which will make uninstalling and checking information on pages sigNIFicantly easier.\nAfter the first request, there are three ways that the client will receive an updated package list.\nTheir package list is too old If the client\u0026rsquo;s package list has not been updated in a certain length of time, they will receive a new package list.\nThe package they requested is not on their local copy of the package list If the client requests a package that is not on their local copy of the package list, it could be on the server\u0026rsquo;s, so it is requested.\nThe client specifies that they want to update their package list with the cli jpkg update Constructing a Request # When the client has checked the package list and determined the correct package to request, it sets up a short request to send to the server, containing the requested package and the time since the package list was last updated.\nnew Request(pack, timeSinceUpdate); Server Functionality # Initially, I thought that the server would be a complete pain to implement. There is so much that it has to do, like getting and caching requests, starting threads to handle multiple requests at the same time, dealing with sending large files over the internet, and figuring out how to store all the packages that it contains.\nOh, you thought I would tell you that it was actually fairly easy? Nope, this time my intuition was correct, and this took a long time. However, I learned a LOT of great skills for the future, so I\u0026rsquo;m overall glad that I did this project.\nSending the Package # I have two ideas for how sending the actual compressed archives of the packages will work. My first idea is that I can just use DataInput and Output Streams. However, if this proves to be infeasible, I think that the http protocol will be perfect for sending these large files, just like cURL does.\nAfter the package is sent, the it should be verified with a checksum to make sure it hasn\u0026rsquo;t been tampered with in transit.\nInstalling the Package # Once the package is received, a shell script that is shipped with the package is run to compile and install any code into the right places on the user\u0026rsquo;s system.\nTHIS IS TERRIBLE. This is a ridiculous way to do this, and I need to make a package manifest as soon as possible, most likely in Yaml, but again, there is a large amount of learning that I will have to do.\nI might also dabble in sandboxed installation, sending over HTTPS, and adding package signatures.\nCode # Core Classes # jpkg\u0026rsquo;s core is based heavily around the Package and Request classes. These take on a lot of the organizational burden, so it\u0026rsquo;s worth mentioning them.\nThe Package Class # The Package class represents a single installable unit in the system. Each package needs to track its basic metadata and dependencies:\nclass Package { private String name; private String version; private String description; private Package[] dependencies; private int id; public Package(String name, String version, String description, Package[] dependencies, int id) { this.name = name; this.version = version; this.description = description; this.dependencies = dependencies; this.id = id; } // lame getters and setters go here } Each package contains:\nA unique name and version\nA short description of its functionality\nAn array of Package objects it depends on\nA numeric ID for quick lookups (This will be replaced by a hashtable solution in a later release)\nThe Request Class # When a client needs to fetch a package, it constructs a Request object:\nclass Request { private Package pack; private int timeSinceLastUpdate; Request(Package pack, int timeSinceLastUpdate) { this.pack = pack; this.timeSinceLastUpdate = timeSinceLastUpdate; } // guess what i omitted here } The Request class is intentionally simple - it just needs to track what package is being requested and when the client last updated their package list. This helps the server decide whether to send an updated package list along with the requested package.\nThe ListManager Class # When the client needs to work with the package list, like updating it, checking against it, and more, a ListManager will be created to\nThe ClientManager Class # Functionality # Alright, now that we\u0026rsquo;ve set up some classes we\u0026rsquo;ll need, let\u0026rsquo;s get something working.\n","date":"2 January 2025","externalUrl":null,"permalink":"/posts/building-jpkg/","section":"Posts","summary":"","title":"Building a Package Manager from Scratch","type":"posts"},{"content":"","date":"2 January 2025","externalUrl":null,"permalink":"/posts/","section":"Posts","summary":"","title":"Posts","type":"posts"},{"content":"Hi!\nMy name is Jack Sovern and I am a senior in high school, about to go to the University of Iowa to study Computer Science and Engineering (yes, it\u0026rsquo;s one major). I\u0026rsquo;ve been interested in computers since I was seven or eight years old watching my dad play Civilization on our old beaten-up Toshiba. Five or so years ago, I built my own computer from parts, and from then on, I have been obsessed with computers. I started coding in Python 3 years ago, took up Rust for a misguided time, learned C for fun, and have now been using Java as my main language for the past year.\nI have a lifelong love of learning as much as I can, and this website is proof of this. I\u0026rsquo;ve recently took up a hobby of self-hosting, with a small server at my home running pi-hole, a web server with Hugo as its landing site, Kiwix for wikipedia, and several of my server-side applications written in Java. This website will be a space where I can share what I have been recently working on. Nothing here will be cutting edge, impressive, or perhaps even well-written. This entire site is an experiment, just for myself.\nSome of my favorite projects I\u0026rsquo;ve created are listed here:\njharlan-hash/JSChat Java 1 0 jharlan-hash/jsh a shell i\u0026rsquo;m making C 0 0 jharlan-hash/jpkg A small, portable package manager written in Java. Java 0 0 jharlan-hash/pi-game A game to memorize Pi Rust 0 0 ","externalUrl":null,"permalink":"/about/","section":"","summary":"","title":"","type":"page"},{"content":"","externalUrl":null,"permalink":"/authors/","section":"Authors","summary":"","title":"Authors","type":"authors"},{"content":"","externalUrl":null,"permalink":"/categories/","section":"Categories","summary":"","title":"Categories","type":"categories"},{"content":"","externalUrl":null,"permalink":"/series/","section":"Series","summary":"","title":"Series","type":"series"},{"content":"","externalUrl":null,"permalink":"/tags/","section":"Tags","summary":"","title":"Tags","type":"tags"}]