Logo Search packages:      
Sourcecode: jigdo version File versions

void JobLine::create ( const char *  uri,
const char *  dest 
) [static]

Kind of a JobLine factory, called when the user clicks on OK to start a new download. It decides whether a normal file download or a .jigdo download is needed and creates the appropriate object. Additionally, the Job is appended to the list of jobs, and run.

url What to download (if it ends in ".jigdo" and dest is a directory, will start jigdo processing)
dest Where to put downloaded data, either a dir or a file.

Definition at line 45 of file jobline.cc.

References Error::message, and GtkSingleUrl::run().


  if (*uri == '\0') {
    MessageBox* m = new MessageBox(MessageBox::INFO, MessageBox::OK,
      _("Field for source URL/filename is empty"),
      _("Please enter an \"http\" or \"ftp\" URL to download, or the name "
        "of a <tt>.jigdo</tt> file to process."));

  /* Removing trailing '\' is necessary on Windows. Also, makeimagedl expects
     no trailing DIRSEP. */
  string destination(dest);
  unsigned destLen = destination.length();
  while (destLen > 1 && destination[destLen - 1] == DIRSEP) --destLen;

  struct stat fileInfo;
  int statDest = stat(destination.c_str(), &fileInfo);
  bool destIsDir = S_ISDIR(fileInfo.st_mode);

  if (statDest != 0 && errno != ENOENT) {
    // destination is present, but error accessing it
    MessageBox* m = new MessageBox(MessageBox::ERROR, MessageBox::OK,
      _("Error accessing destination"),
      subst(_("The destination `%LE1' is present, but cannot be accessed: "
              "%LE2"), destination, strerror(errno)));

  // Also create parent object
  unsigned lastDirSep = destination.rfind(DIRSEP);
  if (lastDirSep == 0) lastDirSep = 1; // Parent of "/tmp" is "/" not ""
  string destParent(destination, 0, lastDirSep); // can be ==destination
  int statDestParent = stat(destParent.c_str(), &fileInfo);
  if (statDestParent != 0) {
    MessageBox* m = new MessageBox(MessageBox::ERROR, MessageBox::OK,
      _("Error accessing directory to save to"),
      subst(_("The destination `%LE1' cannot be accessed: %LE2"),
            destination, strerror(errno)));

  /* We perform a regular download if the destination is either a filename
     (as opposed to a dir name), or the URI is not a jigdo file. */
  string uriStr(uri);
  if ((statDest != 0 && errno == ENOENT) // destination does not exist
      || (statDest == 0 && !destIsDir) // exists as file
      || !compareEnd(uriStr, ".jigdo")) { // URI end not ".jigdo"
    if (statDest == 0 && destIsDir) {
      // Append filename from source to directory name
      unsigned lastDirSep = uriStr.rfind('/');
      destination += DIRSEP;
      /* If URL ends with /, use index.html as filename. DON'T try to use any
         name supplied by the server during a HTTP redirect - a malicious
         server could trick us into overwriting files! */
      if (lastDirSep == uriStr.length() - 1)
        destination.append(uriStr, lastDirSep + 1, string::npos);
    GtkSingleUrl* result = new GtkSingleUrl(uriStr, destination);
    // NB result may already have deleted itself at this point

  static bool dom = false;
  if (!dom) {
    dom = true;
    MessageBox* m = new MessageBox(MessageBox::INFO, MessageBox::NONE,
        "values of β will give rise to dom!",
        "Processing of .jigdo files is not yet implemented - only "
        "downloads of single files (e.g. <tt>.iso</tt> images) work.\n"
        "jigdo might crash any minute now - don't complain, I'm working on "
        "it! :-)\n"
        "Please use <tt>jigdo-lite</tt> to process .jigdo URLs.");
    m->addButton(_("_Cool!"), 0);
    m->addButton(_("_Awesome!"), 0);
    m->addButton(_("_Fantastic!"), GTK_RESPONSE_CANCEL);

  // Not a regular download => a .jigdo download
  // destination is a directory, uriStr ends in ".jigdo"
  GtkMakeImage* result = new GtkMakeImage(uriStr, destination);
  try {
  } catch (Error e) {
    MessageBox* m = new MessageBox(MessageBox::ERROR, MessageBox::OK, 0,
                                   subst("%E1", e.message));
    delete result;

Generated by  Doxygen 1.6.0   Back to index