aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorunknown2010-07-09 12:58:16 -0400
committerJustin Clark-Casey (justincc)2010-07-17 00:44:54 +0100
commit61f9b3c2cf1c39dd0d1c58eed7d322d29029c2c0 (patch)
treea9687caa8efc635c09e00a637c4676bfc7225bd0 /OpenSim
parentMerge branch '0.6.9-post-fixes' of ssh://opensimulator.org/var/git/opensim in... (diff)
downloadopensim-SC-61f9b3c2cf1c39dd0d1c58eed7d322d29029c2c0.zip
opensim-SC-61f9b3c2cf1c39dd0d1c58eed7d322d29029c2c0.tar.gz
opensim-SC-61f9b3c2cf1c39dd0d1c58eed7d322d29029c2c0.tar.bz2
opensim-SC-61f9b3c2cf1c39dd0d1c58eed7d322d29029c2c0.tar.xz
Bug in 0.6.9 sometimes restoring script state causes region console to crash due to unhandled file lock exception. Attempt to resolve by wrapping several instances of file create / read logic in using statements and added some error handling for locked file exceptions. If it is IDisposable, it must be disposed! The close statements are unnecessary but harmless so I have left those in. The end of the using block will close and dispose automagically.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs123
1 files changed, 84 insertions, 39 deletions
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 73ef570..cc37225 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -1317,10 +1317,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1317 1317
1318 try 1318 try
1319 { 1319 {
1320 FileStream tfs = File.Open(assemName + ".text", 1320 using (FileStream tfs = File.Open(assemName + ".text",
1321 FileMode.Open, FileAccess.Read); 1321 FileMode.Open, FileAccess.Read))
1322 tfs.Read(tdata, 0, tdata.Length); 1322 {
1323 tfs.Close(); 1323 tfs.Read(tdata, 0, tdata.Length);
1324 tfs.Close();
1325 }
1324 1326
1325 assem = new System.Text.ASCIIEncoding().GetString(tdata); 1327 assem = new System.Text.ASCIIEncoding().GetString(tdata);
1326 } 1328 }
@@ -1340,9 +1342,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1340 1342
1341 try 1343 try
1342 { 1344 {
1343 FileStream fs = File.Open(assemName, FileMode.Open, FileAccess.Read); 1345 using (FileStream fs = File.Open(assemName, FileMode.Open, FileAccess.Read))
1344 fs.Read(data, 0, data.Length); 1346 {
1345 fs.Close(); 1347 fs.Read(data, 0, data.Length);
1348 fs.Close();
1349 }
1346 1350
1347 assem = System.Convert.ToBase64String(data); 1351 assem = System.Convert.ToBase64String(data);
1348 } 1352 }
@@ -1358,13 +1362,15 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1358 1362
1359 if (File.Exists(fn + ".map")) 1363 if (File.Exists(fn + ".map"))
1360 { 1364 {
1361 FileStream mfs = File.Open(fn + ".map", FileMode.Open, FileAccess.Read); 1365 using (FileStream mfs = File.Open(fn + ".map", FileMode.Open, FileAccess.Read))
1362 StreamReader msr = new StreamReader(mfs); 1366 {
1363 1367 using (StreamReader msr = new StreamReader(mfs))
1364 map = msr.ReadToEnd(); 1368 {
1365 1369 map = msr.ReadToEnd();
1366 msr.Close(); 1370 msr.Close();
1367 mfs.Close(); 1371 }
1372 mfs.Close();
1373 }
1368 } 1374 }
1369 1375
1370 XmlElement assemblyData = doc.CreateElement("", "Assembly", ""); 1376 XmlElement assemblyData = doc.CreateElement("", "Assembly", "");
@@ -1452,30 +1458,59 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1452 { 1458 {
1453 Byte[] filedata = Convert.FromBase64String(base64); 1459 Byte[] filedata = Convert.FromBase64String(base64);
1454 1460
1455 FileStream fs = File.Create(path); 1461 try
1456 fs.Write(filedata, 0, filedata.Length); 1462 {
1457 fs.Close(); 1463 using (FileStream fs = File.Create(path))
1458 1464 {
1459 fs = File.Create(path + ".text"); 1465 fs.Write(filedata, 0, filedata.Length);
1460 StreamWriter sw = new StreamWriter(fs); 1466 fs.Close();
1461 1467 }
1462 sw.Write(base64); 1468 }
1463 1469 catch (IOException ex)
1464 sw.Close(); 1470 {
1465 fs.Close(); 1471 // if there already exists a file at that location, it may be locked.
1472 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", path, ex.Message);
1473 }
1474 try
1475 {
1476 using (FileStream fs = File.Create(path + ".text"))
1477 {
1478 using (StreamWriter sw = new StreamWriter(fs))
1479 {
1480 sw.Write(base64);
1481 sw.Close();
1482 }
1483 fs.Close();
1484 }
1485 }
1486 catch (IOException ex)
1487 {
1488 // if there already exists a file at that location, it may be locked.
1489 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", path, ex.Message);
1490 }
1466 } 1491 }
1467 } 1492 }
1468 1493
1469 string statepath = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString()); 1494 string statepath = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString());
1470 statepath = Path.Combine(statepath, itemID.ToString() + ".state"); 1495 statepath = Path.Combine(statepath, itemID.ToString() + ".state");
1471 1496
1472 FileStream sfs = File.Create(statepath); 1497 try
1473 StreamWriter ssw = new StreamWriter(sfs); 1498 {
1474 1499 using (FileStream sfs = File.Create(statepath))
1475 ssw.Write(stateE.OuterXml); 1500 {
1476 1501 using (StreamWriter ssw = new StreamWriter(sfs))
1477 ssw.Close(); 1502 {
1478 sfs.Close(); 1503 ssw.Write(stateE.OuterXml);
1504 ssw.Close();
1505 }
1506 sfs.Close();
1507 }
1508 }
1509 catch (IOException ex)
1510 {
1511 // if there already exists a file at that location, it may be locked.
1512 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", statepath, ex.Message);
1513 }
1479 1514
1480 XmlNodeList mapL = rootE.GetElementsByTagName("LineMap"); 1515 XmlNodeList mapL = rootE.GetElementsByTagName("LineMap");
1481 if (mapL.Count > 0) 1516 if (mapL.Count > 0)
@@ -1485,13 +1520,23 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1485 string mappath = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString()); 1520 string mappath = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString());
1486 mappath = Path.Combine(mappath, mapE.GetAttribute("Filename")); 1521 mappath = Path.Combine(mappath, mapE.GetAttribute("Filename"));
1487 1522
1488 FileStream mfs = File.Create(mappath); 1523 try
1489 StreamWriter msw = new StreamWriter(mfs); 1524 {
1490 1525 using (FileStream mfs = File.Create(mappath))
1491 msw.Write(mapE.InnerText); 1526 {
1492 1527 using (StreamWriter msw = new StreamWriter(mfs))
1493 msw.Close(); 1528 {
1494 mfs.Close(); 1529 msw.Write(mapE.InnerText);
1530 msw.Close();
1531 }
1532 mfs.Close();
1533 }
1534 }
1535 catch (IOException ex)
1536 {
1537 // if there already exists a file at that location, it may be locked.
1538 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", statepath, ex.Message);
1539 }
1495 } 1540 }
1496 1541
1497 return true; 1542 return true;