Advertisement
Guest User

apt-cache.vala

a guest
Aug 2nd, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 1.44 KB | None | 0 0
  1. using Gtk;
  2. using GLib;
  3.  
  4. private int64[] get_folder_data (File file, string space = "", Cancellable? cancellable = null) throws Error
  5. {
  6.   FileEnumerator enumerator = file.enumerate_children (
  7.     "standard::*",
  8.     FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
  9.     cancellable);
  10.  
  11.     int64 files = 0;
  12.     int64 size  = 0;
  13.     int64[] data = new int64[2];
  14.     FileInfo info = null;
  15.  
  16.     while (cancellable.is_cancelled () == false && ((info = enumerator.next_file (cancellable)) != null)) {
  17.         if (info.get_file_type () == FileType.DIRECTORY) {
  18.             File subdir = file.resolve_relative_path (info.get_name ());
  19.             get_folder_data (subdir, space + " ", cancellable);
  20.         } else {
  21.             files += 1;//Sum Files
  22.             size  += info.get_size ();//Accumulates Size
  23.         }
  24.     }
  25.  
  26.     if (cancellable.is_cancelled ()) {
  27.         throw new IOError.CANCELLED ("Operation was cancelled");
  28.     }
  29.  
  30.     data[0] = files;
  31.     data[1] = size;
  32.  
  33.     stdout.printf ("APT CACHE SIZE: %s\n", files.to_string());
  34.     stdout.printf ("APT CACHE FILES: %s\n", size.to_string());
  35.  
  36.     return data;
  37. }
  38.  
  39. public static int main (string[] args) {
  40.     Gtk.init (ref args);
  41.    
  42.     File APT_CACHE_PATH = File.new_for_path ("/var/cache/apt/archives");
  43.     try {
  44.         get_folder_data (APT_CACHE_PATH, "", new Cancellable ());
  45.     } catch (Error e) {
  46.         stdout.printf ("ERROR: %s\n", e.message);    
  47.     }
  48.     Gtk.main ();
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement