Perl keeps track of online orders
Tearing the Drapes
The script needs to peek behind the drapes of the cache to delete the entry after the goods have arrived because you need to know a file's name to be able to delete it from a Git repository; however, the cache generates a 40-byte hash as the filename for each key (as in d549f860476c…). If the user tries to delete the entry for the iPod by issuing a shop got iPod command, the path_to_key function defined in lines 109ff. peeps behind the drapes of the cache abstraction and retrieves the matching pathname. Line 62 then issues a git rm -f command to remove the file both from the local workspace and the entry in the local repository. A subsequent commit makes this permanent.
The shop list command tells the record_list() function, lines 149ff. to call the cache implementation's get_keys() method and return all the keys that exist in the cache as a list. It then passes each element of the list to the get() method, which retrieves the cache entry for a key from disk.
The git commands are all issued through the cmd_run function defined in lines 188ff., which internally calls tap from the Sysadm::Install module, which in turn runs the command lines, intercepts STDERR and STDOUT, and returns them neatly to the caller as return parameters.
Logging
The local repository logs all the transactions and therefore could easily reinstate past states. If you are interested in the transactions that have occurred in the repository, you can simply query the repository's log by issuing the git log command in the ~/data/shop directory, as Figure 5 shows.
Conflicts Happen
If two clients independently store the same product in their local repositories, a conflict occurs as soon as the second client attempts to shop push its changes to the centralized server.
Figure 6 shows the nasty error message issued by Git when a second client attempts to shop push. Ideally, when a shop pull follows, git should notice that the changes to the remote branch and the local file are identical, but because the object here is a binary file created by Cache::FileCache, it doesn't trust its own judgment and complains instead. Text files, on the other hand, are handled perfectly by Git in this respect.
If a conflict occurs, Git enters a merge state and waits for the user to resolve it. In this case, you need to delete the product locally (shop got) and then create it again (shop buy). The next push is accepted, and the server repository is happy again.
If the client were to delete the product, not create it again, but issue a push instead, the chainsaw ordered in Figure 6 would disappear from the server repository. After a shop pull on the first client, it would disappear from its local repository, too.
« Previous 1 2 3 Next »
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.
-
Gnome OS Transitioning Toward a General-Purpose Distro
If you're looking for the perfectly vanilla take on the Gnome desktop, Gnome OS might be for you.