Exemplo n.º 1
0
int main(int argc, char *argv[])
{
   char        sig[37];
   MetaData    m;
   struct stat s;
   int         index = 1;
   bool        hasmeta = false;

   if (argc < 2)
   {
       printf("Usage: sigapp [-q] [-n] <mp3 file>\n");
       printf("  -q => quiet mode\n");
       printf("  -l => don't lookup data at musicbrainz\n");
       exit(0);
   }

   if (strcmp(argv[index], "-q") == 0)
   {
       quiet = 1;
       index++;
   }

   if (strcmp(argv[index], "-l") == 0)
   {
       nosubmit = 1;
       index++;
   }

   if (get_metadata(argv[index], &m))
   {
       stat(argv[index], &s);
       m.SetSize(s.st_size);
       if (!quiet)
       {
          printf("Local metadata:\n");
          printf("    Title: %s\n", m.Title().c_str());
          printf("    Album: %s\n", m.Album().c_str());
          printf("   Artist: %s\n", m.Artist().c_str());
          printf("    Genre: %s\n", m.Genre().c_str());
          printf("  Comment: %s\n", m.Comment().c_str());
          printf("    Track: %d\n", m.Track());
          printf("     Time: %d\n", m.Time());
          printf("     Size: %d\n", m.Size());
       }
       hasmeta = true;
   }
   
   if (ff_decode(argv[index], sig, 0, 0, 0, 24000, 0))
   {
       m.SetGUID(sig);
       if (!quiet)
           printf("Signature: ");

       printf("%s\n", sig);
       if (!nosubmit)
       {
           lookup_metadata(&m);
       }
#ifdef SIG_DEBUG
       FILE *logfile = fopen("guid_mapping.txt", "a+");
       fprintf(logfile,"%s\t%s\n", argv[index], sig);
       fclose(logfile);
#endif
   }
   else
   {
       if (!quiet)
          printf("Error calculating signature.\n");
   }

   return 0;
}
Exemplo n.º 2
0
/*! \brief Create version file Create version file based on the current file
   attributes.  \param path Complete file path \param dentry Dentry of the file 
   \param with_size Whether version file should be enlarged to the size of the
   current file */
int32_t
version_create_file_with_attr(char *path, internal_dentry dentry, volume vol,
							  string * orgpath)
{
	fattr *sa;

	zfs_fh fh;
	int32_t r;

	sa = &dentry->fh->version_orig_attr;
	// make sure we have correct attributes of the file
	if (orgpath)
	{
		local_getattr_path_ns(sa, orgpath);
	}
	else
		memcpy(sa, &dentry->fh->attr, sizeof(fattr));

	dentry->fh->version_fd = creat(path, GET_MODE(sa->mode));
	dentry->fh->version_path = xstrdup(path);

	if (lchown(path, map_uid_zfs2node(sa->uid),
			   map_gid_zfs2node(sa->gid)) != 0)
		RETURN_INT(errno);

	version_set_time(dentry->fh);

	if (orgpath)
	{
		if (truncate(path, sa->size) != 0)
			RETURN_INT(errno);
	}


	acquire_dentry(dentry->parent);

	r = ZFS_OK;

	if (r == ZFS_OK)
	{
		internal_dentry ndentry;
		zfs_fh master_fh;		// , tmp_fh;
		string name;
		metadata meta;
		fattr attr;
		string spath;
		char *p;

		zfs_fh_undefine(master_fh);

		p = strrchr(path, '/');
		if (p)
			p++;
		else
			p = path;
		xmkstring(&name, p);

		xmkstring(&spath, path);
		r = local_getattr_path_ns(&attr, &spath);
		free(spath.str);

		fh.sid = dentry->fh->local_fh.sid;
		fh.vid = dentry->fh->local_fh.vid;
		fh.dev = attr.dev;
		fh.ino = attr.ino;
		meta.flags = METADATA_COMPLETE;
		meta.modetype = GET_MODETYPE(attr.mode, attr.type);
		meta.uid = attr.uid;
		meta.gid = attr.gid;
		lookup_metadata(vol, &fh, &meta, true);
		set_attr_version(&attr, &meta);

		ndentry =
			internal_dentry_create_ns(&fh, &master_fh, vol, dentry->parent,
									  &name, sa, &meta, LEVEL_UNLOCKED);

		if (INTERNAL_FH_HAS_LOCAL_PATH(dentry->fh))
		{
			if (vol->master != this_node)
			{
				if (!add_journal_entry(vol, dentry->parent->fh->journal,
									   &dentry->parent->fh->local_fh,
									   &ndentry->fh->local_fh,
									   &ndentry->fh->meta.master_fh,
									   ndentry->fh->meta.master_version, &name,
									   JOURNAL_OPERATION_ADD))
				{
					MARK_VOLUME_DELETE(vol);
				}
			}
			if (!inc_local_version(vol, dentry->parent->fh))
				MARK_VOLUME_DELETE(vol);
		}

		dentry->version_dentry = ndentry;

		release_dentry(ndentry);
		free(name.str);
	}

	release_dentry(dentry->parent);

	RETURN_INT(ZFS_OK);
}