/// <summary>Convert a path to a File.</summary> public virtual FilePath PathToFile(Path path) { CheckPath(path); if (!path.IsAbsolute()) { path = new Path(GetWorkingDirectory(), path); } return(new FilePath(path.ToUri().GetPath())); }
private Path MakeAbsolute(Path f) { if (f.IsAbsolute()) { return(f); } else { return(new Path(workingDir, f)); } }
/// <summary> /// This method gets called everytime before any read/write to make sure /// that any change to localDirs is reflected immediately. /// </summary> /// <exception cref="System.IO.IOException"/> private void ConfChanged(Configuration conf) { lock (this) { string newLocalDirs = conf.Get(contextCfgItemName); if (!newLocalDirs.Equals(savedLocalDirs)) { localDirs = StringUtils.GetTrimmedStrings(newLocalDirs); localFS = FileSystem.GetLocal(conf); int numDirs = localDirs.Length; AList <string> dirs = new AList <string>(numDirs); AList <DF> dfList = new AList <DF>(numDirs); for (int i = 0; i < numDirs; i++) { try { // filter problematic directories Path tmpDir = new Path(localDirs[i]); if (localFS.Mkdirs(tmpDir) || localFS.Exists(tmpDir)) { try { FilePath tmpFile = tmpDir.IsAbsolute() ? new FilePath(localFS.MakeQualified(tmpDir ).ToUri()) : new FilePath(localDirs[i]); DiskChecker.CheckDir(tmpFile); dirs.AddItem(tmpFile.GetPath()); dfList.AddItem(new DF(tmpFile, 30000)); } catch (DiskChecker.DiskErrorException de) { Log.Warn(localDirs[i] + " is not writable\n", de); } } else { Log.Warn("Failed to create " + localDirs[i]); } } catch (IOException ie) { Log.Warn("Failed to create " + localDirs[i] + ": " + ie.Message + "\n", ie); } } //ignore localDirs = Collections.ToArray(dirs, new string[dirs.Count]); dirDF = Collections.ToArray(dfList, new DF[dirs.Count]); savedLocalDirs = newLocalDirs; // randomize the first disk picked in the round-robin selection dirNumLastAccessed = dirIndexRandomizer.Next(dirs.Count); } } }
// the getAbsolutexxx method is needed because the root test dir // can be messed up by changing the working dir. /// <exception cref="System.IO.IOException"/> public virtual string GetAbsoluteTestRootDir() { if (absTestRootDir == null) { Path testRootPath = new Path(testRootDir); if (testRootPath.IsAbsolute()) { absTestRootDir = testRootDir; } else { absTestRootDir = GetWorkingDirectory().ToString() + "/" + testRootDir; } } return(absTestRootDir); }
/// <exception cref="System.IO.IOException"/> public override bool MoveToTrash(Path path) { if (!IsEnabled()) { return(false); } if (!path.IsAbsolute()) { // make path absolute path = new Path(fs.GetWorkingDirectory(), path); } if (!fs.Exists(path)) { // check that path exists throw new FileNotFoundException(path.ToString()); } string qpath = fs.MakeQualified(path).ToString(); if (qpath.StartsWith(trash.ToString())) { return(false); } // already in trash if (trash.GetParent().ToString().StartsWith(qpath)) { throw new IOException("Cannot move \"" + path + "\" to the trash, as it contains the trash" ); } Path trashPath = MakeTrashRelativePath(current, path); Path baseTrashPath = MakeTrashRelativePath(current, path.GetParent()); IOException cause = null; // try twice, in case checkpoint between the mkdirs() & rename() for (int i = 0; i < 2; i++) { try { if (!fs.Mkdirs(baseTrashPath, Permission)) { // create current Log.Warn("Can't create(mkdir) trash directory: " + baseTrashPath); return(false); } } catch (IOException e) { Log.Warn("Can't create trash directory: " + baseTrashPath, e); cause = e; break; } try { // if the target path in Trash already exists, then append with // a current time in millisecs. string orig = trashPath.ToString(); while (fs.Exists(trashPath)) { trashPath = new Path(orig + Time.Now()); } if (fs.Rename(path, trashPath)) { // move to current trash return(true); } } catch (IOException e) { cause = e; } } throw (IOException)Extensions.InitCause(new IOException("Failed to move to trash: " + path), cause); }