/// <summary>
        /// Pushes a file to device
        /// </summary>
        /// <param name="localFilePath">the absolute path to file on local host</param>
        /// <returns>destination path on device for file</returns>
        /// <exception cref="IOException">if fatal error occurred when pushing file</exception>
        private string SyncPackageToDevice(string localFilePath)
        {
            this.ValidateDevice();

            try
            {
                string packageFileName = Path.GetFileName(localFilePath);

                // only root has access to /data/local/tmp/... not sure how adb does it then...
                // workitem: 16823
                // workitem: 19711
                string remoteFilePath = LinuxPath.Combine(TempInstallationDirectory, packageFileName);

                Log.Debug(packageFileName, $"Uploading {packageFileName} onto device '{this.Device.Serial}'");

                using (ISyncService sync = Factories.SyncServiceFactory(this.Device))
                    using (Stream stream = File.OpenRead(localFilePath))
                    {
                        string message = $"Uploading file onto device '{this.Device.Serial}'";
                        Log.Debug(Tag, message);

                        sync.Push(stream, remoteFilePath, 644, File.GetLastWriteTime(localFilePath), CancellationToken.None);
                    }

                return(remoteFilePath);
            }
            catch (IOException e)
            {
                Log.Error(Tag, $"Unable to open sync connection! reason: {e.Message}");
                throw;
            }
        }
Exemple #2
0
        /// <summary>
        /// Pushes a file to device
        /// </summary>
        /// <param name="localFilePath">the absolute path to file on local host</param>
        /// <returns>destination path on device for file</returns>
        /// <exception cref="IOException">if fatal error occurred when pushing file</exception>
        private string SyncPackageToDevice(string localFilePath)
        {
            this.ValidateDevice();

            try
            {
                string packageFileName = Path.GetFileName(localFilePath);

                // only root has access to /data/local/tmp/... not sure how adb does it then...
                // workitem: 16823
                // workitem: 19711
                string remoteFilePath = LinuxPath.Combine(TempInstallationDirectory, packageFileName);

                this.logger.LogDebug(packageFileName, $"Uploading {packageFileName} onto device '{this.Device.Serial}'");

                using (ISyncService sync = this.syncServiceFactory(this.client, this.Device))
                    using (Stream stream = File.OpenRead(localFilePath))
                    {
                        this.logger.LogDebug($"Uploading file onto device '{this.Device.Serial}'");

                        // As C# can't use octals, the octal literal 666 (rw-Permission) is here converted to decimal (438)
                        sync.Push(stream, remoteFilePath, 438, File.GetLastWriteTime(localFilePath), null, CancellationToken.None);
                    }

                return(remoteFilePath);
            }
            catch (IOException e)
            {
                this.logger.LogError(e, $"Unable to open sync connection! reason: {e.Message}");
                throw;
            }
        }