Ignore:
Timestamp:
Feb 15, 2013, 1:51:49 AM (8 years ago)
Author:
jordan
Message:

(libT) remove code to migrate config files from pre-2008

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/platform.c

    r13991 r14022  
    302302}
    303303
    304 static const char *
    305 getOldConfigDir (void)
    306 {
    307   static char * path = NULL;
    308 
    309   if (!path)
    310     {
    311 #ifdef SYS_DARWIN
    312       path = tr_buildPath (getHomeDir (), "Library",
    313                            "Application Support",
    314                            "Transmission", NULL);
    315 #elif defined (WIN32)
    316       char appdata[MAX_PATH]; /* SHGetFolderPath () requires MAX_PATH */
    317       SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, appdata);
    318       path = tr_buildPath (appdata, "Transmission", NULL);
    319 #elif defined (__HAIKU__)
    320       char buf[TR_PATH_MAX];
    321       find_directory (B_USER_SETTINGS_DIRECTORY, -1, true, buf, sizeof (buf));
    322       path = tr_buildPath (buf, "Transmission", NULL);
    323 #else
    324       path = tr_buildPath (getHomeDir (), ".transmission", NULL);
    325 #endif
    326     }
    327 
    328   return path;
    329 }
    330 
    331304#if defined (SYS_DARWIN) || defined (WIN32)
    332305 #define RESUME_SUBDIR  "Resume"
     
    337310#endif
    338311
    339 static const char *
    340 getOldTorrentsDir (void)
    341 {
    342   static char * path = NULL;
    343 
    344   if (!path)
    345     path = tr_buildPath (getOldConfigDir (), TORRENT_SUBDIR, NULL);
    346 
    347   return path;
    348 }
    349 
    350 static const char *
    351 getOldCacheDir (void)
    352 {
    353   static char * path = NULL;
    354 
    355   if (!path)
    356     {
    357 #if defined (WIN32)
    358       path = tr_buildPath (getOldConfigDir (), "Cache", NULL);
    359 #elif defined (SYS_DARWIN)
    360       path = tr_buildPath (getHomeDir (), "Library", "Caches", "Transmission", NULL);
    361 #else
    362       path = tr_buildPath (getOldConfigDir (), "cache", NULL);
    363 #endif
    364     }
    365 
    366   return path;
    367 }
    368 
    369 static void
    370 moveFiles (const char * oldDir, const char * newDir)
    371 {
    372   if (oldDir && newDir && strcmp (oldDir, newDir))
    373     {
    374       DIR * dirh = opendir (oldDir);
    375       if (dirh)
    376         {
    377           int count = 0;
    378           struct dirent * dirp;
    379           while ((dirp = readdir (dirh)))
    380             {
    381               const char * name = dirp->d_name;
    382               if (name && strcmp (name, ".") && strcmp (name, ".."))
    383                 {
    384                   char * o = tr_buildPath (oldDir, name, NULL);
    385                   char * n = tr_buildPath (newDir, name, NULL);
    386                   tr_rename (o, n);
    387                   ++count;
    388                   tr_free (n);
    389                   tr_free (o);
    390                 }
    391             }
    392 
    393           if (count)
    394             tr_logAddInfo (_("Migrated %1$d files from \"%2$s\" to \"%3$s\""), count, oldDir, newDir);
    395 
    396           closedir (dirh);
    397         }
    398     }
    399 }
    400 
    401 /**
    402  * This function is for transmission-gtk users to migrate the config files
    403  * from $HOME/.transmission/ (where they were kept before Transmission 1.30)
    404  * to $HOME/.config/$appname as per the XDG directory spec.
    405  */
    406 static void
    407 migrateFiles (const tr_session * session)
    408 {
    409   static int migrated = false;
    410   const bool should_migrate = strstr (getOldConfigDir (), ".transmission") != NULL;
    411 
    412   if (!migrated && should_migrate)
    413     {
    414       const char * oldDir;
    415       const char * newDir;
    416 
    417       migrated = true;
    418 
    419       oldDir = getOldTorrentsDir ();
    420       newDir = tr_getTorrentDir (session);
    421       moveFiles (oldDir, newDir);
    422 
    423       oldDir = getOldCacheDir ();
    424       newDir = tr_getResumeDir (session);
    425       moveFiles (oldDir, newDir);
    426     }
    427 }
    428 
    429312void
    430313tr_setConfigDir (tr_session * session, const char * configDir)
     
    441324  tr_mkdirp (path, 0777);
    442325  session->torrentDir = path;
    443 
    444   migrateFiles (session);
    445326}
    446327
Note: See TracChangeset for help on using the changeset viewer.