Google Summer of Code 2013 Final Report
Creating and extracting archives is easy, safe, and automatic. One module is created (gnome-autoar) and three modules are modified (Epiphany, Evolution, Empathy). The two major steps of this project are:
An wrapper for libarchive, GIO, and GTK+, provides GObject-based C API for archives and a few common widgets.
- Integrate archives into applications. I try to use existing widgets in applications to show archive works and user preferences settings.
Writing gnome-autoar is the first step. Although libarchive provides nearly everything we need to create and extract an archive, we still need a wrapper for it to reduce duplicate code, store user preferences, and share common widgets. Many things are different between the API provided by libarchive and gnome-autoar.
gnome-autoar uses GIO for nearly all operations related to archives. Some operations which are not supported by GIO will use POSIX functions instead if they are available.
gnome-autoar uses GSettings to store user preferences. You can use one function to retrive user preferences and use one object to set preferences when creating and extracting archives. It use the "org.gnome.desktop.archives" schema ID by default, but you can change it.
gnome-autoar will create exactly one directory or file when extracting an archive. No file will be created outside the output directory, so users do not have to worry about malicious archives because all absolute paths in the archives are converted to paths relative to the output directory. The name of the output directory or file is based on the name of the source archive. Even if you do not notify users about the output, users can easily figure it out themselves.
gnome-autoar will prepend a common prefix directory to all paths in the archive if you want to archive more than one file or directory. Users who receive the archive created by gnome-autoar can safely use commands such as bsdtar -xf to extract it.
gnome-autoar redefines the format code and filter code which are defined by libarchive as consecutive positive integer. It is easier for applications to show all available options to users. Some formats and filters such as mtree and uuencode are omitted because they are not suitable for regular use.
gnome-autoar provides functions for applications to check whether a file should be regarded as an archive. There are whitelists stored in GSettings. Package files such as rpm, deb, jar are not listed, so applications should know these files should not be extracted.
gnome-autoar provides an archive format chooser which can be used by GTK+ applications.
These applications will check whether a file is an archive before extracting.
Extracting: Epiphany will extract the downloaded file after the downloading is completed. It uses download panel to show the progress of extracting archive, and it is cancellable via the cancel button next to the item.
Creating: Epiphany use the status message bar to show the progress of creating archive, and it is cancellable via right click on the web page. A web page can only creating one archive at the same time because a WebKitWebView can only start a WebKitFileChooserRequest at the same time.
Dependency: gnome-autoar is currently a hard dependency of Epiphany.
Extracting: Evolution can save the original archive file and extracted files at the same time because the attachment is already loaded into memory. Users can choose what they want save, or save both the archive file and extracted files. It currently has no user interface to show or cancel the progress of extracting archive.
Creating: Evolution can create an archive for a directory when attaching files. It is cancellable via right click on the item.
Dependency: gnome-autoar is currently an optional dependency of Evolution.
Extracting: Empathy can extract the archive file after completely received the file. It is cancellable via the stop button.
Creating: Empathy can create an archive for a directory when sending a file. It will pop up a window and show the progress. It is cancellable via the cancel button on the popup window.
Dependency: gnome-autoar is currently a hard dependency of Empathy.
Actual progress in this summer
- Setup JHBuild environment was the first thing to do because dependencies cannot be satisfied using distribution packages. It took me several hours to setup up a JHBuild environment and resolve all compilation and linking error. Finally, I could start gnome-session inside the JHBuild environment. I ran JHBuild inside a KVM virtual machine before, but the graphics is too slow inside the virtual machine when there is a compilation work. Therefore, I rebuilt the environment on the host, which took several hours again.
- I spent one week to read the documentation of GObject. It seems GObject is not easy to use and understand, knowing how it works and using it needs a lot of time.
- I spent several days (less than one week) to write my first archive extracting program using libarchive. I started writing gnome-autoar inside the source tree of Epiphany, but gnome-autoar does not depend on anything from Epiphany except for the build system.
- After the extracting support is nearly completed, I worked on storing and retrieving user preferences. Later, I integrated the preferences support into extracting.
- I integrated archive extracting support into Epiphany. However, the developer of Epiphany said I should not add a new directory inside the Epiphany source tree, so I converted the gnome-autoar into a separate shared libaray. gnome-autoar uses its own configure.ac and Makefile.am to build itself and provide a pc (pkg-config) file.
- Archive creating, symbolic and hard link support, were later added into gnome-autoar. Some functions were rewritten and split into small functions or scope to ease memory management. Valgrind and clang static analyzer were used to check possible bugs in gnome-autoar every a few commits.
- Some problems are caused by libarchive itself. I don't know whether it should be regarded as a bug of libarchive, but I already read the relevant code of libarchive and provide some workaround in gnome-autoar.
- Archive support for Evolution was added. It took me several days to find the code location because Evolution has nearly one million lines of code. It also took relatively long time to compile Evolution.
- Empathy file transfer finally worked on my computer via changing settings in firewalld and iptables. I worked on it using the People Nearby protocol, which was suggested by the mentor.
- Evolution developer said I should not make Evolution hard depends on gnome-autoar, so I spent one day to change it into an optional dependency.
- Archive creating support for Epiphany is the last feature I added. It seems there is no suitable place to set the cancel button, and I don't want a popup window inside a web browser. Therefore, the cancel function is placed on the right click menu of the web page.
- Most code work seems to be completed! I started writing reference manual for gnome-autoar inside the source code using gtk-doc. It took me one week to get gtk-doc to work and write 1000 lines of comment.
Finally, this is a special summer for me! Although few things in my proposal still not completed, most things are completed and stable now. The code, result, and screenshot are available here.