Пример #1
0
 public static Object Dele(IDir self, String unixPath, ConDyn cd) {
     if (unixPath == null) throw new DeleException("unixPath is null");
     if (unixPath.StartsWith("/")) {
         return Dele(GetRoot(self), unixPath.Substring(1), cd);
     }
     int p = unixPath.IndexOf('/');
     String s1 = (p < 0) ? unixPath : unixPath.Substring(0, p);
     String s2 = (p < 0) ? null : unixPath.Substring(1 + p);
     if (s1 == ".") {
         return Dele(self, s2, cd);
     }
     if (s1 == "..") {
         return Dele(self.ParentDir, s2, cd);
     }
     if (s2 == null) {
         MacfNam m2 = cd.ParseName(s1);
         IEnt o2 = self.FindReal(m2.Name);
         if (false) { }
         else if (m2.Ty == Forkty.Data && o2 is ICanDele) ((ICanDele)o2).DeletefMe(false);
         else if (m2.Ty == Forkty.Res && o2 is ICanDele) ((ICanDele)o2).DeletefMe(true);
         else if (m2.Ty == Forkty.Finder && o2 is ICanDeleFi) ((ICanDeleFi)o2).DeletefMeFinder();
         else throw new DeleException("We can't delete \"" + o2.Name + "\".");
         return null;
     }
     IEnt o = self.FindReal(s1);
     if (o is IDir) {
         return Dele((IDir)o, s2, cd);
     }
     else if (o != null) {
         throw new DeleException("We knew \"" + o.Name + "\" is a file.");
     }
     throw new DeleException("We can't be here for \"" + s1 + "\".");
 }
Пример #2
0
        public static void CreateDir(IDir self, String unixPath) {
            if (unixPath == null) return; // Already exists
            if (unixPath.StartsWith("/")) {
                CreateDir(GetRoot(self), unixPath.Substring(1));
                return;
            }
            int p = unixPath.IndexOf('/');
            String s1 = (p < 0) ? unixPath : unixPath.Substring(0, p);
            String s2 = (p < 0) ? null : unixPath.Substring(1 + p);
            if (s1 == ".") {
                CreateDir(self, s2);
                return;
            }
            if (s1 == "..") {
                CreateDir(self.ParentDir, s2);
                return;
            }
            for (int t = 0; t < 2; t++) {
                IEnt o = self.FindReal(s1);
                if (o is IDir) {
                    CreateDir((IDir)o, s2);
                    return;
                }
                else if (o != null) {
                    throw new MkdException("We knew \"" + o.Name + "\" is a file.");
                }

                self.CreateDirHere(s1);

                if (s2 == null) return;
            }
            throw new MkdException("We can't create \"" + unixPath + "\".");
        }
Пример #3
0
 public static Stream Createf(IDir self, String unixPath, ConDyn cd) {
     if (unixPath == null) throw new StorException("unixPath is null");
     if (unixPath.StartsWith("/")) {
         return Createf(GetRoot(self), unixPath.Substring(1), cd);
     }
     int p = unixPath.IndexOf('/');
     String s1 = (p < 0) ? unixPath : unixPath.Substring(0, p);
     String s2 = (p < 0) ? null : unixPath.Substring(1 + p);
     if (s1 == ".") {
         return Createf(self, s2, cd);
     }
     if (s1 == "..") {
         return Createf(self.ParentDir, s2, cd);
     }
     if (s2 == null) {
         MacfNam m2 = cd.ParseName(s1);
         try {
             self.CreatefHere(m2.Name);
         }
         catch (DSIException err) {
             if (err.ErrorCode == (int)AFPt2.DSIException.ResultCode.kFPObjectExists) {
             }
             else throw new StorException("Failed", err);
         }
         IEnt o2 = self.FindReal(m2.Name);
         if (false) { }
         else if (m2.Ty == Forkty.Data && o2 is ICanUP) return ((ICanUP)o2).OpenWrite(false);
         else if (m2.Ty == Forkty.Res && o2 is ICanUP) return ((ICanUP)o2).OpenWrite(true);
         else if (m2.Ty == Forkty.Finder && o2 is ICanUPFi) return ((ICanUPFi)o2).OpenWriteFinder();
         else throw new StorException("We can't write to \"" + o2.Name + "\".");
     }
     IEnt o = self.FindReal(s1);
     if (o is IDir) {
         return Createf((IDir)o, s2, cd);
     }
     else if (o != null) {
         throw new StorException("We knew \"" + o.Name + "\" is a file.");
     }
     throw new StorException("We can't be here for \"" + o.Name + "\".");
 }
Пример #4
0
 public static void RMDir(IDir self, String unixPath) {
     if (unixPath == null) {
         self.RMDirMe();
         return;
     }
     if (unixPath.StartsWith("/")) {
         RMDir(TravUt.GetRoot(self), unixPath.Substring(1));
         return;
     }
     int p = unixPath.IndexOf('/');
     String s1 = (p < 0) ? unixPath : unixPath.Substring(0, p);
     String s2 = (p < 0) ? null : unixPath.Substring(1 + p);
     if (s1 == ".") {
         RMDir(self, s2);
         return;
     }
     if (s1 == "..") {
         RMDir(self.ParentDir, s2);
         return;
     }
     IEnt o = self.FindReal(s1);
     if (o is IDir) {
         RMDir((IDir)o, s2);
         return;
     }
     else if (o != null) {
         throw new RmdException("We knew \"" + o.Name + "\" is a file.");
     }
     throw new RmdException("We can't remove \"" + unixPath + "\".");
 }