Skip to content

Commit 28370cc

Browse files
committed
code review fix
check if directory has write permission by trying to write to it.
1 parent 997c6d9 commit 28370cc

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

Assets/FbxExporters/Editor/InstallIntegration.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,14 +634,32 @@ public static bool FolderAlreadyUnzippedAtPath(string path)
634634
}
635635

636636
/// <summary>
637-
/// Check if the directory has write permission.
638-
/// TODO: find a way to do this that works in Unity
637+
/// Make sure we can write to this directory.
638+
/// Try creating a file in path directory, if it raises an error, then we can't
639+
/// write here.
640+
/// TODO: find a more reliable way to check this
639641
/// </summary>
640-
/// <returns><c>true</c>, if has write permission was directoryed, <c>false</c> otherwise.</returns>
642+
/// <returns><c>true</c>, if possible to write to path, <c>false</c> otherwise.</returns>
641643
/// <param name="path">Path.</param>
642644
public static bool DirectoryHasWritePermission(string path)
643645
{
644-
return System.IO.Directory.Exists (path);
646+
try
647+
{
648+
using (System.IO.FileStream fs = System.IO.File.Create(
649+
System.IO.Path.Combine(
650+
path,
651+
System.IO.Path.GetRandomFileName()
652+
),
653+
1,
654+
System.IO.FileOptions.DeleteOnClose)
655+
)
656+
{ }
657+
return true;
658+
}
659+
catch(Exception)
660+
{
661+
return false;
662+
}
645663
}
646664

647665
public static void DecompressZip(string zipPath, string destPath){

0 commit comments

Comments
 (0)