Exemplo n.º 1
0
        /// <summary>
        /// Makes the directory.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="forceDeviceMethod">if set to <c>true</c> forces the use of the "non-busybox" method.</param>
        public void MakeDirectory(String path, bool forceDeviceMethod)
        {
            Device.ThrowIfNull("Device");
            path.ThrowIfNullOrWhiteSpace("path");

            CommandErrorReceiver cer = new CommandErrorReceiver( );

            try {
                //var fileEntry = FileEntry.FindOrCreate ( Device, path );
                // if we have busybox we can use the mkdir in there as it supports --parents
                if (Device.BusyBox.Available && !forceDeviceMethod)
                {
                    try {
                        Device.BusyBox.ExecuteShellCommand("mkdir -p {0}", cer, path);
                    } catch {
                        try {
                            // if there was an error, then fallback too.
                            MakeDirectoryFallbackInternal(path, cer);
                        } catch { }
                    }
                }
                else
                {
                    // if busybox is not available then we have to fallback
                    MakeDirectoryFallbackInternal(path, cer);
                }
            } catch {
            }
            if (!String.IsNullOrEmpty(cer.ErrorMessage))
            {
                throw new IOException(cer.ErrorMessage);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Unmounts the specified mount point.
        /// </summary>
        /// <param name="mountPoint">The mount point.</param>
        /// <param name="options">The options.</param>
        public void Unmount(String mountPoint, String options)
        {
            mountPoint.ThrowIfNull("mountPoint");
            Device.ThrowIfNull("Device");

            CommandErrorReceiver cer = new CommandErrorReceiver();

            Device.ExecuteShellCommand("umount {1} {0}", cer, !String.IsNullOrEmpty(options) ? String.Format("-o {0}", options) : String.Empty, mountPoint);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Attempts to mount the mount point to the associated device without knowing the device or the type.
        /// Some devices may not support this method.
        /// </summary>
        /// <param name="mountPoint"></param>
        public void Mount(String mountPoint)
        {
            mountPoint.ThrowIfNull("mountPoint");
            Device.ThrowIfNull("Device");

            CommandErrorReceiver cer = new CommandErrorReceiver();

            Device.ExecuteShellCommand("mount {0}", cer, mountPoint);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Mounts the specified device.
        /// </summary>
        /// <param name="mountPoint">The mp.</param>
        /// <param name="options">The options.</param>
        public void Mount(MountPoint mountPoint, String options)
        {
            mountPoint.ThrowIfNull("mountPoint");
            Device.ThrowIfNull("Device");

            CommandErrorReceiver cer = new CommandErrorReceiver();

            Device.ExecuteShellCommand("mount {0} {4} -t {1} {2} {3}", cer, mountPoint.IsReadOnly ? "-r" : "-w",
                                       mountPoint.FileSystem, mountPoint.Block, mountPoint.Name,
                                       !String.IsNullOrEmpty(options) ? String.Format("-o {0}", options) : String.Empty);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets a file entry from the specified path on the device.
        /// </summary>
        /// <param name="device">The device to check</param>
        /// <param name="path">the path to check</param>
        /// <exception cref="IOException">If the device is not connected.</exception>
        /// <exception cref="ArgumentNullException">If the device or path is null.</exception>
        /// <exception cref="FileNotFoundException">If the entrty is not found.</exception>
        /// <returns></returns>
        public static FileEntry Find(Device device, string path)
        {
            device.ThrowIfNull("device");
            path.ThrowIfNullOrEmpty("path");

            if (!device.IsOffline)
            {
                return(device.FileListingService.FindFileEntry(path));
            }
            else
            {
                throw new IOException("Device is not online");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Attempts to mount the mount point to the associated device without knowing the device or the type.
        /// Some devices may not support this method.
        /// </summary>
        /// <param name="mountPoint"></param>
        public void Mount(String mountPoint)
        {
            mountPoint.ThrowIfNull("mountPoint");
            Device.ThrowIfNull("Device");

            CommandErrorReceiver cer = new CommandErrorReceiver( );

            if (Device.BusyBox.Available)
            {
                Device.ExecuteShellCommand("busybox mount {0}", cer, mountPoint);
            }
            else
            {
                Device.ExecuteShellCommand("mount {0}", cer, mountPoint);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets if the specified path exists on the device.
        /// </summary>
        /// <param name="path">the path to check</param>
        /// <returns><c>true</c>, if the path exists; otherwise, <c>false</c></returns>
        /// <exception cref="IOException">If the device is not connected.</exception>
        /// <exception cref="ArgumentNullException">If the device or path is null.</exception>
        public bool Exists(String path)
        {
            Device.ThrowIfNull("Device");
            path.ThrowIfNullOrWhiteSpace("path");

            if (!Device.IsOffline)
            {
                try {
                    FileEntry fe = Device.FileListingService.FindFileEntry(path);
                    return(fe != null);
                } catch (FileNotFoundException e) {
                    return(false);
                }
            }
            else
            {
                throw new IOException("Device is not online");
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates the specified path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        public FileEntry Create(String path)
        {
            Device.ThrowIfNull("Device");

            path.ThrowIfNullOrWhiteSpace("path");

            if (!Device.IsOffline)
            {
                if (Exists(path))
                {
                    throw new ArgumentException("The specified path already exists.");
                }
                else
                {
                    var cer     = new CommandErrorReceiver( );
                    var escaped = LinuxPath.Escape(path);
                    // use native touch command if its available.
                    var cmd     = Device.BusyBox.Available ? "touch" : ">";
                    var command = String.Format("{0} {1}", cmd, escaped);
                    if (Device.CanSU( ))
                    {
                        Device.ExecuteRootShellCommand(command, cer);
                    }
                    else
                    {
                        Device.ExecuteShellCommand(command, cer);
                    }
                    if (!String.IsNullOrEmpty(cer.ErrorMessage))
                    {
                        throw new IOException(String.Format("Error creating file: {0}", cer.ErrorMessage));
                    }
                    else
                    {
                        // at this point, the newly created file should exist.
                        return(Device.FileListingService.FindFileEntry(path));
                    }
                }
            }
            else
            {
                throw new IOException("Device is not online");
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Finds the file entry, or creates an empty FileEntry if it does not exist.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="path">The path.</param>
        /// <remarks>This does not create the FileEntry on disk. It only creates the FileEntry object.</remarks>
        /// <returns></returns>
        public static FileEntry FindOrCreate(Device device, string path)
        {
            device.ThrowIfNull("device");
            path.ThrowIfNullOrEmpty("path");

            if (!device.IsOffline)
            {
                try {
                    return(device.FileListingService.FindFileEntry(path));
                } catch (FileNotFoundException) {
                    var fe = new FileEntry(device, path);
                    fe.Create( );
                    return(fe);
                }
            }
            else
            {
                throw new IOException("Device is not online");
            }
        }
        /// <summary>
        /// Gets if the specified path exists on the device.
        /// </summary>
        /// <param name="path">the path to check</param>
        /// <returns><c>true</c>, if the path exists; otherwise, <c>false</c></returns>
        /// <exception cref="IOException">If the device is not connected.</exception>
        /// <exception cref="ArgumentNullException">If the device or path is null.</exception>
        public bool Exists(String path)
        {
            Device.ThrowIfNull("Device");
            path.ThrowIfNullOrWhiteSpace("path");

            if (!Device.IsOffline)
            {
                try {
                    Device.ExecuteShellCommand(
                        Device.FileListingService.ForceBusyBox ? FileListingService.BUSYBOX_LS : FileListingService.TOOLBOX_LS,
                        NullOutputReceiver.Instance, path);
                    return(true);
                } catch (FileNotFoundException) {
                    return(false);
                }
            }
            else
            {
                throw new IOException("Device is not online");
            }
        }