📄 diskmanagerimpl.java
字号:
}
public boolean filesExist()
{
return filesExist(download_manager.getAbsoluteSaveLocation().getParent());
}
protected boolean filesExist(String root_dir)
{
DMPieceMapperFile pm_files[];
String storage_types[];
int i;
if (!torrent.isSimpleTorrent())
root_dir = (new StringBuilder()).append(root_dir).append(File.separator).append(download_manager.getAbsoluteSaveLocation().getName()).toString();
if (!root_dir.endsWith(File.separator))
root_dir = (new StringBuilder()).append(root_dir).append(File.separator).toString();
pm_files = piece_mapper.getFiles();
storage_types = getStorageTypes();
i = 0;
_L3:
if (i >= pm_files.length) goto _L2; else goto _L1
_L1:
DMPieceMapperFile pm_info;
File relative_file;
long target_length;
DiskManagerFileInfoImpl file_info;
boolean close_it;
pm_info = pm_files[i];
relative_file = pm_info.getDataFile();
target_length = pm_info.getLength();
file_info = pm_info.getFileInfo();
close_it = false;
if (file_info == null)
{
boolean linear = storage_types[i].equals("L");
file_info = new DiskManagerFileInfoImpl(this, new File((new StringBuilder()).append(root_dir).append(relative_file.toString()).toString()), i, pm_info.getTorrentFile(), linear);
close_it = true;
}
File data_file;
File current;
CacheFile cache_file = file_info.getCacheFile();
data_file = file_info.getFile(true);
if (cache_file.exists())
break MISSING_BLOCK_LABEL_413;
current = data_file;
boolean flag1;
File parent;
do
{
if (current.exists())
break MISSING_BLOCK_LABEL_365;
parent = current.getParentFile();
if (parent == null)
break MISSING_BLOCK_LABEL_365;
if (parent.exists())
break;
current = parent;
} while (true);
if (parent.isDirectory())
errorMessage = (new StringBuilder()).append(current.toString()).append(" not found.").toString();
else
errorMessage = (new StringBuilder()).append(parent.toString()).append(" is not a directory.").toString();
flag1 = false;
if (close_it)
file_info.getCacheFile().close();
return flag1;
boolean flag;
errorMessage = (new StringBuilder()).append(data_file.toString()).append(" not found.").toString();
flag = false;
if (close_it)
file_info.getCacheFile().close();
return flag;
long existing_length = file_info.getCacheFile().getLength();
if (existing_length <= target_length)
break MISSING_BLOCK_LABEL_581;
if (COConfigurationManager.getBooleanParameter("File.truncate.if.too.large"))
{
file_info.setAccessMode(2);
file_info.getCacheFile().setLength(target_length);
Debug.out((new StringBuilder()).append("Existing data file length too large [").append(existing_length).append(">").append(target_length).append("]: ").append(data_file.getAbsolutePath()).append(", truncating").toString());
break MISSING_BLOCK_LABEL_581;
}
errorMessage = (new StringBuilder()).append("Existing data file length too large [").append(existing_length).append(">").append(target_length).append("]: ").append(data_file.getAbsolutePath()).toString();
flag1 = false;
if (close_it)
file_info.getCacheFile().close();
return flag1;
if (close_it)
file_info.getCacheFile().close();
continue; /* Loop/switch isn't completed */
Exception exception;
exception;
if (close_it)
file_info.getCacheFile().close();
throw exception;
Throwable e;
e;
errorMessage = (new StringBuilder()).append(Debug.getNestedExceptionMessage(e)).append(" (filesExist:").append(relative_file.toString()).append(")").toString();
return false;
i++;
goto _L3
_L2:
return true;
}
private int allocateFiles()
{
Set file_set;
DMPieceMapperFile pm_files[];
DiskManagerFileInfoImpl allocated_files[];
file_set = new HashSet();
pm_files = piece_mapper.getFiles();
allocated_files = new DiskManagerFileInfoImpl[pm_files.length];
int numNewFiles;
String root_dir;
String storage_types[];
int i;
allocation_scheduler.register(this);
setState(2);
allocated = 0L;
numNewFiles = 0;
root_dir = download_manager.getAbsoluteSaveLocation().getParent();
if (!torrent.isSimpleTorrent())
root_dir = (new StringBuilder()).append(root_dir).append(File.separator).append(download_manager.getAbsoluteSaveLocation().getName()).toString();
root_dir = (new StringBuilder()).append(root_dir).append(File.separator).toString();
storage_types = getStorageTypes();
i = 0;
_L2:
DMPieceMapperFile pm_info;
long target_length;
File relative_data_file;
if (i >= pm_files.length)
break MISSING_BLOCK_LABEL_1911;
pm_info = pm_files[i];
target_length = pm_info.getLength();
relative_data_file = pm_info.getDataFile();
DiskManagerFileInfoImpl fileInfo;
boolean linear = storage_types[i].equals("L");
fileInfo = new DiskManagerFileInfoImpl(this, new File((new StringBuilder()).append(root_dir).append(relative_data_file.toString()).toString()), i, pm_info.getTorrentFile(), linear);
allocated_files[i] = fileInfo;
pm_info.setFileInfo(fileInfo);
goto _L1
CacheFileManagerException e;
e;
byte byte0;
errorMessage = (new StringBuilder()).append(Debug.getNestedExceptionMessage(e)).append(" (allocateFiles:").append(relative_data_file.toString()).append(")").toString();
setState(10);
byte0 = -1;
allocation_scheduler.unregister(this);
if (files == null)
{
for (int i = 0; i < allocated_files.length; i++)
{
if (allocated_files[i] == null)
continue;
try
{
allocated_files[i].getCacheFile().close();
}
catch (Throwable e) { }
}
}
return byte0;
_L1:
CacheFile cache_file;
File data_file;
String data_file_name;
String file_key;
byte byte1;
cache_file = fileInfo.getCacheFile();
data_file = fileInfo.getFile(true);
data_file_name = data_file.getName();
file_key = data_file.getAbsolutePath();
if (Constants.isWindows)
file_key = file_key.toLowerCase();
if (!file_set.contains(file_key))
break MISSING_BLOCK_LABEL_506;
errorMessage = (new StringBuilder()).append("File occurs more than once in download: ").append(data_file.toString()).toString();
setState(10);
byte1 = -1;
allocation_scheduler.unregister(this);
if (files == null)
{
for (int i = 0; i < allocated_files.length; i++)
{
if (allocated_files[i] == null)
continue;
try
{
allocated_files[i].getCacheFile().close();
}
catch (Throwable e) { }
}
}
return byte1;
boolean mustExistOrAllocate;
file_set.add(file_key);
int separator = data_file_name.lastIndexOf(".");
if (separator == -1)
separator = 0;
fileInfo.setExtension(data_file_name.substring(separator));
String extensions = COConfigurationManager.getStringParameter("priorityExtensions", "");
if (!extensions.equals(""))
{
boolean bIgnoreCase = COConfigurationManager.getBooleanParameter("priorityExtensionsIgnoreCase");
StringTokenizer st = new StringTokenizer(extensions, ";");
do
{
if (!st.hasMoreTokens())
break;
String extension = st.nextToken();
extension = extension.trim();
if (!extension.startsWith("."))
extension = (new StringBuilder()).append(".").append(extension).toString();
boolean bHighPriority = bIgnoreCase ? fileInfo.getExtension().equalsIgnoreCase(extension) : fileInfo.getExtension().equals(extension);
if (bHighPriority)
fileInfo.setPriority(true);
} while (true);
}
fileInfo.setDownloaded(0L);
mustExistOrAllocate = cache_file.getStorageType() != 2 || RDResumeHandler.fileMustExist(download_manager, fileInfo);
if (!mustExistOrAllocate && cache_file.exists())
data_file.delete();
if (!cache_file.exists())
break MISSING_BLOCK_LABEL_1090;
byte byte3;
long existing_length = fileInfo.getCacheFile().getLength();
if (existing_length <= target_length)
break MISSING_BLOCK_LABEL_959;
if (COConfigurationManager.getBooleanParameter("File.truncate.if.too.large"))
{
fileInfo.setAccessMode(2);
cache_file.setLength(target_length);
Debug.out((new StringBuilder()).append("Existing data file length too large [").append(existing_length).append(">").append(target_length).append("]: ").append(data_file.getAbsolutePath()).append(", truncating").toString());
break MISSING_BLOCK_LABEL_959;
}
errorMessage = (new StringBuilder()).append("Existing data file length too large [").append(existing_length).append(">").append(target_length).append("]: ").append(data_file.getAbsolutePath()).toString();
setState(10);
byte3 = -1;
allocation_scheduler.unregister(this);
if (files == null)
{
for (int i = 0; i < allocated_files.length; i++)
{
if (allocated_files[i] == null)
continue;
try
{
allocated_files[i].getCacheFile().close();
}
catch (Throwable e) { }
}
}
return byte3;
int i;
try
{
fileInfo.setAccessMode(1);
break MISSING_BLOCK_LABEL_1076;
}
catch (CacheFileManagerException e)
{
errorMessage = (new StringBuilder()).append(Debug.getNestedExceptionMessage(e)).append(" (allocateFiles existing:").append(data_file.getAbsolutePath()).append(")").toString();
setState(10);
i = -1;
}
allocation_scheduler.unregister(this);
if (files == null)
{
for (int i = 0; i < allocated_files.length; i++)
{
if (allocated_files[i] == null)
continue;
try
{
allocated_files[i].getCacheFile().close();
}
catch (Throwable e) { }
}
}
return i;
allocated += target_length;
break MISSING_BLOCK_LABEL_1905;
byte byte2;
if (!mustExistOrAllocate)
break MISSING_BLOCK_LABEL_1905;
if (!download_manager.isDataAlreadyAllocated())
break MISSING_BLOCK_LABEL_1200;
errorMessage = (new StringBuilder()).append("Data file missing: ").append(data_file.getAbsolutePath()).toString();
setState(10);
byte2 = -1;
allocation_scheduler.unregister(this);
if (files == null)
for (i = 0; i < allocated_files.length; i++)
{
if (allocated_files[i] == null)
continue;
try
{
allocated_files[i].getCacheFile().close();
}
catch (Throwable e) { }
}
return byte2;
while (started && !allocation_scheduler.getPermission(this)) ;
if (started)
break MISSING_BLOCK_LABEL_1287;
byte2 = -1;
allocation_scheduler.unregister(this);
if (files == null)
for (i = 0; i < allocated_files.length; i++)
{
if (allocated_files[i] == null)
continue;
try
{
allocated_files[i].getCacheFile().close();
}
catch (Throwable e) { }
}
return byte2;
try
{
fileInfo.setAccessMode(2);
Exception exception;
Throwable e;
if (COConfigurationManager.getBooleanParameter("Enable incremental file creation"))
fileInfo.getCacheFile().setLength(0L);
else
if (target_length > 0L && COConfigurationManager.getBooleanParameter("XFS Allocation"))
{
fileInfo.getCacheFile().setLength(target_length);
String cmd[] = {
"/usr/sbin/xfs_io", "-c", (new StringBuilder()).append("resvsp 0 ").append(target_length).toString(), data_file.getAbsolutePath()
};
ByteArrayOutputStream os = new ByteArrayOutputStream();
byte buffer[] = new byte[1024];
try
{
Process p = Runtime.getRuntime().exec(cmd);
for (int count = p.getErrorStream().read(buffer); count > 0; count = p.getErrorStream().read(buffer))
os.write(buffer, 0, count);
os.close();
p.waitFor();
}
catch (IOException e)
{
String message = MessageText.getString("xfs.allocation.xfs_io.not.found", new String[] {
e.getMessage()
});
Logger.log(new LogAlert(this, false, 3, message));
}
if (os.size() > 0)
{
String message = os.toString().trim();
if (message.endsWith("is not on an XFS filesystem"))
Logger.log(new LogEvent(this, LogIDs.DISK, (new StringBuilder()).append("XFS file allocation impossible because \"").append(data_file.getAbsolutePath()).append("\" is not on an XFS filesystem. Original error reported by xfs_io : \"").append(message).append("\"").toString()));
else
throw new IOException(message);
}
allocated += target_length;
} else
if (COConfigurationManager.getBooleanParameter("Zero New"))
{
boolean successfulAlloc = false;
try
{
successfulAlloc = writer.zeroFile(fileInfo, target_length);
}
catch (Exception e)
{
errorMessage = (new StringBuilder()).append(Debug.getNestedExceptionMessage(e)).append(" (allocateFiles new:").append(data_file.toString()).append(")").toString();
throw e;
}
finally
{
if (successfulAlloc) goto _L0; else goto _L0
}
if (!successfulAlloc)
{
try
{
fileInfo.getCacheFile().close();
fileInfo.getCacheFile().delete();
}
catch (Throwable e) { }
setState(10);
}
} else
{
fileInfo.getCacheFile().setLength(target_length);
allocated += target_length;
}
break MISSING_BLOCK_LABEL_1902;
}
catch (Exception e)
{
errorMessage = (new StringBuilder()).append(Debug.getNestedExceptionMessage(e)).append(" (allocateFiles new:").append(data_file.toString()).append(")").toString();
setState(10);
e = -1;
}
break MISSING_BLOCK_LABEL_1845;
try
{
fileInfo.getCacheFile().close();
fileInfo.getCacheFile().delete();
}
// Misplaced declaration of an exception variable
catch (Throwable e) { }
setState(10);
throw exception;
allocation_scheduler.unregister(this);
if (files == null)
{
for (int i = 0; i < allocated_files.length; i++)
{
if (allocated_files[i] == null)
continue;
try
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -