public void LinkFromOrCopyTo(MBFile f, IBuildContext ctxt) { // FIXME: like MakeExecutable, probably a hack. string path = GetPath(ctxt); if (!RuntimeEnvironment.MonoUnixSupported) { // emulate with copying CopyTo(f, ctxt); return; } // Try and emulate the copy semantics by obliterating // f if it already exists. string other = f.GetPath(ctxt); try { File.Delete(other); } catch (IOException) { } // FIXME: does this create absolute paths always? // that would be highly lame. UnixFileInfo ufi = new UnixFileInfo(path); ctxt.Logger.Log("io.file_link", other + " -> " + path); ufi.CreateSymbolicLink(other); }
public UartPtyTerminal(string linkName, bool forceCreate = false) { var ptyUnixStream = new PtyUnixStream(); io = new IOProvider { Backend = new StreamIOSource(ptyUnixStream) }; io.ByteRead += b => CallCharReceived((byte)b); if (File.Exists(linkName)) { if (!forceCreate) { throw new RecoverableException(string.Format("File `{0}' already exists. Use forceCreate to overwrite it.", linkName)); } try { File.Delete(linkName); } catch (Exception e) { throw new RecoverableException(string.Format("There was an error when removing existing `{0}' symlink: {1}", linkName, e.Message)); } } try { var slavePtyFile = new UnixFileInfo(ptyUnixStream.SlaveName); symlink = slavePtyFile.CreateSymbolicLink(linkName); } catch (Exception e) { throw new RecoverableException(string.Format("There was an error when when creating a symlink `{0}': {1}", linkName, e.Message)); } }
public static bool Create(string source, string target) { if (!Directory.Exists(source)) { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { //NOTE: attempt with and without the AllowUnprivilegedCreate flag, seems to fix Windows Server 2016 if (!CreateSymbolicLink(source, target, SymbolLinkFlag.Directory | SymbolLinkFlag.AllowUnprivilegedCreate) && !CreateSymbolicLink(source, target, SymbolLinkFlag.Directory)) { var error = new Win32Exception().Message; Console.Error.WriteLine($"Unable to create symbolic link from `{source}` to `{target}`: {error}"); return(false); } } else { try { var fileInfo = new UnixFileInfo(target); fileInfo.CreateSymbolicLink(source); } catch (Exception exc) { Console.Error.WriteLine($"Unable to create symbolic link from `{source}` to `{target}`: {exc.Message}"); return(false); } } } return(true); }
private void CreateSymlink() { if (File.Exists(linkName)) { if (!forceCreate) { throw new RecoverableException(string.Format("File `{0}' already exists. Use forceCreate to overwrite it.", linkName)); } try { File.Delete(linkName); } catch (Exception e) { throw new RecoverableException(string.Format("There was an error when removing existing `{0}' symlink: {1}", linkName, e.Message)); } } try { var slavePtyFile = new UnixFileInfo(ptyStream.SlaveName); symlink = slavePtyFile.CreateSymbolicLink(linkName); } catch (Exception e) { throw new RecoverableException(string.Format("There was an error when when creating a symlink `{0}': {1}", linkName, e.Message)); } }
public void CreateSymLink(string source, string link) { if (File.Exists(link)) { File.Delete(link); } UnixFileInfo ufi = new UnixFileInfo(source); ufi.CreateSymbolicLink(link); }
public override bool CreateSymLink(string target, string symLink) { try { UnixFileInfo targetFile = new UnixFileInfo(target); targetFile.CreateSymbolicLink(symLink); return(true); } catch (Exception ex) { Log.Error("Failed to create symbolic link from '", symLink, "' to '", target, "'"); Log.Error(ex); return(false); } }
public void Analyze() { UnixSymbolicLinkInfo info = new UnixSymbolicLinkInfo(BifDatabasePath); if (info.Exists) { if (!info.IsSymbolicLink && File.Exists(BifLocalPath)) { info.Delete(); UnixFileInfo newInfo = new UnixFileInfo(BifLocalPath); newInfo.CreateSymbolicLink(BifDatabasePath); } else if (!info.IsSymbolicLink) { if (File.Exists(BifLocalPath)) { File.Delete(BifLocalPath); } File.Move(BifDatabasePath, BifLocalPath); UnixFileInfo newInfo = new UnixFileInfo(BifLocalPath); newInfo.CreateSymbolicLink(BifDatabasePath); } } else { if (File.Exists(BifLocalPath)) { UnixFileInfo newInfo = new UnixFileInfo(BifLocalPath); if (!Directory.Exists(IndexDirectory)) { Directory.CreateDirectory(IndexDirectory); } newInfo.CreateSymbolicLink(BifDatabasePath); } } }
public static void EnsureListenerSocket() { var socketPath = InternalSocketPath; Logger.Log.Info($"Configuring socket, internal: {InternalSocketPath}; listener: {ListenerSocketPath}"); try { var socketInfo = new UnixFileInfo(socketPath); _SymLink = socketInfo.CreateSymbolicLink(ListenerSocketPath); Logger.Log.Info($"Created symlink, target: {InternalSocketPath}, source: {ListenerSocketPath}"); socketInfo.FileAccessPermissions = FileAccessPermissions.UserRead | FileAccessPermissions.UserWrite | FileAccessPermissions.GroupRead | FileAccessPermissions.GroupWrite | FileAccessPermissions.OtherRead | FileAccessPermissions.OtherWrite; Logger.Log.Info("Set socket permissions to 0666"); } catch (Exception ex) { Logger.Log.Fatal($"Unable to configure socket, exception: {ex}"); Environment.Exit(-1); } }
private void CreateSymlink(string linkName) { if (File.Exists(linkName)) { try { File.Delete(linkName); } catch (Exception e) { throw new RecoverableException(string.Format("There was an error when removing existing `{0}' symlink: {1}", linkName, e.Message)); } } try { var slavePtyFile = new UnixFileInfo(ptyStream.SlaveName); symlink = slavePtyFile.CreateSymbolicLink(linkName); } catch (Exception e) { throw new RecoverableException(string.Format("There was an error when when creating a symlink `{0}': {1}", linkName, e.Message)); } Logger.Log(LogLevel.Info, "Created a Slip Radio pty connection to {0}", linkName); }
//private Stack<DatabaseTrackInfo> stk=new Stack<DatabaseTrackInfo>(); public void ImportSheet(CueSheet s) { if (import_manager == null) { try { import_manager = new LibraryImportManager(false); /*import_manager.ImportResult+=delegate(object sender,DatabaseImportResultArgs args) { * DatabaseTrackInfo trk=args.Track; * stk.Push (trk); * };*/ } catch (Exception ex) { Hyena.Log.Error(ex.ToString()); } } Hyena.Log.Debug("Importsheet: Starting transaction"); int i, N; for (i = 0, N = s.nEntries(); i < N; i++) { try { CueSheetEntry e = s.entry(i); string file = e.file(); string uuid = Regex.Replace(e.id(), "\\s", "_"); string ext = ".mp3"; string uid = Guid.NewGuid().ToString(); string u1 = uid.Substring(0, 1); string u2 = uid.Substring(0, 2); string dir = basedir + "/.banshee/" + u1; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } dir += "/" + u2; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } uuid = dir + "/" + uuid + ext; UnixFileInfo f = new UnixFileInfo(file); if (File.Exists(uuid)) { File.Delete(uuid); } //f.CreateLink (uuid); f.CreateSymbolicLink(uuid); DatabaseTrackInfo trk = import_manager.ImportTrack(uuid); //File.Delete (uuid); /*if (trk==null) { * Hyena.Log.Warning ("track = null (file="+e.file ()+")"); * if (stk.Count>0) { trk=stk.Pop (); } * }*/ if (trk == null) { Hyena.Log.Error("track = null (file=" + e.file() + ")"); } else { Hyena.Log.Information("track!=null (file=" + e.file() + ")"); //MySource.DbConnection.BeginTransaction(); trk.PartOfCue = 1; trk.CueAudioFile = e.file(); trk.AlbumTitle = s.title(); //trk.Album=s.title (); trk.AlbumArtist = s.performer(); trk.Composer = (e.Composer == "") ? s.composer() : e.Composer; //trk.ArtworkId=s.getArtId (); //trk.Artist= trk.ArtistName = (e.performer() == "") ? s.performer() : e.performer(); trk.TrackTitle = e.title(); trk.TrackNumber = i + 1; trk.Genre = s.genre(); trk.BeginOffset = e.BeginOffset; trk.EndOffset = e.EndOffset; //trk.Uri=trk.CueAudioUri; //trk.MediaAttributes = TrackMediaAttributes.ExternalResource; //trk.PrimarySource = ServiceManager.SourceManager.MusicLibrary; trk.Save(); //MySource.DbConnection.CommitTransaction(); } } catch (Exception ex) { Hyena.Log.Error(ex.ToString()); } } import_manager.NotifyAllSources(); }
private void onStartSync(object o, EventArgs args) { Hyena.Log.Debug("Start of Sync triggered!"); var options = View.GetOptions(); // target directory to copy to Hyena.Log.DebugFormat("Target folder is set to: {0}", options.TargetFolder); // count all files for progress bar int totalFiles = 0; foreach (var playlist in options.SelectedPlaylists) { totalFiles += playlist.Tracks.Count(); } View.Progress.Text = AddinManager.CurrentLocalizer.GetString("Preparing sync"); var progress_step = 1f / totalFiles; var current_progress = 0f; // begin sync worker thread ThreadStart syncStart = delegate() { Hyena.Log.Debug("Sync thread started!"); // foreach playlist foreach (var playlist in options.SelectedPlaylists) { Stream m3u_stream = null; StreamWriter m3u_writer = null; if (options.CreateM3u) { var m3u_fileUri = new StringBuilder().Append(options.TargetFolder) .Append(Path.DirectorySeparatorChar).Append(playlist.Name) .Append(".m3u").ToString(); m3u_stream = Banshee.IO.File.OpenWrite(new SafeUri(m3u_fileUri), true); Log.DebugFormat("opened m3u playlist for writing: {0}", m3u_fileUri); m3u_writer = new StreamWriter(m3u_stream, System.Text.Encoding.UTF8); } // for each contained file foreach (var track in playlist.Tracks) { // get filename part of path var dest_path_suffix = track.GetFilepathSuffix(options.SubfolderDepth); // we dont want %20 etc. in the m3u since some android devices delete // playlists with that encoding in it (i.e. galaxy S) Hyena.Log.DebugFormat("filename for m3u file is {0}", dest_path_suffix); // assemble new Uri of target track var destUri = new SafeUri(new StringBuilder().Append(options.TargetFolder) .Append(Path.DirectorySeparatorChar) .Append(dest_path_suffix).ToString()); // create subfolders if necessary string dest_path = options.TargetFolder; var folders = track.GetSubdirectories(options.SubfolderDepth); try { for (int i = 0; i < folders.Count(); i++) { dest_path += folders [i] + "/"; Hyena.Log.DebugFormat("creating folder {0}", dest_path); if (!Banshee.IO.Directory.Exists(dest_path)) { Banshee.IO.Directory.Create(new SafeUri(dest_path)); } } } catch { // folder creation failed, this is fatal, stop // TODO display a error popup break; } // copy file to selected folder try { var destExists = Banshee.IO.File.Exists(destUri); if (options.OverwriteExisting || !destExists) { if (options.CreateSymLinks) { var trackFilePath = SafeUri.UriToFilename(track.Uri); var destFilePath = SafeUri.UriToFilename(destUri); if (track.Uri.IsLocalPath) { var target = new UnixFileInfo(trackFilePath); // symbolic links need manual deletion, // otherwise an exception is thrown in CreateSymbolicLink() if (destExists) { var dest = new UnixFileInfo(destFilePath); dest.Delete(); } target.CreateSymbolicLink(destFilePath); } else { Hyena.Log.ErrorFormat("Cannot create symlink to remote path {0} in {1}, skipping", track.Uri, destFilePath); } } else { Banshee.IO.File.Copy(track.Uri, destUri, true); } Hyena.Log.DebugFormat("Copying {0} to {1}", track.Uri, destUri); } else { Hyena.Log.Debug("Not overwriting existing file {0}", destUri); } } catch { Hyena.Log.ErrorFormat("Error copying file {0} to {1}, skipping", track.Uri, destUri); } // increment the progressbar current_progress += progress_step; if (current_progress > 1.0f) { current_progress = 1.0f; } Gtk.Application.Invoke(delegate { View.Progress.Fraction = current_progress; View.Progress.Text = AddinManager.CurrentLocalizer.GetString("Copying") + " " + track.Filepath; Gtk.Main.IterationDo(false); }); if (options.CreateM3u) { m3u_writer.Write(track.CreateM3uEntry(options.SubfolderDepth)); } } // close the m3u file before processing next playlist if (options.CreateM3u) { Hyena.Log.Debug("closing m3u filedescriptor"); m3u_writer.Close(); m3u_writer.Dispose(); } Hyena.Log.Debug("sync process finished"); } Gtk.Application.Invoke(delegate { View.Progress.Text = AddinManager.CurrentLocalizer.GetString("Done!"); View.Progress.Fraction = 1f; Gtk.Main.IterationDo(false); }); Hyena.Log.Debug("sync DONE, returning"); return; }; // end of sync worker thread syncThread = new Thread(syncStart); syncThread.Start(); return; }
public static void CreateSymlink(string SourcePath, string DestinationPath) { UnixFileInfo fileinfo = new UnixFileInfo(SourcePath); fileinfo.CreateSymbolicLink(DestinationPath); }