GetPath() public method

public GetPath ( ) : string
return string
Ejemplo n.º 1
0
		private static void RunFileIfExists(Context cx, Scriptable global, FilePath f)
		{
			if (f.IsFile())
			{
				Main.ProcessFileNoThrow(cx, global, f.GetPath());
			}
		}
Ejemplo n.º 2
0
		public SystemProcess Exec (string[] cmd, string[] envp, FilePath dir)
		{
			try {
				ProcessStartInfo psi = new ProcessStartInfo ();
				psi.FileName = cmd[0];
				psi.Arguments = string.Join (" ", cmd, 1, cmd.Length - 1);
				if (dir != null) {
					psi.WorkingDirectory = dir.GetPath ();
				}
				psi.UseShellExecute = false;
				psi.RedirectStandardInput = true;
				psi.RedirectStandardError = true;
				psi.RedirectStandardOutput = true;
				psi.CreateNoWindow = true;
				if (envp != null) {
					foreach (string str in envp) {
						int index = str.IndexOf ('=');
						psi.EnvironmentVariables[str.Substring (0, index)] = str.Substring (index + 1);
					}
				}
				return SystemProcess.Start (psi);
			} catch (System.ComponentModel.Win32Exception ex) {
				throw new IOException (ex.Message);
			}
		}
 public static bool DeleteRecursive (FilePath attachmentsFile)
 {
     var success = true;
     try {
         Directory.Delete (attachmentsFile.GetPath (), true);
     } catch (Exception ex) {
         Log.V(Tag, "Error deleting the '{0}' directory.".Fmt(attachmentsFile.GetAbsolutePath()), ex);
         success = false;
     }
     return success;
 }
Ejemplo n.º 4
0
		public Process Exec (string[] cmd, string[] envp, FilePath dir)
		{
			Process process = new Process ();
			process.StartInfo.FileName = cmd[0];
			process.StartInfo.Arguments = string.Join (" ", cmd, 1, cmd.Length - 1);
			if (dir != null) {
				process.StartInfo.WorkingDirectory = dir.GetPath ();
			}
			process.StartInfo.UseShellExecute = false;
			if (envp != null) {
				foreach (string str in envp) {
					int index = str.IndexOf ('=');
					process.StartInfo.EnvironmentVariables[str.Substring (0, index)] = str.Substring (index + 1);
				}
			}
			process.Start ();
			return process;
		}
Ejemplo n.º 5
0
        public static FilePath CreateTempFile(string prefix, string suffix, FilePath directory)
        {
            string file;

            if (prefix == null)
            {
                throw new ArgumentNullException("prefix");
            }
            if (prefix.Length < 3)
            {
                throw new ArgumentException("prefix must have at least 3 characters");
            }
            string str = (directory == null) ? Path.GetTempPath() : directory.GetPath();

            do
            {
                file = Path.Combine(str, prefix + Interlocked.Increment(ref tempCounter) + suffix);
            } while (File.Exists(file));

            new FileOutputStream(file).Close();
            return(new FilePath(file));
        }
Ejemplo n.º 6
0
 public FileOutputStream(FilePath file) : this(file.GetPath(), false)
 {
 }
Ejemplo n.º 7
0
		public RandomAccessFile (FilePath file, string mode) : this(file.GetPath (), mode)
		{
		}
Ejemplo n.º 8
0
 public FileReader(FilePath f) : base(f.GetPath())
 {
 }
		/// <summary>Constructs an exception indicating a local repository does not exist.</summary>
		/// <remarks>Constructs an exception indicating a local repository does not exist.</remarks>
		/// <param name="location">description of the repository not found, usually file path.
		/// 	</param>
		public RepositoryNotFoundException(FilePath location) : this(location.GetPath())
		{
		}
 public RandomAccessFile(FilePath file, string mode) : this(file.GetPath(), mode)
 {
 }
Ejemplo n.º 11
0
		public static FilePath CreateTempFile (string prefix, string suffix, FilePath directory)
		{
			string file;
			if (prefix == null) {
				throw new ArgumentNullException ("prefix");
			}
			if (prefix.Length < 3) {
				throw new ArgumentException ("prefix must have at least 3 characters");
			}
			string str = (directory == null) ? Path.GetTempPath () : directory.GetPath ();
			do {
				file = Path.Combine (str, prefix + Interlocked.Increment (ref tempCounter) + suffix);
			} while (File.Exists (file));
			
			new FileOutputStream (file).Close ();
			return new FilePath (file);
		}
Ejemplo n.º 12
0
 public FileWriter(FilePath path) : base(Couchbase.Lite.File.OpenStream(path.GetPath(), true))
 {
 }
Ejemplo n.º 13
0
 public FileInputStream(FilePath file) : this(file.GetPath())
 {
 }
Ejemplo n.º 14
0
		public PrintWriter (FilePath path) : base(path.GetPath ())
		{
		}
Ejemplo n.º 15
0
        /// <summary>
        /// Deletes the %Database%.
        /// </summary>
        /// <exception cref="Couchbase.Lite.CouchbaseLiteException"/>
        public void Delete()
        {
            if (open)
            {
                if (!Close())
                {
                    throw new CouchbaseLiteException("The database was open, and could not be closed", 
                        StatusCode.InternalServerError);
                }
            }

            Manager.ForgetDatabase(this);
            if (!Exists())
            {
                return;
            }

            var file = new FilePath(Path);
            var attachmentsFile = new FilePath(AttachmentStorePath);

            var deleteStatus = file.Delete();
            if (!deleteStatus)
            {
                Log.V(Database.Tag, String.Format("Error deleting the SQLite database file at {0}", file.GetAbsolutePath()));
            }

            //recursively delete attachments path
            var deletedAttachmentsPath = true;
            try {
				var dirInfo = new DirectoryInfo(attachmentsFile.GetPath());
				dirInfo.Delete(true);
				//Directory.Delete (attachmentsFile.GetPath (), true);
            } catch (Exception ex) {
                Log.V(Database.Tag, "Error deleting the attachments directory.", ex);
                deletedAttachmentsPath = false;
            }

            if (!deleteStatus)
            {
                throw new CouchbaseLiteException("Was not able to delete the database file", StatusCode.InternalServerError);
            }

            if (!deletedAttachmentsPath)
            {
                throw new CouchbaseLiteException("Was not able to delete the attachments files", StatusCode.InternalServerError);
            }
        }
Ejemplo n.º 16
0
		/// <exception cref="System.Exception"></exception>
		public static void Run(ShellContextFactory shellContextFactory, FilePath jsFile, ShellTest.Parameters parameters, ShellTest.Status status)
		{
			Global global = new Global();
			MemoryStream @out = new MemoryStream();
			TextWriter p = new TextWriter(@out);
			global.SetOut(p);
			global.SetErr(p);
			global.DefineFunctionProperties(new string[] { "options" }, typeof(ShellTest), ScriptableObject.DONTENUM | ScriptableObject.PERMANENT | ScriptableObject.READONLY);
			// test suite expects keywords to be disallowed as identifiers
			shellContextFactory.SetAllowReservedKeywords(false);
			ShellTest.TestState testState = new ShellTest.TestState();
			if (jsFile.GetName().EndsWith("-n.js"))
			{
				status.SetNegative();
			}
			Exception[] thrown = new Exception[] { null };
			Sharpen.Thread t = new Sharpen.Thread(new _Runnable_274(shellContextFactory, thrown, testState, status, jsFile, global), jsFile.GetPath());
			t.SetDaemon(true);
			t.Start();
			t.Join(parameters.GetTimeoutMilliseconds());
			lock (testState)
			{
				if (!testState.finished)
				{
					CallStop(t);
					status.TimedOut();
				}
			}
			int expectedExitCode = 0;
			p.Flush();
			status.OutputWas(Sharpen.Runtime.GetStringForBytes(@out.ToArray()));
			BufferedReader r = new BufferedReader(new StreamReader(new MemoryStream(@out.ToArray())));
			string failures = string.Empty;
			for (; ; )
			{
				string s = r.ReadLine();
				if (s == null)
				{
					break;
				}
				if (s.IndexOf("FAILED!") != -1)
				{
					failures += s + '\n';
				}
				int expex = s.IndexOf("EXPECT EXIT CODE ");
				if (expex != -1)
				{
					expectedExitCode = s[expex + "EXPECT EXIT CODE ".Length] - '0';
				}
			}
			if (thrown[0] != null)
			{
				status.Threw(thrown[0]);
			}
			status.ExitCodesWere(expectedExitCode, testState.exitCode);
			if (failures != string.Empty)
			{
				status.Failed(failures);
			}
		}
Ejemplo n.º 17
0
 ///// <summary>Read at most limit bytes from the local file into memory as a byte array.
 ///// 	</summary>
 ///// <remarks>Read at most limit bytes from the local file into memory as a byte array.
 ///// 	</remarks>
 ///// <param name="path">location of the file to read.</param>
 ///// <param name="limit">
 ///// maximum number of bytes to read, if the file is larger than
 ///// only the first limit number of bytes are returned
 ///// </param>
 ///// <returns>
 ///// complete contents of the requested local file. If the contents
 ///// exceeds the limit, then only the limit is returned.
 ///// </returns>
 ///// <exception cref="System.IO.FileNotFoundException">the file does not exist.</exception>
 ///// <exception cref="System.IO.IOException">the file exists, but its contents cannot be read.
 ///// 	</exception>
 //public static byte[] ReadSome(FilePath path, int limit)
 //{
 //    FileInputStream @in = new FileInputStream(path);
 //    try
 //    {
 //        byte[] buf = new byte[limit];
 //        int cnt = 0;
 //        for (; ; )
 //        {
 //            int n = @in.Read(buf, cnt, buf.Length - cnt);
 //            if (n <= 0)
 //            {
 //                break;
 //            }
 //            cnt += n;
 //        }
 //        if (cnt == buf.Length)
 //        {
 //            return buf;
 //        }
 //        byte[] res = new byte[cnt];
 //        System.Array.Copy(buf, 0, res, 0, cnt);
 //        return res;
 //    }
 //    finally
 //    {
 //        try
 //        {
 //            @in.Close();
 //        }
 //        catch (IOException)
 //        {
 //        }
 //    }
 //}
 //// do nothing
 ///// <summary>Read an entire local file into memory as a byte array.</summary>
 ///// <remarks>Read an entire local file into memory as a byte array.</remarks>
 ///// <param name="path">location of the file to read.</param>
 ///// <param name="max">
 ///// maximum number of bytes to read, if the file is larger than
 ///// this limit an IOException is thrown.
 ///// </param>
 ///// <returns>complete contents of the requested local file.</returns>
 ///// <exception cref="System.IO.FileNotFoundException">the file does not exist.</exception>
 ///// <exception cref="System.IO.IOException">the file exists, but its contents cannot be read.
 ///// 	</exception>
 public static byte[] ReadFully(FilePath path, int max)
 {
     return File.ReadAllBytes(path.GetPath());
 }
		/// <summary>Constructs an exception indicating a local repository does not exist.</summary>
		/// <remarks>Constructs an exception indicating a local repository does not exist.</remarks>
		/// <param name="location">description of the repository not found, usually file path.
		/// 	</param>
		/// <param name="why">why the repository does not exist.</param>
		public RepositoryNotFoundException(FilePath location, Exception why) : this(location
			.GetPath(), why)
		{
		}
 public FileOutputStream (FilePath file): this (file.GetPath (), false)
 {
 }
Ejemplo n.º 20
0
		public FileReader (FilePath f) : base(f.GetPath ())
		{
		}
 public FileOutputStream (FilePath file, bool append) : this(file.GetPath (), append)
 {
 }
Ejemplo n.º 22
0
 public FileReader(FilePath f) : base(Couchbase.Lite.File.OpenStream(f.GetPath()))
 {
 }
Ejemplo n.º 23
0
 public FileWriter (FilePath path) : base(path.GetPath ())
 {
 }
Ejemplo n.º 24
0
		/// <summary>
		/// Waits until it is guaranteed that a subsequent file modification has a
		/// younger modification timestamp than the modification timestamp of the
		/// given file.
		/// </summary>
		/// <remarks>
		/// Waits until it is guaranteed that a subsequent file modification has a
		/// younger modification timestamp than the modification timestamp of the
		/// given file. This is done by touching a temporary file, reading the
		/// lastmodified attribute and, if needed, sleeping. After sleeping this loop
		/// starts again until the filesystem timer has advanced enough.
		/// </remarks>
		/// <param name="lastFile">
		/// the file on which we want to wait until the filesystem timer
		/// has advanced more than the lastmodification timestamp of this
		/// file
		/// </param>
		/// <returns>
		/// return the last measured value of the filesystem timer which is
		/// greater than then the lastmodification time of lastfile.
		/// </returns>
		/// <exception cref="System.Exception">System.Exception</exception>
		/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
		public static long FsTick(FilePath lastFile)
		{
			long sleepTime = 1;
			if (lastFile != null && !lastFile.Exists())
			{
				throw new FileNotFoundException(lastFile.GetPath());
			}
			FilePath tmp = FilePath.CreateTempFile("FileTreeIteratorWithTimeControl", null);
			try
			{
				long startTime = (lastFile == null) ? tmp.LastModified() : lastFile.LastModified(
					);
				long actTime = tmp.LastModified();
				while (actTime <= startTime)
				{
					Sharpen.Thread.Sleep(sleepTime);
					sleepTime *= 5;
					tmp.SetLastModified(Runtime.CurrentTimeMillis());
					actTime = tmp.LastModified();
				}
				return actTime;
			}
			finally
			{
				FileUtils.Delete(tmp);
			}
		}
Ejemplo n.º 25
0
 public FileInputStream (FilePath file) : this(file.GetPath ())
 {
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Updates the file in the working tree with content and mode from an entry
        /// in the index.
        /// </summary>
        /// <remarks>
        /// Updates the file in the working tree with content and mode from an entry
        /// in the index. The new content is first written to a new temporary file in
        /// the same directory as the real file. Then that new file is renamed to the
        /// final filename.
        /// <p>
        /// TODO: this method works directly on File IO, we may need another
        /// abstraction (like WorkingTreeIterator). This way we could tell e.g.
        /// Eclipse that Files in the workspace got changed
        /// </p>
        /// </remarks>
        /// <param name="repo"></param>
        /// <param name="f">
        /// the file to be modified. The parent directory for this file
        /// has to exist already
        /// </param>
        /// <param name="entry">the entry containing new mode and content</param>
        /// <param name="or">object reader to use for checkout</param>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        public static void CheckoutEntry(Repository repo, FilePath f, DirCacheEntry entry
			, ObjectReader or)
        {
            ObjectLoader ol = or.Open(entry.GetObjectId());
            FilePath parentDir = f.GetParentFile();
            FilePath tmpFile = FilePath.CreateTempFile("._" + f.GetName(), null, parentDir);
            WorkingTreeOptions opt = repo.GetConfig().Get(WorkingTreeOptions.KEY);
            FileOutputStream rawChannel = new FileOutputStream(tmpFile);
            OutputStream channel;
            if (opt.GetAutoCRLF() == CoreConfig.AutoCRLF.TRUE)
            {
                channel = new AutoCRLFOutputStream(rawChannel);
            }
            else
            {
                channel = rawChannel;
            }
            try
            {
                ol.CopyTo(channel);
            }
            finally
            {
                channel.Close();
            }
            FS fs = repo.FileSystem;
            if (opt.IsFileMode() && fs.SupportsExecute())
            {
                if (FileMode.EXECUTABLE_FILE.Equals(entry.RawMode))
                {
                    if (!fs.CanExecute(tmpFile))
                    {
                        fs.SetExecute(tmpFile, true);
                    }
                }
                else
                {
                    if (fs.CanExecute(tmpFile))
                    {
                        fs.SetExecute(tmpFile, false);
                    }
                }
            }
            if (!tmpFile.RenameTo(f))
            {
                // tried to rename which failed. Let' delete the target file and try
                // again
                FileUtils.Delete(f);
                if (!tmpFile.RenameTo(f))
                {
                    throw new IOException(MessageFormat.Format(JGitText.Get().couldNotWriteFile, tmpFile
                        .GetPath(), f.GetPath()));
                }
            }
            entry.LastModified = f.LastModified();
            if (opt.GetAutoCRLF() != CoreConfig.AutoCRLF.FALSE)
            {
                entry.SetLength(f.Length());
            }
            else
            {
                // AutoCRLF wants on-disk-size
                entry.SetLength((int)ol.GetSize());
            }
        }
Ejemplo n.º 27
0
 public FileWriter(FilePath path) : base(path.GetPath())
 {
 }
Ejemplo n.º 28
0
 public FileOutputStream(FilePath file, bool append) : this(file.GetPath(), append)
 {
 }
Ejemplo n.º 29
0
		public FileReader (FilePath f) : base(Couchbase.Lite.File.OpenStream(f.GetPath ()))
		{
		}
Ejemplo n.º 30
0
		public FileWriter (FilePath path) : base(Couchbase.Lite.File.OpenStream(path.GetPath (), true))
		{
		}