summaryrefslogtreecommitdiffstats
path: root/libktorrent/migrate
diff options
context:
space:
mode:
Diffstat (limited to 'libktorrent/migrate')
-rw-r--r--libktorrent/migrate/Makefile.am7
-rw-r--r--libktorrent/migrate/cachemigrate.cpp120
-rw-r--r--libktorrent/migrate/cachemigrate.h34
-rw-r--r--libktorrent/migrate/ccmigrate.cpp167
-rw-r--r--libktorrent/migrate/ccmigrate.h36
-rw-r--r--libktorrent/migrate/migrate.cpp75
-rw-r--r--libktorrent/migrate/migrate.h53
7 files changed, 0 insertions, 492 deletions
diff --git a/libktorrent/migrate/Makefile.am b/libktorrent/migrate/Makefile.am
deleted file mode 100644
index 9bb5528..0000000
--- a/libktorrent/migrate/Makefile.am
+++ /dev/null
@@ -1,7 +0,0 @@
-INCLUDES = -I$(srcdir)/.. $(all_includes)
-METASOURCES = AUTO
-libmigrate_la_LDFLAGS = $(all_libraries)
-noinst_LTLIBRARIES = libmigrate.la
-noinst_HEADERS = migrate.h ccmigrate.h cachemigrate.h
-libmigrate_la_SOURCES = migrate.cpp ccmigrate.cpp cachemigrate.cpp
-KDE_CXXFLAGS = $(USE_EXCEPTIONS) $(USE_RTTI)
diff --git a/libktorrent/migrate/cachemigrate.cpp b/libktorrent/migrate/cachemigrate.cpp
deleted file mode 100644
index 9006e2a..0000000
--- a/libktorrent/migrate/cachemigrate.cpp
+++ /dev/null
@@ -1,120 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2005 by Joris Guisson *
- * joris.guisson@gmail.com *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
- ***************************************************************************/
-#include <tqstringlist.h>
-#include <tqfileinfo.h>
-#include <util/log.h>
-#include <util/fileops.h>
-#include <util/functions.h>
-#include <torrent/torrent.h>
-#include <torrent/globals.h>
-#include "cachemigrate.h"
-
-
-namespace bt
-{
-
- bool IsCacheMigrateNeeded(const Torrent & tor,const TQString & cache)
- {
- // mutli files always need to be migrated
- if (tor.isMultiFile())
- return true;
-
- // a single file and a symlink do not need to be migrated
- TQFileInfo finfo(cache);
- if (finfo.isSymLink())
- return false;
-
- return true;
- }
-
- static void MigrateSingleCache(const Torrent & tor,const TQString & cache,const TQString & output_dir)
- {
- Out() << "Migrating single cache " << cache << " to " << output_dir << endl;
-
- bt::Move(cache,output_dir + tor.getNameSuggestion());
- bt::SymLink(output_dir + tor.getNameSuggestion(),cache);
- }
-
- static void MakePath(const TQString & startdir,const TQString & path)
- {
- TQStringList sl = TQStringList::split(bt::DirSeparator(),path);
-
- // create all necessary subdirs
- TQString ctmp = startdir;
-
- for (Uint32 i = 0;i < sl.count() - 1;i++)
- {
- ctmp += sl[i];
- // we need to make the same directory structure in the cache
- // as the output dir
- if (!bt::Exists(ctmp))
- MakeDir(ctmp);
-
- ctmp += bt::DirSeparator();
- }
- }
-
- static void MigrateMultiCache(const Torrent & tor,const TQString & cache,const TQString & output_dir)
- {
- Out() << "Migrating multi cache " << cache << " to " << output_dir << endl;
- // if the cache dir is a symlink, everything is OK
- if (TQFileInfo(cache).isSymLink())
- return;
-
- TQString cache_dir = cache;
-
-
- // make the output dir if it does not exists
- if (!bt::Exists(output_dir + tor.getNameSuggestion()))
- bt::MakeDir(output_dir + tor.getNameSuggestion());
-
- TQString odir = output_dir + tor.getNameSuggestion() + bt::DirSeparator();
- TQString cdir = cache;
- if (!cdir.endsWith(bt::DirSeparator()))
- cdir += bt::DirSeparator();
-
- // loop over all files in the cache and see if they are symlinks
- for (Uint32 i = 0;i < tor.getNumFiles();i++)
- {
- const TorrentFile & tf = tor.getFile(i);
- TQFileInfo fi(cdir + tf.getPath());
- // symlinks are OK
- if (fi.isSymLink())
- continue;
- // make the path if necessary
- MakePath(odir,tf.getPath());
- // no symlink so move to output_dir
- bt::Move(cdir + tf.getPath(),odir + tf.getPath());
- bt::SymLink(odir + tf.getPath(),cdir + tf.getPath());
- }
- }
-
- void MigrateCache(const Torrent & tor,const TQString & cache,const TQString & output_dir)
- {
- TQString odir = output_dir;
- if (!odir.endsWith(bt::DirSeparator()))
- odir += bt::DirSeparator();
-
- if (!tor.isMultiFile())
- MigrateSingleCache(tor,cache,odir);
- else
- MigrateMultiCache(tor,cache,odir);
- }
-}
diff --git a/libktorrent/migrate/cachemigrate.h b/libktorrent/migrate/cachemigrate.h
deleted file mode 100644
index fc618f1..0000000
--- a/libktorrent/migrate/cachemigrate.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2005 by Joris Guisson *
- * joris.guisson@gmail.com *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
- ***************************************************************************/
-#ifndef BTCACHEMIGRATE_H
-#define BTCACHEMIGRATE_H
-
-namespace bt
-{
- class Torrent;
-
- /// See if a cache migrate is needed
- bool IsCacheMigrateNeeded(const Torrent & tor,const TQString & cache);
-
- /// Migrate the cache
- void MigrateCache(const Torrent & tor,const TQString & cache,const TQString & output_dir);
-}
-
-#endif
diff --git a/libktorrent/migrate/ccmigrate.cpp b/libktorrent/migrate/ccmigrate.cpp
deleted file mode 100644
index 631ac6f..0000000
--- a/libktorrent/migrate/ccmigrate.cpp
+++ /dev/null
@@ -1,167 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2005 by Joris Guisson *
- * joris.guisson@gmail.com *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
- ***************************************************************************/
-#include <tdelocale.h>
-#include <util/log.h>
-#include <util/file.h>
-#include <util/error.h>
-#include <util/array.h>
-#include <util/bitset.h>
-#include <util/fileops.h>
-#include <torrent/downloader.h>
-#include <torrent/torrent.h>
-#include <torrent/globals.h>
-#include <torrent/chunkdownload.h>
-#include <ktversion.h>
-#include "ccmigrate.h"
-
-namespace bt
-{
- bool IsPreMMap(const TQString & current_chunks)
- {
- File fptr;
- if (!fptr.open(current_chunks,"rb"))
- return false;
-
- CurrentChunksHeader chdr;
- fptr.read(&chdr,sizeof(CurrentChunksHeader));
- if (chdr.magic != CURRENT_CHUNK_MAGIC)
- {
- // magic number not good, so pre
- return true;
- }
-
- if (chdr.major >= 2 || (chdr.major == 1 && chdr.minor >= 2))
- {
- // version number is 1.2 or greater
- return false;
- }
-
- return false;
- }
-
- static bool MigrateChunk(const Torrent & tor,File & new_cc,File & old_cc)
- {
- Uint32 ch = 0;
- old_cc.read(&ch,sizeof(Uint32));
-
- Out() << "Migrating chunk " << ch << endl;
- if (ch >= tor.getNumChunks())
- return false;
-
- // calculate the size
- Uint32 csize = 0;
- if (ch == tor.getNumChunks() - 1)
- {
- // ch is the last chunk, so it might have a different size
- csize = tor.getFileLength() % tor.getChunkSize();
- if (ch == 0)
- csize = tor.getChunkSize();
- }
- else
- {
- csize = tor.getChunkSize();
- }
-
- // calculate the number of pieces
- Uint32 num_pieces = csize / MAX_PIECE_LEN;
- if (csize % MAX_PIECE_LEN > 0)
- num_pieces++;
-
- // load the pieces array
- Array<bool> pieces(num_pieces);
- old_cc.read(pieces,sizeof(bool)*num_pieces);
-
- // convert bool array to bitset
- BitSet pieces_bs(num_pieces);
- for (Uint32 i = 0;i < num_pieces;i++)
- pieces_bs.set(i,pieces[i]);
-
- // load the actual data
- Array<Uint8> data(csize);
- old_cc.read(data,csize);
-
- // write to the new file
- ChunkDownloadHeader hdr;
- hdr.index = ch;
- hdr.num_bits = num_pieces;
- hdr.buffered = 1; // by default we will use buffered chunks
- // save the chunk header
- new_cc.write(&hdr,sizeof(ChunkDownloadHeader));
- // save the bitset
- new_cc.write(pieces_bs.getData(),pieces_bs.getNumBytes());
- new_cc.write(data,csize);
- return true;
- }
-
- static void MigrateCC(const Torrent & tor,const TQString & current_chunks)
- {
- Out() << "Migrating current_chunks file " << current_chunks << endl;
- // open the old current_chunks file
- File old_cc;
- if (!old_cc.open(current_chunks,"rb"))
- throw Error(i18n("Cannot open file %1 : %2").arg(current_chunks).arg(old_cc.errorString()));
-
- // open a new file in the /tmp dir
- File new_cc;
- TQString tmp = current_chunks + ".tmp";
- if (!new_cc.open(tmp,"wb"))
- throw Error(i18n("Cannot open file %1 : %2").arg(tmp).arg(old_cc.errorString()));
-
- // read the number of chunks
- Uint32 num = 0;
- old_cc.read(&num,sizeof(Uint32));
- Out() << "Found " << num << " chunks" << endl;
-
- // write the new current_chunks header
- CurrentChunksHeader hdr;
- hdr.magic = CURRENT_CHUNK_MAGIC;
- hdr.major = kt::MAJOR;
- hdr.minor = kt::MINOR;
- hdr.num_chunks = num;
- new_cc.write(&hdr,sizeof(CurrentChunksHeader));
-
- for (Uint32 i = 0;i < num;i++)
- {
- if (!MigrateChunk(tor,new_cc,old_cc))
- break;
- }
-
- // migrate done, close both files and move new_cc to old_cc
- new_cc.close();
- old_cc.close();
- bt::Delete(current_chunks);
- bt::Move(tmp,current_chunks);
- }
-
- void MigrateCurrentChunks(const Torrent & tor,const TQString & current_chunks)
- {
- try
- {
- MigrateCC(tor,current_chunks);
- }
- catch (...)
- {
- // cleanup tmp files upon error
- bt::Delete("/tmp/kt_current_chunks",true);
- throw;
- }
- }
-
-}
diff --git a/libktorrent/migrate/ccmigrate.h b/libktorrent/migrate/ccmigrate.h
deleted file mode 100644
index 5272bf5..0000000
--- a/libktorrent/migrate/ccmigrate.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2005 by Joris Guisson *
- * joris.guisson@gmail.com *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
- ***************************************************************************/
-#ifndef BTCCMIGRATE_H
-#define BTCCMIGRATE_H
-
-namespace bt
-{
- class Torrent;
-
- /// Migrates the current_chunks file to the post-mmap era.
- void MigrateCurrentChunks(const Torrent & tor,const TQString & current_chunks);
-
-
- /// Test if a current_chunks file is from the pre-mmap period
- bool IsPreMMap(const TQString & current_chunks);
-
-}
-
-#endif
diff --git a/libktorrent/migrate/migrate.cpp b/libktorrent/migrate/migrate.cpp
deleted file mode 100644
index 4de80cc..0000000
--- a/libktorrent/migrate/migrate.cpp
+++ /dev/null
@@ -1,75 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2005 by Joris Guisson *
- * joris.guisson@gmail.com *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
- ***************************************************************************/
-#include <kurl.h>
-#include <tdelocale.h>
-#include <util/log.h>
-#include <util/error.h>
-#include <util/fileops.h>
-#include <util/functions.h>
-#include <torrent/globals.h>
-#include "migrate.h"
-#include "ccmigrate.h"
-#include "cachemigrate.h"
-
-namespace bt
-{
-
- Migrate::Migrate()
- {}
-
-
- Migrate::~Migrate()
- {}
-
- void Migrate::migrate(const Torrent & tor,const TQString & tor_dir,const TQString & sdir)
- {
- // check if directory exists
- if (!bt::Exists(tor_dir))
- throw Error(i18n("The directory %1 does not exist").arg(tor_dir));
-
- // make sure it ends with a /
- TQString tdir = tor_dir;
- if (!tdir.endsWith(bt::DirSeparator()))
- tdir += bt::DirSeparator();
-
- // see if the current_chunks file exists
- if (bt::Exists(tdir + "current_chunks"))
- {
- // first see if it isn't a download started by a post-mmap version
- if (!IsPreMMap(tdir + "current_chunks"))
- {
- // it's not pre, so it must be post, so just return
- Out() << "No migrate needed" << endl;
- return;
- }
-
- MigrateCurrentChunks(tor,tdir + "current_chunks");
- }
-
- // now we need to migrate t
- if (IsCacheMigrateNeeded(tor,tdir + "cache" + bt::DirSeparator()))
- {
- MigrateCache(tor,tdir + "cache" + bt::DirSeparator(),sdir);
- }
- }
-
-
-
-}
diff --git a/libktorrent/migrate/migrate.h b/libktorrent/migrate/migrate.h
deleted file mode 100644
index 8a943b4..0000000
--- a/libktorrent/migrate/migrate.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2005 by Joris Guisson *
- * joris.guisson@gmail.com *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
- ***************************************************************************/
-#ifndef BTMIGRATE_H
-#define BTMIGRATE_H
-
-namespace bt
-{
- class Torrent;
-
- /**
- @author Joris Guisson <joris.guisson@gmail.com>
-
- Class to migrate old pre-mmap downloads to new ones
- */
- class Migrate
- {
- public:
- Migrate();
- virtual ~Migrate();
-
- /**
- * Migrate a download to the new format.
- * @param tor The torrent
- * @param tor_dir TorX directory
- * @param sdir The save directory
- * @throw Error if something goes wrong
- */
- void migrate(const Torrent & tor,const TQString & tor_dir,const TQString & sdir);
- private:
- bool preMMap(const TQString & current_chunks);
- void migrateCurrentChunks(const TQString & current_chunks);
- };
-
-}
-
-#endif