}
}
- if (access == FileAccess.Read && mode != FileMode.Create && mode != FileMode.OpenOrCreate &&
- mode != FileMode.CreateNew && !File.Exists (path)) {
- // don't leak the path information for isolated storage
- string msg = Locale.GetText ("Could not find file \"{0}\".");
- string fname = GetSecureFileName (path);
- throw new FileNotFoundException (String.Format (msg, fname), fname);
- }
-
// IsolatedStorage needs to keep the Name property to the default "[Unknown]"
if (!anonymous)
this.name = path;
using System.IO;
using System.Globalization;
using System.Threading;
+using System.Runtime.InteropServices;
+
using NUnit.Framework;
MoveTest (FileAccess.ReadWrite, FileShare.Write | FileShare.Delete, true);
MoveTest (FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete, true);
}
+
+
+ [DllImport ("libc", SetLastError=true)]
+ public static extern int symlink (string oldpath, string newpath);
+
+ [Test]
+ public void SymLinkLoop ()
+ {
+ if (!RunningOnUnix)
+ Assert.Ignore ("Symlink are hard on windows");
+
+ var name1 = Path.GetRandomFileName ();
+ var name2 = Path.GetRandomFileName ();
+
+ var path1 = Path.Combine (Path.GetTempPath (), name1);
+ var path2 = Path.Combine (Path.GetTempPath (), name2);
+
+ File.Delete (path1);
+ File.Delete (path2);
+
+ try {
+ symlink (path1, path2);
+ symlink (path2, path1);
+
+ Assert.IsTrue (File.Exists (path1), "File.Exists must return true for path1 symlink loop");
+ Assert.IsTrue (File.Exists (path2), "File.Exists must return true for path2 symlink loop");
+
+ try {
+ using (var f = File.Open (path1, FileMode.Open, FileAccess.Read)) {
+ Assert.Fail ("File.Open must throw for symlink loops");
+ }
+ } catch (IOException ex) {
+ Assert.AreEqual (0x80070781u, (uint)ex.HResult, "Ensure HRESULT is correct");
+ }
+
+ File.Delete (path1); //Delete must not throw and must work
+ Assert.IsFalse (File.Exists (path1), "File.Delete must delete symlink loops");
+
+ } finally {
+ try {
+ File.Delete (path1);
+ File.Delete (path2);
+ } catch (IOException) {
+ //Don't double fault any exception from the tests.
+ }
+
+ }
+ }
}
}
using System.Threading;
using System.Collections.Generic;
+#pragma warning disable CS1718
+
namespace MonoTests.System
{
[TestFixture]
case EIO: return ERROR_INVALID_HANDLE;
case EINTR: return ERROR_IO_PENDING; /* best match I could find */
case EPIPE: return ERROR_WRITE_FAULT;
- case ELOOP: return ERROR_ACCESS_DENIED; /* Empirically found by testing desktop dotnet. */
+ case ELOOP: return ERROR_CANT_RESOLVE_FILENAME;
default:
g_error ("%s: unknown error (%d) \"%s\"", __FILE__, error, g_strerror (error));
#define ERROR_FILENAME_EXCED_RANGE 206
#define ERROR_DIRECTORY 267
#define ERROR_IO_PENDING 997
+#define ERROR_CANT_RESOLVE_FILENAME 1921
#define ERROR_ENCRYPTION_FAILED 6000
#define WSAEINTR 10004
#define WSAEBADF 10009
gchar *filename;
gint retval;
gboolean ret = FALSE;
- guint32 attrs;
#if 0
struct stat statbuf;
FileShare *shareinfo;
return(FALSE);
}
- attrs = mono_w32file_get_attributes (name);
- if (attrs == INVALID_FILE_ATTRIBUTES) {
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: file attributes error", __func__);
- /* Error set by mono_w32file_get_attributes() */
- g_free (filename);
- return(FALSE);
- }
-
#if 0
/* Check to make sure sharing allows us to open the file for
* writing. See bug 323389.
}
result = _wapi_stat (utf8_name, &buf);
- if (result == -1 && errno == ENOENT) {
+ if (result == -1 && (errno == ENOENT || errno == ELOOP)) {
/* Might be a dangling symlink... */
result = _wapi_lstat (utf8_name, &buf);
}