Example #1
0
void
_create_data_dir(void)
{
    GString *profanity_dir = g_string_new(XDG_DATA_HOME);
    g_string_append(profanity_dir, "/profanity");

    if (!_mkdir_recursive(profanity_dir->str)) {
        assert_true(FALSE);
    }

    g_string_free(profanity_dir, TRUE);
}
Example #2
0
void
_create_chatlogs_dir(void)
{
    GString *chatlogs_dir = g_string_new(XDG_DATA_HOME);
    g_string_append(chatlogs_dir, "/profanity/chatlogs");

    if (!_mkdir_recursive(chatlogs_dir->str)) {
        assert_true(FALSE);
    }

    g_string_free(chatlogs_dir, TRUE);
}
Example #3
0
/**
 * Analyzes a file and copies it if it contains image data.
 * @param fpath The filename of the current entry.
 * @param sb A pointer to the stat structure.
 * @param typeflag The current entry type.
 */
static int
_ftw_callback(char const* fpath, struct stat const* sb, int typeflag)
{
  int rc;
  ExifData* exif_data;
  ExifEntry* exif_entry;
  char exif_entry_val[20];
  struct tm tm;

  // The current entry is not a file. Skip it.
  if (!S_ISREG(sb->st_mode)) {
    return 0;
  }

  // The current entry has no EXIF data. Skip it.
  exif_data = exif_data_new_from_file(fpath);
  if (exif_data == NULL) {
    return 0;
  }

  rc = 0;
  exif_entry = exif_content_get_entry(*(exif_data->ifd), EXIF_TAG_DATE_TIME);

  if (exif_entry != NULL
      && exif_entry_get_value(exif_entry, exif_entry_val, 20) != NULL
      && strptime(exif_entry_val, "%Y:%m:%d %H:%M:%S", &tm) != 0) {
    size_t dst_size;
    char* dst;

    dst_size = strlen(_DST) + 12;
    dst = (char*) malloc(dst_size);

    // Create the destination path.
    if (snprintf(dst, dst_size, "%s/%d/%02d/%02d", _DST, tm.tm_year + 1900,
                 tm.tm_mon + 1, tm.tm_mday) >= 0
        && _mkdir_recursive(dst) == 0) {
      size_t offset;
      char* dst_fpath;

      offset = strlen(fpath);
      while (offset > 0 && fpath[offset - 1] != '/') {
        --offset;
      }

      // Copy the file.
      dst_fpath = (char*) malloc(strlen(dst) + strlen(fpath + offset) + 2);
      sprintf(dst_fpath, "%s/%s", dst, fpath + offset);
      rc = _cp(dst_fpath, fpath);
      free(dst_fpath);

      if (rc == -1 && errno == EEXIST) {
        rc = 0;
      }
    }

    free(dst);
  }

  exif_data_unref(exif_data);
  return rc;
}